Search in sources :

Example 71 with DocumentQuery

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());
}
Also used : ORecordAbstract(com.orientechnologies.orient.core.record.ORecordAbstract) DocumentQuery(org.jnosql.diana.api.document.DocumentQuery) ODatabaseDocumentTx(com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx)

Example 72 with DocumentQuery

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);
}
Also used : FindIterable(com.mongodb.async.client.FindIterable) Document(org.bson.Document) MongoDBUtils.getDocument(org.jnosql.diana.mongodb.document.MongoDBUtils.getDocument) ExecuteAsyncQueryException(org.jnosql.diana.api.ExecuteAsyncQueryException) DocumentCollectionManagerAsync(org.jnosql.diana.api.document.DocumentCollectionManagerAsync) MongoCollection(com.mongodb.async.client.MongoCollection) DocumentDeleteQuery(org.jnosql.diana.api.document.DocumentDeleteQuery) BsonDocument(org.bson.BsonDocument) DocumentQuery(org.jnosql.diana.api.document.DocumentQuery) Bson(org.bson.conversions.Bson) Consumer(java.util.function.Consumer) List(java.util.List) Documents(org.jnosql.diana.api.document.Documents) Block(com.mongodb.Block) MongoDatabase(com.mongodb.async.client.MongoDatabase) DocumentEntity(org.jnosql.diana.api.document.DocumentEntity) Duration(java.time.Duration) DeleteResult(com.mongodb.client.result.DeleteResult) ID_FIELD(org.jnosql.diana.mongodb.document.MongoDBUtils.ID_FIELD) SingleResultCallback(com.mongodb.async.SingleResultCallback) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) DocumentEntity(org.jnosql.diana.api.document.DocumentEntity) Document(org.bson.Document) MongoDBUtils.getDocument(org.jnosql.diana.mongodb.document.MongoDBUtils.getDocument) BsonDocument(org.bson.BsonDocument) Bson(org.bson.conversions.Bson) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList)

Example 73 with DocumentQuery

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);
}
Also used : DocumentQuery(org.jnosql.diana.api.document.DocumentQuery) Test(org.junit.jupiter.api.Test)

Example 74 with DocumentQuery

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());
}
Also used : DocumentQuery(org.jnosql.diana.api.document.DocumentQuery) Test(org.junit.jupiter.api.Test)

Example 75 with DocumentQuery

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());
}
Also used : DocumentQuery(org.jnosql.diana.api.document.DocumentQuery) Test(org.junit.jupiter.api.Test)

Aggregations

DocumentQuery (org.jnosql.diana.api.document.DocumentQuery)201 Test (org.junit.jupiter.api.Test)186 DocumentEntity (org.jnosql.diana.api.document.DocumentEntity)95 Document (org.jnosql.diana.api.document.Document)84 List (java.util.List)50 DocumentDeleteQuery (org.jnosql.diana.api.document.DocumentDeleteQuery)46 Person (org.jnosql.artemis.model.Person)37 DocumentCondition (org.jnosql.diana.api.document.DocumentCondition)35 Arrays.asList (java.util.Arrays.asList)27 ArrayList (java.util.ArrayList)21 Duration (java.time.Duration)20 DocumentQueryBuilder.select (org.jnosql.diana.api.document.query.DocumentQueryBuilder.select)20 Optional (java.util.Optional)18 AtomicReference (java.util.concurrent.atomic.AtomicReference)18 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)18 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)17 DocumentQueryBuilder.delete (org.jnosql.diana.api.document.query.DocumentQueryBuilder.delete)17 BeforeEach (org.junit.jupiter.api.BeforeEach)17 Consumer (java.util.function.Consumer)16 Assertions.assertNotNull (org.junit.jupiter.api.Assertions.assertNotNull)16