Search in sources :

Example 1 with OCommandExecutorScript

use of com.orientechnologies.orient.core.command.script.OCommandExecutorScript in project orientdb by orientechnologies.

the class OConsoleDatabaseApp method js.

@SuppressWarnings("unchecked")
@ConsoleCommand(splitInWords = false, description = "Execute javascript commands in the console")
public void js(@ConsoleParameter(name = "text", description = "The javascript to execute. Use 'db' to reference to a document database, 'gdb' for a graph database") final String iText) {
    if (iText == null)
        return;
    resetResultSet();
    long start = System.currentTimeMillis();
    while (true) {
        try {
            final OCommandExecutorScript cmd = new OCommandExecutorScript();
            cmd.parse(new OCommandScript("Javascript", iText));
            currentResult = cmd.execute(null);
            break;
        } catch (ORetryQueryException e) {
            continue;
        }
    }
    float elapsedSeconds = getElapsedSecs(start);
    parseResult();
    if (currentResultSet != null) {
        dumpResultSet(-1);
        message("\nClient side script executed in %f sec(s). Returned %d records", elapsedSeconds, currentResultSet.size());
    } else
        message("\nClient side script executed in %f sec(s). Value returned is: %s", elapsedSeconds, currentResult);
}
Also used : OCommandScript(com.orientechnologies.orient.core.command.script.OCommandScript) ORetryQueryException(com.orientechnologies.orient.core.exception.ORetryQueryException) OCommandExecutorScript(com.orientechnologies.orient.core.command.script.OCommandExecutorScript) ConsoleCommand(com.orientechnologies.common.console.annotation.ConsoleCommand)

Example 2 with OCommandExecutorScript

use of com.orientechnologies.orient.core.command.script.OCommandExecutorScript in project orientdb by orientechnologies.

the class OFunction method execute.

public Object execute(final Map<Object, Object> iArgs) {
    final long start = Orient.instance().getProfiler().startChrono();
    Object result;
    while (true) {
        try {
            if (callback != null)
                return callback.call(iArgs);
            final OCommandExecutorScript command = new OCommandExecutorScript();
            command.parse(new OCommandScript(getLanguage(), getCode()));
            result = command.execute(iArgs);
            break;
        } catch (ONeedRetryException e) {
            continue;
        } catch (ORetryQueryException e) {
            continue;
        }
    }
    if (Orient.instance().getProfiler().isRecording())
        Orient.instance().getProfiler().stopChrono("db." + ODatabaseRecordThreadLocal.INSTANCE.get().getName() + ".function.execute", "Time to execute a function", start, "db.*.function.execute");
    return result;
}
Also used : ONeedRetryException(com.orientechnologies.common.concur.ONeedRetryException) OCommandScript(com.orientechnologies.orient.core.command.script.OCommandScript) ORetryQueryException(com.orientechnologies.orient.core.exception.ORetryQueryException) OCommandExecutorScript(com.orientechnologies.orient.core.command.script.OCommandExecutorScript)

Aggregations

OCommandExecutorScript (com.orientechnologies.orient.core.command.script.OCommandExecutorScript)2 OCommandScript (com.orientechnologies.orient.core.command.script.OCommandScript)2 ORetryQueryException (com.orientechnologies.orient.core.exception.ORetryQueryException)2 ONeedRetryException (com.orientechnologies.common.concur.ONeedRetryException)1 ConsoleCommand (com.orientechnologies.common.console.annotation.ConsoleCommand)1