Package org.apache.openjpa.jdbc.sql
Class MySQLDictionary
- java.lang.Object
-
- org.apache.openjpa.jdbc.sql.DBDictionary
-
- 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.DateMillisecondBehaviors, DBDictionary.SerializedData
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.StringDELIMITER_BACK_TICKbooleandriverDeserializesBlobsWhether the driver automatically deserializes blobs.static java.lang.StringlongBlobTypeNamestatic java.lang.StringlongTextTypeNamestatic java.lang.StringmediumBlobTypeNamestatic java.lang.StringmediumTextTypeNamebooleanoptimizeMultiTableDeletesWhether to inline multi-table bulk-delete operations into MySQL's combinedDELETE FROM foo, bar, bazsyntax.static java.lang.StringSELECT_HINTjava.lang.StringtableTypeThe MySQL table type to use when creating tables; defaults to innodb.static java.lang.StringtinyBlobTypeNamestatic java.lang.StringtinyTextTypeNamebooleanuseClobsWhether to use clobs; defaults to true.-
Fields inherited from class org.apache.openjpa.jdbc.sql.DBDictionary
_procs, _proxyManager, allowQueryTimeoutOnFindUpdate, allowsAliasInBulkClause, arrayTypeName, autoAssignClause, autoAssignTypeName, batchLimit, bigintTypeName, binaryTypeName, bitLengthFunction, bitTypeName, blobBufferSize, blobTypeName, booleanRepresentation, 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, databaseProductName, databaseProductVersion, dateFractionDigits, datePrecision, dateTypeName, DECI, decimalTypeName, defaultSchemaName, delimitedCase, disableAlterSeqenceIncrementBy, disableSchemaFactoryColumnTypeErrors, distinctCountColumnSeparator, distinctTypeName, doubleTypeName, driverVendor, dropTableSQL, fixedSizeTypeNames, fixedSizeTypeNameSet, floatTypeName, forUpdateClause, fractionalTypeNameSet, fullResultCollectionInOrderByRelation, getStringVal, inClauseLimit, indexPhysicalForeignKeys, initializationSQL, innerJoinClause, integerTypeName, invalidColumnWordSet, isJDBC3, isJDBC4, javaObjectTypeName, javaToDbColumnNameProcessing, 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, roundTimeToMillisec, 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, supportsNullUniqueColumn, supportsNullUpdateAction, supportsParameterInSelect, supportsQueryTimeout, supportsRestrictDeleteAction, supportsRestrictUpdateAction, supportsSchemaForGetColumns, supportsSchemaForGetTables, supportsSelectEndIndex, supportsSelectForUpdate, supportsSelectFromFinalTable, supportsSelectStartIndex, supportsSimpleCaseExpression, supportsSubselect, supportsUniqueConstraints, supportsXMLColumn, systemSchemas, systemSchemaSet, systemTables, systemTableSet, tableForUpdateClause, tableLengthIncludesSchema, tableTypes, timestampTypeName, timestampWithZoneTypeName, timeTypeName, timeWithZoneTypeName, tinyintTypeName, toLowerCaseFunction, toUpperCaseFunction, trailingDelimiter, trimBothFunction, trimLeadingFunction, trimSchemaName, trimStringColumns, trimTrailingFunction, typeModifierSet, UNLIMITED, useGetBestRowIdentifierForPrimaryKeys, useGetBytesForBlobs, useGetObjectForBlobs, useGetStringForClobs, useJDBC4SetBinaryStream, useNativeSequenceCache, 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
Constructors Constructor Description MySQLDictionary()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidappendSelectRange(SQLBuffer buf, long start, long end, boolean subselect)If this dictionary can select ranges, use this method to append the range SQL.voidappendXmlComparison(SQLBuffer buf, java.lang.String op, FilterValue lhs, FilterValue rhs, boolean lhsxml, boolean rhsxml)Append XML comparison.voidconnectedConfiguration(java.sql.Connection conn)This method is called when the dictionary first sees any connection.java.sql.Connectiondecorate(java.sql.Connection conn)Decorate the given connection if needed.java.lang.String[]getAddPrimaryKeySQL(PrimaryKey pk)Return a series of SQL statements to add the given primary key to its table.intgetBatchFetchSize(int batchFetchSize)java.lang.ObjectgetBlobObject(java.sql.ResultSet rs, int column, JDBCStore store)Convert the specified column of the SQL ResultSet to the proper java type.java.lang.String[]getCreateTableSQL(Table table)Return a series of SQL statements to create the given table, complete with columns.java.lang.String[]getDeleteTableContentsSQL(Table[] tables, java.sql.Connection conn)Create SQL to delete the contents of the specified tables.java.lang.String[]getDropForeignKeySQL(ForeignKey fk, java.sql.Connection conn)ReturnALTER TABLE <table name> DROP FOREIGN KEY <fk name>.java.lang.String[]getDropIndexSQL(Index index)Return a series of SQL statements to drop the given index.java.lang.String[]getDropPrimaryKeySQL(PrimaryKey pk)ReturnALTER TABLE <table name> DROP PRIMARY KEY.intgetPreferredType(int type)Return the preferredTypestype for the given one.java.lang.StringgetSelectOperation(JDBCFetchConfiguration fetch)Check to see if we have set theSELECT_HINTin the fetch configuration, and if so, append the MySQL hint after the "SELECT" part of the query.protected java.util.Collection<java.lang.String>getSelectTableAliases(Select sel)java.lang.StringgetTypeName(Column col)OPENJPA-740 Special case for MySql special column types, like LONGTEXT, LONGBLOG etc..voidindexOf(SQLBuffer buf, FilterValue str, FilterValue find, FilterValue start)Invoke this database's indexOf function.booleanisFatalException(int subtype, java.sql.SQLException ex)Determine if the given SQL Exception is fatal or recoverable (such as a timeout).protected intmatchErrorState(java.util.Map<java.lang.Integer,java.util.Set<java.lang.String>> errorStates, java.sql.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 ColumnnewColumn(java.sql.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, applyRange, assertSupport, calculateValue, canOuterJoin, closeDataSource, combineForeignKey, comment, comparison, configureNamingRules, convertSchemaCase, convertSchemaCase, copy, copy, createIndexIfNecessary, createIndexIfNecessary, deleteStream, delimitAll, endConfiguration, executeQuery, fromDBName, getAddColumnSQL, getAddForeignKeySQL, getAlterSequenceSQL, getArray, getAsciiStream, getBatchLimit, getBatchUpdateCount, getBigDecimal, getBigInteger, getBinaryStream, getBlob, getBoolean, getBooleanRepresentation, getByte, getBytes, getCalendar, getCastFunction, getCastFunction, getCatalogNameForMetadata, getCatalogNameForMetadata, getChar, getCharacterStream, getClob, getClobString, getColumnDBName, getColumnIdentifier, getColumnNameForMetadata, getColumnNameForMetadata, getColumns, getColumns, getConversionKey, getCreateIndexSQL, getCreateSequenceSQL, getCreateTableSQL, getDate, getDate, getDateFractionDigits, getDeclareColumnSQL, getDefaultIdentifierRule, getDefaultSchemaName, getDeleteTargets, getDelimitedCase, getDelimitIdentifiers, getDouble, getDropColumnSQL, getDropSequenceSQL, getDropTableSQL, getFloat, getForeignKeyConstraintSQL, getForUpdateClause, getFrom, getFromSelect, getFullIdentifier, getFullName, getFullName, getFullName, getGeneratedKey, getGeneratedKeySequenceName, getGenKeySeqName, getIdentifierConcatenator, getIdentifierDelimiter, getIdentifierRule, getIdentifierRules, getIdentityColumnName, getImportedKeys, getImportedKeys, getImportedKeys, getImportedKeys, getIndexInfo, getIndexInfo, getInt, getInvalidColumnWordSet, getIsNotNullSQL, getIsNullSQL, getJDBCType, getJDBCType, getJDBCType, getKey, getLeadingDelimiter, getLOBStream, getLocalDate, getLocalDateTime, getLocale, getLocalTime, getLog, getLong, getMajorVersion, getMarkerForInsertUpdate, getMillisecondBehavior, getMinorVersion, getNamingUtil, getNumber, getObject, getOffsetDateTime, getOffsetTime, getPlaceholderValueString, getPrimaryKeyConstraintSQL, getPrimaryKeys, getPrimaryKeys, getPrimaryKeysFromBestRowIdentifier, getPrimaryKeysFromBestRowIdentifier, getPrimaryKeysFromGetPrimaryKeys, getPrimaryKeysFromGetPrimaryKeys, getRef, getSchemaCase, getSchemaNameForMetadata, getSchemaNameForMetadata, getSelects, getSequence, getSequences, getSequences, getSequencesSQL, getSequencesSQL, getShort, getStoredProcedure, 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, insertBlobForStreamingLoad, insertClobForStreamingLoad, insertSize, isImplicitJoin, isSelect, isSystemIndex, isSystemIndex, isSystemSequence, isSystemSequence, isSystemSequence, isSystemTable, isSystemTable, isUsingLimit, isUsingOffset, isUsingOrderBy, isUsingRange, makeNameValid, makeNameValid, makeNameValid, makeNameValid, mathFunction, needsToCreateIndex, needsToCreateIndex, newForeignKey, newIndex, newPrimaryKey, newSequence, newStoreException, newTable, prepareStatement, processDBColumnName, putBytes, putChars, putString, refSchemaComponents, serialize, setArray, setAsciiStream, setBatchLimit, setBigDecimal, setBigInteger, setBinaryStream, setBlob, setBlobObject, setBoolean, setBooleanRepresentation, setByte, setBytes, setCalendar, setChar, setCharacterStream, setClob, setClobString, setConfiguration, setDate, setDate, setDateMillisecondBehavior, setDefaultSchemaName, setDelimitedCase, setDelimitIdentifiers, setDouble, setFloat, setInt, setJoinSyntax, setLeadingDelimiter, setLocalDate, setLocalDateTime, setLocale, setLocalTime, setLong, setMajorVersion, setMinorVersion, setNull, setNumber, setObject, setOffsetDateTime, setOffsetTime, setQueryTimeout, setRef, setShort, setStatementQueryTimeout, setString, setSupportsDelimitedIdentifiers, setSupportsXMLColumn, setTime, setTimeouts, setTimeouts, setTimestamp, setTrailingDelimiter, setTrimSchemaName, setTyped, setUnknown, setUnknown, setXMLTypeEncoding, shorten, startConfiguration, storageWarning, substring, supportsDeferredForeignKeyConstraints, supportsDeferredUniqueConstraints, supportsDeleteAction, supportsIsolationForUpdate, supportsLocking, supportsRandomAccessResultSet, supportsUpdateAction, toBulkOperation, toDBName, toDBName, toDelete, toNativeJoin, toOperation, toOperation, toSelect, toSelect, toSelect, toSelect, toSelect, toSelectCount, toSnakeCase, toSQL92Join, toTraditionalJoin, toUpdate, updateBlob, updateClob, validateBatchProcess, validateDBSpecificBatchProcess, versionEqualOrEarlierThan, versionEqualOrLaterThan, versionLaterThan
-
-
-
-
Field Detail
-
SELECT_HINT
public static final java.lang.String SELECT_HINT
- See Also:
- Constant Field Values
-
DELIMITER_BACK_TICK
public static final java.lang.String DELIMITER_BACK_TICK
- See Also:
- Constant Field Values
-
tableType
public java.lang.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 combinedDELETE FROM foo, bar, bazsyntax. Defaults to false, since this may fail in the presence of InnoDB tables with foreign keys.
-
tinyBlobTypeName
public static final java.lang.String tinyBlobTypeName
- See Also:
- Constant Field Values
-
mediumBlobTypeName
public static final java.lang.String mediumBlobTypeName
- See Also:
- Constant Field Values
-
longBlobTypeName
public static final java.lang.String longBlobTypeName
- See Also:
- Constant Field Values
-
tinyTextTypeName
public static final java.lang.String tinyTextTypeName
- See Also:
- Constant Field Values
-
mediumTextTypeName
public static final java.lang.String mediumTextTypeName
- See Also:
- Constant Field Values
-
longTextTypeName
public static final java.lang.String longTextTypeName
- See Also:
- Constant Field Values
-
-
Method Detail
-
connectedConfiguration
public void connectedConfiguration(java.sql.Connection conn) throws java.sql.SQLExceptionDescription copied from class:DBDictionaryThis 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 callsuper.connectedConfiguration.- Overrides:
connectedConfigurationin classDBDictionary- Throws:
java.sql.SQLException
-
decorate
public java.sql.Connection decorate(java.sql.Connection conn) throws java.sql.SQLExceptionDescription copied from class:DBDictionaryDecorate the given connection if needed. Some databases require special handling for JDBC bugs. This implementation issues anyDBDictionary.initializationSQLthat has been set for the dictionary but does not decorate the connection.- Specified by:
decoratein interfaceConnectionDecorator- Overrides:
decoratein classDBDictionary- Throws:
java.sql.SQLException
-
getCreateTableSQL
public java.lang.String[] getCreateTableSQL(Table table)
Description copied from class:DBDictionaryReturn a series of SQL statements to create the given table, complete with columns. Indexes and constraints will be created separately.- Overrides:
getCreateTableSQLin classDBDictionary
-
getDropIndexSQL
public java.lang.String[] getDropIndexSQL(Index index)
Description copied from class:DBDictionaryReturn a series of SQL statements to drop the given index. ReturnsDROP INDEX <index name>by default.- Overrides:
getDropIndexSQLin classDBDictionary
-
getDropPrimaryKeySQL
public java.lang.String[] getDropPrimaryKeySQL(PrimaryKey pk)
ReturnALTER TABLE <table name> DROP PRIMARY KEY.- Overrides:
getDropPrimaryKeySQLin classDBDictionary
-
getDropForeignKeySQL
public java.lang.String[] getDropForeignKeySQL(ForeignKey fk, java.sql.Connection conn)
ReturnALTER TABLE <table name> DROP FOREIGN KEY <fk name>.- Overrides:
getDropForeignKeySQLin classDBDictionary
-
getAddPrimaryKeySQL
public java.lang.String[] getAddPrimaryKeySQL(PrimaryKey pk)
Description copied from class:DBDictionaryReturn a series of SQL statements to add the given primary key to its table. Return an empty array if operation not supported. ReturnsALTER TABLE <table name> ADD <pk cons sql >by default.- Overrides:
getAddPrimaryKeySQLin classDBDictionary
-
getDeleteTableContentsSQL
public java.lang.String[] getDeleteTableContentsSQL(Table[] tables, java.sql.Connection conn)
Description copied from class:DBDictionaryCreate 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:
getDeleteTableContentsSQLin classDBDictionary
-
appendSelectRange
protected void appendSelectRange(SQLBuffer buf, long start, long end, boolean subselect)
Description copied from class:DBDictionaryIf this dictionary can select ranges, use this method to append the range SQL.- Overrides:
appendSelectRangein classDBDictionary
-
newColumn
protected Column newColumn(java.sql.ResultSet colMeta) throws java.sql.SQLException
Description copied from class:DBDictionaryCreate a new column from the information in the schema metadata.- Overrides:
newColumnin classDBDictionary- Throws:
java.sql.SQLException
-
getBlobObject
public java.lang.Object getBlobObject(java.sql.ResultSet rs, int column, JDBCStore store) throws java.sql.SQLExceptionDescription copied from class:DBDictionaryConvert the specified column of the SQL ResultSet to the proper java type.- Overrides:
getBlobObjectin classDBDictionary- Throws:
java.sql.SQLException
-
getPreferredType
public int getPreferredType(int type)
Description copied from class:DBDictionaryReturn the preferredTypestype for the given one. Returns the given type by default.- Overrides:
getPreferredTypein classDBDictionary
-
appendXmlComparison
public void appendXmlComparison(SQLBuffer buf, java.lang.String op, FilterValue lhs, FilterValue rhs, boolean lhsxml, boolean rhsxml)
Append XML comparison.- Overrides:
appendXmlComparisonin classDBDictionary- Parameters:
buf- the SQL buffer to write the comparisonop- the comparison operation to performlhs- the left hand side of the comparisonrhs- the right hand side of the comparisonlhsxml- indicates whether the left operand maps to XMLrhsxml- indicates whether the right operand maps to XML
-
getBatchFetchSize
public int getBatchFetchSize(int batchFetchSize)
- Overrides:
getBatchFetchSizein classDBDictionary
-
getSelectOperation
public java.lang.String getSelectOperation(JDBCFetchConfiguration fetch)
Check to see if we have set theSELECT_HINTin the fetch configuration, and if so, append the MySQL hint after the "SELECT" part of the query.- Overrides:
getSelectOperationin classDBDictionary
-
getSelectTableAliases
protected java.util.Collection<java.lang.String> getSelectTableAliases(Select sel)
- Overrides:
getSelectTableAliasesin classDBDictionary
-
matchErrorState
protected int matchErrorState(java.util.Map<java.lang.Integer,java.util.Set<java.lang.String>> errorStates, java.sql.SQLException ex)Description copied from class:DBDictionaryDetermine 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:
matchErrorStatein classDBDictionary- Parameters:
errorStates- classification of SQL error states by their specific nature. The keys of the map represent one of the constants defined inStoreException. The value corresponding to a key represent the set of SQL Error States representing specific category of database error. This supplied map is sourced fromsql-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, java.sql.SQLException ex)Description copied from class:DBDictionaryDetermine 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:
isFatalExceptionin classDBDictionary- Parameters:
subtype- A constant indicating the category of error as defined inStoreException.ex- original SQL Exception as raised by the database driver.- Returns:
- false if the error is fatal.
-
getTypeName
public java.lang.String getTypeName(Column col)
OPENJPA-740 Special case for MySql special column types, like LONGTEXT, LONGBLOG etc..- Overrides:
getTypeNamein classDBDictionary- See Also:
DBDictionary.getTypeName(org.apache.openjpa.jdbc.schema.Column)
-
indexOf
public void indexOf(SQLBuffer buf, FilterValue str, FilterValue find, FilterValue start)
Description copied from class:DBDictionaryInvoke this database's indexOf function.- Overrides:
indexOfin classDBDictionary- Parameters:
buf- the SQL buffer to write the indexOf invocation tostr- a query value representing the target stringfind- a query value representing the search stringstart- a query value representing the start index, or null to start at the beginning
-
-