public static Object convert(final Object iObject, final OCallable<Object, Object> iCallback) { return iCallback != null ? iCallback.call(iObject) : iObject; }
public static Object convert(final Object iObject, final OCallable<Object, Object> iCallback) { return iCallback != null ? iCallback.call(iObject) : iObject; }
public static Object executeWithRetries(final OCallable<Object, Integer> callback, final int maxRetry, final int waitBetweenRetry, final ORecord[] recordToReloadOnRetry) { ONeedRetryException lastException = null; for (int retry = 0; retry < maxRetry; ++retry) { try { return callback.call(retry); } catch (ONeedRetryException e) { // SAVE LAST EXCEPTION AND RETRY lastException = e; if (recordToReloadOnRetry != null) { // RELOAD THE RECORDS for (ORecord r : recordToReloadOnRetry) r.reload(); } if (waitBetweenRetry > 0) try { Thread.sleep(waitBetweenRetry); } catch (InterruptedException ignore) { Thread.currentThread().interrupt(); break; } } } throw lastException; }
public OCommandExecutor getExecutor(OCommandRequestInternal iCommand) { final Class<? extends OCommandExecutor> executorClass = commandReqExecMap.get(iCommand.getClass()); if (executorClass == null) throw new OCommandExecutorNotFoundException("Cannot find a command executor for the command request: " + iCommand); try { final OCommandExecutor exec = executorClass.newInstance(); final OCallable<Void, OCommandRequest> callback = configCallbacks.get(iCommand.getClass()); if (callback != null) callback.call(iCommand); return exec; } catch (Exception e) { throw OException.wrapException(new OCommandExecutionException( "Cannot create the command executor of class " + executorClass + " for the command request: " + iCommand), e); } } }
public <RET> RET execute(final OCallable<RET, OrientGraph> iCallable, final String... iOperationStrings) throws RuntimeException { makeActive(); if (OLogManager.instance().isWarnEnabled() && iOperationStrings.length > 0) { // COMPOSE THE MESSAGE final StringBuilder msg = new StringBuilder(256); for (String s : iOperationStrings) msg.append(s); // ASSURE PENDING TX IF ANY IS COMMITTED OLogManager.instance().warn(this, msg.toString()); } return iCallable.call(this); }
@Deprecated public Object executeInContext(final OCommandContext iContext, final Object... iArgs) { final List<String> params = getParameters(); // CONVERT PARAMETERS IN A MAP Map<Object, Object> args = null; if (iArgs.length > 0) { args = new LinkedHashMap<Object, Object>(); for (int i = 0; i < iArgs.length; ++i) { // final Object argValue = ORecordSerializerStringAbstract.getTypeValue(iArgs[i].toString()); final Object argValue = iArgs[i]; if (params != null && i < params.size()) args.put(params.get(i), argValue); else args.put("param" + i, argValue); } } if (callback != null) { // EXECUTE CALLBACK return callback.call(args); } // EXECUTE DB FUNCTION final OCommandExecutorFunction command = new OCommandExecutorFunction(); command.parse(new OCommandFunction(getName())); return command.executeInContext(iContext, args); }
@Deprecated public Object executeInContext(final OCommandContext iContext, final Map<String, Object> iArgs) { // CONVERT PARAMETERS IN A MAP final Map<Object, Object> args = new LinkedHashMap<Object, Object>(); if (iArgs.size() > 0) { // PRESERVE THE ORDER FOR PARAMETERS (ARE USED AS POSITIONAL) final List<String> params = getParameters(); for (String p : params) { args.put(p, iArgs.get(p)); } } if (callback != null) { // EXECUTE CALLBACK return callback.call(args); } // EXECUTE DB FUNCTION final OCommandExecutorFunction command = new OCommandExecutorFunction(); command.parse(new OCommandFunction(getName())); return command.executeInContext(iContext, args); }
public static Object foreachRecord(final OCallable<Object, OIdentifiable> iCallable, Object iCurrent, final OCommandContext iContext) { if (iCurrent == null) return null; if (!OCommandExecutorAbstract.checkInterruption(iContext)) return null; if (iCurrent instanceof Iterable && !(iCurrent instanceof OIdentifiable)) { iCurrent = ((Iterable) iCurrent).iterator(); } if (OMultiValue.isMultiValue(iCurrent) || iCurrent instanceof Iterator) { final OMultiCollectionIterator<Object> result = new OMultiCollectionIterator<Object>(); for (Object o : OMultiValue.getMultiValueIterable(iCurrent, false)) { if (iContext != null && !iContext.checkTimeout()) return null; if (OMultiValue.isMultiValue(o) || o instanceof Iterator) { for (Object inner : OMultiValue.getMultiValueIterable(o, false)) { result.add(iCallable.call((OIdentifiable) inner)); } } else result.add(iCallable.call((OIdentifiable) o)); } return result; } else if (iCurrent instanceof OIdentifiable) { return iCallable.call((OIdentifiable) iCurrent); } else if (iCurrent instanceof OResult) { return iCallable.call(((OResult) iCurrent).toElement()); } return null; }
protected void execInSeparateDatabase(final OCallable iCallback) { final ODatabaseDocumentInternal prevDb = ODatabaseRecordThreadLocal.instance().getIfDefined(); try { iCallback.call(null); } finally { if (prevDb != null) { ODatabaseRecordThreadLocal.instance().set(prevDb); } else { ODatabaseRecordThreadLocal.instance().remove(); } } }
protected void execInSeparateDatabase(final OCallable iCallback) { final ODatabaseDocumentInternal prevDb = ODatabaseRecordThreadLocal.instance().getIfDefined(); try { iCallback.call(null); } finally { if (prevDb != null) { ODatabaseRecordThreadLocal.instance().set(prevDb); } else { ODatabaseRecordThreadLocal.instance().remove(); } } }
dumpRecordInTable(fetched++, record, columns); if (iAfterDump != null) iAfterDump.call(record);
public <RET> RET executeOutsideTx(final OCallable<RET, OrientBaseGraph> iCallable, final String... iOperationStrings) throws RuntimeException { makeActive(); final int committed; final ODatabaseDocument raw = getRawGraph(); if (raw.getTransaction().isActive()) { if (isWarnOnForceClosingTx() && OLogManager.instance().isWarnEnabled() && iOperationStrings.length > 0) { // COMPOSE THE MESSAGE final StringBuilder msg = new StringBuilder(256); for (String s : iOperationStrings) msg.append(s); // ASSURE PENDING TX IF ANY IS COMMITTED OLogManager.instance().warn(this, "Requested command '%s' must be executed outside active transaction: the transaction will be committed and reopen right after it. To avoid this behavior execute it outside a transaction", msg.toString()); } committed = raw.getTransaction().amountOfNestedTxs(); raw.commit(true); } else committed = 0; try { return iCallable.call(this); } finally { if (this instanceof TransactionalGraph) { // RESTART TRANSACTION for (int i = 0; i < committed; ++i) this.begin(); } } }
@Deprecated 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 | ORetryQueryException ignore) { } } 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; }