Search in sources :

Example 16 with Filter

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

the class SocialIntegrationTest method shouldFetchFriendsInBothDirections.

/**
 * @see DATAGRAPH-594
 */
@Test
public void shouldFetchFriendsInBothDirections() {
    session.query("create (p1:Individual {name:'A'}) create (p2:Individual {name:'B'}) create (p3:Individual {name:'C'})" + " create (p4:Individual {name:'D'}) create (p1)-[:FRIENDS]->(p2) create (p1)-[:FRIENDS]->(p3) create (p4)-[:FRIENDS]->(p1)", Collections.EMPTY_MAP);
    Individual individualA = session.loadAll(Individual.class, new Filter("name", ComparisonOperator.EQUALS, "A")).iterator().next();
    assertThat(individualA).isNotNull();
    assertThat(individualA.getFriends()).hasSize(2);
}
Also used : Filter(org.neo4j.ogm.cypher.Filter) Individual(org.neo4j.ogm.domain.social.Individual) Test(org.junit.Test)

Example 17 with Filter

use of org.neo4j.ogm.cypher.Filter 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 18 with Filter

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

the class MusicIntegrationTest method shouldSaveAndRetrieveEntitiesWithInvalidCharsInLabelsAndRels.

/**
 * @see DATAGRAPH-589
 */
@Test
public void shouldSaveAndRetrieveEntitiesWithInvalidCharsInLabelsAndRels() {
    Studio emi = new Studio("EMI Studios, London");
    Artist theBeatles = new Artist("The Beatles");
    Album please = new Album("Please Please Me");
    Recording pleaseRecording = new Recording(please, emi, 1963);
    please.setRecording(pleaseRecording);
    theBeatles.getAlbums().add(please);
    please.setArtist(theBeatles);
    session.save(theBeatles);
    theBeatles = session.loadAll(Artist.class).iterator().next();
    assertThat(theBeatles.getName()).isEqualTo("The Beatles");
    assertThat(theBeatles.getAlbums()).hasSize(1);
    assertThat(theBeatles.getAlbums().iterator().next().getName()).isEqualTo("Please Please Me");
    assertThat(theBeatles.getAlbums().iterator().next().getRecording().getStudio().getName()).isEqualTo("EMI Studios, London");
    please = session.loadAll(Album.class, new Filter("name", ComparisonOperator.EQUALS, "Please Please Me")).iterator().next();
    assertThat(please.getArtist().getName()).isEqualTo("The Beatles");
    Album hard = new Album("A Hard Day's Night");
    hard.setArtist(theBeatles);
    Recording hardRecording = new Recording(hard, emi, 1964);
    hard.setRecording(hardRecording);
    theBeatles.getAlbums().add(hard);
    session.save(hard);
    Collection<Album> albums = session.loadAll(Album.class);
    assertThat(albums).hasSize(2);
    for (Album album : albums) {
        if (album.getName().equals("Please Please Me")) {
            assertThat(album.getRecording().getYear()).isEqualTo(1963);
        } else {
            assertThat(album.getRecording().getYear()).isEqualTo(1964);
        }
    }
}
Also used : Artist(org.neo4j.ogm.domain.music.Artist) Filter(org.neo4j.ogm.cypher.Filter) Album(org.neo4j.ogm.domain.music.Album) Recording(org.neo4j.ogm.domain.music.Recording) Studio(org.neo4j.ogm.domain.music.Studio) Test(org.junit.Test)

Example 19 with Filter

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

the class CineastsIntegrationTest method nestedFilteringCanBeTheOneAndOnlyOredFilter.

@Test
public void nestedFilteringCanBeTheOneAndOnlyOredFilter() {
    Filter filterB = new Filter("name", ComparisonOperator.EQUALS, "Catty");
    filterB.setNestedPath(new Filter.NestedPathSegment("ratings", Rating.class), new Filter.NestedPathSegment("user", User.class), new Filter.NestedPathSegment("pets", Pet.class));
    filterB.setBooleanOperator(BooleanOperator.OR);
    Filters filters = new Filters(filterB);
    Collection<Movie> films = session.loadAll(Movie.class, filters);
    assertThat(films).hasSize(2);
}
Also used : Movie(org.neo4j.ogm.domain.cineasts.annotated.Movie) Filters(org.neo4j.ogm.cypher.Filters) User(org.neo4j.ogm.domain.cineasts.annotated.User) Filter(org.neo4j.ogm.cypher.Filter) Rating(org.neo4j.ogm.domain.cineasts.annotated.Rating) Pet(org.neo4j.ogm.domain.cineasts.annotated.Pet) Test(org.junit.Test)

Example 20 with Filter

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

the class CineastsIntegrationTest method loadFilmByRatingUsersPet.

@Test
public void loadFilmByRatingUsersPet() {
    // Pulp Fiction and Top Gear rated by Michal who owns Catty
    Filter filter = new Filter("name", ComparisonOperator.EQUALS, "Catty");
    filter.setOwnerEntityType(Movie.class);
    filter.setNestedPath(new Filter.NestedPathSegment("ratings", Rating.class), new Filter.NestedPathSegment("user", User.class), new Filter.NestedPathSegment("pets", Pet.class));
    Collection<Movie> films = session.loadAll(Movie.class, filter);
    assertThat(films).hasSize(2);
}
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) Pet(org.neo4j.ogm.domain.cineasts.annotated.Pet) 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