org.unitils.core.dbsupport
Class MySqlDbSupport

java.lang.Object
  extended by org.unitils.core.dbsupport.DbSupport
      extended by org.unitils.core.dbsupport.MySqlDbSupport

public class MySqlDbSupport
extends DbSupport

Implementation of DbSupport for a MySql database.

Note: by default MySql uses '`' (back-quote) for quoting identifiers. '"' (double quotes) is only supported in MySql if ANSI_QUOTES sql mode is enabled. Quoting identifiers does not make them case-sensitive. Case-sensitivity is platform dependent. E.g. on UNIX systems identifiers will typically be case-sensitive, on Windows platforms they will be converted to lower-case.

Trigger names are an exception to this: they are always case-sensitive.

Author:
Frederick Beernaert, Filip Neven, Tim Ducheyne

Field Summary
 
Fields inherited from class org.unitils.core.dbsupport.DbSupport
PROPKEY_IDENTIFIER_QUOTE_STRING, PROPKEY_STORED_IDENTIFIER_CASE
 
Constructor Summary
MySqlDbSupport()
          Creates support for MySql databases.
 
Method Summary
 void disableReferentialConstraints()
          Disables all referential constraints (e.g. foreign keys) on all table in the schema
protected  void disableReferentialConstraints(String tableName)
           
 void disableValueConstraints()
          Disables all value constraints (e.g. not null) on all tables in the schema
protected  void disableValueConstraints(String tableName)
           
 Set<String> getColumnNames(String tableName)
          Gets the names of all columns of the given table.
 Set<String> getIdentityColumnNames(String tableName)
          Gets the names of all identity columns of the given table.
 Set<String> getTableNames()
          Returns the names of all tables in the database.
 Set<String> getTriggerNames()
          Retrieves the names of all the triggers in the database schema.
 Set<String> getViewNames()
          Retrieves the names of all the views in the database schema.
 void incrementIdentityColumnToValue(String tableName, String primaryKeyColumnName, long identityValue)
          Increments the identity value for the specified primary key on the specified table to the given value.
 boolean supportsCascade()
          Cascade are supported.
 boolean supportsIdentityColumns()
          Identity columns are supported.
 boolean supportsTriggers()
          Triggers are supported.
 String toCorrectCaseIdentifier(String identifier)
          Converts the given identifier to uppercase/lowercase

MySql does not treat quoted identifiers as case sensitive.

 
Methods inherited from class org.unitils.core.dbsupport.DbSupport
dropMaterializedView, dropSequence, dropSynonym, dropTable, dropTrigger, dropType, dropView, getDatabaseDialect, getIdentifierQuoteString, getLongDataType, getMaterializedViewNames, getSchemaName, getSequenceNames, getSequenceValue, getSQLHandler, getStoredIdentifierCase, getSynonymNames, getTextDataType, getTypeNames, incrementSequenceToValue, init, qualified, quoted, supportsMaterializedViews, supportsSequences, supportsSynonyms, supportsTypes
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MySqlDbSupport

public MySqlDbSupport()
Creates support for MySql databases.

Method Detail

getTableNames

public Set<String> getTableNames()
Returns the names of all tables in the database.

Specified by:
getTableNames in class DbSupport
Returns:
The names of all tables in the database

getColumnNames

public Set<String> getColumnNames(String tableName)
Gets the names of all columns of the given table.

Specified by:
getColumnNames in class DbSupport
Parameters:
tableName - The table, not null
Returns:
The names of the columns of the table with the given name

getViewNames

public Set<String> getViewNames()
Retrieves the names of all the views in the database schema.

Specified by:
getViewNames in class DbSupport
Returns:
The names of all views in the database

getTriggerNames

public Set<String> getTriggerNames()
Retrieves the names of all the triggers in the database schema.

Overrides:
getTriggerNames in class DbSupport
Returns:
The names of all triggers in the database

disableReferentialConstraints

public void disableReferentialConstraints()
Disables all referential constraints (e.g. foreign keys) on all table in the schema

Specified by:
disableReferentialConstraints in class DbSupport

disableReferentialConstraints

protected void disableReferentialConstraints(String tableName)

disableValueConstraints

public void disableValueConstraints()
Disables all value constraints (e.g. not null) on all tables in the schema

Specified by:
disableValueConstraints in class DbSupport

disableValueConstraints

protected void disableValueConstraints(String tableName)

getIdentityColumnNames

public Set<String> getIdentityColumnNames(String tableName)
Gets the names of all identity columns of the given table.

Overrides:
getIdentityColumnNames in class DbSupport
Parameters:
tableName - The table, not null
Returns:
The names of the identity columns of the table with the given name

incrementIdentityColumnToValue

public void incrementIdentityColumnToValue(String tableName,
                                           String primaryKeyColumnName,
                                           long identityValue)
Increments the identity value for the specified primary key on the specified table to the given value.

Overrides:
incrementIdentityColumnToValue in class DbSupport
Parameters:
tableName - The table with the identity column, not null
primaryKeyColumnName - The column, not null
identityValue - The new value

toCorrectCaseIdentifier

public String toCorrectCaseIdentifier(String identifier)
Converts the given identifier to uppercase/lowercase

MySql does not treat quoted identifiers as case sensitive. These will also be converted to the correct case.

KNOWN ISSUE: MySql trigger names are case-sensitive (even if not quoted). This will incorrectly be converted to the stored identifier case

Overrides:
toCorrectCaseIdentifier in class DbSupport
Parameters:
identifier - The identifier, not null
Returns:
The name converted to correct case if needed, not null

supportsTriggers

public boolean supportsTriggers()
Triggers are supported.

Overrides:
supportsTriggers in class DbSupport
Returns:
True

supportsIdentityColumns

public boolean supportsIdentityColumns()
Identity columns are supported.

Overrides:
supportsIdentityColumns in class DbSupport
Returns:
True

supportsCascade

public boolean supportsCascade()
Cascade are supported.

Overrides:
supportsCascade in class DbSupport
Returns:
True


Copyright © 2011. All Rights Reserved.