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

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


  {
    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
      {
        TypeId returnTypeId = TypeId.getBuiltInTypeId(returnType.getJDBCTypeId());

        if (
            returnType.isRowMultiSet() &&
            ( routineInfo.getParameterStyle() == RoutineAliasInfo.PS_DERBY_JDBC_RESULT_SET )
        )
        {
            requiredType = "java.sql.ResultSet";
        }
        else
        {
           requiredType = returnTypeId.getCorrespondingJavaTypeName();

          if (!requiredType.equals(typeName)) {
            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;
            }
          }
        }
      }

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

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

      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

    /* Built-in types need no checking */
    if (!getType().getTypeId().userType())
      return;

    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

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

        // 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 = methodCall.getJavaClassName();
            Constructor<?> constr = classInspector.getClass(javaClassName).getConstructor(paramTypeClasses);

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

        throws ClassNotFoundException, IllegalAccessException, InvocationTargetException,
               NoSuchMethodException, SQLException
    {
        int    lastDotIdx = indexDescriptorMaker.lastIndexOf( "." );
        String  className = indexDescriptorMaker.substring( 0, lastDotIdx );
        ClassInspector  ci = getClassFactory().getClassInspector();
        Class<? extends Object>  klass = ci.getClass( className );
        String methodName = indexDescriptorMaker.substring( lastDotIdx + 1, indexDescriptorMaker.length() );
        Method method = klass.getDeclaredMethod( methodName );
                    
        return (LuceneIndexDescriptor) method.invoke( null );
  }
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

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.