org.hibernate.dialect

Class MySQLDialect

Known Direct Subclasses:
MySQL5Dialect, MySQLInnoDBDialect, MySQLMyISAMDialect

public class MySQLDialect
extends Dialect

An SQL dialect for MySQL (prior to 5.x).
Author:
Gavin King

Field Summary

Fields inherited from class org.hibernate.dialect.Dialect

CLOSED_QUOTE, DEFAULT_BATCH_SIZE, NO_BATCH, QUOTE

Constructor Summary

MySQLDialect()

Method Summary

boolean
areStringComparisonsCaseInsensitive()
Are string comparisons implicitly case insensitive.
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 java.sql.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 timestammp from the database.
String
getDropForeignKeyString()
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.
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
getSelectGUIDString()
Get the command used to select a GUID from the underlying database.
String
getTableComment(String comment)
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 returing a java.sql.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 propogating 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
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, 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

MySQLDialect

public MySQLDialect()

Method Details

areStringComparisonsCaseInsensitive

public boolean areStringComparisonsCaseInsensitive()
Are string comparisons implicitly case insensitive.

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

Overrides:
areStringComparisonsCaseInsensitive in interface Dialect
Returns:
True if comparisons are case insensitive.
Since:
3.2

closeQuote

public char closeQuote()
The character specific to this dialect used to close a quoted identifier.
Overrides:
closeQuote in interface Dialect
Returns:
The dialect's specific close quote character.

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.

getAddForeignKeyConstraintString

public String getAddForeignKeyConstraintString(String constraintName,
                                               String[] foreignKey,
                                               String referencedTable,
                                               String[] primaryKey,
                                               boolean referencesPrimaryKey)
The syntax used to add a foreign key constraint to a table.
Overrides:
getAddForeignKeyConstraintString in interface 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

getCastTypeName

public String getCastTypeName(int code)
Get the name of the database type appropriate for casting operations (via the CAST() SQL function) for the given java.sql.Types typecode.
Overrides:
getCastTypeName in interface Dialect
Parameters:
code - The java.sql.Types typecode
Returns:
The database type name

getColumnComment

public String getColumnComment(String comment)
Overrides:
getColumnComment in interface Dialect

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.

getDropForeignKeyString

public String getDropForeignKeyString()
Overrides:
getDropForeignKeyString in interface Dialect

getIdentityColumnString

public String getIdentityColumnString()
The syntax used during DDL to define a column as being an IDENTITY.
Overrides:
getIdentityColumnString in interface Dialect
Returns:
The appropriate DDL fragment.

getIdentitySelectString

public String getIdentitySelectString()
Get the select command to use to retrieve the last generated IDENTITY value.
Overrides:
getIdentitySelectString in interface Dialect
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

getResultSet

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

getSelectGUIDString

public String getSelectGUIDString()
Get the command used to select a GUID from the underlying database.

Optional operation.

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

getTableComment

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

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.

openQuote

public char openQuote()
The character specific to this dialect used to begin a quoted identifier.
Overrides:
openQuote in interface Dialect
Returns:
The dialect's specific open quote character.

performTemporaryTableDDLInIsolation

public 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.

JDBC defines a standard way to query for this information via the java.sql.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:

  • Boolean.TRUE - Unequivocally, perform the temporary table DDL in isolation.
  • Boolean.FALSE - Unequivocally, do not perform the temporary table DDL in isolation.
  • null - defer to the JDBC driver response in regards to java.sql.DatabaseMetaData.dataDefinitionCausesTransactionCommit()
Overrides:
performTemporaryTableDDLInIsolation in interface Dialect
Returns:
see the result matrix above.

qualifyIndexName

public boolean qualifyIndexName()
Do we need to qualify index names with the schema name?
Overrides:
qualifyIndexName in interface Dialect
Returns:
boolean

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.

registerVarcharTypes

protected void registerVarcharTypes()

supportsCascadeDelete

public boolean supportsCascadeDelete()
Overrides:
supportsCascadeDelete 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

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.

supportsIfExistsBeforeTableName

public boolean supportsIfExistsBeforeTableName()
Overrides:
supportsIfExistsBeforeTableName in interface Dialect

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.

supportsLobValueChangePropogation

public boolean supportsLobValueChangePropogation()
Overrides:
supportsLobValueChangePropogation in interface Dialect
Returns:
True if the changes are propogated back to the database; false otherwise.
Since:
3.2

supportsRowValueConstructorSyntax

public boolean supportsRowValueConstructorSyntax()
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 interface Dialect
Returns:
True if this SQL dialect is known to support "row value constructor" syntax; false otherwise.
Since:
3.2

supportsSubqueryOnMutatingTable

public boolean supportsSubqueryOnMutatingTable()
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:

  • delete from TABLE_A where ID not in ( select ID from TABLE_A )
  • update TABLE_A set NON_ID = 'something' where ID in ( select ID from TABLE_A)
Overrides:
supportsSubqueryOnMutatingTable in interface Dialect
Returns:
True if this dialect allows references the mutating table from a subquery.

supportsTemporaryTables

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