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

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


    JavaValueNode bindExpression(FromList fromList,
                                 SubqueryList subqueryList,
                                 List<AggregateNode> aggregates)
      throws StandardException
  {
    ClassInspector classInspector = getClassFactory().getClassInspector();


    if (((getCompilerContext().getReliability() & CompilerContext.INTERNAL_SQL_ILLEGAL) != 0)
      || !javaClassName.startsWith("java.sql.")) {

      throw StandardException.newException(SQLState.LANG_SYNTAX_ERROR, javaClassName + "::" + fieldName);
    }

    verifyClassExist(javaClassName);

    /*
    ** Find the field that is public.
    */
    field = classInspector.findPublicField(javaClassName,
                    fieldName,
                    true);
    /* Get the field type */
     setJavaTypeName( classInspector.getType(field) );

    return this;

  }
View Full Code Here


    /**
     * For creating the class inspector.
     */
    protected   ClassInspector  makeClassInspector( DatabaseClasses dc )
    {
        return new ClassInspector( dc );
    }
View Full Code Here

        // Set the type of the parameters.
        thenElseList.setParameterDescriptor(getTypeServices());

    /* 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...
    */
        for (ValueNode expr : thenElseList) {
            DataTypeDescriptor dtd = expr.getTypeServices();
            String javaTypeName =
                    dtd.getTypeId().getCorrespondingJavaTypeName();
            String resultJavaTypeName =
                    getTypeId().getCorrespondingJavaTypeName();

            if (!dtd.comparable(getTypeServices(), false, getClassFactory())
                    && !cu.assignableTo(javaTypeName, resultJavaTypeName)
                    && !cu.assignableTo(resultJavaTypeName, javaTypeName)) {
                throw StandardException.newException(
                        SQLState.LANG_NOT_TYPE_COMPATIBLE,
                        dtd.getTypeId().getSQLTypeName(),
                        getTypeId().getSQLTypeName());
            }
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

      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

    ** 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, hasVarargs()
                 );

      /* 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, hasVarargs()
                     );
      }
View Full Code Here

    *
    *  @return  the Classes of our parameters
    */
    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

     */
    private void    generateAndCastOneParameter
        ( ExpressionClassBuilder acb, MethodBuilder mb, int param, String parameterType )
        throws StandardException
    {
    ClassInspector classInspector = getClassFactory().getClassInspector();

        generateOneParameter( acb, mb, param );

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

        if (!parameterType.equals(argumentType))
        {
            //
            // This handles the conversion from primitive to wrapper type. See DERBY-6511.
            // If the parameter type is the wrapper form of the primitive argument type,
            // then call the "valueOf" static method of the wrapper type in order to convert
            // the argument into a wrapper object. So, for instance, this converts a primitive "int"
            // into a "java.lang.Integer".
            //
            if (
                ClassInspector.primitiveType( argumentType ) &&
                parameterType.equals( JSQLType.getWrapperClassName( JSQLType.getPrimitiveID( argumentType ) ) )
                )
            {
                // short must be converted to int
                if ( "short".equals( argumentType ) )
                {
                    mb.cast( "int" );
                }
               
                mb.callMethod
                    (
                     VMOpcode.INVOKESTATIC,
                     parameterType,
                     "valueOf",
                     parameterType,
                     1
                     );
            }
            // 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.
            else if (ClassInspector.primitiveType(parameterType))
            {
                mb.cast(parameterType);
            } else
            {
                // for a procedure
                if (routineInfo != null)
                {
                    return; // 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

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.