use of org.jnosql.diana.api.document.DocumentQuery 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.DocumentQuery 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.DocumentQuery 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.DocumentQuery in project jnosql-diana-driver by eclipse.
the class QueryOSQLFactory method toAsync.
static QueryResult toAsync(DocumentQuery documentQuery, Consumer<List<ODocument>> callBack) {
Query query = QueryOSQLConverter.select(documentQuery);
return new QueryResult(new OSQLAsynchQuery<>(query.getQuery(), new OCommandResultListener() {
private List<ODocument> documents = new ArrayList<>();
@Override
public boolean result(Object iRecord) {
ODocument document = (ODocument) iRecord;
documents.add(document);
return true;
}
@Override
public void end() {
callBack.accept(documents);
}
@Override
public Object getResult() {
return null;
}
}), query.getParams());
}
use of org.jnosql.diana.api.document.DocumentQuery in project jnosql-diana-driver by eclipse.
the class QueryOSQLFactory method toLive.
static QueryResult toLive(DocumentQuery documentQuery, OrientDBLiveCallback callbacks) {
Query query = QueryOSQLConverter.select(documentQuery);
OLiveQuery<ODocument> liveQuery = new OLiveQuery<>(LIVE + query.getQuery(), new LiveQueryLIstener(callbacks));
return new QueryResult(liveQuery, query.getParams());
}
Aggregations