Class MariaDBDictionary

All Implemented Interfaces:
JoinSyntaxes, Configurable, IdentifierConfiguration, ConnectionDecorator, LoggingConnectionDecorator.SQLWarningHandler

public class MariaDBDictionary extends AbstractMySQLDictionary
  • Field Details

  • Constructor Details

    • MariaDBDictionary

      public MariaDBDictionary()
  • Method Details

    • delimitsReservedWords

      protected boolean delimitsReservedWords()
      MariaDB delimits a name that is a reserved word, as MySQL does, unless the compatibility option UpdatedReservedWords=false asks for the earlier names, which append a 0 to such a name instead.
      Specified by:
      delimitsReservedWords in class AbstractMySQLDictionary
    • getSelectHint

      protected String getSelectHint()
      Description copied from class: AbstractMySQLDictionary
      The name of the fetch configuration hint whose value is appended after the SELECT keyword of a query.
      Specified by:
      getSelectHint in class AbstractMySQLDictionary
      See Also:
    • getMaxDecimalScale

      protected int getMaxDecimalScale()
      MariaDB allows a scale of 38; an unsized decimal column still gets a scale of 30, the largest scale MySQL allows, which keeps the DDL the same on both.
      Specified by:
      getMaxDecimalScale in class AbstractMySQLDictionary
    • 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
    • getCreateSequenceSQL

      public String[] getCreateSequenceSQL(Sequence seq)
      MariaDB caches 1000 increments of a sequence per server by default, and discards what is left of that range whenever the cache is flushed - an ALTER SEQUENCE, a restart - so the identifiers jump by up to 1000 * increment. OpenJPA caches values itself, in blocks of the generator's allocation size, and NativeJDBCSeq issues ALTER SEQUENCE ... INCREMENT BY once per sequence instance to do so, which is exactly such a flush: the server side cache adds nothing but those gaps. Create the sequence with NOCACHE.

      Measured on MariaDB 11.8 with a sequence created START WITH 100 INCREMENT BY 7: NEXTVAL returns 100 and leaves NEXT_NOT_CACHED_VALUE at 7100, and after ALTER SEQUENCE ... INCREMENT BY 7 the next NEXTVAL returns 7100; with NOCACHE the same statements return 100 and then 107.

      Overrides:
      getCreateSequenceSQL in class DBDictionary
    • getSequencesSQL

      protected String getSequencesSQL(String schemaName, String sequenceName)
      MariaDB has no INFORMATION_SCHEMA.SEQUENCES before 10.6; a sequence is listed in INFORMATION_SCHEMA.TABLES with a TABLE_TYPE of SEQUENCE in every version that has sequences at all. Schema names are matched case insensitively because DBDictionary.getSequences(DatabaseMetaData, String, String, String, Connection) upper cases the schema it passes, while MariaDB keeps the case of the schema as created.

      INFORMATION_SCHEMA spans every database on the server, not just the connected one, and every caller in OpenJPA asks for a null schema - SchemaGenerator.generateSequences() passes DBIdentifier.NULL deliberately, and an unqualified @SequenceGenerator has none. Unrestricted, the reflection would report sequences of other applications' databases, which makes the schema tool skip a CREATE SEQUENCE it owes and, on the drop side, issue DROP SEQUENCE outside the configured database. The no schema case is therefore scoped to DATABASE(), which takes no bind parameter and so leaves the parameter indices DBDictionary.getSequences(DatabaseMetaData, String, String, String, Connection) binds intact.

      Overrides:
      getSequencesSQL in class DBDictionary
    • getSequencesSQL

      protected String getSequencesSQL(DBIdentifier schemaName, DBIdentifier sequenceName)
      Overrides:
      getSequencesSQL in class DBDictionary
    • setDelimitedCase

      protected void setDelimitedCase(DatabaseMetaData metaData)
      Overrides:
      setDelimitedCase in class DBDictionary
    • 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
    • isReplicationConnection

      public boolean isReplicationConnection(Connection conn) throws SQLException
      Whether the given connection was opened by MariaDB Connector/J with a jdbc:mariadb:replication: URL, which routes the statements of a read-only connection to a replica. The driver reports that URL in the connection's metadata without a round trip to the server.
      Overrides:
      isReplicationConnection in class DBDictionary
      Parameters:
      conn - a connection of the store, possibly wrapped by OpenJPA's decorators
      Throws:
      SQLException
    • updateClob

      public void updateClob(Select sel, JDBCStore store, Reader reader) throws SQLException
      Write the reader with ResultSet.updateCharacterStream(int, Reader) instead of the writer of Clob.setCharacterStream(long). The Connector/J clob writer starts at a wrong position when the clob was read from a result set and fails with an ArrayIndexOutOfBoundsException.
      Overrides:
      updateClob in class DBDictionary
      Throws:
      SQLException
    • 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.
    • setTime

      public void setTime(PreparedStatement stmnt, int idx, Time val, Calendar cal, Column col) throws SQLException
      Description copied from class: DBDictionary
      Set the given value as a parameter to the statement.
      Overrides:
      setTime in class DBDictionary
      Throws:
      SQLException