use of org.jnosql.diana.api.document.Document in project jnosql-diana-driver by eclipse.
the class CouchbaseDocumentCollectionManagerTest method shouldSaveSetDocument.
@Test
public void shouldSaveSetDocument() throws InterruptedException {
Set<String> set = new HashSet<>();
set.add("Acarajé");
set.add("Munguzá");
DocumentEntity entity = DocumentEntity.of(COLLECTION_NAME);
entity.add(Document.of("_id", "id"));
entity.add(Document.of("foods", set));
entityManager.insert(entity);
Document id = entity.find("_id").get();
Thread.sleep(1_000L);
DocumentQuery query = select().from(COLLECTION_NAME).where(id.getName()).eq(id.get()).build();
DocumentEntity entityFound = entityManager.singleResult(query).get();
Optional<Document> foods = entityFound.find("foods");
Set<String> setFoods = foods.get().get(new TypeReference<Set<String>>() {
});
assertEquals(set, setFoods);
}
use of org.jnosql.diana.api.document.Document 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);
assertEquals(2, entities.size());
}
use of org.jnosql.diana.api.document.Document in project jnosql-diana-driver by eclipse.
the class DocumentQueryTest method shouldFindDocumentByNameSortDesc.
@Test
public void shouldFindDocumentByNameSortDesc() {
DocumentEntity entity = DocumentEntity.of("person", asList(Document.of("_id", "id4"), Document.of("name", "name3"), Document.of("_key", "person:id4")));
Optional<Document> name = entity.find("name");
DocumentQuery query = select().from(COLLECTION_NAME).orderBy("name").desc().build();
List<DocumentEntity> entities = entityManager.select(query);
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());
assertFalse(result.isEmpty());
assertThat(result, contains("name3", "name", "name", "name"));
}
use of org.jnosql.diana.api.document.Document in project jnosql-diana-driver by eclipse.
the class DocumentQueryTest method shouldShouldDefineLimitAndStart.
@Test
public void shouldShouldDefineLimitAndStart() {
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()).start(2L).limit(2L).build();
List<DocumentEntity> entities = entityManager.select(query);
assertEquals(1, entities.size());
}
use of org.jnosql.diana.api.document.Document in project jnosql-diana-driver by eclipse.
the class DocumentQueryTest method shouldShouldDefineStart.
@Test
public void shouldShouldDefineStart() {
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()).start(1L).build();
List<DocumentEntity> entities = entityManager.select(query);
assertEquals(2, entities.size());
}
Aggregations