org.hibernate.dialect

Class PostgreSQLDialect


public class PostgreSQLDialect
extends Dialect

An SQL dialect for Postgres
Author:
Gavin King

Field Summary

Fields inherited from class org.hibernate.dialect.Dialect

CLOSED_QUOTE, DEFAULT_BATCH_SIZE, NO_BATCH, QUOTE

Constructor Summary

PostgreSQLDialect()

Method Summary

boolean
bindLimitParametersInReverseOrder()
ANSI SQL defines the LIMIT clause to be in the form LIMIT offset, limit.
boolean
dropConstraints()
Do we need to drop constraints before dropping tables in this dialect?
String
getAddColumnString()
The syntax used to add a column to a table (optional).
String
getCascadeConstraintsString()
Completely optional cascading drop clause
String
getCreateSequenceString(String sequenceName)
Typically dialects which support sequences can create a sequence with a single command.
protected String
getCreateSequenceString(String sequenceName, int initialValue, int incrementSize)
Overloaded form of Dialect.getCreateSequenceString(String), additionally taking the initial value and increment size to be applied to the sequence definition.
String
getCreateTemporaryTablePostfix()
Get any fragments needing to be postfixed to the command for temporary table creation.
String
getCreateTemporaryTableString()
Command used to create a temporary table.
String
getCurrentTimestampSelectString()
Retrieve the command used to retrieve the current timestammp from the database.
String
getDropSequenceString(String sequenceName)
Typically dialects which support sequences can drop a sequence with a single command.
String
getForUpdateString(String aliases)
Get the FOR UPDATE OF column_list fragment appropriate for this dialect given the aliases of the columns to be write locked.
String
getIdentityColumnString(int type)
The syntax used during DDL to define a column as being an IDENTITY of a particular type.
String
getIdentitySelectString(String table, String column, int type)
Get the select command to use to retrieve the last generated IDENTITY value for a particuar table
String
getLimitString(String sql, boolean hasOffset)
Apply s limit clause to the query.
Class
getNativeIdentifierGeneratorClass()
The class (which implements IdentifierGenerator) which acts as this dialects native generation strategy.
String
getNoColumnsInsertString()
The fragment used to insert a row without specifying any column values.
String
getQuerySequencesString()
Get the select command used retrieve the names of all sequences.
ResultSet
getResultSet(CallableStatement ps)
Given a callable statement previously processed by Dialect.registerResultSetOutParameter(CallableStatement,int), extract the java.sql.ResultSet from the OUT parameter.
String
getSelectClauseNullString(int sqlType)
Workaround for postgres bug #1453
String
getSelectSequenceNextValString(String sequenceName)
Generate the select expression fragment that will retreive the next value of a sequence as part of another (typically DML) statement.
String
getSequenceNextValString(String sequenceName)
Generate the appropriate select statement to to retreive the next value of a sequence.
ViolatedConstraintNameExtracter
getViolatedConstraintNameExtracter()
boolean
hasDataTypeInIdentityColumn()
Whether this dialect have an Identity clause added to the data type or a completely seperate identity data type
boolean
isCurrentTimestampSelectStringCallable()
Should the value returned by Dialect.getCurrentTimestampSelectString() be treated as callable.
int
registerResultSetOutParameter(CallableStatement statement, int col)
Registers an OUT parameter which will be returing a java.sql.ResultSet.
boolean
supportsCommentOn()
boolean
supportsCurrentTimestampSelection()
Does this dialect support a way to retrieve the database's current timestamp value?
boolean
supportsEmptyInList()
Does this dialect support empty IN lists?

For example, is [where XYZ in ()] a supported construct?

