Search in sources :

Example 51 with DocumentQuery

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

the class OrientDBDocumentCollectionManagerTest method shouldQueryMultiOrderBy.

@Test
public void shouldQueryMultiOrderBy() {
    List<DocumentEntity> entities = new ArrayList<>(getEntities());
    DocumentEntity bruno = DocumentEntity.of(COLLECTION_NAME);
    bruno.add(Document.of("name", "Bruno"));
    bruno.add(Document.of("city", "Sao Paulo"));
    entities.add(bruno);
    List<DocumentEntity> entitiesSaved = StreamSupport.stream(entityManager.insert(entities).spliterator(), false).collect(Collectors.toList());
    DocumentQuery query = select().from(COLLECTION_NAME).orderBy("city").desc().orderBy("name").asc().build();
    List<DocumentEntity> entitiesFound = entityManager.select(query);
    assertThat(entitiesFound, contains(entitiesSaved.get(3), entitiesSaved.get(1), entitiesSaved.get(0), entitiesSaved.get(2)));
}
Also used : DocumentQuery(org.jnosql.diana.api.document.DocumentQuery) DocumentEntity(org.jnosql.diana.api.document.DocumentEntity) ArrayList(java.util.ArrayList) Test(org.junit.jupiter.api.Test)

Example 52 with DocumentQuery

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

the class OrientDBDocumentCollectionManagerTest method shouldRetrieveListSubdocumentList.

@Test
public void shouldRetrieveListSubdocumentList() {
    DocumentEntity entity = entityManager.insert(createSubdocumentList());
    Document key = entity.find("_id").get();
    DocumentQuery query = select().from("AppointmentBook").where(key.getName()).eq(key.get()).build();
    DocumentEntity documentEntity = entityManager.singleResult(query).get();
    assertNotNull(documentEntity);
    List<List<Document>> contacts = (List<List<Document>>) documentEntity.find("contacts").get().get();
    assertEquals(3, contacts.size());
    assertTrue(contacts.stream().allMatch(d -> d.size() == 3));
}
Also used : Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) BeforeEach(org.junit.jupiter.api.BeforeEach) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) Document(org.jnosql.diana.api.document.Document) Arrays(java.util.Arrays) TypeReference(org.jnosql.diana.api.TypeReference) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) HashMap(java.util.HashMap) Random(java.util.Random) AtomicReference(java.util.concurrent.atomic.AtomicReference) ArrayList(java.util.ArrayList) 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) DocumentQueryBuilder.delete(org.jnosql.diana.api.document.query.DocumentQueryBuilder.delete) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) Awaitility.await(org.awaitility.Awaitility.await) DocumentQueryBuilder.select(org.jnosql.diana.api.document.query.DocumentQueryBuilder.select) Matchers.notNullValue(org.hamcrest.Matchers.notNullValue) DocumentConfigurationUtils.get(org.jnosql.diana.orientdb.document.DocumentConfigurationUtils.get) RID_FIELD(org.jnosql.diana.orientdb.document.OrientDBConverter.RID_FIELD) DocumentDeleteQuery(org.jnosql.diana.api.document.DocumentDeleteQuery) Collectors(java.util.stream.Collectors) DocumentQuery(org.jnosql.diana.api.document.DocumentQuery) Test(org.junit.jupiter.api.Test) AfterEach(org.junit.jupiter.api.AfterEach) List(java.util.List) Documents(org.jnosql.diana.api.document.Documents) Matchers.contains(org.hamcrest.Matchers.contains) Matchers.containsInAnyOrder(org.hamcrest.Matchers.containsInAnyOrder) DocumentEntity(org.jnosql.diana.api.document.DocumentEntity) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) Optional(java.util.Optional) 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 53 with DocumentQuery

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

the class OrientDBDocumentCollectionManagerTest method shouldUpdateWithRetry.

@Test
public void shouldUpdateWithRetry() {
    DocumentEntity entity = entityManager.insert(getEntity());
    entity.add(Document.of(OrientDBConverter.VERSION_FIELD, 0));
    Document newField = Documents.of("newField", "99");
    entity.add(newField);
    entityManager.update(entity);
    Document id = entity.find(OrientDBConverter.RID_FIELD).get();
    DocumentQuery query = select().from(entity.getName()).where(id.getName()).eq(id.get()).build();
    Optional<DocumentEntity> updated = entityManager.singleResult(query);
    assertTrue(updated.isPresent());
    assertEquals(newField, updated.get().find(newField.getName()).get());
}
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 54 with DocumentQuery

use of org.jnosql.diana.api.document.DocumentQuery 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).size() == 2);
    DocumentDeleteQuery deleteQuery = delete().from(COLLECTION_NAME).where("city").in(asList("Salvador", "Assis", "Sao Paulo")).build();
    entityManager.delete(deleteQuery);
    assertTrue(entityManager.select(query).isEmpty());
}
Also used : DocumentQuery(org.jnosql.diana.api.document.DocumentQuery) DocumentDeleteQuery(org.jnosql.diana.api.document.DocumentDeleteQuery) Test(org.junit.jupiter.api.Test)

Example 55 with DocumentQuery

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

the class OrientDBDocumentCollectionManagerTest method shouldQueryOr.

@Test
public void shouldQueryOr() {
    DocumentEntity entity = getEntity();
    entity.add(Document.of("age", 24));
    entityManager.insert(entity);
    DocumentQuery query = select().from(COLLECTION_NAME).where("name").eq("Poliana").or("age").gte(10).build();
    DocumentDeleteQuery deleteQuery = delete().from(COLLECTION_NAME).where("name").eq("Poliana").or("age").gte(10).build();
    assertFalse(entityManager.select(query).isEmpty());
    entityManager.delete(deleteQuery);
    assertTrue(entityManager.select(query).isEmpty());
}
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)

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