Package org.apache.derby.iapi.types

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


      boolean pushStack = false;
            EmbedConnection ec = getEmbedConnection();
      try {

        StringDataValue dvd = (StringDataValue)getColumn(columnIndex);
                LanguageConnectionContext lcc = ec.getLanguageConnection();

                if (wasNull = dvd.isNull()) {
                    InterruptStatus.restoreIntrFlagIfSeen();
          return null;
                }

                // Set up a context stack if we have CLOB whose value is a long
                // column in the database.
                if (dvd.hasStream()) {
                    pushStack = true;
                    setupContextStack();
                }

                EmbedClob result =  new EmbedClob(ec, dvd);
View Full Code Here


            case Types.CLOB:
                boolean pushStack = false;
                Object syncObject = getConnectionSynchronization();
                synchronized (syncObject) {
                    try {
                        StringDataValue param = (StringDataValue) getParms().getParameterForGet(parameterIndex - 1);
                        if (param.isNull()) {
                            break;
                        }
                        pushStack = true;
                        setupContextStack();

                        if (param.hasStream()) {
                            CharacterStreamDescriptor csd =
                                    param.getStreamWithDescriptor();
                            reader = new UTF8Reader(csd, this, syncObject);
                        } else {
                            reader = new StringReader(param.getString());
                        }
                    } catch (Throwable t) {
                        throw EmbedResultSet.noStateChangeException(t);
                    } finally {
                        if (pushStack) {
View Full Code Here

    ValueNode evaluateConstantExpressions() throws StandardException {
        if (leftOperand instanceof CharConstantNode &&
                rightOperand instanceof CharConstantNode) {
            CharConstantNode leftOp = (CharConstantNode) leftOperand;
            CharConstantNode rightOp = (CharConstantNode) rightOperand;
            StringDataValue leftValue = (StringDataValue) leftOp.getValue();
            StringDataValue rightValue = (StringDataValue) rightOp.getValue();

            StringDataValue resultValue =
                    (StringDataValue) getTypeServices().getNull();
            resultValue.concatenate(leftValue, rightValue, resultValue);

            return new CharConstantNode(
                resultValue.getString(), getContextManager());
        }

        return this;
    }
View Full Code Here

            case Types.CLOB:
                boolean pushStack = false;
                Object syncObject = getConnectionSynchronization();
                synchronized (syncObject) {
                try {
                    StringDataValue param = (StringDataValue)
                        getParms().getParameterForGet(parameterIndex -1);
                    if (param.isNull()) {
                        break;
                    }
                    pushStack = true;
                    setupContextStack();

                    if (param.hasStream()) {
                        CharacterStreamDescriptor csd =
                            param.getStreamWithDescriptor();
                        reader = new UTF8Reader(csd, this, syncObject);
                    } else {
                        reader = new StringReader(param.getString());
                    }
                } catch (Throwable t) {
                    throw EmbedResultSet.noStateChangeException(t);
                } finally {
                    if (pushStack) {
View Full Code Here

    boolean pushStack = false;
    try {

            useStreamOrLOB(columnIndex);

            StringDataValue dvd = (StringDataValue)getColumn(columnIndex);

      if (wasNull = dvd.isNull()) { return null; }

      pushStack = true;
      setupContextStack();

            java.io.Reader ret; // The reader we will return to the user
            if (dvd.hasStream()) {
                CharacterStreamDescriptor csd = dvd.getStreamWithDescriptor();
                // See if we have to enforce a max field size.
                if (lmfs > 0) {
                    csd = new CharacterStreamDescriptor.Builder().copyState(csd).
                            maxCharLength(lmfs).build();
                }
                ret = new UTF8Reader(csd, this, syncLock);
            } else {
        String val = dvd.getString();
        if (lmfs > 0) {
          if (val.length() > lmfs)
            val = val.substring(0, lmfs);
        }
                ret = new java.io.StringReader(val);
View Full Code Here

            {
                updateNull(columnIndex);
                return;
            }
           
            final StringDataValue dvd = (StringDataValue)
                    getDVDforColumnToBeUpdated(columnIndex, updateMethodName);
            // In the case of updatable result sets, we cannot guarantee that a
            // context is pushed when the header needs to be generated. To fix
            // this, tell the DVD/generator which header format to use.
            dvd.setStreamHeaderFormat(Boolean.valueOf(
                    !getEmbedConnection().getDatabase().getDataDictionary().
                    checkVersion(DataDictionary.DD_VERSION_DERBY_10_5, null)));
            ReaderToUTF8Stream utfIn;
            int usableLength = DataValueDescriptor.UNKNOWN_LOGICAL_LENGTH;
            if (!lengthLess) {
                // check for -ve length here
                if (length < 0)
                    throw newSQLException(SQLState.NEGATIVE_STREAM_LENGTH);

                // max number of characters that can be set to be inserted
                // in Derby is 2Gb-1 (ie Integer.MAX_VALUE).
                // (e.g into a CLOB column).
                if (length > Integer.MAX_VALUE ) {
                    throw newSQLException(
                            SQLState.LANG_OUTSIDE_RANGE_FOR_DATATYPE,
                            getColumnSQLType(columnIndex));
                }

                // length is +ve. at this point, all checks for negative
                // length has already been done
                usableLength = (int) length;
                int truncationLength = 0;

                // Currently long varchar does not allow for truncation of
                // trailing blanks.  For char and varchar types, current
                // mechanism of materializing when using streams seems fine
                // given their max limits. This change is fix for DERBY-352:
                // Insert of clobs using streams should not materialize the
                // entire stream into memory
                // In case of clobs, the truncation of trailing blanks is
                // factored in when reading from the stream without
                // materializing the entire stream, and so the special casing
                // for clob below.
                if (getColumnType(columnIndex) == Types.CLOB) {
                    // Need column width to figure out if truncation is
                    // needed
                    int colWidth = getMaxColumnWidth(columnIndex);

                    // It is possible that the length of the stream passed in
                    // is greater than the column width, in which case the data
                    // from the stream needs to be truncated.
                    // usableLength is the length of the data from stream
                    // that can be used which is min(colWidth,length) provided
                    // length - colWidth has trailing blanks only
                    if (usableLength > colWidth) {
                        truncationLength = usableLength - colWidth;
                        usableLength = colWidth;
                    }
                }

                utfIn = new ReaderToUTF8Stream(reader, usableLength,
                        truncationLength, getColumnSQLType(columnIndex),
                        dvd.getStreamHeaderGenerator());
            } else {
                int colWidth = getMaxColumnWidth(columnIndex);
                utfIn = new ReaderToUTF8Stream(reader, colWidth,
                                               getColumnSQLType(columnIndex),
                                               dvd.getStreamHeaderGenerator());
            }

            dvd.setValue(utfIn, usableLength);
        } catch (StandardException t) {
            throw noStateChangeException(t);
        }
  }
View Full Code Here

      boolean pushStack = false;
            EmbedConnection ec = getEmbedConnection();
      try {

        StringDataValue dvd = (StringDataValue)getColumn(columnIndex);
                LanguageConnectionContext lcc = ec.getLanguageConnection();

                if (wasNull = dvd.isNull()) {
                    InterruptStatus.restoreIntrFlagIfSeen();
          return null;
                }

                // Set up a context stack if we have CLOB whose value is a long
                // column in the database.
                if (dvd.hasStream()) {
                    pushStack = true;
                    setupContextStack();
                }

                EmbedClob result =  new EmbedClob(ec, dvd);
View Full Code Here

    ValueNode evaluateConstantExpressions() throws StandardException {
        if (leftOperand instanceof CharConstantNode &&
                rightOperand instanceof CharConstantNode) {
            CharConstantNode leftOp = (CharConstantNode) leftOperand;
            CharConstantNode rightOp = (CharConstantNode) rightOperand;
            StringDataValue leftValue = (StringDataValue) leftOp.getValue();
            StringDataValue rightValue = (StringDataValue) rightOp.getValue();

            StringDataValue resultValue =
                    (StringDataValue) getTypeServices().getNull();
            resultValue.concatenate(leftValue, rightValue, resultValue);

            return (ValueNode) getNodeFactory().getNode(
                    C_NodeTypes.CHAR_CONSTANT_NODE,
                    resultValue.getString(),
                    getContextManager());
        }

        return this;
    }
View Full Code Here

                int maxLen)
        throws StandardException
    {
        int startInt;
        int lengthInt;
        StringDataValue stringResult;

        if (result == null)
        {
            result = getNewVarchar();
        }

        stringResult = (StringDataValue) result;

        /* The result is null if the receiver (this) is null or if the length
         * is negative.
         * We will return null, which is the only sensible thing to do.
         * (If user did not specify a length then length is not a user null.)
         */
        if (this.isNull() || start.isNull() ||
                (length != null && length.isNull()))
        {
            stringResult.setToNull();
            return stringResult;
        }

        startInt = start.getInt();

        // If length is not specified, make it till end of the string
        if (length != null)
        {
            lengthInt = length.getInt();
        }
        else lengthInt = maxLen - startInt + 1;

        /* DB2 Compatibility: Added these checks to match DB2. We currently
         * enforce these limits in both modes. We could do these checks in DB2
         * mode only, if needed, so leaving earlier code for out of range in
         * for now, though will not be exercised
         */
        if ((startInt <= 0 || lengthInt < 0 || startInt > maxLen ||
                lengthInt > maxLen - startInt + 1))
        {
            throw StandardException.newException(
                    SQLState.LANG_SUBSTR_START_OR_LEN_OUT_OF_RANGE);
        }
           
        // Return null if length is non-positive
        if (lengthInt < 0)
        {
            stringResult.setToNull();
            return stringResult;
        }

        /* If startInt < 0 then we count from the right of the string */
        if (startInt < 0)
        {
            // Return '' if window is to left of string.
            if (startInt + getLength() < 0 &&
                (startInt + getLength() + lengthInt <= 0))
            {
                stringResult.setValue("");
                return stringResult;
            }

            // Convert startInt to positive to get substring from right
            startInt += getLength();

            while (startInt < 0)
            {
                startInt++;
                lengthInt--;
            }
        }
        else if (startInt > 0)
        {
            /* java substring() is 0 based */
            startInt--;
        }

        /* Oracle docs don't say what happens if the window is to the
         * left of the string.  Return "" if the window
         * is to the left or right.
         */
        if (lengthInt == 0 ||
            lengthInt <= 0 - startInt ||
            startInt > getLength())
        {
            stringResult.setValue("");
            return stringResult;
        }

        if (lengthInt >= getLength() - startInt)
        {
            stringResult.setValue(getString().substring(startInt));
        }
        else
        {
            stringResult.setValue(
                getString().substring(startInt, startInt + lengthInt));
        }

        return stringResult;
    }
View Full Code Here

               throw newSQLException(SQLState.LANG_OUTSIDE_RANGE_FOR_DATATYPE,
                                     getParameterSQLType(parameterIndex));

        try {
            ReaderToUTF8Stream utfIn;
            final StringDataValue dvd = (StringDataValue)
                    getParms().getParameter(parameterIndex -1);
            dvd.setStreamHeaderFormat(usePreTenFiveHdrFormat());
            // Need column width to figure out if truncation is needed
            DataTypeDescriptor dtd[] = preparedStatement
                    .getParameterTypes();
            int colWidth = dtd[parameterIndex - 1].getMaximumWidth();
            // Holds either UNKNOWN_LOGICAL_LENGTH or the exact logical length.
            int usableLength = DataValueDescriptor.UNKNOWN_LOGICAL_LENGTH;

            if (!lengthLess) {
                // We cast the length from long to int. This wouldn't be
                // appropriate if the limit of 2G-1 is decided to be increased
                // at a later stage.
                usableLength = (int)length;
                int truncationLength = 0;

                // Currently long varchar does not allow for truncation of
                // trailing blanks.
                // For char and varchar types, current mechanism of
                // materializing when using streams seems fine given their max
                // limits.
                // This change is fix for DERBY-352: Insert of clobs using
                // streams should not materialize the entire stream into memory
                // In case of clobs, the truncation of trailing blanks is
                // factored in when reading from the stream without
                // materializing the entire stream, and so the special casing
                // for clob below.
                if (jdbcTypeId == Types.CLOB)
                {

                    // It is possible that the length of the stream passed in
                    // is greater than the column width, in which case the data
                    // from the stream needs to be truncated.
                    // usableLength is the length of the data from stream that
                    // can be inserted which is min(colWidth,length) provided
                    // length - colWidth has trailing blanks only
                    if (usableLength > colWidth) {
                        truncationLength = usableLength - colWidth;
                        usableLength = colWidth;
                    }
                }
                // Create a stream with truncation.
                utfIn = new ReaderToUTF8Stream(reader, usableLength,
                        truncationLength, getParameterSQLType(parameterIndex),
                        dvd.getStreamHeaderGenerator());
            } else {
                // Create a stream without exactness checks,
                // but with a maximum limit.
                utfIn = new ReaderToUTF8Stream(reader, colWidth,
                        getParameterSQLType(parameterIndex),
                        dvd.getStreamHeaderGenerator());
            }

            // JDBC is one-based, DBMS is zero-based.
            // Note that for lengthless stream, usableLength will be
            // the maximum length for the column.
View Full Code Here

TOP

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

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.