use of org.jnosql.diana.api.document.DocumentEntity in project jnosql-diana-driver by eclipse.
the class MongoDBDocumentCollectionManagerTest method createSubdocumentList.
private DocumentEntity createSubdocumentList() {
DocumentEntity entity = DocumentEntity.of("AppointmentBook");
entity.add(Document.of("_id", new Random().nextInt()));
List<List<Document>> documents = new ArrayList<>();
documents.add(asList(Document.of("name", "Ada"), Document.of("type", ContactType.EMAIL), Document.of("information", "ada@lovelace.com")));
documents.add(asList(Document.of("name", "Ada"), Document.of("type", ContactType.MOBILE), Document.of("information", "11 1231231 123")));
documents.add(asList(Document.of("name", "Ada"), Document.of("type", ContactType.PHONE), Document.of("information", "phone")));
entity.add(Document.of("contacts", documents));
return entity;
}
use of org.jnosql.diana.api.document.DocumentEntity 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.DocumentEntity in project jnosql-diana-driver by eclipse.
the class LiveQueryLIstener method onLiveResult.
@Override
public void onLiveResult(int iLiveToken, ORecordOperation iOp) throws OException {
ODocument oDocument = (ODocument) iOp.getRecord();
DocumentEntity entity = OrientDBConverter.convert(oDocument);
switch(iOp.type) {
case CREATED:
callbacks.getCreateCallback().ifPresent(callback -> callback.accept(entity));
return;
case UPDATED:
callbacks.getUpdateCallback().ifPresent(callback -> callback.accept(entity));
return;
case DELETED:
callbacks.getDeleteCallback().ifPresent(callback -> callback.accept(entity));
return;
default:
}
}
use of org.jnosql.diana.api.document.DocumentEntity in project jnosql-diana-driver by eclipse.
the class OrientDBConverter method convert.
static List<DocumentEntity> convert(List<ODocument> result) {
List<DocumentEntity> entities = new ArrayList<>();
for (ODocument document : result) {
DocumentEntity entity = convert(document);
entities.add(entity);
}
return entities;
}
use of org.jnosql.diana.api.document.DocumentEntity in project jnosql-diana-driver by eclipse.
the class MongoDBDocumentCollectionManagerAsync method select.
@Override
public void select(DocumentQuery query, Consumer<List<DocumentEntity>> callBack) throws ExecuteAsyncQueryException, UnsupportedOperationException {
String collectionName = query.getDocumentCollection();
MongoCollection<Document> collection = asyncMongoDatabase.getCollection(collectionName);
Bson mongoDBQuery = query.getCondition().map(DocumentQueryConversor::convert).orElse(EMPTY);
List<DocumentEntity> entities = new CopyOnWriteArrayList<>();
FindIterable<Document> result = collection.find(mongoDBQuery);
Block<Document> documentBlock = d -> entities.add(createEntity(collectionName, d));
SingleResultCallback<Void> voidSingleResultCallback = (v, e) -> callBack.accept(entities);
result.forEach(documentBlock, voidSingleResultCallback);
}
Aggregations