Search in sources :

Example 46 with DocumentDeleteQuery

use of jakarta.nosql.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).collect(Collectors.toList());
    assertTrue(entitiesFound.size() == 2);
    assertThat(entitiesFound, not(contains(entities.get(0))));
}
Also used : DocumentQuery(jakarta.nosql.document.DocumentQuery) DocumentEntity(jakarta.nosql.document.DocumentEntity) DocumentDeleteQuery(jakarta.nosql.document.DocumentDeleteQuery) Test(org.junit.jupiter.api.Test)

Example 47 with DocumentDeleteQuery

use of jakarta.nosql.document.DocumentDeleteQuery in project jnosql-diana-driver by eclipse.

the class MongoDBDocumentCollectionManagerTest method shouldDeleteAll.

@Test
public void shouldDeleteAll() {
    entityManager.insert(getEntity());
    DocumentQuery query = select().from(COLLECTION_NAME).build();
    List<DocumentEntity> entities = entityManager.select(query).collect(Collectors.toList());
    assertFalse(entities.isEmpty());
    DocumentDeleteQuery deleteQuery = delete().from(COLLECTION_NAME).build();
    entityManager.delete(deleteQuery);
    entities = entityManager.select(query).collect(Collectors.toList());
    assertTrue(entities.isEmpty());
}
Also used : DocumentQuery(jakarta.nosql.document.DocumentQuery) DocumentEntity(jakarta.nosql.document.DocumentEntity) DocumentDeleteQuery(jakarta.nosql.document.DocumentDeleteQuery) Test(org.junit.jupiter.api.Test)

Example 48 with DocumentDeleteQuery

use of jakarta.nosql.document.DocumentDeleteQuery in project jnosql-diana-driver by eclipse.

the class OrientDBDocumentCollectionManagerTest method shouldQueryAnd.

@Test
public void shouldQueryAnd() {
    DocumentEntity entity = getEntity();
    entity.add(Document.of("age", 24));
    entityManager.insert(entity);
    DocumentQuery query = select().from(COLLECTION_NAME).where("name").eq("Poliana").and("age").gte(10).build();
    DocumentDeleteQuery deleteQuery = delete().from(COLLECTION_NAME).where("name").eq("Poliana").and("age").gte(10).build();
    assertFalse(entityManager.select(query).collect(Collectors.toList()).isEmpty());
    entityManager.delete(deleteQuery);
    assertTrue(entityManager.select(query).collect(Collectors.toList()).isEmpty());
}
Also used : DocumentQuery(jakarta.nosql.document.DocumentQuery) DocumentEntity(jakarta.nosql.document.DocumentEntity) DocumentDeleteQuery(jakarta.nosql.document.DocumentDeleteQuery) Test(org.junit.jupiter.api.Test)

Example 49 with DocumentDeleteQuery

use of jakarta.nosql.document.DocumentDeleteQuery in project jnosql-diana-driver by eclipse.

the class OrientDBDocumentCollectionManagerTest method shouldLiveDeleteCallback.

@Test
@Disabled
public void shouldLiveDeleteCallback() {
    AtomicBoolean condition = new AtomicBoolean(false);
    OrientDBLiveDeleteCallback<DocumentEntity> callback = d -> condition.set(true);
    entityManager.insert(getEntity());
    DocumentQuery query = select().from(COLLECTION_NAME).build();
    entityManager.live(query, OrientDBLiveCallbackBuilder.builder().onDelete(callback).build());
    DocumentDeleteQuery deleteQuery = delete().from(COLLECTION_NAME).build();
    entityManager.delete(deleteQuery);
    await().untilTrue(condition);
}
Also used : Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) BeforeEach(org.junit.jupiter.api.BeforeEach) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) Arrays(java.util.Arrays) DocumentQuery.select(jakarta.nosql.document.DocumentQuery.select) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) DocumentDeleteQuery(jakarta.nosql.document.DocumentDeleteQuery) HashMap(java.util.HashMap) Random(java.util.Random) Disabled(org.junit.jupiter.api.Disabled) ArrayList(java.util.ArrayList) TypeReference(jakarta.nosql.TypeReference) DocumentQuery(jakarta.nosql.document.DocumentQuery) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) Arrays.asList(java.util.Arrays.asList) Duration(java.time.Duration) Map(java.util.Map) StreamSupport(java.util.stream.StreamSupport) Collections.singletonMap(java.util.Collections.singletonMap) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) Documents(org.eclipse.jnosql.communication.document.Documents) Awaitility.await(org.awaitility.Awaitility.await) Document(jakarta.nosql.document.Document) DocumentEntity(jakarta.nosql.document.DocumentEntity) Collectors(java.util.stream.Collectors) Test(org.junit.jupiter.api.Test) AfterEach(org.junit.jupiter.api.AfterEach) List(java.util.List) DocumentDeleteQuery.delete(jakarta.nosql.document.DocumentDeleteQuery.delete) Matchers.contains(org.hamcrest.Matchers.contains) Matchers.containsInAnyOrder(org.hamcrest.Matchers.containsInAnyOrder) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) Optional(java.util.Optional) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) DocumentQuery(jakarta.nosql.document.DocumentQuery) DocumentEntity(jakarta.nosql.document.DocumentEntity) DocumentDeleteQuery(jakarta.nosql.document.DocumentDeleteQuery) Test(org.junit.jupiter.api.Test) Disabled(org.junit.jupiter.api.Disabled)

Example 50 with DocumentDeleteQuery

use of jakarta.nosql.document.DocumentDeleteQuery in project jnosql-diana-driver by eclipse.

the class OrientDBDocumentCollectionManagerTest method shouldQueryIn.

@Test
public void shouldQueryIn() {
    entityManager.insert(getEntities());
    DocumentQuery query = select().from(COLLECTION_NAME).where("city").in(asList("Salvador", "Assis")).build();
    assertTrue(entityManager.select(query).collect(Collectors.toList()).size() == 2);
    DocumentDeleteQuery deleteQuery = delete().from(COLLECTION_NAME).where("city").in(asList("Salvador", "Assis", "Sao Paulo")).build();
    entityManager.delete(deleteQuery);
    assertTrue(entityManager.select(query).collect(Collectors.toList()).isEmpty());
}
Also used : DocumentQuery(jakarta.nosql.document.DocumentQuery) DocumentDeleteQuery(jakarta.nosql.document.DocumentDeleteQuery) Test(org.junit.jupiter.api.Test)

Aggregations

DocumentDeleteQuery (jakarta.nosql.document.DocumentDeleteQuery)114 Test (org.junit.jupiter.api.Test)79 DocumentEntity (jakarta.nosql.document.DocumentEntity)45 DocumentQuery (jakarta.nosql.document.DocumentQuery)43 Document (jakarta.nosql.document.Document)37 DocumentCondition (jakarta.nosql.document.DocumentCondition)33 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)20 ValueSource (org.junit.jupiter.params.provider.ValueSource)20 List (java.util.List)15 Person (jakarta.nosql.tck.entities.Person)12 Collectors (java.util.stream.Collectors)7 Params (jakarta.nosql.Params)5 DocumentDeleteQueryParams (jakarta.nosql.document.DocumentDeleteQueryParams)5 Duration (java.time.Duration)5 HashMap (java.util.HashMap)5 Optional (java.util.Optional)5 StreamSupport (java.util.stream.StreamSupport)5 DocumentCollectionManager (jakarta.nosql.document.DocumentCollectionManager)4 DocumentQuery.select (jakarta.nosql.document.DocumentQuery.select)4 Map (java.util.Map)4