use of org.neo4j.graphdb.Result in project neo4j by neo4j.
the class CausalClusteringProceduresIT method readReplicaProceduresShouldBeAvailable.
@Test
public void readReplicaProceduresShouldBeAvailable() throws Exception {
// given
String[] readReplicaProcs = new String[] { // Server role
"dbms.cluster.role", // Kernel built procedures
"dbms.procedures", // Built in procedure from enterprise
"dbms.listQueries" };
// when
for (String procedure : readReplicaProcs) {
Optional<ReadReplica> firstReadReplica = cluster.readReplicas().stream().findFirst();
assert firstReadReplica.isPresent();
ReadReplicaGraphDatabase database = firstReadReplica.get().database();
InternalTransaction tx = database.beginTransaction(KernelTransaction.Type.explicit, AUTH_DISABLED);
Result readReplicaResult = database.execute("CALL " + procedure + "()");
// then
assertTrue("read replica with procedure " + procedure, readReplicaResult.hasNext());
readReplicaResult.close();
tx.close();
}
}
use of org.neo4j.graphdb.Result in project neo4j by neo4j.
the class CausalClusteringProceduresIT method coreProceduresShouldBeAvailable.
@Test
public void coreProceduresShouldBeAvailable() throws Throwable {
String[] coreProcs = new String[] { // Server role
"dbms.cluster.role", // Discover the cluster topology
"dbms.cluster.routing.getServers", // Discover appropriate discovery service
"dbms.cluster.overview", // Kernel built procedures
"dbms.procedures", // Built in procedure from enterprise
"dbms.listQueries" };
for (String procedure : coreProcs) {
Optional<CoreClusterMember> firstCore = cluster.coreMembers().stream().findFirst();
assert firstCore.isPresent();
CoreGraphDatabase database = firstCore.get().database();
InternalTransaction tx = database.beginTransaction(KernelTransaction.Type.explicit, AUTH_DISABLED);
Result coreResult = database.execute("CALL " + procedure + "()");
assertTrue("core with procedure " + procedure, coreResult.hasNext());
coreResult.close();
tx.close();
}
}
use of org.neo4j.graphdb.Result in project neo4j by neo4j.
the class CypherService method cypher.
@POST
@SuppressWarnings({ "unchecked", "ParameterCanBeLocal" })
public Response cypher(String body, @Context HttpServletRequest request, @QueryParam(INCLUDE_STATS_PARAM) boolean includeStats, @QueryParam(INCLUDE_PLAN_PARAM) boolean includePlan, @QueryParam(PROFILE_PARAM) boolean profile) throws BadInputException {
usage.get(features).flag(http_cypher_endpoint);
Map<String, Object> command = input.readMap(body);
if (!command.containsKey(QUERY_KEY)) {
return output.badRequest(new InvalidArgumentsException("You have to provide the 'query' parameter."));
}
String query = (String) command.get(QUERY_KEY);
Map<String, Object> params;
try {
params = (Map<String, Object>) (command.containsKey(PARAMS_KEY) && command.get(PARAMS_KEY) != null ? command.get(PARAMS_KEY) : new HashMap<String, Object>());
} catch (ClassCastException e) {
return output.badRequest(new IllegalArgumentException("Parameters must be a JSON map"));
}
try {
QueryExecutionEngine executionEngine = cypherExecutor.getExecutionEngine();
boolean periodicCommitQuery = executionEngine.isPeriodicCommit(query);
CommitOnSuccessfulStatusCodeRepresentationWriteHandler handler = (CommitOnSuccessfulStatusCodeRepresentationWriteHandler) output.getRepresentationWriteHandler();
if (periodicCommitQuery) {
handler.closeTransaction();
}
TransactionalContext tc = cypherExecutor.createTransactionContext(query, params, request);
Result result;
if (profile) {
result = executionEngine.profileQuery(query, params, tc);
includePlan = true;
} else {
result = executionEngine.executeQuery(query, params, tc);
includePlan = result.getQueryExecutionType().requestedExecutionPlanDescription();
}
if (periodicCommitQuery) {
handler.setTransaction(database.beginTx());
}
return output.ok(new CypherResultRepresentation(result, includeStats, includePlan));
} catch (Throwable e) {
if (e.getCause() instanceof CypherException) {
return output.badRequest(e.getCause());
} else {
return output.badRequest(e);
}
}
}
use of org.neo4j.graphdb.Result in project neo4j by neo4j.
the class TransactionHandle method executeStatements.
private void executeStatements(StatementDeserializer statements, ExecutionResultSerializer output, List<Neo4jError> errors, HttpServletRequest request) {
try {
boolean hasPrevious = false;
while (statements.hasNext()) {
Statement statement = statements.next();
try {
boolean hasPeriodicCommit = engine.isPeriodicCommit(statement.statement());
if ((statements.hasNext() || hasPrevious) && hasPeriodicCommit) {
throw new QueryExecutionKernelException(new InvalidSemanticsException("Cannot execute another statement after executing " + "PERIODIC COMMIT statement in the same transaction"));
}
if (!hasPrevious && hasPeriodicCommit) {
context.closeTransactionForPeriodicCommit();
}
hasPrevious = true;
TransactionalContext tc = txManagerFacade.create(request, queryService, type, securityContext, statement.statement(), statement.parameters());
Result result = safelyExecute(statement, hasPeriodicCommit, tc);
output.statementResult(result, statement.includeStats(), statement.resultDataContents());
output.notifications(result.getNotifications());
} catch (KernelException | CypherException | AuthorizationViolationException | WriteOperationsNotAllowedException e) {
errors.add(new Neo4jError(e.status(), e));
break;
} catch (DeadlockDetectedException e) {
errors.add(new Neo4jError(Status.Transaction.DeadlockDetected, e));
} catch (IOException e) {
errors.add(new Neo4jError(Status.Network.CommunicationError, e));
break;
} catch (Exception e) {
Throwable cause = e.getCause();
if (cause instanceof Status.HasStatus) {
errors.add(new Neo4jError(((Status.HasStatus) cause).status(), cause));
} else {
errors.add(new Neo4jError(Status.Statement.ExecutionFailed, e));
}
break;
}
}
addToCollection(statements.errors(), errors);
} catch (Throwable e) {
errors.add(new Neo4jError(Status.General.UnknownError, e));
}
}
use of org.neo4j.graphdb.Result in project neo4j by neo4j.
the class EmbeddedBuiltInProceduresInteractionTest method shouldNotListAnyQueriesIfNotAuthenticated.
@Test
public void shouldNotListAnyQueriesIfNotAuthenticated() {
GraphDatabaseFacade graph = neo.getLocalGraph();
try (InternalTransaction tx = graph.beginTransaction(KernelTransaction.Type.explicit, AnonymousContext.none())) {
Result result = graph.execute(tx, "CALL dbms.listQueries", Collections.emptyMap());
assertFalse(result.hasNext());
tx.success();
}
}
Aggregations