Search in sources :

Example 1 with ExecutionEngine

use of org.neo4j.cypher.internal.javacompat.ExecutionEngine 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)

Example 2 with ExecutionEngine

use of org.neo4j.cypher.internal.javacompat.ExecutionEngine in project neo4j by neo4j.

the class CypherExecutorTest method setUpMocks.

private void setUpMocks() {
    database = mock(Database.class);
    databaseFacade = mock(GraphDatabaseFacade.class);
    resolver = mock(DependencyResolver.class);
    executionEngine = mock(ExecutionEngine.class);
    statementBridge = mock(ThreadToStatementContextBridge.class);
    databaseQueryService = mock(GraphDatabaseQueryService.class);
    kernelTransaction = mock(KernelTransaction.class);
    statement = mock(Statement.class);
    request = mock(HttpServletRequest.class);
    InternalTransaction transaction = new TopLevelTransaction(kernelTransaction, () -> statement);
    SecurityContext securityContext = AUTH_DISABLED;
    KernelTransaction.Type type = KernelTransaction.Type.implicit;
    QueryRegistryOperations registryOperations = mock(QueryRegistryOperations.class);
    when(statement.queryRegistration()).thenReturn(registryOperations);
    when(statementBridge.get()).thenReturn(statement);
    when(kernelTransaction.securityContext()).thenReturn(securityContext);
    when(kernelTransaction.transactionType()).thenReturn(type);
    when(database.getGraph()).thenReturn(databaseFacade);
    when(databaseFacade.getDependencyResolver()).thenReturn(resolver);
    when(resolver.resolveDependency(QueryExecutionEngine.class)).thenReturn(executionEngine);
    when(resolver.resolveDependency(ThreadToStatementContextBridge.class)).thenReturn(statementBridge);
    when(resolver.resolveDependency(GraphDatabaseQueryService.class)).thenReturn(databaseQueryService);
    when(databaseQueryService.beginTransaction(type, securityContext)).thenReturn(transaction);
    when(databaseQueryService.beginTransaction(type, securityContext, CUSTOM_TRANSACTION_TIMEOUT, TimeUnit.MILLISECONDS)).thenReturn(transaction);
    when(databaseQueryService.getDependencyResolver()).thenReturn(resolver);
    when(request.getScheme()).thenReturn("http");
    when(request.getRemoteAddr()).thenReturn("127.0.0.1");
    when(request.getRemotePort()).thenReturn(5678);
    when(request.getServerName()).thenReturn("127.0.0.1");
    when(request.getServerPort()).thenReturn(7474);
    when(request.getRequestURI()).thenReturn("/");
}
Also used : KernelTransaction(org.neo4j.kernel.api.KernelTransaction) GraphDatabaseQueryService(org.neo4j.kernel.GraphDatabaseQueryService) Statement(org.neo4j.kernel.api.Statement) QueryRegistryOperations(org.neo4j.kernel.api.QueryRegistryOperations) ThreadToStatementContextBridge(org.neo4j.kernel.impl.core.ThreadToStatementContextBridge) InternalTransaction(org.neo4j.kernel.impl.coreapi.InternalTransaction) TopLevelTransaction(org.neo4j.kernel.impl.coreapi.TopLevelTransaction) DependencyResolver(org.neo4j.graphdb.DependencyResolver) HttpServletRequest(javax.servlet.http.HttpServletRequest) QueryExecutionEngine(org.neo4j.kernel.impl.query.QueryExecutionEngine) ExecutionEngine(org.neo4j.cypher.internal.javacompat.ExecutionEngine) SecurityContext(org.neo4j.kernel.api.security.SecurityContext) GraphDatabaseFacade(org.neo4j.kernel.impl.factory.GraphDatabaseFacade)

Aggregations

ExecutionEngine (org.neo4j.cypher.internal.javacompat.ExecutionEngine)2 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 SyntaxException (org.neo4j.cypher.SyntaxException)1 DependencyResolver (org.neo4j.graphdb.DependencyResolver)1 Result (org.neo4j.graphdb.Result)1 GraphDatabaseQueryService (org.neo4j.kernel.GraphDatabaseQueryService)1 KernelTransaction (org.neo4j.kernel.api.KernelTransaction)1 QueryRegistryOperations (org.neo4j.kernel.api.QueryRegistryOperations)1 Statement (org.neo4j.kernel.api.Statement)1 SecurityContext (org.neo4j.kernel.api.security.SecurityContext)1 ThreadToStatementContextBridge (org.neo4j.kernel.impl.core.ThreadToStatementContextBridge)1 InternalTransaction (org.neo4j.kernel.impl.coreapi.InternalTransaction)1 TopLevelTransaction (org.neo4j.kernel.impl.coreapi.TopLevelTransaction)1 GraphDatabaseFacade (org.neo4j.kernel.impl.factory.GraphDatabaseFacade)1 QueryExecutionEngine (org.neo4j.kernel.impl.query.QueryExecutionEngine)1 TransactionalContext (org.neo4j.kernel.impl.query.TransactionalContext)1