Package org.apache.derby.iapi.types

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


      throws StandardException
  {
    super.bindExpression(fromList, subqueryList,
        aggregateVector);

    TypeId  leftType = leftOperand.getTypeId();
    TypeId  rightType = rightOperand.getTypeId();
    DataTypeDescriptor  leftDTS = leftOperand.getTypeServices();
    DataTypeDescriptor  rightDTS = rightOperand.getTypeServices();

    /* Do any implicit conversions from (long) (var)char. */
    if (leftType.isStringTypeId() && rightType.isNumericTypeId())
    {
      boolean nullableResult;
      nullableResult = leftDTS.isNullable() ||
                rightDTS.isNullable();
      /* If other side is decimal/numeric, then we need to diddle
       * with the precision, scale and max width in order to handle
       * computations like:  1.1 + '0.111'
       */
      int precision = rightDTS.getPrecision();
      int scale    = rightDTS.getScale();
      int maxWidth  = rightDTS.getMaximumWidth();

      if (rightType.isDecimalTypeId())
      {
        int charMaxWidth = leftDTS.getMaximumWidth();
        precision += (2 * charMaxWidth);               
        scale += charMaxWidth;               
        maxWidth = precision + 3;
      }

      leftOperand = (ValueNode)
          getNodeFactory().getNode(
            C_NodeTypes.CAST_NODE,
            leftOperand,
            new DataTypeDescriptor(rightType, precision,
                      scale, nullableResult,
                      maxWidth),
            getContextManager());
      ((CastNode) leftOperand).bindCastNodeOnly();
    }
    else if (rightType.isStringTypeId() && leftType.isNumericTypeId())
    {
      boolean nullableResult;
      nullableResult = leftDTS.isNullable() ||
                rightDTS.isNullable();
      /* If other side is decimal/numeric, then we need to diddle
View Full Code Here


    if (getTypeServices() == null)   //CHAR or VARCHAR function without specifying target length
    {
      DataTypeDescriptor opndType = castOperand.getTypeServices();
      int length = -1;
      TypeId srcTypeId = opndType.getTypeId();
      if (opndType != null)
      {
        if (srcTypeId.isNumericTypeId())
        {
          length = opndType.getPrecision() + 1; // 1 for the sign
          if (opndType.getScale() > 0)
            length += 1;               // 1 for the decimal .
        
        }
        /*
         * Derby-1132 : The length for the target type was calculated
         * incorrectly while Char & Varchar functions were used. Thus
         * adding the check for Char & Varchar and calculating the
         * length based on the operand type.
         */
        else if(srcTypeId.isStringTypeId())
        {
          length = opndType.getMaximumWidth();
     
          // Truncate the target type width to the max width of the
          // data type
          if (this.targetCharType == Types.CHAR)
            length = Math.min(length, Limits.DB2_CHAR_MAXWIDTH);
          else if (this.targetCharType == Types.VARCHAR)
            length = Math.min(length, Limits.DB2_VARCHAR_MAXWIDTH);
        }
        else
        {
          TypeId typeid = opndType.getTypeId();
          if (length < 0)
            length = DataTypeUtilities.getColumnDisplaySize(typeid.getJDBCTypeId(),-1);

        }
      }
      if (length < 0)
        length = 1// same default as in parser
View Full Code Here

   * selectivity otherwise.
   */
  protected double booleanSelectivity(Optimizable optTable)
  throws StandardException
  {
    TypeId  typeId = null;
    double        retval = -1.0d;
    int          columnSide;

    columnSide = columnOnOneSide(optTable);

    if (columnSide == LEFT)
      typeId = leftOperand.getTypeId();
    else if (columnSide == RIGHT)
      typeId = rightOperand.getTypeId();

    if (typeId != null && (typeId.getJDBCTypeId() == Types.BIT ||
    typeId.getJDBCTypeId() == JDBC30Translation.SQL_TYPES_BOOLEAN))
      retval = 0.5d;

    return retval;
  }
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

    /*
    ** Generate a CastNode if necessary and
    ** stick it over the original expression
    */
    TypeId condTypeId = getTypeId();
    TypeId thenTypeId = ((ValueNode) thenElseList.elementAt(0)).getTypeId();
    TypeId elseTypeId = ((ValueNode) thenElseList.elementAt(1)).getTypeId();

    /* Need to generate conversion if thenExpr or elseExpr is not of
     * dominant type.  (At least 1 of them must be of the dominant type.)
     */
    if (thenTypeId.typePrecedence() != condTypeId.typePrecedence())
    {
      ValueNode cast = (ValueNode) getNodeFactory().getNode(
                C_NodeTypes.CAST_NODE,
                thenElseList.elementAt(0),
                                getTypeServices()// cast to dominant type
                getContextManager());
      cast = cast.bindExpression(fromList,
                      subqueryList,
                      aggregateVector);
     
      thenElseList.setElementAt(cast, 0);
    }

    else if (elseTypeId.typePrecedence() != condTypeId.typePrecedence())
    {
      ValueNode cast = (ValueNode) getNodeFactory().getNode(
                C_NodeTypes.CAST_NODE,
                thenElseList.elementAt(1),
                                getTypeServices()// cast to dominant type
View Full Code Here

    /*
    ** Generate a CastNode if necessary and
    ** stick it over the original expression
    */
    TypeId condTypeId = getTypeId();
    TypeId thenTypeId = ((ValueNode) thenElseList.elementAt(0)).getTypeId();
    TypeId elseTypeId = ((ValueNode) thenElseList.elementAt(1)).getTypeId();

    /* Need to generate conversion if thenExpr or elseExpr is not of
     * dominant type.  (At least 1 of them must be of the dominant type.)
     */
    if (thenTypeId.typePrecedence() != condTypeId.typePrecedence())
    {
      ValueNode cast = (ValueNode) getNodeFactory().getNode(
                C_NodeTypes.CAST_NODE,
                thenElseList.elementAt(0),
                                getTypeServices()// cast to dominant type
                getContextManager());
      cast = cast.bindExpression(fromList,
                      subqueryList,
                      aggregateVector);
     
      thenElseList.setElementAt(cast, 0);
    }

    else if (elseTypeId.typePrecedence() != condTypeId.typePrecedence())
    {
      ValueNode cast = (ValueNode) getNodeFactory().getNode(
                C_NodeTypes.CAST_NODE,
                thenElseList.elementAt(1),
                                getTypeServices()// cast to dominant type
View Full Code Here

      if (rightOperand.requiresTypeFromContext()) {
        throw StandardException.newException(
            SQLState.LANG_BINARY_OPERANDS_BOTH_PARMS, operator);
      }

      TypeId leftType;

      /*
       * * A ? on the left gets its type from the right. There are eight *
       * legal types for the concatenation operator: CHAR, VARCHAR, * LONG
       * VARCHAR, CLOB, BIT, BIT VARYING, LONG BIT VARYING, and BLOB. * If
       * the right type is BLOB, set the parameter type to BLOB with max
       * length. * If the right type is one of the other bit types, set
       * the parameter type to * BIT VARYING with maximum length. * * If
       * the right type is CLOB, set parameter type to CLOB with max
       * length. * If the right type is anything else, set it to VARCHAR
       * with * maximum length. We count on the resolveConcatOperation
       * method to * catch an illegal type. * * NOTE: When I added the
       * long types, I could have changed the * resulting parameter types
       * to LONG VARCHAR and LONG BIT VARYING, * but they were already
       * VARCHAR and BIT VARYING, and it wasn't * clear to me what effect
       * it would have to change it. - Jeff
       */
      if (rightOperand.getTypeId().isBitTypeId()) {
        if (rightOperand.getTypeId().isBlobTypeId())
          leftType = TypeId.getBuiltInTypeId(Types.BLOB);
        else
          leftType = TypeId.getBuiltInTypeId(Types.VARBINARY);
      } else {
        if (rightOperand.getTypeId().isClobTypeId())
          leftType = TypeId.getBuiltInTypeId(Types.CLOB);
        else
          leftType = TypeId.getBuiltInTypeId(Types.VARCHAR);
      }

      leftOperand.setType(new DataTypeDescriptor(leftType, true));
      if (rightOperand.getTypeId().isStringTypeId()) {
        //collation of ? operand should be picked from the context
        leftOperand.getTypeServices().setCollationDerivation(
            rightOperand.getTypeServices().getCollationDerivation());
        leftOperand.getTypeServices().setCollationType(
            rightOperand.getTypeServices().getCollationType());
      }
    }

    /*
     * Is there a ? parameter on the right?
     */
    if (rightOperand.requiresTypeFromContext()) {
      TypeId rightType;

      /*
       * * A ? on the right gets its type from the left. There are eight *
       * legal types for the concatenation operator: CHAR, VARCHAR, * LONG
       * VARCHAR, CLOB, BIT, BIT VARYING, LONG BIT VARYING, and BLOB. * If
 
View Full Code Here

    // String sqlTypeName = typeId == null ? "OTHER" : typeId.getSQLTypeName();


    String jdbcTypesName = org.apache.derby.impl.jdbc.Util.typeName(sqlType);

    TypeId typeId = TypeId.getBuiltInTypeId(jdbcTypeId);
    String thisTypeName = typeId == null ? declaredClassName : typeId.getSQLTypeName();
       
    StandardException e = StandardException.newException(SQLState.LANG_INVALID_OUT_PARAM_MAP,
          getJDBCParameterNumberStr(),
          jdbcTypesName, thisTypeName);
View Full Code Here

    String columnName;
    String defaultID;
    DefaultInfoImpl    defaultInfo = null;
    ColumnDescriptor colDesc;
    BaseTypeIdImpl    typeId;
    TypeId  wrapperTypeId;
    DataValueDescriptor  defaultValue = null;
    UUID        defaultUUID = null;
    UUID        uuid = null;
    UUIDFactory      uuidFactory = getUUIDFactory();
    long autoincStart, autoincInc;

    DataDescriptorGenerator  ddg = dd.getDataDescriptorGenerator();


    /*
    ** We're going to be getting the UUID for this sucka
    ** so make sure it is a UniqueTupleDescriptor.
    */
    if (parentTupleDescriptor != null)
    {
      if (SanityManager.DEBUG)
      {
        if (!(parentTupleDescriptor instanceof UniqueTupleDescriptor))
        {
          SanityManager.THROWASSERT(parentTupleDescriptor.getClass().getName()
              + " not instanceof UniqueTupleDescriptor")
        }
      }
      uuid = ((UniqueTupleDescriptor)parentTupleDescriptor).getUUID();
    }
    else
    {
      /* 1st column is REFERENCEID (char(36)) */
      uuid = uuidFactory.recreateUUID(row.getColumn(SYSCOLUMNS_REFERENCEID).
                          getString());
    }

    /* NOTE: We get columns 5 and 6 next in order to work around
     * a 1.3.0 HotSpot bug.  (#4361550)
     */

    // 5th column is COLUMNDEFAULT (serialiazable)
    Object object = row.getColumn(SYSCOLUMNS_COLUMNDEFAULT).getObject();
    if (object instanceof DataValueDescriptor)
    {
      defaultValue = (DataValueDescriptor) object;
    }
    else if (object instanceof DefaultInfoImpl)
    {
      defaultInfo = (DefaultInfoImpl) object;
      defaultValue = defaultInfo.getDefaultValue();
    }

    /* 6th column is DEFAULTID (char(36)) */
    defaultID = row.getColumn(SYSCOLUMNS_COLUMNDEFAULTID).getString();

    if (defaultID != null)
    {
      defaultUUID = uuidFactory.recreateUUID(defaultID);
    }

    /* 2nd column is COLUMNNAME (varchar(128)) */
    columnName = row.getColumn(SYSCOLUMNS_COLUMNNAME).getString();

    /* 3rd column is COLUMNNUMBER (int) */
    columnNumber = row.getColumn(SYSCOLUMNS_COLUMNNUMBER).getInt();

    /* 4th column is COLUMNDATATYPE */

    /*
    ** What is stored in the column is a TypeDescriptorImpl, which
    ** points to a BaseTypeIdImpl.  These are simple types that are
    ** intended to be movable to the client, so they don't have
    ** the entire implementation.  We need to wrap them in DataTypeServices
    ** and TypeId objects that contain the full implementations for
    ** language processing.
    */
    TypeDescriptorImpl typeDescriptor = (TypeDescriptorImpl) row.getColumn(SYSCOLUMNS_COLUMNDATATYPE).
                          getObject();
    typeId = typeDescriptor.getTypeId();

    /*
    ** The BaseTypeIdImpl tells what type of TypeId it is supposed to
    ** be wrapped in.
    */
    wrapperTypeId =
      (TypeId) Monitor.newInstanceFromIdentifier(typeId.wrapperTypeFormatId());
    /* Wrap the BaseTypeIdImpl in a full type id */
    wrapperTypeId.setNestedTypeId(typeId);

    /* Wrap the TypeDescriptorImpl in a full DataTypeDescriptor */
    DataTypeDescriptor dataTypeServices = new DataTypeDescriptor(typeDescriptor,
                          wrapperTypeId);

View Full Code Here

    String columnName;
    String defaultID;
    DefaultInfoImpl    defaultInfo = null;
    ColumnDescriptor colDesc;
    BaseTypeIdImpl    typeId;
    TypeId  wrapperTypeId;
    DataValueDescriptor  defaultValue = null;
    UUID        defaultUUID = null;
    UUID        uuid = null;
    UUIDFactory      uuidFactory = getUUIDFactory();
    long autoincStart, autoincInc;

    DataDescriptorGenerator  ddg = dd.getDataDescriptorGenerator();


    /*
    ** We're going to be getting the UUID for this sucka
    ** so make sure it is a UniqueTupleDescriptor.
    */
    if (parentTupleDescriptor != null)
    {
      if (SanityManager.DEBUG)
      {
        if (!(parentTupleDescriptor instanceof UniqueTupleDescriptor))
        {
          SanityManager.THROWASSERT(parentTupleDescriptor.getClass().getName()
              + " not instanceof UniqueTupleDescriptor")
        }
      }
      uuid = ((UniqueTupleDescriptor)parentTupleDescriptor).getUUID();
    }
    else
    {
      /* 1st column is REFERENCEID (char(36)) */
      uuid = uuidFactory.recreateUUID(row.getColumn(SYSCOLUMNS_REFERENCEID).
                          getString());
    }

    /* NOTE: We get columns 5 and 6 next in order to work around
     * a 1.3.0 HotSpot bug.  (#4361550)
     */

    // 5th column is COLUMNDEFAULT (serialiazable)
    Object object = row.getColumn(SYSCOLUMNS_COLUMNDEFAULT).getObject();
    if (object instanceof DataValueDescriptor)
    {
      defaultValue = (DataValueDescriptor) object;
    }
    else if (object instanceof DefaultInfoImpl)
    {
      defaultInfo = (DefaultInfoImpl) object;
      defaultValue = defaultInfo.getDefaultValue();
    }

    /* 6th column is DEFAULTID (char(36)) */
    defaultID = row.getColumn(SYSCOLUMNS_COLUMNDEFAULTID).getString();

    if (defaultID != null)
    {
      defaultUUID = uuidFactory.recreateUUID(defaultID);
    }

    /* 2nd column is COLUMNNAME (varchar(128)) */
    columnName = row.getColumn(SYSCOLUMNS_COLUMNNAME).getString();

    /* 3rd column is COLUMNNUMBER (int) */
    columnNumber = row.getColumn(SYSCOLUMNS_COLUMNNUMBER).getInt();

    /* 4th column is COLUMNDATATYPE */

    /*
    ** What is stored in the column is a TypeDescriptorImpl, which
    ** points to a BaseTypeIdImpl.  These are simple types that are
    ** intended to be movable to the client, so they don't have
    ** the entire implementation.  We need to wrap them in DataTypeServices
    ** and TypeId objects that contain the full implementations for
    ** language processing.
    */
    TypeDescriptorImpl typeDescriptor = (TypeDescriptorImpl) row.getColumn(SYSCOLUMNS_COLUMNDATATYPE).
                          getObject();
    typeId = typeDescriptor.getTypeId();

    /*
    ** The BaseTypeIdImpl tells what type of TypeId it is supposed to
    ** be wrapped in.
    */
    wrapperTypeId =
      (TypeId) Monitor.newInstanceFromIdentifier(typeId.wrapperTypeFormatId());
    /* Wrap the BaseTypeIdImpl in a full type id */
    wrapperTypeId.setNestedTypeId(typeId);

    /* Wrap the TypeDescriptorImpl in a full DataTypeDescriptor */
    DataTypeDescriptor dataTypeServices = new DataTypeDescriptor(typeDescriptor,
                          wrapperTypeId);

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.