use of org.jnosql.diana.api.document.Document in project jnosql-diana-driver by eclipse.
the class OrientDBDocumentCollectionManagerTest method shouldLiveDeleteCallback.
@Test
public void shouldLiveDeleteCallback() {
AtomicBoolean condition = new AtomicBoolean(false);
OrientDBLiveDeleteCallback<DocumentEntity> callback = d -> condition.set(true);
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().onDelete(callback).build());
DocumentDeleteQuery deleteQuery = delete().from(COLLECTION_NAME).where(id.getName()).eq(id.get()).build();
entityManager.delete(deleteQuery);
await().untilTrue(condition);
}
use of org.jnosql.diana.api.document.Document in project jnosql-diana-driver by eclipse.
the class OrientDBDocumentCollectionManagerTest 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;
}
use of org.jnosql.diana.api.document.Document in project jnosql-diana-driver by eclipse.
the class MongoDBDocumentCollectionManagerTest method shouldFindDocument3.
@Test
public void shouldFindDocument3() {
DocumentEntity entity = entityManager.insert(getEntity());
Optional<Document> id = entity.find("_id");
DocumentQuery query = select().from(COLLECTION_NAME).where("name").eq("Poliana").or("city").eq("Salvador").and(id.get().getName()).eq(id.get().get()).build();
List<DocumentEntity> entities = entityManager.select(query);
assertFalse(entities.isEmpty());
assertThat(entities, contains(entity));
}
use of org.jnosql.diana.api.document.Document in project jnosql-diana-driver by eclipse.
the class MongoDBDocumentCollectionManagerTest 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("_id").get();
DocumentQuery query = select().from(COLLECTION_NAME).where("_id").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 OrientDBConverter method toDocument.
private static void toDocument(Map<String, Object> entityValues, Document document) {
Object value = ValueUtil.convert(document.getValue());
if (Document.class.isInstance(value)) {
Document subDocument = Document.class.cast(value);
entityValues.put(document.getName(), singletonMap(subDocument.getName(), subDocument.get()));
} else if (isDocumentIterable(value)) {
entityValues.put(document.getName(), getMap(value));
} else if (isSudDocumentList(value)) {
entityValues.put(document.getName(), StreamSupport.stream(Iterable.class.cast(value).spliterator(), false).map(OrientDBConverter::getMap).collect(toList()));
} else {
entityValues.put(document.getName(), value);
}
}
Aggregations