Top Description Fields Constructors Methods
org.eclipse.persistence.platform.database

public Class PostgreSQLPlatform

extends DatabasePlatform
Class Inheritance
Known Direct Subclasses
org.eclipse.persistence.platform.database.PostgreSQL10Platform
Imports
java.io.CharArrayWriter, .IOException, .StringWriter, .Writer, java.sql.CallableStatement, .PreparedStatement, .SQLException, .Types, java.util.ArrayList, .Collection, .Hashtable, .Iterator, .List, .UUID, .Vector, org.eclipse.persistence.exceptions.ValidationException, org.eclipse.persistence.expressions.Expression, .ExpressionOperator, org.eclipse.persistence.internal.databaseaccess.DatabaseCall, .DatasourceCall, .DatasourceCall.ParameterType, .FieldTypeDefinition, org.eclipse.persistence.internal.expressions.ExpressionJavaPrinter, .ExpressionSQLPrinter, .RelationExpression, .SQLSelectStatement, org.eclipse.persistence.internal.helper.ClassConstants, .DatabaseField, .DatabaseTable, .Helper, org.eclipse.persistence.internal.sessions.AbstractRecord, .AbstractSession, org.eclipse.persistence.mappings.structures.ObjectRelationalDatabaseField, org.eclipse.persistence.queries.SQLCall, .StoredProcedureCall, .ValueReadQuery, org.eclipse.persistence.tools.schemaframework.FieldDefinition

Purpose: Provides Postgres specific behavior.

Responsibilities:

Since
OracleAS TopLink 10g (10.1.3)

Field Summary

Modifier and TypeField and Description
private static final String
private static final String
Inherited from org.eclipse.persistence.platform.database.DatabasePlatform:
DEFAULT_VARCHAR_SIZE

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
protected void
public DatabaseCall
protected Hashtable<Class<?>, FieldTypeDefinition>
buildFieldTypes()

Overrides org.eclipse.persistence.internal.databaseaccess.DatabasePlatform.buildFieldTypes.

Return the mapping of class types to database types for the schema framework.
public String
public ValueReadQuery
buildSelectQueryForIdentity()

Overrides org.eclipse.persistence.internal.databaseaccess.DatasourcePlatform.buildSelectQueryForIdentity.

INTERNAL: Returns query used to read back the value generated by Identity.
public ValueReadQuery
buildSelectQueryForSequenceObject(String qualifiedSeqName, Integer size)

Overrides org.eclipse.persistence.internal.databaseaccess.DatasourcePlatform.buildSelectQueryForSequenceObject.

INTERNAL: Returns query used to read value generated by sequence object (like Oracle sequence).
public boolean
public int
computeMaxRowsForSQL(int firstResultIndex, int maxResults)

Overrides org.eclipse.persistence.internal.databaseaccess.DatabasePlatform.computeMaxRowsForSQL.

INTERNAL: Use the JDBC maxResults and firstResultIndex setting to compute a value to use when limiting the results of a query in SQL.
public String
protected String
protected String
public String
getDropCascadeString()

Overrides org.eclipse.persistence.internal.databaseaccess.DatabasePlatform.getDropCascadeString.

Allows DROP TABLE to cascade dropping of any dependent constraints if the database supports this option.
public String
getInOutputProcedureToken()

Overrides org.eclipse.persistence.internal.databaseaccess.DatabasePlatform.getInOutputProcedureToken.

This method is used to print the output parameter token when stored procedures are called
public int
getJDBCType(Class<?> javaType)

Overrides org.eclipse.persistence.internal.databaseaccess.DatabasePlatform.getJDBCType.

Return the JDBC type for the Java type.
public int
getMaxFieldNameSize()

Overrides org.eclipse.persistence.internal.databaseaccess.DatabasePlatform.getMaxFieldNameSize.

INTERNAL: returns the maximum number of characters that can be used in a field name on this platform.
public String
public String
public ValueReadQuery
getTimestampQuery()

Overrides org.eclipse.persistence.internal.databaseaccess.DatasourcePlatform.getTimestampQuery.

Implements org.eclipse.persistence.internal.databaseaccess.Platform.getTimestampQuery.

