use of com.orientechnologies.orient.core.command.OCommandExecutorNotFoundException in project orientdb by orientechnologies.
the class OSQLFunctionRuntime method execute.
/**
* Execute a function.
*
* @param iCurrentRecord
* Current record
* @param iCurrentResult
* TODO
* @param iContext
* @return
*/
public Object execute(final Object iThis, final OIdentifiable iCurrentRecord, final Object iCurrentResult, final OCommandContext iContext) {
// RESOLVE VALUES USING THE CURRENT RECORD
for (int i = 0; i < configuredParameters.length; ++i) {
runtimeParameters[i] = configuredParameters[i];
if (configuredParameters[i] instanceof OSQLFilterItemField) {
runtimeParameters[i] = ((OSQLFilterItemField) configuredParameters[i]).getValue(iCurrentRecord, iCurrentResult, iContext);
} else if (configuredParameters[i] instanceof OSQLFunctionRuntime)
runtimeParameters[i] = ((OSQLFunctionRuntime) configuredParameters[i]).execute(iThis, iCurrentRecord, iCurrentResult, iContext);
else if (configuredParameters[i] instanceof OSQLFilterItemVariable) {
runtimeParameters[i] = ((OSQLFilterItemVariable) configuredParameters[i]).getValue(iCurrentRecord, iCurrentResult, iContext);
} else if (configuredParameters[i] instanceof OCommandSQL) {
try {
runtimeParameters[i] = ((OCommandSQL) configuredParameters[i]).setContext(iContext).execute();
} catch (OCommandExecutorNotFoundException e) {
// TRY WITH SIMPLE CONDITION
final String text = ((OCommandSQL) configuredParameters[i]).getText();
final OSQLPredicate pred = new OSQLPredicate(text);
runtimeParameters[i] = pred.evaluate(iCurrentRecord instanceof ORecord ? (ORecord) iCurrentRecord : null, (ODocument) iCurrentResult, iContext);
// REPLACE ORIGINAL PARAM
configuredParameters[i] = pred;
}
} else if (configuredParameters[i] instanceof OSQLPredicate)
runtimeParameters[i] = ((OSQLPredicate) configuredParameters[i]).evaluate(iCurrentRecord.getRecord(), (iCurrentRecord instanceof ODocument ? (ODocument) iCurrentResult : null), iContext);
else if (configuredParameters[i] instanceof String) {
if (configuredParameters[i].toString().startsWith("\"") || configuredParameters[i].toString().startsWith("'"))
runtimeParameters[i] = OIOUtils.getStringContent(configuredParameters[i]);
}
}
if (function.getMaxParams() == -1 || function.getMaxParams() > 0) {
if (runtimeParameters.length < function.getMinParams() || (function.getMaxParams() > -1 && runtimeParameters.length > function.getMaxParams()))
throw new OCommandExecutionException("Syntax error: function '" + function.getName() + "' needs " + (function.getMinParams() == function.getMaxParams() ? function.getMinParams() : function.getMinParams() + "-" + function.getMaxParams()) + " argument(s) while has been received " + runtimeParameters.length);
}
final Object functionResult = function.execute(iThis, iCurrentRecord, iCurrentResult, runtimeParameters, iContext);
if (functionResult instanceof OAutoConvertToRecord)
// FORCE AVOIDING TO CONVERT IN RECORD
((OAutoConvertToRecord) functionResult).setAutoConvertToRecord(false);
return transformValue(iCurrentRecord, iContext, functionResult);
}
use of com.orientechnologies.orient.core.command.OCommandExecutorNotFoundException in project orientdb by orientechnologies.
the class OCommandExecutorSQLDelegate method parse.
@SuppressWarnings("unchecked")
public OCommandExecutorSQLDelegate parse(final OCommandRequest iCommand) {
if (iCommand instanceof OCommandRequestText) {
final OCommandRequestText textRequest = (OCommandRequestText) iCommand;
final String text = textRequest.getText();
if (text == null)
throw new IllegalArgumentException("Command text is null");
final String textUpperCase = upperCase(text);
delegate = OSQLEngine.getInstance().getCommand(textUpperCase);
if (delegate == null)
throw new OCommandExecutorNotFoundException("Cannot find a command executor for the command request: " + iCommand);
delegate.setContext(context);
delegate.setLimit(iCommand.getLimit());
delegate.parse(iCommand);
delegate.setProgressListener(progressListener);
if (delegate.getFetchPlan() != null)
textRequest.setFetchPlan(delegate.getFetchPlan());
} else
throw new OCommandExecutionException("Cannot find a command executor for the command request: " + iCommand);
return this;
}
Aggregations