Search in sources :

Example 1 with ORetryQueryException

use of com.orientechnologies.orient.core.exception.ORetryQueryException 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 ORetryQueryException

use of com.orientechnologies.orient.core.exception.ORetryQueryException in project orientdb by orientechnologies.

the class OSQLCommandTask method execute.

public Object execute(ODistributedRequestId requestId, final OServer iServer, ODistributedServerManager iManager, final ODatabaseDocumentInternal database) throws Exception {
    if (ODistributedServerLog.isDebugEnabled())
        ODistributedServerLog.debug(this, iManager.getLocalNodeName(), getNodeSource(), DIRECTION.IN, "Execute command=%s db=%s", text.toString(), database.getName());
    Object res;
    while (true) {
        try {
            final OCommandRequest cmd = database.command(new OCommandSQL(text));
            OCommandExecutor executor = OCommandManager.instance().getExecutor((OCommandRequestInternal) cmd);
            executor.parse(cmd);
            final OCommandExecutor exec = executor instanceof OCommandExecutorSQLDelegate ? ((OCommandExecutorSQLDelegate) executor).getDelegate() : executor;
            if (exec instanceof OCommandExecutorSQLSelect && clusters.size() > 0) {
                // REWRITE THE TARGET TO USE CLUSTERS
                final StringBuilder buffer = new StringBuilder("cluster:[");
                int i = 0;
                for (String c : clusters) {
                    if (i++ > 0)
                        buffer.append(',');
                    buffer.append(c);
                }
                buffer.append("]");
                ((OCommandExecutorSQLSelect) exec).setParsedTarget(new OSQLTarget(buffer.toString(), exec.getContext()));
            }
            if (params != null)
                // EXECUTE WITH PARAMETERS
                res = executor.execute(params);
            else
                res = executor.execute(null);
            break;
        } catch (ORetryQueryException e) {
            continue;
        }
    }
    return res;
}
Also used : OCommandSQL(com.orientechnologies.orient.core.sql.OCommandSQL) OSQLTarget(com.orientechnologies.orient.core.sql.filter.OSQLTarget) OCommandExecutorSQLDelegate(com.orientechnologies.orient.core.sql.OCommandExecutorSQLDelegate) OCommandExecutorSQLSelect(com.orientechnologies.orient.core.sql.OCommandExecutorSQLSelect) ORetryQueryException(com.orientechnologies.orient.core.exception.ORetryQueryException)

Example 3 with ORetryQueryException

use of com.orientechnologies.orient.core.exception.ORetryQueryException 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

ORetryQueryException (com.orientechnologies.orient.core.exception.ORetryQueryException)3 OCommandExecutorScript (com.orientechnologies.orient.core.command.script.OCommandExecutorScript)2 OCommandScript (com.orientechnologies.orient.core.command.script.OCommandScript)2 ONeedRetryException (com.orientechnologies.common.concur.ONeedRetryException)1 ConsoleCommand (com.orientechnologies.common.console.annotation.ConsoleCommand)1 OCommandExecutorSQLDelegate (com.orientechnologies.orient.core.sql.OCommandExecutorSQLDelegate)1 OCommandExecutorSQLSelect (com.orientechnologies.orient.core.sql.OCommandExecutorSQLSelect)1 OCommandSQL (com.orientechnologies.orient.core.sql.OCommandSQL)1 OSQLTarget (com.orientechnologies.orient.core.sql.filter.OSQLTarget)1