Search in sources :

Example 1 with Statements

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

the class EntityGraphMapperTest method doNothingIfNothingHasChanged.

@Test
public void doNothingIfNothingHasChanged() {
    Long existingNodeId = (Long) session.query("CREATE (s:Student:DomainObject {name:'Sheila Smythe'}) RETURN id(s) AS id", emptyMap()).queryResults().iterator().next().get("id");
    Student sheila = new Student();
    sheila.setId(existingNodeId);
    sheila.setName("Sheila Smythe");
    mappingContext.addNodeEntity(sheila);
    session.clear();
    Compiler compiler = this.mapper.map(sheila).getCompiler();
    compiler.useStatementFactory(new RowStatementFactory());
    Statements cypher = new Statements(compiler.getAllStatements());
    assertThat(cypher.getStatements()).isEmpty();
}
Also used : Compiler(org.neo4j.ogm.cypher.compiler.Compiler) RowStatementFactory(org.neo4j.ogm.session.request.RowStatementFactory) Statements(org.neo4j.ogm.request.Statements) Student(org.neo4j.ogm.domain.education.Student) Test(org.junit.Test)

Example 2 with Statements

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

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

the class HttpRequest method cypherRequest.

// we use the OBJECT_MAPPER to create the request string from the statement.
// this driver is the only one that needs to do this, because the request format
// is different for each type of request - GraphModelRequest/RowModelRequest, etc
private String cypherRequest(Statement statement) {
    List<Statement> statementList = new ArrayList<>();
    statementList.add(statement);
    try {
        return OBJECT_MAPPER.writeValueAsString(new Statements(statementList));
    } catch (JsonProcessingException jpe) {
        throw new ResultProcessingException("Could not create JSON due to " + jpe.getLocalizedMessage(), jpe);
    }
}
Also used : ResultProcessingException(org.neo4j.ogm.exception.ResultProcessingException) Statement(org.neo4j.ogm.request.Statement) ArrayList(java.util.ArrayList) Statements(org.neo4j.ogm.request.Statements) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException)

Example 4 with Statements

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

the class HttpRequest method execute.

@Override
public Response<RowModel> execute(DefaultRequest query) {
    Statements statements = new Statements(query.getStatements());
    String cypher = cypherRequest(statements);
    return new RowModelResponse(executeRequest(cypher));
}
Also used : RowModelResponse(org.neo4j.ogm.drivers.http.response.RowModelResponse) Statements(org.neo4j.ogm.request.Statements)

Aggregations

Statements (org.neo4j.ogm.request.Statements)4 ArrayList (java.util.ArrayList)2 Test (org.junit.Test)2 Statement (org.neo4j.ogm.request.Statement)2 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 Compiler (org.neo4j.ogm.cypher.compiler.Compiler)1 DefaultGraphModelRequest (org.neo4j.ogm.cypher.query.DefaultGraphModelRequest)1 PagingAndSortingQuery (org.neo4j.ogm.cypher.query.PagingAndSortingQuery)1 Student (org.neo4j.ogm.domain.education.Student)1 RowModelResponse (org.neo4j.ogm.drivers.http.response.RowModelResponse)1 ResultProcessingException (org.neo4j.ogm.exception.ResultProcessingException)1 RowStatementFactory (org.neo4j.ogm.session.request.RowStatementFactory)1