use of io.micronaut.data.runtime.operations.internal.StoredQuerySqlOperation 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.StoredQuerySqlOperation 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.StoredQuerySqlOperation in project micronaut-data by micronaut-projects.
the class DefaultJdbcRepositoryOperations method persist.
@NonNull
@Override
public <T> T persist(@NonNull InsertOperation<T> operation) {
final AnnotationMetadata annotationMetadata = operation.getAnnotationMetadata();
final Class<?> repositoryType = operation.getRepositoryType();
SqlQueryBuilder queryBuilder = queryBuilders.getOrDefault(repositoryType, DEFAULT_SQL_BUILDER);
return executeWrite(connection -> {
JdbcOperationContext ctx = new JdbcOperationContext(annotationMetadata, repositoryType, queryBuilder.dialect(), connection);
JdbcEntityOperations<T> op = new JdbcEntityOperations<>(ctx, new StoredQuerySqlOperation(queryBuilder, operation.getStoredQuery()), getEntity(operation.getRootEntity()), operation.getEntity(), true);
op.persist();
return op;
}).getEntity();
}
use of io.micronaut.data.runtime.operations.internal.StoredQuerySqlOperation in project micronaut-data by micronaut-projects.
the class DefaultJdbcRepositoryOperations method deleteAll.
@Override
public <T> Optional<Number> deleteAll(@NonNull DeleteBatchOperation<T> operation) {
return Optional.ofNullable(executeWrite(connection -> {
SqlQueryBuilder queryBuilder = queryBuilders.getOrDefault(operation.getRepositoryType(), DEFAULT_SQL_BUILDER);
JdbcOperationContext ctx = new JdbcOperationContext(operation.getAnnotationMetadata(), operation.getRepositoryType(), queryBuilder.dialect(), connection);
Dialect dialect = queryBuilder.dialect();
RuntimePersistentEntity<T> persistentEntity = getEntity(operation.getRootEntity());
if (isSupportsBatchDelete(persistentEntity, dialect)) {
DBOperation dbOperation = new StoredQuerySqlOperation(queryBuilder, operation.getStoredQuery());
JdbcEntitiesOperations<T> op = new JdbcEntitiesOperations<>(ctx, getEntity(operation.getRootEntity()), operation, dbOperation);
op.delete();
return op.rowsUpdated;
}
return sum(operation.split().stream().map(deleteOp -> {
DBOperation dbOperation = new StoredQuerySqlOperation(queryBuilder, operation.getStoredQuery());
JdbcEntityOperations<T> op = new JdbcEntityOperations<>(ctx, getEntity(deleteOp.getRootEntity()), deleteOp.getEntity(), dbOperation);
op.delete();
return op.rowsUpdated;
}));
}));
}
use of io.micronaut.data.runtime.operations.internal.StoredQuerySqlOperation 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