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