use of org.neo4j.ogm.model.Property in project neo4j-ogm by neo4j.
the class DeletedRelationshipEntityStatementBuilder method build.
@Override
public Statement build() {
final Map<String, Object> parameters = new HashMap<>();
final StringBuilder queryBuilder = new StringBuilder();
if (deletedEdges != null && deletedEdges.size() > 0) {
Edge firstEdge = deletedEdges.iterator().next();
queryBuilder.append("UNWIND $rows AS row MATCH ()-[r]->() WHERE ID(r) = row.relId ");
if (firstEdge.hasVersionProperty()) {
queryBuilder.append(OptimisticLockingUtils.getFragmentForExistingNodesAndRelationships(firstEdge, "r"));
}
queryBuilder.append("DELETE r RETURN ID(r) as ref, ID(r) as id, $type as type");
List<Map> rows = new ArrayList<>();
for (Edge edge : deletedEdges) {
Map<String, Object> rowMap = new HashMap<>();
rowMap.put("relId", edge.getId());
if (edge.hasVersionProperty()) {
Property version = edge.getVersion();
rowMap.put((String) version.getKey(), version.getValue());
}
rows.add(rowMap);
}
parameters.put("rows", rows);
parameters.put("type", "rel");
if (firstEdge.hasVersionProperty()) {
OptimisticLockingConfig olConfig = new OptimisticLockingConfig(rows.size(), new String[] { firstEdge.getType() }, firstEdge.getVersion().getKey());
return statementFactory.statement(queryBuilder.toString(), parameters, olConfig);
}
}
return statementFactory.statement(queryBuilder.toString(), parameters);
}
use of org.neo4j.ogm.model.Property in project neo4j-ogm by neo4j.
the class NewRelationshipStatementBuilder method build.
@Override
public Statement build() {
final Map<String, Object> parameters = new HashMap<>();
final StringBuilder queryBuilder = new StringBuilder();
boolean hasProperties = false;
if (edges != null && edges.size() > 0) {
Edge firstEdge = edges.iterator().next();
String relType = firstEdge.getType();
hasProperties = firstEdge.getPropertyList().size() > 0;
boolean hasPrimaryId = firstEdge.getPrimaryIdName() != null;
queryBuilder.append("UNWIND $rows as row ").append("MATCH (startNode) WHERE ID(startNode) = row.startNodeId WITH row,startNode ").append("MATCH (endNode) WHERE ID(endNode) = row.endNodeId ");
if (hasProperties && !hasPrimaryId) {
queryBuilder.append("CREATE ");
} else {
queryBuilder.append("MERGE ");
}
queryBuilder.append("(startNode)-[rel:`").append(relType).append("`");
if (hasPrimaryId) {
queryBuilder.append(" {`").append(firstEdge.getPrimaryIdName()).append("`: row.props.`").append(firstEdge.getPrimaryIdName()).append("`}");
}
queryBuilder.append("]->(endNode) ");
if (hasProperties) {
queryBuilder.append("SET rel += row.props ");
}
queryBuilder.append("RETURN row.relRef as ref, ID(rel) as id, $type as type");
List<Map> rows = new ArrayList<>();
for (Edge edge : edges) {
Map<String, Object> rowMap = new HashMap<>();
rowMap.put("startNodeId", edge.getStartNode());
rowMap.put("endNodeId", edge.getEndNode());
rowMap.put("relRef", edge.getId());
if (hasProperties) {
Map<String, Object> props = new HashMap<>();
for (Property property : edge.getPropertyList()) {
props.put((String) property.getKey(), property.getValue());
}
rowMap.put("props", props);
} else {
// need to put empty map here for simple relationships to avoid Cypher error because
// props is used in the query
rowMap.put("props", emptyMap());
}
rows.add(rowMap);
}
parameters.put("type", "rel");
parameters.put("rows", rows);
}
return statementFactory.statement(queryBuilder.toString(), parameters);
}
use of org.neo4j.ogm.model.Property in project neo4j-ogm by neo4j.
the class ExistingRelationshipStatementBuilder method build.
@Override
public Statement build() {
final Map<String, Object> parameters = new HashMap<>();
final StringBuilder queryBuilder = new StringBuilder();
Edge firstEdge = edges.iterator().next();
if (edges.size() > 0) {
queryBuilder.append("UNWIND $rows AS row MATCH ()-[r]->() WHERE ID(r) = row.relId ");
if (firstEdge.hasVersionProperty()) {
queryBuilder.append(OptimisticLockingUtils.getFragmentForExistingNodesAndRelationships(firstEdge, "r", dirtyEdges ? 1 : 0));
}
queryBuilder.append(firstEdge.createPropertyRemovalFragment("r"));
queryBuilder.append("SET r += row.props ");
queryBuilder.append("RETURN ID(r) as ref, ID(r) as id, $type as type");
List<Map> rows = new ArrayList<>();
for (Edge edge : edges) {
Map<String, Object> rowMap = new HashMap<>();
rowMap.put("relId", edge.getId());
Map<String, Object> props = new HashMap<>();
for (Property property : edge.getPropertyList()) {
if (!property.equals(edge.getVersion())) {
props.put((String) property.getKey(), property.getValue());
}
}
rowMap.put("props", props);
if (edge.hasVersionProperty()) {
Property version = edge.getVersion();
rowMap.put((String) version.getKey(), version.getValue());
}
rows.add(rowMap);
}
parameters.put("rows", rows);
parameters.put("type", "rel");
if (firstEdge.hasVersionProperty()) {
OptimisticLockingConfig olConfig = new OptimisticLockingConfig(rows.size(), new String[] { firstEdge.getType() }, firstEdge.getVersion().getKey());
return statementFactory.statement(queryBuilder.toString(), parameters, olConfig);
}
}
return statementFactory.statement(queryBuilder.toString(), parameters);
}