org.hibernate.dialect
Class PostgreSQLDialect

java.lang.Object
  extended by org.hibernate.dialect.Dialect
      extended by org.hibernate.dialect.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.
 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.
 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.
 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 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, buildSQLExceptionConverter, closeQuote, createCaseFragment, createOuterJoinFragment, doesReadCommittedCauseWritersToBlockReaders, doesRepeatableReadCauseReadersToBlockWriters, dropTemporaryTableAfterUse, forUpdateOfColumns, generateTemporaryTableName, getAddForeignKeyConstraintString, getAddPrimaryKeyConstraintString, getCastTypeName, getColumnComment, getCreateMultisetTableString, getCreateSequenceString, getCreateSequenceStrings, getCreateSequenceStrings, getCreateTableString, getCurrentTimestampSQLFunctionName, getDefaultProperties, getDialect, getDialect, getDropForeignKeyString, getDropSequenceStrings, getForUpdateNowaitString, getForUpdateNowaitString, getForUpdateString, getForUpdateString, getFunctions, getHibernateTypeName, getHibernateTypeName, getIdentityColumnString, getIdentityInsertString, getIdentitySelectString, getKeywords, getLimitString, getLockingStrategy, getLowercaseFunction, getMaxAliasLength, getNullColumnString, getResultSet, getSelectGUIDString, getTableComment, getTableTypeString, getTypeName, getTypeName, hasAlterTable, hasSelfReferentialForeignKeyBug, openQuote, performTemporaryTableDDLInIsolation, qualifyIndexName, quote, registerColumnType, registerColumnType, registerFunction, registerHibernateType, registerHibernateType, registerKeyword, registerResultSetOutParameter, supportsBindAsCallableArgument, supportsCascadeDelete, supportsCircularCascadeDeleteConstraints, supportsColumnCheck, supportsExistsInSelect, supportsIfExistsAfterTableName, supportsIfExistsBeforeTableName, supportsInsertSelectIdentity, supportsLimitOffset, supportsLobValueChangePropogation, supportsNotNullUnique, supportsParametersInInsertSelect, supportsPooledSequences, supportsResultSetPositionQueryMethodsOnForwardOnlyCursor, supportsRowValueConstructorSyntax, supportsRowValueConstructorSyntaxInInList, supportsSubqueryOnMutatingTable, supportsSubselectAsInPredicateLHS, supportsTableCheck, 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 retreive 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 retreive 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 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 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 particuar 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 seperate 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 sytnax 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 timestammp from the database.

Overrides:
getCurrentTimestampSelectString in class Dialect
Returns:
The command.

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

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.