Search in sources :

Example 56 with DocumentDeleteQuery

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

the class ElasticsearchDocumentCollectionManagerAsyncTest method shouldRemoveEntityAsync.

@Test
public void shouldRemoveEntityAsync() throws InterruptedException {
    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);
    Thread.sleep(1_000L);
    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 57 with DocumentDeleteQuery

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

the class ElasticsearchDocumentCollectionManagerTest method shouldRemoveEntityById.

@Test
public void shouldRemoveEntityById() {
    DocumentEntity documentEntity = entityManager.insert(getEntity());
    Document id = documentEntity.find("_id").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();
    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 58 with DocumentDeleteQuery

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

the class ElasticsearchDocumentCollectionManagerTest method shouldRemoveEntityByName.

@Test
public void shouldRemoveEntityByName() throws InterruptedException {
    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 = delete().from(COLLECTION_NAME).where(name.getName()).eq(name.get()).build();
    TimeUnit.SECONDS.sleep(1L);
    entityManager.delete(deleteQuery);
    TimeUnit.SECONDS.sleep(1L);
    List<DocumentEntity> entities = entityManager.select(query);
    System.out.println(entities);
    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) DocumentDeleteQuery(org.jnosql.diana.api.document.DocumentDeleteQuery) Test(org.junit.jupiter.api.Test)

Example 59 with DocumentDeleteQuery

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

the class MongoDBDocumentCollectionManagerAsyncTest method shouldRemoveEntityAsync.

@Test
public void shouldRemoveEntityAsync() throws InterruptedException {
    AtomicReference<DocumentEntity> entityAtomic = new AtomicReference<>();
    entityManager.insert(getEntity(), entityAtomic::set);
    await().until(entityAtomic::get, notNullValue(DocumentEntity.class));
    DocumentEntity entity = entityAtomic.get();
    Document document = entity.find("name").get();
    assertNotNull(entity);
    assertNotNull(document);
    String collection = entity.getName();
    DocumentDeleteQuery deleteQuery = delete().from(collection).where("name").eq(document.get()).build();
    AtomicBoolean condition = new AtomicBoolean(false);
    entityManager.delete(deleteQuery, c -> condition.set(true));
    await().untilTrue(condition);
    AtomicBoolean selectCondition = new AtomicBoolean(false);
    AtomicReference<List<DocumentEntity>> reference = new AtomicReference<>();
    DocumentQuery selectQuery = select().from(collection).where("name").eq(document.get()).build();
    entityManager.select(selectQuery, c -> {
        selectCondition.set(true);
        reference.set(c);
    });
    await().untilTrue(selectCondition);
    assertTrue(reference.get().isEmpty());
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) DocumentQuery(org.jnosql.diana.api.document.DocumentQuery) DocumentEntity(org.jnosql.diana.api.document.DocumentEntity) AtomicReference(java.util.concurrent.atomic.AtomicReference) List(java.util.List) Document(org.jnosql.diana.api.document.Document) DocumentDeleteQuery(org.jnosql.diana.api.document.DocumentDeleteQuery) Test(org.junit.jupiter.api.Test)

Example 60 with DocumentDeleteQuery

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

the class CouchbaseDocumentCollectionManagerAsyncTest method shouldRemoveEntityAsync.

@Test
public void shouldRemoveEntityAsync() {
    DocumentEntity documentEntity = entityManager.insert(getEntity());
    Document id = documentEntity.find("name").get();
    DocumentDeleteQuery deleteQuery = delete().from(COLLECTION_NAME).where(id.getName()).eq(id.get()).build();
    entityManagerAsync.delete(deleteQuery);
}
Also used : 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)

Aggregations

DocumentDeleteQuery (org.jnosql.diana.api.document.DocumentDeleteQuery)86 Test (org.junit.jupiter.api.Test)74 Document (org.jnosql.diana.api.document.Document)35 DocumentEntity (org.jnosql.diana.api.document.DocumentEntity)31 DocumentQuery (org.jnosql.diana.api.document.DocumentQuery)31 DocumentCondition (org.jnosql.diana.api.document.DocumentCondition)20 List (java.util.List)15 Person (org.jnosql.artemis.model.Person)13 Duration (java.time.Duration)7 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)6 AtomicReference (java.util.concurrent.atomic.AtomicReference)6 BeforeEach (org.junit.jupiter.api.BeforeEach)6 Optional (java.util.Optional)4 Consumer (java.util.function.Consumer)4 Collectors (java.util.stream.Collectors)4 DocumentQueryBuilder.delete (org.jnosql.diana.api.document.query.DocumentQueryBuilder.delete)4 DocumentQueryBuilder.select (org.jnosql.diana.api.document.query.DocumentQueryBuilder.select)4 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)4 Assertions.assertNotNull (org.junit.jupiter.api.Assertions.assertNotNull)4 Arrays (java.util.Arrays)3