Class MySQLSupport

All Implemented Interfaces:
DatabaseSupport
Direct Known Subclasses:
MariaDBSupport

public class MySQLSupport extends AbstractDatabaseSupport
MySQL-specific DatabaseSupport.

MySQL's JDBC driver maps most types onto standard JDBC types that the cross-database defaults already handle. The notable exception is JSON, which the driver reports as JDBCType.LONGVARCHAR (type name JSON); a random string would fail the server's JSON validation, so this support routes JSON columns to a JSON generator while leaving ordinary text columns on the default string generator.

Some MySQL types remain unsupported because they need value-aware or binary generation that standard JDBC metadata doesn't expose: ENUM/SET (must match the declared member list), GEOMETRY (well-known binary), and YEAR.

Since:
1.0.0
See Also:
  • Constructor Details

    • MySQLSupport

      public MySQLSupport()
      Creates the MySQL support with its default configuration.
  • Method Details

    • batchRewriteUrlParameter

      public String batchRewriteUrlParameter()
      Returns rewriteBatchedStatements, the MySQL Connector/J parameter that rewrites a batch of single-row INSERTs into one multi-row statement. Enabling it (e.g. jdbc:mysql://host/db?rewriteBatchedStatements=true) collapses many round trips into one and is often the single biggest fill speedup; Bloviate logs a one-time recommendation when a fill connection's URL does not set it.
      Returns:
      the rewriteBatchedStatements parameter name
      Since:
      2.10.0
    • supportsBulkLoad

      public boolean supportsBulkLoad()
      MySQL supports unordered bulk loading by disabling the session's foreign-key and unique checks.
      Returns:
      true
      Since:
      2.17.0
    • disableConstraints

      public BulkLoadHandle disableConstraints(Connection connection, Database database) throws SQLException
      Disables FOREIGN_KEY_CHECKS and UNIQUE_CHECKS for the session. These are ordinary session variables that need no special privilege. MySQL does not re-validate existing rows when the checks are turned back on, which is acceptable because bulk-loaded data is referentially consistent by construction.
      Parameters:
      connection - an open connection whose session variables are changed
      database - the database metadata (unused by this mechanism)
      Returns:
      a handle recording the disabled checks
      Throws:
      SQLException - if a statement fails
    • enableConstraints

      public void enableConstraints(Connection connection, Database database, BulkLoadHandle handle) throws SQLException
      Restores UNIQUE_CHECKS and FOREIGN_KEY_CHECKS to 1 for the session before the connection is returned to the pool.
      Parameters:
      connection - the same connection passed to disableConstraints(Connection, Database)
      database - the database metadata (unused by this mechanism)
      handle - the handle returned by disableConstraints(Connection, Database)
      Throws:
      SQLException - if a statement fails
    • configure

      protected void configure(Map<JDBCType, GeneratorFactory> registry)
      Description copied from class: AbstractDatabaseSupport
      Hook for subclasses to add or replace generator factories for specific JDBC types. The supplied registry already holds the cross-database defaults; subclasses with no customizations need not override this method. Implementations must not retain a reference to the map beyond the call.
      Overrides:
      configure in class AbstractDatabaseSupport
      Parameters:
      registry - the mutable registry to customize, keyed by JDBCType