net.java.ao.db
Class MySQLDatabaseProvider

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

public class MySQLDatabaseProvider
extends DatabaseProvider

Author:
Daniel Spiewak

Constructor Summary
MySQLDatabaseProvider(String uri, String username, String password)
           
 
Method Summary
protected  String convertTypeToString(DatabaseType<?> type)
          Converts the specified type into the database-specific DDL String value.
 Class<? extends Driver> getDriverClass()
          Returns the JDBC Driver class which corresponds to the database being abstracted.
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.
 
Methods inherited from class net.java.ao.DatabaseProvider
considerPrecision, dispose, executeInsertReturningKey, getConnection, getConnectionImpl, getDateFormat, getFunctionNameForField, getInstance, getInstance, getPassword, getTables, getTriggerNameForField, getURI, getUsername, insertReturningKey, isNumericType, parseValue, putNull, renderAction, renderAlterTableAddColumn, renderAlterTableAddKey, renderAlterTableChangeColumn, renderAlterTableChangeColumnStatement, renderAlterTableDropColumn, renderAlterTableDropKey, renderCalendar, renderConstraintsForTable, renderDropFunctions, renderDropIndex, renderDropSequences, renderDropTable, renderDropTriggers, renderField, renderFieldPrecision, renderFieldType, renderForeignKey, renderFunction, renderFunctionForField, renderFunctions, renderOnUpdate, renderQuery, renderQueryGroupBy, renderQueryJoins, renderQueryLimit, renderQueryOrderBy, renderQuerySelect, renderQueryWhere, renderSequences, renderTable, renderTriggerForField, renderTriggers, renderUnique, renderValue, setPostConnectionProperties, setQueryResultSetProperties, setQueryStatementProperties
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MySQLDatabaseProvider

public MySQLDatabaseProvider(String uri,
                             String username,
                             String password)
Method Detail

getDriverClass

public Class<? extends Driver> getDriverClass()
                                       throws ClassNotFoundException
Description copied from class: DatabaseProvider

Returns the JDBC Driver class which corresponds to the database being abstracted. This should be implemented in such a way as to initialize and register the driver with JDBC. For most drivers, this requires code in the following form:

public Class<? extends Driver> getDriverClass() {
     return (Class<? extends Driver>) Class.forName("com.mysql.jdbc.Driver");
 }

The following does not fire the driver's static initializer and thus will (usually) not work:

public Class<? extends Driver> getDriverClass() {
     return com.mysql.jdbc.Driver.class;
 }

If the driver is not on the classpath, a ClassNotFoundException can and should be thrown (certain auto-magic configuration sections of ActiveObjects depend upon this under certain circumstances).

Specified by:
getDriverClass in class DatabaseProvider
Returns:
The JDBC Driver implementation which corresponds to the relevant database.
Throws:
ClassNotFoundException

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.

This method is abstract (as opposed to the other methods which are either defined against MySQL or simply empty) because of the vast differences in rendering auto-incremented fields across different databases. Also, it seemed like a terribly good idea at the time and I haven't found a compelling reason to change it.

Specified by:
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

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.