org.hibernate.dialect
Class MySQLDialect

java.lang.Object
  extended by org.hibernate.dialect.Dialect
      extended by org.hibernate.dialect.MySQLDialect
All Implemented Interfaces:
ConversionContext
Direct Known Subclasses:
MySQL5Dialect, MySQLInnoDBDialect, MySQLMyISAMDialect

public class MySQLDialect
extends Dialect

An SQL dialect for MySQL (prior to 5.x).


Field Summary
 
Fields inherited from class org.hibernate.dialect.Dialect
CLOSED_QUOTE, DEFAULT_BATCH_SIZE, LEGACY_LOB_MERGE_STRATEGY, NEW_LOCATOR_LOB_MERGE_STRATEGY, NO_BATCH, QUOTE, STREAM_XFER_LOB_MERGE_STRATEGY
 
Constructor Summary
MySQLDialect()
           
 
Method Summary
 boolean areStringComparisonsCaseInsensitive()
          Are string comparisons implicitly case insensitive.
 SQLExceptionConversionDelegate buildSQLExceptionConversionDelegate()
          Build an instance of a SQLExceptionConversionDelegate for interpreting dialect-specific error or SQLState codes.
 char closeQuote()
          The character specific to this dialect used to close a quoted identifier.
 String getAddColumnString()
          The syntax used to add a column to a table (optional).
 String getAddForeignKeyConstraintString(String constraintName, String[] foreignKey, String referencedTable, String[] primaryKey, boolean referencesPrimaryKey)
          The syntax used to add a foreign key constraint to a table.
 String getCastTypeName(int code)
          Get the name of the database type appropriate for casting operations (via the CAST() SQL function) for the given Types typecode.
 String getColumnComment(String comment)
           
 String getCreateTemporaryTableString()
          Command used to create a temporary table.
 String getCurrentTimestampSelectString()
          Retrieve the command used to retrieve the current timestamp from the database.
 String getDropForeignKeyString()
           
 String getDropTemporaryTableString()
          Command used to drop a temporary table.
 String getForUpdateString()
          Get the string to append to SELECT statements to acquire locks for this dialect.
 String getIdentityColumnString()
          The syntax used during DDL to define a column as being an IDENTITY.
 String getIdentitySelectString()
          Get the select command to use to retrieve the last generated IDENTITY value.
 String getLimitString(String sql, boolean hasOffset)
          Apply s limit clause to the query.
 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 getSelectGUIDString()
          Get the command used to select a GUID from the underlying database.
 String getTableComment(String comment)
           
 String getWriteLockString(int timeout)
          Get the string to append to SELECT statements to acquire WRITE locks for this dialect.
 boolean isCurrentTimestampSelectStringCallable()
          Should the value returned by Dialect.getCurrentTimestampSelectString() be treated as callable.
 char openQuote()
          The character specific to this dialect used to begin a quoted identifier.
 Boolean performTemporaryTableDDLInIsolation()
          Does the dialect require that temporary table DDL statements occur in isolation from other statements? This would be the case if the creation would cause any current transaction to get committed implicitly.
 boolean qualifyIndexName()
          Do we need to qualify index names with the schema name?
 int registerResultSetOutParameter(CallableStatement statement, int col)
          Registers an OUT parameter which will be returning a ResultSet.
protected  void registerVarcharTypes()
           
 boolean supportsCascadeDelete()
           
 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 supportsIdentityColumns()
          Does this dialect support identity column key generation?
 boolean supportsIfExistsBeforeTableName()
           
 boolean supportsLimit()
          Does this dialect support some form of limiting query results via a SQL clause?
 boolean supportsLobValueChangePropogation()
          Does the dialect support propagating changes to LOB values back to the database? Talking about mutating the internal value of the locator as opposed to supplying a new locator instance...
 boolean supportsLockTimeouts()
          Informational metadata about whether this dialect is known to support specifying timeouts for requested lock acquisitions.
 boolean supportsRowValueConstructorSyntax()
          Is this dialect known to support what ANSI-SQL terms "row value constructor" syntax; sometimes called tuple syntax.
 boolean supportsSubqueryOnMutatingTable()
          Does this dialect support referencing the table being mutated in a subquery.
 boolean supportsTemporaryTables()
          Does this dialect support temporary tables?
 
