Class AbstractMySQLDictionary

java.lang.Object
org.apache.openjpa.jdbc.sql.DBDictionary
org.apache.openjpa.jdbc.sql.AbstractMySQLDictionary
All Implemented Interfaces:
JoinSyntaxes, Configurable, IdentifierConfiguration, ConnectionDecorator, LoggingConnectionDecorator.SQLWarningHandler
Direct Known Subclasses:
MariaDBDictionary, MySQLDictionary

public abstract class AbstractMySQLDictionary extends DBDictionary
Base dictionary for the MySQL family of databases (MySQL and MariaDB), which share the SQL dialect, the DDL types and the behaviour of their JDBC drivers that this dictionary deals with. The differences, such as the reserved words, the version dependent features and the error codes, are left to the subclasses.
  • Field Details

    • DELIMITER_BACK_TICK

      public static final String DELIMITER_BACK_TICK
      See Also:
    • tableType

      public String tableType
      The 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.
    • tinyBlobTypeName

      public static final String tinyBlobTypeName
      See Also:
    • mediumBlobTypeName

      public static final String mediumBlobTypeName
      See Also:
    • longBlobTypeName

      public static final String longBlobTypeName
      See Also:
    • tinyTextTypeName

      public static final String tinyTextTypeName
      See Also:
    • mediumTextTypeName

      public static final String mediumTextTypeName
      See Also:
    • longTextTypeName

      public static final String longTextTypeName
      See Also:
  • Constructor Details

    • AbstractMySQLDictionary

      public AbstractMySQLDictionary()
  • Method Details

    • addUpdatedReservedWords

      protected void addUpdatedReservedWords(Collection<String> words)
      Adds words that the database reserves to the invalid column words and to the reserved words, as far as they are missing there (OPENJPA-3074). The compatibility option UpdatedReservedWords=false removes the words that were added here again, so that the names keep the form an earlier release generated.
      See Also:
    • addUpdatedReservedTableWords

      protected void addUpdatedReservedTableWords(Collection<String> words)
      Adds words that the database reserves in a table name, and that are either invalid column words already or valid column names, to the reserved words only, as far as they are missing there (OPENJPA-3074). The compatibility option UpdatedReservedWords=false removes them again, as the updated reserved words.
    • usesUpdatedReservedWords

      protected boolean usesUpdatedReservedWords()
      Whether the updated reserved words and reserved table words are in use, which the compatibility option UpdatedReservedWords=false turns off. Known once the configuration is set.
    • delimitsReservedWords

      protected abstract boolean delimitsReservedWords()
      Whether a table, column or other name that is a reserved word is delimited in the SQL, so that it keeps its name, rather than renamed, e.g. with a 0 appended.
    • setConfiguration

      public void setConfiguration(Configuration conf)
      Removes the updated reserved words if the compatibility options ask for the earlier names. This has to happen before the naming rules are configured, which take a copy of the words.
      Specified by:
      setConfiguration in interface Configurable
      Overrides:
      setConfiguration in class DBDictionary
    • configureNamingRules

      protected void configureNamingRules()
      Makes the normalizing rule of this dictionary delimit the reserved words if delimitsReservedWords(), so that an identifier named for this dictionary keeps a name that is such a word. The rule is this dictionary's own, the identifiers of other dictionaries of the JVM are not affected.
      Overrides:
      configureNamingRules in class DBDictionary
    • getSelectHint

      protected abstract String getSelectHint()
      The name of the fetch configuration hint whose value is appended after the SELECT keyword of a query.
      See Also:
    • getMaxDecimalScale

      protected abstract int getMaxDecimalScale()
      The largest scale of a decimal column the database allows.
    • useFractionalSecondTemporalTypes

      protected void useFractionalSecondTemporalTypes()
      Use the temporal types with a fraction of a second, which MySQL has from 5.7 and MariaDB from 10.2 on.
    • getExtractDateTimeFieldFunction

      public String getExtractDateTimeFieldFunction(DateTimeExtractField extField)
      EXTRACT(WEEK) counts weeks from Sunday; mode 3 of WEEK gives the ISO week that JPA defines. EXTRACT(SECOND) returns the whole seconds only; the fraction of the second that JPA includes is added from EXTRACT(MICROSECOND).
      Overrides:
      getExtractDateTimeFieldFunction in class DBDictionary
    • setLocalTime

      public void setLocalTime(PreparedStatement stmnt, int idx, LocalTime val, Column col) throws SQLException
      Time has no fraction of a second, so a LocalTime is passed to and read from the driver as it is, keeping the fraction that a TIME(6) column or EXTRACT(SECOND) holds.
      Overrides:
      setLocalTime in class DBDictionary
      Throws:
      SQLException
    • getLocalTime

      public LocalTime getLocalTime(ResultSet rs, int column) throws SQLException
      Description copied from class: DBDictionary
      Retrieve the specified column of the SQL ResultSet to the proper LocalTime java type.
      Overrides:
      getLocalTime 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
    • 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 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
    • 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:
    • indexOf

      public void indexOf(SQLBuffer buf, FilterValue str, FilterValue find, FilterValue start)
      Description copied from class: DBDictionary
      Invoke this database's indexOf function.
      Overrides:
      indexOf in class DBDictionary
      Parameters:
      buf - the SQL buffer to write the indexOf invocation to
      str - a query value representing the target string
      find - a query value representing the search string
      start - a query value representing the start index, or null to start at the beginning
    • appendNullsPrecedence

      public void appendNullsPrecedence(SQLBuffer ordering, int nullPrecedence)
      MySQL / MariaDB do not support ANSI SQL NULLS FIRST / NULLS LAST. Emulate via an auxiliary &lt;expr&gt; IS NULL sort key.

      The default NULL ordering places NULLs before non-NULLs when sorting ASC and after non-NULLs when sorting DESC. When the requested precedence already matches that default, nothing extra is emitted. Otherwise the last order term &lt;expr&gt; ASC|DESC is rewritten to &lt;expr&gt; IS NULL &lt;sort&gt;, &lt;expr&gt; ASC|DESC.

      Overrides:
      appendNullsPrecedence in class DBDictionary
      Parameters:
      ordering - the in-progress ORDER BY buffer
      nullPrecedence - QueryExpressions.NULLS_FIRST or QueryExpressions.NULLS_LAST
    • toJDBCEscapedDateTimeLiteral

      public String toJDBCEscapedDateTimeLiteral(String escape, int parseType)
      MySQL Connector/J and MariaDB Connector/J translate a JDBC escaped date-time literal into a string literal, so that COALESCE or CASE with a date-time column has a string result. A SQL standard typed literal keeps the date-time type.
      Overrides:
      toJDBCEscapedDateTimeLiteral in class DBDictionary