Search in sources :

Example 41 with DocumentQuery

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));
}
Also used : DocumentQuery(org.jnosql.diana.api.document.DocumentQuery) DocumentEntity(org.jnosql.diana.api.document.DocumentEntity) Document(org.jnosql.diana.api.document.Document) Test(org.junit.jupiter.api.Test)

Example 42 with DocumentQuery

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());
}
Also used : DocumentQuery(org.jnosql.diana.api.document.DocumentQuery) DocumentEntity(org.jnosql.diana.api.document.DocumentEntity) Test(org.junit.jupiter.api.Test)

Example 43 with DocumentQuery

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());
    }
}
Also used : Document(org.jnosql.diana.api.document.Document) MultiGetResponse(org.elasticsearch.action.get.MultiGetResponse) MultiGetRequest(org.elasticsearch.action.get.MultiGetRequest) IOException(java.io.IOException) HashMap(java.util.HashMap) MultiGetItemResponse(org.elasticsearch.action.get.MultiGetItemResponse) SearchRequest(org.elasticsearch.action.search.SearchRequest) RestHighLevelClient(org.elasticsearch.client.RestHighLevelClient) DocumentQuery(org.jnosql.diana.api.document.DocumentQuery) ArrayList(java.util.ArrayList) Consumer(java.util.function.Consumer) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) Stream(java.util.stream.Stream) DocumentEntity(org.jnosql.diana.api.document.DocumentEntity) Map(java.util.Map) SearchResponse(org.elasticsearch.action.search.SearchResponse) SearchSourceBuilder(org.elasticsearch.search.builder.SearchSourceBuilder) StreamSupport(java.util.stream.StreamSupport) Collections.singletonMap(java.util.Collections.singletonMap) ValueUtil(org.jnosql.diana.driver.ValueUtil) SearchRequest(org.elasticsearch.action.search.SearchRequest) MultiGetRequest(org.elasticsearch.action.get.MultiGetRequest)

Example 44 with DocumentQuery

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());
}
Also used : Query(org.jnosql.diana.orientdb.document.QueryOSQLConverter.Query) OSQLQuery(com.orientechnologies.orient.core.sql.query.OSQLQuery) OSQLSynchQuery(com.orientechnologies.orient.core.sql.query.OSQLSynchQuery) OLiveQuery(com.orientechnologies.orient.core.sql.query.OLiveQuery) OSQLAsynchQuery(com.orientechnologies.orient.core.sql.query.OSQLAsynchQuery) DocumentQuery(org.jnosql.diana.api.document.DocumentQuery) OCommandResultListener(com.orientechnologies.orient.core.command.OCommandResultListener) List(java.util.List) Arrays.asList(java.util.Arrays.asList) ArrayList(java.util.ArrayList) ODocument(com.orientechnologies.orient.core.record.impl.ODocument)

Example 45 with DocumentQuery

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());
}
Also used : Query(org.jnosql.diana.orientdb.document.QueryOSQLConverter.Query) OSQLQuery(com.orientechnologies.orient.core.sql.query.OSQLQuery) OSQLSynchQuery(com.orientechnologies.orient.core.sql.query.OSQLSynchQuery) OLiveQuery(com.orientechnologies.orient.core.sql.query.OLiveQuery) OSQLAsynchQuery(com.orientechnologies.orient.core.sql.query.OSQLAsynchQuery) DocumentQuery(org.jnosql.diana.api.document.DocumentQuery) OLiveQuery(com.orientechnologies.orient.core.sql.query.OLiveQuery) ODocument(com.orientechnologies.orient.core.record.impl.ODocument)

Aggregations

DocumentQuery (org.jnosql.diana.api.document.DocumentQuery)201 Test (org.junit.jupiter.api.Test)186 DocumentEntity (org.jnosql.diana.api.document.DocumentEntity)95 Document (org.jnosql.diana.api.document.Document)84 List (java.util.List)50 DocumentDeleteQuery (org.jnosql.diana.api.document.DocumentDeleteQuery)46 Person (org.jnosql.artemis.model.Person)37 DocumentCondition (org.jnosql.diana.api.document.DocumentCondition)35 Arrays.asList (java.util.Arrays.asList)27 ArrayList (java.util.ArrayList)21 Duration (java.time.Duration)20 DocumentQueryBuilder.select (org.jnosql.diana.api.document.query.DocumentQueryBuilder.select)20 Optional (java.util.Optional)18 AtomicReference (java.util.concurrent.atomic.AtomicReference)18 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)18 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)17 DocumentQueryBuilder.delete (org.jnosql.diana.api.document.query.DocumentQueryBuilder.delete)17 BeforeEach (org.junit.jupiter.api.BeforeEach)17 Consumer (java.util.function.Consumer)16 Assertions.assertNotNull (org.junit.jupiter.api.Assertions.assertNotNull)16