use of jakarta.nosql.document.DocumentQuery in project jnosql-diana-driver by eclipse.
the class ElasticsearchDocumentCollectionManagerTest method shouldSaveSubDocument2.
@Test
public void shouldSaveSubDocument2() {
DocumentEntity entity = DocumentEntityGerator.getEntity();
entity.add(Document.of("phones", Arrays.asList(Document.of("mobile", "1231231"), Document.of("mobile2", "1231231"))));
DocumentEntity entitySaved = entityManager.insert(entity);
Document id = entitySaved.find("_id").get();
DocumentQuery query = select().from(DocumentEntityGerator.COLLECTION_NAME).where(id.getName()).eq(id.get()).build();
DocumentEntity entityFound = entityManager.select(query).collect(Collectors.toList()).get(0);
Document subDocument = entityFound.find("phones").get();
List<Document> documents = subDocument.get(new TypeReference<List<Document>>() {
});
assertThat(documents, containsInAnyOrder(Document.of("mobile", "1231231"), Document.of("mobile2", "1231231")));
}
use of jakarta.nosql.document.DocumentQuery in project jnosql-diana-driver by eclipse.
the class ElasticsearchDocumentCollectionManagerTest method shouldFindOrderByNameDesc.
@Test
public void shouldFindOrderByNameDesc() throws InterruptedException {
final DocumentEntity poliana = DocumentEntityGerator.getEntity();
final DocumentEntity otavio = DocumentEntityGerator.getEntity();
poliana.add("name", "poliana");
otavio.add("name", "otavio");
otavio.add("_id", "id2");
entityManager.insert(Arrays.asList(poliana, otavio));
SECONDS.sleep(1L);
DocumentQuery query = DocumentQuery.select().from("person").orderBy("name").desc().build();
String[] names = entityManager.select(query).map(d -> d.find("name")).filter(Optional::isPresent).map(Optional::get).map(d -> d.get(String.class)).toArray(String[]::new);
assertArrayEquals(names, new String[] { "poliana", "otavio" });
}
use of jakarta.nosql.document.DocumentQuery in project jnosql-diana-driver by eclipse.
the class ElasticsearchDocumentCollectionManagerTest method shouldRetrieveListSubdocumentList.
@Test
public void shouldRetrieveListSubdocumentList() {
DocumentEntity entity = entityManager.insert(createSubdocumentList());
Document key = entity.find("_id").get();
DocumentQuery query = select().from(DocumentEntityGerator.COLLECTION_NAME).where(key.getName()).eq(key.get()).build();
DocumentEntity documentEntity = entityManager.singleResult(query).get();
assertNotNull(documentEntity);
List<List<Document>> contacts = (List<List<Document>>) documentEntity.find("contacts").get().get();
assertEquals(3, contacts.size());
assertTrue(contacts.stream().allMatch(d -> d.size() == 3));
}
use of jakarta.nosql.document.DocumentQuery in project jnosql-diana-driver by eclipse.
the class EntityConverter method executeStatement.
private static Stream<DocumentEntity> executeStatement(DocumentQuery query, RestHighLevelClient client, String index, QueryConverterResult select) throws IOException {
SearchRequest searchRequest = new SearchRequest(index);
setQueryBuilder(query, select, searchRequest);
SearchResponse response = client.search(searchRequest, RequestOptions.DEFAULT);
return Stream.of(response.getHits()).flatMap(h -> Stream.of(h.getHits())).map(ElasticsearchEntry::of).filter(ElasticsearchEntry::isNotEmpty).map(ElasticsearchEntry::toEntity);
}
use of jakarta.nosql.document.DocumentQuery in project jnosql-diana-driver by eclipse.
the class MongoDBDocumentCollectionManagerTest method shouldFindDocumentLesserEqualsThan.
@Test
public void shouldFindDocumentLesserEqualsThan() {
DocumentDeleteQuery deleteQuery = delete().from(COLLECTION_NAME).where("type").eq("V").build();
entityManager.delete(deleteQuery);
Iterable<DocumentEntity> entitiesSaved = entityManager.insert(getEntitiesWithValues());
List<DocumentEntity> entities = StreamSupport.stream(entitiesSaved.spliterator(), false).collect(Collectors.toList());
DocumentQuery query = select().from(COLLECTION_NAME).where("age").lte(23).and("type").eq("V").build();
List<DocumentEntity> entitiesFound = entityManager.select(query).collect(Collectors.toList());
assertTrue(entitiesFound.size() == 2);
assertThat(entitiesFound, contains(entities.get(0), entities.get(2)));
}
Aggregations