Search in sources :

Example 1 with SyntaxException

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);
}
Also used : QueryExecutionKernelException(org.neo4j.kernel.impl.query.QueryExecutionKernelException) InOrder(org.mockito.InOrder) GraphDatabaseQueryService(org.neo4j.kernel.GraphDatabaseQueryService) QueryExecutionEngine(org.neo4j.kernel.impl.query.QueryExecutionEngine) HttpServletRequest(javax.servlet.http.HttpServletRequest) SyntaxException(org.neo4j.cypher.SyntaxException) TransactionalContext(org.neo4j.kernel.impl.query.TransactionalContext) Test(org.junit.Test)

Example 2 with SyntaxException

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);
}
Also used : ExecutionEngine(org.neo4j.cypher.internal.javacompat.ExecutionEngine) SyntaxException(org.neo4j.cypher.SyntaxException) TransactionalContext(org.neo4j.kernel.impl.query.TransactionalContext) SyntaxException(org.neo4j.cypher.SyntaxException) Result(org.neo4j.graphdb.Result)

Aggregations

SyntaxException (org.neo4j.cypher.SyntaxException)2 TransactionalContext (org.neo4j.kernel.impl.query.TransactionalContext)2 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 Test (org.junit.Test)1 InOrder (org.mockito.InOrder)1 ExecutionEngine (org.neo4j.cypher.internal.javacompat.ExecutionEngine)1 Result (org.neo4j.graphdb.Result)1 GraphDatabaseQueryService (org.neo4j.kernel.GraphDatabaseQueryService)1 QueryExecutionEngine (org.neo4j.kernel.impl.query.QueryExecutionEngine)1 QueryExecutionKernelException (org.neo4j.kernel.impl.query.QueryExecutionKernelException)1