Search in sources :

Example 96 with Filter

use of org.neo4j.ogm.cypher.Filter in project neo4j-ogm by neo4j.

the class CineastsRelationshipEntityTest method shouldBeAbleToDeleteAllRatings.

// DATAGRAPH-586
@Test
public void shouldBeAbleToDeleteAllRatings() {
    Set<Rating> gobletRatings = new HashSet<>();
    Set<Rating> phoenixRatings = new HashSet<>();
    Movie goblet = new Movie("Harry Potter and the Goblet of Fire", 2006);
    session.save(goblet);
    Movie phoenix = new Movie("Harry Potter and the Order of the Phoenix", 2009);
    session.save(phoenix);
    User adam = new User();
    adam.setName("Adam");
    adam.setLogin("adamg");
    Rating good = new Rating();
    good.setUser(adam);
    good.setMovie(goblet);
    good.setStars(3);
    gobletRatings.add(good);
    goblet.setRatings(gobletRatings);
    Rating okay = new Rating();
    okay.setMovie(phoenix);
    okay.setUser(adam);
    okay.setStars(2);
    phoenixRatings.add(okay);
    phoenix.setRatings(phoenixRatings);
    Set<Rating> adamsRatings = new HashSet<>();
    adamsRatings.add(good);
    adamsRatings.add(okay);
    adam.setRatings(adamsRatings);
    session.save(adam);
    adam = session.loadAll(User.class, new Filter("name", ComparisonOperator.EQUALS, "Adam")).iterator().next();
    assertThat(adam.getRatings()).hasSize(2);
    // delete all ratings
    session.deleteAll(Rating.class);
    assertThat(session.loadAll(Rating.class)).isEmpty();
    phoenix = session.loadAll(Movie.class, new Filter("title", ComparisonOperator.EQUALS, "Harry Potter and the Order of the Phoenix")).iterator().next();
    assertThat(phoenix.getRatings()).isNull();
    goblet = session.loadAll(Movie.class, new Filter("title", ComparisonOperator.EQUALS, "Harry Potter and the Goblet of Fire")).iterator().next();
    assertThat(goblet.getRatings()).isNull();
    adam = session.loadAll(User.class, new Filter("name", ComparisonOperator.EQUALS, "Adam")).iterator().next();
    assertThat(adam.getRatings()).isNull();
}
Also used : Movie(org.neo4j.ogm.domain.cineasts.annotated.Movie) User(org.neo4j.ogm.domain.cineasts.annotated.User) Filter(org.neo4j.ogm.cypher.Filter) Rating(org.neo4j.ogm.domain.cineasts.annotated.Rating) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 97 with Filter

use of org.neo4j.ogm.cypher.Filter in project neo4j-ogm by neo4j.

the class CineastsRelationshipEntityTest method shouldSaveRelationshipEntityWithCamelCaseStartEndNodes.

// DATAGRAPH-567
@Test
public void shouldSaveRelationshipEntityWithCamelCaseStartEndNodes() {
    Actor bruce = new Actor("Bruce");
    Actor jim = new Actor("Jim");
    Knows knows = new Knows();
    knows.setFirstActor(bruce);
    knows.setSecondActor(jim);
    knows.setSince(new Date());
    bruce.getKnows().add(knows);
    session.save(bruce);
    Actor actor = TestUtils.firstOrNull(session.loadAll(Actor.class, new Filter("name", ComparisonOperator.EQUALS, "Bruce")));
    assertThat(actor).isNotNull();
    assertThat(actor.getKnows()).hasSize(1);
    assertThat(actor.getKnows().iterator().next().getSecondActor().getName()).isEqualTo("Jim");
}
Also used : Filter(org.neo4j.ogm.cypher.Filter) Actor(org.neo4j.ogm.domain.cineasts.annotated.Actor) Knows(org.neo4j.ogm.domain.cineasts.annotated.Knows) Date(java.util.Date) Test(org.junit.Test)

