Package org.apache.derby.iapi.types

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


   */

  private boolean implicitVarcharComparison()
    throws StandardException
  {
    TypeId leftType = leftOperand.getTypeId();
    TypeId rightType = rightOperand.getTypeId();
   
    if (leftType.isStringTypeId() && !rightType.isStringTypeId())
      return true;

    if (rightType.isStringTypeId() && (!leftType.isStringTypeId()))
      return true;

    return false;
  }
View Full Code Here


  public ValueNode bindExpression(
    FromList  fromList, SubqueryList subqueryList,
    Vector  aggregateVector)
      throws StandardException
  {
    TypeId  operandType;

    super.bindExpression(fromList, subqueryList,
        aggregateVector);

    /*
    ** Check the type of the operand - this function is allowed only on
    ** string value types. 
    */
    operandType = operand.getTypeId();
    switch (operandType.getJDBCTypeId())
    {
        case Types.CHAR:
        case Types.VARCHAR:
        case Types.BINARY:
        case Types.VARBINARY:
        case Types.LONGVARBINARY:
        case Types.LONGVARCHAR:
                case JDBC20Translation.SQL_TYPES_BLOB:
                case JDBC20Translation.SQL_TYPES_CLOB:
          break;
     
        default:
          throw StandardException.newException(SQLState.LANG_UNARY_FUNCTION_BAD_TYPE,
                      getOperatorString(),
                      operandType.getSQLTypeName());
    }

    /*
    ** The result type of XXX_length is int.
    */
 
View Full Code Here

      leftOperand.setType(DataTypeDescriptor.getBuiltInDataTypeDescriptor( Types.DATE));
    //Set the type if there is a parameter involved here
    if (rightOperand.requiresTypeFromContext())
      rightOperand.setType(DataTypeDescriptor.getBuiltInDataTypeDescriptor( Types.TIME));

    TypeId leftTypeId = leftOperand.getTypeId();
        TypeId rightTypeId = rightOperand.getTypeId();
        if( !(leftOperand.requiresTypeFromContext() || leftTypeId.isStringTypeId() || leftTypeId.getJDBCTypeId() == Types.DATE))
            throw StandardException.newException(SQLState.LANG_BINARY_OPERATOR_NOT_SUPPORTED,
                                                 operator, leftTypeId.getSQLTypeName(), rightTypeId.getSQLTypeName());
        if( !(rightOperand.requiresTypeFromContext() || rightTypeId.isStringTypeId() || rightTypeId.getJDBCTypeId() == Types.TIME))
            throw StandardException.newException(SQLState.LANG_BINARY_OPERATOR_NOT_SUPPORTED,
                                                 operator, leftTypeId.getSQLTypeName(), rightTypeId.getSQLTypeName());
        setType(DataTypeDescriptor.getBuiltInDataTypeDescriptor( Types.TIMESTAMP));
    return genSQLJavaSQLTree();
  } // end of bindExpression
