Search in sources :

Example 1 with Continuation

use of org.neo4j.shell.Continuation in project neo4j by neo4j.

the class AbstractAppServer method interpretLine.

@Override
public Response interpretLine(Serializable clientId, String line, Output out) throws ShellException {
    Session session = getClientSession(clientId);
    if (line == null || line.trim().length() == 0) {
        return new Response(getPrompt(session), Continuation.INPUT_COMPLETE);
    }
    try {
        Continuation commandResult = null;
        for (String command : line.split(Pattern.quote("&&"))) {
            command = TextUtil.removeSpaces(command);
            command = replaceAlias(command, session);
            AppCommandParser parser = new AppCommandParser(this, command);
            commandResult = parser.app().execute(parser, session, out);
        }
        return new Response(getPrompt(session), commandResult);
    } catch (Exception e) {
        throw wrapException(e);
    }
}
Also used : Response(org.neo4j.shell.Response) Continuation(org.neo4j.shell.Continuation) AppCommandParser(org.neo4j.shell.AppCommandParser) RemoteException(java.rmi.RemoteException) ShellException(org.neo4j.shell.ShellException) Session(org.neo4j.shell.Session)

Example 2 with Continuation

use of org.neo4j.shell.Continuation in project neo4j by neo4j.

the class AbstractClient method evaluate.

@Override
public void evaluate(String line, Output out) throws ShellException {
    if (EXIT_COMMANDS.contains(line)) {
        end();
        return;
    }
    boolean success = false;
    try {
        String expandedLine = fullLine(line);
        Response response = getServer().interpretLine(id, expandedLine, out);
        Continuation continuation = response.getContinuation();
        switch(continuation) {
            case INPUT_COMPLETE:
                endMultiLine();
                break;
            case INPUT_INCOMPLETE:
                multiLine.add(line);
                break;
            case EXIT:
                getServer().leave(id);
                end();
                break;
            case EXCEPTION_CAUGHT:
                endMultiLine();
                break;
            default:
                throw new IllegalStateException("Unknown continuation: " + continuation);
        }
        prompt = response.getPrompt();
        success = true;
    } catch (RemoteException e) {
        throw ShellException.wrapCause(e);
    } finally {
        if (!success) {
            endMultiLine();
        }
    }
}
Also used : Response(org.neo4j.shell.Response) Continuation(org.neo4j.shell.Continuation) RemoteException(java.rmi.RemoteException)

Example 3 with Continuation

use of org.neo4j.shell.Continuation in project neo4j by neo4j.

the class TransactionProvidingApp method execute.

@Override
public Continuation execute(AppCommandParser parser, Session session, Output out) throws Exception {
    try (Transaction tx = getServer().getDb().beginTransaction(implicit, AUTH_DISABLED)) {
        getServer().registerTopLevelTransactionInProgress(session.getId());
        Continuation result = this.exec(parser, session, out);
        if (result == Continuation.EXCEPTION_CAUGHT) {
            tx.failure();
        } else {
            tx.success();
        }
        return result;
    }
}
Also used : Continuation(org.neo4j.shell.Continuation) Transaction(org.neo4j.graphdb.Transaction)

Aggregations

Continuation (org.neo4j.shell.Continuation)3 RemoteException (java.rmi.RemoteException)2 Response (org.neo4j.shell.Response)2 Transaction (org.neo4j.graphdb.Transaction)1 AppCommandParser (org.neo4j.shell.AppCommandParser)1 Session (org.neo4j.shell.Session)1 ShellException (org.neo4j.shell.ShellException)1