Search in sources :

Example 31 with Filter

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

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

the class DeepNestQueryingOfRelationshipEntitiesIntegrationTest method flattenedPathSegmentsShouldWorkFromBothEnds.

@Test
public void flattenedPathSegmentsShouldWorkFromBothEnds() {
    Filter outgoing = new Filter("name", ComparisonOperator.EQUALS, "U1");
    outgoing.setOwnerEntityType(GroupMember.class);
    outgoing.setNestedPath(new Filter.NestedPathSegment("user", User.class));
    Filter incoming = new Filter("name", ComparisonOperator.EQUALS, "EuregJUG");
    incoming.setOwnerEntityType(GroupMember.class);
    incoming.setNestedPath(new Filter.NestedPathSegment("group", UserGroup.class));
    Collection<GroupMember> members = sessionFactory.openSession().loadAll(GroupMember.class, outgoing.and(incoming));
    assertThat(members).hasSize(1);
}
Also used : GroupMember(org.neo4j.ogm.domain.gh824.GroupMember) User(org.neo4j.ogm.domain.gh824.User) Filter(org.neo4j.ogm.cypher.Filter) UserGroup(org.neo4j.ogm.domain.gh824.UserGroup) Test(org.junit.Test)

Example 33 with Filter

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

the class DeepNestQueryingOfRelationshipEntitiesIntegrationTest method nPlus1PathSegmentsShouldWork.

@Test
public void nPlus1PathSegmentsShouldWork() {
    Filter filter = new Filter("name", ComparisonOperator.EQUALS, "Aachen");
    filter.setOwnerEntityType(GroupMember.class);
    filter.setNestedPath(new Filter.NestedPathSegment("user", User.class), new Filter.NestedPathSegment("address", Address.class), new Filter.NestedPathSegment("city", City.class));
    Collection<GroupMember> members = sessionFactory.openSession().loadAll(GroupMember.class, filter);
    assertThat(members).hasSize(1);
}
Also used : GroupMember(org.neo4j.ogm.domain.gh824.GroupMember) User(org.neo4j.ogm.domain.gh824.User) Address(org.neo4j.ogm.domain.gh824.Address) Filter(org.neo4j.ogm.cypher.Filter) City(org.neo4j.ogm.domain.gh824.City) Test(org.junit.Test)

Example 34 with Filter

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

the class DeepNestQueryingOfRelationshipEntitiesIntegrationTest method nPathSegmentsShouldWorkFromBothEnds.

@Test
public void nPathSegmentsShouldWorkFromBothEnds() {
    Filter outgoing = new Filter("code", ComparisonOperator.EQUALS, "0001");
    outgoing.setOwnerEntityType(GroupMember.class);
    outgoing.setNestedPath(new Filter.NestedPathSegment("user", User.class), new Filter.NestedPathSegment("address", Address.class));
    Filter incoming = new Filter("name", ComparisonOperator.EQUALS, "Aachen");
    incoming.setOwnerEntityType(GroupMember.class);
    incoming.setNestedPath(new Filter.NestedPathSegment("group", UserGroup.class), new Filter.NestedPathSegment("city", City.class));
    Collection<GroupMember> members = sessionFactory.openSession().loadAll(GroupMember.class, outgoing.and(incoming));
    assertThat(members).hasSize(1);
}
Also used : GroupMember(org.neo4j.ogm.domain.gh824.GroupMember) User(org.neo4j.ogm.domain.gh824.User) Address(org.neo4j.ogm.domain.gh824.Address) Filter(org.neo4j.ogm.cypher.Filter) City(org.neo4j.ogm.domain.gh824.City) UserGroup(org.neo4j.ogm.domain.gh824.UserGroup) Test(org.junit.Test)

Example 35 with Filter

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

the class DeepNestQueryingOfRelationshipEntitiesIntegrationTest method flattenedPathSegmentsShouldWork.

@Test
public void flattenedPathSegmentsShouldWork() {
    Filter filter = new Filter("name", ComparisonOperator.EQUALS, "Mr. User");
    filter.setOwnerEntityType(GroupMember.class);
    filter.setNestedPath(new Filter.NestedPathSegment("user", User.class));
    Collection<GroupMember> members = sessionFactory.openSession().loadAll(GroupMember.class, filter);
    assertThat(members).hasSize(1);
}
Also used : GroupMember(org.neo4j.ogm.domain.gh824.GroupMember) User(org.neo4j.ogm.domain.gh824.User) Filter(org.neo4j.ogm.cypher.Filter) 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