Methods inherited from class org.hibernate.dialect.Dialect
appendIdentitySelectToInsert, appendLockHint, applyLocksToSql, bindLimitParametersFirst, bindLimitParametersInReverseOrder, buildSQLExceptionConverter, convertToFirstRowValue, createCaseFragment, createOuterJoinFragment, doesReadCommittedCauseWritersToBlockReaders, doesRepeatableReadCauseReadersToBlockWriters, dropConstraints, dropTemporaryTableAfterUse, forceLimitUsage, forUpdateOfColumns, generateTemporaryTableName, getAddPrimaryKeyConstraintString, getAddUniqueConstraintString, getCascadeConstraintsString, getCaseInsensitiveLike, getColumnAliasExtractor, getCreateMultisetTableString, getCreateSequenceString, getCreateSequenceString, getCreateSequenceStrings, getCreateSequenceStrings, getCreateTableString, getCreateTemporaryTablePostfix, getCrossJoinSeparator, getCurrentTimestampSQLFunctionName, getDefaultProperties, getDialect, getDialect, getDropSequenceString, getDropSequenceStrings, getForUpdateNowaitString, getForUpdateNowaitString, getForUpdateString, getForUpdateString, getForUpdateString, getForUpdateString, getFunctions, getHibernateTypeName, getHibernateTypeName, getIdentityColumnString, getIdentityInsertString, getIdentitySelectString, getKeywords, getLimitString, getLobMergeStrategy, getLockingStrategy, getLowercaseFunction, getMaxAliasLength, getNativeIdentifierGeneratorClass, getNoColumnsInsertString, getNullColumnString, getQuerySequencesString, getSelectClauseNullString, getSelectSequenceNextValString, getSequenceNextValString, getSqlTypeDescriptorOverride, getTableTypeString, getTypeName, getTypeName, getViolatedConstraintNameExtracter, hasAlterTable, hasDataTypeInIdentityColumn, hasSelfReferentialForeignKeyBug, isLockTimeoutParameterized, quote, registerColumnType, registerColumnType, registerFunction, registerHibernateType, registerHibernateType, registerKeyword, remapSqlTypeDescriptor, replaceResultVariableInOrderByClauseWithPosition, requiresCastingOfParametersInSelectClause, supportsBindAsCallableArgument, supportsCaseInsensitiveLike, supportsCircularCascadeDeleteConstraints, supportsColumnCheck, supportsCommentOn, supportsExistsInSelect, supportsExpectedLobUsagePattern, supportsIfExistsAfterTableName, supportsInsertSelectIdentity, supportsLimitOffset, supportsNotNullUnique, supportsOuterJoinForUpdate, supportsParametersInInsertSelect, supportsPooledSequences, supportsResultSetPositionQueryMethodsOnForwardOnlyCursor, supportsRowValueConstructorSyntaxInInList, supportsSequences, supportsSubselectAsInPredicateLHS, supportsTableCheck, supportsTupleCounts, supportsTupleDistinctCounts, supportsUnboundedLobLocatorMaterialization, supportsUnionAll, supportsUnique, supportsUniqueConstraintInCreateAlterTable, supportsVariableLimit, toBooleanValueString, toString, transformSelectString, useInputStreamToInsertBlob, useMaxForLimit
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

MySQLDialect

public MySQLDialect()
Method Detail

registerVarcharTypes

protected void registerVarcharTypes()

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.

qualifyIndexName

public boolean qualifyIndexName()
Description copied from class: Dialect
Do we need to qualify index names with the schema name?

Overrides:
qualifyIndexName in class Dialect
Returns:
boolean

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.

getIdentitySelectString

public String getIdentitySelectString()
Description copied from class: Dialect
Get the select command to use to retrieve the last generated IDENTITY value.

Overrides:
getIdentitySelectString in class Dialect
Returns:
The appropriate select command

getIdentityColumnString

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

Overrides:
getIdentityColumnString in class Dialect
Returns:
The appropriate DDL fragment.

getAddForeignKeyConstraintString

public String getAddForeignKeyConstraintString(String constraintName,
                                               String[] foreignKey,
                                               String referencedTable,
                                               String[] primaryKey,
                                               boolean referencesPrimaryKey)
Description copied from class: Dialect
The syntax used to add a foreign key constraint to a table.

Overrides:
getAddForeignKeyConstraintString in class Dialect
Parameters:
constraintName - The FK constraint name.
foreignKey - The names of the columns comprising the FK
referencedTable - The table referenced by the FK
primaryKey - The explicit columns in the referencedTable referenced by this FK.
referencesPrimaryKey - if false, constraint should be explicit about which column names the constraint refers to
Returns:
the "add FK" fragment

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.

getDropForeignKeyString

public String getDropForeignKeyString()
Overrides:
getDropForeignKeyString in class Dialect

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

closeQuote

public char closeQuote()
Description copied from class: Dialect
The character specific to this dialect used to close a quoted identifier.

Overrides:
closeQuote in class Dialect
Returns:
The dialect's specific close quote character.

openQuote

public char openQuote()
Description copied from class: Dialect
The character specific to this dialect used to begin a quoted identifier.

Overrides:
openQuote in class Dialect
Returns:
The dialect's specific open quote character.

supportsIfExistsBeforeTableName

public boolean supportsIfExistsBeforeTableName()
Overrides:
supportsIfExistsBeforeTableName in class Dialect

getSelectGUIDString

public String getSelectGUIDString()
Description copied from class: Dialect
Get the command used to select a GUID from the underlying database.

Optional operation.

Overrides:
getSelectGUIDString in class Dialect
Returns:
The appropriate command.

supportsCascadeDelete

public boolean supportsCascadeDelete()
Overrides:
supportsCascadeDelete in class Dialect

getTableComment

