Class DNIdentifierFactory

java.lang.Object
org.datanucleus.store.rdbms.identifier.AbstractIdentifierFactory
org.datanucleus.store.rdbms.identifier.DNIdentifierFactory
All Implemented Interfaces:
IdentifierFactory
Direct Known Subclasses:
DN2IdentifierFactory, JPOXIdentifierFactory

public class DNIdentifierFactory extends AbstractIdentifierFactory
Factory that creates immutable instances of DatastoreIdentifier for mapped datastores. Includes a "JPOX" naming strategy, naming as follows
  • Class called "MyClass" will generate table name of "MYCLASS"
  • Field called "myField" will generate column name of "MY_FIELD"
  • Datastore id field for class "MyClass" will have the PK field "MYCLASS_ID"
  • Join table will be named after the class and field, so "MyClass" with field "myField" will become a table with name "MYCLASS_MYFIELD".
  • Columns of a join table will be named after the PK fields of the owner and element. So something like "MYCLASS_ID_OID" and "MYELEMENT_ID_EID"
  • Discriminator field columns will, by default, be called "DISCRIMINATOR"
  • Index field columns will, by default, be called "INTEGER_IDX"
  • Version field columns will, by default, be called "OPT_VERSION"
  • Adapter index field columns will, by default, be called "ADPT_PK_IDX"
Strictly speaking the naming of the table is inconsistent with the naming of the column since the table doesn't use the word separator whereas the column does, but JPOX 1.0/1.1/1.2 were like this so provided for compatibility.
  • Field Details

    • tablePrefix

      protected String tablePrefix
      Prefix for all generated table names.
    • tableSuffix

      protected String tableSuffix
      Suffix for all generated table names.
  • Constructor Details

    • DNIdentifierFactory

      public DNIdentifierFactory(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)
      • WordSeparator : separator character(s) between identifier words
      • TablePrefix : Prefix to prepend to all table identifiers
      • TableSuffix : Suffix to append to all table identifiers
      Parameters:
      dba - Database adapter
      clr - ClassLoader resolver
      props - Any properties controlling identifier generation
  • Method Details

    • newTableIdentifier

      public DatastoreIdentifier newTableIdentifier(org.datanucleus.metadata.AbstractMemberMetaData mmd)
      Method to return a Table identifier for the join table of the specified field.
      Parameters:
      mmd - Meta data for the field
      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 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(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 field
      relatedFmd - MetaData for the related 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 ?
      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 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 owner, index ?
      Returns:
      The identifier
    • newDiscriminatorFieldIdentifier

      public DatastoreIdentifier newDiscriminatorFieldIdentifier()
      Method to return an identifier for a discriminator column. Returns an identifier "DISCRIMINATOR"
      Returns:
      The discriminator column identifier
    • newVersionFieldIdentifier

      public DatastoreIdentifier newVersionFieldIdentifier()
      Method to return an identifier for a version column.
      Returns:
      The version 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
    • 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 - not used here
      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 a word separator. 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 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 class AbstractIdentifierFactory
      Parameters:
      role - column role
      embedded - Whether the column is stored embedded
      Returns:
      The suffix (e.g _ID for id columns).