Search in sources :

Example 1 with DefaultRequest

use of org.neo4j.ogm.session.request.DefaultRequest 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)

Example 2 with DefaultRequest

use of org.neo4j.ogm.session.request.DefaultRequest 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 3 with DefaultRequest

use of org.neo4j.ogm.session.request.DefaultRequest in project neo4j-ogm by neo4j.

the class AutoIndexManager method executeStatements.

private void executeStatements(List<Statement> statements) {
    DefaultRequest request = new DefaultRequest();
    request.setStatements(statements);
    session.doInTransaction(() -> {
        try (Response<RowModel> response = session.requestHandler().execute(request)) {
        // Success
        }
    }, READ_WRITE);
}
Also used : DefaultRequest(org.neo4j.ogm.session.request.DefaultRequest) RowModel(org.neo4j.ogm.model.RowModel)

Aggregations

DefaultRequest (org.neo4j.ogm.session.request.DefaultRequest)3 ArrayList (java.util.ArrayList)2 Statement (org.neo4j.ogm.request.Statement)2 RowModel (org.neo4j.ogm.model.RowModel)1