use of org.neo4j.ogm.cypher.compiler.builders.statement.NewRelationshipStatementBuilder in project neo4j-ogm by neo4j.
the class MultiStatementCypherCompiler method createRelationshipsStatements.
@Override
public List<Statement> createRelationshipsStatements() {
assertStatementFactoryExists();
// Group relationships by type and non-null properties
// key: relationship type, value: Map where key=Set<Property strings>, value: Set of edges with those properties
Map<String, Map<String, Set<Edge>>> relsByTypeAndProps = new HashMap<>();
for (RelationshipBuilder relationshipBuilder : newRelationshipBuilders) {
if (relationshipBuilder.edge().getStartNode() == null || relationshipBuilder.edge().getEndNode() == null) {
// TODO this is a carry forward from the old emitters. We want to prevent this rel builder getting created or remove it
continue;
}
Map<String, Set<Edge>> relsByProps = relsByTypeAndProps.computeIfAbsent(relationshipBuilder.type(), (key) -> new HashMap<>());
RelationshipModel edge = (RelationshipModel) relationshipBuilder.edge();
String primaryId = edge.getPrimaryIdName();
Set<Edge> rels = relsByProps.computeIfAbsent(primaryId, (s) -> new HashSet<>());
edge.setStartNode(context.getId(edge.getStartNode()));
edge.setEndNode(context.getId(edge.getEndNode()));
rels.add(edge);
}
List<Statement> statements = new ArrayList<>();
// For each relationship type
for (Map<String, Set<Edge>> edgesByProperties : relsByTypeAndProps.values()) {
// For each set of unique property keys
for (Set<Edge> edges : edgesByProperties.values()) {
NewRelationshipStatementBuilder newRelationshipBuilder = new NewRelationshipStatementBuilder(edges, statementFactory);
statements.add(newRelationshipBuilder.build());
}
}
return statements;
}
Aggregations