Class JPAMetadataGenerator
java.lang.Object
org.eclipse.persistence.tools.metadata.generation.JPAMetadataGenerator
This class is responsible for generating an XMLEntityMappings instance based
on a given list of meta-model database types.
- See Also:
-
Field Summary
Modifier and TypeFieldDescriptionprotected DatabasePlatform
protected static final String
protected String
protected boolean
protected XMLEntityMappings
-
Constructor Summary
ConstructorDescriptionDefault constructor.JPAMetadataGenerator
(String defaultPackage, String platformClassName) This constructor allows setting the default package name and database platform.JPAMetadataGenerator
(String defaultPackage, DatabasePlatform dbPlatform) This constructor allows setting the default package name and database platform.JPAMetadataGenerator
(String defaultPackage, DatabasePlatform dbPlatform, boolean generateCRUDOps) This constructor allows setting the default package name and database platform. -
Method Summary
Modifier and TypeMethodDescriptionprotected 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.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.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.protected ArrayAccessor
generateArrayAccessor
(String arrayName, String columnName, String databaseTypeName) Returns an ArrayAccessor instance, constructed based on the given String values.protected ArrayAccessor
generateArrayAccessor
(String arrayName, String columnName, String databaseTypeName, String targetClassName) Returns an ArrayAccessor instance, constructed based on the given String values.protected BasicAccessor
generateBasicAccessor
(String basicName, String columnName, String attributeTypeName) Returns a BasicAccessor instance, constructed based on the given String values.protected void
generateCRUDMetadata
(EntityAccessor entity) Generates NamedNativeQueryMetadata for CRUD operations (create, findAll, findByPk, update and delete) for a given Entity if required, i.e.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.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.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.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.protected StructureAccessor
generateStructureAccessor
(String structureName, String columnName, String attributeTypeName) Returns a StructureAccessor instance, constructed based on the given String values.protected StructureAccessor
generateStructureAccessor
(String structureName, String columnName, String attributeTypeName, String targetClassName) Returns a StructureAccessor instance, constructed based on the given String values.generateXmlEntityMappings
(List<CompositeDatabaseType> databaseTypes) Generate an XMLEntityMappings instance based on a given list of meta-model database types.Lazy-load the List of embeddables.Lazy-load the List of processed composite types.protected String
Convenience method that returns a query name for a given ProcedureType.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'.protected void
initializeXMLAttributeLists
(ClassAccessor accessor) XMLAttributes processing at runtime (i.e.protected void
XMLEntityMappings processing at runtime (i.e.static DatabasePlatform
loadDatabasePlatform
(String platformClassName) Attempt to load the DatabasePlatform using the given platform class name.protected StoredProcedureParameterMetadata
Generate a stored procedure parameter based on the given ArgumentType.protected OracleArrayTypeMetadata
processArrayType
(DatabaseType dbType) Generate array type metadata based on the given VArray or ObjectTable type.protected void
processCompositeType
(DatabaseType compositeType) Process the given composite database type.protected void
processCompositeType
(DatabaseType compositeType, String typeName) Process the given composite database type.protected NamedStoredFunctionQueryMetadata
processFunctionType
(FunctionType fType) Generate a stored function query based on the given FunctionType.protected OracleObjectTypeMetadata
processObjectType
(ObjectType oType) Generate object type metadata based on the given ObjectType.protected PLSQLParameterMetadata
Generate a PL/SQL parameter based on the given ArgumentType.protected PLSQLTableMetadata
processPLSQLCollectionType
(PLSQLCollectionType plsqlCollectionType) Process the given PLSQLCollectionType and return a PLSQLTableMetadata instance.protected NamedPLSQLStoredFunctionQueryMetadata
processPLSQLFunctionType
(FunctionType fType, PLSQLPackageType pkgType) Generate a PL/SQL stored function query based on the given FunctionType.protected NamedPLSQLStoredProcedureQueryMetadata
processPLSQLProcedureType
(ProcedureType pType, PLSQLPackageType pkgType) Generate a PL/SQL stored procedure query based on the given ProcedureType.protected PLSQLRecordMetadata
processPLSQLRecordType
(PLSQLRecordType plsqlRecordType) Process the given PLSQLRecordType and return a PLSQLRecordMetadata instance.protected NamedStoredProcedureQueryMetadata
Generate a stored procedure query based on the given ProcedureType.protected EntityAccessor
processTableType
(TableType tType) Generate an EntityAccessor based on the given TableType.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.
-
Field Details
-
xmlEntityMappings
-
dbPlatform
-
defaultPackage
-
generateCRUDOps
protected boolean generateCRUDOps -
processedTypes
-
generatedEmbeddables
-
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:
-
JPAMetadataGenerator
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
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
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
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
Generate an EntityAccessor based on the given TableType. -
processFunctionType
Generate a stored function query based on the given FunctionType. -
processProcedureType
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
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
Generate a stored procedure parameter based on the given ArgumentType. For PL/SQL arguments the processPLSQLArgument method should be used. -
processPLSQLArgument
Generate a PL/SQL parameter based on the given ArgumentType. For non-PL/SQL arguments the processArgument method should be used. -
processObjectType
Generate object type metadata based on the given ObjectType. -
processArrayType
Generate array type metadata based on the given VArray or ObjectTable type. -
processPLSQLCollectionType
Process the given PLSQLCollectionType and return a PLSQLTableMetadata instance. -
processPLSQLRecordType
Process the given PLSQLRecordType and return a PLSQLRecordMetadata instance. -
processCompositeType
Process the given composite database type. -
processCompositeType
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
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
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 EmbeddablerecordType
- 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
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
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
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
Lazy-load the List of processed composite types. -
getGeneratedEmbeddables
Lazy-load the List of embeddables. -
embeddableAlreadyProcessed
Indicates if an embeddable has already been processed - the list of generated embeddable names will be checked for the given typeName. -
alreadyProcessed
Indicates if a type has already been processed - the list of processed type names will be checked for the given typeName. -
loadDatabasePlatform
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:
-