Class BaseDatastoreAdapter

    • Field Detail

      • MAX_IDENTIFIER_LENGTH

        public static final int MAX_IDENTIFIER_LENGTH
        The maximum length of a SQL/92 identifier in characters.
        See Also:
        Constant Field Values
      • SQL92_RESERVED_WORDS

        public static final String SQL92_RESERVED_WORDS
        A string containing the list of SQL/92 reserved words, separated by commas.
        See Also:
        Constant Field Values
      • SQL99_RESERVED_WORDS

        public static final String SQL99_RESERVED_WORDS
        A string containing the list of SQL/99 reserved words, separated by commas.
        See Also:
        Constant Field Values
      • SQL2003_RESERVED_WORDS

        public static final String SQL2003_RESERVED_WORDS
        A string containing the list of SQL/2003 reserved words, separated by commas.
        See Also:
        Constant Field Values
      • NONRESERVED_WORDS

        public static final String NONRESERVED_WORDS
        A string containing the list of SQL/92 non-reserved words, separated by commas.
        See Also:
        Constant Field Values
      • supportedJdbcTypesById

        protected Map<Integer,​String> supportedJdbcTypesById
      • unsupportedJdbcTypesById

        protected Map<Integer,​String> unsupportedJdbcTypesById
      • reservedKeywords

        protected final HashSet<String> reservedKeywords
        The set of reserved keywords for this datastore.
      • datastoreProductName

        protected String datastoreProductName
        The product name of the underlying datastore.
      • datastoreProductVersion

        protected String datastoreProductVersion
        The version number of the underlying datastore as a string.
      • datastoreMajorVersion

        protected int datastoreMajorVersion
        The major version number of the underlying datastore.
      • datastoreMinorVersion

        protected int datastoreMinorVersion
        The minor version number of the underlying datastore.
      • datastoreRevisionVersion

        protected int datastoreRevisionVersion
        The revision version number of the underlying datastore.
      • identifierQuoteString

        protected String identifierQuoteString
        The String used to quote identifiers.
      • supportedOptions

        protected Collection<String> supportedOptions
        Supported option names.
      • driverName

        protected String driverName
        the JDBC driver name
      • driverVersion

        protected String driverVersion
        the JDBC driver version
      • driverMajorVersion

        protected int driverMajorVersion
        The major version number of the underlying driver.
      • driverMinorVersion

        protected int driverMinorVersion
        The minor version number of the underlying driver.
      • maxTableNameLength

        protected int maxTableNameLength
        The maximum length to be used for a table name.
      • maxConstraintNameLength

        protected int maxConstraintNameLength
        The maximum length to be used for a table constraint name.
      • maxIndexNameLength

        protected int maxIndexNameLength
        The maximum length to be used for an index name.
      • maxColumnNameLength

        protected int maxColumnNameLength
        The maximum length to be used for a column name.
      • catalogSeparator

        protected String catalogSeparator
        The String used to separate catalog and table name.
      • properties

        protected Map<String,​Object> properties
        Optional properties controlling the configuration.
    • Constructor Detail

      • BaseDatastoreAdapter

        protected BaseDatastoreAdapter​(DatabaseMetaData metadata)
        Constructs a database adapter based on the given JDBC metadata.
        Parameters:
        metadata - the database metadata.
    • Method Detail

      • initialise

        public void initialise​(org.datanucleus.store.schema.StoreSchemaHandler handler,
                               org.datanucleus.store.connection.ManagedConnection mconn)
        Description copied from interface: DatastoreAdapter
        Initialise the datastore adapter.
        Specified by:
        initialise in interface DatastoreAdapter
        Parameters:
        handler - SchemaHandler that we initialise the types for
        mconn - Managed connection to use
      • initialiseTypes

        public void initialiseTypes​(org.datanucleus.store.schema.StoreSchemaHandler handler,
                                    org.datanucleus.store.connection.ManagedConnection mconn)
        Initialise the types for this datastore.
        Specified by:
        initialiseTypes in interface DatastoreAdapter
        Parameters:
        handler - SchemaHandler that we initialise the types for
        mconn - Managed connection to use
      • initialiseDatastore

        public void initialiseDatastore​(Connection conn)
        Creates the auxiliary functions/procedures in the schema
        Specified by:
        initialiseDatastore in interface DatastoreAdapter
        Parameters:
        conn - the connection to the datastore
      • getPreferredDefaultSQLTypeForJDBCType

        public String getPreferredDefaultSQLTypeForJDBCType​(org.datanucleus.metadata.JdbcType jdbcType)
        Description copied from interface: DatastoreAdapter
        Way for a DatastoreAdapter to specify a preferred default SQL type for a JDBC type (when there are multiple).
        Specified by:
        getPreferredDefaultSQLTypeForJDBCType in interface DatastoreAdapter
        Parameters:
        jdbcType - The JDBC type
        Returns:
        The SQL type preferred
      • getNameForJDBCType

        public String getNameForJDBCType​(int jdbcType)
        Description copied from interface: DatastoreAdapter
        Return a name for a JDBC Types value.
        Specified by:
        getNameForJDBCType in interface DatastoreAdapter
        Parameters:
        jdbcType - The jdbc type
        Returns:
        The name
      • getJDBCTypeForName

        public int getJDBCTypeForName​(String typeName)
        Description copied from interface: DatastoreAdapter
        Method to return the type given the "jdbc-type" name.
        Specified by:
        getJDBCTypeForName in interface DatastoreAdapter
        Parameters:
        typeName - "jdbc-type" name
        Returns:
        Whether it is valid
      • setProperties

        public void setProperties​(Map<String,​Object> props)
        Set any properties controlling how the adapter is configured.
        Specified by:
        setProperties in interface DatastoreAdapter
        Parameters:
        props - The properties
      • getValueForProperty

        public Object getValueForProperty​(String name)
        Accessor for a property. Null implies not defined
        Parameters:
        name - Name of the property
        Returns:
        Its value
      • getSQLTypeInfoForJdbcType

        protected Collection<SQLTypeInfo> getSQLTypeInfoForJdbcType​(org.datanucleus.store.schema.StoreSchemaHandler handler,
                                                                    org.datanucleus.store.connection.ManagedConnection mconn,
                                                                    short jdbcTypeNumber)
        Accessor for the SQLType info for the specified JDBC type and the SQL type name.
        Parameters:
        handler - Schema handler
        mconn - Connection
        jdbcTypeNumber - JDBC type
        Returns:
        The SQL type info
      • addSQLTypeForJDBCType

        protected boolean addSQLTypeForJDBCType​(org.datanucleus.store.schema.StoreSchemaHandler handler,
                                                org.datanucleus.store.connection.ManagedConnection mconn,
                                                short jdbcTypeNumber,
                                                SQLTypeInfo sqlType,
                                                boolean addIfNotPresent)
        Convenience method for use by adapters to add their own fake JDBC/SQL types in where the JDBC driver doesn't provide some type.
        Parameters:
        handler - the schema handler managing the types
        mconn - Connection to use
        jdbcTypeNumber - The JDBC type
        sqlType - The type info to use
        addIfNotPresent - whether to add only if JDBC type not present
        Returns:
        Whether the SQL type for JDBC type was added
      • supportsTransactionIsolation

        public boolean supportsTransactionIsolation​(int level)
        Accessor for whether this database adapter supports the specified transaction isolation.
        Specified by:
        supportsTransactionIsolation in interface DatastoreAdapter
        Parameters:
        level - The isolation level (as defined by Connection enums).
        Returns:
        Whether it is supported.
      • getSupportedOptions

        public Collection<String> getSupportedOptions()
        Accessor for the options that are supported by this datastore adapter and the underlying datastore.
        Specified by:
        getSupportedOptions in interface DatastoreAdapter
        Returns:
        The options (Collection<String>)
      • supportsOption

        public boolean supportsOption​(String option)
        Accessor for whether the supplied option is supported.
        Specified by:
        supportsOption in interface DatastoreAdapter
        Parameters:
        option - The option
        Returns:
        Whether supported.
      • getAdapterTime

        public long getAdapterTime​(Timestamp time)
        Description copied from interface: DatastoreAdapter
        Utility to return the adapter time in case there are rounding issues with millisecs etc.
        Specified by:
        getAdapterTime in interface DatastoreAdapter
        Parameters:
        time - The timestamp
        Returns:
        The time in millisecs
      • getTime

        protected long getTime​(long time,
                               long nanos)
      • getMiliseconds

        protected int getMiliseconds​(long nanos)
      • supportsQueryFetchSize

        public boolean supportsQueryFetchSize​(int size)
        Whether the datastore will support setting the query fetch size to the supplied value.
        Specified by:
        supportsQueryFetchSize in interface DatastoreAdapter
        Parameters:
        size - The value to set to
        Returns:
        Whether it is supported.
      • isReservedKeyword

        public boolean isReservedKeyword​(String word)
        Tests if a given string is an SQL keyword.

        The list of key words tested against is defined to contain all SQL/92 keywords, plus any additional key words reported by the JDBC driver for this adapter via DatabaseMetaData.getSQLKeywords().

        In general, use of a SQL key word as an identifier should be avoided. SQL/92 key words are divided into reserved and non-reserved words. If a reserved word is used as an identifier it must be quoted with double quotes. Strictly speaking, the same is not true of non-reserved words. However, as C.J. Date writes in A Guide To The SQL Standard :

        The rule by which it is determined within the standard that one key word needs to be reserved while another need not is not clear to this writer. In practice, it is probably wise to treat all key words as reserved.
        Specified by:
        isReservedKeyword in interface DatastoreAdapter
        Parameters:
        word - The word to test.
        Returns:
        true if word is a SQL key word for this DBMS. The comparison is case-insensitive.
      • getDriverMajorVersion

        public int getDriverMajorVersion()
        Accessor for the JDBC driver major version
        Specified by:
        getDriverMajorVersion in interface DatastoreAdapter
        Returns:
        The driver major version
      • getDriverMinorVersion

        public int getDriverMinorVersion()
        Accessor for the JDBC driver minor version
        Specified by:
        getDriverMinorVersion in interface DatastoreAdapter
        Returns:
        The driver minor version
      • getDatastoreIdentifierMaxLength

        public int getDatastoreIdentifierMaxLength​(IdentifierType identifierType)
        Method to return the maximum length of a datastore identifier of the specified type. If no limit exists then returns -1
        Specified by:
        getDatastoreIdentifierMaxLength in interface DatastoreAdapter
        Parameters:
        identifierType - Type of identifier (see IdentifierFactory.TABLE, etc)
        Returns:
        The max permitted length of this type of identifier
      • getMaxForeignKeys

        public int getMaxForeignKeys()
        Accessor for the maximum foreign keys by table permitted for this datastore.
        Specified by:
        getMaxForeignKeys in interface DatastoreAdapter
        Returns:
        Max number of FKs for a table
      • getMaxIndexes

        public int getMaxIndexes()
        Accessor for the maximum indexes by schema permitted for this datastore.
        Specified by:
        getMaxIndexes in interface DatastoreAdapter
        Returns:
        Max number of indexes for a table
      • iteratorReservedWords

        public Iterator iteratorReservedWords()
        Iterator for the reserved words constructed from the method DataBaseMetaData.getSQLKeywords + standard SQL reserved words
        Specified by:
        iteratorReservedWords in interface DatastoreAdapter
        Returns:
        an Iterator with a set of reserved words
      • newRDBMSColumnInfo

        public RDBMSColumnInfo newRDBMSColumnInfo​(ResultSet rs)
        Description copied from interface: DatastoreAdapter
        Create a new column info from the current row of the passed ResultSet. Allows an adapter to override particular column information where the JDBC driver is known to be buggy.
        Specified by:
        newRDBMSColumnInfo in interface DatastoreAdapter
        Parameters:
        rs - Result Set
        Returns:
        The column info
      • newSQLTypeInfo

        public SQLTypeInfo newSQLTypeInfo​(ResultSet rs)
        Description copied from interface: DatastoreAdapter
        Create a new SQL type info from the current row of the passed ResultSet. Allows an adapter to override particular types where the JDBC driver is known to be buggy.
        Specified by:
        newSQLTypeInfo in interface DatastoreAdapter
        Parameters:
        rs - ResultSet
        Returns:
        The SQL type info
      • newFKInfo

        public ForeignKeyInfo newFKInfo​(ResultSet rs)
        Method to return ForeignKeyInfo for the current row of the ResultSet which will have been obtained from a call to DatabaseMetaData.getImportedKeys() or DatabaseMetaData.getExportedKeys().
        Specified by:
        newFKInfo in interface DatastoreAdapter
        Parameters:
        rs - The result set returned from DatabaseMetaData.get??portedKeys()
        Returns:
        The foreign key info
      • getUnlimitedLengthPrecisionValue

        public int getUnlimitedLengthPrecisionValue​(SQLTypeInfo typeInfo)
        Returns the precision value to be used when creating string columns of "unlimited" length. Usually, if this value is needed it is provided in. However, for some types in some databases the value must be computed.
        Specified by:
        getUnlimitedLengthPrecisionValue in interface DatastoreAdapter
        Parameters:
        typeInfo - the typeInfo object for which the precision value is needed.
        Returns:
        the precision value to be used when creating the column, or -1 if no value should be used.
      • isValidPrimaryKeyType

        public boolean isValidPrimaryKeyType​(org.datanucleus.metadata.JdbcType datatype)
        Method to return whether the specified JDBC type is valid for use in a PrimaryKey.
        Specified by:
        isValidPrimaryKeyType in interface DatastoreAdapter
        Parameters:
        datatype - The JDBC type.
        Returns:
        Whether it is valid for use in the PK
      • getSurrogateForEmptyStrings

        public String getSurrogateForEmptyStrings()
        Some databases, Oracle, treats an empty string (0 length) equals null
        Specified by:
        getSurrogateForEmptyStrings in interface DatastoreAdapter
        Returns:
        returns a surrogate to replace the empty string in the database otherwise it would be treated as null
      • getTransactionIsolationForSchemaCreation

        public int getTransactionIsolationForSchemaCreation()
        Accessor for the transaction isolation level to use during schema creation.
        Specified by:
        getTransactionIsolationForSchemaCreation in interface DatastoreAdapter
        Returns:
        The transaction isolation level for schema generation process
      • getRequiredTransactionIsolationLevel

        public int getRequiredTransactionIsolationLevel()
        Accessor for the "required" transaction isolation level if it has to be a certain value for this adapter.
        Specified by:
        getRequiredTransactionIsolationLevel in interface DatastoreAdapter
        Returns:
        Transaction isolation level (-1 implies no restriction)
      • getCatalogName

        public String getCatalogName​(Connection conn)
                              throws SQLException
        Accessor for the Catalog Name for this datastore.
        Specified by:
        getCatalogName in interface DatastoreAdapter
        Parameters:
        conn - Connection to the datastore
        Returns:
        The catalog name
        Throws:
        SQLException - Thrown if error occurs in determining the catalog name.
      • getSchemaName

        public String getSchemaName​(Connection conn)
                             throws SQLException
        Accessor for the Schema Name for this datastore.
        Specified by:
        getSchemaName in interface DatastoreAdapter
        Parameters:
        conn - Connection to the datastore
        Returns:
        The schema name
        Throws:
        SQLException - Thrown if error occurs in determining the schema name.
      • getSelectWithLockOption

        public String getSelectWithLockOption()
        The option to specify in "SELECT ... FROM TABLE ... WITH (option)" to lock instances Returns null if not supported.
        Specified by:
        getSelectWithLockOption in interface DatastoreAdapter
        Returns:
        The option to specify with "SELECT ... FROM TABLE ... WITH (option)"
      • getSelectForUpdateText

        public String getSelectForUpdateText()
        Method returning the text to append to the end of the SELECT to perform the equivalent of "SELECT ... FOR UPDATE" (on some RDBMS). This method means that we can have different text with some datastores (e.g Derby).
        Specified by:
        getSelectForUpdateText in interface DatastoreAdapter
        Returns:
        The "FOR UPDATE" text
      • getSelectNewUUIDStmt

        public String getSelectNewUUIDStmt()
        The function to creates a unique value of type uniqueidentifier.
        Specified by:
        getSelectNewUUIDStmt in interface DatastoreAdapter
        Returns:
        The function. e.g. "SELECT NEWID()"
      • getNewUUIDFunction

        public String getNewUUIDFunction()
        The function to creates a unique value of type uniqueidentifier.
        Returns:
        The function. e.g. "NEWID()"
      • getOrderString

        public String getOrderString​(org.datanucleus.store.StoreManager storeMgr,
                                     String orderString,
                                     SQLExpression sqlExpr)
        Convenience method to allow adaption of an ordering string before applying it. This is useful where the datastore accepts some conversion adapter around the ordering column for example.
        Specified by:
        getOrderString in interface DatastoreAdapter
        Parameters:
        storeMgr - StoreManager
        orderString - The basic ordering string
        sqlExpr - The sql expression being represented here
        Returns:
        The adapted ordering string
      • validToSelectMappingInStatement

        public boolean validToSelectMappingInStatement​(SelectStatement stmt,
                                                       JavaTypeMapping m)
        Method to return if it is valid to select the specified mapping for the specified statement for this datastore adapter. Sometimes, dependent on the type of the column(s), and what other components are present in the statement, it may be invalid to select the mapping. This implementation returns true, so override in database-specific subclass as required.
        Specified by:
        validToSelectMappingInStatement in interface DatastoreAdapter
        Parameters:
        stmt - The statement
        m - The mapping that we want to select
        Returns:
        Whether it is valid
      • getIdentityLastValueStmt

        public String getIdentityLastValueStmt​(Table table,
                                               String columnName)
        Accessor for the autoincrementing sql statement for this datastore.
        Specified by:
        getIdentityLastValueStmt in interface DatastoreAdapter
        Parameters:
        table - Name of the table that the autoincrement is for
        columnName - Name of the column that the autoincrement is for
        Returns:
        The statement for getting the latest autoincremented key
      • getIdentityKeyword

        public String getIdentityKeyword()
        Accessor for the autoincrementing keyword for generating DDLs. (CREATE TABLEs...).
        Specified by:
        getIdentityKeyword in interface DatastoreAdapter
        Returns:
        The keyword for a column using autoincrement
      • getIdentityJavaTypeForType

        public Class getIdentityJavaTypeForType​(Class type)
        Description copied from interface: DatastoreAdapter
        Return the java type that represents any identity (autoincrement) column value.
        Specified by:
        getIdentityJavaTypeForType in interface DatastoreAdapter
        Parameters:
        type - The type of the member mapping to an IDENTITY column
        Returns:
        The type that should be used in generating the column
      • isIdentityFieldDataType

        public boolean isIdentityFieldDataType​(String typeName)
        Verifies if the given typeName is auto incremented by the datastore.
        Specified by:
        isIdentityFieldDataType in interface DatastoreAdapter
        Parameters:
        typeName - the datastore type name
        Returns:
        true when the typeName has values auto incremented by the datastore
      • getInsertStatementForNoColumns

        public String getInsertStatementForNoColumns​(Table table)
        Method to return the INSERT statement to use when inserting into a table that has no columns specified. This is the case when we have a single column in the table and that column is autoincrement/identity (and so is assigned automatically in the datastore).
        Specified by:
        getInsertStatementForNoColumns in interface DatastoreAdapter
        Parameters:
        table - The table
        Returns:
        The statement for the INSERT
      • sequenceExists

        public boolean sequenceExists​(Connection conn,
                                      String catalogName,
                                      String schemaName,
                                      String seqName)
        Description copied from interface: DatastoreAdapter
        Convenience method to return whether the specified sequence already exists.
        Specified by:
        sequenceExists in interface DatastoreAdapter
        Parameters:
        conn - Connection to use for checking
        catalogName - Catalog name
        schemaName - Schema name
        seqName - Name of the sequence
        Returns:
        Whether it exists
      • getSequenceCreateStmt

        public String getSequenceCreateStmt​(String sequence_name,
                                            Integer min,
                                            Integer max,
                                            Integer start,
                                            Integer increment,
                                            Integer cache_size)
        Accessor for the sequence create statement for this datastore.
        Specified by:
        getSequenceCreateStmt in interface DatastoreAdapter
        Parameters:
        sequence_name - Name of the sequence
        min - Minimum value for the sequence
        max - Maximum value for the sequence
        start - Start value for the sequence
        increment - Increment value for the sequence
        cache_size - Cache size for the sequence
        Returns:
        The statement for getting the next id from the sequence
      • getSequenceNextStmt

        public String getSequenceNextStmt​(String sequence_name)
        Accessor for the sequence statement to get the next id for this datastore.
        Specified by:
        getSequenceNextStmt in interface DatastoreAdapter
        Parameters:
        sequence_name - Name of the sequence
        Returns:
        The statement for getting the next id for the sequence
      • getExistingIndexes

        public ResultSet getExistingIndexes​(Connection conn,
                                            String catalog,
                                            String schema,
                                            String table)
                                     throws SQLException
        Provide the existing indexes in the database for the table. This is implemented if and only if the datastore has its own way of getting indexes. Otherwise we will use DatabaseMetaData.getIndexInfo(). The implementation here returns null.
        Specified by:
        getExistingIndexes in interface DatastoreAdapter
        Parameters:
        conn - the JDBC connection
        catalog - the catalog name
        schema - the schema name
        table - the table name
        Returns:
        a ResultSet with the format @see DatabaseMetaData#getIndexInfo(java.lang.String, java.lang.String, java.lang.String, boolean, boolean)
        Throws:
        SQLException - if an error occurs
      • getCreateTableStatement

        public String getCreateTableStatement​(TableImpl table,
                                              Column[] columns,
                                              Properties props,
                                              IdentifierFactory factory)
        Returns the appropriate SQL to create the given table having the given columns. No column constraints or key definitions should be included. It should return something like:
         CREATE TABLE FOO ( BAR VARCHAR(30), BAZ INTEGER )
         
        Specified by:
        getCreateTableStatement in interface DatastoreAdapter
        Parameters:
        table - The table to create.
        columns - The columns of the table.
        props - Properties for controlling the table creation
        factory - Factory for identifiers
        Returns:
        The text of the SQL statement.
      • getAddPrimaryKeyStatement

        public String getAddPrimaryKeyStatement​(PrimaryKey pk,
                                                IdentifierFactory factory)
        Returns the appropriate SQL to add a primary key to its table. It should return something like:
         ALTER TABLE FOO ADD CONSTRAINT FOO_PK PRIMARY KEY (BAR)
         ALTER TABLE FOO ADD PRIMARY KEY (BAR)
         
        Specified by:
        getAddPrimaryKeyStatement in interface DatastoreAdapter
        Parameters:
        pk - An object describing the primary key.
        factory - Identifier factory
        Returns:
        The text of the SQL statement.
      • getAddCandidateKeyStatement

        public String getAddCandidateKeyStatement​(CandidateKey ck,
                                                  IdentifierFactory factory)
        Returns the appropriate SQL to add a candidate key to its table. It should return something like:
         ALTER TABLE FOO ADD CONSTRAINT FOO_CK UNIQUE (BAZ)
         ALTER TABLE FOO ADD UNIQUE (BAZ)
         
        Specified by:
        getAddCandidateKeyStatement in interface DatastoreAdapter
        Parameters:
        ck - An object describing the candidate key.
        factory - Identifier factory
        Returns:
        The text of the SQL statement.
      • getAddForeignKeyStatement

        public String getAddForeignKeyStatement​(ForeignKey fk,
                                                IdentifierFactory factory)
        Returns the appropriate SQL to add a foreign key to its table. It should return something like:
         ALTER TABLE FOO ADD CONSTRAINT FOO_FK1 FOREIGN KEY (BAR, BAZ) REFERENCES ABC (COL1, COL2)
         ALTER TABLE FOO ADD FOREIGN KEY (BAR, BAZ) REFERENCES ABC (COL1, COL2)
         
        Specified by:
        getAddForeignKeyStatement in interface DatastoreAdapter
        Parameters:
        fk - An object describing the foreign key.
        factory - Identifier factory
        Returns:
        The text of the SQL statement.
      • getAddColumnStatement

        public String getAddColumnStatement​(Table table,
                                            Column col)
        Accessor for the SQL statement to add a column to a table.
        Specified by:
        getAddColumnStatement in interface DatastoreAdapter
        Parameters:
        table - The table
        col - The column
        Returns:
        The SQL necessary to add the column
      • getCreateIndexStatement

        public String getCreateIndexStatement​(Index idx,
                                              IdentifierFactory factory)
        Returns the appropriate DDL to create an index. It should return something like:
         CREATE INDEX FOO_N1 ON FOO (BAR,BAZ) [Extended Settings]
         CREATE UNIQUE INDEX FOO_U1 ON FOO (BAR,BAZ) [Extended Settings]
         
        Specified by:
        getCreateIndexStatement in interface DatastoreAdapter
        Parameters:
        idx - An object describing the index.
        factory - Identifier factory
        Returns:
        The text of the SQL statement.
      • getCheckConstraintForValues

        public String getCheckConstraintForValues​(DatastoreIdentifier identifier,
                                                  Object[] values,
                                                  boolean nullable)
        Creates a CHECK constraint definition based on the given values e.g.
        CHECK ("COLUMN" IN ('VAL1','VAL2') OR "COLUMN" IS NULL)
        Specified by:
        getCheckConstraintForValues in interface DatastoreAdapter
        Parameters:
        identifier - Column identifier
        values - Valid values
        nullable - whether the datastore identifier is null
        Returns:
        The check constraint
      • getCreateDatabaseStatement

        public String getCreateDatabaseStatement​(String catalogName,
                                                 String schemaName)
        Description copied from interface: DatastoreAdapter
        Method to return the statement necessary to create a database with this RDBMS. Note that some RDBMS don't support this.
        Specified by:
        getCreateDatabaseStatement in interface DatastoreAdapter
        Parameters:
        catalogName - name of the catalog
        schemaName - Name of the schema
        Returns:
        The DDL statement
      • getDropDatabaseStatement

        public String getDropDatabaseStatement​(String catalogName,
                                               String schemaName)
        Description copied from interface: DatastoreAdapter
        Method to return the statement necessary to drop a database with this RDBMS. Note that some RDBMS don't support this.
        Specified by:
        getDropDatabaseStatement in interface DatastoreAdapter
        Parameters:
        catalogName - Name of the catalog
        schemaName - Name of the schema
        Returns:
        The DDL statement
      • getDropTableStatement

        public String getDropTableStatement​(Table table)
        Returns the appropriate SQL to drop the given table. It should return something like:
         DROP TABLE FOO CASCADE
         
        Specified by:
        getDropTableStatement in interface DatastoreAdapter
        Parameters:
        table - The table to drop.
        Returns:
        The text of the SQL statement.
      • getDropViewStatement

        public String getDropViewStatement​(ViewImpl view)
        Returns the appropriate SQL to drop the given view. It should return something like:
         DROP VIEW FOO
         
        Specified by:
        getDropViewStatement in interface DatastoreAdapter
        Parameters:
        view - The view to drop.
        Returns:
        The text of the SQL statement.
      • getDeleteTableStatement

        public String getDeleteTableStatement​(SQLTable tbl)
        Method to return the basic SQL for a DELETE TABLE statement. Returns the String as DELETE FROM tbl t1. Doesn't include any where clause.
        Specified by:
        getDeleteTableStatement in interface DatastoreAdapter
        Parameters:
        tbl - The SQLTable to delete
        Returns:
        The delete table string
      • getUpdateTableStatement

        public SQLText getUpdateTableStatement​(SQLTable tbl,
                                               SQLText setSQL)
        Method to return the SQLText for an UPDATE TABLE statement. Returns the SQLText for UPDATE tbl t1 SET x1 = val1, x2 = val2. Override if the datastore doesn't support that standard syntax.
        Specified by:
        getUpdateTableStatement in interface DatastoreAdapter
        Parameters:
        tbl - The primary table
        setSQL - The SQLText for the SET component
        Returns:
        SQLText for the update statement
      • getRangeByLimitEndOfStatementClause

        public String getRangeByLimitEndOfStatementClause​(long offset,
                                                          long count,
                                                          boolean hasOrdering)
        Method to return the SQL to append to the end of the SELECT statement to handle restriction of ranges using the LIMIT keyword. Defaults to an empty string (not supported). SELECT param ... WHERE {LIMIT}
        Specified by:
        getRangeByLimitEndOfStatementClause in interface DatastoreAdapter
        Parameters:
        offset - The offset to return from
        count - The number of items to return
        hasOrdering - Whether there is ordering present
        Returns:
        The SQL to append to allow for ranges using LIMIT.
      • getRangeByRowNumberColumn

        public String getRangeByRowNumberColumn()
        Method to return the column name to use when handling ranges via a row-number on the select using the original method (DB2). Defaults to an empty string (not supported).
        Specified by:
        getRangeByRowNumberColumn in interface DatastoreAdapter
        Returns:
        The row number column.
      • getRangeByRowNumberColumn2

        public String getRangeByRowNumberColumn2()
        Method to return the column name to use when handling ranges via a rownumber on the select using the second method (Oracle). Defaults to an empty string (not supported).
        Specified by:
        getRangeByRowNumberColumn2 in interface DatastoreAdapter
        Returns:
        The row number column.
      • getColumns

        public ResultSet getColumns​(Connection conn,
                                    String catalog,
                                    String schema,
                                    String tableNamePattern,
                                    String columnNamePattern)
                             throws SQLException
        Accessor for table and column information for a catalog/schema in this datastore.
        Specified by:
        getColumns in interface DatastoreAdapter
        Parameters:
        conn - Connection to use
        catalog - The catalog (null if none)
        schema - The schema (null if none)
        tableNamePattern - The table name pattern (null if all)
        columnNamePattern - The column name pattern (null if all)
        Returns:
        ResultSet containing the table/column information
        Throws:
        SQLException - Thrown if an error occurs
      • getDatastoreDateStatement

        public String getDatastoreDateStatement()
        Accessor for a statement that will return the statement to use to get the datastore date.
        Specified by:
        getDatastoreDateStatement in interface DatastoreAdapter
        Returns:
        SQL statement to get the datastore date
      • getPatternExpressionAnyCharacter

        public String getPatternExpressionAnyCharacter()
        The pattern string for representing one character that is expanded in word searches. Most of databases will use the underscore character.
        Specified by:
        getPatternExpressionAnyCharacter in interface DatastoreAdapter
        Returns:
        the pattern string.
      • getPatternExpressionZeroMoreCharacters

        public String getPatternExpressionZeroMoreCharacters()
        The pattern string for representing zero or more characters that is expanded in word searches. Most of databases will use the percent sign character.
        Specified by:
        getPatternExpressionZeroMoreCharacters in interface DatastoreAdapter
        Returns:
        the pattern string.
      • getEscapeCharacter

        public String getEscapeCharacter()
        The character for escaping characters in pattern expressions.
        Specified by:
        getEscapeCharacter in interface DatastoreAdapter
        Returns:
        the character.
      • getContinuationString

        public String getContinuationString()
        Continuation string to use where the SQL statement goes over more than 1 line. Some JDBC adapters (e.g DB2) don't do conversion.
        Returns:
        Continuation string.
      • getNumericConversionFunction

        public String getNumericConversionFunction()
        Accessor for the function to use for converting to numeric.
        Specified by:
        getNumericConversionFunction in interface DatastoreAdapter
        Returns:
        The numeric conversion function for this datastore.
      • isStatementCancel

        public boolean isStatementCancel​(SQLException sqle)
        return whether this exception represents a cancelled statement.
        Specified by:
        isStatementCancel in interface DatastoreAdapter
        Parameters:
        sqle - the exception
        Returns:
        whether it is a cancel
      • isStatementTimeout

        public boolean isStatementTimeout​(SQLException sqle)
        return whether this exception represents a timed out statement.
        Specified by:
        isStatementTimeout in interface DatastoreAdapter
        Parameters:
        sqle - the exception
        Returns:
        whether it is a timeout
      • validToIndexMapping

        public boolean validToIndexMapping​(JavaTypeMapping mapping)
        Description copied from interface: DatastoreAdapter
        Method to return whether the specified mapping is indexable. Allows a datastore to not index particular column types.
        Specified by:
        validToIndexMapping in interface DatastoreAdapter
        Parameters:
        mapping - The mapping
        Returns:
        Whether it is indexable
      • getSQLOperationClass

        public Class getSQLOperationClass​(String operationName)
        Description copied from interface: DatastoreAdapter
        Accessor for the SQLOperation class for the specified operation (if available for this datastore).
        Specified by:
        getSQLOperationClass in interface DatastoreAdapter
        Parameters:
        operationName - operation name
        Returns:
        SQLOperation class (or null if none available)
      • getSQLMethodClass

        public Class getSQLMethodClass​(String className,
                                       String methodName,
                                       org.datanucleus.ClassLoaderResolver clr)
        Description copied from interface: DatastoreAdapter
        Accessor for the SQLMethod class for the query invocation of specified class + method name (if available for this datastore).
        Specified by:
        getSQLMethodClass in interface DatastoreAdapter
        Parameters:
        className - Name of the class (or null if this is a STATIC method)
        methodName - Method name
        clr - ClassLoader resolver, in case className is a subclass of a supported type
        Returns:
        The SQLMethod class (or null if not defined for this datastore).
      • loadColumnMappings

        protected void loadColumnMappings​(org.datanucleus.plugin.PluginManager pluginMgr,
                                          org.datanucleus.ClassLoaderResolver clr)
        Load all column mappings defined in the associated plugins via the plugin mechanism. All individual DatastoreAdapters should load up their own built-in support.
        Parameters:
        pluginMgr - the PluginManager
        clr - the ClassLoaderResolver
      • registerColumnMapping

        public void registerColumnMapping​(String javaTypeName,
                                          Class<? extends ColumnMapping> columnMappingType,
                                          String jdbcType,
                                          String sqlType,
                                          boolean dflt)
        Description copied from interface: DatastoreAdapter
        Method to register a column mapping for a specified java type, and against particular JDBC/SQL type.
        Specified by:
        registerColumnMapping in interface DatastoreAdapter
        Parameters:
        javaTypeName - Java type that this is used for
        columnMappingType - The column mapping class to use
        jdbcType - The JDBC type
        sqlType - The SQL type (optional)
        dflt - Whether this is the default mapping for this java type
      • deregisterColumnMappingsForJDBCType

        public void deregisterColumnMappingsForJDBCType​(String jdbcTypeName)
        Utility to deregister all datastore mappings for a JDBC type. This is called when a JDBC driver doesn't own up to knowing about a JDBC type so we ensure that there are no DataNucleus-added references to that JDBC type.
        Specified by:
        deregisterColumnMappingsForJDBCType in interface DatastoreAdapter
        Parameters:
        jdbcTypeName - The JDBC type name
      • getDefaultSqlTypeForJavaType

        public String getDefaultSqlTypeForJavaType​(String javaType,
                                                   String jdbcType)
        Description copied from interface: DatastoreAdapter
        Method to return the default sql-type for the specified java type (and JDBC type)
        Specified by:
        getDefaultSqlTypeForJavaType in interface DatastoreAdapter
        Parameters:
        javaType - The java type
        jdbcType - The JDBC type (optional)
        Returns:
        The SQL type
      • getColumnMappingClass

        public Class<? extends ColumnMapping> getColumnMappingClass​(String javaType,
                                                                    String jdbcType,
                                                                    String sqlType,
                                                                    org.datanucleus.ClassLoaderResolver clr,
                                                                    String fieldName)
        Accessor for a datastore mapping class for the specified java type (and optional jdbc-type or sql-type).
        Specified by:
        getColumnMappingClass in interface DatastoreAdapter
        Parameters:
        javaType - The java type
        jdbcType - The JDBC type
        sqlType - The SQL Type
        clr - ClassLoader resolver to use
        fieldName - Name of the field (if known, for logging only)
        Returns:
        The datastore mapping class