Search in sources :

Example 16 with Student

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

the class CompilerTest method updateSingleObjectPropertyAndLabel.

@Test
public void updateSingleObjectPropertyAndLabel() {
    Student sheila = new Student("Sheila Smythe");
    Long sid = 0L;
    sheila.setId(sid);
    mappingContext.addNodeEntity(sheila);
    // now update the object's properties locally
    sheila.setName("Sheila Smythe-Jones");
    Compiler compiler = mapAndCompile(sheila, -1);
    assertThat(compiler.hasStatementsDependentOnNewNodes()).isFalse();
    compiler.useStatementFactory(new RowStatementFactory());
    assertThat(compiler.createNodesStatements()).isEmpty();
    assertThat(compiler.updateNodesStatements()).extracting(Statement::getStatement).containsOnly("UNWIND $rows as row MATCH (n) WHERE ID(n)=row.nodeId SET n:`DomainObject`:`Student` SET n += row.props RETURN row.nodeId as ref, ID(n) as id, $type as type");
}
Also used : RowStatementFactory(org.neo4j.ogm.session.request.RowStatementFactory) Student(org.neo4j.ogm.domain.education.Student) Test(org.junit.Test)

Example 17 with Student

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

the class CompilerTest method createSingleObjectWithLabelsAndProperties.

@Test
public void createSingleObjectWithLabelsAndProperties() {
    Student newStudent = new Student("Gary");
    assertThat(newStudent.getId()).isNull();
    Compiler compiler = mapAndCompile(newStudent, -1);
    assertThat(compiler.hasStatementsDependentOnNewNodes()).isFalse();
    assertThat(compiler.createNodesStatements()).extracting(Statement::getStatement).containsOnly("UNWIND $rows as row CREATE (n:`DomainObject`:`Student`) SET n=row.props RETURN row.nodeRef as ref, ID(n) as id, $type as type");
}
Also used : Student(org.neo4j.ogm.domain.education.Student) Test(org.junit.Test)

Example 18 with Student

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

the class CompilerTest method shouldCorrectlyRemoveRelationshipWhenItemIsRemovedFromCollection.

@Test
public void shouldCorrectlyRemoveRelationshipWhenItemIsRemovedFromCollection() {
    // simple music course with three students
    Long mid = 0L;
    Long xid = 1L;
    Long yid = 2L;
    Long zid = 3L;
    Course music = new Course("GCSE Music");
    music.setId(mid);
    Student xavier = new Student("xavier");
    xavier.setId(xid);
    Student yvonne = new Student("Yvonne");
    yvonne.setId(yid);
    Student zack = new Student("Zack");
    zack.setId(zid);
    music.setStudents(Arrays.asList(yvonne, xavier, zack));
    mappingContext.addRelationship(new MappedRelationship(mid, "STUDENTS", xid, null, Course.class, Student.class));
    mappingContext.addRelationship(new MappedRelationship(mid, "STUDENTS", yid, null, Course.class, Student.class));
    mappingContext.addRelationship(new MappedRelationship(mid, "STUDENTS", zid, null, Course.class, Student.class));
    mappingContext.addNodeEntity(xavier);
    mappingContext.addNodeEntity(yvonne);
    mappingContext.addNodeEntity(zack);
    mappingContext.addNodeEntity(music);
    // now, update the domain model, setting yvonne as the only music student (i.e remove zack and xavier)
    music.setStudents(Arrays.asList(yvonne));
    // Save music
    Compiler compiler = mapAndCompile(music, -1);
    assertThat(compiler.createNodesStatements()).isEmpty();
    assertThat(compiler.createRelationshipsStatements()).isEmpty();
    List<Statement> deleteRelsStatement = compiler.deleteRelationshipStatements();
    assertThat(deleteRelsStatement).extracting(Statement::getStatement).containsOnly("UNWIND $rows as row MATCH (startNode) WHERE ID(startNode) = row.startNodeId WITH row,startNode MATCH (endNode) WHERE ID(endNode) = row.endNodeId MATCH (startNode)-[rel:`STUDENTS`]->(endNode) DELETE rel");
    assertThat(((List) deleteRelsStatement.get(0).getParameters().get("rows"))).hasSize(2);
}
Also used : Statement(org.neo4j.ogm.request.Statement) MappedRelationship(org.neo4j.ogm.context.MappedRelationship) Course(org.neo4j.ogm.domain.education.Course) Student(org.neo4j.ogm.domain.education.Student) 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