Class SqlBatchSupport
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
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumHow a JDBC insert batch operation has to be executed.static final recordThe JDBC metadata used to resolve batch insert capabilities. -
Method Summary
Modifier and TypeMethodDescriptionstatic booleanisSupportsBatchInsert(PersistentEntity persistentEntity, Dialect dialect) Resolves whether insert batching is supported for a SQL dialect.static booleanisSupportsBatchInsert(PersistentEntity persistentEntity, SqlStoredQuery<?, ?> sqlStoredQuery) Resolves whether insert batching is supported for a stored query.static booleanrequiresBatchGeneratedKeys(RuntimePersistentEntity<?> persistentEntity, InsertBatchOperation<?> operation) Resolves whether a batch insert operation needs generated keys to be returned.resolveJdbcBatchInsertMode(PersistentEntity persistentEntity, Dialect dialect, SqlBatchSupport.JdbcBatchMetadata metadata, boolean requiresGeneratedKeys) Resolves how a JDBC insert batch operation has to be executed.
-
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 entitysqlStoredQuery- The SQL stored query- Returns:
trueif insert batching is supported
-
isSupportsBatchInsert
Resolves whether insert batching is supported for a SQL dialect.- Parameters:
persistentEntity- The persistent entitydialect- The SQL dialect- Returns:
trueif 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 entitydialect- The SQL dialectmetadata- The JDBC metadata of the connectionrequiresGeneratedKeys- 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 entityoperation- The insert batch operation- Returns:
trueif generated keys must be requested
-