org.hibernate.dialect
Class PostgreSQLDialect

java.lang.Object
  extended by org.hibernate.dialect.Dialect
      extended by org.hibernate.dialect.PostgreSQLDialect
Direct Known Subclasses:
PostgresPlusDialect

public class PostgreSQLDialect
extends Dialect

An SQL dialect for Postgres

For discussion of BLOB "support" in postrges, as of 8.4, have a peek at http://jdbc.postgresql.org/documentation/84/binary-data.html. For the effects in regards to Hibernate see http://in.relation.to/15492.lace

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 timestamp from the database.
 String getDropSequenceString(String sequenceName)
          Typically dialects which support sequences can drop a sequence with a single command.
 String getForUpdateString()
          Get the string to append to SELECT statements to acquire locks for this dialect.
 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 particular 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.
 String getReadLockString(int timeout)
          Get the string to append to SELECT statements to acquire WRITE locks for this dialect.
 ResultSet getResultSet(CallableStatement ps)
          Given a callable statement previously processed by Dialect.registerResultSetOutParameter(java.sql.CallableStatement, int), extract the 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 retrieve the next value of a sequence as part of another (typically DML) statement.
 String getSequenceNextValString(String sequenceName)
          Generate the appropriate select statement to to retrieve the next value of a sequence.
 ViolatedConstraintNameExtracter getViolatedConstraintNameExtracter()
           
 String getWriteLockString(int timeout)
          Get the string to append to SELECT statements to acquire WRITE locks for this dialect.
 boolean hasDataTypeInIdentityColumn()
          Whether this dialect have an Identity clause added to the data type or a completely separate 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 returning a 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 supportsTupleDistinctCounts()
          Does this dialect support `count(distinct a,b)`?
 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, buildSQLExceptionConverter, closeQuote, convertToFirstRowValue, createCaseFragment, createOuterJoinFragment, doesReadCommittedCauseWritersToBlockReaders, doesRepeatableReadCauseReadersToBlockWriters, dropTemporaryTableAfterUse, forceLimitUsage, forUpdateOfColumns, generateTemporaryTableName, getAddForeignKeyConstraintString, getAddPrimaryKeyConstraintString, getCastTypeName, getColumnComment, getCreateMultisetTableString, getCreateSequenceStrings, getCreateSequenceStrings, getCreateTableString, getCrossJoinSeparator, getCurrentTimestampSQLFunctionName, getDefaultProperties, getDialect, getDialect, getDropForeignKeyString, getDropSequenceStrings, getDropTemporaryTableString, getForUpdateNowaitString, getForUpdateNowaitString, getForUpdateString, getForUpdateString, getForUpdateString, getFunctions, getHibernateTypeName, getHibernateTypeName, getIdentityColumnString, getIdentityInsertString, getIdentitySelectString, getKeywords, getLimitString, getLockingStrategy, getLowercaseFunction, getMaxAliasLength, getNullColumnString, getSelectGUIDString, getTableComment, getTableTypeString, getTypeName, getTypeName, hasAlterTable, hasSelfReferentialForeignKeyBug, isLockTimeoutParameterized, openQuote, performTemporaryTableDDLInIsolation, qualifyIndexName, quote, registerColumnType, registerColumnType, registerFunction, registerHibernateType, registerHibernateType, registerKeyword, requiresCastingOfParametersInSelectClause, supportsBindAsCallableArgument, supportsCascadeDelete, supportsCircularCascadeDeleteConstraints, supportsColumnCheck, supportsExistsInSelect, supportsIfExistsAfterTableName, supportsIfExistsBeforeTableName, supportsInsertSelectIdentity, supportsLimitOffset, supportsLobValueChangePropogation, supportsLockTimeouts, supportsNotNullUnique, supportsParametersInInsertSelect, supportsResultSetPositionQueryMethodsOnForwardOnlyCursor, supportsRowValueConstructorSyntax, supportsRowValueConstructorSyntaxInInList, supportsSubqueryOnMutatingTable, supportsSubselectAsInPredicateLHS, supportsTableCheck, supportsTupleCounts, supportsUnboundedLobLocatorMaterialization, supportsUnique, supportsUniqueConstraintInCreateAlterTable, supportsVariableLimit, toString, transformSelectString, useMaxForLimit
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