INTERNAL: This method returns the query to select the timestamp from the server for Postgres.
protected void
public boolean
isAlterSequenceObjectSupported()

Overrides org.eclipse.persistence.internal.databaseaccess.DatabasePlatform.isAlterSequenceObjectSupported.

INTERNAL: Override this method if the platform supports sequence objects and it's possible to alter sequence object's increment in the database.
public boolean
isJDBCExecuteCompliant()

Overrides org.eclipse.persistence.internal.databaseaccess.DatabasePlatform.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.
public boolean
protected ExpressionOperator
operatorLocate()

INTERNAL: Override the default locate operator.

protected ExpressionOperator
operatorLocate2()

INTERNAL: Override the default locate operator.

private static ExpressionOperator
public void
printFieldIdentityClause(Writer writer)

Overrides org.eclipse.persistence.internal.databaseaccess.DatabasePlatform.printFieldIdentityClause.

INTERNAL: Append the receiver's field 'identity' constraint clause to a writer.
public void
public void
public void
printSQLSelectStatement(DatabaseCall call, ExpressionSQLPrinter printer, SQLSelectStatement statement)

Overrides org.eclipse.persistence.internal.databaseaccess.DatabasePlatform.printSQLSelectStatement.

Print the pagination SQL using Postgres syntax " LIMIT <max> OFFSET <first>".
public static ExpressionOperator
regexpOperator()

INTERNAL: Create the ~ operator.

protected void
public void
setParameterValueInDatabaseCall(final Object
the parameter to set
parameter
,
final PreparedStatement
target PreparedStatement instance
statement
,
final int
index of the parameter in the statement
index
,
final AbstractSession
current database session
session
)

Overrides org.eclipse.persistence.internal.databaseaccess.DatabasePlatform.setParameterValueInDatabaseCall.

INTERNAL Set the parameter in the JDBC statement at the given index in case it is a UUID value.
public void
setParameterValueInDatabaseCall(Object
the parameter to set
parameter
,
CallableStatement
target CallableStatement instance
statement
,
String
name of the parameter in the statement
name
,
AbstractSession
current database session
session
)

Overrides org.eclipse.persistence.internal.databaseaccess.DatabasePlatform.setParameterValueInDatabaseCall.

INTERNAL Set the parameter in the JDBC statement at the given index in case it is a UUID value.
public boolean
shouldPrintAliasForUpdate()

Overrides org.eclipse.persistence.internal.databaseaccess.DatabasePlatform.shouldPrintAliasForUpdate.

INTERNAL: Indicates whether locking OF clause should print alias for field.
public boolean
shouldPrintOutputTokenAtStart()

Overrides org.eclipse.persistence.internal.databaseaccess.DatabasePlatform.shouldPrintOutputTokenAtStart.

This is required in the construction of the stored procedures with output parameters
public boolean
shouldUseJDBCOuterJoinSyntax()

Overrides org.eclipse.persistence.internal.databaseaccess.DatabasePlatform.shouldUseJDBCOuterJoinSyntax.

JDBC defines and outer join syntax, many drivers do not support this.
public boolean
supportsIdentity()

Overrides org.eclipse.persistence.internal.databaseaccess.DatasourcePlatform.supportsIdentity.

INTERNAL: Indicates whether the platform supports identity.
public boolean
public boolean
supportsSequenceObjects()

Overrides org.eclipse.persistence.internal.databaseaccess.DatasourcePlatform.supportsSequenceObjects.

INTERNAL: Indicates whether the platform supports sequence objects.
protected ExpressionOperator
toNumberOperator()

INTERNAL: Postgres to_number has two arguments, as fix format argument.

public void
writeUpdateOriginalFromTempTableSql(Writer
for writing the sql
writer
,
DatabaseTable
is original table for which temp table is created.
table
,
Collection<DatabaseField>
- primary key fields for the original table.
pkFields
,
Collection<DatabaseField>
- fields to be assigned a new value.
assignedFields
)

Overrides org.eclipse.persistence.internal.databaseaccess.DatabasePlatform.writeUpdateOriginalFromTempTableSql.

INTERNAL: May need to override this method if the platform supports temporary tables and the generated sql doesn't work.

Field Detail

