Search in sources :

Example 11 with Student

use of org.neo4j.ogm.domain.education.Student in project neo4j-ogm by neo4j.

the class EntityGraphMapperTest method addObjectToCollection.

@Test
public void addObjectToCollection() {
    // fake load one student on a course
    Iterable<Map<String, Object>> executionResult = session.query("CREATE (c:Course {name:'BSc Computer Science'})-[:STUDENTS]->(s:Student:DomainObject {name:'Gianfranco'}) " + "RETURN id(s) AS student_id, id(c) AS course_id", emptyMap()).queryResults();
    Map<String, Object> resultSetRow = executionResult.iterator().next();
    Long studentId = Long.valueOf(resultSetRow.get("student_id").toString());
    Long courseId = Long.valueOf(resultSetRow.get("course_id").toString());
    session.clear();
    Student gianFranco = session.load(Student.class, studentId);
    Course bscComputerScience = session.load(Course.class, courseId);
    // create a new student and set both students on the course
    Student lakshmipathy = new Student("Lakshmipathy");
    bscComputerScience.setStudents(Arrays.asList(lakshmipathy, gianFranco));
    // XXX: NB: currently using a dodgy relationship type because of simple strategy read/write relationship naming inconsistency
    session.save(bscComputerScience);
    session.clear();
    assertThat(session.queryForObject(Course.class, "MATCH (c:Course)-[students:STUDENTS]->(s:Student:DomainObject) return c, students, s", emptyMap()).getStudents()).hasSize(2);
}
Also used : Student(org.neo4j.ogm.domain.education.Student) Course(org.neo4j.ogm.domain.education.Course) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.junit.Test)

Example 12 with Student

use of org.neo4j.ogm.domain.education.Student in project neo4j-ogm by neo4j.

the class EntityGraphMapperTest method createObjectWithLabelsAndProperties.

@Test
public void createObjectWithLabelsAndProperties() {
    Student newStudent = new Student("Gary");
    session.save(newStudent);
    session.clear();
    assertThat(session.query("MATCH (s:Student:DomainObject {name: 'Gary'}) return s", emptyMap()).queryResults()).isNotEmpty();
}
Also used : Student(org.neo4j.ogm.domain.education.Student) Test(org.junit.Test)

Example 13 with Student

use of org.neo4j.ogm.domain.education.Student in project neo4j-ogm by neo4j.

the class EntityGraphMapperTest method updateObjectPropertyAndLabel.

@Test
public void updateObjectPropertyAndLabel() {
    // This does only work in non-strict querying
    Session customSession = new SessionFactory(getDriver(), false, "org.neo4j.ogm.domain.education").openSession();
    Long sid = (Long) customSession.query("CREATE (s:Student {name:'Sheila Smythe'}) RETURN id(s) AS id", emptyMap()).queryResults().iterator().next().get("id");
    customSession.clear();
    Student sheila = customSession.load(Student.class, sid);
    // now update the object's properties locally
    sheila.setName("Sheila Smythe-Jones");
    customSession.save(sheila);
    customSession.clear();
    assertThat(customSession.query("MATCH (s:DomainObject:Student {name:'Sheila Smythe-Jones'}) return s", emptyMap()).queryResults()).isNotEmpty();
}
Also used : SessionFactory(org.neo4j.ogm.session.SessionFactory) Student(org.neo4j.ogm.domain.education.Student) Session(org.neo4j.ogm.session.Session) Test(org.junit.Test)

Example 14 with Student

use of org.neo4j.ogm.domain.education.Student in project neo4j-ogm by neo4j.

the class EntityGraphMapperTest method shouldCorrectlyRemoveRelationshipWhenItemIsMovedToDifferentCollection.