PostgreSQLDialect

public PostgreSQLDialect()
Method Detail

getAddColumnString

public String getAddColumnString()
Description copied from class: Dialect
The syntax used to add a column to a table (optional).

Overrides:
getAddColumnString in class Dialect
Returns:
The "add column" fragment.

getSequenceNextValString

public String getSequenceNextValString(String sequenceName)
Description copied from class: Dialect
Generate the appropriate select statement to to retrieve the next value of a sequence.

This should be a "stand alone" select statement.

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

getSelectSequenceNextValString

public String getSelectSequenceNextValString(String sequenceName)
Description copied from class: Dialect
Generate the select expression fragment that will retrieve the next value of a sequence as part of another (typically DML) statement.

This differs from Dialect.getSequenceNextValString(String) in that this should return an expression usable within another statement.

Overrides:
getSelectSequenceNextValString in class Dialect
Parameters:
sequenceName - the name of the sequence
Returns:
The "nextval" fragment.

getCreateSequenceString

public String getCreateSequenceString(String sequenceName)
Description copied from class: Dialect
Typically dialects which support sequences can create a sequence with a single command. This is convenience form of Dialect.getCreateSequenceStrings(java.lang.String) 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 Dialect.getCreateSequenceStrings(java.lang.String).

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

getDropSequenceString

