use of org.jnosql.diana.api.document.Document in project jnosql-diana-driver by eclipse.
the class DocumentQueryTest method shouldSelectAll.
@Test
public void shouldSelectAll() {
DocumentEntity entity = DocumentEntity.of("person", asList(Document.of("_id", "id"), Document.of("name", "name")));
DocumentQuery query = select().from(COLLECTION_NAME).build();
Optional<Document> name = entity.find("name");
List<DocumentEntity> entities = entityManager.select(query);
assertFalse(entities.isEmpty());
assertTrue(entities.size() >= 4);
}
use of org.jnosql.diana.api.document.Document in project jnosql-diana-driver by eclipse.
the class DocumentEntityGerator method getEntity.
static DocumentEntity getEntity() {
DocumentEntity entity = DocumentEntity.of(COLLECTION_NAME);
Map<String, Object> map = new HashMap<>();
map.put("name", "Poliana");
map.put("city", "Salvador");
map.put("_id", "id");
List<Document> documents = Documents.of(map);
documents.forEach(entity::add);
return entity;
}
use of org.jnosql.diana.api.document.Document 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));
}
use of org.jnosql.diana.api.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 = document.get();
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 = document.get(new TypeReference<List<Object>>() {
});
return Filters.in(document.getName(), inList.toArray());
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 org.jnosql.diana.api.document.Document in project jnosql-diana-driver by eclipse.
the class OrientDBDocumentCollectionManagerAsyncTest method shouldRemoveEntityAsync.
@Test
public void shouldRemoveEntityAsync() throws InterruptedException {
DocumentEntity documentEntity = entityManager.insert(getEntity());
Document id = documentEntity.find("name").get();
DocumentQuery query = select().from(COLLECTION_NAME).where(id.getName()).eq(id.get()).build();
DocumentDeleteQuery deleteQuery = delete().from(COLLECTION_NAME).where(id.getName()).eq(id.get()).build();
AtomicBoolean condition = new AtomicBoolean(false);
entityManagerAsync.delete(deleteQuery, c -> condition.set(true));
await().untilTrue(condition);
assertTrue(entityManager.select(query).isEmpty());
}
Aggregations