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

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


    ** 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

  protected final boolean generateReceiver(ExpressionClassBuilder acb,
                      MethodBuilder mb,
                      JavaValueNode receiver)
                  throws StandardException
  {
    ClassInspector classInspector = getClassFactory().getClassInspector();

    /*
    ** Don't generate the expression now if it returns a primitive
    ** type to the Java domain.
    */
    if ( (! valueReturnedToSQLDomain()) &&
        classInspector.primitiveType(getJavaTypeName()))
    {
      return false;
    }

    /*
 
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

  {
    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;
    String[]    primParmTypeNames = null;
    boolean[]    isParam = getIsParam();

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

        /*
        ** Find the matching method that is public.
        */

          int signatureOffset = methodName.indexOf('(');
         
            // support Java signatures by checking if the method name contains a '('
            if (signatureOffset != -1) {
                 parmTypeNames = parseValidateSignature(methodName, signatureOffset, hasDynamicResultSets);
               methodName = methodName.substring(0, signatureOffset);
              
               // If the signature is specified then Derby resolves to exactly
               // that method. Setting this flag to false disables the method
               // resolution from automatically optionally repeating the last
               // parameter as needed.
               hasDynamicResultSets = false;
                
            }
            else
            {
              parmTypeNames = getObjectSignature();
            }
        try
        {                       
                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.
                // Also if the DDL specified a signature, then no alternate resolution
                if (signatureOffset == -1 && 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];

View Full Code Here

   * @exception StandardException    Thrown on error
   */
  void verifyClassExist(String javaClassName)
    throws StandardException
  {
    ClassInspector classInspector = getClassFactory().getClassInspector();

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

      foundMatch = classInspector.accessible(javaClassName);

    } catch (ClassNotFoundException cnfe) {

      reason = cnfe;
    }
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

      thenElseList.setParameterDescriptor(dts);
    }

    /* The then and else expressions must be type compatible */
    ClassInspector cu = getClassFactory().getClassInspector();

    /*
    ** If it is comparable, then we are ok.  Note that we
    ** could in fact allow any expressions that are convertible()
    ** since we are going to generate a cast node, but that might
    ** be confusing to users...
    */

    // RESOLVE DJDOI - this looks wrong, why should the then expression
    // be comparable to the then expression ??
    if (! thenExpression.getTypeServices().
       comparable(elseExpression.getTypeServices(), false, getClassFactory()) &&
      ! cu.assignableTo(thenExpression.getTypeId().getCorrespondingJavaTypeName(),
                elseExpression.getTypeId().getCorrespondingJavaTypeName()) &&
      ! cu.assignableTo(elseExpression.getTypeId().getCorrespondingJavaTypeName(),
                thenExpression.getTypeId().getCorrespondingJavaTypeName()))
    {
      throw StandardException.newException(SQLState.LANG_NOT_TYPE_COMPATIBLE,
            thenExpression.getTypeId().getSQLTypeName(),
            elseExpression.getTypeId().getSQLTypeName()
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.