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 );
     if (routineInfo != null)
                {
                    TypeDescriptor returnType = routineInfo.getReturnType();
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

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

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

  {
    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;
      TypeDescriptorImpl returnType = (TypeDescriptorImpl) routineInfo.getReturnType();
      String requiredType;
      if (returnType == null)
      {
        // must have a void method for a procedure call.
        requiredType = "void";
      }
      else
      {
        TypeId returnTypeId = TypeId.getBuiltInTypeId(returnType.getJDBCTypeId());

        if (
            returnType.isRowMultiSet() &&
            ( routineInfo.getParameterStyle() == RoutineAliasInfo.PS_DERBY_JDBC_RESULT_SET )
        )
        {
            requiredType = ResultSet.class.getName();
        }
                else if ( returnType.getTypeId().userType() )
                {
                    requiredType = ((UserDefinedTypeIdImpl) returnType.getTypeId()).getClassName();
                }
        else
        {
           requiredType = returnTypeId.getCorrespondingJavaTypeName();

          if (!requiredType.equals(typeName)) {
            switch (returnType.getJDBCTypeId()) {
            case java.sql.Types.BOOLEAN:
            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;
            }
          }
        }
      }

            boolean foundCorrectType;
            if ( ResultSet.class.getName().equals( requiredType )  )
            {
                // allow subtypes of ResultSet too
                try {
                    Class actualType = classInspector.getClass( typeName );

                    foundCorrectType = ResultSet.class.isAssignableFrom( actualType );
                }
                catch (ClassNotFoundException cnfe) { foundCorrectType = false; }
            }
            else{ foundCorrectType = requiredType.equals(typeName); }

      if (!foundCorrectType)
      {
        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;
      //propogate collation type from RoutineAliasInfo to
      // MethodCallNode DERBY-2972
                        if (routineInfo.getReturnType() != null)
                            setCollationType(routineInfo.getReturnType().getCollationType());    
                }
     setJavaTypeName( typeName );
               
    methodParameterTypes = classInspector.getParameterTypes(method);

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

View Full Code Here

      return;

        // bind the UDT if necessary
        setType( bindUserType( getType() ) );

    ClassInspector classInspector = getClassFactory().getClassInspector();

    columnTypeName =
      getType().getTypeId().getCorrespondingJavaTypeName();

    /* User type - We first check for the columnTypeName as a java class.
     * If that fails, then we treat it as a class alias.
     */

    boolean foundMatch = false;
    Throwable reason = null;
    try {
      foundMatch = classInspector.accessible(columnTypeName);
    } catch (ClassNotFoundException cnfe) {
      reason = cnfe;
    }

    if (!foundMatch)
    {
      throw StandardException.newException(SQLState.LANG_TYPE_DOESNT_EXIST, reason, columnTypeName,
                                name);
    }

    if (! classInspector.assignableTo(columnTypeName,
                      "java.io.Serializable"&&
            // Before Java2, SQLData is not defined, assignableTo call returns false
            ! classInspector.assignableTo(columnTypeName,"java.sql.SQLData"))
        {
      getCompilerContext().addWarning(
        StandardException.newWarning(SQLState.LANG_TYPE_NOT_SERIALIZABLE, columnTypeName,
                                 name));
    }
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

      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

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.