Search in sources :

Example 6 with Statement

use of org.neo4j.ogm.request.Statement in project neo4j-ogm by neo4j.

the class AutoIndexManager method create.

private void create() {
    // build indexes according to metadata
    List<Statement> statements = new ArrayList<>();
    for (AutoIndex index : indexes) {
        final Statement createStatement = index.getCreateStatement();
        statements.add(createStatement);
        LOGGER.debug("[{}] added to create statements.", createStatement);
    }
    LOGGER.debug("Creating indexes and constraints.");
    DefaultRequest request = new DefaultRequest();
    request.setStatements(statements);
    session.doInTransaction(() -> session.requestHandler().execute(request).close(), READ_WRITE);
}
Also used : DefaultRequest(org.neo4j.ogm.session.request.DefaultRequest) Statement(org.neo4j.ogm.request.Statement) ArrayList(java.util.ArrayList)

Example 7 with Statement

use of org.neo4j.ogm.request.Statement in project neo4j-ogm by neo4j.

the class ParameterisedStatementsTest method testStatement.

@Test
public void testStatement() throws Exception {
    List<Statement> statements = new ArrayList<>();
    PagingAndSortingQuery query = new NodeQueryStatements().findOne(123L, 1);
    statements.add(new DefaultGraphModelRequest(query.getStatement(), query.getParameters()));
    String cypher = mapper.writeValueAsString(new Statements(statements));
    assertThat(cypher).isEqualTo("{\"statements\":[{\"statement\":\"MATCH (n) WHERE ID(n) = $id WITH n MATCH p=(n)-[*0..1]-(m) RETURN p\",\"parameters\":{\"id\":123},\"resultDataContents\":[\"graph\"],\"includeStats\":false}]}");
}
Also used : DefaultGraphModelRequest(org.neo4j.ogm.cypher.query.DefaultGraphModelRequest) Statement(org.neo4j.ogm.request.Statement) ArrayList(java.util.ArrayList) Statements(org.neo4j.ogm.request.Statements) PagingAndSortingQuery(org.neo4j.ogm.cypher.query.PagingAndSortingQuery) Test(org.junit.Test)

Example 8 with Statement

use of org.neo4j.ogm.request.Statement in project neo4j-ogm by neo4j.

the class DeleteDelegate method getDeleteStatement.

private Statement getDeleteStatement(Object object, Long identity, ClassInfo classInfo) {
    DeleteStatements deleteStatements = getDeleteStatementsBasedOnType(object.getClass());
    Statement request;
    if (classInfo.hasVersionField()) {
        request = deleteStatements.delete(identity, object, classInfo);
    } else {
        request = deleteStatements.delete(identity);
    }
    return request;
}
Also used : RelationshipDeleteStatements(org.neo4j.ogm.session.request.strategy.impl.RelationshipDeleteStatements) DeleteStatements(org.neo4j.ogm.session.request.strategy.DeleteStatements) NodeDeleteStatements(org.neo4j.ogm.session.request.strategy.impl.NodeDeleteStatements) Statement(org.neo4j.ogm.request.Statement)

Example 9 with Statement

use of org.neo4j.ogm.request.Statement 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 10 with Statement

use of org.neo4j.ogm.request.Statement in project neo4j-ogm by neo4j.

the class RequestExecutor method executeSave.

/**
 * Execute a save request.
 * Decides how the request is split depending upon characteristics of what is to be saved.
 * Processes the response(s) and updates the mapping context.
 *
 * @param context the CompileContext for this request
 */
