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