Search in sources :

Example 36 with Filter

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

the class DualTargetEntityRelationshipTest method shouldKeepAllRelations.

// DATAGRAPH-690
@Test
public void shouldKeepAllRelations() {
    Category category = new Category("cat1");
    Tag tag1 = new Tag("tag1");
    Set<Tag> tags = new HashSet<>();
    tags.add(tag1);
    Event event = new Event("title");
    event.setCategory(category);
    event.setTags(tags);
    session.save(event);
    assertThat(event.getNodeId()).isNotNull();
    assertThat(category.getNodeId()).isNotNull();
    assertThat(tag1.getNodeId()).isNotNull();
    session.clear();
    Collection<Tag> tagsFound = session.loadAll(Tag.class, new Filter("name", ComparisonOperator.EQUALS, "tag1"));
    assertThat(tagsFound).hasSize(1);
    event.setTags(new HashSet<>(tagsFound));
    Collection<Category> categoriesFound = session.loadAll(Category.class, new Filter("name", ComparisonOperator.EQUALS, "cat1"));
    assertThat(categoriesFound).hasSize(1);
    event.setCategory(categoriesFound.iterator().next());
    assertThat(event.getTags().iterator().next()).isEqualTo(tag1);
    assertThat(event.getCategory()).isEqualTo(category);
    session.save(event);
    session.clear();
    Event eventFound = session.load(Event.class, event.getNodeId(), 1);
    assertThat(eventFound.getNodeId()).isNotNull();
    assertThat(eventFound.getCategory()).isEqualTo(category);
    assertThat(eventFound.getTags().iterator().next()).isEqualTo(tag1);
}
Also used : Category(org.neo4j.ogm.domain.mappings.Category) Filter(org.neo4j.ogm.cypher.Filter) Event(org.neo4j.ogm.domain.mappings.Event) Tag(org.neo4j.ogm.domain.mappings.Tag) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 37 with Filter

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

the class MultipleRelationshipsTest method shouldMapFromGraphToEntitiesCorrectly.

/**
 * @see DATAGRAPH-636
 */
@Test
public void shouldMapFromGraphToEntitiesCorrectly() {
    session.query("create (_5:`PersonX` {`name`:\"Jim\"})\n" + "create (_6:`PersonX` {`name`:\"Mary\"})\n" + "create (_7:`PersonX` {`name`:\"Bill\"})\n" + "create (_8:`Movie` {`name`:\"Die Hard\"})\n" + "create (_9:`Movie` {`name`:\"The Matrix\"})\n" + "create (_5)-[:`FOLLOWS`]->(_6)\n" + "create (_5)-[:`LIKES`]->(_6)\n" + "create (_5)-[:`RATED` {`value`:4}]->(_9)\n" + "create (_5)-[:`RATED` {`value`:5}]->(_8)\n" + "create (_6)-[:`FOLLOWS`]->(_5)\n" + "create (_6)-[:`FOLLOWS`]->(_7)\n" + "create (_6)-[:`LIKES`]->(_5)\n" + "create (_6)-[:`RATED` {`value`:5}]->(_8)\n" + "create (_7)-[:`FOLLOWS`]->(_5)\n" + "create (_7)-[:`LIKES`]->(_6)\n" + "create (_7)-[:`RATED` {`value`:4}]->(_9)\n" + "create (_7)-[:`RATED` {`value`:5}]->(_9)\n" + ";\n", Collections.EMPTY_MAP);
    Person jim = session.loadAll(Person.class, new Filter("name", ComparisonOperator.EQUALS, "Jim")).iterator().next();
    assertThat(jim.movieRatings).hasSize(2);
    assertThat(jim.peopleILike).hasSize(1);
    assertThat(jim.peopleWhoLikeMe).hasSize(1);
    assertThat(jim.peopleIFollow).hasSize(1);
    assertThat(jim.peopleWhoFollowMe).hasSize(2);
    assertThat(jim.peopleILike.get(0).name).isEqualTo("Mary");
    Person bill = session.loadAll(Person.class, new Filter("name", ComparisonOperator.EQUALS, "Bill")).iterator().next();
    assertThat(bill.movieRatings).hasSize(2);
    assertThat(bill.peopleILike).hasSize(1);
    assertThat(bill.peopleWhoLikeMe).isEmpty();
    assertThat(bill.peopleIFollow).hasSize(1);
    assertThat(bill.peopleWhoFollowMe).hasSize(1);
    Person mary = session.loadAll(Person.class, new Filter("name", ComparisonOperator.EQUALS, "Mary")).iterator().next();
    Movie dieHard = session.loadAll(Movie.class, new Filter("name", ComparisonOperator.EQUALS, "Die Hard")).iterator().next();
    Movie matrix = session.loadAll(Movie.class, new Filter("name", ComparisonOperator.EQUALS, "The Matrix")).iterator().next();
    assertThat(mary.movieRatings).hasSize(1);
    assertThat(mary.peopleILike).hasSize(1);
    assertThat(mary.peopleWhoLikeMe).hasSize(2);
    assertThat(mary.peopleIFollow).hasSize(2);
    assertThat(mary.peopleWhoFollowMe).hasSize(1);
    assertThat(matrix.ratings).hasSize(3);
    assertThat(dieHard.ratings).hasSize(2);
}
Also used : Movie(org.neo4j.ogm.domain.entityMapping.Movie) Filter(org.neo4j.ogm.cypher.Filter) Person(org.neo4j.ogm.domain.entityMapping.Person) Test(org.junit.Test)

