use of io.micronaut.data.model.runtime.InsertBatchOperation in project micronaut-data by micronaut-projects.
the class DefaultJdbcRepositoryOperations method persistAll.
@NonNull
public <T> Iterable<T> persistAll(@NonNull InsertBatchOperation<T> operation) {
return executeWrite(connection -> {
final AnnotationMetadata annotationMetadata = operation.getAnnotationMetadata();
final Class<?> repositoryType = operation.getRepositoryType();
SqlQueryBuilder sqlQueryBuilder = queryBuilders.getOrDefault(repositoryType, DEFAULT_SQL_BUILDER);
DBOperation dbOperation = new StoredQuerySqlOperation(sqlQueryBuilder, operation.getStoredQuery());
final RuntimePersistentEntity<T> persistentEntity = getEntity(operation.getRootEntity());
JdbcOperationContext ctx = new JdbcOperationContext(annotationMetadata, repositoryType, sqlQueryBuilder.dialect(), connection);
if (!isSupportsBatchInsert(persistentEntity, sqlQueryBuilder.dialect())) {
return operation.split().stream().map(persistOp -> {
JdbcEntityOperations<T> op = new JdbcEntityOperations<>(ctx, dbOperation, persistentEntity, persistOp.getEntity(), true);
op.persist();
return op.getEntity();
}).collect(Collectors.toList());
} else {
JdbcEntitiesOperations<T> op = new JdbcEntitiesOperations<>(ctx, persistentEntity, operation, dbOperation, true);
op.persist();
return op.getEntities();
}
});
}
Aggregations