Package org.apache.derby.iapi.types

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


            invalidOperandType();
        }
      
        if( operand instanceof ConstantNode)
        {
            DataValueFactory dvf = getLanguageConnectionContext().getDataValueFactory();
            DataValueDescriptor sourceValue = ((ConstantNode) operand).getValue();
            DataValueDescriptor destValue = null;
            if( sourceValue.isNull())
            {
                destValue = (TIMESTAMP_METHOD_NAME.equals( methodName))
                ? dvf.getNullTimestamp( (DateTimeDataValue) null)
                : dvf.getNullDate( (DateTimeDataValue) null);
            }
            else
            {
                destValue = (TIMESTAMP_METHOD_NAME.equals( methodName))
                  ? dvf.getTimestamp( sourceValue) : dvf.getDate( sourceValue);
            }
            return (ValueNode) getNodeFactory().getNode( C_NodeTypes.USERTYPE_CONSTANT_NODE,
                                                         destValue, getContextManager());
        }
View Full Code Here


   */
  private DataValueDescriptor convertConstant(TypeId toTypeId, int maxWidth, DataValueDescriptor constantValue)
    throws StandardException
  {
    int formatId = toTypeId.getTypeFormatId();
    DataValueFactory dvf = getDataValueFactory();
    switch (formatId)
    {
      default:
      case StoredFormatIds.CHAR_TYPE_ID:
        return constantValue;

      case StoredFormatIds.VARCHAR_TYPE_ID:
      case StoredFormatIds.NATIONAL_CHAR_TYPE_ID:
      case StoredFormatIds.NATIONAL_VARCHAR_TYPE_ID:
        String sourceValue = constantValue.getString();
        int sourceWidth = sourceValue.length();
        int posn;

        /*
        ** If the input is already the right length, no normalization is
        ** necessary - just return the source.
        **
        */

        if (sourceWidth <= maxWidth)
        {
          switch (formatId)
          {
            // For NCHAR we must pad the result, saves on normilization later if all
            // constants are of the correct size
            case StoredFormatIds.NATIONAL_CHAR_TYPE_ID:

              if (sourceWidth < maxWidth)
              {
                StringBuffer stringBuffer = new StringBuffer(sourceValue);

                int needed = maxWidth - sourceWidth;
                char blankArray[] = new char[needed];
                for (int i = 0; i < needed; i++)
                  blankArray[i] = ' ';
                stringBuffer.append(blankArray, 0,
                        maxWidth - sourceWidth);
                sourceValue = stringBuffer.toString();
              }
              return dvf.getNationalCharDataValue(sourceValue);

            case StoredFormatIds.NATIONAL_VARCHAR_TYPE_ID:
              return dvf.getNationalVarcharDataValue(sourceValue);

            case StoredFormatIds.VARCHAR_TYPE_ID:
              return dvf.getVarcharDataValue(sourceValue);
          }
        }

        /*
        ** Check whether any non-blank characters will be truncated.
        */
        for (posn = maxWidth; posn < sourceWidth; posn++)
        {
          if (sourceValue.charAt(posn) != ' ')
          {
            String typeName = null;
            switch (formatId)
            {
              case StoredFormatIds.NATIONAL_CHAR_TYPE_ID:
                typeName = TypeId.NATIONAL_CHAR_NAME;
                break;

              case StoredFormatIds.NATIONAL_VARCHAR_TYPE_ID:
                typeName = TypeId.NATIONAL_VARCHAR_NAME;
                break;

              case StoredFormatIds.VARCHAR_TYPE_ID:
                typeName = TypeId.VARCHAR_NAME;
                break;
            }
            throw StandardException.newException(SQLState.LANG_STRING_TRUNCATION,
                           typeName,
                           StringUtil.formatForPrint(sourceValue),
                           String.valueOf(maxWidth));
          }
        }

        switch (formatId)
        {
          case StoredFormatIds.NATIONAL_CHAR_TYPE_ID:
            return dvf.getNationalCharDataValue(sourceValue.substring(0, maxWidth));

          case StoredFormatIds.NATIONAL_VARCHAR_TYPE_ID:
            return dvf.getNationalVarcharDataValue(sourceValue.substring(0, maxWidth));

          case StoredFormatIds.VARCHAR_TYPE_ID:
            return dvf.getVarcharDataValue(sourceValue.substring(0, maxWidth));
        }

      case StoredFormatIds.LONGVARCHAR_TYPE_ID:
        //No need to check widths here (unlike varchar), since no max width
        return dvf.getLongvarcharDataValue(constantValue.getString());

      case StoredFormatIds.NATIONAL_LONGVARCHAR_TYPE_ID:
        //No need to check widths here (unlike varchar), since no max width
        return dvf.getNationalLongvarcharDataValue(constantValue.getString());

    }
  }
View Full Code Here

    RowLocation        rl = null;
    RowLocation        scanRL = null;
    ScanController      scan = null;
    int[]          baseColumnPositions;
    int            baseColumns = 0;
    DataValueFactory    dvf;
    long          indexRows;
    ConglomerateController  baseCC = null;
    ConglomerateController  indexCC = null;
    ExecutionContext    ec;
    SchemaDescriptor    sd;
