Search in sources :

Example 61 with Document

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

the class MongoDBDocumentCollectionManagerAsyncTest method shouldRemoveEntity.

@Test
public void shouldRemoveEntity() {
    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();
    DocumentDeleteQuery deleteQuery = delete().from(entity.getName()).where(document.getName()).eq(document.get()).build();
    entityManager.delete(deleteQuery);
}
Also used : DocumentEntity(org.jnosql.diana.api.document.DocumentEntity) 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 62 with Document

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

the class MongoDBDocumentCollectionManagerAsyncTest method getEntity.

private DocumentEntity getEntity() {
    DocumentEntity entity = DocumentEntity.of(COLLECTION_NAME);
    Map<String, Object> map = new HashMap<>();
    map.put("name", "Poliana");
    map.put("city", "Salvador");
    List<Document> documents = Documents.of(map);
    documents.forEach(entity::add);
    return entity;
}
Also used : DocumentEntity(org.jnosql.diana.api.document.DocumentEntity) HashMap(java.util.HashMap) Document(org.jnosql.diana.api.document.Document)

Example 63 with Document

use of org.jnosql.diana.api.document.Document in project jnosql-artemis by eclipse.

the class DefaultDocumentEntityConverterTest method shouldConvertToDocumentWhenHaConverter.

@Test
public void shouldConvertToDocumentWhenHaConverter() {
    Worker worker = new Worker();
    Job job = new Job();
    job.setCity("Sao Paulo");
    job.setDescription("Java Developer");
    worker.setName("Bob");
    worker.setSalary(new Money("BRL", BigDecimal.TEN));
    worker.setJob(job);
    DocumentEntity entity = converter.toDocument(worker);
    assertEquals("Worker", entity.getName());
    assertEquals("Bob", entity.find("name").get().get());
    Document subDocument = entity.find("job").get();
    List<Document> documents = subDocument.get(new TypeReference<List<Document>>() {
    });
    assertThat(documents, Matchers.containsInAnyOrder(Document.of("city", "Sao Paulo"), Document.of("description", "Java Developer")));
    assertEquals("BRL 10", entity.find("money").get().get());
}
Also used : Money(org.jnosql.artemis.model.Money) DocumentEntity(org.jnosql.diana.api.document.DocumentEntity) Worker(org.jnosql.artemis.model.Worker) ArrayList(java.util.ArrayList) Arrays.asList(java.util.Arrays.asList) List(java.util.List) Job(org.jnosql.artemis.model.Job) Document(org.jnosql.diana.api.document.Document) Test(org.junit.jupiter.api.Test)

Example 64 with Document

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

the class OrientDBDocumentCollectionManagerAsyncTest method shouldFindAsyncWithNativeQueryMapParam.

@Test
public void shouldFindAsyncWithNativeQueryMapParam() {
    DocumentEntity entity = entityManager.insert(getEntity());
    Optional<Document> id = entity.find(OrientDBConverter.RID_FIELD);
    Optional<Document> name = entity.find("name");
    AtomicReference<List<DocumentEntity>> reference = new AtomicReference<>();
    Map<String, Object> params = new HashMap<>();
    params.put("id", id.get().get());
    params.put("name", name.get().get());
    entityManagerAsync.sql("select * from person where @rid = :id and name = :name", reference::set, params);
    await().until(reference::get, notNullValue(List.class));
    assertFalse(reference.get().isEmpty());
    assertEquals(reference.get().get(0), entity);
}
Also used : DocumentEntity(org.jnosql.diana.api.document.DocumentEntity) HashMap(java.util.HashMap) List(java.util.List) AtomicReference(java.util.concurrent.atomic.AtomicReference) Document(org.jnosql.diana.api.document.Document) Test(org.junit.jupiter.api.Test)

Example 65 with Document

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

the class OrientDBDocumentCollectionManagerTest method shouldSQL.

@Test
public void shouldSQL() {
    DocumentEntity entity = entityManager.insert(getEntity());
    Optional<Document> id = entity.find("name");
    List<DocumentEntity> entities = entityManager.sql("select * from person where name = ?", id.get().get());
    assertFalse(entities.isEmpty());
    assertThat(entities, contains(entity));
}
Also used : DocumentEntity(org.jnosql.diana.api.document.DocumentEntity) Document(org.jnosql.diana.api.document.Document) Test(org.junit.jupiter.api.Test)

Aggregations

Document (org.jnosql.diana.api.document.Document)126 Test (org.junit.jupiter.api.Test)102 DocumentEntity (org.jnosql.diana.api.document.DocumentEntity)94 DocumentQuery (org.jnosql.diana.api.document.DocumentQuery)71 List (java.util.List)41 DocumentDeleteQuery (org.jnosql.diana.api.document.DocumentDeleteQuery)37 ArrayList (java.util.ArrayList)25 DocumentCondition (org.jnosql.diana.api.document.DocumentCondition)25 Arrays.asList (java.util.Arrays.asList)23 HashMap (java.util.HashMap)18 AtomicReference (java.util.concurrent.atomic.AtomicReference)12 Map (java.util.Map)11 MatcherAssert.assertThat (org.hamcrest.MatcherAssert.assertThat)11 TypeReference (org.jnosql.diana.api.TypeReference)11 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)10 Matchers.contains (org.hamcrest.Matchers.contains)10 DocumentQueryBuilder.select (org.jnosql.diana.api.document.query.DocumentQueryBuilder.select)10 Arrays (java.util.Arrays)8 Optional (java.util.Optional)8 Matchers.containsInAnyOrder (org.hamcrest.Matchers.containsInAnyOrder)8