Search in sources :

Example 76 with DocumentEntity

use of jakarta.nosql.document.DocumentEntity in project jnosql-diana-driver by eclipse.

the class SearchQueryTest method shouldSearchElement3.

@Test
public void shouldSearchElement3() {
    MatchQuery match = SearchQuery.match("Salvador").field("name");
    SearchQuery query = new SearchQuery("index-diana", match);
    List<DocumentEntity> entities = entityManager.search(query).collect(Collectors.toList());
    assertEquals(1, entities.size());
    List<String> result = entities.stream().flatMap(e -> e.getDocuments().stream()).filter(d -> "name".equals(d.getName())).map(d -> d.get(String.class)).collect(Collectors.toList());
    assertThat(result, containsInAnyOrder("Salvador"));
}
Also used : SearchQuery(com.couchbase.client.java.search.SearchQuery) BucketManagerFactory(jakarta.nosql.keyvalue.BucketManagerFactory) Arrays(java.util.Arrays) MatchQuery(com.couchbase.client.java.search.queries.MatchQuery) CouchbaseUtil(org.eclipse.jnosql.communication.couchbase.CouchbaseUtil) Document(jakarta.nosql.document.Document) DocumentEntity(jakarta.nosql.document.DocumentEntity) Collectors(java.util.stream.Collectors) AfterAll(org.junit.jupiter.api.AfterAll) Test(org.junit.jupiter.api.Test) CouchbaseKeyValueTcConfiguration(org.eclipse.jnosql.communication.couchbase.configuration.CouchbaseKeyValueTcConfiguration) List(java.util.List) CouchbaseDocumentTcConfiguration(org.eclipse.jnosql.communication.couchbase.configuration.CouchbaseDocumentTcConfiguration) BeforeAll(org.junit.jupiter.api.BeforeAll) Matchers.containsInAnyOrder(org.hamcrest.Matchers.containsInAnyOrder) Arrays.asList(java.util.Arrays.asList) CouchbaseKeyValueConfiguration(org.eclipse.jnosql.communication.couchbase.keyvalue.CouchbaseKeyValueConfiguration) BucketManager(jakarta.nosql.keyvalue.BucketManager) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) SearchQuery(com.couchbase.client.java.search.SearchQuery) DocumentEntity(jakarta.nosql.document.DocumentEntity) MatchQuery(com.couchbase.client.java.search.queries.MatchQuery) Test(org.junit.jupiter.api.Test)

Example 77 with DocumentEntity

use of jakarta.nosql.document.DocumentEntity in project jnosql-diana-driver by eclipse.

the class SearchQueryTest method shouldSearchElement.

@Test
public void shouldSearchElement() {
    MatchQuery match = SearchQuery.match("Financial");
    SearchQuery query = new SearchQuery("index-diana", match);
    List<DocumentEntity> entities = entityManager.search(query).collect(Collectors.toList());
    assertEquals(1, entities.size());
    assertEquals(Document.of("name", "São Paulo"), entities.get(0).find("name").get());
}
Also used : SearchQuery(com.couchbase.client.java.search.SearchQuery) DocumentEntity(jakarta.nosql.document.DocumentEntity) MatchQuery(com.couchbase.client.java.search.queries.MatchQuery) Test(org.junit.jupiter.api.Test)

Example 78 with DocumentEntity

use of jakarta.nosql.document.DocumentEntity in project jnosql-diana-driver by eclipse.

the class DefaultCouchbaseDocumentCollectionManager method select.

@Override
public Stream<DocumentEntity> select(DocumentQuery query) throws NullPointerException {
    QueryConverter.QueryConverterResult select = QueryConverter.select(query, database);
    Stream<DocumentEntity> idsQuery = Stream.empty();
    Stream<DocumentEntity> n1qlQueryStream = Stream.empty();
    if (nonNull(select.getStatement())) {
        ParameterizedN1qlQuery n1qlQuery = N1qlQuery.parameterized(select.getStatement(), select.getParams());
        N1qlQueryResult result = bucket.query(n1qlQuery);
        idsQuery = convert(result, database);
    }
    if (!select.getKeys().isEmpty()) {
        idsQuery = convert(select.getKeys().stream(), bucket);
    }
    return Stream.concat(n1qlQueryStream, idsQuery);
}
Also used : DocumentEntity(jakarta.nosql.document.DocumentEntity) ParameterizedN1qlQuery(com.couchbase.client.java.query.ParameterizedN1qlQuery) N1qlQueryResult(com.couchbase.client.java.query.N1qlQueryResult)

Example 79 with DocumentEntity

use of jakarta.nosql.document.DocumentEntity in project jnosql-diana-driver by eclipse.

the class DocumentQueryTest method shouldShouldDefineLimit.

@Test
public void shouldShouldDefineLimit() {
    DocumentEntity entity = DocumentEntity.of("person", asList(Document.of("_id", "id"), Document.of("name", "name")));
    Document name = entity.find("name").get();
    DocumentQuery query = select().from(COLLECTION_NAME).where(name.getName()).eq(name.get()).limit(2L).build();
    List<DocumentEntity> entities = entityManager.select(query).collect(Collectors.toList());
    assertEquals(2, entities.size());
}
Also used : DocumentQuery(jakarta.nosql.document.DocumentQuery) DocumentEntity(jakarta.nosql.document.DocumentEntity) Document(jakarta.nosql.document.Document) Test(org.junit.jupiter.api.Test)

Example 80 with DocumentEntity

use of jakarta.nosql.document.DocumentEntity in project jnosql-diana-driver by eclipse.

the class DocumentQueryTest method shouldFindDocumentByName.

@Test
public void shouldFindDocumentByName() {
    DocumentEntity entity = DocumentEntity.of("person", asList(Document.of("_id", "id4"), Document.of("name", "name3"), Document.of("_key", "person:id4")));
    Document name = entity.find("name").get();
    DocumentQuery query = select().from(COLLECTION_NAME).where(name.getName()).eq(name.get()).build();
    List<DocumentEntity> entities = entityManager.select(query).collect(Collectors.toList());
    assertFalse(entities.isEmpty());
    assertThat(entities, contains(entity));
}
Also used : DocumentQuery(jakarta.nosql.document.DocumentQuery) DocumentEntity(jakarta.nosql.document.DocumentEntity) Document(jakarta.nosql.document.Document) Test(org.junit.jupiter.api.Test)

Aggregations

DocumentEntity (jakarta.nosql.document.DocumentEntity)312 Test (org.junit.jupiter.api.Test)238 DocumentQuery (jakarta.nosql.document.DocumentQuery)131 Document (jakarta.nosql.document.Document)129 DocumentDeleteQuery (jakarta.nosql.document.DocumentDeleteQuery)62 List (java.util.List)54 Arrays.asList (java.util.Arrays.asList)51 ArrayList (java.util.ArrayList)46 Duration (java.time.Duration)31 HashMap (java.util.HashMap)30 Map (java.util.Map)27 Collectors (java.util.stream.Collectors)27 MatcherAssert.assertThat (org.hamcrest.MatcherAssert.assertThat)25 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)25 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)23 ValueSource (org.junit.jupiter.params.provider.ValueSource)23 TypeReference (jakarta.nosql.TypeReference)21 DocumentQuery.select (jakarta.nosql.document.DocumentQuery.select)21 Matchers.contains (org.hamcrest.Matchers.contains)21 Assertions.assertFalse (org.junit.jupiter.api.Assertions.assertFalse)21