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