Class AbstractNamingFactory

    • Field Detail

      • reservedWords

        protected java.util.Set<java.lang.String> reservedWords
      • wordSeparator

        protected java.lang.String wordSeparator
        Separator to use for words in the identifiers.
      • quoteString

        protected java.lang.String quoteString
        Quote used when the identifier case selected requires it.
      • maxLengthByComponent

        java.util.Map<SchemaComponent,​java.lang.Integer> maxLengthByComponent
        Map of max name length, keyed by the schema component type
      • TRUNCATE_HASH_LENGTH

        private static final int TRUNCATE_HASH_LENGTH
        The number of characters used to build the hash.
        See Also:
        Constant Field Values
      • TRUNCATE_HASH_RANGE

        private static final int TRUNCATE_HASH_RANGE
        Range to use for creating hashed ending when truncating identifiers. The actual hashes have a value between 0 and HASH_RANGE - 1.
    • Constructor Detail

      • AbstractNamingFactory

        public AbstractNamingFactory​(NucleusContext nucCtx)
    • Method Detail

      • setReservedKeywords

        public NamingFactory setReservedKeywords​(java.util.Set<java.lang.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 interface NamingFactory
        Parameters:
        keywords - The keywords
        Returns:
        This naming factory
      • setQuoteString

        public NamingFactory setQuoteString​(java.lang.String quote)
        Description copied from interface: NamingFactory
        Method to set the quote string to use (when the identifiers need to be quoted). See
        setIdentifierCase
        .
        Specified by:
        setQuoteString in interface NamingFactory
        Parameters:
        quote - The quote string
        Returns:
        This naming factory
      • setWordSeparator

        public NamingFactory setWordSeparator​(java.lang.String sep)
        Description copied from interface: NamingFactory
        Method to set the word separator of the names.
        Specified by:
        setWordSeparator in interface NamingFactory
        Parameters:
        sep - Separator
        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 interface NamingFactory
        Parameters:
        cmpt - The component
        max - The maximum it accepts
        Returns:
        This naming factory
      • getMaximumLengthForComponent

        protected int getMaximumLengthForComponent​(SchemaComponent cmpt)
      • getTableName

        public java.lang.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 interface NamingFactory
        Parameters:
        cmd - Metadata for the class
        Returns:
        Name of the table
      • getColumnName

        public java.lang.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 other
        getColumnName
        method.
        Specified by:
        getColumnName in interface NamingFactory
        Parameters:
        mmd - Metadata for the field
        type - Type of column
        Returns:
        The column name
      • getColumnName

        public java.lang.String getColumnName​(java.util.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 interface NamingFactory
        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 java.lang.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 interface NamingFactory
        Parameters:
        cmd - Metadata for the class
        cnstrmd - The constraint metadata
        position - Number of the constraint at class level (first is 0)
        Returns:
        Name of the constraint
      • getConstraintName

        public java.lang.String getConstraintName​(java.lang.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 interface NamingFactory
        Parameters:
        className - Name of the class that this constraint is for.
        mmd - Metadata for the member
        cnstrmd - The constraint metadata
        Returns:
        Name of the constraint
      • getConstraintName

        public java.lang.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 interface NamingFactory
        Parameters:
        cmd - Metadata for the class
        cnstrmd - The constraint metadata
        type - Column type
        Returns:
        Name of the constraint
      • getSequenceName

        public java.lang.String getSequenceName​(SequenceMetaData seqmd)
        Description copied from interface: NamingFactory
        Method to return the name of sequence.
        Specified by:
        getSequenceName in interface NamingFactory
        Parameters:
        seqmd - Metadata for the sequence
        Returns:
        Name of the sequence
      • calculateHashMax

        private static final int calculateHashMax()
      • truncate

        protected static java.lang.String truncate​(java.lang.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 by TRUNCATE_HASH_LENGTH) (at the end) to attempt to create uniqueness.
        Parameters:
        name - The name
        length - The (max) length to use
        Returns:
        The truncated name.
      • getNameInRequiredCase

        protected java.lang.String getNameInRequiredCase​(java.lang.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 java.lang.String prepareIdentifierNameForUse​(java.lang.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 name
        cmpt - The schema component that it is for
        Returns:
        The prepared identifier name