use of org.jnosql.diana.api.document.DocumentEntity in project jnosql-diana-driver by eclipse.
the class OrientDBDocumentCollectionManagerAsyncTest method shouldUpdateAsyncWithCallback.
@Test
public void shouldUpdateAsyncWithCallback() {
final String NEW_FIELD_NAME = "newField2";
final String NEW_FIELD_VALUE = "55";
DocumentEntity entity = entityManager.insert(getEntity());
Document newField = Documents.of(NEW_FIELD_NAME, NEW_FIELD_VALUE);
entity.add(newField);
AtomicBoolean condition = new AtomicBoolean(false);
entityManagerAsync.update(entity, c -> condition.set(true));
await().untilTrue(condition);
Optional<Document> idDocument = entity.find(OrientDBConverter.RID_FIELD);
DocumentQuery query = select().from(entity.getName()).where(idDocument.get().getName()).eq(idDocument.get().get()).build();
Optional<DocumentEntity> entityUpdated = entityManager.singleResult(query);
assertTrue(entityUpdated.isPresent());
assertEquals(entityUpdated.get().find(NEW_FIELD_NAME).get(), newField);
}
use of org.jnosql.diana.api.document.DocumentEntity 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)));
}
use of org.jnosql.diana.api.document.DocumentEntity 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.DocumentEntity 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.DocumentEntity 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());
}
Aggregations