public MemberHoldingTypeDetails build() {
   if (existing instanceof ItdTypeDetails) {
     ItdTypeDetailsBuilder builder = new ItdTypeDetailsBuilder((ItdTypeDetails) existing);
     // Push in all members that may have been modified
     builder.setDeclaredFields(this.getDeclaredFields());
     builder.setDeclaredMethods(this.getDeclaredMethods());
     builder.setAnnotations(this.getAnnotations());
     builder.setCustomData(this.getCustomData());
     builder.setDeclaredConstructors(this.getDeclaredConstructors());
     builder.setDeclaredInitializers(this.getDeclaredInitializers());
     builder.setDeclaredInnerTypes(this.getDeclaredInnerTypes());
     builder.setExtendsTypes(this.getExtendsTypes());
     builder.setImplementsTypes(this.getImplementsTypes());
     builder.setModifier(this.getModifier());
     return builder.build();
   } else if (existing instanceof ClassOrInterfaceTypeDetails) {
     ClassOrInterfaceTypeDetailsBuilder builder =
         new ClassOrInterfaceTypeDetailsBuilder((ClassOrInterfaceTypeDetails) existing);
     // Push in all members that may
     builder.setDeclaredFields(this.getDeclaredFields());
     builder.setDeclaredMethods(this.getDeclaredMethods());
     builder.setAnnotations(this.getAnnotations());
     builder.setCustomData(this.getCustomData());
     builder.setDeclaredConstructors(this.getDeclaredConstructors());
     builder.setDeclaredInitializers(this.getDeclaredInitializers());
     builder.setDeclaredInnerTypes(this.getDeclaredInnerTypes());
     builder.setExtendsTypes(this.getExtendsTypes());
     builder.setImplementsTypes(this.getImplementsTypes());
     builder.setModifier(this.getModifier());
     return builder.build();
   } else {
     throw new IllegalStateException("Unknown instance of MemberHoldingTypeDetails");
   }
 }
  /**
   * 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;
  }