Search in sources :

Example 1 with RowStatementFactory

use of org.neo4j.ogm.session.request.RowStatementFactory in project neo4j-ogm by neo4j.

the class EntityGraphMapperTest method doNothingIfNothingHasChanged.

@Test
public void doNothingIfNothingHasChanged() {
    Long existingNodeId = (Long) session.query("CREATE (s:Student:DomainObject {name:'Sheila Smythe'}) RETURN id(s) AS id", emptyMap()).queryResults().iterator().next().get("id");
    Student sheila = new Student();
    sheila.setId(existingNodeId);
    sheila.setName("Sheila Smythe");
    mappingContext.addNodeEntity(sheila);
    session.clear();
    Compiler compiler = this.mapper.map(sheila).getCompiler();
    compiler.useStatementFactory(new RowStatementFactory());
    Statements cypher = new Statements(compiler.getAllStatements());
    assertThat(cypher.getStatements()).isEmpty();
}
Also used : Compiler(org.neo4j.ogm.cypher.compiler.Compiler) RowStatementFactory(org.neo4j.ogm.session.request.RowStatementFactory) Statements(org.neo4j.ogm.request.Statements) Student(org.neo4j.ogm.domain.education.Student) Test(org.junit.Test)

Example 2 with RowStatementFactory

use of org.neo4j.ogm.session.request.RowStatementFactory in project neo4j-ogm by neo4j.

the class DirectRelationshipsTest method shouldBeAbleToRemoveAnyRegisteredRelationship.

@Test
public void shouldBeAbleToRemoveAnyRegisteredRelationship() {
    // given
    Folder folder = new Folder();
    Document doc1 = new Document();
    Document doc2 = new Document();
    folder.getDocuments().add(doc1);
    folder.getDocuments().add(doc2);
    doc1.setFolder(folder);
    doc2.setFolder(folder);
    folder.setId(0L);
    doc1.setId(1L);
    doc2.setId(2L);
    mappingContext.addNodeEntity(folder);
    mappingContext.addNodeEntity(doc1);
    mappingContext.addNodeEntity(doc2);
    mappingContext.addRelationship(new MappedRelationship(folder.getId(), "CONTAINS", doc1.getId(), null, Folder.class, Document.class));
    mappingContext.addRelationship(new MappedRelationship(folder.getId(), "CONTAINS", doc2.getId(), null, Folder.class, Document.class));
    // when
    doc2.setFolder(null);
    folder.getDocuments().remove(doc2);
    // then
    assertThat(folder.getDocuments()).hasSize(1);
    Compiler compiler = mapper.map(folder).getCompiler();
    compiler.useStatementFactory(new RowStatementFactory());
    List<Statement> statements = compiler.deleteRelationshipStatements();
    assertThat(statements).hasSize(1);
    assertThat(statements.get(0).getStatement()).isEqualTo("UNWIND $rows as row MATCH (startNode) WHERE ID(startNode) = row.startNodeId WITH row,startNode MATCH (endNode) WHERE ID(endNode) = row.endNodeId MATCH (startNode)-[rel:`CONTAINS`]->(endNode) DELETE rel");
    // we need to re-establish the relationship in the mapping context for this expectation, otherwise
    // the previous save will have de-registered the relationship.
    mappingContext.addRelationship(new MappedRelationship(folder.getId(), "CONTAINS", doc2.getId(), null, Folder.class, Document.class));
    compiler = mapper.map(doc1).getCompiler();
    compiler.useStatementFactory(new RowStatementFactory());
    statements = compiler.deleteRelationshipStatements();
    assertThat(statements).hasSize(1);
    assertThat(statements.get(0).getStatement()).isEqualTo("UNWIND $rows as row MATCH (startNode) WHERE ID(startNode) = row.startNodeId WITH row,startNode MATCH (endNode) WHERE ID(endNode) = row.endNodeId MATCH (startNode)-[rel:`CONTAINS`]->(endNode) DELETE rel");
    // we need to re-establish the relationship in the mapping context for this expectation, otherwise
    // the previous save will have de-registered the relationship.
    mappingContext.addRelationship(new MappedRelationship(folder.getId(), "CONTAINS", doc2.getId(), null, Folder.class, Document.class));
    compiler = mapper.map(doc2).getCompiler();
    compiler.useStatementFactory(new RowStatementFactory());
    statements = compiler.deleteRelationshipStatements();
    assertThat(statements).hasSize(1);
    assertThat(statements.get(0).getStatement()).isEqualTo("UNWIND $rows as row MATCH (startNode) WHERE ID(startNode) = row.startNodeId WITH row,startNode MATCH (endNode) WHERE ID(endNode) = row.endNodeId MATCH (startNode)-[rel:`CONTAINS`]->(endNode) DELETE rel");
}
Also used : Compiler(org.neo4j.ogm.cypher.compiler.Compiler) Statement(org.neo4j.ogm.request.Statement) MappedRelationship(org.neo4j.ogm.context.MappedRelationship) RowStatementFactory(org.neo4j.ogm.session.request.RowStatementFactory) Folder(org.neo4j.ogm.domain.filesystem.Folder) Document(org.neo4j.ogm.domain.filesystem.Document) Test(org.junit.Test)