LIMITback to summary
private static final String LIMIT
OFFSETback to summary
private static final String OFFSET

Constructor Detail

PostgreSQLPlatformback to summary
public PostgreSQLPlatform()

Method Detail

appendBooleanback to summary
protected void appendBoolean(Boolean bool, Writer writer) throws IOException

Overrides org.eclipse.persistence.internal.databaseaccess.DatabasePlatform.appendBoolean.

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.

Annotations
@Override
buildCallWithReturningback to summary
public DatabaseCall buildCallWithReturning(SQLCall sqlCall, Vector<DatabaseField> returnFields)

Overrides org.eclipse.persistence.internal.databaseaccess.DatabasePlatform.buildCallWithReturning.

INTERNAL: Uses the returning clause on Postgres.

Annotations
@Override
buildFieldTypesback to summary
protected Hashtable<Class<?>, FieldTypeDefinition> buildFieldTypes()

Overrides org.eclipse.persistence.internal.databaseaccess.DatabasePlatform.buildFieldTypes.

Doc from org.eclipse.persistence.internal.databaseaccess.DatabasePlatform.buildFieldTypes.

Return the mapping of class types to database types for the schema framework.

Annotations
@Override
buildProcedureCallStringback to summary
public String buildProcedureCallString(StoredProcedureCall call, AbstractSession session, AbstractRecord row)

Overrides org.eclipse.persistence.internal.databaseaccess.DatabasePlatform.buildProcedureCallString.

INTERNAL: Used for sp calls. PostGreSQL uses a different method for executing StoredProcedures than other platforms.

Annotations
@Override
buildSelectQueryForIdentityback to summary
public ValueReadQuery buildSelectQueryForIdentity()

Overrides org.eclipse.persistence.internal.databaseaccess.DatasourcePlatform.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.

Annotations
@Override
buildSelectQueryForSequenceObjectback to summary
public ValueReadQuery buildSelectQueryForSequenceObject(String qualifiedSeqName, Integer size)

Overrides org.eclipse.persistence.internal.databaseaccess.DatasourcePlatform.buildSelectQueryForSequenceObject.

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.

Annotations
@Override
canBuildCallWithReturningback to summary
public boolean canBuildCallWithReturning()

Overrides org.eclipse.persistence.internal.databaseaccess.DatabasePlatform.canBuildCallWithReturning.

INTERNAL: Postgres has a returning clause.

Annotations
@Override
computeMaxRowsForSQLback to summary
public int computeMaxRowsForSQL(int firstResultIndex, int maxResults)

Overrides org.eclipse.persistence.internal.databaseaccess.DatabasePlatform.computeMaxRowsForSQL.

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

Annotations
@Override
See Also
org.eclipse.persistence.platform.database.MySQLPlatform
getAssignmentStringback to summary
public String getAssignmentString()

Overrides org.eclipse.persistence.internal.databaseaccess.DatabasePlatform.getAssignmentString.

INTERNAL Used for stored function calls.

Annotations
@Override
getCreateTempTableSqlPrefixback to summary
protected String getCreateTempTableSqlPrefix()

Overrides org.eclipse.persistence.internal.databaseaccess.DatabasePlatform.getCreateTempTableSqlPrefix.

INTERNAL:

Annotations
@Override
getCreateTempTableSqlSuffixback to summary
protected String getCreateTempTableSqlSuffix()

Overrides org.eclipse.persistence.internal.databaseaccess.DatabasePlatform.getCreateTempTableSqlSuffix.

INTERNAL:

Annotations
@Override
getDropCascadeStringback to summary
public String getDropCascadeString()

Overrides org.eclipse.persistence.internal.databaseaccess.DatabasePlatform.getDropCascadeString.

Allows DROP TABLE to cascade dropping of any dependent constraints if the database supports this option.

Annotations
@Override
getInOutputProcedureTokenback to summary
public String getInOutputProcedureToken()

Overrides org.eclipse.persistence.internal.databaseaccess.DatabasePlatform.getInOutputProcedureToken.

This method is used to print the output parameter token when stored procedures are called

Annotations
@Override
getJDBCTypeback to summary
public int getJDBCType(Class<?> javaType)

Overrides org.eclipse.persistence.internal.databaseaccess.DatabasePlatform.getJDBCType.

