Class AbstractIdentifierFactory
java.lang.Object
org.datanucleus.store.rdbms.identifier.AbstractIdentifierFactory
- All Implemented Interfaces:
IdentifierFactory
- Direct Known Subclasses:
DNIdentifierFactory, JPAIdentifierFactory
Abstract representation of an identifier factory for ORM datastores.
To be extended to generate the identifiers.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected Map<String, DatastoreIdentifier> static final intstatic final intstatic final intprotected org.datanucleus.ClassLoaderResolverprotected Map<String, DatastoreIdentifier> protected DatastoreAdapterprotected StringDefault catalog name for any created identifiers.protected StringDefault schema name for any created identifiers.protected Map<String, DatastoreIdentifier> private static final intThe number of characters used to build the hash.private static final intRange to use for creating hashed ending when truncating identifiers.protected Map<String, DatastoreIdentifier> protected org.datanucleus.store.schema.naming.NamingCaseCase to use for identifiers.protected org.datanucleus.store.schema.naming.NamingFactoryprotected Map<String, DatastoreIdentifier> protected Stringprotected Map<String, DatastoreIdentifier> protected Map<String, DatastoreIdentifier> protected Map<String, DatastoreIdentifier> protected StringSeparator to use for words in the identifiers.Fields inherited from interface IdentifierFactory
PROPERTY_DEFAULT_CATALOG, PROPERTY_DEFAULT_SCHEMA, PROPERTY_NAMING_FACTORY, PROPERTY_REQUIRED_CASE, PROPERTY_TABLE_PREFIX, PROPERTY_TABLE_SUFFIX, PROPERTY_WORD_SEPARATOR -
Constructor Summary
ConstructorsConstructorDescriptionAbstractIdentifierFactory(DatastoreAdapter dba, org.datanucleus.ClassLoaderResolver clr, Map props) Constructor. -
Method Summary
Modifier and TypeMethodDescriptionprivate static final intprotected abstract StringgenerateIdentifierNameForJavaName(String javaName) Generate a datastore identifier from a Java identifier.protected abstract StringgetColumnIdentifierSuffix(org.datanucleus.metadata.FieldRole role, boolean embedded) Accessor for the suffix to add to any column identifier, based on the role type.Accessor for the datastore adapter that we are creating identifiers for.getIdentifierInAdapterCase(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 String[]Convenience method to split a fully-specified identifier name (inc catalog/schema) into its constituent parts.getIdentifierTruncatedToAdapterColumnLength(String identifier) Method to truncate the provided identifier as required to the datastore adapter column length (if required)org.datanucleus.store.schema.naming.NamingCaseAccessor for the identifier case being used.Accessor for the word separator for identifiers.newCandidateKeyIdentifier(Table table, int seq) Method to generate an identifier for a candidate key in the supplied table.newColumnIdentifier(String identifierName) Method to use to generate an identifier for a column.newColumnIdentifier(String javaName, boolean embedded, org.datanucleus.metadata.FieldRole fieldRole, boolean custom) Method to create an identifier for a column 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).newForeignKeyIdentifier(Table table, int seq) Method to create a new identifier for a foreign key in the supplied table.newIdentifier(DatastoreIdentifier identifier, String suffix) Method to return a new Identifier based on the passed identifier, but adding on the passed suffixnewIdentifier(IdentifierType identifierType, String name) Method to generate an identifier based on the supplied name for the requested type of identifier.newIndexIdentifier(Table table, boolean isUnique, int seq) Method to create an identifier for an Index in the supplied table.newPrimaryKeyIdentifier(Table table) Method to generate an identifier for a primary key for the supplied table.newSequenceIdentifier(String sequenceName) Method to generate an identifier for a sequence using the passed name.newTableIdentifier(String identifierName) Method to use to generate an identifier for a column in the default catalog/schema.newTableIdentifier(String identifierName, String catalogName, String schemaName) Method to use to generate an identifier for a column.protected voidsetCatalogSchemaForTable(TableIdentifier identifier) Convenience method to set the catalog/schema on the passed TableIdentifier.protected StringMethod to truncate an identifier to fit within the specified identifier length.
-
Field Details
-
CASE_PRESERVE
public static final int CASE_PRESERVE- See Also:
-
CASE_UPPER
public static final int CASE_UPPER- See Also:
-
CASE_LOWER
public static final int CASE_LOWER- See Also:
-
HASH_LENGTH
private static final int HASH_LENGTHThe number of characters used to build the hash.- See Also:
-
HASH_RANGE
private static final int HASH_RANGERange to use for creating hashed ending when truncating identifiers. The actual hashes have a value between 0 andHASH_RANGE- 1. -
namingFactory
protected org.datanucleus.store.schema.naming.NamingFactory namingFactory -
dba
-
clr
protected org.datanucleus.ClassLoaderResolver clr -
namingCase
protected org.datanucleus.store.schema.naming.NamingCase namingCaseCase to use for identifiers. -
quoteString
-
wordSeparator
Separator to use for words in the identifiers. -
tables
-
columns
-
foreignkeys
-
indexes
-
candidates
-
-
sequences
-
references
-
defaultCatalogName
Default catalog name for any created identifiers. -
defaultSchemaName
Default schema name for any created identifiers.
-
-
Constructor Details
-
AbstractIdentifierFactory
public AbstractIdentifierFactory(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- Database adapterclr- ClassLoader resolverprops- Any properties controlling identifier generation
-
-
Method Details
-
calculateHashMax
private static final int calculateHashMax() -
getDatastoreAdapter
Accessor for the datastore adapter that we are creating identifiers for.- Specified by:
getDatastoreAdapterin interfaceIdentifierFactory- Returns:
- The datastore adapter
-
getNamingCase
public org.datanucleus.store.schema.naming.NamingCase getNamingCase()Accessor for the identifier case being used.- Specified by:
getNamingCasein interfaceIdentifierFactory- Returns:
- The identifier case
-
getWordSeparator
Accessor for the word separator for identifiers.- Returns:
- The word separator
-
getIdentifierTruncatedToAdapterColumnLength
Description copied from interface:IdentifierFactoryMethod to truncate the provided identifier as required to the datastore adapter column length (if required)- Specified by:
getIdentifierTruncatedToAdapterColumnLengthin interfaceIdentifierFactory- Parameters:
identifier- The identifier- Returns:
- The truncated variant (if the length was longer than the max column identifier length);
-
truncate
Method to truncate an identifier to fit within the specified identifier length. If truncation is necessary will use a 4 char hashcode (defined byHASH_LENGTH) (at the end) to attempt to create uniqueness.- Parameters:
identifier- The identifierlength- The (max) length to use- Returns:
- The truncated identifier.
-
getIdentifierInAdapterCase
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:
getIdentifierInAdapterCasein interfaceIdentifierFactory- Parameters:
identifier- The identifier- Returns:
- The updated identifier in the correct case
-
newIdentifier
Method to generate an identifier based on the supplied name for the requested type of identifier.- Specified by:
newIdentifierin interfaceIdentifierFactory- Parameters:
identifierType- the type of identifier to be createdname- The Java or SQL identifier name- Returns:
- The DatastoreIdentifier
-
newIdentifier
Method to return a new Identifier based on the passed identifier, but adding on the passed suffix- Specified by:
newIdentifierin interfaceIdentifierFactory- Parameters:
identifier- The current identifiersuffix- The suffix- Returns:
- The new identifier
-
newTableIdentifier
Method to use to generate an identifier for a column in the default catalog/schema. 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 column identifier.- Specified by:
newTableIdentifierin interfaceIdentifierFactory- Parameters:
identifierName- The identifier name- Returns:
- The DatastoreIdentifier for the table
-
newTableIdentifier
public DatastoreIdentifier newTableIdentifier(String identifierName, String catalogName, String schemaName) Method to use to generate an identifier for a column. 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 column identifier.- Specified by:
newTableIdentifierin interfaceIdentifierFactory- Parameters:
identifierName- The identifier name for the tablecatalogName- Optional catalog name (null means not set)schemaName- Optional schema name (null means not set)- Returns:
- The DatastoreIdentifier for the table
-
newColumnIdentifier
Method to use to generate an identifier for a column. 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 column identifier.- Specified by:
newColumnIdentifierin interfaceIdentifierFactory- Parameters:
identifierName- The identifier name- Returns:
- The DatastoreIdentifier
-
newColumnIdentifier
public DatastoreIdentifier newColumnIdentifier(String javaName, boolean embedded, org.datanucleus.metadata.FieldRole fieldRole, boolean custom) Method to create an identifier for a column 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:
newColumnIdentifierin interfaceIdentifierFactory- Parameters:
javaName- The java field nameembedded- Whether the identifier is for a field embeddedfieldRole- The role to be performed by this column e.g FK, Index ?custom- Whether this has a user-defined name- Returns:
- The DatastoreIdentifier
-
newSequenceIdentifier
Method to generate an identifier for a sequence using the passed name.- Specified by:
newSequenceIdentifierin interfaceIdentifierFactory- Parameters:
sequenceName- the name of the sequence to use- Returns:
- The DatastoreIdentifier
-
newPrimaryKeyIdentifier
Method to generate an identifier for a primary key for the supplied table.- Specified by:
newPrimaryKeyIdentifierin interfaceIdentifierFactory- Parameters:
table- the table- Returns:
- The DatastoreIdentifier
-
newCandidateKeyIdentifier
Method to generate an identifier for a candidate key in the supplied table.- Specified by:
newCandidateKeyIdentifierin interfaceIdentifierFactory- Parameters:
table- the tableseq- the sequential number- Returns:
- The DatastoreIdentifier
-
newForeignKeyIdentifier
Method to create a new identifier for a foreign key in the supplied table.- Specified by:
newForeignKeyIdentifierin interfaceIdentifierFactory- Parameters:
table- the tableseq- the sequential number- Returns:
- The DatastoreIdentifier
-
newIndexIdentifier
Method to create an identifier for an Index in the supplied table.- Specified by:
newIndexIdentifierin interfaceIdentifierFactory- Parameters:
table- the tableisUnique- if the index is uniqueseq- the sequential number- Returns:
- The DatastoreIdentifier
-
getColumnIdentifierSuffix
protected abstract String getColumnIdentifierSuffix(org.datanucleus.metadata.FieldRole role, boolean embedded) Accessor for the suffix to add to any column identifier, based on the role type.- Parameters:
role- column roleembedded- Whether the column is stored embedded- Returns:
- The suffix (e.g _ID for id columns).
-
generateIdentifierNameForJavaName
-
setCatalogSchemaForTable
Convenience method to set the catalog/schema on the passed TableIdentifier.- Parameters:
identifier- The TableIdentifier
-
getIdentifierNamePartsFromName
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
-