use of io.micronaut.data.runtime.operations.internal.DBOperation 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();
});
}
use of io.micronaut.data.runtime.operations.internal.DBOperation in project micronaut-data by micronaut-projects.
the class DefaultJdbcRepositoryOperations method update.
@NonNull
@Override
public <T> T update(@NonNull UpdateOperation<T> operation) {
final AnnotationMetadata annotationMetadata = operation.getAnnotationMetadata();
final Class<?> repositoryType = operation.getRepositoryType();
SqlQueryBuilder queryBuilder = queryBuilders.getOrDefault(repositoryType, DEFAULT_SQL_BUILDER);
DBOperation dbOperation = new StoredQuerySqlOperation(queryBuilder, operation.getStoredQuery());
return executeWrite(connection -> {
JdbcOperationContext ctx = new JdbcOperationContext(annotationMetadata, repositoryType, queryBuilder.dialect(), connection);
JdbcEntityOperations<T> op = new JdbcEntityOperations<>(ctx, getEntity(operation.getRootEntity()), operation.getEntity(), dbOperation);
op.update();
return op.getEntity();
});
}
use of io.micronaut.data.runtime.operations.internal.DBOperation in project micronaut-data by micronaut-projects.
the class DefaultR2dbcRepositoryOperations method updateOne.
@Override
public <T> Mono<T> updateOne(R2dbcOperationContext ctx, T value, RuntimePersistentEntity<T> persistentEntity) {
DBOperation childSqlUpdateOperation = resolveEntityUpdate(ctx.annotationMetadata, ctx.repositoryType, value.getClass(), persistentEntity);
R2dbcEntityOperations<T> op = new R2dbcEntityOperations<>(ctx, persistentEntity, value, childSqlUpdateOperation);
op.update();
return op.getEntity();
}
use of io.micronaut.data.runtime.operations.internal.DBOperation in project micronaut-data by micronaut-projects.
the class DefaultR2dbcRepositoryOperations method persistManyAssociation.
@Override
public Mono<Void> persistManyAssociation(R2dbcOperationContext ctx, RuntimeAssociation runtimeAssociation, Object value, RuntimePersistentEntity<Object> persistentEntity, Object child, RuntimePersistentEntity<Object> childPersistentEntity) {
DBOperation dbInsertOperation = resolveSqlInsertAssociation(ctx.repositoryType, ctx.dialect, runtimeAssociation, persistentEntity, value);
R2dbcEntityOperations<Object> assocEntityOp = new R2dbcEntityOperations<>(ctx, childPersistentEntity, child, dbInsertOperation);
try {
assocEntityOp.execute();
} catch (Exception e1) {
throw new DataAccessException("SQL error executing INSERT: " + e1.getMessage(), e1);
}
return assocEntityOp.getEntity().then();
}
use of io.micronaut.data.runtime.operations.internal.DBOperation in project micronaut-data by micronaut-projects.
the class DefaultR2dbcRepositoryOperations method persistBatch.
@Override
public <T> Flux<T> persistBatch(R2dbcOperationContext ctx, Iterable<T> values, RuntimePersistentEntity<T> persistentEntity, Predicate<T> predicate) {
DBOperation childSqlPersistOperation = resolveEntityInsert(ctx.annotationMetadata, ctx.repositoryType, persistentEntity.getIntrospection().getBeanType(), persistentEntity);
R2dbcEntitiesOperations<T> op = new R2dbcEntitiesOperations<>(ctx, childSqlPersistOperation, persistentEntity, values, true);
if (predicate != null) {
op.veto(predicate);
}
op.persist();
return op.getEntities();
}
Aggregations