Search in sources :

Example 51 with DocumentDeleteQuery

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

the class MongoDBDocumentCollectionManagerTest method shouldFindDocumentGreaterThan.

@Test
public void shouldFindDocumentGreaterThan() {
    DocumentDeleteQuery deleteQuery = delete().from(COLLECTION_NAME).where("type").eq("V").build();
    entityManager.delete(deleteQuery);
    Iterable<DocumentEntity> entitiesSaved = entityManager.insert(getEntitiesWithValues());
    List<DocumentEntity> entities = StreamSupport.stream(entitiesSaved.spliterator(), false).collect(Collectors.toList());
    DocumentQuery query = select().from(COLLECTION_NAME).where("age").gt(22).and("type").eq("V").build();
    List<DocumentEntity> entitiesFound = entityManager.select(query);
    assertTrue(entitiesFound.size() == 2);
    assertThat(entitiesFound, not(contains(entities.get(0))));
}
Also used : DocumentQuery(org.jnosql.diana.api.document.DocumentQuery) DocumentEntity(org.jnosql.diana.api.document.DocumentEntity) DocumentDeleteQuery(org.jnosql.diana.api.document.DocumentDeleteQuery) Test(org.junit.jupiter.api.Test)

Example 52 with DocumentDeleteQuery

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

the class MongoDBDocumentCollectionManagerTest method shouldFindDocumentLike.

@Test
public void shouldFindDocumentLike() {
    DocumentDeleteQuery deleteQuery = delete().from(COLLECTION_NAME).where("type").eq("V").build();
    entityManager.delete(deleteQuery);
    Iterable<DocumentEntity> entitiesSaved = entityManager.insert(getEntitiesWithValues());
    List<DocumentEntity> entities = StreamSupport.stream(entitiesSaved.spliterator(), false).collect(Collectors.toList());
    DocumentQuery query = select().from(COLLECTION_NAME).where("name").like("Lu").and("type").eq("V").build();
    List<DocumentEntity> entitiesFound = entityManager.select(query);
    assertTrue(entitiesFound.size() == 2);
    assertThat(entitiesFound, contains(entities.get(0), entities.get(2)));
}
Also used : DocumentQuery(org.jnosql.diana.api.document.DocumentQuery) DocumentEntity(org.jnosql.diana.api.document.DocumentEntity) DocumentDeleteQuery(org.jnosql.diana.api.document.DocumentDeleteQuery) Test(org.junit.jupiter.api.Test)

Example 53 with DocumentDeleteQuery

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

the class MongoDBDocumentCollectionManagerTest method shouldRemoveEntity.

@Test
public void shouldRemoveEntity() {
    DocumentEntity documentEntity = entityManager.insert(getEntity());
    Optional<Document> id = documentEntity.find("_id");
    DocumentQuery query = select().from(COLLECTION_NAME).where("_id").eq(id.get().get()).build();
    DocumentDeleteQuery deleteQuery = delete().from(COLLECTION_NAME).where("_id").eq(id.get().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 54 with DocumentDeleteQuery

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

the class MongoDBDocumentCollectionManagerTest method shouldFindDocumentIn.

@Test
public void shouldFindDocumentIn() {
    DocumentDeleteQuery deleteQuery = delete().from(COLLECTION_NAME).where("type").eq("V").build();
    entityManager.delete(deleteQuery);
    Iterable<DocumentEntity> entitiesSaved = entityManager.insert(getEntitiesWithValues());
    List<DocumentEntity> entities = StreamSupport.stream(entitiesSaved.spliterator(), false).collect(Collectors.toList());
    DocumentQuery query = select().from(COLLECTION_NAME).where("location").in(asList("BR", "US")).and("type").eq("V").build();
    assertEquals(entities, entityManager.select(query));
}
Also used : DocumentQuery(org.jnosql.diana.api.document.DocumentQuery) DocumentEntity(org.jnosql.diana.api.document.DocumentEntity) DocumentDeleteQuery(org.jnosql.diana.api.document.DocumentDeleteQuery) Test(org.junit.jupiter.api.Test)

Example 55 with DocumentDeleteQuery

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

the class ElasticsearchDocumentCollectionManagerAsyncTest method setUp.

@BeforeEach
public void setUp() {
    ElasticsearchDocumentConfiguration configuration = new ElasticsearchDocumentConfiguration();
    ElasticsearchDocumentCollectionManagerFactory managerFactory = configuration.get();
    entityManagerAsync = managerFactory.getAsync(COLLECTION_NAME);
    entityManager = managerFactory.get(INDEX);
    DocumentEntity documentEntity = 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);
}
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) BeforeEach(org.junit.jupiter.api.BeforeEach)

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