Search in sources :

Example 1 with Expression

use of com.couchbase.client.java.query.dsl.Expression in project jnosql-diana-driver by eclipse.

the class QueryConverter method delete.

static QueryConverterResult delete(DocumentDeleteQuery query, String bucket) {
    JsonObject params = JsonObject.create();
    List<String> ids = new ArrayList<>();
    Expression condition = getCondition(query.getCondition().orElseThrow(() -> new IllegalArgumentException("Condigtion is required")), params, ids, query.getDocumentCollection());
    MutateLimitPath statement = null;
    if (nonNull(condition)) {
        statement = Delete.deleteFrom(bucket).where(condition);
    }
    return new QueryConverterResult(params, statement, ids);
}
Also used : MutateLimitPath(com.couchbase.client.java.query.dsl.path.MutateLimitPath) Expression(com.couchbase.client.java.query.dsl.Expression) ArrayList(java.util.ArrayList) JsonObject(com.couchbase.client.java.document.json.JsonObject)

Example 2 with Expression

use of com.couchbase.client.java.query.dsl.Expression in project jnosql-diana-driver by eclipse.

the class QueryConverter method select.

static QueryConverterResult select(DocumentQuery query, String bucket) {
    JsonObject params = JsonObject.create();
    List<String> keys = new ArrayList<>();
    String[] documents = query.getDocuments().stream().toArray(String[]::new);
    if (documents.length == 0) {
        documents = ALL_SELECT;
    }
    Statement statement = null;
    int firstResult = (int) query.getFirstResult();
    int maxResult = (int) query.getMaxResults();
    com.couchbase.client.java.query.dsl.Sort[] sorts = query.getSorts().stream().map(SORT_MAP).toArray(com.couchbase.client.java.query.dsl.Sort[]::new);
    if (query.getCondition().isPresent()) {
        Expression condition = getCondition(query.getCondition().get(), params, keys, query.getDocumentCollection());
        if (nonNull(condition)) {
            statement = create(bucket, documents, firstResult, maxResult, sorts, condition);
        } else {
            statement = null;
        }
    } else {
        statement = create(bucket, documents, firstResult, maxResult, sorts);
    }
    return new QueryConverterResult(params, statement, keys);
}
Also used : Statement(com.couchbase.client.java.query.Statement) ArrayList(java.util.ArrayList) JsonObject(com.couchbase.client.java.document.json.JsonObject) Expression(com.couchbase.client.java.query.dsl.Expression) Sort(org.jnosql.diana.api.Sort)

Aggregations

JsonObject (com.couchbase.client.java.document.json.JsonObject)2 Expression (com.couchbase.client.java.query.dsl.Expression)2 ArrayList (java.util.ArrayList)2 Statement (com.couchbase.client.java.query.Statement)1 MutateLimitPath (com.couchbase.client.java.query.dsl.path.MutateLimitPath)1 Sort (org.jnosql.diana.api.Sort)1