org.apache.openjpa.jdbc.sql
Class MySQLDictionary

java.lang.Object
  extended by org.apache.openjpa.jdbc.sql.DBDictionary
      extended by org.apache.openjpa.jdbc.sql.MySQLDictionary
All Implemented Interfaces:
JoinSyntaxes, Configurable, IdentifierConfiguration, ConnectionDecorator, LoggingConnectionDecorator.SQLWarningHandler

public class MySQLDictionary
extends DBDictionary

Dictionary for MySQL.


Nested Class Summary
 
Nested classes/interfaces inherited from class org.apache.openjpa.jdbc.sql.DBDictionary
DBDictionary.SerializedData
 
Field Summary
static String DELIMITER_BACK_TICK
           
 boolean driverDeserializesBlobs
          Whether the driver automatically deserializes blobs.
static String longBlobTypeName
           
static String mediumBlobTypeName
           
 boolean optimizeMultiTableDeletes
          Whether to inline multi-table bulk-delete operations into MySQL's combined DELETE FROM foo, bar, baz syntax.
static String SELECT_HINT
           
 String tableType
          The MySQL table type to use when creating tables; defaults to innodb.
static String tinyBlobTypeName
           
 boolean useClobs
          Whether to use clobs; defaults to true.
 
Fields inherited from class org.apache.openjpa.jdbc.sql.DBDictionary
allowsAliasInBulkClause, arrayTypeName, autoAssignClause, autoAssignTypeName, batchLimit, bigintTypeName, binaryTypeName, bitLengthFunction, bitTypeName, blobBufferSize, blobTypeName, booleanTypeName, castFunction, catalogSeparator, CENTI, characterColumnSize, charTypeName, clobBufferSize, clobTypeName, closePoolSQL, concatenateDelimiter, concatenateFunction, conf, connected, CONS_NAME_AFTER, CONS_NAME_BEFORE, CONS_NAME_MID, constraintNameMode, createPrimaryKeys, crossJoinClause, currentDateFunction, currentTimeFunction, currentTimestampFunction, datePrecision, dateTypeName, DECI, decimalTypeName, delimitedCase, distinctCountColumnSeparator, distinctTypeName, doubleTypeName, driverVendor, dropTableSQL, fixedSizeTypeNames, fixedSizeTypeNameSet, floatTypeName, forUpdateClause, getStringVal, inClauseLimit, initializationSQL, innerJoinClause, integerTypeName, invalidColumnWordSet, isJDBC3, javaObjectTypeName, joinSyntax, lastGeneratedKeyQuery, leadingDelimiter, log, longVarbinaryTypeName, longVarcharTypeName, maxAutoAssignNameLength, maxColumnNameLength, maxConstraintNameLength, maxEmbeddedBlobSize, maxEmbeddedClobSize, maxIndexesPerTable, maxIndexNameLength, maxTableNameLength, MICRO, MILLI, NAME_ANY, NAME_SEQUENCE, NAME_TABLE, nameConcatenator, NANO, nativeSequenceType, nextSequenceQuery, NO_BATCH, nullTypeName, numericTypeName, otherTypeName, outerJoinClause, platform, RANGE_POST_DISTINCT, RANGE_POST_LOCK, RANGE_POST_SELECT, RANGE_PRE_DISTINCT, rangePosition, realTypeName, refTypeName, reportsSuccessNoInfoOnBatchUpdates, requiresAliasForSubselect, requiresAutoCommitForMetaData, requiresCastForComparisons, requiresCastForMathFunctions, requiresConditionForCrossJoin, requiresSearchStringEscapeForLike, requiresTargetForDelete, reservedWords, reservedWordSet, SCHEMA_CASE_LOWER, SCHEMA_CASE_PRESERVE, SCHEMA_CASE_UPPER, schemaCase, searchStringEscape, SEC, selectWords, selectWordSet, sequenceNameSQL, sequenceSchemaSQL, sequenceSQL, setStringRightTruncationOn, simulateLocking, smallintTypeName, sqlStateCodes, storageLimitationsFatal, storeCharsAsNumbers, storeLargeNumbersAsStrings, stringLengthFunction, structTypeName, substringFunctionName, supportsAlterTableWithAddColumn, supportsAlterTableWithDropColumn, supportsAutoAssign, supportsCascadeDeleteAction, supportsCascadeUpdateAction, supportsCaseConversionForLob, supportsComments, supportsCorrelatedSubselect, supportsDefaultDeleteAction, supportsDefaultUpdateAction, supportsDeferredConstraints, supportsDelimitedIdentifiers, supportsForeignKeys, supportsForeignKeysComposite, supportsGeneralCaseExpression, supportsGetGeneratedKeys, supportsHaving, supportsLockingWithDistinctClause, supportsLockingWithInnerJoin, supportsLockingWithMultipleTables, supportsLockingWithOrderClause, supportsLockingWithOuterJoin, supportsLockingWithSelectRange, supportsModOperator, supportsMultipleNontransactionalResultSets, supportsNullDeleteAction, supportsNullTableForGetColumns, supportsNullTableForGetImportedKeys, supportsNullTableForGetIndexInfo, supportsNullTableForGetPrimaryKeys, supportsNullUpdateAction, supportsParameterInSelect, supportsQueryTimeout, supportsRestrictDeleteAction, supportsRestrictUpdateAction, supportsSchemaForGetColumns, supportsSchemaForGetTables, supportsSelectEndIndex, supportsSelectForUpdate, supportsSelectFromFinalTable, supportsSelectStartIndex, supportsSimpleCaseExpression, supportsSubselect, supportsUniqueConstraints, supportsXMLColumn, systemSchemas, systemSchemaSet, systemTables, systemTableSet, tableForUpdateClause, tableTypes, timestampTypeName, timeTypeName, tinyintTypeName, toLowerCaseFunction, toUpperCaseFunction, trailingDelimiter, trimBothFunction, trimLeadingFunction, trimSchemaName, trimTrailingFunction, typeModifierSet, UNLIMITED, useGetBestRowIdentifierForPrimaryKeys, useGetBytesForBlobs, useGetObjectForBlobs, useGetStringForClobs, useSchemaName, useSetBytesForBlobs, useSetStringForClobs, useWildCardForCount, validationSQL, varbinaryTypeName, varcharTypeName, VENDOR_DATADIRECT, VENDOR_OTHER, xmlTypeEncoding, xmlTypeName
 
