java.lang.Object
org.eclipse.persistence.tools.metadata.generation.JPAMetadataGenerator

public class JPAMetadataGenerator extends Object
This class is responsible for generating an XMLEntityMappings instance based on a given list of meta-model database types.
See Also:
  • Field Details

    • xmlEntityMappings

      protected XMLEntityMappings xmlEntityMappings
    • dbPlatform

      protected DatabasePlatform dbPlatform
    • defaultPackage

      protected String defaultPackage
    • generateCRUDOps

      protected boolean generateCRUDOps
    • processedTypes

      protected List<String> processedTypes
    • generatedEmbeddables

      protected List<String> generatedEmbeddables
    • DEFAULT_PLATFORM

      protected static final String DEFAULT_PLATFORM
      See Also:
  • Constructor Details

    • JPAMetadataGenerator

      public JPAMetadataGenerator()
      Default constructor. Sets the default package name to null, and dbPlatform to org.eclipse.persistence.platform.database.oracle.Oracle11Platform. The default package name will be prepended to generated class names for database artifacts that are not in a PL/SQL package. The database platform is used to get class names for database types, i.e. java.math.BigDecimal for DECIMAL.
      See Also:
      • "org.eclipse.persistence.platform.database.oracle.Oracle11Platform"
      • DatabasePlatform
    • JPAMetadataGenerator

      public JPAMetadataGenerator(String defaultPackage, String platformClassName)
      This constructor allows setting the default package name and database platform.
      Parameters:
      defaultPackage - package name to be prepended to generated class names for artifacts not in a PL/SQL package such as an Entity (to avoid having classes in the default package)
      platformClassName - class name of the DatabasePlatform to be used to get class names for database types, i.e. java.math.BigDecimal for DECIMAL.
      See Also:
    • JPAMetadataGenerator

      public JPAMetadataGenerator(String defaultPackage, DatabasePlatform dbPlatform)
      This constructor allows setting the default package name and database platform.
      Parameters:
      defaultPackage - package name to be prepended to generated class names for artifacts not in a PL/SQL package such as an Entity (to avoid having classes in the default package)
      dbPlatform - DatabasePlatform to be used to get class names for database types, i.e. java.math.BigDecimal for DECIMAL.
      See Also:
    • JPAMetadataGenerator

      public JPAMetadataGenerator(String defaultPackage, DatabasePlatform dbPlatform, boolean generateCRUDOps)
      This constructor allows setting the default package name and database platform.
      Parameters:
      defaultPackage - package name to be prepended to generated class names for artifacts not in a PL/SQL package such as an Entity (to avoid having classes in the default package)
      dbPlatform - DatabasePlatform to be used to get class names for database types, i.e. java.math.BigDecimal for DECIMAL.
      generateCRUDOps - if true, CRUD operations (NamedNativeQueryMetadata) will be generated for each Entity
      See Also:
  • Method Details

    • initializeXMLEntityMappingLists

      protected void initializeXMLEntityMappingLists()
      XMLEntityMappings processing at runtime (i.e. PersistenceUnitProcessor.processORMetadata) assumes that all lists are initialized. We need to init all lists to avoid runtime exceptions.
      See Also:
    • initializeXMLAttributeLists

      protected void initializeXMLAttributeLists(ClassAccessor accessor)
      XMLAttributes processing at runtime (i.e. PersistenceUnitProcessor.processORMetadata) assumes that all lists are initialized. We need to init all lists to avoid runtime exceptions.
      See Also:
    • generateXmlEntityMappings

      public XMLEntityMappings generateXmlEntityMappings(List<CompositeDatabaseType> databaseTypes)
      Generate an XMLEntityMappings instance based on a given list of meta-model database types.
      Parameters:
      databaseTypes - the list of meta-model database types to be used to generate an XMLEntityMappings
      See Also:
    • processTableType

      protected EntityAccessor processTableType(TableType tType)
      Generate an EntityAccessor based on the given TableType.
    • processFunctionType

      protected NamedStoredFunctionQueryMetadata processFunctionType(FunctionType fType)
      Generate a stored function query based on the given FunctionType.
    • processProcedureType

      protected NamedStoredProcedureQueryMetadata processProcedureType(ProcedureType pType)
      Generate a stored procedure query based on the given ProcedureType.
    • processPLSQLFunctionType

      protected NamedPLSQLStoredFunctionQueryMetadata processPLSQLFunctionType(FunctionType fType, PLSQLPackageType pkgType)
      Generate a PL/SQL stored function query based on the given FunctionType.
    • processPLSQLProcedureType

      protected NamedPLSQLStoredProcedureQueryMetadata processPLSQLProcedureType(ProcedureType pType, PLSQLPackageType pkgType)
      Generate a PL/SQL stored procedure query based on the given ProcedureType.
    • getQueryNameForProcedureType

      protected String getQueryNameForProcedureType(ProcedureType pType)
      Convenience method that returns a query name for a given ProcedureType. The name will be the procedureName value of the ProcedureType with "_" + overload value if the ProcedureType's overload value is > 0. For example, if the procedureName value is "P1" and overload == 0, "P1" is returned. If the procedureName value is "P1" and overload == 4, "P1_4" is returned.
    • processArgument

      protected StoredProcedureParameterMetadata processArgument(ArgumentType arg)
      Generate a stored procedure parameter based on the given ArgumentType. For PL/SQL arguments the processPLSQLArgument method should be used.
    • processPLSQLArgument

      protected PLSQLParameterMetadata processPLSQLArgument(ArgumentType arg)
      Generate a PL/SQL parameter based on the given ArgumentType. For non-PL/SQL arguments the processArgument method should be used.
    • processObjectType

      protected OracleObjectTypeMetadata processObjectType(ObjectType oType)
      Generate object type metadata based on the given ObjectType.
    • processArrayType

      protected OracleArrayTypeMetadata processArrayType(DatabaseType dbType)
      Generate array type metadata based on the given VArray or ObjectTable type.
    • processPLSQLCollectionType

      protected PLSQLTableMetadata processPLSQLCollectionType(PLSQLCollectionType plsqlCollectionType)
      Process the given PLSQLCollectionType and return a PLSQLTableMetadata instance.
    • processPLSQLRecordType

      protected PLSQLRecordMetadata processPLSQLRecordType(PLSQLRecordType plsqlRecordType)
      Process the given PLSQLRecordType and return a PLSQLRecordMetadata instance.
    • processCompositeType

      protected void processCompositeType(DatabaseType compositeType)
      Process the given composite database type.
    • processCompositeType

      protected void processCompositeType(DatabaseType compositeType, String typeName)
      Process the given composite database type. For PL/SQL types, typeName will be the fully qualified type name (i.e. packagename.typename). The type should be one of: PLSQLCollection, PLSQLRecord, Object, ObjectTable, or Varray.
    • generateEmbeddable

      protected void generateEmbeddable(PLSQLTableMetadata tableMetadata, String targetClassName)
      Generate an Embeddable for the given PLSQLTableMetadata, and add it to the list of Embeddables on the XMLEntityMappings instance.
      Parameters:
      tableMetadata - PLSQLTableMetadata used to build the Embeddable
    • generateEmbeddable

      protected void generateEmbeddable(PLSQLRecordMetadata recordMetadata, PLSQLRecordType recordType)
      Generate an Embeddable for the given PLSQLRecordMetadata and PLSQLRecordType, and add it to the list of Embeddables on the XMLEntityMappings instance.
      Parameters:
      recordMetadata - PLSQLRecordMetadata used to build the Embeddable
      recordType - PLSQLRecordType used to build the Embeddable
    • generateEmbeddable

      protected void generateEmbeddable(OracleArrayTypeMetadata arrayTypeMetadata, CompositeDatabaseTypeWithEnclosedType dbType)
      Generate an Embeddable for the given OracleArrayTypeMetadata, and add it to the list of Embeddables on the XMLEntityMappings instance.
    • generateEmbeddable

      protected void generateEmbeddable(OracleObjectTypeMetadata objectTypeMetadata, ObjectType objectType)
      Generate an Embeddable for the given OracleObjectTypeMetadata, and add it to the list of Embeddables on the XMLEntityMappings instance.
    • initEmbeddable

      protected EmbeddableAccessor initEmbeddable(String embeddableClassName)
      Convenience method that creates and EmbeddableAccessor, setting the class name to the provided embeddableClassName, initializes the various lists (Basics, Arrays, etc.), and sets the access type to 'VIRTUAL'.
    • addEmbeddableAttributes

      protected void addEmbeddableAttributes(EmbeddableAccessor embeddable, List<FieldType> fields)
      Process a list of FieldTypes, creating an attribute for each - the created XMLAttributes are set on the given EmbeddableAccessor.
      See Also:
    • generateArrayAccessor

      protected ArrayAccessor generateArrayAccessor(String arrayName, String columnName, String databaseTypeName)
      Returns an ArrayAccessor instance, constructed based on the given String values. This method can be used when the database type and target class names are the same.
    • generateArrayAccessor

      protected ArrayAccessor generateArrayAccessor(String arrayName, String columnName, String databaseTypeName, String targetClassName)
      Returns an ArrayAccessor instance, constructed based on the given String values.
    • generateBasicAccessor

      protected BasicAccessor generateBasicAccessor(String basicName, String columnName, String attributeTypeName)
      Returns a BasicAccessor instance, constructed based on the given String values.
    • generateStructureAccessor

      protected StructureAccessor generateStructureAccessor(String structureName, String columnName, String attributeTypeName)
      Returns a StructureAccessor instance, constructed based on the given String values. This method can be used when the attribute type and target class names are the same.
    • generateStructureAccessor

      protected StructureAccessor generateStructureAccessor(String structureName, String columnName, String attributeTypeName, String targetClassName)
      Returns a StructureAccessor instance, constructed based on the given String values.
    • generateCRUDMetadata

      protected void generateCRUDMetadata(EntityAccessor entity)
      Generates NamedNativeQueryMetadata for CRUD operations (create, findAll, findByPk, update and delete) for a given Entity if required, i.e. generateCRUDOps is true.
    • setGenerateCRUDOps

      protected void setGenerateCRUDOps(boolean generateCRUDOps)
      If set to true, NamedNativeQueryMetadata for CRUD operations (create, findAll, findByPk, update and delete) will be generated for each Entity. The default is false.
    • getProcessedTypes

      protected List<String> getProcessedTypes()
      Lazy-load the List of processed composite types.
    • getGeneratedEmbeddables

      protected List<String> getGeneratedEmbeddables()
      Lazy-load the List of embeddables.
    • embeddableAlreadyProcessed

      protected boolean embeddableAlreadyProcessed(String embeddableName)
      Indicates if an embeddable has already been processed - the list of generated embeddable names will be checked for the given typeName.
    • alreadyProcessed

      protected boolean alreadyProcessed(String typeName)
      Indicates if a type has already been processed - the list of processed type names will be checked for the given typeName.
    • loadDatabasePlatform

      public static DatabasePlatform loadDatabasePlatform(String platformClassName)
      Attempt to load the DatabasePlatform using the given platform class name. If the platform cannot be loaded Oracle11Platform will be returned - if available.
      Parameters:
      platformClassName - class name of the DatabasePlatform to be loaded
      Returns:
      DatabasePlatform loaded for the given platformClassname, or Oracle11Platform if not found
      See Also:
      • "org.eclipse.persistence.platform.database.oracle.Oracle11Platform"