Class MySQLSupport
java.lang.Object
io.bloviate.ext.AbstractDatabaseSupport
io.bloviate.ext.MySQLSupport
- All Implemented Interfaces:
DatabaseSupport
- Direct Known Subclasses:
MariaDBSupport
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 Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionReturnsrewriteBatchedStatements, the MySQL Connector/J parameter that rewrites a batch of single-rowINSERTs into one multi-row statement.protected voidconfigure(Map<JDBCType, GeneratorFactory> registry) Hook for subclasses to add or replace generator factories for specific JDBC types.disableConstraints(Connection connection, Database database) DisablesFOREIGN_KEY_CHECKSandUNIQUE_CHECKSfor the session.voidenableConstraints(Connection connection, Database database, BulkLoadHandle handle) RestoresUNIQUE_CHECKSandFOREIGN_KEY_CHECKSto1for the session before the connection is returned to the pool.booleanMySQL supports unordered bulk loading by disabling the session's foreign-key and unique checks.Methods inherited from class AbstractDatabaseSupport
getDataGeneratorMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface DatabaseSupport
readConstraints
-
Constructor Details
-
MySQLSupport
public MySQLSupport()Creates the MySQL support with its default configuration.
-
-
Method Details
-
batchRewriteUrlParameter
ReturnsrewriteBatchedStatements, the MySQL Connector/J parameter that rewrites a batch of single-rowINSERTs 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
rewriteBatchedStatementsparameter 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 DisablesFOREIGN_KEY_CHECKSandUNIQUE_CHECKSfor 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 changeddatabase- 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 RestoresUNIQUE_CHECKSandFOREIGN_KEY_CHECKSto1for the session before the connection is returned to the pool.- Parameters:
connection- the same connection passed todisableConstraints(Connection, Database)database- the database metadata (unused by this mechanism)handle- the handle returned bydisableConstraints(Connection, Database)- Throws:
SQLException- if a statement fails
-
configure
Description copied from class:AbstractDatabaseSupportHook 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:
configurein classAbstractDatabaseSupport- Parameters:
registry- the mutable registry to customize, keyed byJDBCType
-