use of org.jnosql.diana.api.document.Document 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));
}
use of org.jnosql.diana.api.document.Document 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());
}
use of org.jnosql.diana.api.document.Document in project jnosql-diana-driver by eclipse.
the class OrientDBDocumentCollectionManagerTest method shouldLiveUpdateCallback.
@Test
public void shouldLiveUpdateCallback() {
AtomicReference<DocumentEntity> reference = new AtomicReference<>();
OrientDBLiveUpdateCallback<DocumentEntity> callback = reference::set;
DocumentEntity entity = entityManager.insert(getEntity());
Document id = entity.find(OrientDBConverter.RID_FIELD).get();
DocumentQuery query = select().from(COLLECTION_NAME).where(id.getName()).eq(id.get()).build();
entityManager.live(query, OrientDBLiveCallbackBuilder.builder().onUpdate(callback).build());
Document newName = Document.of("name", "Lucas");
entity.add(newName);
entityManager.update(entity);
await().until(reference::get, notNullValue());
assertEquals("Lucas", reference.get().find("name").get().get());
}
use of org.jnosql.diana.api.document.Document in project jnosql-diana-driver by eclipse.
the class OrientDBDocumentCollectionManagerTest method shouldSaveSubDocument.
@Test
public void shouldSaveSubDocument() {
DocumentEntity entity = getEntity();
entity.add(Document.of("phones", Document.of("mobile", "1231231")));
DocumentEntity entitySaved = entityManager.insert(entity);
Document id = entitySaved.find("name").get();
DocumentQuery query = select().from(COLLECTION_NAME).where(id.getName()).eq(id.get()).build();
DocumentEntity entityFound = entityManager.select(query).get(0);
Document subDocument = entityFound.find("phones").get();
List<Document> documents = subDocument.get(new TypeReference<List<Document>>() {
});
assertThat(documents, contains(Document.of("mobile", "1231231")));
}
use of org.jnosql.diana.api.document.Document in project jnosql-diana-driver by eclipse.
the class OrientDBDocumentCollectionManagerTest method shouldUpdateSave.
@Test
public void shouldUpdateSave() {
DocumentEntity entity = entityManager.insert(getEntity());
Document newField = Documents.of("newField", "10");
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());
}
Aggregations