private void createIdentifierClass(final JavaType identifierType) {
    final List<AnnotationMetadataBuilder> identifierAnnotations =
        new ArrayList<AnnotationMetadataBuilder>();

    final AnnotationMetadataBuilder identifierBuilder =
        new AnnotationMetadataBuilder(ROO_IDENTIFIER);
    identifierBuilder.addBooleanAttribute(DB_MANAGED.getSymbolName(), true);
    identifierAnnotations.add(identifierBuilder);

    // Produce identifier itself
    final String declaredByMetadataId =
        PhysicalTypeIdentifier.createIdentifier(
            identifierType, projectOperations.getPathResolver().getFocusedPath(Path.SRC_MAIN_JAVA));
    final ClassOrInterfaceTypeDetailsBuilder cidBuilder =
        new ClassOrInterfaceTypeDetailsBuilder(
            declaredByMetadataId,
            Modifier.PUBLIC | Modifier.FINAL,
            identifierType,
            PhysicalTypeCategory.CLASS);
    cidBuilder.setAnnotations(identifierAnnotations);
    typeManagementService.createOrUpdateTypeOnDisk(cidBuilder.build());

    shell.flash(
        Level.FINE,
        "Created " + identifierType.getFullyQualifiedTypeName(),
        DbreDatabaseListenerImpl.class.getName());
    shell.flash(Level.FINE, "", DbreDatabaseListenerImpl.class.getName());
  }
  /**
   * Creates a new DBRE-managed entity from the given table
   *
   * @param javaType the name of the entity to be created (required)
   * @param table the table from which to create the entity (required)
   * @param activeRecord whether to create "active record" CRUD methods in the new entity
   * @return the newly created entity
   */
  private ClassOrInterfaceTypeDetails createNewManagedEntityFromTable(
      final JavaType javaType, final Table table, final boolean activeRecord) {
    // Create type annotations for new entity
    final List<AnnotationMetadataBuilder> annotations = new ArrayList<AnnotationMetadataBuilder>();
    annotations.add(new AnnotationMetadataBuilder(ROO_JAVA_BEAN));
    annotations.add(new AnnotationMetadataBuilder(ROO_TO_STRING));

    // Find primary key from db metadata and add identifier attributes to
    // @RooJpaEntity
    final AnnotationMetadataBuilder jpaAnnotationBuilder =
        new AnnotationMetadataBuilder(activeRecord ? ROO_JPA_ACTIVE_RECORD : ROO_JPA_ENTITY);
    manageIdentifier(javaType, jpaAnnotationBuilder, new HashSet<JavaSymbolName>(), table);

    if (!hasVersionField(table)) {
      jpaAnnotationBuilder.addStringAttribute(VERSION_FIELD, "");
    }
    if (table.isDisableGeneratedIdentifiers()) {
      jpaAnnotationBuilder.addStringAttribute(SEQUENCE_NAME_FIELD, "");
    }

    jpaAnnotationBuilder.addStringAttribute("table", table.getName());
    if (!DbreModelService.NO_SCHEMA_REQUIRED.equals(table.getSchema().getName())) {
      jpaAnnotationBuilder.addStringAttribute("schema", table.getSchema().getName());
    }

    annotations.add(jpaAnnotationBuilder);

    // Add @RooDbManaged
    annotations.add(getRooDbManagedAnnotation());

    final JavaType superclass = OBJECT;
    final List<JavaType> extendsTypes = new ArrayList<JavaType>();
    extendsTypes.add(superclass);

    // Create entity class
    final String declaredByMetadataId =
        PhysicalTypeIdentifier.createIdentifier(
            javaType, projectOperations.getPathResolver().getFocusedPath(Path.SRC_MAIN_JAVA));
    final ClassOrInterfaceTypeDetailsBuilder cidBuilder =
        new ClassOrInterfaceTypeDetailsBuilder(
            declaredByMetadataId, Modifier.PUBLIC, javaType, PhysicalTypeCategory.CLASS);
    cidBuilder.setExtendsTypes(extendsTypes);
    cidBuilder.setAnnotations(annotations);

    final ClassOrInterfaceTypeDetails entity = cidBuilder.build();
    typeManagementService.createOrUpdateTypeOnDisk(entity);

    shell.flash(
        Level.FINE,
        "Created " + javaType.getFullyQualifiedTypeName(),
        DbreDatabaseListenerImpl.class.getName());
    shell.flash(Level.FINE, "", DbreDatabaseListenerImpl.class.getName());

    return entity;
  }
  /**
   * Deletes the given {@link JavaType} for the given reason
   *
   * @param javaType the type to be deleted (required)
   * @param reason the reason for deletion (can be blank)
   */
  private void deleteJavaType(final JavaType javaType, final String reason) {
    final PhysicalTypeMetadata governorPhysicalTypeMetadata = getPhysicalTypeMetadata(javaType);
    if (governorPhysicalTypeMetadata != null) {
      final String filePath = governorPhysicalTypeMetadata.getPhysicalLocationCanonicalPath();
      if (fileManager.exists(filePath)) {
        fileManager.delete(filePath, reason);
        shell.flash(
            Level.FINE,
            "Deleted " + javaType.getFullyQualifiedTypeName(),
            DbreDatabaseListenerImpl.class.getName());
      }

      shell.flash(Level.FINE, "", DbreDatabaseListenerImpl.class.getName());
    }
  }