@Test
public void shouldCorrectlyRemoveRelationshipWhenItemIsMovedToDifferentCollection() {
    // start with one teacher teachers two courses, each with one student in
    Iterable<Map<String, Object>> executionResult = session.query("CREATE (t:Teacher {name:'Ms Thompson'}), " + "(bs:Course {name:'GNVQ Business Studies'})-[:STUDENTS]->(s:Student:DomainObject {name:'Shivani'}), " + "(dt:Course {name:'GCSE Design & Technology'})-[:STUDENTS]->(j:Student:DomainObject {name:'Jeff'}), " + "(t)-[:COURSES]->(bs), (t)-[:COURSES]->(dt) " + "RETURN id(t) AS teacher_id, id(bs) AS bs_id, id(dt) AS dt_id, id(s) AS s_id", emptyMap()).queryResults();
    Map<String, ?> results = executionResult.iterator().next();
    Long teacherId = (Long) results.get("teacher_id");
    Long businessStudiesCourseId = (Long) results.get("bs_id");
    Long designTechnologyCourseId = (Long) results.get("dt_id");
    Long studentId = (Long) results.get("s_id");
    session.clear();
    Course designTech = session.load(Course.class, designTechnologyCourseId);
    Course businessStudies = session.load(Course.class, businessStudiesCourseId);
    Teacher msThompson = session.load(Teacher.class, teacherId);
    Student shivani = session.load(Student.class, studentId);
    // move student from one course to the other
    businessStudies.setStudents(Collections.<Student>emptyList());
    designTech.getStudents().add(shivani);
    session.save(msThompson);
    session.clear();
    assertThat(session.query("MATCH (t:Teacher {name:'Ms Thompson'}), " + "(bs:Course {name:'GNVQ Business Studies'}), (dt:Course {name:'GCSE Design & Technology'}) " + "WHERE (dt)-[:STUDENTS]->(:Student:DomainObject {name:'Jeff'}) and " + "(dt)-[:STUDENTS]->(:Student:DomainObject {name:'Shivani'}) and " + "(t)-[:COURSES]->(bs) and (t)-[:COURSES]->(dt) return t, bs, dt", emptyMap()).queryResults()).hasSize(1);
}
Also used : Teacher(org.neo4j.ogm.domain.education.Teacher) Course(org.neo4j.ogm.domain.education.Course) Student(org.neo4j.ogm.domain.education.Student) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.junit.Test)

Example 15 with Student

use of org.neo4j.ogm.domain.education.Student in project neo4j-ogm by neo4j.

the class LoadCapabilityTest method loadAllByInstancesShouldLoadAllClasses.

@Test
public void loadAllByInstancesShouldLoadAllClasses() {
    SessionFactory sf = new SessionFactory(getDriver(), "org.neo4j.ogm.domain.education");
    Session sessionWithEducationDomain = sf.openSession();
    School school = new School();
    Student student = new Student();
    sessionWithEducationDomain.save(school);
    sessionWithEducationDomain.save(student);
    Collection<DomainObject> loaded = sessionWithEducationDomain.loadAll(Arrays.asList(school, student));
    assertThat(loaded).contains(school, student);
}
Also used : SessionFactory(org.neo4j.ogm.session.SessionFactory) School(org.neo4j.ogm.domain.education.School) DomainObject(org.neo4j.ogm.domain.education.DomainObject) Student(org.neo4j.ogm.domain.education.Student) Neo4jSession(org.neo4j.ogm.session.Neo4jSession) Session(org.neo4j.ogm.session.Session) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)18 Student (org.neo4j.ogm.domain.education.Student)18 Course (org.neo4j.ogm.domain.education.Course)11 Teacher (org.neo4j.ogm.domain.education.Teacher)6 HashMap (java.util.HashMap)3 Map (java.util.Map)3 Statement (org.neo4j.ogm.request.Statement)3 RowStatementFactory (org.neo4j.ogm.session.request.RowStatementFactory)3 ArrayList (java.util.ArrayList)2 List (java.util.List)2 MappedRelationship (org.neo4j.ogm.context.MappedRelationship)2 School (org.neo4j.ogm.domain.education.School)2 Session (org.neo4j.ogm.session.Session)2 SessionFactory (org.neo4j.ogm.session.SessionFactory)2 HashSet (java.util.HashSet)1 Filter (org.neo4j.ogm.cypher.Filter)1 Compiler (org.neo4j.ogm.cypher.compiler.Compiler)1 DomainObject (org.neo4j.ogm.domain.education.DomainObject)1 Statements (org.neo4j.ogm.request.Statements)1 Neo4jSession (org.neo4j.ogm.session.Neo4jSession)1