Example 38 with Filter

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

the class EducationIntegrationTest method loadingCourseByPropertyShouldNotLoadOtherEntitiesWithSamePropertyValue.

@Test
public void loadingCourseByPropertyShouldNotLoadOtherEntitiesWithSamePropertyValue() {
    // create a course
    Course course = new Course("CompSci");
    // create a student with the same name as the course
    Student student = new Student("CompSci");
    // relate them so they're both in the mappingContext
    course.setStudents(Collections.singletonList(student));
    session.save(course);
    // fetch Courses by name
    Collection<Course> courses = session.loadAll(Course.class, new Filter("name", ComparisonOperator.EQUALS, "CompSci"));
    assertThat(courses).hasSize(1);
    assertThat(courses.iterator().next()).isEqualTo(course);
    assertThat(courses.iterator().next().getStudents()).hasSize(1);
}
Also used : Filter(org.neo4j.ogm.cypher.Filter) Course(org.neo4j.ogm.domain.education.Course) Student(org.neo4j.ogm.domain.education.Student) Test(org.junit.Test)

Example 39 with Filter

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

the class TreeIntegrationTest method shouldMapElementsToTreeSetProperly.

// GH-88
@Test
public void shouldMapElementsToTreeSetProperly() {
    String cypher = "CREATE (parent:Entity {name:'parent'}) CREATE (child1:Entity {name:'c1'}) CREATE (child2:Entity {name:'c2'}) CREATE (child1)-[:REL]->(parent) CREATE (child2)-[:REL]->(parent)";
    session.query(cypher, Collections.emptyMap());
    session.clear();
    Entity parent = session.loadAll(Entity.class, new Filter("name", ComparisonOperator.EQUALS, "parent")).iterator().next();
    assertThat(parent).isNotNull();
    assertThat(parent.getChildren()).hasSize(2);
    assertThat(parent.getParent()).isNull();
    List<String> childNames = new ArrayList<>();
    for (Entity child : parent.getChildren()) {
        childNames.add(child.getName());
        assertThat(child.getParent().getName()).isEqualTo(parent.getName());
    }
    assertThat(childNames.get(0)).isEqualTo("c1");
    assertThat(childNames.get(1)).isEqualTo("c2");
}
Also used : Entity(org.neo4j.ogm.domain.tree.Entity) Filter(org.neo4j.ogm.cypher.Filter) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 40 with Filter

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

the class ConvertibleIntegrationTest method shouldSaveAndRetrieveEnums.

// DATAGRAPH-550
@Test
public void shouldSaveAndRetrieveEnums() {
    List<Education> completed = new ArrayList<>();
    completed.add(Education.HIGHSCHOOL);
    completed.add(Education.BACHELORS);
    Person person = new Person();
    person.setName("luanne");
    person.setInProgressEducation(new Education[] { Education.MASTERS, Education.PHD });
    person.setCompletedEducation(completed);
    person.setGender(Gender.FEMALE);
    session.save(person);
    Person luanne = session.loadAll(Person.class, new Filter("name", ComparisonOperator.EQUALS, "luanne")).iterator().next();
    assertThat(luanne.getGender()).isEqualTo(Gender.FEMALE);
    assertThat(luanne.getCompletedEducation().contains(Education.HIGHSCHOOL)).isTrue();
    assertThat(luanne.getCompletedEducation().contains(Education.BACHELORS)).isTrue();
    assertThat(luanne.getInProgressEducation().length).isEqualTo(2);
    assertThat(luanne.getInProgressEducation()[0].equals(Education.MASTERS) || luanne.getInProgressEducation()[1].equals(Education.MASTERS)).isTrue();
    assertThat(luanne.getInProgressEducation()[0].equals(Education.PHD) || luanne.getInProgressEducation()[1].equals(Education.PHD)).isTrue();
}
Also used : Education(org.neo4j.ogm.domain.convertible.enums.Education) Filter(org.neo4j.ogm.cypher.Filter) Person(org.neo4j.ogm.domain.convertible.enums.Person) 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