use of org.neo4j.kernel.impl.query.QueryExecutionKernelException in project neo4j by neo4j.
the class TransactionHandleTest method shouldLogMessageIfCypherSyntaxErrorOccurs.
@Test
public void shouldLogMessageIfCypherSyntaxErrorOccurs() throws Exception {
// given
TransitionalPeriodTransactionMessContainer kernel = mockKernel();
QueryExecutionEngine executionEngine = mock(QueryExecutionEngine.class);
TransactionalContext transactionalContext = prepareKernelWithQuerySession(kernel);
when(executionEngine.executeQuery("matsch (n) return n", map(), transactionalContext)).thenThrow(new QueryExecutionKernelException(new SyntaxException("did you mean MATCH?")));
TransactionRegistry registry = mock(TransactionRegistry.class);
when(registry.begin(any(TransactionHandle.class))).thenReturn(1337L);
GraphDatabaseQueryService queryService = mock(GraphDatabaseQueryService.class);
TransactionHandle handle = new TransactionHandle(kernel, executionEngine, queryService, registry, uriScheme, false, AUTH_DISABLED, anyLong(), NullLogProvider.getInstance());
ExecutionResultSerializer output = mock(ExecutionResultSerializer.class);
// when
Statement statement = new Statement("matsch (n) return n", map(), false, (ResultDataContent[]) null);
handle.commit(statements(statement), output, mock(HttpServletRequest.class));
// then
verify(registry).forget(1337L);
InOrder outputOrder = inOrder(output);
outputOrder.verify(output).errors(argThat(hasErrors(Status.Statement.SyntaxError)));
outputOrder.verify(output).finish();
verifyNoMoreInteractions(output);
}
use of org.neo4j.kernel.impl.query.QueryExecutionKernelException 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.kernel.impl.query.QueryExecutionKernelException in project neo4j by neo4j.
the class TestFabricTransaction method execute.
@Override
public Result execute(String query, Map<String, Object> parameters) throws QueryExecutionException {
var ctx = new TestFabricTransactionalContext(kernelInternalTransaction);
var params = ValueUtils.asParameterMapValue(parameters);
var result = new ResultSubscriber(ctx, ctx.valueMapper());
try {
BoltQueryExecution boltQueryExecution = fabricTransaction.executeQuery(query, params, false, result);
result.init(boltQueryExecution.getQueryExecution());
} catch (FabricException e) {
if (e.getCause() instanceof RuntimeException) {
throw (RuntimeException) e.getCause();
} else {
throw new QueryExecutionException(e.getMessage(), e, e.status().code().serialize());
}
} catch (QueryExecutionKernelException | Neo4jException e) {
throw new QueryExecutionException(e.getMessage(), e, e.status().code().serialize());
}
return result;
}
use of org.neo4j.kernel.impl.query.QueryExecutionKernelException in project neo4j by neo4j.
the class SnapshotExecutionEngine method executeWithRetries.
protected MaterialisedResult executeWithRetries(String query, TransactionalContext context, QueryExecutor executor) throws QueryExecutionKernelException {
VersionContext versionContext = getCursorContext(context);
MaterialisedResult materialisedResult;
int attempt = 0;
boolean dirtySnapshot;
do {
if (attempt == maxQueryExecutionAttempts) {
throw new QueryExecutionKernelException(new UnstableSnapshotException("Unable to get clean data snapshot for query '%s' after %d attempts.", query, attempt));
}
if (attempt > 0) {
context.executingQuery().onRetryAttempted();
}
attempt++;
versionContext.initRead();
materialisedResult = new MaterialisedResult();
QueryExecution queryExecution = executor.execute(materialisedResult);
materialisedResult.consumeAll(queryExecution);
// objects is guaranteed by schema and not by execution engine
if (context.transaction().kernelTransaction().isSchemaTransaction()) {
return materialisedResult;
}
dirtySnapshot = versionContext.isDirty();
if (isUnstableSnapshot(materialisedResult, dirtySnapshot)) {
throw new QueryExecutionKernelException(new UnstableSnapshotException("Unable to get clean data snapshot for query '%s' that performs updates.", query, attempt));
}
} while (dirtySnapshot);
return materialisedResult;
}
use of org.neo4j.kernel.impl.query.QueryExecutionKernelException in project neo4j by neo4j.
the class SnapshotExecutionEngine method executeQuery.
@Override
public Result executeQuery(String query, MapValue parameters, TransactionalContext context, boolean prePopulate) throws QueryExecutionKernelException {
QueryExecutor queryExecutor = querySubscriber -> super.executeQuery(query, parameters, context, prePopulate, querySubscriber);
ResultSubscriber resultSubscriber = new ResultSubscriber(context);
MaterialisedResult materialisedResult = executeWithRetries(query, context, queryExecutor);
QueryExecution queryExecution = materialisedResult.stream(resultSubscriber);
resultSubscriber.init(queryExecution);
return resultSubscriber;
}
Aggregations