boolean
supportsExpectedLobUsagePattern()
Expected LOB usage pattern is such that I can perform an insert via prepared statement with a parameter binding for a LOB value without crazy casting to JDBC driver implementation-specific classes...
boolean
supportsIdentityColumns()
Does this dialect support identity column key generation?
boolean
supportsLimit()
Does this dialect support some form of limiting query results via a SQL clause?
boolean
supportsOuterJoinForUpdate()
Does this dialect support FOR UPDATE in conjunction with outer joined rows?
boolean
supportsPooledSequences()
Does this dialect support "pooled" sequences.
boolean
supportsSequences()
Does this dialect support sequences?
boolean
supportsTemporaryTables()
Does this dialect support temporary tables?
boolean
supportsUnionAll()
Does this dialect support UNION ALL, which is generally a faster variant of UNION?
String
toBooleanValueString(boolean bool)
The SQL literal value to which this database maps boolean values.
boolean
useInputStreamToInsertBlob()
Should LOBs (both BLOB and CLOB) be bound using stream operations (i.e.

Methods inherited from class org.hibernate.dialect.Dialect

appendIdentitySelectToInsert, appendLockHint, applyLocksToSql, areStringComparisonsCaseInsensitive, bindLimitParametersFirst, bindLimitParametersInReverseOrder, buildSQLExceptionConverter, closeQuote, createCaseFragment, createOuterJoinFragment, doesReadCommittedCauseWritersToBlockReaders, doesRepeatableReadCauseReadersToBlockWriters, dropConstraints, dropTemporaryTableAfterUse, forUpdateOfColumns, generateTemporaryTableName, getAddColumnString, getAddForeignKeyConstraintString, getAddPrimaryKeyConstraintString, getCascadeConstraintsString, getCastTypeName, getColumnComment, getCreateMultisetTableString, getCreateSequenceString, getCreateSequenceString, getCreateSequenceStrings, getCreateSequenceStrings, getCreateTableString, getCreateTemporaryTablePostfix, getCreateTemporaryTableString, getCurrentTimestampSQLFunctionName, getCurrentTimestampSelectString, getDefaultProperties, getDialect, getDialect, getDropForeignKeyString, getDropSequenceString, getDropSequenceStrings, getForUpdateNowaitString, getForUpdateNowaitString, getForUpdateString, getForUpdateString, getForUpdateString, getFunctions, getHibernateTypeName, getHibernateTypeName, getIdentityColumnString, getIdentityColumnString, getIdentityInsertString, getIdentitySelectString, getIdentitySelectString, getKeywords, getLimitString, getLimitString, getLockingStrategy, getLowercaseFunction, getMaxAliasLength, getNativeIdentifierGeneratorClass, getNoColumnsInsertString, getNullColumnString, getQuerySequencesString, getResultSet, getSelectClauseNullString, getSelectGUIDString, getSelectSequenceNextValString, getSequenceNextValString, getTableComment, getTableTypeString, getTypeName, getTypeName, getViolatedConstraintNameExtracter, hasAlterTable, hasDataTypeInIdentityColumn, hasSelfReferentialForeignKeyBug, isCurrentTimestampSelectStringCallable, openQuote, performTemporaryTableDDLInIsolation, qualifyIndexName, quote, registerColumnType, registerColumnType, registerFunction, registerHibernateType, registerHibernateType, registerKeyword, registerResultSetOutParameter, supportsBindAsCallableArgument, supportsCascadeDelete, supportsCircularCascadeDeleteConstraints, supportsColumnCheck, supportsCommentOn, supportsCurrentTimestampSelection, supportsEmptyInList, supportsExistsInSelect, supportsExpectedLobUsagePattern, supportsIdentityColumns, supportsIfExistsAfterTableName, supportsIfExistsBeforeTableName, supportsInsertSelectIdentity, supportsLimit, supportsLimitOffset, supportsLobValueChangePropogation, supportsNotNullUnique, supportsOuterJoinForUpdate, supportsParametersInInsertSelect, supportsPooledSequences, supportsResultSetPositionQueryMethodsOnForwardOnlyCursor, supportsRowValueConstructorSyntax, supportsRowValueConstructorSyntaxInInList, supportsSequences, supportsSubqueryOnMutatingTable, supportsSubselectAsInPredicateLHS, supportsTableCheck, supportsTemporaryTables, supportsUnboundedLobLocatorMaterialization, supportsUnionAll, supportsUnique, supportsUniqueConstraintInCreateAlterTable, supportsVariableLimit, toBooleanValueString, toString, transformSelectString, useInputStreamToInsertBlob, useMaxForLimit

Constructor Details

PostgreSQLDialect

public PostgreSQLDialect()

Method Details

bindLimitParametersInReverseOrder

public boolean bindLimitParametersInReverseOrder()
ANSI SQL defines the LIMIT clause to be in the form LIMIT offset, limit. Does this dialect require us to bind the parameters in reverse order?
Overrides:
bindLimitParametersInReverseOrder in interface Dialect
Returns:
true if the correct order is limit, offset

dropConstraints

public boolean dropConstraints()
Do we need to drop constraints before dropping tables in this dialect?
Overrides:
dropConstraints in interface Dialect
Returns:
True if constraints must be dropped prior to dropping the table; false otherwise.

getAddColumnString

public String getAddColumnString()
The syntax used to add a column to a table (optional).
Overrides:
getAddColumnString in interface Dialect
Returns:
The "add column" fragment.

getCascadeConstraintsString

public String getCascadeConstraintsString()
Completely optional cascading drop clause
Overrides:
getCascadeConstraintsString in interface Dialect
Returns:
String

getCreateSequenceString

public String getCreateSequenceString(String sequenceName)
Typically dialects which support sequences can create a sequence with a single command. This is convenience form of getCreateSequenceStrings to help facilitate that.

Dialects which support sequences and can create a sequence in a single command need *only* override this method. Dialects which support sequences but require multiple commands to create a sequence should instead override getCreateSequenceStrings.

Overrides:
getCreateSequenceString in interface Dialect
Parameters:
sequenceName - The name of the sequence
Returns:
The sequence creation command

getCreateSequenceString

protected String getCreateSequenceString(String sequenceName,
                                         int initialValue,
                                         int incrementSize)
Overloaded form of Dialect.getCreateSequenceString(String), additionally taking the initial value and increment size to be applied to the sequence definition. The default definition is to suffix Dialect.getCreateSequenceString(String) with the string: " start with {initialValue} increment by {incrementSize}" where {initialValue} and {incrementSize} are replacement placeholders. Generally dialects should only need to override this method if different key phrases are used to apply the allocation information.
Overrides:
getCreateSequenceString in interface Dialect
Parameters:
sequenceName - The name of the sequence
initialValue - The initial value to apply to 'create sequence' statement
incrementSize - The increment value to apply to 'create sequence' statement
Returns:
The sequence creation command

getCreateTemporaryTablePostfix

public String getCreateTemporaryTablePostfix()
Get any fragments needing to be postfixed to the command for temporary table creation.
Overrides:
getCreateTemporaryTablePostfix in interface Dialect
Returns:
Any required postfix.

getCreateTemporaryTableString

public String getCreateTemporaryTableString()
Command used to create a temporary table.
Overrides:
getCreateTemporaryTableString in interface Dialect
Returns:
The command used to create a temporary table.

getCurrentTimestampSelectString

public String getCurrentTimestampSelectString()
Retrieve the command used to retrieve the current timestammp from the database.
Overrides:
getCurrentTimestampSelectString in interface Dialect
Returns:
The command.

getDropSequenceString

public String getDropSequenceString(String sequenceName)
Typically dialects which support sequences can drop a sequence with a single command. This is convenience form of Dialect.getDropSequenceStrings(String) to help facilitate that.

Dialects which support sequences and can drop a sequence in a single command need *only* override this method. Dialects which support sequences but require multiple commands to drop a sequence should instead override Dialect.getDropSequenceStrings(String).

Overrides:
getDropSequenceString in interface Dialect
Parameters:
sequenceName - The name of the sequence
Returns:
The sequence drop commands

getForUpdateString

public String getForUpdateString(String aliases)
Get the FOR UPDATE OF column_list fragment appropriate for this dialect given the aliases of the columns to be write locked.
Overrides:
getForUpdateString in interface Dialect
Parameters:
aliases - The columns to be write locked.
Returns:
The appropriate FOR UPDATE OF column_list clause string.

getIdentityColumnString

public String getIdentityColumnString(int type)
The syntax used during DDL to define a column as being an IDENTITY of a particular type.
Overrides:
getIdentityColumnString in interface Dialect
Parameters:
type - The java.sql.Types type code.
Returns:
The appropriate DDL fragment.

getIdentitySelectString

public String getIdentitySelectString(String table,
                                      String column,
                                      int type)
Get the select command to use to retrieve the last generated IDENTITY value for a particuar table
Overrides:
getIdentitySelectString in interface Dialect
Parameters:
table - The table into which the insert was done
column - The PK column.
type - The java.sql.Types type code.
Returns:
The appropriate select command

getLimitString

public String getLimitString(String sql,
                             boolean hasOffset)
Apply s limit clause to the query.

Typically dialects utilize variable limit caluses when they support limits. Thus, when building the select command we do not actually need to know the limit or the offest since we will just be using placeholders.

Here we do still pass along whether or not an offset was specified so that dialects not supporting offsets can generate proper exceptions. In general, dialects will override one or the other of this method and Dialect.getLimitString(String,int,int).

Overrides:
getLimitString in interface Dialect
Parameters:
hasOffset - Is the query requesting an offset?
Returns:
the modified SQL

getNativeIdentifierGeneratorClass

public Class getNativeIdentifierGeneratorClass()
The class (which implements IdentifierGenerator) which acts as this dialects native generation strategy.

Comes into play whenever the user specifies the native generator.

Overrides:
getNativeIdentifierGeneratorClass in interface Dialect
Returns:
The native generator class.

getNoColumnsInsertString

public String getNoColumnsInsertString()
The fragment used to insert a row without specifying any column values. This is not possible on some databases.
Overrides:
getNoColumnsInsertString in interface Dialect
Returns:
The appropriate empty values clause.

getQuerySequencesString

public String getQuerySequencesString()
Get the select command used retrieve the names of all sequences.
Overrides:
getQuerySequencesString in interface Dialect
Returns:
The select command; or null if sequences are not supported.
See Also:
SchemaUpdate

getResultSet

public ResultSet getResultSet(CallableStatement ps)
            throws SQLException
Overrides:
getResultSet in interface Dialect
Parameters:
Returns:
The extracted result set.

getSelectClauseNullString

public String getSelectClauseNullString(int sqlType)
Workaround for postgres bug #1453
Overrides:
getSelectClauseNullString in interface Dialect

getSelectSequenceNextValString

public String getSelectSequenceNextValString(String sequenceName)
Overrides:
getSelectSequenceNextValString in interface Dialect
Parameters:
sequenceName - the name of the sequence
Returns:
The "nextval" fragment.

getSequenceNextValString

public String getSequenceNextValString(String sequenceName)
Generate the appropriate select statement to to retreive the next value of a sequence.

This should be a "stand alone" select statement.

Overrides:
getSequenceNextValString in interface Dialect
Parameters:
sequenceName - the name of the sequence
Returns:
String The "nextval" select string.

getViolatedConstraintNameExtracter

public ViolatedConstraintNameExtracter getViolatedConstraintNameExtracter()
Overrides:
getViolatedConstraintNameExtracter in interface Dialect

hasDataTypeInIdentityColumn

public boolean hasDataTypeInIdentityColumn()
Whether this dialect have an Identity clause added to the data type or a completely seperate identity data type
Overrides:
hasDataTypeInIdentityColumn in interface Dialect
Returns:
boolean

isCurrentTimestampSelectStringCallable

public boolean isCurrentTimestampSelectStringCallable()
Should the value returned by Dialect.getCurrentTimestampSelectString() be treated as callable. Typically this indicates that JDBC escape sytnax is being used...
Overrides:
isCurrentTimestampSelectStringCallable in interface Dialect
Returns:
True if the Dialect.getCurrentTimestampSelectString() return is callable; false otherwise.

registerResultSetOutParameter

public int registerResultSetOutParameter(CallableStatement statement,
                                         int col)
            throws SQLException
Overrides:
registerResultSetOutParameter in interface Dialect
Parameters:
statement - The callable statement.
Returns:
The number of (contiguous) bind positions used.

supportsCommentOn

public boolean supportsCommentOn()
Overrides:
supportsCommentOn in interface Dialect

supportsCurrentTimestampSelection

public boolean supportsCurrentTimestampSelection()
Does this dialect support a way to retrieve the database's current timestamp value?
Overrides:
supportsCurrentTimestampSelection in interface Dialect
Returns:
True if the current timestamp can be retrieved; false otherwise.

supportsEmptyInList

public boolean supportsEmptyInList()
Does this dialect support empty IN lists?

For example, is [where XYZ in ()] a supported construct?

Overrides:
supportsEmptyInList in interface Dialect
Returns:
True if empty in lists are supported; false otherwise.
Since:
3.2

supportsExpectedLobUsagePattern

public boolean supportsExpectedLobUsagePattern()
Expected LOB usage pattern is such that I can perform an insert via prepared statement with a parameter binding for a LOB value without crazy casting to JDBC driver implementation-specific classes...

Part of the trickiness here is the fact that this is largely driver dependent. For example, Oracle (which is notoriously bad with LOB support in their drivers historically) actually does a pretty good job with LOB support as of the 10.2.x versions of their drivers...

Overrides:
supportsExpectedLobUsagePattern in interface Dialect
Returns:
True if normal LOB usage patterns can be used with this driver; false if driver-specific hookiness needs to be applied.
Since:
3.2

supportsIdentityColumns

public boolean supportsIdentityColumns()
Does this dialect support identity column key generation?
Overrides:
supportsIdentityColumns in interface Dialect
Returns:
True if IDENTITY columns are supported; false otherwise.

supportsLimit

public boolean supportsLimit()
Does this dialect support some form of limiting query results via a SQL clause?
Overrides:
supportsLimit in interface Dialect
Returns:
True if this dialect supports some form of LIMIT.

supportsOuterJoinForUpdate

public boolean supportsOuterJoinForUpdate()
Does this dialect support FOR UPDATE in conjunction with outer joined rows?
Overrides:
supportsOuterJoinForUpdate in interface Dialect
Returns:
True if outer joined rows can be locked via FOR UPDATE.

supportsPooledSequences

public boolean supportsPooledSequences()
Does this dialect support "pooled" sequences. Not aware of a better name for this. Essentially can we specify the initial and increment values?
Overrides:
supportsPooledSequences in interface Dialect
Returns:
True if such "pooled" sequences are supported; false otherwise.

supportsSequences

public boolean supportsSequences()
Does this dialect support sequences?
Overrides:
supportsSequences in interface Dialect
Returns:
True if sequences supported; false otherwise.

supportsTemporaryTables

public boolean supportsTemporaryTables()
Does this dialect support temporary tables?
Overrides:
supportsTemporaryTables in interface Dialect
Returns:
True if temp tables are supported; false otherwise.

supportsUnionAll

public boolean supportsUnionAll()
Does this dialect support UNION ALL, which is generally a faster variant of UNION?
Overrides:
supportsUnionAll in interface Dialect
Returns:
True if UNION ALL is supported; false otherwise.

toBooleanValueString

public String toBooleanValueString(boolean bool)
The SQL literal value to which this database maps boolean values.
Overrides:
toBooleanValueString in interface Dialect
Parameters:
bool - The boolean value
Returns:
The appropriate SQL literal.

useInputStreamToInsertBlob

public boolean useInputStreamToInsertBlob()
Should LOBs (both BLOB and CLOB) be bound using stream operations (i.e. java.sql.PreparedStatement.setBinaryStream).
Overrides:
useInputStreamToInsertBlob in interface Dialect
Returns:
True if BLOBs and CLOBs should be bound using stream operations.
Since:
3.2