Search in sources :

Example 1 with RowModelResponse

use of org.neo4j.ogm.drivers.embedded.response.RowModelResponse in project neo4j-ogm by neo4j.

the class EmbeddedRequest method execute.

@Override
public Response<RowModel> execute(DefaultRequest query) {
    // TODO this is a hack to get the embedded driver to work with executing multiple statements
    final List<RowModel> rowmodels = new ArrayList<>();
    String[] columns = null;
    for (Statement statement : query.getStatements()) {
        Result result = executeRequest(statement);
        if (columns == null) {
            columns = result.columns().toArray(new String[result.columns().size()]);
        }
        RowModelResponse rowModelResponse = new RowModelResponse(result, entityAdapter);
        RowModel model;
        while ((model = rowModelResponse.next()) != null) {
            rowmodels.add(model);
        }
        result.close();
    }
    final String[] finalColumns = columns;
    return new Response<>() {

        int currentRow = 0;

        @Override
        public RowModel next() {
            if (currentRow < rowmodels.size()) {
                return rowmodels.get(currentRow++);
            }
            return null;
        }

        @Override
        public void close() {
        }

        @Override
        public String[] columns() {
            return finalColumns;
        }
    };
}
Also used : Response(org.neo4j.ogm.response.Response) EmptyResponse(org.neo4j.ogm.response.EmptyResponse) GraphRowModelResponse(org.neo4j.ogm.drivers.embedded.response.GraphRowModelResponse) GraphModelResponse(org.neo4j.ogm.drivers.embedded.response.GraphModelResponse) RowModelResponse(org.neo4j.ogm.drivers.embedded.response.RowModelResponse) RestModelResponse(org.neo4j.ogm.drivers.embedded.response.RestModelResponse) GraphRowModelResponse(org.neo4j.ogm.drivers.embedded.response.GraphRowModelResponse) RowModelResponse(org.neo4j.ogm.drivers.embedded.response.RowModelResponse) Statement(org.neo4j.ogm.request.Statement) ArrayList(java.util.ArrayList) RowModel(org.neo4j.ogm.model.RowModel) Result(org.neo4j.graphdb.Result)

Aggregations

ArrayList (java.util.ArrayList)1 Result (org.neo4j.graphdb.Result)1 GraphModelResponse (org.neo4j.ogm.drivers.embedded.response.GraphModelResponse)1 GraphRowModelResponse (org.neo4j.ogm.drivers.embedded.response.GraphRowModelResponse)1 RestModelResponse (org.neo4j.ogm.drivers.embedded.response.RestModelResponse)1 RowModelResponse (org.neo4j.ogm.drivers.embedded.response.RowModelResponse)1 RowModel (org.neo4j.ogm.model.RowModel)1 Statement (org.neo4j.ogm.request.Statement)1 EmptyResponse (org.neo4j.ogm.response.EmptyResponse)1 Response (org.neo4j.ogm.response.Response)1