use of org.neo4j.ogm.request.Statement 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);
}
use of org.neo4j.ogm.request.Statement 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.Statement in project neo4j-ogm by neo4j.
the class DeleteDelegate method getDeleteStatement.
private Statement getDeleteStatement(Object object, Long identity, ClassInfo classInfo) {
DeleteStatements deleteStatements = getDeleteStatementsBasedOnType(object.getClass());
Statement request;
if (classInfo.hasVersionField()) {
request = deleteStatements.delete(identity, object, classInfo);
} else {
request = deleteStatements.delete(identity);
}
return request;
}
use of org.neo4j.ogm.request.Statement in project neo4j-ogm by neo4j.
the class DeleteDelegate method purgeDatabase.
public void purgeDatabase() {
Statement stmt = new NodeDeleteStatements().deleteAll();
RowModelRequest query = new DefaultRowModelRequest(stmt.getStatement(), stmt.getParameters());
session.doInTransaction(() -> {
session.requestHandler().execute(query).close();
}, Transaction.Type.READ_WRITE);
session.context().clear();
}
use of org.neo4j.ogm.request.Statement in project neo4j-ogm by neo4j.
the class RequestExecutor method executeSave.
/**
* Execute a save request.
* Decides how the request is split depending upon characteristics of what is to be saved.
* Processes the response(s) and updates the mapping context.
*
* @param context the CompileContext for this request
*/
public void executeSave(CompileContext context) {
Compiler compiler = context.getCompiler();
compiler.useStatementFactory(new RowStatementFactory());
List<ReferenceMapping> entityReferenceMappings = new ArrayList<>();
List<ReferenceMapping> relReferenceMappings = new ArrayList<>();
boolean forceTx = compiler.updateNodesStatements().stream().anyMatch(st -> st.optimisticLockingConfig().isPresent()) || compiler.updateRelationshipStatements().stream().anyMatch(st -> st.optimisticLockingConfig().isPresent());
session.doInTransaction(() -> {
// we must create the new nodes first, and then use their node IDs when creating relationships between them
if (compiler.hasStatementsDependentOnNewNodes()) {
// execute the statements to create new nodes. The ids will be returned
// and will be used in subsequent statements that refer to these new nodes.
executeStatements(context, entityReferenceMappings, relReferenceMappings, compiler.createNodesStatements());
List<Statement> statements = new ArrayList<>();
statements.addAll(compiler.createRelationshipsStatements());
statements.addAll(compiler.updateNodesStatements());
statements.addAll(compiler.updateRelationshipStatements());
statements.addAll(compiler.deleteRelationshipStatements());
statements.addAll(compiler.deleteRelationshipEntityStatements());
executeStatements(context, entityReferenceMappings, relReferenceMappings, statements);
} else {
// only update / delete statements
List<Statement> statements = compiler.getAllStatements();
executeStatements(context, entityReferenceMappings, relReferenceMappings, statements);
}
}, forceTx, Transaction.Type.READ_WRITE);
// Update the mapping context now that the request is successful
updateNodeEntities(context, entityReferenceMappings);
updateRelationshipEntities(context, relReferenceMappings);
updateRelationships(context, relReferenceMappings);
}
Aggregations