View Full Code Here

    throws StandardException
  {
    ColumnDescriptor cd;
    TypeDescriptor oldType;
    DataTypeDescriptor newType = dataTypeServices;
    TypeId oldTypeId;
    TypeId newTypeId;

    if (getNodeType() != C_NodeTypes.MODIFY_COLUMN_TYPE_NODE)
      return;        // nothing to do if user not changing length

    cd = td.getColumnDescriptor(name);
View Full Code Here

    super.bindExpression(fromList, subqueryList, aggregateVector);

//RESOLVELOCALIZE - convert constants to national constants
    TypeCompiler leftTC = leftOperand.getTypeCompiler();
    TypeCompiler rightTC = rightOperand.getTypeCompiler();
    TypeId leftTypeId = leftOperand.getTypeId();
    TypeId rightTypeId = rightOperand.getTypeId();

    /*
     * If we are comparing a non-string with a string type, then we
     * must prevent the non-string value from being used to probe into
     * an index on a string column. This is because the string types
     * are all of low precedence, so the comparison rules of the non-string
     * value are used, so it may not find values in a string index because
     * it will be in the wrong order. So, cast the string value to its
     * own type. This is easier than casting it to the non-string type,
     * because we would have to figure out the right length to cast it to.
     */
    if (! leftTypeId.isStringTypeId() && rightTypeId.isStringTypeId())
    {
      DataTypeDescriptor rightTypeServices = rightOperand.getTypeServices();

      rightOperand =  (ValueNode)
        getNodeFactory().getNode(
          C_NodeTypes.CAST_NODE,
          rightOperand,
          new DataTypeDescriptor(
              rightTypeId,
              true,
              rightTypeServices.getMaximumWidth()),
          getContextManager());
      ((CastNode) rightOperand).bindCastNodeOnly();
    }
    else if (! rightTypeId.isStringTypeId() && leftTypeId.isStringTypeId())
    {
      DataTypeDescriptor leftTypeServices = leftOperand.getTypeServices();

      leftOperand =  (ValueNode)
        getNodeFactory().getNode(
          C_NodeTypes.CAST_NODE,
          leftOperand,
          new DataTypeDescriptor(
              leftTypeId,
              true,
              leftTypeServices.getMaximumWidth()),
          getContextManager());
      ((CastNode) leftOperand).bindCastNodeOnly();
    }
    /* If we are comparing a char with a national char then
     * we need to generate a cast to the appropriate national
     * char above the char operand.
     */
    else if (! leftTypeId.isNationalStringTypeId() &&
      rightTypeId.isNationalStringTypeId())
    {
      leftOperand =  (ValueNode)
        getNodeFactory().getNode(
          C_NodeTypes.CAST_NODE,
          leftOperand,
          DataTypeDescriptor.getBuiltInDataTypeDescriptor(leftTC.getMatchingNationalCharTypeName(),
                    leftTC.getCastToCharWidth(
                      leftOperand.getTypeServices())),
          getContextManager());
      ((CastNode) leftOperand).bindCastNodeOnly();
    }
    else if (! rightTypeId.isNationalStringTypeId() &&
        leftTypeId.isNationalStringTypeId())
    {
      rightOperand =  (ValueNode)
        getNodeFactory().getNode(
          C_NodeTypes.CAST_NODE,
View Full Code Here

   * @exception StandardException    Thrown on error
   */
  public void bindComparisonOperator()
      throws StandardException
  {
    TypeId  leftType;
    TypeId  rightType;
    boolean        nullableResult;

    leftType = leftOperand.getTypeId();
    rightType = rightOperand.getTypeId();


    /*
    ** Can the types be compared to each other?  If not, throw an
    ** exception.
    */
    boolean forEquals = operator.equals("=") || operator.equals("<>");

        boolean cmp = leftOperand.getTypeCompiler().comparable(rightType,
                                                               forEquals,
                                                               getClassFactory());
    // Bypass the comparable check if this is a rewrite from the
    // optimizer.  We will assume Mr. Optimizer knows what he is doing.
          if (!cmp && !forQueryRewrite) {
      throw StandardException.newException(SQLState.LANG_NOT_COMPARABLE,
          leftType.getSQLTypeName(),
          rightType.getSQLTypeName()
        );
      }

   
    /*
 
View Full Code Here

  }
 
  /** @see BinaryOperatorNode#genSQLJavaSQLTree */
  public ValueNode genSQLJavaSQLTree() throws StandardException
  {
    TypeId leftTypeId = leftOperand.getTypeId();

    /* If I have Java types, I need only add java->sql->java if the types
     * are not comparable
     */
    if (leftTypeId.userType())
    {
      if (leftOperand.getTypeCompiler().comparable(leftTypeId, false,
                               getClassFactory()))
        return this;

      leftOperand = leftOperand.genSQLJavaSQLTree();
    }

    TypeId rightTypeId = rightOperand.getTypeId();

    if (rightTypeId.userType())
    {
      if (rightOperand.getTypeCompiler().comparable(rightTypeId, false,
                              getClassFactory()))
        return this;

View Full Code Here

          FromList      fromList,
          SubqueryList    subqueryList,
          Vector        aggregateVector)
      throws StandardException
  {
    TypeId  outType;
    TypeId  inputType = null;
    Class        inputClass = null;
    String        inputTypeName = null;
    Class        inputInterfaceClass = null;
    String        inputInterfaceName = null;
    DataTypeDescriptor   dts = null;
    TypeDescriptor     resultType = null;
    ClassFactory    cf;

    cf = getClassFactory();
    classInspector = cf.getClassInspector();

    instantiateAggDef();

    /* Add ourselves to the aggregateVector before we do anything else */
    aggregateVector.addElement(this);

    super.bindExpression(
        fromList, subqueryList,
        aggregateVector);

    if (operand != null)
    {
      /*
      ** Make sure that we don't have an aggregate
      ** IMMEDIATELY below us.  Don't search below
      ** any ResultSetNodes.
      */
      HasNodeVisitor visitor = new HasNodeVisitor(this.getClass(), ResultSetNode.class);
      operand.accept(visitor);
      if (visitor.hasNode())
      {
        throw StandardException.newException(SQLState.LANG_USER_AGGREGATE_CONTAINS_AGGREGATE,
            aggregateName);
      }

      /*
      ** Check the type of the operand.  Make sure that the user
      ** defined aggregate can handle the operand datatype.
      */
      dts = operand.getTypeServices();

      /* Convert count(nonNullableColumn) to count(*)  */
      if (uad instanceof CountAggregateDefinition &&
        !dts.isNullable())
      {
        setOperator(aggregateName);
        setMethodName(aggregateName);
      }

      /*
      ** If we have a distinct, then the value expression
      ** MUST implement Orderable because we are going
      ** to process it using it as part of a sort.
      */
      if (distinct)
      {
        /*
        ** For now, we check to see if orderable() returns
        ** true for this type.  In the future we may need
        ** to check to see if the type implements Orderable
        **
        */
        if (!operand.getTypeId().orderable(cf))
        {
          throw StandardException.newException(SQLState.LANG_COLUMN_NOT_ORDERABLE_DURING_EXECUTION,
              dts.getTypeId().getSQLTypeName());
        }

      }

      /*
      ** Don't allow an untyped null
      */
      if (operand instanceof UntypedNullConstantNode)
      {
        throw StandardException.newException(SQLState.LANG_USER_AGGREGATE_BAD_TYPE_NULL, aggregateName);
      }
    }

    /*
    ** Ask the aggregate definition whether it can handle
     ** the input datatype.  If an exception is thrown,
    ** barf.
     */
    try
    {
      aggregatorClassName = new StringBuffer();
      resultType = uad.getAggregator(dts, aggregatorClassName);
    } catch (Exception e)
    {
      //RESOLVE: would be a good idea to add some additional text to
      // this error, like during getResultDataType on aggregate x
      // maybe enhance this error everywhere (seems like execution
      // should also add some text, at the very least saying during
      // execution.  see Compiltion/Generator/UserExpressionBuilder.java
      throw StandardException.unexpectedUserException(e);
    }

    if (resultType == null)
    {
      throw StandardException.newException(SQLState.LANG_USER_AGGREGATE_BAD_TYPE,
            aggregateName,
            operand.getTypeId().getSQLTypeName());
    }

    checkAggregatorClassName(aggregatorClassName.toString());

    /*
    ** Try for a built in type matching the
    ** type name. 
    */
    TypeId compTypeId = TypeId.getBuiltInTypeId(resultType.getTypeName());
    /*
    ** If not built in, it is probably a java type.
    ** Get the sql type descriptor for that. 
    */
    if (compTypeId == null)
View Full Code Here

  public ResultColumn  getNewAggregatorResultColumn(DataDictionary  dd)
    throws StandardException
  {
    String  className = aggregatorClassName.toString();

    TypeId compTypeId = TypeId.getSQLTypeForJavaType(className);

    /*
    ** Create a null of the right type.  The proper aggregators
    ** are created dynamically by the SortObservers
    */
 
View Full Code Here

  public void generateExpression(ExpressionClassBuilder acb,
                      MethodBuilder mb)
                  throws StandardException
  {
    TypeId      resultType;
    String            resultTypeName;

    /*
    ** Tell the Java node that it's value is being returned to the
    ** SQL domain.  This way, it knows whether the checking for a null
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.