use of org.jnosql.diana.api.document.DocumentEntity in project jnosql-diana-driver by eclipse.
the class OrientDBDocumentCollectionManagerTest method shouldQueryLike.
@Test
public void shouldQueryLike() {
List<DocumentEntity> entitiesSaved = StreamSupport.stream(entityManager.insert(getEntities()).spliterator(), false).collect(Collectors.toList());
DocumentQuery query = select().from(COLLECTION_NAME).where("city").like("Sa%").build();
List<DocumentEntity> entities = entityManager.select(query);
assertTrue(entities.size() == 2);
assertThat(entities, containsInAnyOrder(entitiesSaved.get(0), entitiesSaved.get(1)));
}
use of org.jnosql.diana.api.document.DocumentEntity in project jnosql-diana-driver by eclipse.
the class OrientDBDocumentCollectionManagerTest method shouldQueryAnd.
@Test
public void shouldQueryAnd() {
DocumentEntity entity = getEntity();
entity.add(Document.of("age", 24));
entityManager.insert(entity);
DocumentQuery query = select().from(COLLECTION_NAME).where("name").eq("Poliana").and("age").gte(10).build();
DocumentDeleteQuery deleteQuery = delete().from(COLLECTION_NAME).where("name").eq("Poliana").and("age").gte(10).build();
assertFalse(entityManager.select(query).isEmpty());
entityManager.delete(deleteQuery);
assertTrue(entityManager.select(query).isEmpty());
}
use of org.jnosql.diana.api.document.DocumentEntity in project jnosql-diana-driver by eclipse.
the class OrientDBDocumentCollectionManagerTest method shouldLiveDeleteCallback.
@Test
public void shouldLiveDeleteCallback() {
AtomicBoolean condition = new AtomicBoolean(false);
OrientDBLiveDeleteCallback<DocumentEntity> callback = d -> condition.set(true);
DocumentEntity entity = entityManager.insert(getEntity());
Document id = entity.find(OrientDBConverter.RID_FIELD).get();
DocumentQuery query = select().from(COLLECTION_NAME).where(id.getName()).eq(id.get()).build();
entityManager.live(query, OrientDBLiveCallbackBuilder.builder().onDelete(callback).build());
DocumentDeleteQuery deleteQuery = delete().from(COLLECTION_NAME).where(id.getName()).eq(id.get()).build();
entityManager.delete(deleteQuery);
await().untilTrue(condition);
}
use of org.jnosql.diana.api.document.DocumentEntity in project jnosql-diana-driver by eclipse.
the class OrientDBDocumentCollectionManagerTest method getEntity.
private DocumentEntity getEntity() {
DocumentEntity entity = DocumentEntity.of(COLLECTION_NAME);
Map<String, Object> map = new HashMap<>();
map.put("name", "Poliana");
map.put("city", "Salvador");
List<Document> documents = Documents.of(map);
documents.forEach(entity::add);
return entity;
}
use of org.jnosql.diana.api.document.DocumentEntity in project jnosql-diana-driver by eclipse.
the class OrientDBDocumentCollectionManagerTest method shouldQueryLesserThan.
@Test
public void shouldQueryLesserThan() {
DocumentEntity entity = getEntity();
entity.add("age", 25);
entityManager.insert(entity);
DocumentQuery query = select().from(COLLECTION_NAME).where("age").lt(25).build();
assertTrue(entityManager.select(query).isEmpty());
DocumentQuery query2 = select().from(COLLECTION_NAME).where("age").lt(26).build();
assertTrue(entityManager.select(query2).size() == 1);
}
Aggregations