com.triactive.jdo.store.adapter
Class MysqlAdapter

java.lang.Object
  extended bycom.triactive.jdo.store.adapter.DatabaseAdapter
      extended bycom.triactive.jdo.store.adapter.MysqlAdapter

public class MysqlAdapter
extends DatabaseAdapter

Provides methods for adapting SQL language elements to the MySQL database.

Author:
Mike Martin

Field Summary
static java.lang.String NONSQL92_RESERVED_WORDS
          A string containing the list of MySQL keywords that are not also SQL/92 reserved words, separated by commas.
 
Fields inherited from class com.triactive.jdo.store.adapter.DatabaseAdapter
dbid, identifierQuoteString, keywords, maxCatalogNameLength, maxColumnNameLength, maxConstraintNameLength, maxCorrelationNameLength, maxIndexNameLength, maxSchemaNameLength, maxTableNameLength, storesLowerCaseIdentifiers, storesUpperCaseIdentifiers, supportsCorrelatedSubqueries, supportsGroupByUnrelated, supportsOrderByUnrelated, supportsSubqueriesInExists, supportsSubqueriesInIns, typeMappings, types
 
Constructor Summary
MysqlAdapter()
           
 
Method Summary
protected  void adaptTo(DatabaseIdentifier dbid, java.sql.DatabaseMetaData metadata)
          Initializes the database adapter based on the given JDBC metadata.
 SqlExpression cast(SqlExpression expr, java.lang.Class toType)
          Returns the appropriate SQL expression for casting an expression to another type.
 boolean createIndexesBeforeForeignKeys()
           
 java.lang.String getDropForeignKeyStatement(BaseTable table, ConstraintName fkName)
          Returns the appropriate SQL to drop a foreign key from its table.
protected  java.lang.String getQueryCurrentTimestampStatement()
          Returns a statement that will return a timestamp reflecting the database's current date and time.
 ColumnInfo newColumnInfo(java.sql.ResultSet rs)
          A factory for ColumnInfo objects.
 TypeInfo newTypeInfo(java.sql.ResultSet rs, int row)
          A factory for TypeInfo objects.
 boolean supportsDeferredConstraints()
           
 
Methods inherited from class com.triactive.jdo.store.adapter.DatabaseAdapter
avgFunction, bitTypeIsReallyBoolean, countFunction, createTypeInfo, getAddCandidateKeyStatement, getAddForeignKeyStatement, getAddPrimaryKeyStatement, getBestIdentifyingPatterns, getCreateIndexStatement, getCreateTableStatement, getCurrentTimestamp, getDropTableStatement, getDropViewStatement, getIdentifierQuoteString, getInstance, getMaxCatalogNameLength, getMaxColumnNameLength, getMaxConstraintNameLength, getMaxCorrelationNameLength, getMaxIndexNameLength, getMaxPreparedStatementParameters, getMaxSchemaNameLength, getMaxTableNameLength, getQueryCurrentSchemaNameStatement, getSchemaName, getSqlState, getTypeInfo, getTypeInfo, getUnlimitedLengthPrecisionValue, getVendorID, isBestAdapterFor, isEmbeddedType, isSqlKeyword, lengthMethod, mappingClassFor, mappingClassFor, maxFunction, minFunction, newColumnMapping, newDataStoreException, newForeignKeyInfo, newIndexInfo, newMapping, newMapping, newPrimaryKeyInfo, newQueryStatement, newQueryStatement, newQueryStatement, newTableExpression, newTableInfo, parseKeywordList, storesLowerCaseIdentifiers, storesUpperCaseIdentifiers, substringMethod, substringMethod, sumFunction, supportsBooleanComparison, supportsCorrelatedSubqueries, supportsGroupByUnrelated, supportsNullsInCandidateKeys, supportsOrderByUnrelated, supportsSubqueriesInExists, supportsSubqueriesInIns, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

NONSQL92_RESERVED_WORDS

public static final java.lang.String NONSQL92_RESERVED_WORDS
A string containing the list of MySQL keywords that are not also SQL/92 reserved words, separated by commas. This list is normally obtained dynamically from the driver using DatabaseMetaData.getSQLKeywords(), but MySQL drivers are known to return an incomplete list.

This list was produced based on the reserved word list in the MySQL Manual (Version 4.1).

