Class JPAIdentifierFactory
- java.lang.Object
-
- org.datanucleus.store.rdbms.identifier.AbstractIdentifierFactory
-
- org.datanucleus.store.rdbms.identifier.JPAIdentifierFactory
-
- All Implemented Interfaces:
IdentifierFactory
public class JPAIdentifierFactory extends AbstractIdentifierFactory
Factory that creates immutable instances of DatastoreIdentifier for mapped datastores with JPA. Includes the JPA naming strategy, naming as follows- Class called "MyClass" will generate table name of "MYCLASS"
- Field called "myField" will generate column name of "MYFIELD"
- Join table will be named after the ownerClass and the otherClass so "MyClass" joining to "MyOtherClass" will have a join table called "MYCLASS_MYOTHERCLASS"
- Join table for Collection element/Map value of nonPC will be based on "{ownerEntity}_{memberName}"
- Join table column for Map key will be "{memberName}_KEY"
- Datastore-identity column for class "MyClass" will be "MYCLASS_ID" (not part of JPA)
- 1-N uni between "MyClass" (field="myField") and "MyElement" will have FK in "MYELEMENT" of MYFIELD_MYCLASS_ID
- 1-N bi between "MyClass" (field="myField") and "MyElement" (field="myClassRef") will have FK in "MYELEMENT" of name "MYCLASSREF_MYCLASS_ID".
- 1-1 uni between "MyClass" (field="myField") and "MyElement" will have FK in "MYCLASS" of name "MYFIELD_MYELEMENT_ID"
- Discriminator field columns will, by default, be called "DTYPE"
- Version field columns will, by default, be called "VERSION"
- Index (ordering) field columns will, for field "myField", be called "MYFIELD_ORDER"
- Adapter index field columns will, by default, be called "IDX"
-
-
Field Summary
-
Fields inherited from class org.datanucleus.store.rdbms.identifier.AbstractIdentifierFactory
candidates, CASE_LOWER, CASE_PRESERVE, CASE_UPPER, clr, columns, dba, defaultCatalogName, defaultSchemaName, foreignkeys, indexes, namingCase, namingFactory, primarykeys, quoteString, references, sequences, tables, wordSeparator
-
Fields inherited from interface org.datanucleus.store.rdbms.identifier.IdentifierFactory
PROPERTY_DEFAULT_CATALOG, PROPERTY_DEFAULT_SCHEMA, PROPERTY_NAMING_FACTORY, PROPERTY_REQUIRED_CASE, PROPERTY_TABLE_PREFIX, PROPERTY_TABLE_SUFFIX, PROPERTY_WORD_SEPARATOR
-
-
Constructor Summary
Constructors Constructor Description JPAIdentifierFactory(DatastoreAdapter dba, org.datanucleus.ClassLoaderResolver clr, Map props)
Constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description String
generateIdentifierNameForJavaName(String javaName)
Generate a datastore identifier from a Java identifier.protected String
getColumnIdentifierSuffix(org.datanucleus.metadata.FieldRole role, boolean embedded)
Accessor for the suffix to add to any column identifier, based on the role type.DatastoreIdentifier
newAdapterIndexFieldIdentifier()
Method to return an identifier for an adapter index column.DatastoreIdentifier
newDiscriminatorFieldIdentifier()
Method to return an identifier for a discriminator column.DatastoreIdentifier
newForeignKeyFieldIdentifier(org.datanucleus.metadata.AbstractMemberMetaData ownerFmd, org.datanucleus.metadata.AbstractMemberMetaData relatedFmd, DatastoreIdentifier destinationId, boolean embedded, org.datanucleus.metadata.FieldRole fieldRole)
Method to generate a FK/FK-index field identifier.DatastoreIdentifier
newIndexFieldIdentifier(org.datanucleus.metadata.AbstractMemberMetaData mmd)
Method to return an identifier for an index (ordering) column.DatastoreIdentifier
newJoinTableFieldIdentifier(org.datanucleus.metadata.AbstractMemberMetaData ownerFmd, org.datanucleus.metadata.AbstractMemberMetaData relatedFmd, DatastoreIdentifier destinationId, boolean embedded, org.datanucleus.metadata.FieldRole fieldRole)
Method to generate a join-table identifier.DatastoreIdentifier
newReferenceFieldIdentifier(org.datanucleus.metadata.AbstractMemberMetaData refMetaData, org.datanucleus.metadata.AbstractClassMetaData implMetaData, DatastoreIdentifier implIdentifier, boolean embedded, org.datanucleus.metadata.FieldRole fieldRole)
Method to generate an identifier name for reference field, based on the metadata for the field, and the ClassMetaData for the implementation.DatastoreIdentifier
newTableIdentifier(org.datanucleus.metadata.AbstractClassMetaData cmd)
Method to return a Table identifier for the specified class.DatastoreIdentifier
newTableIdentifier(org.datanucleus.metadata.AbstractMemberMetaData mmd)
Method to return a Table identifier for the join table of the specified field/property.DatastoreIdentifier
newVersionFieldIdentifier()
Method to return an identifier for a version column.-
Methods inherited from class org.datanucleus.store.rdbms.identifier.AbstractIdentifierFactory
getDatastoreAdapter, getIdentifierInAdapterCase, getIdentifierNamePartsFromName, getIdentifierTruncatedToAdapterColumnLength, getNamingCase, getWordSeparator, newCandidateKeyIdentifier, newColumnIdentifier, newColumnIdentifier, newForeignKeyIdentifier, newIdentifier, newIdentifier, newIndexIdentifier, newPrimaryKeyIdentifier, newSequenceIdentifier, newTableIdentifier, newTableIdentifier, setCatalogSchemaForTable, truncate
-
-
-
-
Constructor Detail
-
JPAIdentifierFactory
public JPAIdentifierFactory(DatastoreAdapter dba, org.datanucleus.ClassLoaderResolver clr, Map props)
Constructor. The properties accepted are- RequiredCase : what case the identifiers should be in
- DefaultCatalog : default catalog to use (if any)
- DefaultSchema : default schema to use (if any)
- Parameters:
dba
- Datastore adapterclr
- ClassLoader resolverprops
- Any properties controlling identifier generation
-
-
Method Detail
-
newTableIdentifier
public DatastoreIdentifier newTableIdentifier(org.datanucleus.metadata.AbstractMemberMetaData mmd)
Method to return a Table identifier for the join table of the specified field/property.- Parameters:
mmd
- Meta data for the field/property- Returns:
- The identifier for the table
-
newTableIdentifier
public DatastoreIdentifier newTableIdentifier(org.datanucleus.metadata.AbstractClassMetaData cmd)
Method to return a Table identifier for the specified class.- Parameters:
cmd
- Meta data for the class- Returns:
- The identifier for the table
-
newReferenceFieldIdentifier
public DatastoreIdentifier newReferenceFieldIdentifier(org.datanucleus.metadata.AbstractMemberMetaData refMetaData, org.datanucleus.metadata.AbstractClassMetaData implMetaData, DatastoreIdentifier implIdentifier, boolean embedded, org.datanucleus.metadata.FieldRole fieldRole)
Method to generate an identifier name for reference field, based on the metadata for the field, and the ClassMetaData for the implementation.- Parameters:
refMetaData
- the metadata for the reference fieldimplMetaData
- the AbstractClassMetaData for this implementationimplIdentifier
- PK identifier for the implementationembedded
- Whether the identifier is for a field embeddedfieldRole
- The role to be performed by this column e.g FK, collection element ?- Returns:
- The DatastoreIdentifier
-
newJoinTableFieldIdentifier
public DatastoreIdentifier newJoinTableFieldIdentifier(org.datanucleus.metadata.AbstractMemberMetaData ownerFmd, org.datanucleus.metadata.AbstractMemberMetaData relatedFmd, DatastoreIdentifier destinationId, boolean embedded, org.datanucleus.metadata.FieldRole fieldRole)
Method to generate a join-table identifier. The identifier could be for a foreign-key to another table (if the destinationId is provided), or could be for a simple column in the join table.- Parameters:
ownerFmd
- MetaData for the owner fielddestinationId
- Identifier for the identity field of the destination (if FK)embedded
- Whether the identifier is for a field embeddedfieldRole
- The role to be performed by this column e.g FK, collection element ?relatedFmd
- MetaData for the related field (if bidirectional)- Returns:
- The identifier.
-
newForeignKeyFieldIdentifier
public DatastoreIdentifier newForeignKeyFieldIdentifier(org.datanucleus.metadata.AbstractMemberMetaData ownerFmd, org.datanucleus.metadata.AbstractMemberMetaData relatedFmd, DatastoreIdentifier destinationId, boolean embedded, org.datanucleus.metadata.FieldRole fieldRole)
Method to generate a FK/FK-index field identifier. The identifier could be for the FK field itself, or for a related index for the FK.- Parameters:
ownerFmd
- MetaData for the owner fieldrelatedFmd
- MetaData for the related fielddestinationId
- Identifier for the identity field of the destination table (if strict FK)embedded
- Whether the identifier is for a field embeddedfieldRole
- The role to be performed by this column e.g ROLE_OWNER, ROLE_INDEX- Returns:
- The identifier
-
newDiscriminatorFieldIdentifier
public DatastoreIdentifier newDiscriminatorFieldIdentifier()
Method to return an identifier for a discriminator column. Returns an identifier "DTYPE"- Returns:
- The discriminator column identifier
-
newVersionFieldIdentifier
public DatastoreIdentifier newVersionFieldIdentifier()
Method to return an identifier for a version column.- Returns:
- The version column identifier
-
newIndexFieldIdentifier
public DatastoreIdentifier newIndexFieldIdentifier(org.datanucleus.metadata.AbstractMemberMetaData mmd)
Method to return an identifier for an index (ordering) column.- Parameters:
mmd
- MetaData for the field/property- Returns:
- The index column identifier
-
newAdapterIndexFieldIdentifier
public DatastoreIdentifier newAdapterIndexFieldIdentifier()
Method to return an identifier for an adapter index column. An "adapter index" is a column added to be part of a primary key when some other column cant perform that role.- Returns:
- The index column identifier
-
generateIdentifierNameForJavaName
public String generateIdentifierNameForJavaName(String javaName)
Generate a datastore identifier from a Java identifier.Conversion consists of breaking the identifier into words, converting each word to upper-case, and separating each one with an underscore "_". Words are identified by a leading upper-case character. Any leading or trailing underscores are removed.
- Specified by:
generateIdentifierNameForJavaName
in classAbstractIdentifierFactory
- Parameters:
javaName
- the Java identifier.- Returns:
- The datastore identifier
-
getColumnIdentifierSuffix
protected String getColumnIdentifierSuffix(org.datanucleus.metadata.FieldRole role, boolean embedded)
Accessor for the suffix to add to any column identifier, based on the role type.- Specified by:
getColumnIdentifierSuffix
in classAbstractIdentifierFactory
- Parameters:
role
- column roleembedded
- Whether the column is stored embedded- Returns:
- The suffix (e.g _ID for id columns).
-
-