Fields inherited from interface org.apache.openjpa.jdbc.sql.JoinSyntaxes
SYNTAX_DATABASE, SYNTAX_SQL92, SYNTAX_TRADITIONAL
 
Constructor Summary
MySQLDictionary()
           
 
Method Summary
protected  void appendSelectRange(SQLBuffer buf, long start, long end, boolean subselect)
          If this dictionary can select ranges, use this method to append the range SQL.
 void appendXmlComparison(SQLBuffer buf, String op, FilterValue lhs, FilterValue rhs, boolean lhsxml, boolean rhsxml)
          Append XML comparison.
 void connectedConfiguration(Connection conn)
          This method is called when the dictionary first sees any connection.
 Connection decorate(Connection conn)
          Decorate the given connection if needed.
 String[] getAddPrimaryKeySQL(PrimaryKey pk)
          Return a series of SQL statements to add the given primary key to its table.
 int getBatchFetchSize(int batchFetchSize)
           
 Object getBlobObject(ResultSet rs, int column, JDBCStore store)
          Convert the specified column of the SQL ResultSet to the proper java type.
 String[] getCreateTableSQL(Table table)
          Return a series of SQL statements to create the given table, complete with columns.
 String[] getDeleteTableContentsSQL(Table[] tables, Connection conn)
          Create SQL to delete the contents of the specified tables.
 String[] getDropForeignKeySQL(ForeignKey fk, Connection conn)
          Return ALTER TABLE <table name> DROP FOREIGN KEY <fk name>.
 String[] getDropIndexSQL(Index index)
          Return a series of SQL statements to drop the given index.
 String[] getDropPrimaryKeySQL(PrimaryKey pk)
          Return ALTER TABLE <table name> DROP PRIMARY KEY.
 int getPreferredType(int type)
          Return the preferred Types type for the given one.
 String getSelectOperation(JDBCFetchConfiguration fetch)
          Check to see if we have set the SELECT_HINT in the fetch configuration, and if so, append the MySQL hint after the "SELECT" part of the query.
protected  Collection<String> getSelectTableAliases(Select sel)
           
 String getTypeName(Column col)
          OPENJPA-740 Special case for MySql special column types, like LONGTEXT, LONGBLOG etc..
 boolean isFatalException(int subtype, SQLException ex)
          Determine if the given SQL Exception is fatal or recoverable (such as a timeout).
