Class AbstractIdentifierFactory

    • 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 adapter
        clr - ClassLoader resolver
        props - Any properties controlling identifier generation
    • Method Detail

      • getNamingCase

        public org.datanucleus.store.schema.naming.NamingCase getNamingCase()
        Accessor for the identifier case being used.
        Specified by:
        getNamingCase in interface IdentifierFactory
        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 interface IdentifierFactory
        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 by HASH_LENGTH) (at the end) to attempt to create uniqueness.
        Parameters:
        identifier - The identifier
        length - 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 interface IdentifierFactory
        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 interface IdentifierFactory
        Parameters:
        identifierType - the type of identifier to be created
        name - The Java or SQL identifier name
        Returns:
        The DatastoreIdentifier
      • 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 interface IdentifierFactory
        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 interface IdentifierFactory
        Parameters:
        identifierName - The identifier name for the table
        catalogName - 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 interface IdentifierFactory
        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 interface IdentifierFactory
        Parameters:
        javaName - The java field name
        embedded - Whether the identifier is for a field embedded
        fieldRole - 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 interface IdentifierFactory
        Parameters:
        sequenceName - the name of the sequence to use
        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 interface IdentifierFactory
        Parameters:
        table - the table
        seq - 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 interface IdentifierFactory
        Parameters:
        table - the table
        seq - 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 interface IdentifierFactory
        Parameters:
        table - the table
        isUnique - if the index is unique
        seq - 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 role
        embedded - 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