Class PostgreSQLAdapter

  • All Implemented Interfaces:
    DatastoreAdapter

    public class PostgreSQLAdapter
    extends BaseDatastoreAdapter
    Provides methods for adapting SQL language elements to the PostgreSQL database.
    • Field Detail

      • POSTGRESQL_RESERVED_WORDS

        public static final java.lang.String POSTGRESQL_RESERVED_WORDS
        List of Postgresql keywords that aren't in SQL92, SQL99
        See Also:
        Constant Field Values
    • Constructor Detail

      • PostgreSQLAdapter

        public PostgreSQLAdapter​(java.sql.DatabaseMetaData metadata)
        Constructor.
        Parameters:
        metadata - MetaData from the JDBC driver
    • Method Detail

      • 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
        Overrides:
        initialiseTypes in class BaseDatastoreAdapter
        Parameters:
        handler - SchemaHandler that we initialise the types for
        mconn - Managed connection to use
      • newSQLTypeInfo

        public SQLTypeInfo newSQLTypeInfo​(java.sql.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
        Overrides:
        newSQLTypeInfo in class BaseDatastoreAdapter
        Parameters:
        rs - ResultSet
        Returns:
        The SQL type info
      • newRDBMSColumnInfo

        public RDBMSColumnInfo newRDBMSColumnInfo​(java.sql.ResultSet rs)
        Method to create a column info for the current row. Overrides the dataType/columnSize/decimalDigits to cater for Postgresql particularities.
        Specified by:
        newRDBMSColumnInfo in interface DatastoreAdapter
        Overrides:
        newRDBMSColumnInfo in class BaseDatastoreAdapter
        Parameters:
        rs - ResultSet from DatabaseMetaData.getColumns()
        Returns:
        column info
      • newFKInfo

        public ForeignKeyInfo newFKInfo​(java.sql.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
        Overrides:
        newFKInfo in class BaseDatastoreAdapter
        Parameters:
        rs - The result set returned from DatabaseMetaData.get??portedKeys()
        Returns:
        The foreign key info
      • getDropDatabaseStatement

        public java.lang.String getDropDatabaseStatement​(java.lang.String catalogName,
                                                         java.lang.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
        Overrides:
        getDropDatabaseStatement in class BaseDatastoreAdapter
        Parameters:
        catalogName - Name of the catalog
        schemaName - Name of the schema
        Returns:
        The DDL statement
      • getInsertStatementForNoColumns

        public java.lang.String getInsertStatementForNoColumns​(Table table)
        Method to return the INSERT statement to use when inserting into a table and we dont want to specify columns. 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). Postgresql expects something like
         INSERT INTO tbl VALUES(DEFAULT)
         
        Specified by:
        getInsertStatementForNoColumns in interface DatastoreAdapter
        Overrides:
        getInsertStatementForNoColumns in class BaseDatastoreAdapter
        Parameters:
        table - The table
        Returns:
        The statement for the INSERT
      • getDropTableStatement

        public java.lang.String getDropTableStatement​(Table table)
        Accessor for the statement for dropping a table. PostgreSQL has supported the DROP TABLE tbl-name CASCADE since 7.3.
        Specified by:
        getDropTableStatement in interface DatastoreAdapter
        Overrides:
        getDropTableStatement in class BaseDatastoreAdapter
        Parameters:
        table - The table to drop.
        Returns:
        The statement for dropping a table.
      • getCreateIndexStatement

        public java.lang.String getCreateIndexStatement​(Index idx,
                                                        IdentifierFactory factory)
        Returns the appropriate DDL to create an index. Overrides the superclass variant since Postgresql doesn't support having index names specified in a particular schema (i.e "{schema}.{indexName}").
        Specified by:
        getCreateIndexStatement in interface DatastoreAdapter
        Overrides:
        getCreateIndexStatement in class BaseDatastoreAdapter
        Parameters:
        idx - An object describing the index.
        factory - Identifier factory
        Returns:
        The text of the SQL statement.
      • getIdentityLastValueStmt

        public java.lang.String getIdentityLastValueStmt​(Table table,
                                                         java.lang.String columnName)
        Accessor for the autoincrement sql access statement for this datastore.
        Specified by:
        getIdentityLastValueStmt in interface DatastoreAdapter
        Overrides:
        getIdentityLastValueStmt in class BaseDatastoreAdapter
        Parameters:
        table - Table that the autoincrement is for
        columnName - Name of the column that the autoincrement is for
        Returns:
        The statement for getting the latest auto-increment key
      • getIdentityKeyword

        public java.lang.String getIdentityKeyword​(org.datanucleus.store.StoreManager storeMgr,
                                                   ColumnMapping columnMapping)
        Accessor for the identity (auto-increment) keyword for generating DDLs (CREATE TABLEs...). Provides the ColumnMapping as context for data stores that have different identity keywords based on the mapped Java / JDBC type.
        Parameters:
        storeMgr - The Store manager
        columnMapping - The column mapping
        Returns:
        The keyword for a column using auto-increment/identity
      • sequenceExists

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

        public java.lang.String getSequenceCreateStmt​(java.lang.String sequenceName,
                                                      java.lang.Integer min,
                                                      java.lang.Integer max,
                                                      java.lang.Integer start,
                                                      java.lang.Integer increment,
                                                      java.lang.Integer cacheSize)
        Accessor for the sequence statement to create the sequence.
        Specified by:
        getSequenceCreateStmt in interface DatastoreAdapter
        Overrides:
        getSequenceCreateStmt in class BaseDatastoreAdapter
        Parameters:
        sequenceName - 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
        cacheSize - Cache size for the sequence
        Returns:
        The statement for getting the next id from the sequence
      • getSequenceNextStmt

        public java.lang.String getSequenceNextStmt​(java.lang.String sequenceName)
        Accessor for the statement for getting the next id from the sequence for this datastore.
        Specified by:
        getSequenceNextStmt in interface DatastoreAdapter
        Overrides:
        getSequenceNextStmt in class BaseDatastoreAdapter
        Parameters:
        sequenceName - Name of the sequence
        Returns:
        The statement for getting the next id for the sequence
      • getRangeByLimitEndOfStatementClause

        public java.lang.String getRangeByLimitEndOfStatementClause​(long offset,
                                                                    long count,
                                                                    boolean hasOrdering)
        Method to return the SQL to append to the WHERE clause of a SELECT statement to handle restriction of ranges using the LIMUT keyword.
        Specified by:
        getRangeByLimitEndOfStatementClause in interface DatastoreAdapter
        Overrides:
        getRangeByLimitEndOfStatementClause in class BaseDatastoreAdapter
        Parameters:
        offset - The offset to return from
        count - The number of items to return
        hasOrdering - Whether ordering is present
        Returns:
        The SQL to append to allow for ranges using LIMIT.
      • getSQLMethodClass

        public java.lang.Class<? extends SQLMethod> getSQLMethodClass​(java.lang.String className,
                                                                      java.lang.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
        Overrides:
        getSQLMethodClass in class BaseDatastoreAdapter
        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 mgr,
                                          org.datanucleus.ClassLoaderResolver clr)
        Load all datastore mappings for this RDBMS database.
        Overrides:
        loadColumnMappings in class BaseDatastoreAdapter
        Parameters:
        mgr - the PluginManager
        clr - the ClassLoaderResolver