public String getDropSequenceString(String sequenceName)
Description copied from class: Dialect
Typically dialects which support sequences can drop a sequence with a single command. This is convenience form of Dialect.getDropSequenceStrings(java.lang.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(java.lang.String).

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

getCascadeConstraintsString

public String getCascadeConstraintsString()
Description copied from class: Dialect
Completely optional cascading drop clause

Overrides:
getCascadeConstraintsString in class Dialect
Returns:
String

dropConstraints

public boolean dropConstraints()
Description copied from class: Dialect
Do we need to drop constraints before dropping tables in this dialect?

Overrides:
dropConstraints in class Dialect
Returns:
True if constraints must be dropped prior to dropping the table; false otherwise.

supportsSequences

public boolean supportsSequences()
Description copied from class: Dialect
Does this dialect support sequences?

Overrides:
supportsSequences in class Dialect
Returns:
True if sequences supported; false otherwise.

getQuerySequencesString

public String getQuerySequencesString()
Description copied from class: Dialect
Get the select command used retrieve the names of all sequences.

Overrides:
getQuerySequencesString in class Dialect
Returns:
The select command; or null if sequences are not supported.
See Also:
SchemaUpdate

supportsLimit

public boolean supportsLimit()
Description copied from class: Dialect
Does this dialect support some form of limiting query results via a SQL clause?

Overrides:
supportsLimit in class Dialect
Returns:
True if this dialect supports some form of LIMIT.

getLimitString

public String getLimitString(String sql,
                             boolean hasOffset)
Description copied from class: Dialect
Apply s limit clause to the query.

Typically dialects utilize variable limit clauses 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 class Dialect
Parameters:
sql - The query to which to apply the limit.
hasOffset - Is the query requesting an offset?
Returns:
the modified SQL

bindLimitParametersInReverseOrder

public boolean bindLimitParametersInReverseOrder()
Description copied from class: Dialect
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 class Dialect
Returns:
true if the correct order is limit, offset

supportsIdentityColumns

public boolean supportsIdentityColumns()
Description copied from class: Dialect
Does this dialect support identity column key generation?

Overrides:
supportsIdentityColumns in class Dialect
Returns:
True if IDENTITY columns are supported; false otherwise.

getForUpdateString

public String getForUpdateString(String aliases)
Description copied from class: Dialect
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 class Dialect
Parameters:
aliases - The columns to be write locked.
Returns:
The appropriate FOR UPDATE OF column_list clause string.

getIdentitySelectString

public String getIdentitySelectString(String table,
                                      String column,
                                      int type)
Description copied from class: Dialect
Get the select command to use to retrieve the last generated IDENTITY value for a particular table

Overrides:
getIdentitySelectString in class Dialect
Parameters:
table - The table into which the insert was done
column - The PK column.
type - The Types type code.
Returns:
The appropriate select command

getIdentityColumnString

public String getIdentityColumnString(int type)
Description copied from class: Dialect
The syntax used during DDL to define a column as being an IDENTITY of a particular type.

Overrides:
getIdentityColumnString in class Dialect
Parameters:
type - The Types type code.
Returns:
The appropriate DDL fragment.

hasDataTypeInIdentityColumn

public boolean hasDataTypeInIdentityColumn()
Description copied from class: Dialect
Whether this dialect have an Identity clause added to the data type or a completely separate identity data type

Overrides:
hasDataTypeInIdentityColumn in class Dialect
Returns:
boolean

getNoColumnsInsertString

public String getNoColumnsInsertString()
Description copied from class: Dialect
The fragment used to insert a row without specifying any column values. This is not possible on some databases.

Overrides:
getNoColumnsInsertString in class Dialect
Returns:
The appropriate empty values clause.

getNativeIdentifierGeneratorClass

public Class getNativeIdentifierGeneratorClass()
Description copied from class: Dialect
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 class Dialect
Returns:
The native generator class.

supportsOuterJoinForUpdate

public boolean supportsOuterJoinForUpdate()
Description copied from class: Dialect
Does this dialect support FOR UPDATE in conjunction with outer joined rows?

Overrides:
supportsOuterJoinForUpdate in class Dialect
Returns:
True if outer joined rows can be locked via FOR UPDATE.

useInputStreamToInsertBlob

public boolean useInputStreamToInsertBlob()
Description copied from class: Dialect
Should LOBs (both BLOB and CLOB) be bound using stream operations (i.e. PreparedStatement.setBinaryStream(int, java.io.InputStream, int)).

Overrides:
useInputStreamToInsertBlob in class Dialect
Returns:
True if BLOBs and CLOBs should be bound using stream operations.

supportsUnionAll

public boolean supportsUnionAll()
Description copied from class: Dialect
Does this dialect support UNION ALL, which is generally a faster variant of UNION?

Overrides:
supportsUnionAll in class Dialect
Returns:
True if UNION ALL is supported; false otherwise.

getSelectClauseNullString

public String getSelectClauseNullString(int sqlType)
Workaround for postgres bug #1453

Overrides:
getSelectClauseNullString in class Dialect
Parameters:
sqlType - The Types type code.
Returns:
The appropriate select clause value fragment.

supportsCommentOn

public boolean supportsCommentOn()
Overrides:
supportsCommentOn in class Dialect

supportsTemporaryTables

public boolean supportsTemporaryTables()
Description copied from class: Dialect
Does this dialect support temporary tables?

Overrides:
supportsTemporaryTables in class Dialect
Returns:
True if temp tables are supported; false otherwise.

getCreateTemporaryTableString

public String getCreateTemporaryTableString()
Description copied from class: Dialect
Command used to create a temporary table.

Overrides:
getCreateTemporaryTableString in class Dialect
Returns:
The command used to create a temporary table.

getCreateTemporaryTablePostfix

public String getCreateTemporaryTablePostfix()
Description copied from class: Dialect
Get any fragments needing to be postfixed to the command for temporary table creation.

Overrides:
getCreateTemporaryTablePostfix in class Dialect
Returns:
Any required postfix.

supportsCurrentTimestampSelection

public boolean supportsCurrentTimestampSelection()
Description copied from class: Dialect
Does this dialect support a way to retrieve the database's current timestamp value?

Overrides:
supportsCurrentTimestampSelection in class Dialect
Returns:
True if the current timestamp can be retrieved; false otherwise.

isCurrentTimestampSelectStringCallable

public boolean isCurrentTimestampSelectStringCallable()
Description copied from class: Dialect
Should the value returned by Dialect.getCurrentTimestampSelectString() be treated as callable. Typically this indicates that JDBC escape syntax is being used...

Overrides:
isCurrentTimestampSelectStringCallable in class Dialect
Returns:
True if the Dialect.getCurrentTimestampSelectString() return is callable; false otherwise.

getCurrentTimestampSelectString

public String getCurrentTimestampSelectString()
Description copied from class: Dialect
Retrieve the command used to retrieve the current timestamp from the database.

Overrides:
getCurrentTimestampSelectString in class Dialect
Returns:
The command.

supportsTupleDistinctCounts

public boolean supportsTupleDistinctCounts()
Description copied from class: Dialect
Does this dialect support `count(distinct a,b)`?

Overrides:
supportsTupleDistinctCounts in class Dialect
Returns:
True if the database supports counting disintct tuples; false otherwise.

toBooleanValueString

public String toBooleanValueString(boolean bool)
Description copied from class: Dialect
The SQL literal value to which this database maps boolean values.

Overrides:
toBooleanValueString in class Dialect
Parameters:
bool - The boolean value
Returns:
The appropriate SQL literal.

getViolatedConstraintNameExtracter

public ViolatedConstraintNameExtracter getViolatedConstraintNameExtracter()
Overrides:
getViolatedConstraintNameExtracter in class Dialect

registerResultSetOutParameter

public int registerResultSetOutParameter(CallableStatement statement,
                                         int col)
                                  throws SQLException
Description copied from class: Dialect
Registers an OUT parameter which will be returning a ResultSet. How this is accomplished varies greatly from DB to DB, hence its inclusion (along with Dialect.getResultSet(java.sql.CallableStatement)) here.

Overrides:
registerResultSetOutParameter in class Dialect
Parameters:
statement - The callable statement.
col - The bind position at which to register the OUT param.
Returns:
The number of (contiguous) bind positions used.
Throws:
SQLException - Indicates problems registering the OUT param.

getResultSet

public ResultSet getResultSet(CallableStatement ps)
                       throws SQLException
Description copied from class: Dialect
Given a callable statement previously processed by Dialect.registerResultSetOutParameter(java.sql.CallableStatement, int), extract the ResultSet from the OUT parameter.

Overrides:
getResultSet in class Dialect
Parameters:
ps - The callable statement.
Returns:
The extracted result set.
Throws:
SQLException - Indicates problems extracting the result set.

supportsPooledSequences

public boolean supportsPooledSequences()
Description copied from class: Dialect
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 class Dialect
Returns:
True if such "pooled" sequences are supported; false otherwise.
See Also:
Dialect.getCreateSequenceStrings(String, int, int), Dialect.getCreateSequenceString(String, int, int)

getCreateSequenceString

protected String getCreateSequenceString(String sequenceName,
                                         int initialValue,
                                         int incrementSize)
Description copied from class: Dialect
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 class 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

supportsEmptyInList

public boolean supportsEmptyInList()
Description copied from class: Dialect
Does this dialect support empty IN lists?

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

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

supportsExpectedLobUsagePattern

public boolean supportsExpectedLobUsagePattern()
Description copied from class: Dialect
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 class Dialect
Returns:
True if normal LOB usage patterns can be used with this driver; false if driver-specific hookiness needs to be applied.

getForUpdateString

public String getForUpdateString()
Description copied from class: Dialect
Get the string to append to SELECT statements to acquire locks for this dialect.

Overrides:
getForUpdateString in class Dialect
Returns:
The appropriate FOR UPDATE clause string.

getWriteLockString

public String getWriteLockString(int timeout)
Description copied from class: Dialect
Get the string to append to SELECT statements to acquire WRITE locks for this dialect. Location of the of the returned string is treated the same as getForUpdateString.

Overrides:
getWriteLockString in class Dialect
Parameters:
timeout - in milliseconds, -1 for indefinite wait and 0 for no wait.
Returns:
The appropriate LOCK clause string.

getReadLockString

public String getReadLockString(int timeout)
Description copied from class: Dialect
Get the string to append to SELECT statements to acquire WRITE locks for this dialect. Location of the of the returned string is treated the same as getForUpdateString.

Overrides:
getReadLockString in class Dialect
Parameters:
timeout - in milliseconds, -1 for indefinite wait and 0 for no wait.
Returns:
The appropriate LOCK clause string.


Copyright © 2001-2010 Red Hat, Inc. All Rights Reserved.