use of org.neo4j.cypher.SyntaxException 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.cypher.SyntaxException in project neo4j by neo4j.
the class CypherSession method evaluate.
@Override
public Pair<String, String> evaluate(String script) {
if (StringUtils.EMPTY.equals(script.trim())) {
return Pair.of(StringUtils.EMPTY, null);
}
String resultString;
try {
TransactionalContext tc = cypherExecutor.createTransactionContext(script, emptyMap(), request);
ExecutionEngine engine = cypherExecutor.getExecutionEngine();
Result result = engine.executeQuery(script, emptyMap(), tc);
resultString = result.resultAsString();
} catch (SyntaxException error) {
resultString = error.getMessage();
} catch (Exception exception) {
log.error("Unknown error executing cypher query", exception);
resultString = "Error: " + exception.getClass().getSimpleName() + " - " + exception.getMessage();
}
return Pair.of(resultString, null);
}
Aggregations