Search in sources :

Example 1 with ParameterizedN1qlQuery

use of com.couchbase.client.java.query.ParameterizedN1qlQuery in project neo4j-apoc-procedures by neo4j-contrib.

the class CouchbaseConnection method executeParametrizedStatement.

/**
 * Executes a N1QL statement with named parameters.
 *
 * @param statement
 *          the raw statement string to execute (containing named
 *          placeholders: $param1, $param2, ...)
 * @param parameterNames
 *          the placeholders' names in statement
 * @param parameterValues
 *          the values for the named placeholders in statement
 * @return the list of {@link JsonObject}s retrieved by this query
 *
 * @see N1qlQuery#parameterized(Statement, JsonObject)
 */
public List<JsonObject> executeParametrizedStatement(String statement, List<String> parameterNames, List<Object> parameterValues) {
    JsonObject namedParams = JsonObject.create();
    for (int param = 0; param < parameterNames.size(); param++) {
        namedParams.put(parameterNames.get(param), parameterValues.get(param));
    }
    ParameterizedN1qlQuery query = N1qlQuery.parameterized(statement, namedParams);
    return executeQuery(query);
}
Also used : JsonObject(com.couchbase.client.java.document.json.JsonObject) ParameterizedN1qlQuery(com.couchbase.client.java.query.ParameterizedN1qlQuery)

Example 2 with ParameterizedN1qlQuery

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

the class DefaultCouchbaseDocumentCollectionManager method delete.

@Override
public void delete(DocumentDeleteQuery query) {
    QueryConverter.QueryConverterResult delete = QueryConverter.delete(query, database);
    if (nonNull(delete.getStatement())) {
        ParameterizedN1qlQuery n1qlQuery = N1qlQuery.parameterized(delete.getStatement(), delete.getParams());
        bucket.query(n1qlQuery);
    }
    if (!delete.getKeys().isEmpty()) {
        delete.getKeys().stream().map(s -> getPrefix(query.getDocumentCollection(), s)).forEach(bucket::remove);
    }
}
Also used : Document(org.jnosql.diana.api.document.Document) EntityConverter.getPrefix(org.jnosql.diana.couchbase.document.EntityConverter.getPrefix) Statement(com.couchbase.client.java.query.Statement) ParameterizedN1qlQuery(com.couchbase.client.java.query.ParameterizedN1qlQuery) JsonObject(com.couchbase.client.java.document.json.JsonObject) ArrayList(java.util.ArrayList) JsonDocument(com.couchbase.client.java.document.JsonDocument) Duration(java.time.Duration) Objects.requireNonNull(java.util.Objects.requireNonNull) StreamSupport(java.util.stream.StreamSupport) Collectors.toSet(java.util.stream.Collectors.toSet) N1qlQueryResult(com.couchbase.client.java.query.N1qlQueryResult) KEY_FIELD(org.jnosql.diana.couchbase.document.EntityConverter.KEY_FIELD) Set(java.util.Set) DocumentDeleteQuery(org.jnosql.diana.api.document.DocumentDeleteQuery) DocumentQuery(org.jnosql.diana.api.document.DocumentQuery) Bucket(com.couchbase.client.java.Bucket) SearchQueryRow(com.couchbase.client.java.search.result.SearchQueryRow) List(java.util.List) DocumentEntity(org.jnosql.diana.api.document.DocumentEntity) N1qlQuery(com.couchbase.client.java.query.N1qlQuery) SearchQuery(com.couchbase.client.java.search.SearchQuery) Objects.nonNull(java.util.Objects.nonNull) ID_FIELD(org.jnosql.diana.couchbase.document.EntityConverter.ID_FIELD) EntityConverter.convert(org.jnosql.diana.couchbase.document.EntityConverter.convert) SearchQueryResult(com.couchbase.client.java.search.result.SearchQueryResult) ParameterizedN1qlQuery(com.couchbase.client.java.query.ParameterizedN1qlQuery)

Example 3 with ParameterizedN1qlQuery

use of com.couchbase.client.java.query.ParameterizedN1qlQuery in project neo4j-apoc-procedures by neo4j-contrib.

the class CouchbaseConnection method executeParametrizedStatement.

/**
 * Executes a N1QL statement with positional parameters.
 *
 * @param statement
 *          the raw statement string to execute (containing positional
 *          placeholders: $1, $2, ...)
 * @param parameters
 *          the values for the positional placeholders in statement
 * @return the list of {@link JsonObject}s retrieved by this query
 *
 * @see N1qlQuery#parameterized(Statement, JsonArray)
 */
public List<JsonObject> executeParametrizedStatement(String statement, List<Object> parameters) {
    JsonArray positionalParams = JsonArray.from(parameters);
    ParameterizedN1qlQuery query = N1qlQuery.parameterized(statement, positionalParams);
    return executeQuery(query);
}
Also used : JsonArray(com.couchbase.client.java.document.json.JsonArray) ParameterizedN1qlQuery(com.couchbase.client.java.query.ParameterizedN1qlQuery)

Example 4 with ParameterizedN1qlQuery

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

the class DefaultCouchbaseDocumentCollectionManager method select.

@Override
public List<DocumentEntity> select(DocumentQuery query) throws NullPointerException {
    QueryConverter.QueryConverterResult select = QueryConverter.select(query, database);
    List<DocumentEntity> entities = new ArrayList<>();
    if (nonNull(select.getStatement())) {
        ParameterizedN1qlQuery n1qlQuery = N1qlQuery.parameterized(select.getStatement(), select.getParams());
        N1qlQueryResult result = bucket.query(n1qlQuery);
        entities.addAll(convert(result, database));
    }
    if (!select.getKeys().isEmpty()) {
        entities.addAll(convert(select.getKeys(), bucket));
    }
    return entities;
}
Also used : DocumentEntity(org.jnosql.diana.api.document.DocumentEntity) ArrayList(java.util.ArrayList) ParameterizedN1qlQuery(com.couchbase.client.java.query.ParameterizedN1qlQuery) N1qlQueryResult(com.couchbase.client.java.query.N1qlQueryResult)

Aggregations

ParameterizedN1qlQuery (com.couchbase.client.java.query.ParameterizedN1qlQuery)4 JsonObject (com.couchbase.client.java.document.json.JsonObject)2 N1qlQueryResult (com.couchbase.client.java.query.N1qlQueryResult)2 ArrayList (java.util.ArrayList)2 DocumentEntity (org.jnosql.diana.api.document.DocumentEntity)2 Bucket (com.couchbase.client.java.Bucket)1 JsonDocument (com.couchbase.client.java.document.JsonDocument)1 JsonArray (com.couchbase.client.java.document.json.JsonArray)1 N1qlQuery (com.couchbase.client.java.query.N1qlQuery)1 Statement (com.couchbase.client.java.query.Statement)1 SearchQuery (com.couchbase.client.java.search.SearchQuery)1 SearchQueryResult (com.couchbase.client.java.search.result.SearchQueryResult)1 SearchQueryRow (com.couchbase.client.java.search.result.SearchQueryRow)1 Duration (java.time.Duration)1 List (java.util.List)1 Objects.nonNull (java.util.Objects.nonNull)1 Objects.requireNonNull (java.util.Objects.requireNonNull)1 Set (java.util.Set)1 Collectors.toSet (java.util.stream.Collectors.toSet)1 StreamSupport (java.util.stream.StreamSupport)1