use of org.jnosql.diana.api.document.DocumentEntity in project jnosql-diana-driver by eclipse.
the class CouchbaseDocumentCollectionManagerTest method shouldSaveSubDocument2.
@Test
public void shouldSaveSubDocument2() throws InterruptedException {
DocumentEntity entity = getEntity();
entity.add(Document.of("phones", asList(Document.of("mobile", "1231231"), Document.of("mobile2", "1231231"))));
DocumentEntity entitySaved = entityManager.insert(entity);
Thread.sleep(1_00L);
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, contains(Document.of("mobile", "1231231"), Document.of("mobile2", "1231231")));
}
use of org.jnosql.diana.api.document.DocumentEntity in project jnosql-diana-driver by eclipse.
the class CouchbaseDocumentCollectionManagerTest method shouldSaveSubDocument.
@Test
public void shouldSaveSubDocument() throws InterruptedException {
DocumentEntity entity = getEntity();
entity.add(Document.of("phones", Document.of("mobile", "1231231")));
DocumentEntity entitySaved = entityManager.insert(entity);
Thread.sleep(5_00L);
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, contains(Document.of("mobile", "1231231")));
}
use of org.jnosql.diana.api.document.DocumentEntity in project jnosql-diana-driver by eclipse.
the class CouchbaseDocumentCollectionManagerTest method shouldSaveSetDocument.
@Test
public void shouldSaveSetDocument() throws InterruptedException {
Set<String> set = new HashSet<>();
set.add("Acarajé");
set.add("Munguzá");
DocumentEntity entity = DocumentEntity.of(COLLECTION_NAME);
entity.add(Document.of("_id", "id"));
entity.add(Document.of("foods", set));
entityManager.insert(entity);
Document id = entity.find("_id").get();
Thread.sleep(1_000L);
DocumentQuery query = select().from(COLLECTION_NAME).where(id.getName()).eq(id.get()).build();
DocumentEntity entityFound = entityManager.singleResult(query).get();
Optional<Document> foods = entityFound.find("foods");
Set<String> setFoods = foods.get().get(new TypeReference<Set<String>>() {
});
assertEquals(set, setFoods);
}
use of org.jnosql.diana.api.document.DocumentEntity in project jnosql-diana-driver by eclipse.
the class CouchbaseDocumentCollectionManagerTest method shouldConvertFromListSubdocumentList.
@Test
public void shouldConvertFromListSubdocumentList() {
DocumentEntity entity = createSubdocumentList();
entityManager.insert(entity);
}
use of org.jnosql.diana.api.document.DocumentEntity in project jnosql-diana-driver by eclipse.
the class DefaultElasticsearchDocumentCollectionManager method delete.
@Override
public void delete(DocumentDeleteQuery query) throws NullPointerException {
requireNonNull(query, "query is required");
query.getCondition().orElseThrow(() -> new IllegalArgumentException("condition is required"));
DocumentQuery select = new ElasticsearchDocumentQuery(query);
List<DocumentEntity> entities = select(select);
if (entities.isEmpty()) {
return;
}
BulkRequest bulk = new BulkRequest();
entities.stream().map(entity -> entity.find(ID_FIELD).get().get(String.class)).map(id -> new DeleteRequest(index, query.getDocumentCollection(), id)).forEach(bulk::add);
try {
client.bulk(bulk);
} catch (IOException e) {
throw new ElasticsearchException("An error to delete entities on elasticsearch", e);
}
}
Aggregations