org.jpox.store.rdbms.sqlidentifier
Class JPOXIdentifierFactory

java.lang.Object
  extended by org.jpox.store.AbstractIdentifierFactory
      extended by org.jpox.store.rdbms.sqlidentifier.AbstractRDBMSIdentifierFactory
          extended by org.jpox.store.rdbms.sqlidentifier.JPOXIdentifierFactory
All Implemented Interfaces:
IdentifierFactory, RDBMSIdentifierFactory
Direct Known Subclasses:
JPOX2IdentifierFactory

public class JPOXIdentifierFactory
extends AbstractRDBMSIdentifierFactory

Factory that creates immutable instances of DatastoreIdentifier for RDBMS datastores. Includes a JPOX naming strategy, naming as follows

Strictly speaking the naming of the table is inconsistent with the naming of the column since the table doesnt use the word separator whereas the column does, but JPOX has been like this for some time so we cant just change the default like that - an option needs adding to allow backwards compatibility.

Version:
$Revision: 1.30.2.1 $

Field Summary
protected  java.lang.String defaultCatalogName
          Default catalog name for any created identifiers.
protected  java.lang.String defaultSchemaName
          Default schema name for any created identifiers.
protected  java.lang.String tablePrefix
          Prefix for all generated table names.
protected  java.lang.String tableSuffix
          Suffix for all generated table names.
 
Fields inherited from class org.jpox.store.rdbms.sqlidentifier.AbstractRDBMSIdentifierFactory
candidates, columns, foreignkeys, indexes, primarykeys, rdba, references, sequences, tables, wordSeparator
 
Fields inherited from class org.jpox.store.AbstractIdentifierFactory
CASE_LOWER, CASE_PRESERVE, CASE_UPPER, dba, identifierCase, LOCALISER
 
Fields inherited from interface org.jpox.store.IdentifierFactory
CANDIDATE_KEY, COLUMN, FOREIGN_KEY, IDENTIFIER_LOWER_CASE, IDENTIFIER_LOWER_CASE_QUOTED, IDENTIFIER_MIXED_CASE, IDENTIFIER_MIXED_CASE_QUOTED, IDENTIFIER_UPPER_CASE, IDENTIFIER_UPPER_CASE_QUOTED, INDEX, PRIMARY_KEY, SEQUENCE, TABLE
 
Constructor Summary
JPOXIdentifierFactory(DatastoreAdapter dba, java.lang.String defaultCatalog, java.lang.String defaultSchema, java.lang.String requiredCase, java.lang.String wordSeparator, java.lang.String tablePrefix, java.lang.String tableSuffix)
          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(ClassLoaderResolver clr, AbstractClassMetaData cmd)
          Method to return a Table identifier for the specified class.
 DatastoreIdentifier newDatastoreContainerIdentifier(ClassLoaderResolver clr, AbstractPropertyMetaData fmd)
          Method to return a Table identifier for the join table of the specified field.
 DatastoreIdentifier newDiscriminatorFieldIdentifier()
          Method to return an identifier for a discriminator column.
 DatastoreIdentifier newForeignKeyFieldIdentifier(AbstractPropertyMetaData ownerFmd, AbstractPropertyMetaData relatedFmd, DatastoreIdentifier destinationId, boolean embedded, int fieldRole)
          Method to generate a FK/FK-index field identifier.
 DatastoreIdentifier newIndexFieldIdentifier()
          Method to return an identifier for an index datastore field.
 DatastoreIdentifier newJoinTableFieldIdentifier(AbstractPropertyMetaData ownerFmd, AbstractPropertyMetaData relatedFmd, DatastoreIdentifier destinationId, boolean embedded, int fieldRole)
          Method to generate a join-table identifier.
 DatastoreIdentifier newReferenceFieldIdentifier(AbstractPropertyMetaData 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.jpox.store.rdbms.sqlidentifier.AbstractRDBMSIdentifierFactory
getIdentifierInAdapterCase, getIdentifierNamePartsFromName, getMaxLengthForIdentifierType, getWordSeparator, newCandidateKeyIdentifier, newDatastoreContainerIdentifier, newDatastoreFieldIdentifier, newDatastoreFieldIdentifier, newForeignKeyIdentifier, newIdentifier, newIdentifier, newIndexIdentifier, newPrimaryKeyIdentifier, newSequenceIdentifier, setCatalogSchemaForTable
 
Methods inherited from class org.jpox.store.AbstractIdentifierFactory
getDatastoreAdapter, getIdentifierCase, getNameOfIdentifierCase, truncate
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.jpox.store.IdentifierFactory
getDatastoreAdapter, getIdentifierCase, getNameOfIdentifierCase
 

Field Detail

tablePrefix

protected java.lang.String tablePrefix
Prefix for all generated table names.


tableSuffix

protected java.lang.String tableSuffix
Suffix for all generated table names.


defaultCatalogName

protected java.lang.String defaultCatalogName
Default catalog name for any created identifiers.


defaultSchemaName

protected java.lang.String defaultSchemaName
Default schema name for any created identifiers.

Constructor Detail

JPOXIdentifierFactory

public JPOXIdentifierFactory(DatastoreAdapter dba,
                             java.lang.String defaultCatalog,
                             java.lang.String defaultSchema,
                             java.lang.String requiredCase,
                             java.lang.String wordSeparator,
                             java.lang.String tablePrefix,
                             java.lang.String tableSuffix)
Constructor. TODO Allow specification of multiple properties in PMF to control the id generation and just pass in a Properties into here

Parameters:
dba - Datastore adapter
defaultCatalog - Name of the default catalog (if any)
defaultSchema - Name of the default schema (if any)
requiredCase - The case the user requires
wordSeparator - Word separator for identifiers
tablePrefix - Prefix for table names when being generated
tableSuffix - Suffix for table names when being generated
Method Detail

newDatastoreContainerIdentifier

public DatastoreIdentifier newDatastoreContainerIdentifier(ClassLoaderResolver clr,
                                                           AbstractPropertyMetaData fmd)
Method to return a Table identifier for the join table of the specified field.

Parameters:
clr - the ClassLoaderResolver
fmd - Meta data for the field
Returns:
The identifier for the table

newDatastoreContainerIdentifier

public DatastoreIdentifier newDatastoreContainerIdentifier(ClassLoaderResolver clr,
                                                           AbstractClassMetaData cmd)
Method to return a Table identifier for the specified class.

Parameters:
clr - the ClassLoaderResolver
cmd - Meta data for the class
Returns:
The identifier for the table

newReferenceFieldIdentifier

public DatastoreIdentifier newReferenceFieldIdentifier(AbstractPropertyMetaData 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 AbstractPropertyMetaData 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(AbstractPropertyMetaData ownerFmd,
                                                       AbstractPropertyMetaData 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
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(AbstractPropertyMetaData ownerFmd,
                                                        AbstractPropertyMetaData 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 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 datastore field.

Returns:
The version 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

newIndexFieldIdentifier

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

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 a word separator. Words are identified by a leading upper-case character. Any leading or trailing underscores are removed.

Specified by:
generateIdentifierNameForJavaName in class AbstractRDBMSIdentifierFactory
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 AbstractRDBMSIdentifierFactory
Parameters:
role - Datastore field role
embedded - Whether the DatastoreField is stored embedded
Returns:
The suffix (e.g _ID for id columns).


Copyright © -2008 . All Rights Reserved.