Class PostgreSQLPlatform

  • All Implemented Interfaces:
    Serializable, Cloneable, CorePlatform<ConversionManager>, Platform

    public class PostgreSQLPlatform
    extends DatabasePlatform

    Purpose: Provides Postgres specific behavior.

    Responsibilities:

    • Native SQL for Date, Time, & Timestamp.
    • Native sequencing.
    • Mapping of class types to database types for the schema framework.
    • Pessimistic locking.
    • Platform specific operators.
    • LIMIT/OFFSET query syntax for select statements.
    Since:
    OracleAS TopLink 10g (10.1.3)
    See Also:
    Serialized Form
    • Constructor Detail

      • PostgreSQLPlatform

        public PostgreSQLPlatform()
    • Method Detail

      • getJDBCType

        public int getJDBCType​(Class javaType)
        Return the JDBC type for the Java type. For some reason PostgreSQL does not seem to like the JDBC Blob type (PostgreSQL 8.2).
        Overrides:
        getJDBCType in class DatabasePlatform
      • appendBoolean

        protected void appendBoolean​(Boolean bool,
                                     Writer writer)
                              throws IOException
        Appends a Boolean value. Refer to : http://www.postgresql.org/docs/8.0/static/datatype-boolean.html In PostgreSQL the following are the values that are value for a boolean field Valid literal values for the "true" state are: TRUE, 't', 'true', 'y', 'yes', '1' Valid literal values for the false" state are : FALSE, 'f', 'false', 'n', 'no', '0' To be consistent with the other data platforms we are using the values '1' and '0' for true and false states of a boolean field.
        Overrides:
        appendBoolean in class DatabasePlatform
        Throws:
        IOException
      • computeMaxRowsForSQL

        public int computeMaxRowsForSQL​(int firstResultIndex,
                                        int maxResults)
        INTERNAL: Use the JDBC maxResults and firstResultIndex setting to compute a value to use when limiting the results of a query in SQL. These limits tend to be used in two ways. 1. MaxRows is the index of the last row to be returned (like JDBC maxResults) 2. MaxRows is the number of rows to be returned PostGreSQL uses case #2 and therefore the maxResults has to be altered based on the firstResultIndex
        Overrides:
        computeMaxRowsForSQL in class DatabasePlatform
        Parameters:
        firstResultIndex -
        maxResults -
        See Also:
        MySQLPlatform
      • regexpOperator

        public static ExpressionOperator regexpOperator()
        INTERNAL: Create the ~ operator. REGEXP allows for comparison through regular expression.
      • toNumberOperator

        protected ExpressionOperator toNumberOperator()
        INTERNAL: Postgres to_number has two arguments, as fix format argument.
      • shouldPrintOutputTokenAtStart

        public boolean shouldPrintOutputTokenAtStart()
        This is required in the construction of the stored procedures with output parameters
        Overrides:
        shouldPrintOutputTokenAtStart in class DatabasePlatform
      • isJDBCExecuteCompliant

        public boolean isJDBCExecuteCompliant()
        Calling a stored procedure query on PostgreSQL with no output parameters always returns true from an execute call regardless if a result set is returned or not. This flag will help avoid throwing a JPA mandated exception on an executeUpdate call (which calls jdbc execute and checks the return value to ensure no results sets are returned (true))
        Overrides:
        isJDBCExecuteCompliant in class DatabasePlatform
        See Also:
        PostgreSQLPlatform
      • shouldPrintAliasForUpdate

        public boolean shouldPrintAliasForUpdate()
        INTERNAL: Indicates whether locking OF clause should print alias for field. Example: on Oracle platform (method returns false): SELECT ADDRESS_ID, ... FROM ADDRESS T1 WHERE (T1.ADDRESS_ID = ?) FOR UPDATE OF T1.ADDRESS_ID on Postgres platform (method returns true): SELECT ADDRESS_ID, ... FROM ADDRESS T1 WHERE (T1.ADDRESS_ID = ?) FOR UPDATE OF T1
        Overrides:
        shouldPrintAliasForUpdate in class DatabasePlatform
      • supportsIdentity

        public boolean supportsIdentity()
        INTERNAL: Indicates whether the platform supports identity.
        Overrides:
        supportsIdentity in class DatasourcePlatform
      • buildSelectQueryForIdentity

        public ValueReadQuery buildSelectQueryForIdentity()
        INTERNAL: Returns query used to read back the value generated by Identity. This method is called when identity NativeSequence is connected, the returned query used until the sequence is disconnected. If the platform supportsIdentity then (at least) one of buildSelectQueryForIdentity methods should return non-null query.
        Overrides:
        buildSelectQueryForIdentity in class DatasourcePlatform
      • buildSelectQueryForSequenceObject

        public ValueReadQuery buildSelectQueryForSequenceObject​(String qualifiedSeqName,
                                                                Integer size)
        INTERNAL: Returns query used to read value generated by sequence object (like Oracle sequence). This method is called when sequence object NativeSequence is connected, the returned query used until the sequence is disconnected. If the platform supportsSequenceObjects then (at least) one of buildSelectQueryForSequenceObject methods should return non-null query.
        Overrides:
        buildSelectQueryForSequenceObject in class DatasourcePlatform
      • operatorLocate

        protected ExpressionOperator operatorLocate()
        INTERNAL: Override the default locate operator.
      • operatorLocate2

        protected ExpressionOperator operatorLocate2()
        INTERNAL: Override the default locate operator.
      • getMaxFieldNameSize

        public int getMaxFieldNameSize()
        INTERNAL: returns the maximum number of characters that can be used in a field name on this platform.
        Overrides:
        getMaxFieldNameSize in class DatabasePlatform
      • getDropCascadeString

        public String getDropCascadeString()
        Allows DROP TABLE to cascade dropping of any dependent constraints if the database supports this option.
        Overrides:
        getDropCascadeString in class DatabasePlatform
      • shouldUseJDBCOuterJoinSyntax

        public boolean shouldUseJDBCOuterJoinSyntax()
        JDBC defines and outer join syntax, many drivers do not support this. So we normally avoid it.
        Overrides:
        shouldUseJDBCOuterJoinSyntax in class DatabasePlatform
      • isAlterSequenceObjectSupported

        public boolean isAlterSequenceObjectSupported()
        INTERNAL: Override this method if the platform supports sequence objects and it's possible to alter sequence object's increment in the database.
        Overrides:
        isAlterSequenceObjectSupported in class DatabasePlatform
      • writeUpdateOriginalFromTempTableSql

        public void writeUpdateOriginalFromTempTableSql​(Writer writer,
                                                        DatabaseTable table,
                                                        Collection pkFields,
                                                        Collection assignedFields)
                                                 throws IOException
        INTERNAL: May need to override this method if the platform supports temporary tables and the generated sql doesn't work. Write an sql string for updating the original table from the temporary table. Precondition: supportsTempTables() == true. Precondition: pkFields and assignFields don't intersect.
        Overrides:
        writeUpdateOriginalFromTempTableSql in class DatabasePlatform
        Parameters:
        writer - for writing the sql
        table - is original table for which temp table is created.
        pkFields - - primary key fields for the original table.
        assignedFields - - fields to be assigned a new value.
        Throws:
        IOException