Class AbstractNamingFactory
java.lang.Object
org.datanucleus.store.schema.naming.AbstractNamingFactory
- All Implemented Interfaces:
NamingFactory
- Direct Known Subclasses:
DN2NamingFactory
,JPANamingFactory
Abstract base for any naming factory, providing convenience facilities like truncation.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected ClassLoaderResolver
(package private) Map
<SchemaComponent, Integer> Map of max name length, keyed by the schema component typeprotected NamingCase
protected NucleusContext
protected String
Quote used when the identifier case selected requires it.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 String
Separator to use for words in the identifiers. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate static final int
getColumnName
(List<AbstractMemberMetaData> mmds, int colPosition) Method to return the name of the column for the position of the specified EMBEDDED field, within the specified owner field.getColumnName
(AbstractMemberMetaData mmd, ColumnType type) Method to return the name of the column for the specified field.getConstraintName
(String className, AbstractMemberMetaData mmd, ConstraintMetaData cnstrmd) Method to return the name of a constraint specified at member level.getConstraintName
(AbstractClassMetaData cmd, ConstraintMetaData cnstrmd, int position) Method to return the name of a constraint specified at class level.getConstraintName
(AbstractClassMetaData cmd, ConstraintMetaData cnstrmd, ColumnType type) Method to return the name of the constraint for the specified class (version, datastore-id, discriminator etc).protected int
protected String
getNameInRequiredCase
(String name) Convenience method to convert the passed name into a name in the required "case".getSequenceName
(SequenceMetaData seqmd) Method to return the name of sequence.Method to return the name of the table for the specified class.protected String
prepareIdentifierNameForUse
(String name, SchemaComponent cmpt) Convenience method that will truncate the provided name if it is longer than the longest possible for the specified schema component, and then convert it into the required case.setMaximumLength
(SchemaComponent cmpt, int max) Method to set the maximum length of the name of the specified schema component.setNamingCase
(NamingCase nameCase) Method to set the required case of the names.setQuoteString
(String quote) Method to set the quote string to use (when the identifiers need to be quoted).setReservedKeywords
(Set<String> keywords) Method to set the provided list of keywords as names that identifiers have to surround by quotes to use.setWordSeparator
(String sep) Method to set the word separator of the names.protected static String
Method to truncate a name to fit within the specified name 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.schema.naming.NamingFactory
getColumnName, getColumnName, getTableName
-
Field Details
-
reservedWords
-
wordSeparator
Separator to use for words in the identifiers. -
quoteString
Quote used when the identifier case selected requires it. -
namingCase
-
nucCtx
-
clr
-
maxLengthByComponent
Map<SchemaComponent,Integer> maxLengthByComponentMap of max name length, keyed by the schema component type -
TRUNCATE_HASH_LENGTH
private static final int TRUNCATE_HASH_LENGTHThe number of characters used to build the hash.- See Also:
-
TRUNCATE_HASH_RANGE
private static final int TRUNCATE_HASH_RANGERange to use for creating hashed ending when truncating identifiers. The actual hashes have a value between 0 andHASH_RANGE
- 1.
-
-
Constructor Details
-
AbstractNamingFactory
-
-
Method Details
-
setReservedKeywords
Description copied from interface:NamingFactory
Method to set the provided list of keywords as names that identifiers have to surround by quotes to use.- Specified by:
setReservedKeywords
in interfaceNamingFactory
- Parameters:
keywords
- The keywords- Returns:
- This naming factory
-
setQuoteString
Description copied from interface:NamingFactory
Method to set the quote string to use (when the identifiers need to be quoted). SeesetIdentifierCase
.- Specified by:
setQuoteString
in interfaceNamingFactory
- Parameters:
quote
- The quote string- Returns:
- This naming factory
-
setWordSeparator
Description copied from interface:NamingFactory
Method to set the word separator of the names.- Specified by:
setWordSeparator
in interfaceNamingFactory
- Parameters:
sep
- Separator- Returns:
- This naming factory
-
setNamingCase
Description copied from interface:NamingFactory
Method to set the required case of the names.- Specified by:
setNamingCase
in interfaceNamingFactory
- Parameters:
nameCase
- Required case- Returns:
- This naming factory
-
setMaximumLength
Description copied from interface:NamingFactory
Method to set the maximum length of the name of the specified schema component.- Specified by:
setMaximumLength
in interfaceNamingFactory
- Parameters:
cmpt
- The componentmax
- The maximum it accepts- Returns:
- This naming factory
-
getMaximumLengthForComponent
-
getTableName
Description copied from interface:NamingFactory
Method to return the name of the table for the specified class.- Specified by:
getTableName
in interfaceNamingFactory
- Parameters:
cmd
- Metadata for the class- Returns:
- Name of the table
-
getColumnName
Description copied from interface:NamingFactory
Method to return the name of the column for the specified field. If you have multiple columns for a field then call the othergetColumnName
method.- Specified by:
getColumnName
in interfaceNamingFactory
- Parameters:
mmd
- Metadata for the fieldtype
- Type of column- Returns:
- The column name
-
getColumnName
Description copied from interface:NamingFactory
Method to return the name of the column for the position of the specified EMBEDDED field, within the specified owner field. For example, say we have a class Type1 with field "field1" that is marked as embedded, and this is of type Type2. In turn Type2 has a field "field2" that is also embedded, of type Type3. Type3 has a field "name". So to get the column name for Type3.name in the table for Type1 we call "getColumnName({mmdForField1InType1, mmdForField2InType2, mmdForNameInType3}, 0)".- Specified by:
getColumnName
in interfaceNamingFactory
- Parameters:
mmds
- MetaData for the field(s) with the column. The first value is the original field that is embedded, followed by fields of the embedded object(s).colPosition
- The position of the column (where this field has multiple columns)- Returns:
- The column name TODO Pass in something that distinguishes between map key and map value
-
getConstraintName
public String getConstraintName(AbstractClassMetaData cmd, ConstraintMetaData cnstrmd, int position) Description copied from interface:NamingFactory
Method to return the name of a constraint specified at class level.- Specified by:
getConstraintName
in interfaceNamingFactory
- Parameters:
cmd
- Metadata for the classcnstrmd
- The constraint metadataposition
- Number of the constraint at class level (first is 0)- Returns:
- Name of the constraint
-
getConstraintName
public String getConstraintName(String className, AbstractMemberMetaData mmd, ConstraintMetaData cnstrmd) Description copied from interface:NamingFactory
Method to return the name of a constraint specified at member level.- Specified by:
getConstraintName
in interfaceNamingFactory
- Parameters:
className
- Name of the class that this constraint is for.mmd
- Metadata for the membercnstrmd
- The constraint metadata- Returns:
- Name of the constraint
-
getConstraintName
public String getConstraintName(AbstractClassMetaData cmd, ConstraintMetaData cnstrmd, ColumnType type) Description copied from interface:NamingFactory
Method to return the name of the constraint for the specified class (version, datastore-id, discriminator etc).- Specified by:
getConstraintName
in interfaceNamingFactory
- Parameters:
cmd
- Metadata for the classcnstrmd
- The constraint metadatatype
- Column type- Returns:
- Name of the constraint
-
getSequenceName
Description copied from interface:NamingFactory
Method to return the name of sequence.- Specified by:
getSequenceName
in interfaceNamingFactory
- Parameters:
seqmd
- Metadata for the sequence- Returns:
- Name of the sequence
-
calculateHashMax
private static final int calculateHashMax() -
truncate
Method to truncate a name to fit within the specified name length. If truncation is necessary will use a 4 char hashcode (defined byTRUNCATE_HASH_LENGTH
) (at the end) to attempt to create uniqueness.- Parameters:
name
- The namelength
- The (max) length to use- Returns:
- The truncated name.
-
getNameInRequiredCase
Convenience method to convert the passed name into a name in the required "case". Also adds on any required quoting.- Parameters:
name
- The name- Returns:
- The updated name in the correct case
-
prepareIdentifierNameForUse
Convenience method that will truncate the provided name if it is longer than the longest possible for the specified schema component, and then convert it into the required case.- Parameters:
name
- The namecmpt
- The schema component that it is for- Returns:
- The prepared identifier name
-