use of org.jnosql.diana.api.document.DocumentQuery in project jnosql-diana-driver by eclipse.
the class DefaultOrientDBDocumentCollectionManagerAsync method delete.
@Override
public void delete(DocumentDeleteQuery query, Consumer<Void> callBack) throws ExecuteAsyncQueryException, UnsupportedOperationException {
requireNonNull(query, "query is required");
requireNonNull(callBack, "callBack is required");
ODatabaseDocumentTx tx = pool.acquire();
DocumentQuery selectQuery = new OrientDBDocumentQuery(query);
QueryOSQLFactory.QueryResult orientQuery = toAsync(selectQuery, l -> {
l.forEach(ORecordAbstract::delete);
callBack.accept(null);
});
tx.command(orientQuery.getQuery()).execute(orientQuery.getParams());
}
use of org.jnosql.diana.api.document.DocumentQuery in project jnosql-diana-driver by eclipse.
the class MongoDBDocumentCollectionManagerAsync method select.
@Override
public void select(DocumentQuery query, Consumer<List<DocumentEntity>> callBack) throws ExecuteAsyncQueryException, UnsupportedOperationException {
String collectionName = query.getDocumentCollection();
MongoCollection<Document> collection = asyncMongoDatabase.getCollection(collectionName);
Bson mongoDBQuery = query.getCondition().map(DocumentQueryConversor::convert).orElse(EMPTY);
List<DocumentEntity> entities = new CopyOnWriteArrayList<>();
FindIterable<Document> result = collection.find(mongoDBQuery);
Block<Document> documentBlock = d -> entities.add(createEntity(collectionName, d));
SingleResultCallback<Void> voidSingleResultCallback = (v, e) -> callBack.accept(entities);
result.forEach(documentBlock, voidSingleResultCallback);
}
use of org.jnosql.diana.api.document.DocumentQuery in project jnosql-diana-driver by eclipse.
the class QueryOSQLConverterTest method shouldNegate.
@Test
public void shouldNegate() {
DocumentQuery query = select().from("collection").where("city").not().eq("Assis").and("name").eq("Otavio").or("name").not().eq("Lucas").build();
QueryOSQLConverter.Query convert = QueryOSQLConverter.select(query);
String sql = convert.getQuery();
List<Object> values = convert.getParams();
assertEquals(3, values.size());
assertEquals("Assis", values.get(0));
assertEquals("Otavio", values.get(1));
assertEquals("Lucas", values.get(2));
assertEquals("SELECT FROM collection WHERE NOT (city = ?) AND name = ? OR NOT (name = ?)", sql);
}
use of org.jnosql.diana.api.document.DocumentQuery in project jnosql-diana-driver by eclipse.
the class QueryOSQLConverterTest method shouldSortDesc.
@Test
public void shouldSortDesc() {
DocumentQuery query = select().from("collection").orderBy("name").desc().build();
QueryOSQLConverter.Query convert = QueryOSQLConverter.select(query);
assertEquals("SELECT FROM collection ORDER BY name DESC", convert.getQuery());
}
use of org.jnosql.diana.api.document.DocumentQuery in project jnosql-diana-driver by eclipse.
the class QueryOSQLConverterTest method shouldPaginateWithLimit.
@Test
public void shouldPaginateWithLimit() {
DocumentQuery query = select().from("collection").limit(100).build();
QueryOSQLConverter.Query convert = QueryOSQLConverter.select(query);
assertEquals("SELECT FROM collection LIMIT 100", convert.getQuery());
}
Aggregations