Example 3 with RowStatementFactory

use of org.neo4j.ogm.session.request.RowStatementFactory in project neo4j-ogm by neo4j.

the class CompilerTest method mapAndCompile.

private static Compiler mapAndCompile(Object object, int depth) {
    EntityMapper mapper = new EntityGraphMapper(mappingMetadata, mappingContext);
    CompileContext context = mapper.map(object, depth);
    Compiler compiler = context.getCompiler();
    compiler.useStatementFactory(new RowStatementFactory());
    return compiler;
}
Also used : EntityGraphMapper(org.neo4j.ogm.context.EntityGraphMapper) RowStatementFactory(org.neo4j.ogm.session.request.RowStatementFactory) EntityMapper(org.neo4j.ogm.context.EntityMapper)

Example 4 with RowStatementFactory

use of org.neo4j.ogm.session.request.RowStatementFactory in project neo4j-ogm by neo4j.

the class CompilerTest method doNothingIfNothingHasChanged.

@Test
public void doNothingIfNothingHasChanged() {
    Long existingNodeId = 0L;
    Student sheila = new Student();
    sheila.setId(existingNodeId);
    sheila.setName("Sheila Smythe");
    mappingContext.addNodeEntity(sheila);
    Compiler compiler = mapAndCompile(sheila, -1);
    compiler.useStatementFactory(new RowStatementFactory());
    assertThat(compiler.createNodesStatements()).isEmpty();
    assertThat(compiler.updateNodesStatements()).isEmpty();
}
Also used : RowStatementFactory(org.neo4j.ogm.session.request.RowStatementFactory) Student(org.neo4j.ogm.domain.education.Student) Test(org.junit.Test)

Example 5 with RowStatementFactory

use of org.neo4j.ogm.session.request.RowStatementFactory in project neo4j-ogm by neo4j.

the class MergeWithPrimaryIndexTests method mapAndCompile.

private Compiler mapAndCompile(Object object) {
    CompileContext context = this.mapper.map(object);
    Compiler compiler = context.getCompiler();
    compiler.useStatementFactory(new RowStatementFactory());
    return compiler;
}
Also used : Compiler(org.neo4j.ogm.cypher.compiler.Compiler) RowStatementFactory(org.neo4j.ogm.session.request.RowStatementFactory) CompileContext(org.neo4j.ogm.cypher.compiler.CompileContext)

Aggregations

RowStatementFactory (org.neo4j.ogm.session.request.RowStatementFactory)15 Test (org.junit.Test)12 Compiler (org.neo4j.ogm.cypher.compiler.Compiler)9 Document (org.neo4j.ogm.domain.filesystem.Document)7 Folder (org.neo4j.ogm.domain.filesystem.Folder)7 Statement (org.neo4j.ogm.request.Statement)6 MappedRelationship (org.neo4j.ogm.context.MappedRelationship)4 ArrayList (java.util.ArrayList)3 List (java.util.List)3 EntityGraphMapper (org.neo4j.ogm.context.EntityGraphMapper)3 Student (org.neo4j.ogm.domain.education.Student)3 EntityMapper (org.neo4j.ogm.context.EntityMapper)2 School (org.neo4j.ogm.domain.education.School)2 Teacher (org.neo4j.ogm.domain.education.Teacher)2 MappingContext (org.neo4j.ogm.context.MappingContext)1 CompileContext (org.neo4j.ogm.cypher.compiler.CompileContext)1 MetaData (org.neo4j.ogm.metadata.MetaData)1 Statements (org.neo4j.ogm.request.Statements)1