Package org.apache.derby.iapi.types

Examples of org.apache.derby.iapi.types.TypeId


                        int judgeUserJDBCTypeId)
                    throws StandardException
  {
    DataValueDescriptor judge;
    if (judgeUserJDBCTypeId == -1)
      judge = (DataValueDescriptor) new TypeId(judgeTypeFormatId, null).getNull();
    else
      judge = (DataValueDescriptor) new TypeId(judgeTypeFormatId, new UserDefinedTypeIdImpl()).getNull();
     
    DataValueDescriptor minVal = v1;
    if (v2 != null && judge.lessThan(v2, minVal).equals(true))
      minVal = v2;
    if (v3 != null && judge.lessThan(v3, minVal).equals(true))
View Full Code Here


                        int judgeUserJDBCTypeId)
                    throws StandardException
  {
    DataValueDescriptor judge;
    if (judgeUserJDBCTypeId == -1)
      judge =  new TypeId(judgeTypeFormatId, null).getNull();
    else
      judge =  new TypeId(judgeTypeFormatId, new UserDefinedTypeIdImpl()).getNull();

    DataValueDescriptor maxVal = v1;
    if (v2 != null && judge.greaterThan(v2, maxVal).equals(true))
      maxVal = v2;
    if (v3 != null && judge.greaterThan(v3, maxVal).equals(true))
View Full Code Here

   */

  private ValueNode trimBind()
      throws StandardException
  {
    TypeId  receiverType;
    TypeId  resultType = TypeId.getBuiltInTypeId(Types.VARCHAR);

    // handle parameters here

    /* Is there a ? parameter for the receiver? */
    if (receiver.requiresTypeFromContext())
    {
      /*
      ** According to the SQL standard, if trim has a ? receiver,
      ** its type is varchar with the implementation-defined maximum length
      ** for a varchar.
      */
 
      receiver.setType(getVarcharDescriptor());
            //check if this parameter can pick up it's collation from the
      //character that will be used for trimming. If not(meaning the
      //character to be trimmed is also a parameter), then it will take
      //it's collation from the compilation schema.
            if (!leftOperand.requiresTypeFromContext()) {
              receiver.getTypeServices().setCollationDerivation(
                  leftOperand.getTypeServices().getCollationDerivation());
              receiver.getTypeServices().setCollationType(
                  leftOperand.getTypeServices().getCollationType());
            } else {
          receiver.setCollationUsingCompilationSchema(
              StringDataValue.COLLATION_DERIVATION_IMPLICIT);             
            }
    }

    /* Is there a ? parameter on the left? */
    if (leftOperand.requiresTypeFromContext())
    {
      /* Set the left operand type to varchar. */
      leftOperand.setType(getVarcharDescriptor());
      //collation of ? operand should be picked up from the context.
            //By the time we come here, receiver will have correct collation
            //set on it and hence we can rely on it to get correct collation
            //for the ? for the character that needs to be used for trimming.
      leftOperand.getTypeServices().setCollationDerivation(
          receiver.getTypeServices().getCollationDerivation());
      leftOperand.getTypeServices().setCollationType(
              receiver.getTypeServices().getCollationType());             
    }

    bindToBuiltIn();

    /*
    ** Check the type of the receiver - this function is allowed only on
    ** string value types. 
    */
    receiverType = receiver.getTypeId();
    if (receiverType.userType())
      throwBadType("trim", receiverType.getSQLTypeName());

    receiver = castArgToString(receiver);

    if (receiverType.getTypeFormatId() == StoredFormatIds.CLOB_TYPE_ID) {
    // special case for CLOBs: if we start with a CLOB, we have to get
    // a CLOB as a result (as opposed to a VARCHAR), because we can have a
    // CLOB that is beyond the max length of VARCHAR (ex. "clob(100k)").
    // This is okay because CLOBs, like VARCHARs, allow variable-length
    // values (which is a must for the trim to actually work).
      resultType = receiverType;
    }

    /*
    ** Check the type of the leftOperand (trimSet).
    ** The leftOperand should be a string value type. 
    */
    TypeId  leftCTI;
    leftCTI = leftOperand.getTypeId();
    if (leftCTI.userType())
      throwBadType("trim", leftCTI.getSQLTypeName());

    leftOperand = castArgToString(leftOperand);

    /*
    ** The result type of trim is varchar.
View Full Code Here

   * @exception StandardException    Thrown on error
   */

  public ValueNode locateBind() throws StandardException
  {
    TypeId  firstOperandType, secondOperandType, offsetType;

    /*
     * Is there a ? parameter for the first arg.  Copy the
     * left/firstOperand's.  If the left/firstOperand are both parameters,
     * both will be max length.
     */
    if( receiver.requiresTypeFromContext())
    {
      if( leftOperand.requiresTypeFromContext())
      {
        receiver.setType(getVarcharDescriptor());
              //Since both receiver and leftOperands are parameters, use the
        //collation of compilation schema for receiver.
        receiver.setCollationUsingCompilationSchema(
            StringDataValue.COLLATION_DERIVATION_IMPLICIT);             
      }
      else
      {
        if( leftOperand.getTypeId().isStringTypeId() )
        {
          //Since the leftOperand is not a parameter, receiver will
          //get it's collation from leftOperand through following
          //setType method
          receiver.setType(
                       leftOperand.getTypeServices());
        }
      }
    }
                                         
    /*
     * Is there a ? parameter for the second arg.  Copy the receiver's.
     * If the receiver are both parameters, both will be max length.
     */
    if(leftOperand.requiresTypeFromContext())
    {
      if(receiver.requiresTypeFromContext())
      {
        leftOperand.setType(getVarcharDescriptor());
      }
      else
      {
        if( receiver.getTypeId().isStringTypeId() )
        {
          leftOperand.setType(
                       receiver.getTypeServices());
        }
      }
      //collation of ? operand should be picked up from the context.
            //By the time we come here, receiver will have correct collation
            //set on it and hence we can rely on it to get correct collation
            //for this ?
      leftOperand.getTypeServices().setCollationDerivation(
          receiver.getTypeServices().getCollationDerivation());
      leftOperand.getTypeServices().setCollationType(
              receiver.getTypeServices().getCollationType());             
    }

    /*
     * Is there a ? paramter for the third arg.  It will be an int.
     */
    if( rightOperand.requiresTypeFromContext())
    {
      rightOperand.setType(
        new DataTypeDescriptor(TypeId.INTEGER_ID, true));
    }

    bindToBuiltIn();

    /*
    ** Check the type of the operand - this function is allowed only
    ** for: receiver = CHAR
    **      firstOperand = CHAR
    **      secondOperand = INT
    */
    secondOperandType = leftOperand.getTypeId();
    offsetType = rightOperand.getTypeId();
    firstOperandType = receiver.getTypeId();

    if (!firstOperandType.isStringTypeId() ||
      !secondOperandType.isStringTypeId() ||
      offsetType.getJDBCTypeId() != Types.INTEGER)
      throw StandardException.newException(SQLState.LANG_DB2_FUNCTION_INCOMPATIBLE,
          "LOCATE", "FUNCTION");

View Full Code Here

   */

   public ValueNode substrBind()
      throws StandardException
  {
    TypeId  receiverType;
    TypeId  resultType = TypeId.getBuiltInTypeId(Types.VARCHAR);

    // handle parameters here

    /* Is there a ? parameter for the receiver? */
    if (receiver.requiresTypeFromContext())
View Full Code Here

        throw StandardException.newException(SQLState.LANG_COLUMN_NOT_FOUND_IN_TABLE,
                              columnNames[i],
                              tableName);
      }

      TypeId typeId = columnDescriptor.getType().getTypeId();

      // Don't allow a column to be created on a non-orderable type
      ClassFactory cf = lcc.getLanguageConnectionFactory().getClassFactory();
      boolean isIndexable = typeId.orderable(cf);

      if (isIndexable && typeId.userType()) {
        String userClass = typeId.getCorrespondingJavaTypeName();

        // Don't allow indexes to be created on classes that
        // are loaded from the database. This is because recovery
        // won't be able to see the class and it will need it to
        // run the compare method.
        try {
          if (cf.isApplicationClass(cf.loadApplicationClass(userClass)))
            isIndexable = false;
        } catch (ClassNotFoundException cnfe) {
          // shouldn't happen as we just check the class is orderable
          isIndexable = false;
        }
      }

      if (!isIndexable) {
        throw StandardException.newException(SQLState.LANG_COLUMN_NOT_ORDERABLE_DURING_EXECUTION,
          typeId.getSQLTypeName());
      }

      // Remember the position in the base table of each column
      baseColumnPositions[i] = columnDescriptor.getPosition();
View Full Code Here

     * @return Object representing the column.
     */
    static SystemColumn getJavaColumn(String name, String javaClassName,
            boolean nullability) {

        TypeId typeId = TypeId.getUserDefinedTypeId(javaClassName, false);

        DataTypeDescriptor dtd = new DataTypeDescriptor(typeId, nullability);
        return new SystemColumnImpl(name, dtd);
    }
View Full Code Here

      ** get the type of the first non-? in its column, so it can't
      ** affect the final dominant type.  It's possible that all the
      ** rows for a particular column will have ? parameters - this is
      ** an error condition that will be caught later.
      */
      TypeId thisTypeId = thisExpr.getTypeId();
      if (thisTypeId == null)
        continue;

      TypeId otherTypeId = otherExpr.getTypeId();
      if (otherTypeId == null)
        continue;

      /*
      ** Check type compatability.
      */
      ClassFactory cf = getClassFactory();
      if ( !unionCompatible( thisExpr, otherExpr ) )
      {
        throw StandardException.newException(SQLState.LANG_NOT_UNION_COMPATIBLE,
                                                     thisTypeId.getSQLTypeName(),
                                                     otherTypeId.getSQLTypeName(),
                                                     operatorName);
      }

      DataTypeDescriptor resultType = thisExpr.getTypeServices().getDominantType(
                        otherExpr.getTypeServices(),
View Full Code Here

     * Standard.
     */
    private boolean unionCompatible( ValueNode left, ValueNode right )
        throws StandardException
    {
        TypeId leftTypeId = left.getTypeId();
        TypeId rightTypeId = right.getTypeId();
        ClassFactory cf = getClassFactory();

        if (
            !left.getTypeCompiler().storable(rightTypeId, cf) &&
            !right.getTypeCompiler().storable(leftTypeId, cf)
            )
        { return false; }

        if ( leftTypeId.isBooleanTypeId() != rightTypeId.isBooleanTypeId() ) { return false; }

        return true;
    }
View Full Code Here

      for (int index = 1; index <= numColumns; index++)
      {
        boolean nullableResult =
          (rsmd.isNullable(index) != ResultSetMetaData.columnNoNulls);

        TypeId cti;

        int jdbcColumnType = rsmd.getColumnType(index);

        switch (jdbcColumnType) {
        case Types.JAVA_OBJECT:
        case Types.OTHER:
        {
          cti = TypeId.getUserDefinedTypeId(rsmd.getColumnTypeName(index), false);
          break;
        }
        default:
        {
          cti = TypeId.getBuiltInTypeId(jdbcColumnType);
          break;
        }
        }

        // Handle the case where a VTI returns a bad column type
        if (cti == null)
        {
          throw StandardException.newException(SQLState.LANG_BAD_J_D_B_C_TYPE_INFO, Integer.toString(index));
        }

        // Get the maximum byte storage for this column
        int maxWidth;

        /* Get maximum byte storage from rsmd for variable
         * width types, set it to MAXINT for the long types,
         * otherwise get it from the TypeId
         */
        if (cti.variableLength())
        {
          maxWidth = rsmd.getColumnDisplaySize(index);
        }
        else if (jdbcColumnType == Types.LONGVARCHAR ||
             jdbcColumnType == Types.LONGVARBINARY)
        {
          maxWidth = Integer.MAX_VALUE;
        }
        else
        {
          maxWidth = 0;
        }

        int precision = cti.isDecimalTypeId() ? rsmd.getPrecision(index) : 0;
        int scale = cti.isDecimalTypeId() ? rsmd.getScale(index) : 0;
        DataTypeDescriptor dts = new DataTypeDescriptor(cti,
                      precision,
                      scale,
                      nullableResult,
                      maxWidth);
View Full Code Here

TOP

Related Classes of org.apache.derby.iapi.types.TypeId

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.