Search in sources :

Example 6 with Pagination

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);
}
Also used : Pagination(org.neo4j.ogm.cypher.query.Pagination) Ingredient(org.neo4j.ogm.domain.ingredients.Ingredient) Pairing(org.neo4j.ogm.domain.ingredients.Pairing) Test(org.junit.Test)

Example 7 with Pagination

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)");
}
Also used : Pagination(org.neo4j.ogm.cypher.query.Pagination) PagingAndSortingQuery(org.neo4j.ogm.cypher.query.PagingAndSortingQuery) Test(org.junit.Test)

Example 8 with Pagination

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;
}
Also used : Pagination(org.neo4j.ogm.cypher.query.Pagination) Filters(org.neo4j.ogm.cypher.Filters) SortOrder(org.neo4j.ogm.cypher.query.SortOrder) BeanSorter(tools.dynamia.commons.BeanSorter)

Example 9 with Pagination

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);
}
Also used : Pagination(org.neo4j.ogm.cypher.query.Pagination) Filters(org.neo4j.ogm.cypher.Filters) SortOrder(org.neo4j.ogm.cypher.query.SortOrder)

Aggregations

Pagination (org.neo4j.ogm.cypher.query.Pagination)9 Test (org.junit.Test)6 SortOrder (org.neo4j.ogm.cypher.query.SortOrder)4 Filter (org.neo4j.ogm.cypher.Filter)3 Filters (org.neo4j.ogm.cypher.Filters)2 User (org.neo4j.ogm.domain.cineasts.annotated.User)2 Ingredient (org.neo4j.ogm.domain.ingredients.Ingredient)2 Pairing (org.neo4j.ogm.domain.ingredients.Pairing)2 PagingAndSortingQuery (org.neo4j.ogm.cypher.query.PagingAndSortingQuery)1 Movie (org.neo4j.ogm.domain.cineasts.annotated.Movie)1 Rating (org.neo4j.ogm.domain.cineasts.annotated.Rating)1 Album (org.neo4j.ogm.domain.music.Album)1 Artist (org.neo4j.ogm.domain.music.Artist)1 BeanSorter (tools.dynamia.commons.BeanSorter)1