org.datanucleus.store.mapped.identifier
Class AbstractIdentifierFactory

java.lang.Object
  extended by org.datanucleus.store.mapped.identifier.AbstractIdentifierFactory
All Implemented Interfaces:
IdentifierFactory
Direct Known Subclasses:
DNIdentifierFactory, JPAIdentifierFactory

public abstract class AbstractIdentifierFactory
extends java.lang.Object
implements IdentifierFactory

Abstract representation of an identifier factory for ORM datastores. To be extended to generate the identifiers.


Field Summary
protected  java.util.Map<java.lang.String,DatastoreIdentifier> candidates
           
static int CASE_LOWER
           
static int CASE_PRESERVE
           
static int CASE_UPPER
           
protected  ClassLoaderResolver clr
          Resolver for any class loading.
protected  java.util.Map<java.lang.String,DatastoreIdentifier> columns
           
protected  DatastoreAdapter dba
          Adapter for the datastore.
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.util.Map<java.lang.String,DatastoreIdentifier> foreignkeys
           
protected  IdentifierCase identifierCase
          Case to use for identifiers.
protected  java.util.Map<java.lang.String,DatastoreIdentifier> indexes
           
protected static Localiser LOCALISER
          Localiser for messages.
protected  java.util.Map<java.lang.String,DatastoreIdentifier> primarykeys
           
protected  java.lang.String quoteString
           
protected  DatastoreAdapter rdba
          Convenience RDBMSAdapter variable to save casting.
protected  java.util.Map<java.lang.String,DatastoreIdentifier> references
           
protected  java.util.Map<java.lang.String,DatastoreIdentifier> sequences
           
protected  java.util.Map<java.lang.String,DatastoreIdentifier> tables
           
protected  java.lang.String wordSeparator
          Separator to use for words in the identifiers.
 
Constructor Summary
AbstractIdentifierFactory(DatastoreAdapter dba, ClassLoaderResolver clr, java.util.Map props)
          Constructor.
 
Method Summary
protected abstract  java.lang.String generateIdentifierNameForJavaName(java.lang.String javaName)
          Generate a datastore identifier from a Java identifier.
protected abstract  java.lang.String getColumnIdentifierSuffix(int role, boolean embedded)
          Accessor for the suffix to add to any column identifier, based on the role type.
 DatastoreAdapter getDatastoreAdapter()
          Accessor for the datastore adapter that we are creating identifiers for.
 IdentifierCase getIdentifierCase()
          Accessor for the identifier case being used.
 java.lang.String getIdentifierInAdapterCase(java.lang.String identifier)
          Convenience method to convert the passed identifier into an identifier in the correct case, and with any required quoting for the datastore adapter.
protected  java.lang.String[] getIdentifierNamePartsFromName(java.lang.String name)
          Convenience method to split a fully-specified identifier name (inc catalog/schema) into its constituent parts.
 java.lang.String getWordSeparator()
          Accessor for the word separator for identifiers.
 DatastoreIdentifier newCandidateKeyIdentifier(DatastoreContainerObject table, int seq)
          Method to generate an identifier for a candidate key in the supplied table.
 DatastoreIdentifier newDatastoreContainerIdentifier(java.lang.String identifierName)
          Method to use to generate an identifier for a datastore field.
 DatastoreIdentifier newDatastoreFieldIdentifier(java.lang.String identifierName)
          Method to use to generate an identifier for a datastore field.
 DatastoreIdentifier newDatastoreFieldIdentifier(java.lang.String javaName, boolean embedded, int fieldRole)
          Method to create an identifier for a datastore field where we want the name based on the supplied java name, and the field has a particular role (and so could have its naming set according to the role).
 DatastoreIdentifier newForeignKeyIdentifier(DatastoreContainerObject table, int seq)
          Method to create a new identifier for a foreign key in the supplied table.
 DatastoreIdentifier newIdentifier(DatastoreIdentifier identifier, java.lang.String suffix)
          Method to return a new Identifier based on the passed identifier, but adding on the passed suffix
 DatastoreIdentifier newIdentifier(IdentifierType identifierType, java.lang.String name)
          Method to generate an identifier based on the supplied name for the requested type of identifier.
 DatastoreIdentifier newIndexIdentifier(DatastoreContainerObject table, boolean isUnique, int seq)
          Method to create an identifier for an Index in the supplied table.
 DatastoreIdentifier newPrimaryKeyIdentifier(DatastoreContainerObject table)
          Method to generate an identifier for a primary key for the supplied table.
 DatastoreIdentifier newSequenceIdentifier(java.lang.String sequenceName)
          Method to generate an identifier for a sequence using the passed name.