Return the JDBC type for the Java type. For some reason PostgreSQL does not seem to like the JDBC Blob type (PostgreSQL 8.2).

Annotations
@Override
getMaxFieldNameSizeback to summary
public int getMaxFieldNameSize()

Overrides org.eclipse.persistence.internal.databaseaccess.DatabasePlatform.getMaxFieldNameSize.

INTERNAL: returns the maximum number of characters that can be used in a field name on this platform.

Annotations
@Override
getProcedureBeginStringback to summary
public String getProcedureBeginString()

Overrides org.eclipse.persistence.internal.databaseaccess.DatabasePlatform.getProcedureBeginString.

INTERNAL: Used for sp calls.

Annotations
@Override
getProcedureEndStringback to summary
public String getProcedureEndString()

Overrides org.eclipse.persistence.internal.databaseaccess.DatabasePlatform.getProcedureEndString.

INTERNAL: Used for sp calls.

Annotations
@Override
getTimestampQueryback to summary
public ValueReadQuery getTimestampQuery()

Overrides org.eclipse.persistence.internal.databaseaccess.DatasourcePlatform.getTimestampQuery.

Implements org.eclipse.persistence.internal.databaseaccess.Platform.getTimestampQuery.

INTERNAL: This method returns the query to select the timestamp from the server for Postgres.

Annotations
@Override
initializePlatformOperatorsback to summary
protected void initializePlatformOperators()

Overrides org.eclipse.persistence.internal.databaseaccess.DatasourcePlatform.initializePlatformOperators.

INTERNAL: Initialize any platform-specific operators

Annotations
@Override
isAlterSequenceObjectSupportedback to summary
public boolean isAlterSequenceObjectSupported()

Overrides org.eclipse.persistence.internal.databaseaccess.DatabasePlatform.isAlterSequenceObjectSupported.

INTERNAL: Override this method if the platform supports sequence objects and it's possible to alter sequence object's increment in the database.

Annotations
@Override
isJDBCExecuteCompliantback to summary
public boolean isJDBCExecuteCompliant()

Overrides org.eclipse.persistence.internal.databaseaccess.DatabasePlatform.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))

Annotations
@Override
See Also
PostgreSQLPlatform
isPostgreSQLback to summary
public boolean isPostgreSQL()

Overrides org.eclipse.persistence.internal.databaseaccess.DatasourcePlatform.isPostgreSQL.

Implements org.eclipse.persistence.internal.databaseaccess.Platform.isPostgreSQL.

INTERNAL: Answers whether platform is Postgres.

Annotations
@Override
operatorLocateback to summary
protected ExpressionOperator operatorLocate()

INTERNAL: Override the default locate operator.

operatorLocate2back to summary
protected ExpressionOperator operatorLocate2()

INTERNAL: Override the default locate operator.

pgsqlRoundOperatorback to summary
private static ExpressionOperator pgsqlRoundOperator()
printFieldIdentityClauseback to summary
public void printFieldIdentityClause(Writer writer) throws ValidationException

Overrides org.eclipse.persistence.internal.databaseaccess.DatabasePlatform.printFieldIdentityClause.

INTERNAL: Append the receiver's field 'identity' constraint clause to a writer.

Annotations
@Override
printFieldTypeSizeback to summary
public void printFieldTypeSize(Writer writer, FieldDefinition field, FieldTypeDefinition fieldType, boolean shouldPrintFieldIdentityClause) throws IOException

Overrides org.eclipse.persistence.internal.databaseaccess.DatabasePlatform.printFieldTypeSize.

Annotations
@Override
printFieldUniqueback to summary
public void printFieldUnique(Writer writer, boolean shouldPrintFieldIdentityClause) throws IOException

Overrides org.eclipse.persistence.internal.databaseaccess.DatabasePlatform.printFieldUnique.

Annotations
@Override
printSQLSelectStatementback to summary
public void printSQLSelectStatement(DatabaseCall call, ExpressionSQLPrinter printer, SQLSelectStatement statement)

Overrides org.eclipse.persistence.internal.databaseaccess.DatabasePlatform.printSQLSelectStatement.

Print the pagination SQL using Postgres syntax " LIMIT <max> OFFSET <first>".

