Search in sources :

Example 1 with Statement

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

the class BoltRequest method execute.

@Override
public Response<RowModel> execute(DefaultRequest query) {
    final List<RowModel> rowModels = new ArrayList<>();
    String[] columns = null;
    for (Statement statement : query.getStatements()) {
        Result result = executeRequest(statement);
        if (columns == null) {
            try {
                List<String> columnSet = result.keys();
                columns = columnSet.toArray(new String[columnSet.size()]);
            } catch (ClientException e) {
                throw new CypherException(e.code(), e.getMessage(), e);
            }
        }
        try (RowModelResponse rowModelResponse = new RowModelResponse(result, entityAdapter)) {
            RowModel model;
            while ((model = rowModelResponse.next()) != null) {
                rowModels.add(model);
            }
            result.consume();
        } catch (ClientException e) {
            throw new CypherException(e.code(), e.getMessage(), e);
        }
    }
    return new MultiStatementBasedResponse(columns, rowModels);
}
Also used : RowModelResponse(org.neo4j.ogm.drivers.bolt.response.RowModelResponse) GraphRowModelResponse(org.neo4j.ogm.drivers.bolt.response.GraphRowModelResponse) Statement(org.neo4j.ogm.request.Statement) ArrayList(java.util.ArrayList) RowModel(org.neo4j.ogm.model.RowModel) ClientException(org.neo4j.driver.exceptions.ClientException) CypherException(org.neo4j.ogm.exception.CypherException) Result(org.neo4j.driver.Result)

Example 2 with Statement

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

the class MultiStatementCypherCompiler method deleteRelationshipEntityStatements.

@Override
public List<Statement> deleteRelationshipEntityStatements() {
    assertStatementFactoryExists();
    // Group relationships by type
    Map<String, Set<Edge>> deletedRelsByType = groupRelationshipsByType(deletedRelationshipEntityBuilders);
    List<Statement> statements = new ArrayList<>();
    for (Set<Edge> edges : deletedRelsByType.values()) {
        DeletedRelationshipEntityStatementBuilder deletedRelationshipBuilder = new DeletedRelationshipEntityStatementBuilder(edges, statementFactory);
        statements.add(deletedRelationshipBuilder.build());
    }
    return statements;
}
Also used : Statement(org.neo4j.ogm.request.Statement) DeletedRelationshipEntityStatementBuilder(org.neo4j.ogm.cypher.compiler.builders.statement.DeletedRelationshipEntityStatementBuilder) Edge(org.neo4j.ogm.model.Edge)

Example 3 with Statement

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

the class MultiStatementCypherCompiler method updateRelationshipStatements.

@Override
public List<Statement> updateRelationshipStatements() {
    assertStatementFactoryExists();
    if (existingRelationshipBuilders.isEmpty()) {
        return Collections.emptyList();
    }
    Map<Boolean, Set<Edge>> collect = existingRelationshipBuilders.values().stream().collect(partitioningBy(RelationshipBuilder::isDirty, Collectors.mapping(RelationshipBuilder::edge, Collectors.toSet())));
    List<Statement> result = new ArrayList<>();
    if (!collect.get(true).isEmpty()) {
        ExistingRelationshipStatementBuilder builder = new ExistingRelationshipStatementBuilder(collect.get(true), statementFactory, true);
        result.add(builder.build());
    }
    if (!collect.get(false).isEmpty()) {
        ExistingRelationshipStatementBuilder builder = new ExistingRelationshipStatementBuilder(collect.get(false), statementFactory, false);
        result.add(builder.build());
    }
    return result;
}
Also used : ExistingRelationshipStatementBuilder(org.neo4j.ogm.cypher.compiler.builders.statement.ExistingRelationshipStatementBuilder) Statement(org.neo4j.ogm.request.Statement) DefaultRelationshipBuilder(org.neo4j.ogm.cypher.compiler.builders.node.DefaultRelationshipBuilder)

Example 4 with Statement

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

the class MultiStatementCypherCompiler method updateNodesStatements.

@Override
public List<Statement> updateNodesStatements() {
    assertStatementFactoryExists();
    Map<String, Set<Node>> existingNodesByLabels = groupNodesByLabel(existingNodeBuilders.values());
    List<Statement> statements = new ArrayList<>(existingNodesByLabels.size());
    for (Set<Node> nodeModels : existingNodesByLabels.values()) {
        ExistingNodeStatementBuilder existingNodeBuilder = new ExistingNodeStatementBuilder(nodeModels, statementFactory);
        statements.add(existingNodeBuilder.build());
    }
    return statements;
}
Also used : Statement(org.neo4j.ogm.request.Statement) Node(org.neo4j.ogm.model.Node) ExistingNodeStatementBuilder(org.neo4j.ogm.cypher.compiler.builders.statement.ExistingNodeStatementBuilder)

Example 5 with Statement

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

the class AutoIndexManager method assertIndexes.

private void assertIndexes() {
    LOGGER.debug("Asserting indexes and constraints");
    List<Statement> dropStatements = new ArrayList<>();
    List<AutoIndex> dbIndexes = loadIndexesFromDB();
    for (AutoIndex dbIndex : dbIndexes) {
        LOGGER.debug("[{}] added to drop statements.", dbIndex.getDescription());
        dropStatements.add(dbIndex.getDropStatement());
    }
    DefaultRequest dropIndexesRequest = new DefaultRequest();
    dropIndexesRequest.setStatements(dropStatements);
    LOGGER.debug("Dropping all indexes and constraints");
    // make sure drop and create happen in separate transactions
    // neo does not support that
    session.doInTransaction(() -> {
        session.requestHandler().execute(dropIndexesRequest);
    }, READ_WRITE);
    create();
}
Also used : DefaultRequest(org.neo4j.ogm.session.request.DefaultRequest) 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