org.datanucleus.store.mapped.identifier
Class JPAIdentifierFactory

java.lang.Object
  extended by org.datanucleus.store.mapped.identifier.AbstractIdentifierFactory
      extended by org.datanucleus.store.mapped.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


Field Summary
 
Fields inherited from class org.datanucleus.store.mapped.identifier.AbstractIdentifierFactory
candidates, CASE_LOWER, CASE_PRESERVE, CASE_UPPER, clr, columns, dba, defaultCatalogName, defaultSchemaName, foreignkeys, identifierCase, indexes, LOCALISER, primarykeys, quoteString, rdba, references, sequences, tables, wordSeparator
 
Constructor Summary
JPAIdentifierFactory(DatastoreAdapter dba, ClassLoaderResolver clr, java.util.Map props)
          Constructor.
 
Method Summary
 java.lang.String generateIdentifierNameForJavaName(java.lang.String javaName)
          Generate a datastore identifier from a Java identifier.
protected  java.lang.String getColumnIdentifierSuffix(int 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 datastore field.
 DatastoreIdentifier newDatastoreContainerIdentifier(AbstractClassMetaData cmd)
          Method to return a Table identifier for the specified class.
 DatastoreIdentifier newDatastoreContainerIdentifier(AbstractMemberMetaData mmd)
          Method to return a Table identifier for the join table of the specified field/property.
 DatastoreIdentifier newDiscriminatorFieldIdentifier()
          Method to return an identifier for a discriminator column.
 DatastoreIdentifier newForeignKeyFieldIdentifier(AbstractMemberMetaData ownerFmd, AbstractMemberMetaData relatedFmd, DatastoreIdentifier destinationId, boolean embedded, int fieldRole)
          Method to generate a FK/FK-index field identifier.
 DatastoreIdentifier newIndexFieldIdentifier(AbstractMemberMetaData mmd)
          Method to return an identifier for an index (ordering) datastore field.
 DatastoreIdentifier newJoinTableFieldIdentifier(AbstractMemberMetaData ownerFmd, AbstractMemberMetaData relatedFmd, DatastoreIdentifier destinationId, boolean embedded, int fieldRole)
          Method to generate a join-table identifier.
 DatastoreIdentifier newReferenceFieldIdentifier(AbstractMemberMetaData refMetaData, AbstractClassMetaData implMetaData, DatastoreIdentifier implIdentifier, boolean embedded, int fieldRole)
          Method to generate an identifier name for reference field, based on the metadata for the field, and the ClassMetaData for the implementation.
 DatastoreIdentifier newVersionFieldIdentifier()
          Method to return an identifier for a version datastore field.
 
Methods inherited from class org.datanucleus.store.mapped.identifier.AbstractIdentifierFactory
getDatastoreAdapter, getIdentifierCase, getIdentifierInAdapterCase, getIdentifierNamePartsFromName, getWordSeparator, newCandidateKeyIdentifier, newDatastoreContainerIdentifier, newDatastoreFieldIdentifier, newDatastoreFieldIdentifier, newForeignKeyIdentifier, newIdentifier, newIdentifier, newIndexIdentifier, newPrimaryKeyIdentifier, newSequenceIdentifier, setCatalogSchemaForTable, truncate
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

JPAIdentifierFactory

public JPAIdentifierFactory(DatastoreAdapter dba,
                            ClassLoaderResolver clr,
                            java.util.Map props)
Constructor. The properties accepted are

Parameters:
dba - Datastore adapter
clr - ClassLoader resolver
props - Any properties controlling identifier generation
Method Detail

newDatastoreContainerIdentifier

public DatastoreIdentifier newDatastoreContainerIdentifier(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

newDatastoreContainerIdentifier

public DatastoreIdentifier newDatastoreContainerIdentifier(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(AbstractMemberMetaData refMetaData,
                                                       AbstractClassMetaData implMetaData,
                                                       DatastoreIdentifier implIdentifier,
                                                       boolean embedded,
                                                       int 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 field
implMetaData - the AbstractClassMetaData for this implementation
implIdentifier - PK identifier for the implementation
embedded - Whether the identifier is for a field embedded
fieldRole - The role to be performed by this column e.g FK, collection element ?
Returns:
The DatastoreIdentifier

newJoinTableFieldIdentifier

public DatastoreIdentifier newJoinTableFieldIdentifier(AbstractMemberMetaData ownerFmd,
                                                       AbstractMemberMetaData relatedFmd,
                                                       DatastoreIdentifier destinationId,
                                                       boolean embedded,
                                                       int 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 field
destinationId - Identifier for the identity field of the destination (if FK)
embedded - Whether the identifier is for a field embedded
fieldRole - 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(AbstractMemberMetaData ownerFmd,
                                                        AbstractMemberMetaData relatedFmd,
                                                        DatastoreIdentifier destinationId,
                                                        boolean embedded,
                                                        int 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 field
relatedFmd - MetaData for the related field
destinationId - Identifier for the identity field of the destination table (if strict FK)
embedded - Whether the identifier is for a field embedded
fieldRole - 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 datastore field.

Returns:
The version datastore field identifier

newIndexFieldIdentifier

public DatastoreIdentifier newIndexFieldIdentifier(AbstractMemberMetaData mmd)
Method to return an identifier for an index (ordering) datastore field.

Parameters:
mmd - MetaData for the field/property
Returns:
The index datastore field identifier

newAdapterIndexFieldIdentifier

public DatastoreIdentifier newAdapterIndexFieldIdentifier()
Method to return an identifier for an adapter index datastore field. 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 datastore field identifier

generateIdentifierNameForJavaName

public java.lang.String generateIdentifierNameForJavaName(java.lang.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 class AbstractIdentifierFactory
Parameters:
javaName - the Java identifier.
Returns:
The datastore identifier

getColumnIdentifierSuffix

protected java.lang.String getColumnIdentifierSuffix(int role,
                                                     boolean embedded)
Accessor for the suffix to add to any column identifier, based on the role type.

Specified by:
getColumnIdentifierSuffix in class AbstractIdentifierFactory
Parameters:
role - Datastore field role
embedded - Whether the DatastoreField is stored embedded
Returns:
The suffix (e.g _ID for id columns).


Copyright © 2011. All Rights Reserved.