Search in sources :

Example 21 with DocumentQuery

use of org.jnosql.diana.api.document.DocumentQuery in project jnosql-diana-driver by eclipse.

the class CouchbaseDocumentCollectionManagerAsyncTest method shouldInserAsyncTTL.

@Test
public void shouldInserAsyncTTL() throws InterruptedException {
    DocumentEntity entity = getEntity();
    entityManagerAsync.insert(entity, Duration.ofSeconds(1L));
    TimeUnit.SECONDS.sleep(2L);
    Document id = entity.find("name").get();
    DocumentQuery query = select().from(COLLECTION_NAME).where(id.getName()).eq(id.get()).build();
    List<DocumentEntity> entities = entityManager.select(query);
    assertTrue(entities.isEmpty());
}
Also used : DocumentQuery(org.jnosql.diana.api.document.DocumentQuery) DocumentEntity(org.jnosql.diana.api.document.DocumentEntity) Document(org.jnosql.diana.api.document.Document) Test(org.junit.jupiter.api.Test)

Example 22 with DocumentQuery

use of org.jnosql.diana.api.document.DocumentQuery in project jnosql-diana-driver by eclipse.

the class CouchbaseDocumentCollectionManagerAsyncTest method shouldRemoveEntityAsyncCallBack.

@Test
public void shouldRemoveEntityAsyncCallBack() {
    AtomicBoolean condition = new AtomicBoolean(false);
    AtomicReference<List<DocumentEntity>> references = new AtomicReference<>();
    DocumentEntity documentEntity = entityManager.insert(getEntity());
    Document id = documentEntity.find("name").get();
    DocumentQuery query = select().from(COLLECTION_NAME).where(id.getName()).eq(id.get()).build();
    DocumentDeleteQuery deleteQuery = delete().from(COLLECTION_NAME).where(id.getName()).eq(id.get()).build();
    entityManagerAsync.delete(deleteQuery, d -> {
        condition.set(true);
    });
    await().untilTrue(condition);
    entityManagerAsync.select(query, references::set);
    await().until(() -> references.get(), notNullValue());
    assertFalse(references.get().isEmpty());
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) DocumentQuery(org.jnosql.diana.api.document.DocumentQuery) DocumentEntity(org.jnosql.diana.api.document.DocumentEntity) List(java.util.List) AtomicReference(java.util.concurrent.atomic.AtomicReference) Document(org.jnosql.diana.api.document.Document) DocumentDeleteQuery(org.jnosql.diana.api.document.DocumentDeleteQuery) Test(org.junit.jupiter.api.Test)

Example 23 with DocumentQuery

use of org.jnosql.diana.api.document.DocumentQuery in project jnosql-diana-driver by eclipse.

the class CouchbaseDocumentCollectionManagerTest method shouldRemoveEntityByName.

@Test
public void shouldRemoveEntityByName() {
    DocumentEntity documentEntity = entityManager.insert(getEntity());
    Document name = documentEntity.find("name").get();
    DocumentQuery query = select().from(COLLECTION_NAME).where(name.getName()).eq(name.get()).build();
    DocumentDeleteQuery deleteQuery = DocumentQueryBuilder.delete().from(COLLECTION_NAME).where(name.getName()).eq(name.get()).build();
    entityManager.delete(deleteQuery);
    assertTrue(entityManager.select(query).isEmpty());
}
Also used : DocumentQuery(org.jnosql.diana.api.document.DocumentQuery) DocumentEntity(org.jnosql.diana.api.document.DocumentEntity) Document(org.jnosql.diana.api.document.Document) DocumentDeleteQuery(org.jnosql.diana.api.document.DocumentDeleteQuery) Test(org.junit.jupiter.api.Test)

Example 24 with DocumentQuery

use of org.jnosql.diana.api.document.DocumentQuery in project jnosql-diana-driver by eclipse.

the class CouchbaseDocumentCollectionManagerTest method shouldSaveSubDocument2.

@Test
public void shouldSaveSubDocument2() throws InterruptedException {
    DocumentEntity entity = getEntity();
    entity.add(Document.of("phones", asList(Document.of("mobile", "1231231"), Document.of("mobile2", "1231231"))));
    DocumentEntity entitySaved = entityManager.insert(entity);
    Thread.sleep(1_00L);
    Document id = entitySaved.find("_id").get();
    DocumentQuery query = select().from(COLLECTION_NAME).where(id.getName()).eq(id.get()).build();
    DocumentEntity entityFound = entityManager.select(query).get(0);
    Document subDocument = entityFound.find("phones").get();
    List<Document> documents = subDocument.get(new TypeReference<List<Document>>() {
    });
    assertThat(documents, contains(Document.of("mobile", "1231231"), Document.of("mobile2", "1231231")));
}
Also used : DocumentQuery(org.jnosql.diana.api.document.DocumentQuery) DocumentEntity(org.jnosql.diana.api.document.DocumentEntity) ArrayList(java.util.ArrayList) Arrays.asList(java.util.Arrays.asList) List(java.util.List) Document(org.jnosql.diana.api.document.Document) Test(org.junit.jupiter.api.Test)

Example 25 with DocumentQuery

use of org.jnosql.diana.api.document.DocumentQuery in project jnosql-diana-driver by eclipse.

the class CouchbaseDocumentCollectionManagerTest method shouldSaveSubDocument.

@Test
public void shouldSaveSubDocument() throws InterruptedException {
    DocumentEntity entity = getEntity();
    entity.add(Document.of("phones", Document.of("mobile", "1231231")));
    DocumentEntity entitySaved = entityManager.insert(entity);
    Thread.sleep(5_00L);
    Document id = entitySaved.find("_id").get();
    DocumentQuery query = select().from(COLLECTION_NAME).where(id.getName()).eq(id.get()).build();
    DocumentEntity entityFound = entityManager.select(query).get(0);
    Document subDocument = entityFound.find("phones").get();
    List<Document> documents = subDocument.get(new TypeReference<List<Document>>() {
    });
    assertThat(documents, contains(Document.of("mobile", "1231231")));
}
Also used : DocumentQuery(org.jnosql.diana.api.document.DocumentQuery) DocumentEntity(org.jnosql.diana.api.document.DocumentEntity) ArrayList(java.util.ArrayList) Arrays.asList(java.util.Arrays.asList) List(java.util.List) Document(org.jnosql.diana.api.document.Document) 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