use of jakarta.nosql.document.Document 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.Document in project jnosql-diana-driver by eclipse.
the class DocumentQueryConversor method convert.
public static Bson convert(DocumentCondition condition) {
Document document = condition.getDocument();
Object value = ValueUtil.convert(document.getValue());
switch(condition.getCondition()) {
case EQUALS:
return Filters.eq(document.getName(), value);
case GREATER_THAN:
return Filters.gt(document.getName(), value);
case GREATER_EQUALS_THAN:
return Filters.gte(document.getName(), value);
case LESSER_THAN:
return Filters.lt(document.getName(), value);
case LESSER_EQUALS_THAN:
return Filters.lte(document.getName(), value);
case IN:
List<Object> inList = ValueUtil.convertToList(document.getValue());
return Filters.in(document.getName(), inList.toArray());
case NOT:
return Filters.not(convert(document.get(DocumentCondition.class)));
case LIKE:
return Filters.regex(document.getName(), value.toString());
case AND:
List<DocumentCondition> andList = condition.getDocument().getValue().get(new TypeReference<List<DocumentCondition>>() {
});
return Filters.and(andList.stream().map(DocumentQueryConversor::convert).collect(Collectors.toList()));
case OR:
List<DocumentCondition> orList = condition.getDocument().getValue().get(new TypeReference<List<DocumentCondition>>() {
});
return Filters.or(orList.stream().map(DocumentQueryConversor::convert).collect(Collectors.toList()));
default:
throw new UnsupportedOperationException("The condition " + condition.getCondition() + " is not supported from mongoDB diana driver");
}
}
use of jakarta.nosql.document.Document in project jnosql-diana-driver by eclipse.
the class MongoDBDocumentCollectionManagerTest method shouldFindDocument2.
@Test
public void shouldFindDocument2() {
DocumentEntity entity = entityManager.insert(getEntity());
Optional<Document> id = entity.find("_id");
DocumentQuery query = select().from(COLLECTION_NAME).where("name").eq("Poliana").and("city").eq("Salvador").and("_id").eq(id.get().get()).build();
List<DocumentEntity> entities = entityManager.select(query).collect(Collectors.toList());
assertFalse(entities.isEmpty());
assertThat(entities, contains(entity));
}
use of jakarta.nosql.document.Document in project jnosql-diana-driver by eclipse.
the class MongoDBDocumentCollectionManagerTest method shouldFindDocument3.
@Test
public void shouldFindDocument3() {
DocumentEntity entity = entityManager.insert(getEntity());
Optional<Document> id = entity.find("_id");
DocumentQuery query = select().from(COLLECTION_NAME).where("name").eq("Poliana").or("city").eq("Salvador").and(id.get().getName()).eq(id.get().get()).build();
List<DocumentEntity> entities = entityManager.select(query).collect(Collectors.toList());
assertFalse(entities.isEmpty());
assertThat(entities, contains(entity));
}
use of jakarta.nosql.document.Document in project jnosql-diana-driver by eclipse.
the class MongoDBDocumentCollectionManagerTest method shouldFindDocument.
@Test
public void shouldFindDocument() {
DocumentEntity entity = entityManager.insert(getEntity());
Optional<Document> id = entity.find("_id");
DocumentQuery query = select().from(COLLECTION_NAME).where("_id").eq(id.get().get()).build();
List<DocumentEntity> entities = entityManager.select(query).collect(Collectors.toList());
assertFalse(entities.isEmpty());
assertThat(entities, contains(entity));
}
Aggregations