Class AbstractNamingFactory
- java.lang.Object
-
- org.datanucleus.store.schema.naming.AbstractNamingFactory
-
- All Implemented Interfaces:
NamingFactory
- Direct Known Subclasses:
DN2NamingFactory
,JPANamingFactory
public abstract class AbstractNamingFactory extends Object implements NamingFactory
Abstract base for any naming factory, providing convenience facilities like truncation.
-
-
Field Summary
Fields Modifier and Type Field Description protected ClassLoaderResolver
clr
protected NamingCase
namingCase
protected NucleusContext
nucCtx
protected String
quoteString
Quote used when the identifier case selected requires it.protected Set<String>
reservedWords
protected String
wordSeparator
Separator to use for words in the identifiers.
-
Constructor Summary
Constructors Constructor Description AbstractNamingFactory(NucleusContext nucCtx)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description String
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.String
getColumnName(AbstractMemberMetaData mmd, ColumnType type)
Method to return the name of the column for the specified field.String
getConstraintName(String className, AbstractMemberMetaData mmd, ConstraintMetaData cnstrmd)
Method to return the name of a constraint specified at member level.String
getConstraintName(AbstractClassMetaData cmd, ConstraintMetaData cnstrmd, int position)
Method to return the name of a constraint specified at class level.String
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
getMaximumLengthForComponent(SchemaComponent cmpt)
protected String
getNameInRequiredCase(String name)
Convenience method to convert the passed name into a name in the required "case".String
getSequenceName(SequenceMetaData seqmd)
Method to return the name of sequence.String
getTableName(AbstractClassMetaData cmd)
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.NamingFactory
setMaximumLength(SchemaComponent cmpt, int max)
Method to set the maximum length of the name of the specified schema component.NamingFactory
setNamingCase(NamingCase nameCase)
Method to set the required case of the names.NamingFactory
setQuoteString(String quote)
Method to set the quote string to use (when the identifiers need to be quoted).NamingFactory
setReservedKeywords(Set<String> keywords)
Method to set the provided list of keywords as names that identifiers have to surround by quotes to use.NamingFactory
setWordSeparator(String sep)
Method to set the word separator of the names.protected static String
truncate(String name, int length)
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 Detail
-
wordSeparator
protected String wordSeparator
Separator to use for words in the identifiers.
-
quoteString
protected String quoteString
Quote used when the identifier case selected requires it.
-
namingCase
protected NamingCase namingCase
-
nucCtx
protected NucleusContext nucCtx
-
clr
protected ClassLoaderResolver clr
-
-
Constructor Detail
-
AbstractNamingFactory
public AbstractNamingFactory(NucleusContext nucCtx)
-
-
Method Detail
-
setReservedKeywords
public NamingFactory setReservedKeywords(Set<String> keywords)
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
public NamingFactory setQuoteString(String quote)
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
public NamingFactory setWordSeparator(String sep)
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
public NamingFactory setNamingCase(NamingCase nameCase)
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
public NamingFactory setMaximumLength(SchemaComponent cmpt, int max)
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
protected int getMaximumLengthForComponent(SchemaComponent cmpt)
-
getTableName
public String getTableName(AbstractClassMetaData cmd)
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
public String getColumnName(AbstractMemberMetaData mmd, ColumnType type)
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
public String getColumnName(List<AbstractMemberMetaData> mmds, int colPosition)
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
public String getSequenceName(SequenceMetaData seqmd)
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
-
truncate
protected static String truncate(String name, int length)
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
protected String getNameInRequiredCase(String name)
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
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.- Parameters:
name
- The namecmpt
- The schema component that it is for- Returns:
- The prepared identifier name
-
-