use of org.jnosql.diana.api.document.Document in project jnosql-diana-driver by eclipse.
the class ArangoDBDocumentCollectionManagerTest method shouldSaveSubDocument2.
@Test
public void shouldSaveSubDocument2() {
DocumentEntity entity = getEntity();
entity.add(Document.of("phones", Arrays.asList(Document.of("mobile", "1231231"), Document.of("mobile2", "1231231"))));
DocumentEntity entitySaved = entityManager.insert(entity);
Document id = entitySaved.find(KEY_NAME).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 EntityConverter method convertIterable.
private static void convertIterable(JsonObject jsonObject, Document document, Object value) {
JsonObject map = JsonObject.create();
JsonArray array = JsonArray.create();
Iterable.class.cast(value).forEach(element -> {
if (Document.class.isInstance(element)) {
Document subdocument = Document.class.cast(element);
map.put(subdocument.getName(), subdocument.get());
} else if (isSudDocument(element)) {
JsonObject subJson = JsonObject.create();
stream(Iterable.class.cast(element).spliterator(), false).forEach(getSubdocument(subJson));
array.add(subJson);
} else {
array.add(element);
}
});
if (array.isEmpty()) {
jsonObject.put(document.getName(), map);
} else {
jsonObject.put(document.getName(), array);
}
}
use of org.jnosql.diana.api.document.Document in project jnosql-diana-driver by eclipse.
the class EntityConverter method convertDocument.
private static void convertDocument(JsonObject jsonObject, Document d, Object value) {
Document document = Document.class.cast(value);
jsonObject.put(d.getName(), Collections.singletonMap(document.getName(), document.get()));
}
use of org.jnosql.diana.api.document.Document in project jnosql-diana-driver by eclipse.
the class CouchbaseDocumentCollectionManagerAsyncTest method setUp.
@BeforeEach
public void setUp() {
CouchbaseDocumentConfiguration configuration = new CouchbaseDocumentConfiguration();
CouhbaseDocumentCollectionManagerFactory managerFactory = configuration.get();
entityManagerAsync = managerFactory.getAsync(CouchbaseUtil.BUCKET_NAME);
entityManager = managerFactory.get(CouchbaseUtil.BUCKET_NAME);
DocumentEntity documentEntity = getEntity();
Document id = documentEntity.find("name").get();
DocumentDeleteQuery deleteQuery = delete().from(COLLECTION_NAME).where(id.getName()).eq(id.get()).build();
entityManagerAsync.delete(deleteQuery);
}
use of org.jnosql.diana.api.document.Document in project jnosql-diana-driver by eclipse.
the class CouchbaseDocumentCollectionManagerAsyncTest method shouldInserAsyncTTL.
@Test
public void shouldInserAsyncTTL() throws InterruptedException {
DocumentEntity entity = getEntity();
entityManagerAsync.insert(entity, Duration.ofSeconds(1L));
TimeUnit.SECONDS.sleep(2L);
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);
assertTrue(entities.isEmpty());
}
Aggregations