use of org.jnosql.diana.api.document.Document in project jnosql-diana-driver by eclipse.
the class MongoDBDocumentCollectionManagerTest method shouldRemoveEntity.
@Test
public void shouldRemoveEntity() {
DocumentEntity documentEntity = entityManager.insert(getEntity());
Optional<Document> id = documentEntity.find("_id");
DocumentQuery query = select().from(COLLECTION_NAME).where("_id").eq(id.get().get()).build();
DocumentDeleteQuery deleteQuery = delete().from(COLLECTION_NAME).where("_id").eq(id.get().get()).build();
entityManager.delete(deleteQuery);
assertTrue(entityManager.select(query).isEmpty());
}
use of org.jnosql.diana.api.document.Document in project jnosql-diana-driver by eclipse.
the class MongoDBDocumentCollectionManagerTest method shouldSaveSubDocument2.
@Test
public void shouldSaveSubDocument2() {
DocumentEntity entity = getEntity();
entity.add(Document.of("phones", asList(Document.of("mobile", "1231231"), Document.of("mobile2", "1231231"))));
DocumentEntity entitySaved = entityManager.insert(entity);
Document id = entitySaved.find("_id").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, containsInAnyOrder(Document.of("mobile", "1231231"), Document.of("mobile2", "1231231")));
}
use of org.jnosql.diana.api.document.Document in project jnosql-diana-driver by eclipse.
the class DefaultOrientDBDocumentCollectionManagerAsync method insert.
@Override
public void insert(DocumentEntity entity, Consumer<DocumentEntity> callBack) throws ExecuteAsyncQueryException, UnsupportedOperationException {
requireNonNull(entity, "Entity is required");
requireNonNull(callBack, "Callback is required");
ODatabaseDocumentTx tx = pool.acquire();
ODocument document = new ODocument(entity.getName());
Map<String, Object> entityValues = entity.toMap();
entityValues.keySet().stream().forEach(k -> document.field(k, entityValues.get(k)));
ORecordCallback<Number> createCallBack = (rid, clusterPosition) -> {
entity.add(Document.of(RID_FIELD, rid.toString()));
callBack.accept(entity);
};
ORecordCallback<Integer> updateCallback = (rid, version) -> {
entity.add(Document.of(RID_FIELD, rid.toString()));
entity.add(Document.of(VERSION_FIELD, version));
callBack.accept(entity);
};
tx.save(document, null, ASYNCHRONOUS, false, createCallBack, updateCallback);
}
use of org.jnosql.diana.api.document.Document in project jnosql-diana-driver by eclipse.
the class OrientDBConverter method convert.
static DocumentEntity convert(ODocument document) {
DocumentEntity entity = DocumentEntity.of(document.getClassName());
Stream.of(document.fieldNames()).map(f -> Document.of(f, convert((Object) document.field(f)))).forEach(entity::add);
entity.add(Document.of(RID_FIELD, document.field(RID_FIELD).toString()));
entity.add(Document.of(VERSION_FIELD, document.getVersion()));
return entity;
}
use of org.jnosql.diana.api.document.Document in project jnosql-diana-driver by eclipse.
the class ElasticsearchDocumentCollectionManagerAsyncTest method setUp.
@BeforeEach
public void setUp() {
ElasticsearchDocumentConfiguration configuration = new ElasticsearchDocumentConfiguration();
ElasticsearchDocumentCollectionManagerFactory managerFactory = configuration.get();
entityManagerAsync = managerFactory.getAsync(COLLECTION_NAME);
entityManager = managerFactory.get(INDEX);
DocumentEntity documentEntity = 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();
entityManagerAsync.delete(deleteQuery);
}
Aggregations