See Also:
Constant Field Values
Constructor Detail

MysqlAdapter

public MysqlAdapter()
Method Detail

adaptTo

protected void adaptTo(DatabaseIdentifier dbid,
                       java.sql.DatabaseMetaData metadata)
                throws java.sql.SQLException
Description copied from class: DatabaseAdapter
Initializes the database adapter based on the given JDBC metadata. Called only once after an adapter object has been selected for use.

Overrides:
adaptTo in class DatabaseAdapter
Parameters:
dbid - the database identifier
metadata - the database metadata
Throws:
java.sql.SQLException

getQueryCurrentTimestampStatement

protected java.lang.String getQueryCurrentTimestampStatement()
Description copied from class: DatabaseAdapter
Returns a statement that will return a timestamp reflecting the database's current date and time. The statement is expected to return the timestamp in the first column of the first row of the result set. There is no generic SQL way to do this so the implementation in this class always throws UnsupportedOperationException.

Overrides:
getQueryCurrentTimestampStatement in class DatabaseAdapter
Returns:
a statement to return the name of the current schema.

newTypeInfo

public TypeInfo newTypeInfo(java.sql.ResultSet rs,
                            int row)
                     throws java.sql.SQLException
Description copied from class: DatabaseAdapter
A factory for TypeInfo objects. This method should always be used instead of directly constructing TypeInfo objects in order to give the DatabaseAdapter an opportunity to modify and/or correct the metadata obtained from the JDBC driver. The type information object is constructed from the current row of the given result set. The ResultSet object passed must have been obtained from a call to DatabaseMetaData.getTypeInfo().

The constructor only retrieves the values from the current row; the caller is required to advance to the next row with ResultSet.next().

Overrides:
newTypeInfo in class DatabaseAdapter
Parameters:
rs - The result set returned from DatabaseMetaData.getTypeInfo().
row - The current row number in the result set. The first row is 1.
Returns:
A TypeInfo object constructed from the current result set row, or null if the type indicated by this row should be excluded from use.
Throws:
java.sql.SQLException - If a database error occurs.

newColumnInfo

public ColumnInfo newColumnInfo(java.sql.ResultSet rs)
                         throws java.sql.SQLException
Description copied from class: DatabaseAdapter
A factory for ColumnInfo objects. This method should always be used instead of directly constructing ColumnInfo objects in order to give the DatabaseAdapter an opportunity to modify and/or correct the metadata obtained from the JDBC driver.

The column information object is constructed from the current row of the given result set. The result set passed must have been obtained from a call to DatabaseMetaData.getColumns().

The constructor only retrieves the values from the current row; the caller is required to advance to the next row with ResultSet.next().

Overrides:
newColumnInfo in class DatabaseAdapter
Parameters:
rs - The result set returned from DatabaseMetaData.getColumns().
Throws:
java.sql.SQLException - If a database error occurs.

createIndexesBeforeForeignKeys

public boolean createIndexesBeforeForeignKeys()
Overrides:
createIndexesBeforeForeignKeys in class DatabaseAdapter

supportsDeferredConstraints

public boolean supportsDeferredConstraints()
Overrides:
supportsDeferredConstraints in class DatabaseAdapter

getDropForeignKeyStatement

public java.lang.String getDropForeignKeyStatement(BaseTable table,
                                                   ConstraintName fkName)
Description copied from class: DatabaseAdapter
Returns the appropriate SQL to drop a foreign key from its table. It should return something like:

 ALTER TABLE FOO DROP CONSTRAINT FOO_FK1
 

Overrides:
getDropForeignKeyStatement in class DatabaseAdapter
Parameters:
table - The table from which to drop the foreign key.
fkName - The name of the foreign key to drop.
Returns:
The text of the SQL statement.

cast

public SqlExpression cast(SqlExpression expr,
                          java.lang.Class toType)
Description copied from class: DatabaseAdapter
Returns the appropriate SQL expression for casting an expression to another type. It should return something like:

 CAST(expr AS type)
 

Overrides:
cast in class DatabaseAdapter
Parameters:
expr - The expression to be cast.
toType - The Java type to cast it to.
Returns:
The resulting SQL expression.


Copyright © 2001-2007 The TJDO Project All Rights Reserved.