protected  int matchErrorState(Map<Integer,Set<String>> errorStates, SQLException ex)
          Determine the more appropriate type of store exception by matching the SQL Error State of the the given SQLException to the given Error States categorized by error types.
protected  Column newColumn(ResultSet colMeta)
          Create a new column from the information in the schema metadata.
 
Methods inherited from class org.apache.openjpa.jdbc.sql.DBDictionary
addCastAsType, addErrorCode, appendCast, appendLength, appendNumericCast, appendSelect, appendSize, appendUpdates, assertSupport, calculateValue, canOuterJoin, checkNameLength, closeDataSource, combineForeignKey, comment, comparison, configureNamingRules, convertSchemaCase, convertSchemaCase, copy, copy, createIndexIfNecessary, createIndexIfNecessary, deleteStream, delimitAll, endConfiguration, executeQuery, fromDBName, getAddColumnSQL, getAddForeignKeySQL, getArray, getAsciiStream, getBatchLimit, getBatchUpdateCount, getBigDecimal, getBigInteger, getBinaryStream, getBlob, getBoolean, getByte, getBytes, getCalendar, getCastFunction, getCastFunction, getCatalogNameForMetadata, getCatalogNameForMetadata, getChar, getCharacterStream, getClob, getClobString, getColumnDBName, getColumnIdentifier, getColumnNameForMetadata, getColumnNameForMetadata, getColumns, getColumns, getConversionKey, getCreateIndexSQL, getCreateSequenceSQL, getDate, getDate, getDeclareColumnSQL, getDefaultIdentifierRule, getDefaultSchemaName, getDeleteTargets, getDelimitedCase, getDelimitIdentifiers, getDouble, getDropColumnSQL, getDropSequenceSQL, getDropTableSQL, getFloat, getForeignKeyConstraintSQL, getForUpdateClause, getFrom, getFromSelect, getFullIdentifier, getFullName, getFullName, getFullName, getGeneratedKey, getGeneratedKeySequenceName, getIdentifierConcatenator, getIdentifierDelimiter, getIdentifierRule, getIdentifierRules, getImportedKeys, getImportedKeys, getImportedKeys, getImportedKeys, getIndexInfo, getIndexInfo, getInt, getInvalidColumnWordSet, getJDBCType, getJDBCType, getJDBCType, getKey, getLeadingDelimiter, getLOBStream, getLocale, getLog, getLong, getNamingUtil, getNumber, getObject, getPlaceholderValueString, getPrimaryKeyConstraintSQL, getPrimaryKeys, getPrimaryKeys, getPrimaryKeysFromBestRowIdentifier, getPrimaryKeysFromBestRowIdentifier, getPrimaryKeysFromGetPrimaryKeys, getPrimaryKeysFromGetPrimaryKeys, getRef, getSchemaCase, getSchemaNameForMetadata, getSchemaNameForMetadata, getSelects, getSequence, getSequences, getSequences, getSequencesSQL, getSequencesSQL, getShort, getString, getSupportsDelimitedIdentifiers, getSupportsXMLColumn, getTableNameForMetadata, getTableNameForMetadata, getTables, getTables, getTime, getTimestamp, getTrailingDelimiter, getTrimSchemaName, getTypeName, getUniqueConstraintSQL, getValidColumnName, getValidColumnName, getValidColumnName, getValidColumnName, getValidForeignKeyName, getValidForeignKeyName, getValidIndexName, getValidIndexName, getValidPrimaryKeyName, getValidSequenceName, getValidSequenceName, getValidTableName, getValidTableName, getValidUniqueName, getValidUniqueName, getVersionColumn, getVersionColumn, getWhere, getXMLTypeEncoding, handleWarning, indexOf, insertBlobForStreamingLoad, insertClobForStreamingLoad, insertSize, isSelect, isSystemIndex, isSystemIndex, isSystemSequence, isSystemSequence, isSystemTable, isSystemTable, makeNameValid, makeNameValid, makeNameValid, makeNameValid, mathFunction, narrow, needsToCreateIndex, newForeignKey, newIndex, newPrimaryKey, newSequence, newStoreException, newTable, prepareStatement, putBytes, putChars, putString, refSchemaComponents, serialize, setArray, setAsciiStream, setBatchLimit, setBigDecimal, setBigInteger, setBinaryStream, setBlob, setBlobObject, setBoolean, setByte, setBytes, setCalendar, setChar, setCharacterStream, setClob, setClobString, setConfiguration, setDate, setDate, setDefaultSchemaName, setDelimitedCase, setDelimitIdentifiers, setDouble, setFloat, setInt, setJoinSyntax, setLeadingDelimiter, setLocale, setLong, setNull, setNumber, setObject, setQueryTimeout, setRef, setShort, setStatementQueryTimeout, setString, setSupportsDelimitedIdentifiers, setSupportsXMLColumn, setTime, setTimeouts, setTimeouts, setTimestamp, setTrailingDelimiter, setTrimSchemaName, setTyped, setUnknown, setXMLTypeEncoding, shorten, startConfiguration, storageWarning, substring, supportsDeferredForeignKeyConstraints, supportsDeferredUniqueConstraints, supportsDeleteAction, supportsIsolationForUpdate, supportsLocking, supportsRandomAccessResultSet, supportsUpdateAction, toBulkOperation, toDBName, toDBName, toDelete, toLong, toNativeJoin, toOperation, toOperation, toSelect, toSelect, toSelect, toSelect, toSelect, toSelectCount, toSQL92Join, toTraditionalJoin, toUpdate, updateBlob, updateClob, validateBatchProcess, validateDBSpecificBatchProcess
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

