Search in sources :

Example 1 with DefaultRowModelRequest

use of org.neo4j.ogm.cypher.query.DefaultRowModelRequest in project neo4j-ogm by neo4j.

the class DeleteDelegate method purgeDatabase.

public void purgeDatabase() {
    Statement stmt = new NodeDeleteStatements().deleteAll();
    RowModelRequest query = new DefaultRowModelRequest(stmt.getStatement(), stmt.getParameters());
    session.doInTransaction(() -> {
        session.requestHandler().execute(query).close();
    }, Transaction.Type.READ_WRITE);
    session.context().clear();
}
Also used : Statement(org.neo4j.ogm.request.Statement) RowModelRequest(org.neo4j.ogm.request.RowModelRequest) DefaultRowModelRequest(org.neo4j.ogm.cypher.query.DefaultRowModelRequest) NodeDeleteStatements(org.neo4j.ogm.session.request.strategy.impl.NodeDeleteStatements) DefaultRowModelRequest(org.neo4j.ogm.cypher.query.DefaultRowModelRequest)

Example 2 with DefaultRowModelRequest

use of org.neo4j.ogm.cypher.query.DefaultRowModelRequest in project neo4j-ogm by neo4j.

the class CountStatements method countNodes.

@Override
public CypherQuery countNodes(String label, Iterable<Filter> filters) {
    FilteredQuery query = FilteredQueryBuilder.buildNodeQuery(label, filters);
    query.setReturnClause(" RETURN COUNT(n)");
    return new DefaultRowModelRequest(query.statement(), query.parameters());
}
Also used : FilteredQuery(org.neo4j.ogm.session.request.FilteredQuery) DefaultRowModelRequest(org.neo4j.ogm.cypher.query.DefaultRowModelRequest)

Example 3 with DefaultRowModelRequest

use of org.neo4j.ogm.cypher.query.DefaultRowModelRequest in project neo4j-ogm by neo4j.

the class RelationshipDeleteStatements 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", "rel");
    return new DefaultRowModelRequest("MATCH (n)-[r0]->() " + "  WHERE ID(r0) = $id AND r0.`" + versionField.property() + "` = $version " + "SET " + " r0.`" + versionField.property() + "` = r0.`" + versionField.property() + "` + 1 " + "WITH r0 " + " WHERE r0.`" + versionField.property() + "` = $version + 1 " + "DELETE r0 " + // Use DISTINCT because node may have multiple relationships
    "RETURN DISTINCT ID(r0) AS id", params, optimisticLockingConfig);
}
Also used : HashMap(java.util.HashMap) OptimisticLockingConfig(org.neo4j.ogm.request.OptimisticLockingConfig) FieldInfo(org.neo4j.ogm.metadata.FieldInfo) DefaultRowModelRequest(org.neo4j.ogm.cypher.query.DefaultRowModelRequest)

Example 4 with DefaultRowModelRequest

use of org.neo4j.ogm.cypher.query.DefaultRowModelRequest in project neo4j-ogm by neo4j.

the class RelationshipDeleteStatements method delete.

@Override
public CypherQuery delete(String type, Iterable<Filter> filters) {
    FilteredQuery query = FilteredQueryBuilder.buildRelationshipQuery(type, filters);
    query.setReturnClause(" DELETE r0");
    return new DefaultRowModelRequest(query.statement(), query.parameters());
}
Also used : FilteredQuery(org.neo4j.ogm.session.request.FilteredQuery) DefaultRowModelRequest(org.neo4j.ogm.cypher.query.DefaultRowModelRequest)

Example 5 with DefaultRowModelRequest

use of org.neo4j.ogm.cypher.query.DefaultRowModelRequest in project neo4j-ogm by neo4j.

the class CountStatements method countEdges.

@Override
public CypherQuery countEdges(String type, Iterable<Filter> filters) {
    FilteredQuery query = FilteredQueryBuilder.buildRelationshipQuery(type, filters);
    query.setReturnClause(" RETURN COUNT(r0)");
    return new DefaultRowModelRequest(query.statement(), query.parameters());
}
Also used : FilteredQuery(org.neo4j.ogm.session.request.FilteredQuery) DefaultRowModelRequest(org.neo4j.ogm.cypher.query.DefaultRowModelRequest)

Aggregations

DefaultRowModelRequest (org.neo4j.ogm.cypher.query.DefaultRowModelRequest)11 FilteredQuery (org.neo4j.ogm.session.request.FilteredQuery)6 RowModelRequest (org.neo4j.ogm.request.RowModelRequest)3 Statement (org.neo4j.ogm.request.Statement)3 HashMap (java.util.HashMap)2 ClassInfo (org.neo4j.ogm.metadata.ClassInfo)2 FieldInfo (org.neo4j.ogm.metadata.FieldInfo)2 RowModel (org.neo4j.ogm.model.RowModel)2 OptimisticLockingConfig (org.neo4j.ogm.request.OptimisticLockingConfig)2 PersistenceEvent (org.neo4j.ogm.session.event.PersistenceEvent)2 NodeDeleteStatements (org.neo4j.ogm.session.request.strategy.impl.NodeDeleteStatements)2 Serializable (java.io.Serializable)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 Collections (java.util.Collections)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Map (java.util.Map)1 Set (java.util.Set)1 MappingContext (org.neo4j.ogm.context.MappingContext)1