use of com.couchbase.client.java.query.N1qlQueryRow in project sling by apache.
the class CouchbaseNoSqlAdapter method getChildren.
@Override
public Iterator<NoSqlData> getChildren(String parentPath) {
Bucket bucket = couchbaseClient.getBucket();
// fetch all direct children of this path
N1qlQuery query = N1qlQuery.simple(select("*").from(couchbaseClient.getBucketName()).where(x(PN_PARENT_PATH).eq(s(parentPath))), N1QL_PARAMS);
N1qlQueryResult queryResult = bucket.query(query);
handleQueryError(queryResult);
final Iterator<N1qlQueryRow> results = queryResult.iterator();
return new Iterator<NoSqlData>() {
@Override
public boolean hasNext() {
return results.hasNext();
}
@Override
public NoSqlData next() {
JsonObject item = results.next().value();
JsonObject envelope = item.getObject(couchbaseClient.getBucketName());
String path = envelope.getString(PN_PATH);
JsonObject data = envelope.getObject(PN_DATA);
return new NoSqlData(path, data.toMap(), MultiValueMode.LISTS);
}
@Override
public void remove() {
throw new UnsupportedOperationException();
}
};
}
use of com.couchbase.client.java.query.N1qlQueryRow in project sling by apache.
the class CouchbaseNoSqlAdapter method deleteRecursive.
@Override
public boolean deleteRecursive(String path) {
Bucket bucket = couchbaseClient.getBucket();
// fetch all descendants and self for deletion
Pattern descendantsAndSelf = Pattern.compile("^" + path + "(/.+)?$");
N1qlQuery query = N1qlQuery.simple(select("*").from(couchbaseClient.getBucketName()).where("REGEXP_LIKE(`" + PN_PATH + "`, '" + descendantsAndSelf.pattern() + "')"), N1QL_PARAMS);
N1qlQueryResult queryResult = bucket.query(query);
handleQueryError(queryResult);
final Iterator<N1qlQueryRow> results = queryResult.iterator();
boolean deletedAny = false;
while (results.hasNext()) {
JsonObject item = results.next().value();
JsonObject envelope = item.getObject(couchbaseClient.getBucketName());
String itemPath = envelope.getString(PN_PATH);
String itemCacheKey = CouchbaseKey.build(itemPath, cacheKeyPrefix);
bucket.remove(itemCacheKey);
deletedAny = true;
}
return deletedAny;
}
Aggregations