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 int
static final int
static final int
protected org.datanucleus.ClassLoaderResolver
protected Map
<String, DatastoreIdentifier> protected DatastoreAdapter
protected String
Default catalog name for any created identifiers.protected String
Default schema name for any created identifiers.protected Map
<String, DatastoreIdentifier> private static final int
The number of characters used to build the hash.private static final int
Range to use for creating hashed ending when truncating identifiers.protected Map
<String, DatastoreIdentifier> protected org.datanucleus.store.schema.naming.NamingCase
Case to use for identifiers.protected org.datanucleus.store.schema.naming.NamingFactory
protected Map
<String, DatastoreIdentifier> protected String
protected Map
<String, DatastoreIdentifier> protected Map
<String, DatastoreIdentifier> protected Map
<String, DatastoreIdentifier> protected String
Separator to use for words in the identifiers.Fields inherited from interface org.datanucleus.store.rdbms.identifier.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 int
protected abstract String
generateIdentifierNameForJavaName
(String javaName) Generate a datastore identifier from a Java identifier.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.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.NamingCase
Accessor 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 void
setCatalogSchemaForTable
(TableIdentifier identifier) Convenience method to set the catalog/schema on the passed TableIdentifier.protected String
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.rdbms.identifier.IdentifierFactory
newAdapterIndexFieldIdentifier, newDiscriminatorFieldIdentifier, newForeignKeyFieldIdentifier, newIndexFieldIdentifier, newJoinTableFieldIdentifier, newReferenceFieldIdentifier, newTableIdentifier, newTableIdentifier, newVersionFieldIdentifier
-
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:
getDatastoreAdapter
in interfaceIdentifierFactory
- Returns:
- The datastore adapter
-
getNamingCase
public org.datanucleus.store.schema.naming.NamingCase getNamingCase()Accessor for the identifier case being used.- Specified by:
getNamingCase
in interfaceIdentifierFactory
- Returns:
- The identifier case
-
getWordSeparator
Accessor for the word separator for identifiers.- Returns:
- The word separator
-
getIdentifierTruncatedToAdapterColumnLength
Description copied from interface:IdentifierFactory
Method to truncate the provided identifier as required to the datastore adapter column length (if required)- Specified by:
getIdentifierTruncatedToAdapterColumnLength
in 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:
getIdentifierInAdapterCase
in 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:
newIdentifier
in 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:
newIdentifier
in 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:
newTableIdentifier
in 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:
newTableIdentifier
in 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:
newColumnIdentifier
in 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:
newColumnIdentifier
in 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:
newSequenceIdentifier
in 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:
newPrimaryKeyIdentifier
in interfaceIdentifierFactory
- Parameters:
table
- the table- Returns:
- The DatastoreIdentifier
-
newCandidateKeyIdentifier
Method to generate an identifier for a candidate key in the supplied table.- Specified by:
newCandidateKeyIdentifier
in 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:
newForeignKeyIdentifier
in 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:
newIndexIdentifier
in 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
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
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
-