Example 98 with Filter

use of org.neo4j.ogm.cypher.Filter in project neo4j-ogm by neo4j.

the class CineastsRelationshipEntityTest method shouldBeAbleToSaveAndUpdateMultipleUserRatings.

// DATAGRAPH-569
@Test
public void shouldBeAbleToSaveAndUpdateMultipleUserRatings() {
    Set<Rating> gobletRatings = new HashSet<>();
    Set<Rating> phoenixRatings = new HashSet<>();
    Movie goblet = new Movie("Harry Potter and the Goblet of Fire", 2006);
    session.save(goblet);
    Movie phoenix = new Movie("Harry Potter and the Order of the Phoenix", 2009);
    session.save(phoenix);
    User adam = new User();
    adam.setName("Adam");
    adam.setLogin("adamg");
    Rating good = new Rating();
    good.setUser(adam);
    good.setMovie(goblet);
    good.setStars(3);
    gobletRatings.add(good);
    goblet.setRatings(gobletRatings);
    Rating okay = new Rating();
    okay.setMovie(phoenix);
    okay.setUser(adam);
    okay.setStars(2);
    phoenixRatings.add(okay);
    phoenix.setRatings(phoenixRatings);
    Set<Rating> adamsRatings = new HashSet<>();
    adamsRatings.add(good);
    adamsRatings.add(okay);
    adam.setRatings(adamsRatings);
    session.save(adam);
    Collection<Movie> movies = session.loadAll(Movie.class, new Filter("title", ComparisonOperator.EQUALS, "Harry Potter and the Goblet of Fire"));
    goblet = movies.iterator().next();
    assertThat(goblet.getRatings()).isNotNull();
    assertThat(goblet.getRatings()).hasSize(1);
    movies = session.loadAll(Movie.class, new Filter("title", ComparisonOperator.EQUALS, "Harry Potter and the Order of the Phoenix"));
    phoenix = movies.iterator().next();
    assertThat(phoenix.getRatings()).isNotNull();
    assertThat(phoenix.getRatings()).hasSize(1);
    adam = session.loadAll(User.class, new Filter("name", ComparisonOperator.EQUALS, "Adam")).iterator().next();
    assertThat(adam.getRatings()).hasSize(2);
    // Get rid of the Phoenix rating
    adam.setRatings(gobletRatings);
    session.save(adam);
    adam = session.loadAll(User.class, new Filter("name", ComparisonOperator.EQUALS, "Adam")).iterator().next();
    assertThat(adam.getRatings()).hasSize(1);
    movies = session.loadAll(Movie.class, new Filter("title", ComparisonOperator.EQUALS, "Harry Potter and the Order of the Phoenix"));
    phoenix = movies.iterator().next();
    assertThat(phoenix.getRatings()).isNull();
    movies = session.loadAll(Movie.class, new Filter("title", ComparisonOperator.EQUALS, "Harry Potter and the Goblet of Fire"));
    goblet = movies.iterator().next();
    assertThat(goblet.getRatings()).isNotNull();
    assertThat(goblet.getRatings()).hasSize(1);
}
Also used : Movie(org.neo4j.ogm.domain.cineasts.annotated.Movie) User(org.neo4j.ogm.domain.cineasts.annotated.User) Filter(org.neo4j.ogm.cypher.Filter) Rating(org.neo4j.ogm.domain.cineasts.annotated.Rating) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 99 with Filter

use of org.neo4j.ogm.cypher.Filter in project neo4j-ogm by neo4j.

the class CineastsRelationshipEntityTest method shouldRetainREsWhenAStartOrEndNodeIsLoaded.

/**
 * @see DATAGRAPH-704
 */