Annotations
@Override
regexpOperatorback to summary
public static ExpressionOperator regexpOperator()

INTERNAL: Create the ~ operator. REGEXP allows for comparison through regular expression.

setNullFromDatabaseFieldback to summary
protected void setNullFromDatabaseField(DatabaseField databaseField, PreparedStatement statement, int index) throws SQLException

Overrides org.eclipse.persistence.internal.databaseaccess.DatabasePlatform.setNullFromDatabaseField.

Annotations
@Override
setParameterValueInDatabaseCallback to summary
public void setParameterValueInDatabaseCall(final Object parameter, final PreparedStatement statement, final int index, final AbstractSession session) throws SQLException

Overrides org.eclipse.persistence.internal.databaseaccess.DatabasePlatform.setParameterValueInDatabaseCall.

INTERNAL Set the parameter in the JDBC statement at the given index in case it is a UUID value.

Parameters
parameter:Object

the parameter to set

statement:PreparedStatement

target PreparedStatement instance

index:int

index of the parameter in the statement

session:AbstractSession

current database session

Annotations
@Override
setParameterValueInDatabaseCallback to summary
public void setParameterValueInDatabaseCall(Object parameter, CallableStatement statement, String name, AbstractSession session) throws SQLException

Overrides org.eclipse.persistence.internal.databaseaccess.DatabasePlatform.setParameterValueInDatabaseCall.

INTERNAL Set the parameter in the JDBC statement at the given index in case it is a UUID value.

Parameters
parameter:Object

the parameter to set

statement:CallableStatement

target CallableStatement instance

name:String

name of the parameter in the statement

session:AbstractSession

current database session

Annotations
@Override
shouldPrintAliasForUpdateback to summary
public boolean shouldPrintAliasForUpdate()

Overrides org.eclipse.persistence.internal.databaseaccess.DatabasePlatform.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

Annotations
@Override
shouldPrintOutputTokenAtStartback to summary
public boolean shouldPrintOutputTokenAtStart()

Overrides org.eclipse.persistence.internal.databaseaccess.DatabasePlatform.shouldPrintOutputTokenAtStart.

This is required in the construction of the stored procedures with output parameters

Annotations
@Override
shouldUseJDBCOuterJoinSyntaxback to summary
public boolean shouldUseJDBCOuterJoinSyntax()

Overrides org.eclipse.persistence.internal.databaseaccess.DatabasePlatform.shouldUseJDBCOuterJoinSyntax.

JDBC defines and outer join syntax, many drivers do not support this. So we normally avoid it.

Annotations
@Override
supportsIdentityback to summary
public boolean supportsIdentity()

Overrides org.eclipse.persistence.internal.databaseaccess.DatasourcePlatform.supportsIdentity.

INTERNAL: Indicates whether the platform supports identity.

Annotations
@Override
supportsLocalTempTablesback to summary
public boolean supportsLocalTempTables()

Overrides org.eclipse.persistence.internal.databaseaccess.DatabasePlatform.supportsLocalTempTables.

INTERNAL:

Annotations
@Override
supportsSequenceObjectsback to summary
public boolean supportsSequenceObjects()

Overrides org.eclipse.persistence.internal.databaseaccess.DatasourcePlatform.supportsSequenceObjects.

INTERNAL: Indicates whether the platform supports sequence objects.

Annotations
@Override
toNumberOperatorback to summary
protected ExpressionOperator toNumberOperator()

INTERNAL: Postgres to_number has two arguments, as fix format argument.

writeUpdateOriginalFromTempTableSqlback to summary
public void writeUpdateOriginalFromTempTableSql(Writer writer, DatabaseTable table, Collection<DatabaseField> pkFields, Collection<DatabaseField> assignedFields) throws IOException

Overrides org.eclipse.persistence.internal.databaseaccess.DatabasePlatform.writeUpdateOriginalFromTempTableSql.

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.

Parameters
writer:Writer

for writing the sql

table:DatabaseTable

is original table for which temp table is created.

pkFields:Collection<DatabaseField>

- primary key fields for the original table.

assignedFields:Collection<DatabaseField>

- fields to be assigned a new value.

Annotations
@Override