use of io.jans.orm.exception.operation.DeleteException in project jans by JanssenProject.
the class SqlOperationServiceImpl method deleteImpl.
private long deleteImpl(TableMapping tableMapping, ConvertedExpression expression, int count) throws DeleteException {
try {
RelationalPathBase<Object> tableRelationalPath = buildTableRelationalPath(tableMapping);
SQLDeleteClause sqlDeleteQuery = this.sqlQueryFactory.delete(tableRelationalPath);
Predicate exp = (Predicate) expression.expression();
sqlDeleteQuery.where(exp);
if (count > 0) {
sqlDeleteQuery = sqlDeleteQuery.limit(count);
}
long rowDeleted = sqlDeleteQuery.execute();
return rowDeleted;
} catch (QueryException ex) {
throw new DeleteException(String.format("Failed to delete entries. Expression: '%s'", expression.expression()), ex);
}
}
use of io.jans.orm.exception.operation.DeleteException in project jans by JanssenProject.
the class CouchbaseOperationServiceImpl method deleteImpl.
private int deleteImpl(BucketMapping bucketMapping, String key, ScanConsistency scanConsistency, Expression expression, int count) throws DeleteException {
Bucket bucket = bucketMapping.getBucket();
Expression finalExpression = expression;
if (enableScopeSupport) {
Expression scopeExpression = Expression.path("META().id").like(Expression.s(key + "%"));
finalExpression = scopeExpression.and(expression);
}
MutateLimitPath deleteQuery = Delete.deleteFrom(Expression.i(bucketMapping.getBucketName())).where(finalExpression);
ReturningPath query = deleteQuery.limit(count);
LOG.debug("Execution query: '" + query + "'");
N1qlQueryResult result = bucket.query(N1qlQuery.simple(query, N1qlParams.build().consistency(scanConsistency)));
if (!result.finalSuccess()) {
throw new DeleteException(String.format("Failed to delete entries. Query: '%s'. Error: '%s', Error count: '%d'", query, result.errors(), result.info().errorCount()), result.errors().get(0).getInt("code"));
}
return result.info().mutationCount();
}
use of io.jans.orm.exception.operation.DeleteException in project jans by JanssenProject.
the class SpannerOperationServiceImpl method deleteImpl.
private long deleteImpl(TableMapping tableMapping, ConvertedExpression expression, int count) throws DeleteException {
try {
Table table = buildTable(tableMapping);
// select
PlainSelect sqlSelectQuery = new PlainSelect();
sqlSelectQuery.setFromItem(table);
// doc_id
Column selectDocIdColumn = new Column(tableAlias, DOC_ID);
SelectExpressionItem selectDocIdItem = new SelectExpressionItem(selectDocIdColumn);
sqlSelectQuery.addSelectItems(selectDocIdItem);
applyWhereExpression(sqlSelectQuery, expression);
long useCount = connectionProvider.getMaximumResultDeleteSize();
if (count > 0) {
useCount = Math.min(count, useCount);
}
Limit limit = new Limit();
limit.setRowCount(new LongValue(useCount));
sqlSelectQuery.setLimit(limit);
SubSelect subSelect = new SubSelect();
subSelect.setSelectBody(sqlSelectQuery);
subSelect.withUseBrackets(true);
Expression inExpression = new InExpression(selectDocIdColumn, subSelect);
Delete sqlDeleteQuery = new Delete();
sqlDeleteQuery.setTable(table);
sqlDeleteQuery.setWhere(inExpression);
Statement.Builder statementBuilder = Statement.newBuilder(sqlDeleteQuery.toString());
applyParametersBinding(statementBuilder, expression);
Statement statement = statementBuilder.build();
LOG.debug("Executing delete query: '{}'", statement);
Long rowDeleted = databaseClient.readWriteTransaction().run(new TransactionCallable<Long>() {
@Override
public Long run(TransactionContext transaction) throws Exception {
long rowCount = transaction.executeUpdate(statement);
return rowCount;
}
});
return rowDeleted;
} catch (SpannerException | IncompatibleTypeException ex) {
throw new DeleteException(String.format("Failed to delete entries. Expression: '%s'", expression.expression()), ex);
}
}
Aggregations