@Test
public void shouldRetainREsWhenAStartOrEndNodeIsLoaded() {
    bootstrap("org/neo4j/ogm/cql/cineasts.cql");
    Collection<Movie> films = session.loadAll(Movie.class, new Filter("title", ComparisonOperator.EQUALS, "Top Gear"));
    Movie movie = films.iterator().next();
    assertThat(movie.getRatings()).hasSize(2);
    session.loadAll(User.class, new Filter("name", ComparisonOperator.EQUALS, "Michal")).iterator().next();
    assertThat(movie.getRatings()).hasSize(// should not lose one rating because Michal is loaded; ratings should me merged and not overwritten
    2);
}
Also used : Movie(org.neo4j.ogm.domain.cineasts.annotated.Movie) Filter(org.neo4j.ogm.cypher.Filter) Test(org.junit.Test)

Example 100 with Filter

use of org.neo4j.ogm.cypher.Filter in project neo4j-ogm by neo4j.

the class CineastsRelationshipEntityTest method shouldCreateREWithExistingStartAndEndNodes.

@Test
public void shouldCreateREWithExistingStartAndEndNodes() {
    bootstrap("org/neo4j/ogm/cql/cineasts.cql");
    Collection<Movie> films = session.loadAll(Movie.class, new Filter("title", ComparisonOperator.EQUALS, "Top Gear"));
    Movie movie = films.iterator().next();
    assertThat(movie.getRatings()).hasSize(2);
    User michal = null;
    for (Rating rating : movie.getRatings()) {
        if (rating.getUser().getName().equals("Michal")) {
            michal = rating.getUser();
            break;
        }
    }
    assertThat(michal).isNotNull();
    Set<Rating> ratings = new HashSet<>();
    Rating awesome = new Rating();
    awesome.setComment("Awesome");
    awesome.setMovie(movie);
    awesome.setUser(michal);
    awesome.setStars(5);
    ratings.add(awesome);
    // Overwrite Michal's earlier rating
    michal.setRatings(ratings);
    movie.setRatings(ratings);
    session.save(movie);
    Collection<Movie> movies = session.loadAll(Movie.class, new Filter("title", ComparisonOperator.EQUALS, "Top Gear"));
    movie = movies.iterator().next();
    assertThat(movie.getRatings()).isNotNull();
    assertThat(movie.getRatings()).hasSize(1);
    assertThat(movie.getRatings().iterator().next().getUser().getName()).isEqualTo("Michal");
}
Also used : Movie(org.neo4j.ogm.domain.cineasts.annotated.Movie) User(org.neo4j.ogm.domain.cineasts.annotated.User) Filter(org.neo4j.ogm.cypher.Filter) Rating(org.neo4j.ogm.domain.cineasts.annotated.Rating) HashSet(java.util.HashSet) Test(org.junit.Test)

Aggregations

Filter (org.neo4j.ogm.cypher.Filter)155 Test (org.junit.Test)146 Filters (org.neo4j.ogm.cypher.Filters)78 User (org.neo4j.ogm.domain.cineasts.annotated.User)19 Rating (org.neo4j.ogm.domain.cineasts.annotated.Rating)18 Movie (org.neo4j.ogm.domain.cineasts.annotated.Movie)17 Restaurant (org.neo4j.ogm.domain.restaurant.Restaurant)12 Date (java.util.Date)10 Session (org.neo4j.ogm.session.Session)10 DistanceFromNativePoint (org.neo4j.ogm.cypher.function.DistanceFromNativePoint)8 SomethingSpatial (org.neo4j.ogm.persistence.types.nativetypes.SomethingSpatial)8 HashSet (java.util.HashSet)7 CypherQuery (org.neo4j.ogm.cypher.query.CypherQuery)7 GroupMember (org.neo4j.ogm.domain.gh824.GroupMember)7 ArrayList (java.util.ArrayList)4 Actor (org.neo4j.ogm.domain.cineasts.annotated.Actor)4 User (org.neo4j.ogm.domain.gh824.User)4 UserGroup (org.neo4j.ogm.domain.gh824.UserGroup)4 Studio (org.neo4j.ogm.domain.music.Studio)4 Collections (java.util.Collections)2