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);
}
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);
}
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);
}
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);
}
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);
}
Aggregations