SELECT_HINT

public static final String SELECT_HINT
See Also:
Constant Field Values

DELIMITER_BACK_TICK

public static final String DELIMITER_BACK_TICK
See Also:
Constant Field Values

tableType

public String tableType
The MySQL table type to use when creating tables; defaults to innodb.


useClobs

public boolean useClobs
Whether to use clobs; defaults to true. Set this to false if you have an old version of MySQL which does not handle clobs properly.


driverDeserializesBlobs

public boolean driverDeserializesBlobs
Whether the driver automatically deserializes blobs.


optimizeMultiTableDeletes

public boolean optimizeMultiTableDeletes
Whether to inline multi-table bulk-delete operations into MySQL's combined DELETE FROM foo, bar, baz syntax. Defaults to false, since this may fail in the presence of InnoDB tables with foreign keys.

See Also:
http://dev.mysql.com/doc/refman/5.0/en/delete.html

tinyBlobTypeName

public static final String tinyBlobTypeName
See Also:
Constant Field Values

mediumBlobTypeName

public static final String mediumBlobTypeName
See Also:
Constant Field Values

longBlobTypeName

public static final String longBlobTypeName
See Also:
Constant Field Values
Constructor Detail

MySQLDictionary

public MySQLDictionary()
Method Detail

connectedConfiguration

public void connectedConfiguration(Connection conn)
                            throws SQLException
Description copied from class: DBDictionary
This method is called when the dictionary first sees any connection. It is used to initialize dictionary metadata if needed. If you override this method, be sure to call super.connectedConfiguration.

Overrides:
connectedConfiguration in class DBDictionary
Throws:
SQLException

decorate

public Connection decorate(Connection conn)
                    throws SQLException
Description copied from class: DBDictionary
Decorate the given connection if needed. Some databases require special handling for JDBC bugs. This implementation issues any DBDictionary.initializationSQL that has been set for the dictionary but does not decorate the connection.

Specified by:
decorate in interface ConnectionDecorator
Overrides:
decorate in class DBDictionary
Throws:
SQLException

getCreateTableSQL

public String[] getCreateTableSQL(Table table)
Description copied from class: DBDictionary
Return a series of SQL statements to create the given table, complete with columns. Indexes and constraints will be created separately.

Overrides:
getCreateTableSQL in class DBDictionary

getDropIndexSQL

public String[] getDropIndexSQL(Index index)
Description copied from class: DBDictionary
Return a series of SQL statements to drop the given index. Returns DROP INDEX <index name> by default.

Overrides:
getDropIndexSQL in class DBDictionary

getDropPrimaryKeySQL

public String[] getDropPrimaryKeySQL(PrimaryKey pk)
Return ALTER TABLE <table name> DROP PRIMARY KEY.

Overrides:
getDropPrimaryKeySQL in class DBDictionary

getDropForeignKeySQL

public String[] getDropForeignKeySQL(ForeignKey fk,
                                     Connection conn)
Return ALTER TABLE <table name> DROP FOREIGN KEY <fk name>.

Overrides:
getDropForeignKeySQL in class DBDictionary

getAddPrimaryKeySQL

public String[] getAddPrimaryKeySQL(PrimaryKey pk)
Description copied from class: DBDictionary
Return a series of SQL statements to add the given primary key to its table. Return an empty array if operation not supported. Returns ALTER TABLE <table name> ADD <pk cons sql > by default.

