net.java.ao.db
Class MySQLDatabaseProvider

java.lang.Object
  extended by net.java.ao.DatabaseProvider
      extended by net.java.ao.db.MySQLDatabaseProvider

public final class MySQLDatabaseProvider
extends DatabaseProvider

Author:
Daniel Spiewak

Nested Class Summary
 
Nested classes/interfaces inherited from class net.java.ao.DatabaseProvider
DatabaseProvider.SqlListener
 
Field Summary
 
Fields inherited from class net.java.ao.DatabaseProvider
logger, schema, sqlLogger
 
Constructor Summary
MySQLDatabaseProvider(DisposableDataSource dataSource)
           
 
Method Summary
protected  boolean considerPrecision(DDLField field)
          Determines whether or not the database allows explicit precisions for the field in question.
protected  String convertTypeToString(DatabaseType<?> type)
          Converts the specified type into the database-specific DDL String value.
protected  Set<String> getReservedWords()
          Retrieves the set of all reserved words for the underlying database.
 boolean isCaseSensetive()
          Flag indicating whether or not the underlying database uses case-sensetive identifiers.
protected  String renderAppend()
          Generates any database-specific options which must be appended to the end of a table definition.
protected  String renderAutoIncrement()
          Generates the DDL fragment required to specify an INTEGER field as auto-incremented.
protected  String renderCreateIndex(DDLIndex index)
          Generates the database-specific DDL statement required to create a new index.
protected  String renderFieldType(DDLField field)
          Renders the database-specific DDL type for the field in question.
 
Methods inherited from class net.java.ao.DatabaseProvider
addSqlListener, dispose, executeInsertReturningKey, executeUpdate, getConnection, getDateFormat, getFunctionNameForField, getMaxIDLength, getSchema, getSequences, getTables, getTriggerNameForField, handleBlob, handleUpdateError, insertReturningKey, isNumericType, onSql, parseValue, preparedStatement, preparedStatement, preparedStatement, processID, processWhereClause, putBoolean, putNull, quote, removeSqlListener, renderAction, renderAlterTableAddColumn, renderAlterTableAddKey, renderAlterTableChangeColumn, renderAlterTableChangeColumnStatement, renderAlterTableDropColumn, renderAlterTableDropKey, renderCalendar, renderConstraintsForTable, renderDropFunctions, renderDropIndex, renderDropSequences, renderDropTable, renderDropTriggers, renderField, renderFieldPrecision, renderForeignKey, renderFunction, renderFunctionForField, renderFunctions, renderInsert, renderOnUpdate, renderQuery, renderQueryGroupBy, renderQueryJoins, renderQueryLimit, renderQueryOrderBy, renderQuerySelect, renderQueryWhere, renderSequences, renderTable, renderTriggerForField, renderTriggers, renderUnique, renderValue, setPostConnectionProperties, setQueryResultSetProperties, setQueryStatementProperties, shorten, shouldQuoteID, withSchema
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MySQLDatabaseProvider

public MySQLDatabaseProvider(DisposableDataSource dataSource)
Method Detail

considerPrecision

protected boolean considerPrecision(DDLField field)
Description copied from class: DatabaseProvider

Determines whether or not the database allows explicit precisions for the field in question. This is to support databases such as Derby which do not support precisions for certain types. By default, this method returns true.

More often than not, all that is required for this determination is the type. As such, the method signature may change in a future release.

Overrides:
considerPrecision in class DatabaseProvider
Parameters:
field - The field for which precision should/shouldn't be rendered.
Returns:
true if precision should be rendered, otherwise false.

convertTypeToString

protected String convertTypeToString(DatabaseType<?> type)
Description copied from class: DatabaseProvider
Converts the specified type into the database-specific DDL String value. By default, this delegates to the DatabaseType#getDefaultName() method. Subclass implementations should be sure to make a super call in order to ensure that both default naming and future special cases are handled appropriately.

Overrides:
convertTypeToString in class DatabaseProvider
Parameters:
type - The type instance to convert to a DDL string.
Returns:
The database-specific DDL representation of the type (e.g. "VARCHAR").
See Also:
DatabaseType.getDefaultName()

renderAutoIncrement

protected String renderAutoIncrement()
Description copied from class: DatabaseProvider

Generates the DDL fragment required to specify an INTEGER field as auto-incremented. For databases which do not support such flags (which is just about every database exception MySQL), "" is an acceptable return value. This method should never return null as it would cause the field rendering method to throw a NullPointerException.

Overrides:
renderAutoIncrement in class DatabaseProvider

renderAppend

protected String renderAppend()
Description copied from class: DatabaseProvider

Generates any database-specific options which must be appended to the end of a table definition. The only database I am aware of which requires this is MySQL. For example:

CREATE TABLE test (
     id INTEGER NOT NULL AUTO_INCREMENT,
     name VARCHAR(45),
     PRIMARY KEY(id)
 ) ENGINE=InnoDB;

The "ENGINE=InnoDB" clause is what is returned by this method. The default implementation simply returns null, signifying that no append should be rendered.

Overrides:
renderAppend in class DatabaseProvider
Returns:
A DDL clause to be appended to the CREATE TABLE DDL, or null

renderFieldType

protected String renderFieldType(DDLField field)
Description copied from class: DatabaseProvider
Renders the database-specific DDL type for the field in question. This method merely delegates to the DatabaseProvider.convertTypeToString(DatabaseType) method, passing the field type. Thus, it is rarely necessary (if ever) to override this method. It may be deprecated in a future release.

Overrides:
renderFieldType in class DatabaseProvider
Parameters:
field - The field which contains the type to be rendered.
Returns:
The database-specific type DDL rendering.

renderCreateIndex

protected String renderCreateIndex(DDLIndex index)
Description copied from class: DatabaseProvider
Generates the database-specific DDL statement required to create a new index. The syntax for this operation is highly standardized and thus it is unlikely this method will be overridden. If the database in question does not support indexes, a warning should be printed to stderr and null returned.

Overrides:
renderCreateIndex in class DatabaseProvider
Parameters:
index - The index to create. This single instance contains all of the data necessary to create the index, thus no separate parameters (such as a DDLTable) are required.
Returns:
A DDL statement to be executed, or null.

getReservedWords

protected Set<String> getReservedWords()
Description copied from class: DatabaseProvider
Retrieves the set of all reserved words for the underlying database. The set returns should be speculative, meaning that it should include any possible reserved words, not just those for a particular version. As an implementation guideline, the Set instance returned from this method should guarentee O(1) lookup times, otherwise ORM performance will suffer greatly.

Specified by:
getReservedWords in class DatabaseProvider
Returns:
A set of upper case reserved words specific to the database.

isCaseSensetive

public boolean isCaseSensetive()
Description copied from class: DatabaseProvider
Flag indicating whether or not the underlying database uses case-sensetive identifiers. This specifically affects comparisons in the SchemaReader utility. The default value is true. Note that databases which support both case-sensetive and case-insensetive identifiers (like MySQL) should return true for better all-around compatibility.

Overrides:
isCaseSensetive in class DatabaseProvider
Returns:
boolean true if identifiers are case-sensetive, false otherwise.


Copyright © 2007-2011. All Rights Reserved.