public void executeSave(CompileContext context) {
    Compiler compiler = context.getCompiler();
    compiler.useStatementFactory(new RowStatementFactory());
    List<ReferenceMapping> entityReferenceMappings = new ArrayList<>();
    List<ReferenceMapping> relReferenceMappings = new ArrayList<>();
    boolean forceTx = compiler.updateNodesStatements().stream().anyMatch(st -> st.optimisticLockingConfig().isPresent()) || compiler.updateRelationshipStatements().stream().anyMatch(st -> st.optimisticLockingConfig().isPresent());
    session.doInTransaction(() -> {
        // we must create the new nodes first, and then use their node IDs when creating relationships between them
        if (compiler.hasStatementsDependentOnNewNodes()) {
            // execute the statements to create new nodes. The ids will be returned
            // and will be used in subsequent statements that refer to these new nodes.
            executeStatements(context, entityReferenceMappings, relReferenceMappings, compiler.createNodesStatements());
            List<Statement> statements = new ArrayList<>();
            statements.addAll(compiler.createRelationshipsStatements());
            statements.addAll(compiler.updateNodesStatements());
            statements.addAll(compiler.updateRelationshipStatements());
            statements.addAll(compiler.deleteRelationshipStatements());
            statements.addAll(compiler.deleteRelationshipEntityStatements());
            executeStatements(context, entityReferenceMappings, relReferenceMappings, statements);
        } else {
            // only update / delete statements
            List<Statement> statements = compiler.getAllStatements();
            executeStatements(context, entityReferenceMappings, relReferenceMappings, statements);
        }
    }, forceTx, Transaction.Type.READ_WRITE);
    // Update the mapping context now that the request is successful
    updateNodeEntities(context, entityReferenceMappings);
    updateRelationshipEntities(context, relReferenceMappings);
    updateRelationships(context, relReferenceMappings);
}
Also used : MappedRelationship(org.neo4j.ogm.context.MappedRelationship) RelationshipEntity(org.neo4j.ogm.annotation.RelationshipEntity) AbstractTransaction(org.neo4j.ogm.transaction.AbstractTransaction) Logger(org.slf4j.Logger) LoggerFactory(org.slf4j.LoggerFactory) Response(org.neo4j.ogm.response.Response) HashMap(java.util.HashMap) CompileContext(org.neo4j.ogm.cypher.compiler.CompileContext) Neo4jSession(org.neo4j.ogm.session.Neo4jSession) MappingContext(org.neo4j.ogm.context.MappingContext) Statement(org.neo4j.ogm.request.Statement) ArrayList(java.util.ArrayList) List(java.util.List) RowModel(org.neo4j.ogm.model.RowModel) Map(java.util.Map) Compiler(org.neo4j.ogm.cypher.compiler.Compiler) ClassInfo(org.neo4j.ogm.metadata.ClassInfo) Transaction(org.neo4j.ogm.transaction.Transaction) EntityUtils(org.neo4j.ogm.utils.EntityUtils) TransientRelationship(org.neo4j.ogm.context.TransientRelationship) Compiler(org.neo4j.ogm.cypher.compiler.Compiler) Statement(org.neo4j.ogm.request.Statement) ArrayList(java.util.ArrayList)

Aggregations

Statement (org.neo4j.ogm.request.Statement)38 ArrayList (java.util.ArrayList)20 Test (org.junit.Test)19 List (java.util.List)15 MappedRelationship (org.neo4j.ogm.context.MappedRelationship)10 Compiler (org.neo4j.ogm.cypher.compiler.Compiler)7 Map (java.util.Map)6 Document (org.neo4j.ogm.domain.filesystem.Document)6 Folder (org.neo4j.ogm.domain.filesystem.Folder)6 RowModel (org.neo4j.ogm.model.RowModel)6 RowStatementFactory (org.neo4j.ogm.session.request.RowStatementFactory)5 Teacher (org.neo4j.ogm.domain.education.Teacher)4 HashMap (java.util.HashMap)3 Set (java.util.Set)3 DefaultRowModelRequest (org.neo4j.ogm.cypher.query.DefaultRowModelRequest)3 Forum (org.neo4j.ogm.domain.forum.Forum)3 ForumTopicLink (org.neo4j.ogm.domain.forum.ForumTopicLink)3 Topic (org.neo4j.ogm.domain.forum.Topic)3 Node (org.neo4j.ogm.model.Node)3 Arrays (java.util.Arrays)2