Overrides:
getAddPrimaryKeySQL in class DBDictionary

getDeleteTableContentsSQL

public String[] getDeleteTableContentsSQL(Table[] tables,
                                          Connection conn)
Description copied from class: DBDictionary
Create SQL to delete the contents of the specified tables. The default implementation drops all non-deferred RESTRICT foreign key constraints involving the specified tables, issues DELETE statements against the tables, and then adds the dropped constraints back in. Databases with more optimal ways of deleting the contents of several tables should override this method.

Overrides:
getDeleteTableContentsSQL in class DBDictionary

appendSelectRange

protected void appendSelectRange(SQLBuffer buf,
                                 long start,
                                 long end,
                                 boolean subselect)
Description copied from class: DBDictionary
If this dictionary can select ranges, use this method to append the range SQL.

Overrides:
appendSelectRange in class DBDictionary

newColumn

protected Column newColumn(ResultSet colMeta)
                    throws SQLException
Description copied from class: DBDictionary
Create a new column from the information in the schema metadata.

Overrides:
newColumn in class DBDictionary
Throws:
SQLException

getBlobObject

public Object getBlobObject(ResultSet rs,
                            int column,
                            JDBCStore store)
                     throws SQLException
Description copied from class: DBDictionary
Convert the specified column of the SQL ResultSet to the proper java type.

Overrides:
getBlobObject in class DBDictionary
Throws:
SQLException

getPreferredType

public int getPreferredType(int type)
Description copied from class: DBDictionary
Return the preferred Types type for the given one. Returns the given type by default.

Overrides:
getPreferredType in class DBDictionary

appendXmlComparison

public void appendXmlComparison(SQLBuffer buf,
                                String op,
                                FilterValue lhs,
                                FilterValue rhs,
                                boolean lhsxml,
                                boolean rhsxml)
Append XML comparison.

Overrides:
appendXmlComparison in class DBDictionary
Parameters:
buf - the SQL buffer to write the comparison
op - the comparison operation to perform
lhs - the left hand side of the comparison
rhs - the right hand side of the comparison
lhsxml - indicates whether the left operand maps to XML
rhsxml - indicates whether the right operand maps to XML

getBatchFetchSize

public int getBatchFetchSize(int batchFetchSize)
Overrides:
getBatchFetchSize in class DBDictionary

getSelectOperation

public String getSelectOperation(JDBCFetchConfiguration fetch)
Check to see if we have set the SELECT_HINT in the fetch configuration, and if so, append the MySQL hint after the "SELECT" part of the query.

Overrides:
getSelectOperation in class DBDictionary

getSelectTableAliases

protected Collection<String> getSelectTableAliases(Select sel)
Overrides:
getSelectTableAliases in class DBDictionary

matchErrorState

protected int matchErrorState(Map<Integer,Set<String>> errorStates,
                              SQLException ex)
Description copied from class: DBDictionary
Determine the more appropriate type of store exception by matching the SQL Error State of the the given SQLException to the given Error States categorized by error types. Dictionary subclass can override this method and extract SQLException data to figure out if the exception is recoverable.

Overrides:
matchErrorState in class DBDictionary
Parameters:
errorStates - classification of SQL error states by their specific nature. The keys of the map represent one of the constants defined in StoreException. The value corresponding to a key represent the set of SQL Error States representing specific category of database error. This supplied map is sourced from sql-error-state-codes.xml and filtered the error states for the current database.
ex - original SQL Exception as raised by the database driver.
Returns:
A constant indicating the category of error as defined in StoreException.

isFatalException

public boolean isFatalException(int subtype,
                                SQLException ex)
Description copied from class: DBDictionary
Determine if the given SQL Exception is fatal or recoverable (such as a timeout). This implementation always returns true (i.e. all exceptions are fatal). The current dictionary implementation can overwrite this method to mark certain exception conditions as recoverable error.

Overrides:
isFatalException in class DBDictionary
Parameters:
subtype - A constant indicating the category of error as defined in StoreException.
ex - original SQL Exception as raised by the database driver.
Returns:
false if the error is fatal.

getTypeName

public String getTypeName(Column col)
OPENJPA-740 Special case for MySql special column types, like LONGTEXT, LONGBLOG etc..

Overrides:
getTypeName in class DBDictionary
See Also:
DBDictionary.getTypeName(org.apache.openjpa.jdbc.schema.Column)


Copyright © 2006-2010 Apache Software Foundation. All Rights Reserved.