Search in sources :

Example 1 with ReturningPath

use of com.couchbase.client.java.query.dsl.path.ReturningPath 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();
}
Also used : MutateLimitPath(com.couchbase.client.java.query.dsl.path.MutateLimitPath) Bucket(com.couchbase.client.java.Bucket) Expression(com.couchbase.client.java.query.dsl.Expression) DeleteException(io.jans.orm.exception.operation.DeleteException) ReturningPath(com.couchbase.client.java.query.dsl.path.ReturningPath) N1qlQueryResult(com.couchbase.client.java.query.N1qlQueryResult)

Aggregations

Bucket (com.couchbase.client.java.Bucket)1 N1qlQueryResult (com.couchbase.client.java.query.N1qlQueryResult)1 Expression (com.couchbase.client.java.query.dsl.Expression)1 MutateLimitPath (com.couchbase.client.java.query.dsl.path.MutateLimitPath)1 ReturningPath (com.couchbase.client.java.query.dsl.path.ReturningPath)1 DeleteException (io.jans.orm.exception.operation.DeleteException)1