Search in sources :

Example 1 with Pagination

use of org.neo4j.ogm.cypher.query.Pagination in project neo4j-ogm by neo4j.

the class IngredientsIntegrationTest method shouldBeAbleToLoadIngredientsWithFiltersPagingAndDepth.

/**
 * @see Issue 97
 */
@Test
public void shouldBeAbleToLoadIngredientsWithFiltersPagingAndDepth() {
    Ingredient chicken = new Ingredient("Chicken");
    session.save(chicken);
    Ingredient carrot = new Ingredient("Chicken");
    session.save(carrot);
    Ingredient butter = new Ingredient("Chicken");
    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 Filter("name", ComparisonOperator.EQUALS, "Chicken"), new Pagination(0, 1));
    assertThat(ingredients).hasSize(1);
    session.clear();
    ingredients = session.loadAll(Ingredient.class, new Filter("name", ComparisonOperator.EQUALS, "Chicken"), new Pagination(1, 1));
    assertThat(ingredients).hasSize(1);
    session.clear();
    ingredients = session.loadAll(Ingredient.class, new Filter("name", ComparisonOperator.EQUALS, "Chicken"), new Pagination(0, 2));
    assertThat(ingredients).hasSize(2);
    ingredients = session.loadAll(Ingredient.class, new Filter("name", ComparisonOperator.EQUALS, "Chicken"), new Pagination(0, 3));
    assertThat(ingredients).hasSize(3);
    session.clear();
    Collection<Pairing> pairings = session.loadAll(Pairing.class, new Filter("affinity", ComparisonOperator.EQUALS, "EXCELLENT"), new Pagination(0, 1));
    assertThat(pairings).hasSize(1);
    session.clear();
    pairings = session.loadAll(Pairing.class, new Filter("affinity", ComparisonOperator.EQUALS, "EXCELLENT"), new Pagination(1, 1));
    assertThat(pairings).hasSize(1);
    session.clear();
    pairings = session.loadAll(Pairing.class, new Filter("affinity", ComparisonOperator.EQUALS, "EXCELLENT"), new Pagination(0, 2));
    assertThat(pairings).hasSize(2);
    pairings = session.loadAll(Pairing.class, new Filter("affinity", ComparisonOperator.EQUALS, "EXCELLENT"), new Pagination(0, 3));
    assertThat(pairings).hasSize(3);
}
Also used : Pagination(org.neo4j.ogm.cypher.query.Pagination) Ingredient(org.neo4j.ogm.domain.ingredients.Ingredient) Filter(org.neo4j.ogm.cypher.Filter) Pairing(org.neo4j.ogm.domain.ingredients.Pairing) Test(org.junit.Test)

Example 2 with Pagination

use of org.neo4j.ogm.cypher.query.Pagination in project neo4j-ogm by neo4j.

the class CineastsRelationshipEntityTest method testFilterOnRelationshipEntity.