public String getTableComment(String comment)
Overrides:
getTableComment in class Dialect

getColumnComment

public String getColumnComment(String comment)
Overrides:
getColumnComment 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.

getDropTemporaryTableString

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

Overrides:
getDropTemporaryTableString in class Dialect
Returns:
The command used to drop a temporary table.

performTemporaryTableDDLInIsolation

public Boolean performTemporaryTableDDLInIsolation()
Description copied from class: Dialect
Does the dialect require that temporary table DDL statements occur in isolation from other statements? This would be the case if the creation would cause any current transaction to get committed implicitly.

JDBC defines a standard way to query for this information via the DatabaseMetaData.dataDefinitionCausesTransactionCommit() method. However, that does not distinguish between temporary table DDL and other forms of DDL; MySQL, for example, reports DDL causing a transaction commit via its driver, even though that is not the case for temporary table DDL.

Possible return values and their meanings:

Overrides:
performTemporaryTableDDLInIsolation in class Dialect
Returns:
see the result matrix above.

getCastTypeName

public String getCastTypeName(int code)
Description copied from class: Dialect
Get the name of the database type appropriate for casting operations (via the CAST() SQL function) for the given Types typecode.

Overrides:
getCastTypeName in class Dialect
Parameters:
code - The Types typecode
Returns:
The database type name

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.

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.

supportsRowValueConstructorSyntax

public boolean supportsRowValueConstructorSyntax()
Description copied from class: Dialect
Is this dialect known to support what ANSI-SQL terms "row value constructor" syntax; sometimes called tuple syntax.

Basically, does it support syntax like "... where (FIRST_NAME, LAST_NAME) = ('Steve', 'Ebersole') ...".

Overrides:
supportsRowValueConstructorSyntax in class Dialect
Returns:
True if this SQL dialect is known to support "row value constructor" syntax; false otherwise.

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.

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.

areStringComparisonsCaseInsensitive

public boolean areStringComparisonsCaseInsensitive()
Description copied from class: Dialect
Are string comparisons implicitly case insensitive.

In other words, does [where 'XYZ' = 'xyz'] resolve to true?

Overrides:
areStringComparisonsCaseInsensitive in class Dialect
Returns:
True if comparisons are case insensitive.

supportsLobValueChangePropogation

public boolean supportsLobValueChangePropogation()
Description copied from class: Dialect
Does the dialect support propagating changes to LOB values back to the database? Talking about mutating the internal value of the locator as opposed to supplying a new locator instance...

For BLOBs, the internal value might be changed by: Blob.setBinaryStream(long), Blob.setBytes(long, byte[]), Blob.setBytes(long, byte[], int, int), or Blob.truncate(long).

For CLOBs, the internal value might be changed by: Clob.setAsciiStream(long), Clob.setCharacterStream(long), Clob.setString(long, String), Clob.setString(long, String, int, int), or Clob.truncate(long).

NOTE : I do not know the correct answer currently for databases which (1) are not part of the cruise control process or (2) do not Dialect.supportsExpectedLobUsagePattern().

Overrides:
supportsLobValueChangePropogation in class Dialect
Returns:
True if the changes are propagated back to the database; false otherwise.

supportsSubqueryOnMutatingTable

public boolean supportsSubqueryOnMutatingTable()
Description copied from class: Dialect
Does this dialect support referencing the table being mutated in a subquery. The "table being mutated" is the table referenced in an UPDATE or a DELETE query. And so can that table then be referenced in a subquery of said UPDATE/DELETE query.

For example, would the following two syntaxes be supported:

Overrides:
supportsSubqueryOnMutatingTable in class Dialect
Returns:
True if this dialect allows references the mutating table from a subquery.

supportsLockTimeouts

public boolean supportsLockTimeouts()
Description copied from class: Dialect
Informational metadata about whether this dialect is known to support specifying timeouts for requested lock acquisitions.

Overrides:
supportsLockTimeouts in class Dialect
Returns:
True is this dialect supports specifying lock timeouts.

buildSQLExceptionConversionDelegate

public SQLExceptionConversionDelegate buildSQLExceptionConversionDelegate()
Description copied from class: Dialect
Build an instance of a SQLExceptionConversionDelegate for interpreting dialect-specific error or SQLState codes.

When Dialect.buildSQLExceptionConverter() returns null, the default SQLExceptionConverter is used to interpret SQLState and error codes. If this method is overridden to return a non-null value, the default SQLExceptionConverter will use the returned SQLExceptionConversionDelegate in addition to the following standard delegates:

  1. a "static" delegate based on the JDBC 4 defined SQLException hierarchy;
  2. a delegate that interprets SQLState codes for either X/Open or SQL-2003 codes, depending on java.sql.DatabaseMetaData#getSQLStateType

It is strongly recommended that specific Dialect implementations override this method, since interpretation of a SQL error is much more accurate when based on the a vendor-specific ErrorCode rather than the SQLState.

Specific Dialects may override to return whatever is most appropriate for that vendor.

Overrides:
buildSQLExceptionConversionDelegate in class Dialect


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