View Full Code Here

   */
  private DataValueDescriptor convertConstant(TypeId toTypeId, int maxWidth, DataValueDescriptor constantValue)
    throws StandardException
  {
    int formatId = toTypeId.getTypeFormatId();
    DataValueFactory dvf = getDataValueFactory();
    switch (formatId)
    {
      default:
      case StoredFormatIds.CHAR_TYPE_ID:
        return constantValue;

      case StoredFormatIds.VARCHAR_TYPE_ID:
      case StoredFormatIds.NATIONAL_CHAR_TYPE_ID:
      case StoredFormatIds.NATIONAL_VARCHAR_TYPE_ID:
        String sourceValue = constantValue.getString();
        int sourceWidth = sourceValue.length();
        int posn;

        /*
        ** If the input is already the right length, no normalization is
        ** necessary - just return the source.
        **
        */

        if (sourceWidth <= maxWidth)
        {
          switch (formatId)
          {
            // For NCHAR we must pad the result, saves on normilization later if all
            // constants are of the correct size
            case StoredFormatIds.NATIONAL_CHAR_TYPE_ID:

              if (sourceWidth < maxWidth)
              {
                StringBuffer stringBuffer = new StringBuffer(sourceValue);

                int needed = maxWidth - sourceWidth;
                char blankArray[] = new char[needed];
                for (int i = 0; i < needed; i++)
                  blankArray[i] = ' ';
                stringBuffer.append(blankArray, 0,
                        maxWidth - sourceWidth);
                sourceValue = stringBuffer.toString();
              }
              return dvf.getNationalCharDataValue(sourceValue);

            case StoredFormatIds.NATIONAL_VARCHAR_TYPE_ID:
              return dvf.getNationalVarcharDataValue(sourceValue);

            case StoredFormatIds.VARCHAR_TYPE_ID:
              return dvf.getVarcharDataValue(sourceValue);
          }
        }

        /*
        ** Check whether any non-blank characters will be truncated.
        */
        for (posn = maxWidth; posn < sourceWidth; posn++)
        {
          if (sourceValue.charAt(posn) != ' ')
          {
            String typeName = null;
            switch (formatId)
            {
              case StoredFormatIds.NATIONAL_CHAR_TYPE_ID:
                typeName = TypeId.NATIONAL_CHAR_NAME;
                break;

              case StoredFormatIds.NATIONAL_VARCHAR_TYPE_ID:
                typeName = TypeId.NATIONAL_VARCHAR_NAME;
                break;

              case StoredFormatIds.VARCHAR_TYPE_ID:
                typeName = TypeId.VARCHAR_NAME;
                break;
            }
            throw StandardException.newException(SQLState.LANG_STRING_TRUNCATION,
                           typeName,
                           StringUtil.formatForPrint(sourceValue),
                           String.valueOf(maxWidth));
          }
        }

        switch (formatId)
        {
          case StoredFormatIds.NATIONAL_CHAR_TYPE_ID:
            return dvf.getNationalCharDataValue(sourceValue.substring(0, maxWidth));

          case StoredFormatIds.NATIONAL_VARCHAR_TYPE_ID:
            return dvf.getNationalVarcharDataValue(sourceValue.substring(0, maxWidth));

          case StoredFormatIds.VARCHAR_TYPE_ID:
            return dvf.getVarcharDataValue(sourceValue.substring(0, maxWidth));
        }

      case StoredFormatIds.LONGVARCHAR_TYPE_ID:
        //No need to check widths here (unlike varchar), since no max width
        return dvf.getLongvarcharDataValue(constantValue.getString());

      case StoredFormatIds.NATIONAL_LONGVARCHAR_TYPE_ID:
        //No need to check widths here (unlike varchar), since no max width
        return dvf.getNationalLongvarcharDataValue(constantValue.getString());

    }
  }
