use of org.jnosql.diana.api.document.DocumentQuery 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);
assertFalse(entities.isEmpty());
assertThat(entities, contains(entity));
}
use of org.jnosql.diana.api.document.DocumentQuery in project jnosql-diana-driver by eclipse.
the class MongoDBDocumentCollectionManagerTest method shouldFindDocumentLesserThan.
@Test
public void shouldFindDocumentLesserThan() {
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").lt(23).and("type").eq("V").build();
List<DocumentEntity> entitiesFound = entityManager.select(query);
assertTrue(entitiesFound.size() == 1);
assertThat(entitiesFound, contains(entities.get(0)));
}
use of org.jnosql.diana.api.document.DocumentQuery in project jnosql-diana-driver by eclipse.
the class MongoDBDocumentCollectionManagerTest method shouldFindDocumentGreaterEqualsThan.
@Test
public void shouldFindDocumentGreaterEqualsThan() {
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").gte(23).and("type").eq("V").build();
List<DocumentEntity> entitiesFound = entityManager.select(query);
assertTrue(entitiesFound.size() == 2);
assertThat(entitiesFound, not(contains(entities.get(0))));
}
use of org.jnosql.diana.api.document.DocumentQuery in project jnosql-diana-driver by eclipse.
the class MongoDBDocumentCollectionManagerTest method shouldSaveSubDocument.
@Test
public void shouldSaveSubDocument() {
DocumentEntity entity = getEntity();
entity.add(Document.of("phones", Document.of("mobile", "1231231")));
DocumentEntity entitySaved = entityManager.insert(entity);
Document id = entitySaved.find("_id").get();
DocumentQuery query = select().from(COLLECTION_NAME).where("_id").eq(id.get()).build();
DocumentEntity entityFound = entityManager.select(query).get(0);
Document subDocument = entityFound.find("phones").get();
List<Document> documents = subDocument.get(new TypeReference<List<Document>>() {
});
assertThat(documents, contains(Document.of("mobile", "1231231")));
}
use of org.jnosql.diana.api.document.DocumentQuery in project jnosql-diana-driver by eclipse.
the class DefaultOrientDBDocumentCollectionManager method delete.
@Override
public void delete(DocumentDeleteQuery query) {
requireNonNull(query, "query is required");
DocumentQuery selectQuery = new OrientDBDocumentQuery(query);
try (ODatabaseDocumentTx tx = pool.acquire()) {
QueryOSQLFactory.QueryResult orientQuery = QueryOSQLFactory.to(selectQuery);
List<ODocument> result = tx.command(orientQuery.getQuery()).execute(orientQuery.getParams());
result.forEach(tx::delete);
}
}
Aggregations