use of org.jnosql.diana.api.document.DocumentEntity in project jnosql-diana-driver by eclipse.
the class ElasticsearchDocumentCollectionManagerTest method shouldUserSearchBuilder.
@Test
public void shouldUserSearchBuilder() {
DocumentEntity entity = getEntity();
entityManager.insert(entity);
TermQueryBuilder query = termQuery("name", "Poliana");
List<DocumentEntity> account = entityManager.search(query, "person");
assertFalse(account.isEmpty());
}
use of org.jnosql.diana.api.document.DocumentEntity in project jnosql-diana-driver by eclipse.
the class ElasticsearchDocumentCollectionManagerTest method shouldFindDocumentByName.
@Test
public void shouldFindDocumentByName() throws InterruptedException {
DocumentEntity entity = entityManager.insert(getEntity());
Document name = entity.find("name").get();
DocumentQuery query = select().from(COLLECTION_NAME).where(name.getName()).eq(name.get()).build();
TimeUnit.SECONDS.sleep(1L);
List<DocumentEntity> entities = entityManager.select(query);
assertFalse(entities.isEmpty());
assertThat(entities, contains(entity));
}
use of org.jnosql.diana.api.document.DocumentEntity in project jnosql-diana-driver by eclipse.
the class ElasticsearchDocumentCollectionManagerTest method shouldReturnAll.
@Test
public void shouldReturnAll() {
DocumentEntity entity = getEntity();
entityManager.insert(entity);
DocumentQuery query = select().from(COLLECTION_NAME).build();
List<DocumentEntity> result = entityManager.select(query);
assertFalse(result.isEmpty());
}
use of org.jnosql.diana.api.document.DocumentEntity in project jnosql-diana-driver by eclipse.
the class EntityConverter method queryAsync.
static void queryAsync(DocumentQuery query, RestHighLevelClient client, String index, Consumer<List<DocumentEntity>> callBack) {
FindAsyncListener listener = new FindAsyncListener(callBack, query.getDocumentCollection());
QueryConverterResult select = QueryConverter.select(query);
if (!select.getIds().isEmpty()) {
MultiGetRequest multiGetRequest = new MultiGetRequest();
select.getIds().stream().map(id -> new MultiGetRequest.Item(index, query.getDocumentCollection(), id)).forEach(multiGetRequest::add);
client.multiGetAsync(multiGetRequest, listener.getIds());
}
if (select.hasStatement()) {
SearchRequest searchRequest = new SearchRequest(index);
searchRequest.types(query.getDocumentCollection());
if (select.hasQuery()) {
setQueryBuilder(query, select, searchRequest);
}
client.searchAsync(searchRequest, listener.getSearch());
}
}
use of org.jnosql.diana.api.document.DocumentEntity in project jnosql-diana-driver by eclipse.
the class OrientDBDocumentCollectionManagerAsyncTest method shouldRemoveEntityAsync.
@Test
public void shouldRemoveEntityAsync() throws InterruptedException {
DocumentEntity documentEntity = entityManager.insert(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();
AtomicBoolean condition = new AtomicBoolean(false);
entityManagerAsync.delete(deleteQuery, c -> condition.set(true));
await().untilTrue(condition);
assertTrue(entityManager.select(query).isEmpty());
}
Aggregations