protected  void setCatalogSchemaForTable(org.datanucleus.store.mapped.identifier.TableIdentifier identifier)
          Convenience method to set the catalog/schema on the passed TableIdentifier.
protected  java.lang.String truncate(java.lang.String identifier, int length)
          Method to truncate an identifier to fit within the specified identifier length.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.datanucleus.store.mapped.IdentifierFactory
newAdapterIndexFieldIdentifier, newDatastoreContainerIdentifier, newDatastoreContainerIdentifier, newDiscriminatorFieldIdentifier, newForeignKeyFieldIdentifier, newIndexFieldIdentifier, newJoinTableFieldIdentifier, newReferenceFieldIdentifier, newVersionFieldIdentifier
 

Field Detail

LOCALISER

protected static final Localiser LOCALISER
Localiser for messages.


CASE_PRESERVE

public static final int CASE_PRESERVE
See Also:
Constant Field Values

CASE_UPPER

public static final int CASE_UPPER
See Also:
Constant Field Values

CASE_LOWER

public static final int CASE_LOWER
See Also:
Constant Field Values

dba

protected DatastoreAdapter dba
Adapter for the datastore.


clr

protected ClassLoaderResolver clr
Resolver for any class loading.


identifierCase

protected IdentifierCase identifierCase
Case to use for identifiers.


quoteString

protected java.lang.String quoteString

tables

protected java.util.Map<java.lang.String,DatastoreIdentifier> tables

columns

protected java.util.Map<java.lang.String,DatastoreIdentifier> columns

foreignkeys

protected java.util.Map<java.lang.String,DatastoreIdentifier> foreignkeys

indexes

protected java.util.Map<java.lang.String,DatastoreIdentifier> indexes

candidates

protected java.util.Map<java.lang.String,DatastoreIdentifier> candidates

primarykeys

protected java.util.Map<java.lang.String,DatastoreIdentifier> primarykeys

sequences

protected java.util.Map<java.lang.String,DatastoreIdentifier> sequences

references

protected java.util.Map<java.lang.String,DatastoreIdentifier> references

wordSeparator

protected java.lang.String wordSeparator
Separator to use for words in the identifiers.


rdba

protected DatastoreAdapter rdba
Convenience RDBMSAdapter variable to save casting.


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

AbstractIdentifierFactory

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

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

getDatastoreAdapter

public DatastoreAdapter getDatastoreAdapter()
Accessor for the datastore adapter that we are creating identifiers for.

Specified by:
getDatastoreAdapter in interface IdentifierFactory
Returns:
The datastore adapter

getIdentifierCase

public IdentifierCase getIdentifierCase()
Accessor for the identifier case being used.

Specified by:
getIdentifierCase in interface IdentifierFactory
Returns:
The identifier case

truncate

protected java.lang.String truncate(java.lang.String identifier,
                                    int length)
Method to truncate an identifier to fit within the specified identifier length. If truncation is necessary will use a 4 char hashcode (defined by HASH_LENGTH) (at the end) to attempt to create uniqueness.

Parameters:
identifier - The identifier
length - The (max) length to use
Returns:
The truncated identifier.

getWordSeparator

public java.lang.String getWordSeparator()
Accessor for the word separator for identifiers.

Returns:
The word separator

getIdentifierInAdapterCase

public java.lang.String getIdentifierInAdapterCase(java.lang.String identifier)
Convenience method to convert the passed identifier into an identifier in the correct case, and with any required quoting for the datastore adapter. If the identifier is already quoted and needs quotes then none are added.

Specified by:
getIdentifierInAdapterCase in interface IdentifierFactory
Parameters:
identifier - The identifier
Returns:
The updated identifier in the correct case

newIdentifier

public DatastoreIdentifier newIdentifier(IdentifierType identifierType,
                                         java.lang.String name)
Method to generate an identifier based on the supplied name for the requested type of identifier.

Specified by:
newIdentifier in interface IdentifierFactory
Parameters:
identifierType - the type of identifier to be created
name - The Java or SQL identifier name
Returns:
The DatastoreIdentifier

newIdentifier

public DatastoreIdentifier newIdentifier(DatastoreIdentifier identifier,
                                         java.lang.String suffix)
Method to return a new Identifier based on the passed identifier, but adding on the passed suffix