View Full Code Here

        //depending on the collation type.
        if (newValue instanceof StringDataValue)
        {
                    constant.setCollationInfo(resultColumnType);
                   
          DataValueFactory dvf = getDataValueFactory();
          newValue = ((StringDataValue)newValue).getValue(dvf.getCharacterCollator(
              constant.getTypeServices().getCollationType()));
          constant.setValue(newValue);
        }
      }
      if ( ! resultColumnType.getTypeId().equals(
View Full Code Here

  private DataValueDescriptor convertConstant(TypeId toTypeId, int maxWidth,
      DataValueDescriptor constantValue)
    throws StandardException
  {
    int formatId = toTypeId.getTypeFormatId();
    DataValueFactory dvf = getDataValueFactory();
    switch (formatId)
    {
      default:
      case StoredFormatIds.CHAR_TYPE_ID:
        return constantValue;

      case StoredFormatIds.VARCHAR_TYPE_ID:
        String sourceValue = constantValue.getString();
        int sourceWidth = sourceValue.length();
        int posn;

        /*
        ** If the input is already the right length, no normalization is
        ** necessary - just return the source.
        **
        */

        if (sourceWidth <= maxWidth)
        {
          if(formatId == StoredFormatIds.VARCHAR_TYPE_ID)
            return dvf.getVarcharDataValue(sourceValue);
        }

        /*
        ** Check whether any non-blank characters will be truncated.
        */
        for (posn = maxWidth; posn < sourceWidth; posn++)
        {
          if (sourceValue.charAt(posn) != ' ')
          {
            String typeName = null;
            if (formatId == StoredFormatIds.VARCHAR_TYPE_ID)
                typeName = TypeId.VARCHAR_NAME;
            throw StandardException.newException(SQLState.LANG_STRING_TRUNCATION,
                           typeName,
                           StringUtil.formatForPrint(sourceValue),
                           String.valueOf(maxWidth));
          }
        }

        if (formatId == StoredFormatIds.VARCHAR_TYPE_ID)
          return dvf.getVarcharDataValue(sourceValue.substring(0, maxWidth));

      case StoredFormatIds.LONGVARCHAR_TYPE_ID:
        //No need to check widths here (unlike varchar), since no max width
        return dvf.getLongvarcharDataValue(constantValue.getString());

    }
  }
View Full Code Here

        //depending on the collation type.
        if (newValue instanceof StringDataValue)
        {
                    constant.setCollationInfo(resultColumnType);
                   
          DataValueFactory dvf = getDataValueFactory();
          newValue = ((StringDataValue)newValue).getValue(dvf.getCharacterCollator(
              constant.getTypeServices().getCollationType()));
          constant.setValue(newValue);
        }
      }
      if ( ! resultColumnType.getTypeId().equals(
View Full Code Here

  private DataValueDescriptor convertConstant(TypeId toTypeId, int maxWidth,
      DataValueDescriptor constantValue)
    throws StandardException
  {
    int formatId = toTypeId.getTypeFormatId();
    DataValueFactory dvf = getDataValueFactory();
    switch (formatId)
    {
      default:
      case StoredFormatIds.CHAR_TYPE_ID:
        return constantValue;

      case StoredFormatIds.VARCHAR_TYPE_ID:
        String sourceValue = constantValue.getString();
        int sourceWidth = sourceValue.length();
        int posn;

        /*
        ** If the input is already the right length, no normalization is
        ** necessary - just return the source.
        **
        */

        if (sourceWidth <= maxWidth)
        {
          if(formatId == StoredFormatIds.VARCHAR_TYPE_ID)
            return dvf.getVarcharDataValue(sourceValue);
        }

        /*
        ** Check whether any non-blank characters will be truncated.
        */
        for (posn = maxWidth; posn < sourceWidth; posn++)
        {
          if (sourceValue.charAt(posn) != ' ')
          {
            String typeName = null;
            if (formatId == StoredFormatIds.VARCHAR_TYPE_ID)
                typeName = TypeId.VARCHAR_NAME;
            throw StandardException.newException(SQLState.LANG_STRING_TRUNCATION,
                           typeName,
                           StringUtil.formatForPrint(sourceValue),
                           String.valueOf(maxWidth));
          }
        }

        if (formatId == StoredFormatIds.VARCHAR_TYPE_ID)
          return dvf.getVarcharDataValue(sourceValue.substring(0, maxWidth));

      case StoredFormatIds.LONGVARCHAR_TYPE_ID:
        //No need to check widths here (unlike varchar), since no max width
        return dvf.getLongvarcharDataValue(constantValue.getString());

    }
  }
View Full Code Here

        DataValueDescriptor[] ret_row =
            new DataValueDescriptor[num_cols_to_allocate];
        int         num_cols =
            (column_list == null ? format_ids.length : column_list.size());

        DataValueFactory dvf = rawtran.getDataValueFactory();

        for (int i = 0; i < num_cols; i++)
        {
            // does caller want this column?
            if ((column_list != null) && (!column_list.get(i)))
            {
                // no - column should be skipped.
            }
            else
            {
                // yes - create the column

                // get empty instance of object identified by the format id.
                ret_row[i] = dvf.getNull(format_ids[i], collation_ids[i]);

                if (SanityManager.DEBUG)
                {
                    DataValueDescriptor o = ret_row[i];
View Full Code Here

            invalidOperandType();
        }
      
        if( operand instanceof ConstantNode)
        {
            DataValueFactory dvf = getLanguageConnectionContext().getDataValueFactory();
            DataValueDescriptor sourceValue = ((ConstantNode) operand).getValue();
            DataValueDescriptor destValue = null;
            if( sourceValue.isNull())
            {
                destValue = (TIMESTAMP_METHOD_NAME.equals( methodName))
                ? dvf.getNullTimestamp( (DateTimeDataValue) null)
                : dvf.getNullDate( (DateTimeDataValue) null);
            }
            else
            {
                destValue = (TIMESTAMP_METHOD_NAME.equals( methodName))
                  ? dvf.getTimestamp( sourceValue) : dvf.getDate( sourceValue);
            }
            return (ValueNode) getNodeFactory().getNode( C_NodeTypes.USERTYPE_CONSTANT_NODE,
                                                         destValue, getContextManager());
        }
View Full Code Here

TOP

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

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.