Package org.apache.derby.iapi.types

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


   * @exception StandardException    Thrown on error
   */
  public void typeUntypedNullExpression( ResultColumn bindingRC)
      throws StandardException
  {
        TypeId typeId = bindingRC.getTypeId();
    /* This is where we catch null in a VALUES clause outside
     * of INSERT VALUES()
     */
    if (typeId == null)
    {
View Full Code Here


    @exception StandardException thrown if types not suitable.
   */
  public void checkStorableExpression(ResultColumn toStore)
          throws StandardException
  {
    TypeId columnTypeId, toStoreTypeId;

    toStoreTypeId = toStore.getTypeId();
        if( toStoreTypeId == null)
            return;
       
    columnTypeId = getTypeId();

    if (! getTypeCompiler().storable(toStoreTypeId, getClassFactory()))
      throw StandardException.newException(SQLState.LANG_NOT_STORABLE,
        columnTypeId.getSQLTypeName(),
        toStoreTypeId.getSQLTypeName() );
  }
View Full Code Here

    @exception StandardException thrown if types not suitable.
   */
  public void checkStorableExpression()
          throws StandardException
  {
    TypeId columnTypeId = getTypeId();
    TypeId toStoreTypeId = getExpressionType().getTypeId();

    if (! getTypeCompiler().storable(toStoreTypeId, getClassFactory()))
      throw StandardException.newException(SQLState.LANG_NOT_STORABLE,
        columnTypeId.getSQLTypeName(),
        toStoreTypeId.getSQLTypeName() );
  }
View Full Code Here

   * @return  The TypeId from this Node.  This
   *    may be null if the node isn't bound yet.
   */
  public TypeId getTypeId() throws StandardException
  {
        TypeId t = super.getTypeId();
        if( t == null)
        {
            if( expression != null)
            {
                DataTypeDescriptor dtd = getTypeServices();
View Full Code Here

        optimizeDomainValueConversion();
     
      TypeDescriptor returnType = routineInfo.getReturnType();
      if (returnType != null)
      {
        TypeId returnTypeId = TypeId.getBuiltInTypeId(returnType.getJDBCTypeId());

        if (returnTypeId.variableLength()) {
          // Cast the return using a cast node, but have to go
          // into the SQL domain, and back to the Java domain.

          DataTypeDescriptor returnValueDtd = new DataTypeDescriptor(
                returnTypeId,
View Full Code Here

        // find the declared type.

        TypeDescriptor td = parameterTypes[p];

        TypeId typeId = TypeId.getBuiltInTypeId(td.getJDBCTypeId());

        TypeId parameterTypeId = typeId;


        // if it's an OUT or INOUT parameter we need an array.
        int parameterMode = routineInfo.getParameterModes()[p];

        if (parameterMode != JDBC30Translation.PARAMETER_MODE_IN) {

          String arrayType;
          switch (typeId.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:
              arrayType = getTypeCompiler(typeId).getCorrespondingPrimitiveTypeName().concat("[]");
              break;
            default:
              arrayType = typeId.getCorrespondingJavaTypeName().concat("[]");
              break;
          }

          typeId = TypeId.getUserDefinedTypeId(arrayType, false);
        }

        // this is the type descriptor of the require method parameter
        DataTypeDescriptor methoddtd = new DataTypeDescriptor(
            typeId,
            td.getPrecision(),
            td.getScale(),
            td.isNullable(),
            td.getMaximumWidth()
          );

        signature[p] = new JSQLType(methoddtd);

        // check parameter is a ? node for INOUT and OUT parameters.

        ValueNode sqlParamNode = null;

        if (methodParms[p] instanceof SQLToJavaValueNode) {
          SQLToJavaValueNode sql2j = (SQLToJavaValueNode) methodParms[p];
          sqlParamNode = sql2j.getSQLValueNode();
        }
        else
        {
        }

        boolean isParameterMarker = true;
        if ((sqlParamNode == null) || !sqlParamNode.requiresTypeFromContext())
        {
          if (parameterMode != JDBC30Translation.PARAMETER_MODE_IN) {
          
            throw StandardException.newException(SQLState.LANG_DB2_PARAMETER_NEEDS_MARKER,
              RoutineAliasInfo.parameterMode(parameterMode),
              routineInfo.getParameterNames()[p]);
          }
          isParameterMarker = false;
        }
        else
        {
          if (applicationParameterNumbers == null)
            applicationParameterNumbers = new int[parameterCount];
            if (sqlParamNode instanceof UnaryOperatorNode) {
              ParameterNode pn = ((UnaryOperatorNode)sqlParamNode).getParameterOperand();
              applicationParameterNumbers[p] = pn.getParameterNumber();
            } else
            applicationParameterNumbers[p] = ((ParameterNode) sqlParamNode).getParameterNumber();
        }

        // this is the SQL type of the procedure parameter.
        DataTypeDescriptor paramdtd = new DataTypeDescriptor(
          parameterTypeId,
          td.getPrecision(),
          td.getScale(),
          td.isNullable(),
          td.getMaximumWidth()
        );

        boolean needCast = false;
        if (!isParameterMarker)
        {

          // can only be an IN parameter.
          // check that the value can be assigned to the
          // type of the procedure parameter.
          if (sqlParamNode instanceof UntypedNullConstantNode)
          {
            sqlParamNode.setType(paramdtd);
          }
          else
          {


            DataTypeDescriptor dts;
            TypeId argumentTypeId;

            if (sqlParamNode != null)
            {
              // a node from the SQL world
              argumentTypeId = sqlParamNode.getTypeId();
              dts = sqlParamNode.getTypeServices();
            }
            else
            {
              // a node from the Java world
              dts = DataTypeDescriptor.getSQLDataTypeDescriptor(methodParms[p].getJavaTypeName());
              if (dts == null)
              {
                throw StandardException.newException(SQLState.LANG_NO_CORRESPONDING_S_Q_L_TYPE,
                  methodParms[p].getJavaTypeName());
              }

              argumentTypeId = dts.getTypeId();
            }

            if (! getTypeCompiler(parameterTypeId).storable(argumentTypeId, getClassFactory()))
                throw StandardException.newException(SQLState.LANG_NOT_STORABLE,
                  parameterTypeId.getSQLTypeName(),
                  argumentTypeId.getSQLTypeName() );

            // if it's not an exact length match then some cast will be needed.
            if (!paramdtd.isExactTypeAndLengthMatch(dts))
              needCast = true;
          }
        }
        else
        {
          // any variable length type will need a cast from the
          // Java world (the ? parameter) to the SQL type. This
          // ensures values like CHAR(10) are passed into the procedure
          // correctly as 10 characters long.
          if (parameterTypeId.variableLength()) {

            if (parameterMode != JDBC30Translation.PARAMETER_MODE_OUT)
              needCast = true;
          }
        }
       

        if (needCast)
        {
          // push a cast node to ensure the
          // correct type is passed to the method
          // this gets tacky because before we knew
          // it was a procedure call we ensured all the
          // parameter are JavaNodeTypes. Now we need to
          // push them back to the SQL domain, cast them
          // and then push them back to the Java domain.

          if (sqlParamNode == null) {

            sqlParamNode = (ValueNode) getNodeFactory().getNode(
              C_NodeTypes.JAVA_TO_SQL_VALUE_NODE,
              methodParms[p],
              getContextManager());
          }

          ValueNode castNode = (ValueNode) getNodeFactory().getNode(
            C_NodeTypes.CAST_NODE,
            sqlParamNode,
            paramdtd,
            getContextManager());


          methodParms[p] = (JavaValueNode) getNodeFactory().getNode(
              C_NodeTypes.SQL_TO_JAVA_VALUE_NODE,
              castNode,
              getContextManager());

          methodParms[p] = methodParms[p].bindExpression(fromList, subqueryList, aggregateVector);
        }

        // only force the type for a ? so that the correct type shows up
        // in parameter meta data
        if (isParameterMarker)
          sqlParamNode.setType(paramdtd);
      }

      if (sigParameterCount != parameterCount) {

        TypeId typeId = TypeId.getUserDefinedTypeId("java.sql.ResultSet[]", false);

        DataTypeDescriptor dtd = new DataTypeDescriptor(
            typeId,
            0,
            0,
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());
    }

    /* Is there a ? parameter on the left? */
    if (leftOperand.requiresTypeFromContext())
    {
      /* Set the left operand type to varchar. */
      leftOperand.setType(getVarcharDescriptor());
    }

    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) ||
       (receiverType.getTypeFormatId() == StoredFormatIds.NCLOB_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());
      }
      else
      {
        if( leftOperand.getTypeId().isStringTypeId() )
        {
          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());
        }
      }
    }

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

    // handle parameters here

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

                        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

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.