use of org.neo4j.ogm.cypher.query.Pagination in project neo4j-ogm by neo4j.
the class IngredientsIntegrationTest method shouldBeAbleToLoadIngredientsWithPagingAndDepth.
/**
* @see Issue 97
*/
@Test
public void shouldBeAbleToLoadIngredientsWithPagingAndDepth() {
Ingredient chicken = new Ingredient("Chicken");
session.save(chicken);
Ingredient carrot = new Ingredient("Carrot");
session.save(carrot);
Ingredient butter = new Ingredient("Butter");
session.save(butter);
Pairing pairing = new Pairing();
pairing.setFirst(chicken);
pairing.setSecond(carrot);
pairing.setAffinity("EXCELLENT");
carrot.addPairing(pairing);
session.save(chicken);
Pairing pairing2 = new Pairing();
pairing2.setFirst(chicken);
pairing2.setSecond(butter);
pairing2.setAffinity("EXCELLENT");
carrot.addPairing(pairing2);
session.save(chicken);
Pairing pairing3 = new Pairing();
pairing3.setFirst(carrot);
pairing3.setSecond(butter);
pairing3.setAffinity("EXCELLENT");
carrot.addPairing(pairing3);
session.save(carrot);
session.clear();
Collection<Ingredient> ingredients = session.loadAll(Ingredient.class, new Pagination(0, 1));
assertThat(ingredients).hasSize(1);
session.clear();
ingredients = session.loadAll(Ingredient.class, new Pagination(1, 1));
assertThat(ingredients).hasSize(1);
session.clear();
ingredients = session.loadAll(Ingredient.class, new Pagination(0, 2));
assertThat(ingredients).hasSize(2);
ingredients = session.loadAll(Ingredient.class, new Pagination(0, 3));
assertThat(ingredients).hasSize(3);
session.clear();
Collection<Pairing> pairings = session.loadAll(Pairing.class, new Pagination(0, 1));
assertThat(pairings).hasSize(1);
session.clear();
pairings = session.loadAll(Pairing.class, new Pagination(1, 1));
assertThat(pairings).hasSize(1);
session.clear();
pairings = session.loadAll(Pairing.class, new Pagination(0, 2));
assertThat(pairings).hasSize(2);
session.clear();
pairings = session.loadAll(Pairing.class, new Pagination(0, 3));
assertThat(pairings).hasSize(3);
}
use of org.neo4j.ogm.cypher.query.Pagination in project neo4j-ogm by neo4j.
the class NodeEntityQueryPagingTest method testFindByTypeAndOffset.
@Test
public void testFindByTypeAndOffset() {
Pagination pagination = new Pagination(1, 5);
pagination.setOffset(3);
PagingAndSortingQuery query = queryStatements.findByType("Raptor", 1).setPagination(pagination);
assertThat(query.getStatement()).isEqualTo("MATCH (n:`Raptor`) WITH n SKIP 3 LIMIT 5 MATCH p=(n)-[*0..1]-(m) RETURN p, ID(n)");
}
use of org.neo4j.ogm.cypher.query.Pagination in project framework by dynamiatools.
the class Neo4jCrudService method find.
@Override
public <T> List<T> find(Class<T> type, QueryParameters parameters) {
parameters.setType(type);
fireListeners(parameters, EventType.BEFORE_QUERY);
Filters filters = buildFilters(parameters);
SortOrder sortOrder = new SortOrder();
Pagination pagination = null;
int depth = getDepth(parameters);
if (parameters.getPaginator() != null) {
long totalSize = s().count(type, filters);
parameters.getPaginator().setTotalSize(totalSize);
pagination = buildPagination(parameters);
}
if (parameters.getSorter() != null) {
BeanSorter s = parameters.getSorter();
sortOrder.add(s.isAscending() ? SortOrder.Direction.ASC : SortOrder.Direction.DESC, s.getColumnName());
}
List<T> result = new ArrayList<>(s().loadAll(type, filters, sortOrder, pagination, depth));
fireListeners(parameters, EventType.AFTER_QUERY);
return result;
}
use of org.neo4j.ogm.cypher.query.Pagination in project framework by dynamiatools.
the class Neo4jCrudService method findSingle.
@Override
public <T> T findSingle(Class<T> entityClass, QueryParameters params) {
Optional<T> result;
if (params.size() == 1 && params.containsKey("id")) {
result = Optional.of(s().load(entityClass, (Serializable) params.get("id"), params.getDepth()));
} else {
params.setType(entityClass);
fireListeners(params, EventType.BEFORE_QUERY);
Filters filters = buildFilters(params);
SortOrder sortOrder = new SortOrder();
Pagination pagination = new Pagination(0, 1);
int depth = getDepth(params);
Collection<T> data = s().loadAll(entityClass, filters, sortOrder, pagination, depth);
result = data.stream().findFirst();
fireListeners(params, EventType.AFTER_QUERY);
}
return result.orElse(null);
}
Aggregations