Specified by:
newIdentifier in interface IdentifierFactory
Parameters:
identifier - The current identifier
suffix - The suffix
Returns:
The new identifier

newDatastoreContainerIdentifier

public DatastoreIdentifier newDatastoreContainerIdentifier(java.lang.String identifierName)
Method to use to generate an identifier for a datastore field. The passed name will not be changed (other than in its case) although it may be truncated to fit the maximum length permitted for a datastore field identifier.

Specified by:
newDatastoreContainerIdentifier in interface IdentifierFactory
Parameters:
identifierName - The identifier name
Returns:
The DatastoreIdentifier for the table

newDatastoreFieldIdentifier

public DatastoreIdentifier newDatastoreFieldIdentifier(java.lang.String identifierName)
Method to use to generate an identifier for a datastore field. The passed name will not be changed (other than in its case) although it may be truncated to fit the maximum length permitted for a datastore field identifier.

Specified by:
newDatastoreFieldIdentifier in interface IdentifierFactory
Parameters:
identifierName - The identifier name
Returns:
The DatastoreIdentifier

newDatastoreFieldIdentifier

public DatastoreIdentifier newDatastoreFieldIdentifier(java.lang.String javaName,
                                                       boolean embedded,
                                                       int fieldRole)
Method to create an identifier for a datastore field where we want the name based on the supplied java name, and the field has a particular role (and so could have its naming set according to the role).

Specified by:
newDatastoreFieldIdentifier in interface IdentifierFactory
Parameters:
javaName - The java field name
embedded - Whether the identifier is for a field embedded
fieldRole - The role to be performed by this column e.g FK, Index ?
Returns:
The DatastoreIdentifier

newSequenceIdentifier

public DatastoreIdentifier newSequenceIdentifier(java.lang.String sequenceName)
Method to generate an identifier for a sequence using the passed name.

Specified by:
newSequenceIdentifier in interface IdentifierFactory
Parameters:
sequenceName - the name of the sequence to use
Returns:
The DatastoreIdentifier

newPrimaryKeyIdentifier

public DatastoreIdentifier newPrimaryKeyIdentifier(DatastoreContainerObject table)
Method to generate an identifier for a primary key for the supplied table.

Specified by:
newPrimaryKeyIdentifier in interface IdentifierFactory
Parameters:
table - the table
Returns:
The DatastoreIdentifier

newCandidateKeyIdentifier

public DatastoreIdentifier newCandidateKeyIdentifier(DatastoreContainerObject table,
                                                     int seq)
Method to generate an identifier for a candidate key in the supplied table.

Specified by:
newCandidateKeyIdentifier in interface IdentifierFactory
Parameters:
table - the table
seq - the sequential number
Returns:
The DatastoreIdentifier

newForeignKeyIdentifier

public DatastoreIdentifier newForeignKeyIdentifier(DatastoreContainerObject table,
                                                   int seq)
Method to create a new identifier for a foreign key in the supplied table.

Specified by:
newForeignKeyIdentifier in interface IdentifierFactory
Parameters:
table - the table
seq - the sequential number
Returns:
The DatastoreIdentifier

newIndexIdentifier

public DatastoreIdentifier newIndexIdentifier(DatastoreContainerObject table,
                                              boolean isUnique,
                                              int seq)
Method to create an identifier for an Index in the supplied table.

Specified by:
newIndexIdentifier in interface IdentifierFactory
Parameters:
table - the table
isUnique - if the index is unique
seq - the sequential number
Returns:
The DatastoreIdentifier

getColumnIdentifierSuffix

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

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

generateIdentifierNameForJavaName

protected abstract java.lang.String generateIdentifierNameForJavaName(java.lang.String javaName)
Generate a datastore identifier from a Java identifier. Embodies the naming rules for the factory.

Parameters:
javaName - the Java identifier.
Returns:
The datastore identifier

setCatalogSchemaForTable

protected void setCatalogSchemaForTable(org.datanucleus.store.mapped.identifier.TableIdentifier identifier)
Convenience method to set the catalog/schema on the passed TableIdentifier.

Parameters:
identifier - The TableIdentifier

getIdentifierNamePartsFromName

protected java.lang.String[] getIdentifierNamePartsFromName(java.lang.String name)
Convenience method to split a fully-specified identifier name (inc catalog/schema) into its constituent parts. Returns a String array with 3 elements. The first is the catalog, second the schema, and third the identifier.

Parameters:
name - Name
Returns:
The parts


Copyright © 2011. All Rights Reserved.