@Test
public void testFilterOnRelationshipEntity() throws Exception {
    Movie pulpFiction = new Movie("Pulp Fiction", 1994);
    Movie ootf = new Movie("Harry Potter and the Order of the Phoenix", 2009);
    User frantisek = new User();
    frantisek.setName("Frantisek");
    frantisek.setLogin("frantisek");
    Rating pulpRating = new Rating();
    pulpRating.setStars(3);
    pulpRating.setMovie(pulpFiction);
    pulpRating.setUser(frantisek);
    pulpFiction.setRatings(new HashSet<>(Arrays.asList(pulpRating)));
    Rating ootfRating = new Rating();
    ootfRating.setStars(3);
    ootfRating.setMovie(ootf);
    ootfRating.setUser(frantisek);
    frantisek.setRatings(new HashSet<>(Arrays.asList(ootfRating, pulpRating)));
    User otto = new User();
    otto.setName("Otto");
    otto.setLogin("otto");
    Rating pulpRating2 = new Rating();
    pulpRating2.setStars(3);
    pulpRating2.setMovie(pulpFiction);
    pulpRating2.setUser(otto);
    Rating ootfRating2 = new Rating();
    ootfRating2.setStars(3);
    ootfRating2.setMovie(ootf);
    ootfRating2.setUser(otto);
    pulpFiction.setRatings(new HashSet<>(Arrays.asList(pulpRating, pulpRating2)));
    ootf.setRatings(new HashSet<>(Arrays.asList(ootfRating, ootfRating2)));
    otto.setRatings(new HashSet<>(Arrays.asList(pulpRating2, ootfRating2)));
    session.save(otto);
    session.clear();
    Filter filter = new Filter("stars", ComparisonOperator.EQUALS, 3);
    filter.setNestedPropertyName("ratings");
    filter.setNestedPropertyType(Rating.class);
    filter.setNestedRelationshipEntity(true);
    Collection<User> users = session.loadAll(User.class, filter, new Pagination(0, 2));
    assertThat(users).hasSize(2);
}
Also used : Movie(org.neo4j.ogm.domain.cineasts.annotated.Movie) Pagination(org.neo4j.ogm.cypher.query.Pagination) User(org.neo4j.ogm.domain.cineasts.annotated.User) Filter(org.neo4j.ogm.cypher.Filter) Rating(org.neo4j.ogm.domain.cineasts.annotated.Rating) Test(org.junit.Test)

Example 3 with Pagination

use of org.neo4j.ogm.cypher.query.Pagination in project neo4j-ogm by neo4j.

the class LoadCapabilityTest method loadAllShouldRespectEntityType.

// DATAGRAPH-707
@Test
public void loadAllShouldRespectEntityType() {
    Collection<Artist> artists = session.loadAll(Artist.class, Collections.singletonList(beatlesId));
    assertThat(artists).hasSize(1);
    assertThat(artists.iterator().next().getName()).isEqualTo("The Beatles");
    Collection<Album> albums = session.loadAll(Album.class, Collections.singletonList(beatlesId));
    assertThat(albums).isEmpty();
    artists = session.loadAll(Artist.class, Collections.singletonList(beatlesId), 0);
    assertThat(artists).hasSize(1);
    assertThat(artists.iterator().next().getName()).isEqualTo("The Beatles");
    albums = session.loadAll(Album.class, Collections.singletonList(beatlesId), 0);
    assertThat(albums).isEmpty();
    artists = session.loadAll(Artist.class, Collections.singletonList(beatlesId), new SortOrder().add("name"));
    assertThat(artists).hasSize(1);
    assertThat(artists.iterator().next().getName()).isEqualTo("The Beatles");
    albums = session.loadAll(Album.class, Collections.singletonList(beatlesId), new SortOrder().add("name"));
    assertThat(albums).isEmpty();
    artists = session.loadAll(Artist.class, Collections.singletonList(beatlesId), new SortOrder().add("name"), 0);
    assertThat(artists).hasSize(1);
    assertThat(artists.iterator().next().getName()).isEqualTo("The Beatles");
    albums = session.loadAll(Album.class, Collections.singletonList(beatlesId), new SortOrder().add("name"), 0);
    assertThat(albums).isEmpty();
    artists = session.loadAll(Artist.class, Collections.singletonList(beatlesId), new Pagination(0, 5));
    assertThat(artists).hasSize(1);
    assertThat(artists.iterator().next().getName()).isEqualTo("The Beatles");
    albums = session.loadAll(Album.class, Collections.singletonList(beatlesId), new Pagination(0, 5));
    assertThat(albums).isEmpty();
    artists = session.loadAll(Artist.class, Collections.singletonList(beatlesId), new Pagination(0, 5), 0);
    assertThat(artists).hasSize(1);
    assertThat(artists.iterator().next().getName()).isEqualTo("The Beatles");
    albums = session.loadAll(Album.class, Collections.singletonList(beatlesId), new Pagination(0, 5), 0);
    assertThat(albums).isEmpty();
    artists = session.loadAll(Artist.class, Collections.singletonList(beatlesId), new SortOrder().add("name"), new Pagination(0, 5));
    assertThat(artists).hasSize(1);
    assertThat(artists.iterator().next().getName()).isEqualTo("The Beatles");
    albums = session.loadAll(Album.class, Collections.singletonList(beatlesId), new SortOrder().add("name"), new Pagination(0, 5));
    assertThat(albums).isEmpty();
    artists = session.loadAll(Artist.class, Collections.singletonList(beatlesId), new SortOrder().add("name"), new Pagination(0, 5), 0);
    assertThat(artists).hasSize(1);
    assertThat(artists.iterator().next().getName()).isEqualTo("The Beatles");
    Artist bonJovi = new Artist("Bon Jovi");
    session.save(bonJovi);
    artists = session.loadAll(Artist.class, Arrays.asList(beatlesId, pleaseId, bonJovi.getId()), new SortOrder().add("name"), new Pagination(0, 5), 0);
    assertThat(artists).hasSize(2);
    artists = session.loadAll(Artist.class, Collections.singletonList(beatlesId), new SortOrder().add("name"), new Pagination(0, 5), 0);
    assertThat(artists).hasSize(1);
    assertThat(artists.iterator().next().getName()).isEqualTo(// make sure Bon Jovi isn't returned as well
    "The Beatles");
    albums = session.loadAll(Album.class, Collections.singletonList(beatlesId), new SortOrder().add("name"), new Pagination(0, 5), 0);
    assertThat(albums).isEmpty();
}
Also used : Artist(org.neo4j.ogm.domain.music.Artist) Pagination(org.neo4j.ogm.cypher.query.Pagination) Album(org.neo4j.ogm.domain.music.Album) SortOrder(org.neo4j.ogm.cypher.query.SortOrder) Test(org.junit.Test)

