Class SqlBatchSupport

java.lang.Object
io.micronaut.data.runtime.operations.internal.sql.SqlBatchSupport

@Internal public final class SqlBatchSupport extends Object
Shared SQL batch-operation capability checks.

Micronaut Data uses Dialect.MYSQL for both MySQL and MariaDB SQL generation. Runtime driver behavior can still diverge, so runtime capability checks stay internal and separate from the public dialect enum.

MySQL and MariaDB are told apart by the product and driver names reported by JDBC metadata. The supportsBatchUpdates flag keeps drivers that do not advertise batch support on the conservative path. The supportsGetGeneratedKeys flag determines whether a MySQL batch may read generated keys; it does not guarantee that a driver returns one key per inserted row. Both MySQL Connector/J and the MariaDB driver report these flags generally, so they cannot by themselves describe all batched generated-key behavior.

Since:
5.2.0
  • Method Details

    • isSupportsBatchInsert

      public static boolean isSupportsBatchInsert(PersistentEntity persistentEntity, SqlStoredQuery<?,?> sqlStoredQuery)
      Resolves whether insert batching is supported for a stored query.
      Parameters:
      persistentEntity - The persistent entity
      sqlStoredQuery - The SQL stored query
      Returns:
      true if insert batching is supported
    • isSupportsBatchInsert

      public static boolean isSupportsBatchInsert(PersistentEntity persistentEntity, Dialect dialect)
      Resolves whether insert batching is supported for a SQL dialect.
      Parameters:
      persistentEntity - The persistent entity
      dialect - The SQL dialect
      Returns:
      true if insert batching is supported
    • resolveJdbcBatchInsertMode

      public static SqlBatchSupport.JdbcBatchInsertMode resolveJdbcBatchInsertMode(PersistentEntity persistentEntity, Dialect dialect, SqlBatchSupport.JdbcBatchMetadata metadata, boolean requiresGeneratedKeys)
      Resolves how a JDBC insert batch operation has to be executed.

      Only the MySQL dialect can resolve to SqlBatchSupport.JdbcBatchInsertMode.BATCH_WITHOUT_GENERATED_KEYS. Every other dialect keeps its previous behavior of reading generated keys back whenever the entity has a generated identity.

      Parameters:
      persistentEntity - The persistent entity
      dialect - The SQL dialect
      metadata - The JDBC metadata of the connection
      requiresGeneratedKeys - Whether generated keys are needed back from the batch
      Returns:
      The batch insert mode
    • requiresBatchGeneratedKeys

      public static boolean requiresBatchGeneratedKeys(RuntimePersistentEntity<?> persistentEntity, InsertBatchOperation<?> operation)
      Resolves whether a batch insert operation needs generated keys to be returned.
      Parameters:
      persistentEntity - The runtime persistent entity
      operation - The insert batch operation
      Returns:
      true if generated keys must be requested