use of org.jnosql.diana.api.document.DocumentQuery in project jnosql-diana-driver by eclipse.
the class OrientDBDocumentCollectionManagerAsyncTest method shouldRemoveEntityAsync.
@Test
public void shouldRemoveEntityAsync() throws InterruptedException {
DocumentEntity documentEntity = entityManager.insert(getEntity());
Document id = documentEntity.find("name").get();
DocumentQuery query = select().from(COLLECTION_NAME).where(id.getName()).eq(id.get()).build();
DocumentDeleteQuery deleteQuery = delete().from(COLLECTION_NAME).where(id.getName()).eq(id.get()).build();
AtomicBoolean condition = new AtomicBoolean(false);
entityManagerAsync.delete(deleteQuery, c -> condition.set(true));
await().untilTrue(condition);
assertTrue(entityManager.select(query).isEmpty());
}
use of org.jnosql.diana.api.document.DocumentQuery in project jnosql-diana-driver by eclipse.
the class OrientDBDocumentCollectionManagerAsyncTest method shouldRemoveEntityAsyncWithoutCallback.
@Test
public void shouldRemoveEntityAsyncWithoutCallback() throws InterruptedException {
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();
DocumentDeleteQuery deleteQuery = delete().from(COLLECTION_NAME).where(id.getName()).eq(id.get()).build();
entityManagerAsync.delete(deleteQuery);
Thread.sleep(1000L);
assertTrue(entityManager.select(query).isEmpty());
}
use of org.jnosql.diana.api.document.DocumentQuery in project jnosql-diana-driver by eclipse.
the class OrientDBDocumentCollectionManagerAsyncTest method shouldSaveAsync.
@Test
public void shouldSaveAsync() throws InterruptedException {
AtomicReference<DocumentEntity> entityAtomic = new AtomicReference<>();
entityManagerAsync.insert(getEntity(), entityAtomic::set);
await().until(entityAtomic::get, notNullValue(DocumentEntity.class));
DocumentEntity entity = entityAtomic.get();
Document id = entity.find("name").get();
DocumentQuery query = select().from(COLLECTION_NAME).where(id.getName()).eq(id.get()).build();
List<DocumentEntity> entities = entityManager.select(query);
assertFalse(entities.isEmpty());
}
use of org.jnosql.diana.api.document.DocumentQuery in project jnosql-diana-driver by eclipse.
the class OrientDBDocumentCollectionManagerAsyncTest method shouldFindAsync.
@Test
public void shouldFindAsync() {
DocumentEntity entity = entityManager.insert(getEntity());
AtomicReference<List<DocumentEntity>> reference = new AtomicReference<>();
DocumentQuery query = select().from(COLLECTION_NAME).build();
entityManagerAsync.select(query, reference::set);
await().until(reference::get, notNullValue(List.class));
assertFalse(reference.get().isEmpty());
assertEquals(reference.get().get(0), entity);
}
use of org.jnosql.diana.api.document.DocumentQuery 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);
}
Aggregations