Class AbstractIdentifierFactory
- java.lang.Object
-
- org.datanucleus.store.rdbms.identifier.AbstractIdentifierFactory
-
- All Implemented Interfaces:
IdentifierFactory
- Direct Known Subclasses:
DNIdentifierFactory
,JPAIdentifierFactory
public abstract class AbstractIdentifierFactory extends Object implements IdentifierFactory
Abstract representation of an identifier factory for ORM datastores. To be extended to generate the identifiers.
-
-
Field Summary
Fields Modifier and Type Field Description protected Map<String,DatastoreIdentifier>
candidates
static int
CASE_LOWER
static int
CASE_PRESERVE
static int
CASE_UPPER
protected org.datanucleus.ClassLoaderResolver
clr
protected Map<String,DatastoreIdentifier>
columns
protected DatastoreAdapter
dba
protected String
defaultCatalogName
Default catalog name for any created identifiers.protected String
defaultSchemaName
Default schema name for any created identifiers.protected Map<String,DatastoreIdentifier>
foreignkeys
protected Map<String,DatastoreIdentifier>
indexes
protected org.datanucleus.store.schema.naming.NamingCase
namingCase
Case to use for identifiers.protected org.datanucleus.store.schema.naming.NamingFactory
namingFactory
protected Map<String,DatastoreIdentifier>
primarykeys
protected String
quoteString
protected Map<String,DatastoreIdentifier>
references
protected Map<String,DatastoreIdentifier>
sequences
protected Map<String,DatastoreIdentifier>
tables
protected String
wordSeparator
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
Constructors Constructor Description AbstractIdentifierFactory(DatastoreAdapter dba, org.datanucleus.ClassLoaderResolver clr, Map props)
Constructor.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description 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.DatastoreAdapter
getDatastoreAdapter()
Accessor for the datastore adapter that we are creating identifiers for.String
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[]
getIdentifierNamePartsFromName(String name)
Convenience method to split a fully-specified identifier name (inc catalog/schema) into its constituent parts.String
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
getNamingCase()
Accessor for the identifier case being used.String
getWordSeparator()
Accessor for the word separator for identifiers.DatastoreIdentifier
newCandidateKeyIdentifier(Table table, int seq)
Method to generate an identifier for a candidate key in the supplied table.DatastoreIdentifier
newColumnIdentifier(String identifierName)
Method to use to generate an identifier for a column.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).DatastoreIdentifier
newForeignKeyIdentifier(Table table, int seq)
Method to create a new identifier for a foreign key in the supplied table.DatastoreIdentifier
newIdentifier(DatastoreIdentifier identifier, String suffix)
Method to return a new Identifier based on the passed identifier, but adding on the passed suffixDatastoreIdentifier
newIdentifier(IdentifierType identifierType, String name)
Method to generate an identifier based on the supplied name for the requested type of identifier.DatastoreIdentifier
newIndexIdentifier(Table table, boolean isUnique, int seq)
Method to create an identifier for an Index in the supplied table.DatastoreIdentifier
newPrimaryKeyIdentifier(Table table)
Method to generate an identifier for a primary key for the supplied table.DatastoreIdentifier
newSequenceIdentifier(String sequenceName)
Method to generate an identifier for a sequence using the passed name.DatastoreIdentifier
newTableIdentifier(String identifierName)
Method to use to generate an identifier for a column in the default catalog/schema.DatastoreIdentifier
newTableIdentifier(String identifierName, String catalogName, String schemaName)
Method to use to generate an identifier for a column.protected void
setCatalogSchemaForTable(org.datanucleus.store.rdbms.identifier.TableIdentifier identifier)
Convenience method to set the catalog/schema on the passed TableIdentifier.protected String
truncate(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.rdbms.identifier.IdentifierFactory
newAdapterIndexFieldIdentifier, newDiscriminatorFieldIdentifier, newForeignKeyFieldIdentifier, newIndexFieldIdentifier, newJoinTableFieldIdentifier, newReferenceFieldIdentifier, newTableIdentifier, newTableIdentifier, newVersionFieldIdentifier
-
-
-
-
Field Detail
-
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
-
namingFactory
protected org.datanucleus.store.schema.naming.NamingFactory namingFactory
-
dba
protected DatastoreAdapter dba
-
clr
protected org.datanucleus.ClassLoaderResolver clr
-
namingCase
protected org.datanucleus.store.schema.naming.NamingCase namingCase
Case to use for identifiers.
-
quoteString
protected String quoteString
-
wordSeparator
protected String wordSeparator
Separator to use for words in the identifiers.
-
tables
protected Map<String,DatastoreIdentifier> tables
-
columns
protected Map<String,DatastoreIdentifier> columns
-
foreignkeys
protected Map<String,DatastoreIdentifier> foreignkeys
-
indexes
protected Map<String,DatastoreIdentifier> indexes
-
candidates
protected Map<String,DatastoreIdentifier> candidates
-
primarykeys
protected Map<String,DatastoreIdentifier> primarykeys
-
sequences
protected Map<String,DatastoreIdentifier> sequences
-
references
protected Map<String,DatastoreIdentifier> references
-
defaultCatalogName
protected String defaultCatalogName
Default catalog name for any created identifiers.
-
defaultSchemaName
protected String defaultSchemaName
Default schema name for any created identifiers.
-
-
Constructor Detail
-
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 Detail
-
getDatastoreAdapter
public DatastoreAdapter 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
public String getWordSeparator()
Accessor for the word separator for identifiers.- Returns:
- The word separator
-
getIdentifierTruncatedToAdapterColumnLength
public String getIdentifierTruncatedToAdapterColumnLength(String identifier)
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
protected String truncate(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 byHASH_LENGTH
) (at the end) to attempt to create uniqueness.- Parameters:
identifier
- The identifierlength
- The (max) length to use- Returns:
- The truncated identifier.
-
getIdentifierInAdapterCase
public String 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. 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
public DatastoreIdentifier newIdentifier(IdentifierType identifierType, String name)
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
public DatastoreIdentifier newIdentifier(DatastoreIdentifier identifier, String suffix)
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
public DatastoreIdentifier newTableIdentifier(String identifierName)
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
public DatastoreIdentifier newColumnIdentifier(String identifierName)
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
public DatastoreIdentifier newSequenceIdentifier(String sequenceName)
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
public DatastoreIdentifier newPrimaryKeyIdentifier(Table table)
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
public DatastoreIdentifier newCandidateKeyIdentifier(Table table, int seq)
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
public DatastoreIdentifier newForeignKeyIdentifier(Table table, int seq)
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
public DatastoreIdentifier newIndexIdentifier(Table table, boolean isUnique, int seq)
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
protected abstract String generateIdentifierNameForJavaName(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.rdbms.identifier.TableIdentifier identifier)
Convenience method to set the catalog/schema on the passed TableIdentifier.- Parameters:
identifier
- The TableIdentifier
-
getIdentifierNamePartsFromName
protected String[] getIdentifierNamePartsFromName(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
-
-