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();
}
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}]}");
}
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);
}
}
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));
}
Aggregations