core/src/main/java/com/orientechnologies/orient/core/sql/method/OSQLMethodRuntime.java
public Object execute(final Object iThis, final OIdentifiable iCurrentRecord, final Object iCurrentResult,
      final OCommandContext iContext) {
    if (iThis == null)
      return null;

    if (configuredParameters != null) {
      // RESOLVE VALUES USING THE CURRENT RECORD
      for (int i = 0; i < configuredParameters.length; ++i) {
        runtimeParameters[i] = configuredParameters[i];

        if (method.evaluateParameters()) {
          if (configuredParameters[i] instanceof OSQLFilterItemField) {
            runtimeParameters[i] = ((OSQLFilterItemField) configuredParameters[i]).getValue(iCurrentRecord, iCurrentResult,
                iContext);
            if (runtimeParameters[i] == null && iCurrentResult instanceof OIdentifiable)
              // LOOK INTO THE CURRENT RESULT
              runtimeParameters[i] = ((OSQLFilterItemField) configuredParameters[i]).getValue((OIdentifiable) iCurrentResult,
                  iCurrentResult, iContext);
          } else if (configuredParameters[i] instanceof OSQLMethodRuntime)
            runtimeParameters[i] = ((OSQLMethodRuntime) configuredParameters[i]).execute(iThis, iCurrentRecord, iCurrentResult,
                iContext);
          else if (configuredParameters[i] instanceof OSQLFunctionRuntime)
            runtimeParameters[i] = ((OSQLFunctionRuntime) configuredParameters[i]).execute(iCurrentRecord, iCurrentRecord, iCurrentResult,
                iContext);
          else if (configuredParameters[i] instanceof OSQLFilterItemVariable) {
            runtimeParameters[i] = ((OSQLFilterItemVariable) configuredParameters[i]).getValue(iCurrentRecord, iCurrentResult,
                iContext);
            if (runtimeParameters[i] == null && iCurrentResult instanceof OIdentifiable)
              // LOOK INTO THE CURRENT RESULT
              runtimeParameters[i] = ((OSQLFilterItemVariable) configuredParameters[i]).getValue((OIdentifiable) iCurrentResult,
                  iCurrentResult, iContext);
          } else if (configuredParameters[i] instanceof OCommandSQL) {
            try {
              runtimeParameters[i] = ((OCommandSQL) configuredParameters[i]).setContext(iContext).execute();
            } catch (OCommandExecutorNotFoundException ignore) {
              // 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 (method.getMaxParams() == -1 || method.getMaxParams() > 0) {
        if (runtimeParameters.length < method.getMinParams()
            || (method.getMaxParams() > -1 && runtimeParameters.length > method.getMaxParams()))
          throw new OCommandExecutionException("Syntax error: function '"
              + method.getName()
              + "' needs "
              + (method.getMinParams() == method.getMaxParams() ? method.getMinParams() : method.getMinParams() + "-"
                  + method.getMaxParams()) + " argument(s) while has been received " + runtimeParameters.length);
      }
    }

    final Object functionResult = method.execute(iThis, iCurrentRecord, iContext, iCurrentResult, runtimeParameters);

    return transformValue(iCurrentRecord, iContext, functionResult);
  }
public Object execute(final Object iThis, final OIdentifiable iCurrentRecord, final Object iCurrentResult,
      final OCommandContext iContext) {
    if (iThis == null)
      return null;

    if (configuredParameters != null) {
      // RESOLVE VALUES USING THE CURRENT RECORD
      for (int i = 0; i < configuredParameters.length; ++i) {
        runtimeParameters[i] = configuredParameters[i];

        if (method.evaluateParameters()) {
          if (configuredParameters[i] instanceof OSQLFilterItemField) {
            runtimeParameters[i] = ((OSQLFilterItemField) configuredParameters[i]).getValue(iCurrentRecord, iCurrentResult,
                iContext);
            if (runtimeParameters[i] == null && iCurrentResult instanceof OIdentifiable)
              // LOOK INTO THE CURRENT RESULT
              runtimeParameters[i] = ((OSQLFilterItemField) configuredParameters[i]).getValue((OIdentifiable) iCurrentResult,
                  iCurrentResult, iContext);
          } else if (configuredParameters[i] instanceof OSQLMethodRuntime)
            runtimeParameters[i] = ((OSQLMethodRuntime) configuredParameters[i]).execute(iThis, iCurrentRecord, iCurrentResult,
                iContext);
          else if (configuredParameters[i] instanceof OSQLFunctionRuntime)
            runtimeParameters[i] = ((OSQLFunctionRuntime) configuredParameters[i]).execute(iCurrentRecord, iCurrentRecord, iCurrentResult,
                iContext);
          else if (configuredParameters[i] instanceof OSQLFilterItemVariable) {
            runtimeParameters[i] = ((OSQLFilterItemVariable) configuredParameters[i]).getValue(iCurrentRecord, iCurrentResult,
                iContext);
            if (runtimeParameters[i] == null && iCurrentResult instanceof OIdentifiable)
              // LOOK INTO THE CURRENT RESULT
              runtimeParameters[i] = ((OSQLFilterItemVariable) configuredParameters[i]).getValue((OIdentifiable) iCurrentResult,
                  iCurrentResult, iContext);
          } else if (configuredParameters[i] instanceof OCommandSQL) {
            try {
              runtimeParameters[i] = ((OCommandSQL) configuredParameters[i]).setContext(iContext).execute();
            } catch (OCommandExecutorNotFoundException ignore) {
              // 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 (method.getMaxParams() == -1 || method.getMaxParams() > 0) {
        if (runtimeParameters.length < method.getMinParams()
            || (method.getMaxParams() > -1 && runtimeParameters.length > method.getMaxParams()))
          throw new OCommandExecutionException("Syntax error: function '"
              + method.getName()
              + "' needs "
              + (method.getMinParams() == method.getMaxParams() ? method.getMinParams() : method.getMinParams() + "-"
                  + method.getMaxParams()) + " argument(s) while has been received " + runtimeParameters.length);
      }
    }

    final Object functionResult = method.execute(iThis, iCurrentRecord, iContext, iCurrentResult, runtimeParameters);

    return transformValue(iCurrentRecord, iContext, functionResult);
  }
public Object execute ( final Object iThis , final OIdentifiable iCurrentRecord , final Object iCurrentResult , final OCommandContext iContext ) { if ( iThis == null ) return null ; if ( configuredParameters != null ) { // RESOLVE VALUES USING THE CURRENT RECORD for ( int i = 0 ; i < configuredParameters . length ; ++ i ) { runtimeParameters [ i ] = configuredParameters [ i ] ; if ( method . evaluateParameters ( ) ) { if ( configuredParameters [ i ] instanceof OSQLFilterItemField ) { runtimeParameters [ i ] = ( ( OSQLFilterItemField ) configuredParameters [ i ] ) . getValue ( iCurrentRecord , iCurrentResult , iContext ) ; if ( runtimeParameters [ i ] == null && iCurrentResult instanceof OIdentifiable ) // LOOK INTO THE CURRENT RESULT runtimeParameters [ i ] = ( ( OSQLFilterItemField ) configuredParameters [ i ] ) . getValue ( ( OIdentifiable ) iCurrentResult , iCurrentResult , iContext ) ; } else if ( configuredParameters [ i ] instanceof OSQLMethodRuntime ) runtimeParameters [ i ] = ( ( OSQLMethodRuntime ) configuredParameters [ i ] ) . execute ( iThis , iCurrentRecord , iCurrentResult , iContext ) ; else if ( configuredParameters [ i ] instanceof OSQLFunctionRuntime ) runtimeParameters [ i ] = ( ( OSQLFunctionRuntime ) configuredParameters [ i ] ) . execute ( iCurrentRecord , iCurrentRecord , iCurrentResult , iContext ) ; else if ( configuredParameters [ i ] instanceof OSQLFilterItemVariable ) { runtimeParameters [ i ] = ( ( OSQLFilterItemVariable ) configuredParameters [ i ] ) . getValue ( iCurrentRecord , iCurrentResult , iContext ) ; if ( runtimeParameters [ i ] == null && iCurrentResult instanceof OIdentifiable ) // LOOK INTO THE CURRENT RESULT runtimeParameters [ i ] = ( ( OSQLFilterItemVariable ) configuredParameters [ i ] ) . getValue ( ( OIdentifiable ) iCurrentResult , iCurrentResult , iContext ) ; } else if ( configuredParameters [ i ] instanceof OCommandSQL ) { try { runtimeParameters [ i ] = ( ( OCommandSQL ) configuredParameters [ i ] ) . setContext ( iContext ) . execute ( ) ; } catch ( OCommandExecutorNotFoundException ignore ) { // 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 ( method . getMaxParams ( ) == - 1 || method . getMaxParams ( ) > 0 ) { if ( runtimeParameters . length < method . getMinParams ( ) || ( method . getMaxParams ( ) > - 1 && runtimeParameters . length > method . getMaxParams ( ) ) ) throw new OCommandExecutionException ( "Syntax error: function '" + method . getName ( ) + "' needs " + ( method . getMinParams ( ) == method . getMaxParams ( ) ? method . getMinParams ( ) : method . getMinParams ( ) + "-" + method . getMaxParams ( ) ) + " argument(s) while has been received " + runtimeParameters . length ) ; } } final Object functionResult = method . execute ( iThis , iCurrentRecord , iContext , iCurrentResult , runtimeParameters ) ; return transformValue ( iCurrentRecord , iContext , functionResult ) ; }
Execute a method.

@param iCurrentRecord
Current record
@param iCurrentResult
TODO
@param iContext
@return
Execute a method .