use of org.neo4j.ogm.cypher.query.DefaultRowModelRequest in project neo4j-ogm by neo4j.
the class NodeDeleteStatements method delete.
@Override
public CypherQuery delete(Long id, Object object, ClassInfo classInfo) {
FieldInfo versionField = classInfo.getVersionField();
Long version = (Long) versionField.read(object);
OptimisticLockingConfig optimisticLockingConfig = new OptimisticLockingConfig(1, classInfo.staticLabels().toArray(new String[] {}), versionField.property());
Map<String, Object> params = new HashMap<>();
params.put("id", id);
params.put("version", version);
params.put("type", "node");
return new DefaultRowModelRequest("MATCH (n) " + " WHERE id(n) = $id AND n.`" + versionField.property() + "` = $version " + "SET " + " n.`" + versionField.property() + "` = n.`" + versionField.property() + "` + 1 " + "WITH n " + " WHERE n.`" + versionField.property() + "` = $version + 1 " + "OPTIONAL MATCH (n)-[r0]-() " + "DELETE r0, n " + // Use DISTINCT because node may have multiple relationships
"RETURN DISTINCT id(n) AS id", params, optimisticLockingConfig);
}
use of org.neo4j.ogm.cypher.query.DefaultRowModelRequest in project neo4j-ogm by neo4j.
the class NodeDeleteStatements method delete.
@Override
public CypherQuery delete(String label, Iterable<Filter> filters) {
FilteredQuery query = FilteredQueryBuilder.buildNodeQuery(label, filters);
query.setReturnClause(" OPTIONAL MATCH (n)-[r0]-() DELETE r0, n");
return new DefaultRowModelRequest(query.statement(), query.parameters());
}
use of org.neo4j.ogm.cypher.query.DefaultRowModelRequest in project neo4j-ogm by neo4j.
the class NodeDeleteStatements method deleteAndList.
@Override
public CypherQuery deleteAndList(String label, Iterable<Filter> filters) {
FilteredQuery query = FilteredQueryBuilder.buildNodeQuery(label, filters);
query.setReturnClause(" OPTIONAL MATCH (n)-[r0]-() DELETE r0, n RETURN ID(n)");
return new DefaultRowModelRequest(query.statement(), query.parameters());
}
use of org.neo4j.ogm.cypher.query.DefaultRowModelRequest in project neo4j-ogm by neo4j.
the class RelationshipDeleteStatements method deleteAndList.
@Override
public CypherQuery deleteAndList(String type, Iterable<Filter> filters) {
FilteredQuery query = FilteredQueryBuilder.buildRelationshipQuery(type, filters);
query.setReturnClause(" DELETE r0 RETURN ID(r0)");
return new DefaultRowModelRequest(query.statement(), query.parameters());
}
use of org.neo4j.ogm.cypher.query.DefaultRowModelRequest in project neo4j-ogm by neo4j.
the class DeleteDelegate method deleteAll.
/**
* Deletes all nodes of a given type. They will get discovered by using the matching label for that type.
* To avoid a delete of every node in the database the method will abort the delete operation if no label
* can be determined.
*
* @param type The type of the nodes/objects to be deleted.
* @param <T> The type to work with
*/
public <T> void deleteAll(Class<T> type) {
ClassInfo classInfo = session.metaData().classInfo(type.getName());
if (classInfo != null) {
String entityLabel = classInfo.neo4jName();
if (entityLabel == null) {
session.warn("Unable to find database label for entity " + type.getName() + " : no results will be returned. Make sure the class is registered, " + "and not abstract without @NodeEntity annotation");
return;
}
Statement request = getDeleteStatementsBasedOnType(type).delete(entityLabel);
RowModelRequest query = new DefaultRowModelRequest(request.getStatement(), request.getParameters());
session.notifyListeners(new PersistenceEvent(type, Event.TYPE.PRE_DELETE));
session.doInTransaction(() -> {
try (Response<RowModel> response = session.requestHandler().execute(query)) {
session.context().removeType(type);
if (session.eventsEnabled()) {
session.notifyListeners(new PersistenceEvent(type, Event.TYPE.POST_DELETE));
}
}
}, Transaction.Type.READ_WRITE);
} else {
session.warn(type.getName() + " is not a persistable class");
}
}
Aggregations