Example 4 with Pagination

use of org.neo4j.ogm.cypher.query.Pagination in project framework by dynamiatools.

the class Neo4jCrudService method buildPagination.

private Pagination buildPagination(QueryParameters params) {
    DataPaginator paginator = params.getPaginator();
    Pagination pag = new Pagination(paginator.getPage(), paginator.getPageSize());
    pag.setOffset(paginator.getFirstResult());
    return pag;
}
Also used : Pagination(org.neo4j.ogm.cypher.query.Pagination)

Example 5 with Pagination

use of org.neo4j.ogm.cypher.query.Pagination in project neo4j-ogm by neo4j.

the class CineastsRelationshipEntityTest method testFilterOnRelatedNode.

@Test
public void testFilterOnRelatedNode() throws Exception {
    User frantisek = new User();
    frantisek.setName("Frantisek");
    frantisek.setLogin("frantisek");
    User michal = new User();
    michal.setName("Michal");
    michal.setLogin("michal");
    User ottoH = new User();
    ottoH.setName("Otto");
    ottoH.setLogin("otto");
    User ottoB = new User();
    ottoB.setName("Otto von Bismarc");
    ottoB.setLogin("ottob");
    frantisek.addFriends(ottoH, ottoB);
    session.save(frantisek);
    michal.addFriends(ottoH, ottoB);
    session.save(michal);
    // name contains ' '
    Filter filter = new Filter("name", ComparisonOperator.CONTAINING, "Otto");
    filter.setNestedPropertyName("friends");
    filter.setNestedPropertyType(User.class);
    SortOrder sortOrder = new SortOrder();
    sortOrder.add("name");
    Collection<User> users = session.loadAll(User.class, filter, sortOrder, new Pagination(0, 2));
    assertThat(users).hasSize(2);
}
Also used : Pagination(org.neo4j.ogm.cypher.query.Pagination) User(org.neo4j.ogm.domain.cineasts.annotated.User) Filter(org.neo4j.ogm.cypher.Filter) SortOrder(org.neo4j.ogm.cypher.query.SortOrder) Test(org.junit.Test)

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