Package org.apache.derby.iapi.services.loader

Examples of org.apache.derby.iapi.services.loader.ClassInspector


  public void boot(boolean create, Properties startParams)
    throws StandardException
  {

    classInspector = new ClassInspector(this);

    //
    //The ClassFactory runs per service (database) mode (booted as a service module after AccessFactory).
    //If the code that booted
    //us needs a per-database classpath then they pass in the classpath using
View Full Code Here


      }
    }
    else
    {
      /* At least 1 type is not a system built-in type */
      ClassInspector    cu = cf.getClassInspector();

      TypeId thisCompType = (TypeId) thisType;
      TypeId otherCompType = (TypeId) otherType;

      if (cu.assignableTo(thisCompType.getCorrespondingJavaTypeName(),
                  otherCompType.getCorrespondingJavaTypeName()))
      {
        higherType = otherDTS;
      }
      else
      {
        if (SanityManager.DEBUG)
            SanityManager.ASSERT(
              cu.assignableTo(otherCompType.getCorrespondingJavaTypeName(),
                  thisCompType.getCorrespondingJavaTypeName()),
              otherCompType.getCorrespondingJavaTypeName() +
              " expected to be assignable to " +
              thisCompType.getCorrespondingJavaTypeName());

View Full Code Here

  String verifyClassExist(String javaClassName, boolean convertCase)
    throws StandardException
  {
    /* Verify that the class exists */

    ClassInspector classInspector = getClassFactory().getClassInspector();

    /* We first try to resolve the javaClassName as a class.  If that
     * fails then we try to resolve it as a class alias.
     */

    Throwable reason = null;
    boolean foundMatch = false;
    try {

      foundMatch = classInspector.accessible(javaClassName);

    } catch (ClassNotFoundException cnfe) {

      reason = cnfe;
    } catch (LinkageError le) {
View Full Code Here

      paramObjects = new Object[0];
    }

        try
        {
            ClassInspector classInspector = getClassFactory().getClassInspector();
            String javaClassName = newInvocation.getJavaClassName();
            Constructor constructor = classInspector.getClass(javaClassName).getConstructor(paramTypeClasses);

            return constructor.newInstance(paramObjects);
        }
    catch(Throwable t)
    {
View Full Code Here

  {
    int        param;

    String[] expectedTypes = methodParameterTypes;

    ClassInspector classInspector = getClassFactory().getClassInspector();

    /* Generate the code for each user parameter, generating the appropriate
     * cast when the passed type needs to get widened to the expected type.
     */
    for (param = 0; param < methodParms.length; param++)
    {
      generateOneParameter( acb, mb, param );

      // type from the SQL-J expression
      String argumentType = getParameterTypeName( methodParms[param] );

      // type of the method
      String parameterType = expectedTypes[param];

      if (!parameterType.equals(argumentType))
      {
        // since we reached here through method resolution
        // casts are only required for primitive types.
        // In any other case the expression type must be assignable
        // to the parameter type.
        if (classInspector.primitiveType(parameterType)) {

          mb.cast(parameterType);

        } else {

          // for a prodcedure
          if (routineInfo != null) {
            continue; // probably should be only for INOUT/OUT parameters.
          }

          if (SanityManager.DEBUG) {
            SanityManager.ASSERT(classInspector.assignableTo(argumentType, parameterType),
              "Argument type " + argumentType + " is not assignable to parameter " + parameterType);
          }

          /*
          ** Set the parameter type in case the argument type is narrower
View Full Code Here

      }
    }

    int      count = signature.length;

    ClassInspector classInspector = getClassFactory().getClassInspector();

    String[]    parmTypeNames = getObjectSignature();
    String[]    primParmTypeNames = null;
    boolean[]    isParam = getIsParam();

    boolean hasDynamicResultSets = (routineInfo != null) && (count != 0) && (count != methodParms.length);

    /*
    ** Find the matching method that is public.
    */
    try
    {
      /* First try with built-in types and mappings */
      method = classInspector.findPublicMethod(javaClassName,
                        methodName,
                        parmTypeNames,
                        null,
                        isParam,
                        staticMethod,
                        hasDynamicResultSets);


      // DB2 LUW does not support Java object types for SMALLINT, INTEGER, BIGINT, REAL, DOUBLE
      // and these are the only types that can map to a primitive or an object type according
      // to SQL part 13. So we never have a second chance match.
      if (routineInfo == null) {

        /* If no match, then retry with combinations of object and
         * primitive types.
         */
        if (method == null)
        {
          primParmTypeNames = getPrimitiveSignature(false);

          method = classInspector.findPublicMethod(javaClassName,
                        methodName,
                        parmTypeNames,
                        primParmTypeNames,
                        isParam,
                        staticMethod,
                        hasDynamicResultSets);
        }
      }
    }
    catch (ClassNotFoundException e)
    {
      /*
      ** If one of the classes couldn't be found, just act like the
      ** method couldn't be found.  The error lists all the class names,
      ** which should give the user enough info to diagnose the problem.
      */
      method = null;
    }

    /* Throw exception if no matching signature found */
    if (method == null)
    {
      throwNoMethodFound(javaClassName, parmTypeNames, primParmTypeNames);
    }

    String  typeName = classInspector.getType(method);
    actualMethodReturnType = typeName;

    if (routineInfo == null) {

      /* void methods are only okay for CALL Statements */
      if (typeName.equals("void"))
      {
        if (!forCallStatement)
          throw StandardException.newException(SQLState.LANG_VOID_METHOD_CALL);
      }
    }
    else
    {
      String promoteName = null;
      TypeDescriptor returnType = routineInfo.getReturnType();
      String requiredType;
      if (returnType == null)
      {
        // must have a void method for a procedure call.
        requiredType = "void";
      }
      else
      {


        // DB2 LUW does not support Java object types for SMALLINT, INTEGER, BIGINT, REAL, DOUBLE
        // and these are the only types that can map to a primitive or an object type according
        // to SQL part 13. So always map to the primitive type. We can not use the getPrimitiveSignature()
        // as it (incorrectly but historically always has) maps a DECIMAL to a double.

       
        TypeId returnTypeId = TypeId.getBuiltInTypeId(returnType.getJDBCTypeId());
        switch (returnType.getJDBCTypeId()) {
        case java.sql.Types.SMALLINT:
        case java.sql.Types.INTEGER:
        case java.sql.Types.BIGINT:
        case java.sql.Types.REAL:
        case java.sql.Types.DOUBLE:
          TypeCompiler tc = getTypeCompiler(returnTypeId);
          requiredType = tc.getCorrespondingPrimitiveTypeName();
          if (!routineInfo.calledOnNullInput() && routineInfo.getParameterCount() != 0)
          {
            promoteName = returnTypeId.getCorrespondingJavaTypeName();
          }

          break;
        default:
          requiredType = returnTypeId.getCorrespondingJavaTypeName();
          break;
        }

      }

      if (!requiredType.equals(typeName))
      {
        throwNoMethodFound(requiredType + " " + javaClassName, parmTypeNames, primParmTypeNames);
      }

      // for a returns null on null input with a primitive
      // type we need to promote to an object so we can return null.
      if (promoteName != null)
        typeName = promoteName;
    }
     setJavaTypeName( typeName );

    methodParameterTypes = classInspector.getParameterTypes(method);

    for (int i = 0; i < methodParameterTypes.length; i++)
    {
      String methodParameter = methodParameterTypes[i];

      if (routineInfo != null) {
        if (i < routineInfo.getParameterCount()) {
          int parameterMode = routineInfo.getParameterModes()[i];

          switch (parameterMode) {
          case JDBC30Translation.PARAMETER_MODE_IN:
            break;
          case JDBC30Translation.PARAMETER_MODE_IN_OUT:
            // we need to see if the type of the array is
            // primitive, not the array itself.
            methodParameter = methodParameter.substring(0, methodParameter.length() - 2);
            break;

          case JDBC30Translation.PARAMETER_MODE_OUT:
            // value is not obtained *from* parameter.
            continue;
          }
        }
      }

      if (classInspector.primitiveType(methodParameter))
        methodParms[i].castToPrimitive(true);
    }

    /* Set type info for any null parameters */
    if ( someParametersAreNull() )
View Full Code Here

    *
    *  @return  the Classes of our parameters
    */
  public  Class[]  getMethodParameterClasses()
  {
    ClassInspector ci = getClassFactory().getClassInspector();

    Class[]  parmTypeClasses = new Class[methodParms.length];
    for (int i = 0; i < methodParms.length; i++)
    {
      String className = methodParameterTypes[i];
      try
      {
        parmTypeClasses[i] = ci.getClass(className);
      }
      catch (ClassNotFoundException cnfe)
      {
        /* We should never get this exception since we verified
         * that the classes existed at bind time.  Just return null.
View Full Code Here

    ** Get the parameter type names out of the parameters and put them
    ** in an array.
    */
    String[]  parmTypeNames = getObjectSignature();
    boolean[]  isParam = getIsParam();
    ClassInspector classInspector = getClassFactory().getClassInspector();

    /*
    ** Find the matching constructor.
    */
    try
    {
      /* First try with built-in types and mappings */
      method = classInspector.findPublicConstructor(javaClassName,
                      parmTypeNames, null, isParam);

      /* If no match, then retry to match any possible combinations of
       * object and primitive types.
       */
      if (method == null)
      {
        String[] primParmTypeNames = getPrimitiveSignature(false);
        method = classInspector.findPublicConstructor(javaClassName,
                parmTypeNames, primParmTypeNames, isParam);
      }
    }
    catch (ClassNotFoundException e)
    {
      /*
      ** If one of the classes couldn't be found, just act like the
      ** method couldn't be found.  The error lists all the class names,
      ** which should give the user enough info to diagnose the problem.
      */
      method = null;
    }

    if (method == null)
    {
      /* Put the parameter type names into a single string */
      String  parmTypes = "";
      for (int i = 0; i < parmTypeNames.length; i++)
      {
        if (i != 0)
          parmTypes += ", ";
        parmTypes += (parmTypeNames[i].length() != 0 ?
                parmTypeNames[i] :
                MessageService.getTextMessage(
                  SQLState.LANG_UNTYPED)
                  );
      }

      throw StandardException.newException(SQLState.LANG_NO_CONSTRUCTOR_FOUND,
                          javaClassName,
                           parmTypes);
    }

    methodParameterTypes = classInspector.getParameterTypes(method);

    for (int i = 0; i < methodParameterTypes.length; i++)
    {
      if (classInspector.primitiveType(methodParameterTypes[i]))
        methodParms[i].castToPrimitive(true);
    }

    /* Set type info for any null parameters */
    if ( someParametersAreNull() )
    {
      setNullParameterInfo(methodParameterTypes);
    }

    /* Constructor always returns an object of type javaClassName */
    if (SanityManager.DEBUG) {
      SanityManager.ASSERT(javaClassName.equals(classInspector.getType(method)),
        "Constructor is wrong type, expected " + javaClassName +
        " actual is " + classInspector.getType(method));
    }
     setJavaTypeName( javaClassName );

    return this;
  }
View Full Code Here

   *
   * @exception StandardException    Thrown on error
   */
  protected boolean assignableTo(String toClassName) throws StandardException
  {
    ClassInspector classInspector = getClassFactory().getClassInspector();
    return classInspector.assignableTo(javaClassName, toClassName);
  }
View Full Code Here

    ** in an array.
    */
    String[]  parmTypeNames = getObjectSignature();
    boolean[]  isParam = getIsParam();

    ClassInspector classInspector = getClassFactory().getClassInspector();

    try
    {
      publicMethod = classInspector.findPublicMethod(javaClassName, methodName,
                         parmTypeNames, null, isParam, staticMethod, false);

      /* If no match, then retry to match any possible combinations of
       * object and primitive types.
       */
      if (publicMethod == null)
      {
        String[] primParmTypeNames = getPrimitiveSignature(false);
        publicMethod = classInspector.findPublicMethod(javaClassName,
                    methodName, parmTypeNames,
                    primParmTypeNames, isParam, staticMethod, false);
      }
    }
    catch (ClassNotFoundException e)
View Full Code Here

TOP

Related Classes of org.apache.derby.iapi.services.loader.ClassInspector

Copyright © 2018 www.massapicom. 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.