Examples of LocalField


Examples of org.apache.derby.iapi.services.compiler.LocalField

      // application could retain a reference to it and corrupt
      // future calls with the same CallableStatement object.

      String methodParameterType = methodParameterTypes[parameterNumber];
      String arrayType = methodParameterType.substring(0, methodParameterType.length() - 2);
      LocalField lf = acb.newFieldDeclaration(Modifier.PRIVATE, methodParameterType);

      if (outParamArrays == null)
        outParamArrays = new LocalField[methodParms.length];

      outParamArrays[parameterNumber] = lf;
View Full Code Here

Examples of org.apache.derby.iapi.services.compiler.LocalField

      mb.pushThis();
    }

    int nargs = generateParameters(acb, mb);

    LocalField functionEntrySQLAllowed = null;

    if (routineInfo != null) {

      short sqlAllowed = routineInfo.getSQLAllowed();

      // Before we set up our authorization level, add a check to see if this
      // method can be called. If the routine is NO SQL or CONTAINS SQL
      // then there is no need for a check. As follows:
      //
      // Current Level = NO_SQL - CALL will be rejected when getting CALL result set
      // Current Level = anything else - calls to procedures defined as NO_SQL and CONTAINS SQL both allowed.


      if (sqlAllowed != RoutineAliasInfo.NO_SQL)
      {
       
        int sqlOperation;
       
        if (sqlAllowed == RoutineAliasInfo.READS_SQL_DATA)
          sqlOperation = Authorizer.SQL_SELECT_OP;
        else if (sqlAllowed == RoutineAliasInfo.MODIFIES_SQL_DATA)
          sqlOperation = Authorizer.SQL_WRITE_OP;
        else
          sqlOperation = Authorizer.SQL_ARBITARY_OP;
       
        generateAuthorizeCheck((ActivationClassBuilder) acb, mb, sqlOperation);
      }

      int statmentContextReferences = isSystemCode ? 2 : 1;
     
      boolean isFunction = routineInfo.getReturnType() != null;

      if (isFunction)
        statmentContextReferences++;


      if (statmentContextReferences != 0) {
        acb.pushThisAsActivation(mb);
        mb.callMethod(VMOpcode.INVOKEINTERFACE, null,
                  "getLanguageConnectionContext", ClassName.LanguageConnectionContext, 0);
        mb.callMethod(VMOpcode.INVOKEINTERFACE, null,
                  "getStatementContext", "org.apache.derby.iapi.sql.conn.StatementContext", 0);

        for (int scc = 1; scc < statmentContextReferences; scc++)
          mb.dup();
      }

      /**
        Set the statement context to reflect we are running
        System procedures, so that we can execute non-standard SQL.
      */
      if (isSystemCode) {
        mb.callMethod(VMOpcode.INVOKEINTERFACE, null,
                  "setSystemCode", "void", 0);
      }

      // for a function we need to fetch the current SQL control
      // so that we can reset it once the function is complete.
      //
      if (isFunction)
      {
        functionEntrySQLAllowed = acb.newFieldDeclaration(Modifier.PRIVATE, "short");
        mb.callMethod(VMOpcode.INVOKEINTERFACE, null,
                  "getSQLAllowed", "short", 0);
        mb.setField(functionEntrySQLAllowed);

      }
     
     
      // Set up the statement context to reflect the
      // restricted SQL execution allowed by this routine.

      mb.push(sqlAllowed);
      mb.push(false);
      mb.callMethod(VMOpcode.INVOKEINTERFACE, null,
                "setSQLAllowed", "void", 2);

    }

    // add in the ResultSet arrays.
    if (routineInfo != null) {

      int compiledResultSets = methodParameterTypes.length - methodParms.length;

      if (compiledResultSets != 0) {

        // Add a method that indicates the maxium number of dynamic result sets.
        int maxDynamicResults = routineInfo.getMaxDynamicResultSets();
        if (maxDynamicResults > 0) {
          MethodBuilder gdr = acb.getClassBuilder().newMethodBuilder(Modifier.PUBLIC, "int", "getMaxDynamicResults");
          gdr.push(maxDynamicResults);
          gdr.methodReturn();
          gdr.complete();
        }

        // add a method to return all the dynamic result sets (unordered)
        MethodBuilder gdr = acb.getClassBuilder().newMethodBuilder(Modifier.PUBLIC, "java.sql.ResultSet[][]", "getDynamicResults");

        MethodBuilder cons = acb.getConstructor();
        // if (procDef.getParameterStyle() == RoutineAliasInfo.PS_JAVA)
        {
          // PARAMETER STYLE JAVA

          LocalField procedureResultSetsHolder = acb.newFieldDeclaration(Modifier.PRIVATE, "java.sql.ResultSet[][]");

          // getDynamicResults body
          gdr.getField(procedureResultSetsHolder);

          // create the holder of all the ResultSet arrays, new java.sql.ResultSet[][compiledResultSets]
          cons.pushNewArray("java.sql.ResultSet[]", compiledResultSets);
          cons.setField(procedureResultSetsHolder);


          // arguments for the dynamic result sets
          for (int i = 0; i < compiledResultSets; i++) {

            mb.pushNewArray("java.sql.ResultSet", 1);
            mb.dup();

            mb.getField(procedureResultSetsHolder);
            mb.swap();

            mb.setArrayElement(i);
          }
        }

        // complete the method that returns the ResultSet[][] to the
        gdr.methodReturn();
        gdr.complete();

        nargs += compiledResultSets;
      }

    }

    String javaReturnType = getJavaTypeName();

    MethodBuilder mbnc = null;
    MethodBuilder mbcm = mb;


    // If any of the parameters are null then
    // do not call the method, just return null.
    if (returnsNullOnNullState != null)
    {
      mbnc = acb.newGeneratedFun(javaReturnType, Modifier.PRIVATE, methodParameterTypes);

      // add the throws clause for the public static method we are going to call.
      Class[] throwsSet = ((java.lang.reflect.Method) method).getExceptionTypes();
      for (int te = 0; te < throwsSet.length; te++)
      {
        mbnc.addThrownException(throwsSet[te].getName());
      }

      mbnc.getField(returnsNullOnNullState);
      mbnc.conditionalIf();

      // set up for a null!!
      // for objects is easy.
      mbnc.pushNull(javaReturnType);

      mbnc.startElseCode()

      if (!actualMethodReturnType.equals(javaReturnType))
        mbnc.pushNewStart(javaReturnType);

      // fetch all the arguments
      for (int pa = 0; pa < nargs; pa++)
      {
        mbnc.getParameter(pa);
      }

      mbcm = mbnc;
    }

    mbcm.callMethod(VMOpcode.INVOKESTATIC, method.getDeclaringClass().getName(), methodName,
          actualMethodReturnType, nargs);


    if (returnsNullOnNullState != null)
    {
      if (!actualMethodReturnType.equals(javaReturnType))
        mbnc.pushNewComplete(1);

      mbnc.completeConditional();

      mbnc.methodReturn();
      mbnc.complete();

      // now call the wrapper method
      mb.callMethod(VMOpcode.INVOKEVIRTUAL, acb.getClassBuilder().getFullName(), mbnc.getName(),
          javaReturnType, nargs);
      mbnc = null;
    }


    if (routineInfo != null) {

      // reset the SQL allowed setting that we set upon
      // entry to the method.
      if (functionEntrySQLAllowed != null) {
        acb.pushThisAsActivation(mb);
        mb.callMethod(VMOpcode.INVOKEINTERFACE, null,
                  "getLanguageConnectionContext", ClassName.LanguageConnectionContext, 0);
        mb.callMethod(VMOpcode.INVOKEINTERFACE, null,
                  "getStatementContext", "org.apache.derby.iapi.sql.conn.StatementContext", 0);
        mb.getField(functionEntrySQLAllowed);
        mb.push(true); // override as we are ending the control set by this function all.
        mb.callMethod(VMOpcode.INVOKEINTERFACE, null,
                  "setSQLAllowed", "void", 2);

      }

      if (outParamArrays != null) {

        MethodBuilder constructor = acb.getConstructor();

        // constructor  - setting up correct paramter type info
        acb.pushThisAsActivation(constructor);
        constructor.callMethod(VMOpcode.INVOKEINTERFACE, null,
                  "getParameterValueSet", ClassName.ParameterValueSet, 0);

        // execute  - passing out parameters back.
        acb.pushThisAsActivation(mb);
        mb.callMethod(VMOpcode.INVOKEINTERFACE, null,
                  "getParameterValueSet", ClassName.ParameterValueSet, 0);

        int[] parameterModes = routineInfo.getParameterModes();
        for (int i = 0; i < outParamArrays.length; i++) {

          int parameterMode = parameterModes[i];
          if (parameterMode != JDBC30Translation.PARAMETER_MODE_IN) {

            // must be a parameter if it is INOUT or OUT.
            ValueNode sqlParamNode = ((SQLToJavaValueNode) methodParms[i]).getSQLValueNode();


            int applicationParameterNumber = applicationParameterNumbers[i];

            // Set the correct parameter nodes in the ParameterValueSet at constructor time.
            constructor.dup();
            constructor.push(applicationParameterNumber);
            constructor.push(parameterMode);
            constructor.callMethod(VMOpcode.INVOKEINTERFACE, null,
                    "setParameterMode", "void", 2);

            // Pass the value of the outparameters back to the calling code
            LocalField lf = outParamArrays[i];

            mb.dup();
            mb.push(applicationParameterNumber);
            mb.callMethod(VMOpcode.INVOKEINTERFACE, null,
                  "getParameter", ClassName.DataValueDescriptor, 1);
View Full Code Here

Examples of org.apache.derby.iapi.services.compiler.LocalField

    int      argumentsListSize = argumentsList.size();
    String    receiverType = ClassName.DataValueDescriptor;
    String    argumentsListInterfaceType = ClassName.DataValueDescriptor + "[]";

    // Generate the code to build the array
    LocalField arrayField =
      acb.newFieldDeclaration(Modifier.PRIVATE, argumentsListInterfaceType);

    /* The array gets created in the constructor.
     * All constant elements in the array are initialized
     * in the constructor. 
     */
    /* Assign the initializer to the DataValueDescriptor[] field */
    MethodBuilder cb = acb.getConstructor();
    cb.pushNewArray(ClassName.DataValueDescriptor, argumentsListSize);
    cb.setField(arrayField);

    /* Set the array elements that are constant */
    int numConstants = 0;
    MethodBuilder nonConstantMethod = null;
    MethodBuilder currentConstMethod = cb;
    for (int index = 0; index < argumentsListSize; index++)
    {
      MethodBuilder setArrayMethod;
 
      if (argumentsList.elementAt(index) instanceof ConstantNode)
      {
        numConstants++;
   
        /*if too many statements are added  to a  method,
        *size of method can hit  65k limit, which will
        *lead to the class format errors at load time.
        *To avoid this problem, when number of statements added
        *to a method is > 2048, remaing statements are added to  a new function
        *and called from the function which created the function.
        *See Beetle 5135 or 4293 for further details on this type of problem.
        */
        if(currentConstMethod.statementNumHitLimit(1))
        {
          MethodBuilder genConstantMethod = acb.newGeneratedFun("void", Modifier.PRIVATE);
          currentConstMethod.pushThis();
          currentConstMethod.callMethod(VMOpcode.INVOKEVIRTUAL,
                          (String) null,
                          genConstantMethod.getName(),
                          "void", 0);
          //if it is a generate function, close the metod.
          if(currentConstMethod != cb){
            currentConstMethod.methodReturn();
            currentConstMethod.complete();
          }
          currentConstMethod = genConstantMethod;
        }
        setArrayMethod = currentConstMethod;
      } else {
        if (nonConstantMethod == null)
          nonConstantMethod = acb.newGeneratedFun("void", Modifier.PROTECTED);
        setArrayMethod = nonConstantMethod;

      }

      setArrayMethod.getField(arrayField);
      ((ValueNode) argumentsList.elementAt(index)).generateExpression(acb, setArrayMethod);
      setArrayMethod.upCast(receiverType);
      setArrayMethod.setArrayElement(index);
    }

    //if a generated function was created to reduce the size of the methods close the functions.
    if(currentConstMethod != cb){
      currentConstMethod.methodReturn();
      currentConstMethod.complete();
    }

    if (nonConstantMethod != null) {
      nonConstantMethod.methodReturn();
      nonConstantMethod.complete();
      mb.pushThis();
      mb.callMethod(VMOpcode.INVOKEVIRTUAL, (String) null, nonConstantMethod.getName(), "void", 0);
    }

    /*
    **  Call the method for coalesce/value function.
    **  First generate following
    **  <first non-param argument in the list>.method(<all the arguments>, <resultType>)
    **  Next, if we are dealing with result type that is variable length, then generate a call to setWidth.
    */

    firstNonParameterNode.generateExpression(acb, mb); //coalesce will be called on this non-parameter argument
    mb.upCast(ClassName.DataValueDescriptor);

    mb.getField(arrayField); // first arg to the coalesce function

    //Following is for the second arg. This arg will be used to pass the return value.
    //COALESCE method expects this to be initialized to NULL SQLxxx type object.
    LocalField field = acb.newFieldDeclaration(Modifier.PRIVATE, receiverType);
    acb.generateNull(mb, getTypeCompiler(), getTypeServices().getCollationType());
    mb.upCast(ClassName.DataValueDescriptor);
    mb.putField(field);

    mb.callMethod(VMOpcode.INVOKEINTERFACE, receiverType, "coalesce", receiverType, 2);
View Full Code Here

Examples of org.apache.derby.iapi.services.compiler.LocalField

    /* If this node is for an ungrouped aggregator,
     * then we generate a conditional
     * wrapper so that we only new the aggregator once.
     *    (fx == null) ? fx = new ... : fx
     */
    LocalField objectFieldLF = null;
    if (singleInstantiation)
    {
      /* Declare the field */
      objectFieldLF = acb.newFieldDeclaration(Modifier.PRIVATE, javaClassName);

View Full Code Here

Examples of org.apache.derby.iapi.services.compiler.LocalField

  {
    int nargs = 0;
    String receiverType = null;

    /* Allocate an object for re-use to hold the result of the operator */
    LocalField field = acb.newFieldDeclaration(Modifier.PRIVATE, resultInterfaceType);

    receiver.generateExpression(acb, mb);
    if (operatorType == TRIM)
    {
      mb.push(trimType);
View Full Code Here

Examples of org.apache.derby.iapi.services.compiler.LocalField

    {
      /* This sets up the method and the static field */
      MethodBuilder exprFun = acb.newExprFun();

      /* Now we fill in the body of the method */
      LocalField rowField =
                generateIndexableRow(acb, numberOfStopPredicates);

      int  colNum = 0;
      int size = size();
      for (int index = 0; index < size; index++)
View Full Code Here

Examples of org.apache.derby.iapi.services.compiler.LocalField

    String                  retvalType  = ClassName.Qualifier + "[][]";
    MethodBuilder           consMB      = acb.getConstructor();
    MethodBuilder           executeMB   = acb.getExecuteMethod();

    /* Create and initialize the array of Qualifiers */
    LocalField qualField =
            acb.newFieldDeclaration(Modifier.PRIVATE, retvalType);


    /*
    ** Stick a reinitialize of the Qualifier array in execute().
View Full Code Here

Examples of org.apache.derby.iapi.services.compiler.LocalField

    {
      /* This sets up the method and the static field */
      MethodBuilder exprFun = acb.newExprFun();

      /* Now we fill in the body of the method */
      LocalField rowField = generateIndexableRow(acb, numberOfStartPredicates);

      int  colNum = 0;
      int size = size();
      for (int index = 0; index < size; index++)
      {
View Full Code Here

Examples of org.apache.derby.iapi.services.compiler.LocalField

    /*
    ** Assign the indexable row to a field, and put this assignment into
    ** the constructor for the activation class.  This way, we only have
    ** to get the row once.
    */
    LocalField field =
      acb.newFieldDeclaration(Modifier.PRIVATE, ClassName.ExecIndexRow);
   
    mb.setField(field);

    return field;
View Full Code Here

Examples of org.apache.derby.iapi.services.compiler.LocalField

       // this sets up the method and the static field.
       MethodBuilder userExprFun = acb.newUserExprFun();

    /* Declare the field */
    LocalField field = acb.newFieldDeclaration(Modifier.PRIVATE, ClassName.ExecRow);

    // Generate the code to create the row in the constructor
    genCreateRow(acb, field, "getValueRow", ClassName.ExecRow, size());

    ResultColumn rc;
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.