Class Request

    • Field Detail

      • buffer

        protected java.nio.ByteBuffer buffer
      • markStack_

        private int[] markStack_
      • top_

        private int top_
      • dssLengthLocation_

        private int dssLengthLocation_
      • correlationID_

        private int correlationID_
      • simpleDssFinalize

        private boolean simpleDssFinalize
      • passwordIncluded_

        protected boolean passwordIncluded_
      • passwordStart_

        protected int passwordStart_
      • passwordLength_

        protected int passwordLength_
      • netAgent_

        protected NetAgent netAgent_
    • Constructor Detail

      • Request

        Request​(NetAgent netAgent,
                int minSize)
    • Method Detail

      • clearBuffer

        private final void clearBuffer()
      • initialize

        final void initialize()
      • ensureLength

        private final void ensureLength​(int length)
      • createCommand

        protected final void createCommand()
      • createCommandData

        final void createCommandData()
      • createEncryptedCommandData

        final void createEncryptedCommandData()
      • buildDss

        private final void buildDss​(boolean dssHasSameCorrelator,
                                    boolean chainedToNextStructure,
                                    boolean nextHasSameCorrelator,
                                    int dssType,
                                    int corrId,
                                    boolean simpleFinalizeBuildingNextDss)
      • writePlainScalarStream

        private final void writePlainScalarStream​(boolean chained,
                                                  boolean chainedWithSameCorrelator,
                                                  int codePoint,
                                                  long length,
                                                  java.io.InputStream in,
                                                  boolean writeNullByte,
                                                  int parameterIndex)
                                           throws DisconnectException,
                                                  SqlException
        Writes a stream with a known length onto the wire.

        To avoid DRDA protocol exceptions, the data is truncated or padded as required to complete the transfer. This can be avoided by implementing the request abort mechanism specified by DRDA, but it is rather complex and may not be worth the trouble.

        Also note that any exceptions generated while writing the stream will be accumulated and raised at a later time.

        Parameters:
        length - the byte length of the stream
        in - the stream to transfer
        writeNullByte - whether or not to write a NULL indicator
        parameterIndex - one-based parameter index
        Throws:
        DisconnectException - if a severe error condition is encountered, causing the connection to be broken
        SqlException
      • writePlainScalarStream

        private final void writePlainScalarStream​(boolean chained,
                                                  boolean chainedWithSameCorrelator,
                                                  int codePoint,
                                                  java.io.InputStream in,
                                                  boolean writeNullByte,
                                                  int parameterIndex)
                                           throws DisconnectException
        Writes a stream with unknown length onto the wire.

        To avoid DRDA protocol exceptions, the data is truncated or padded as required to complete the transfer. This can be avoided by implementing the request abort mechanism specified by DRDA, but it is rather complex and may not be worth the trouble.

        Also note that any exceptions generated while writing the stream will be accumulated and raised at a later time.

        Implementation note: This method does not support sending values with a specified length using layer B streaming and at the same time applying length checking. For large values layer B streaming may be more efficient than using layer A streaming.

        Parameters:
        in - the stream to transfer
        writeNullByte - whether or not to write a NULL indicator
        parameterIndex - one-based parameter index
        Throws:
        DisconnectException - if a severe error condition is encountered, causing the connection to be broken
      • prepScalarStream

        private final int prepScalarStream​(boolean chained,
                                           boolean chainedWithSameCorrelator,
                                           boolean writeNullByte,
                                           long leftToRead)
                                    throws DisconnectException
        Throws:
        DisconnectException
      • padScalarStreamForError

        private final void padScalarStreamForError​(long leftToRead,
                                                   int bytesToRead,
                                                   boolean writeStatus,
                                                   byte status)
                                            throws DisconnectException
        Pads a value with zeros until it has reached its defined length.

        This functionality was introduced to handle the error situation where the actual length of the user stream is shorter than specified. To avoid DRDA protocol errors (or in this case a hang), we have to pad the data until the specified length has been reached. In a later increment the Derby-specific EXTDTA status flag was introduced to allow the client to inform the server that the value sent is invalid.

        Parameters:
        leftToRead - total number of bytes left to read
        bytesToRead - remaining bytes to read before flushing
        writeStatus - whether or not to wrote the Derby-specific trailing EXTDTA status flag (see DRDAConstants)
        status - the EXTDTA status (for this data value), ignored if writeStatus is false
        Throws:
        DisconnectException - if flushing the buffer fails
      • writeExtendedLengthBytes

        private final void writeExtendedLengthBytes​(int extendedLengthByteCount,
                                                    long length)
      • finalizePreviousChainedDss

        private final void finalizePreviousChainedDss​(boolean dssHasSameCorrelator)
      • doesRequestContainData

        private final boolean doesRequestContainData()
      • finalizeDssLength

        private final void finalizeDssLength()
        Signal the completion of a DSS Layer A object.

        The length of the DSS object will be calculated based on the difference between the start of the DSS, saved in the variable dssLengthLocation_, and the current offset into the buffer which marks the end of the data.

        In the event the length requires the use of continuation DSS headers, one for each 32k chunk of data, the data will be shifted and the continuation headers will be inserted with the correct values as needed. Note: In the future, we may try to optimize this approach in an attempt to avoid these shifts.

      • markLengthBytes

        protected final void markLengthBytes​(int codePoint)
      • mark

        private final void mark()
      • popMark

        private final int popMark()
      • markForCachingPKGNAMCSN

        protected final void markForCachingPKGNAMCSN()
      • popMarkForCachingPKGNAMCSN

        protected final int popMarkForCachingPKGNAMCSN()
      • calculateExtendedLengthByteCount

        private final int calculateExtendedLengthByteCount​(long ddmSize)
      • padBytes

        private final void padBytes​(byte padByte,
                                    int length)
      • write1Byte

        final void write1Byte​(int value)
      • buildTripletHeader

        final void buildTripletHeader​(int tripletLength,
                                      int tripletType,
                                      int tripletId)
      • writeLidAndLengths

        private void writeLidAndLengths​(int[][] lidAndLengthOverrides,
                                        int count,
                                        int offset)
      • writeLidAndLengths

        final void writeLidAndLengths​(int[][] lidAndLengthOverrides,
                                      int count,
                                      int offset,
                                      boolean mddRequired,
                                      java.util.Hashtable map)
      • write2Bytes

        final void write2Bytes​(int value)
      • write4Bytes

        final void write4Bytes​(long value)
      • writeBytes

        final void writeBytes​(byte[] buf,
                              int length)
      • writeBytes

        final void writeBytes​(byte[] buf)
      • writeCodePoint4Bytes

        final void writeCodePoint4Bytes​(int codePoint,
                                        int value)
      • writeScalar1Byte

        protected final void writeScalar1Byte​(int codePoint,
                                              int value)
      • writeScalar2Bytes

        final void writeScalar2Bytes​(int codePoint,
                                     int value)
      • writeScalar4Bytes

        protected final void writeScalar4Bytes​(int codePoint,
                                               long value)
      • writeScalar8Bytes

        final void writeScalar8Bytes​(int codePoint,
                                     long value)
      • writeLengthCodePoint

        final void writeLengthCodePoint​(int length,
                                        int codePoint)
      • writeScalarString

        final void writeScalarString​(int codePoint,
                                     java.lang.String string)
                              throws SqlException
        Write string with no minimum or maximum limit.
        Parameters:
        codePoint - codepoint to write
        string - value to write
        Throws:
        SqlException
      • writeScalarString

        final void writeScalarString​(int codePoint,
                                     java.lang.String string,
                                     int byteMinLength,
                                     int byteLengthLimit,
                                     java.lang.String sqlState)
                              throws SqlException
        insert a 4 byte length/codepoint pair plus ddm character data into the buffer. This method assumes that the String argument can be converted by the ccsid manager. This should be fine because usually there are restrictions on the characters which can be used for ddm character data. The two byte length field will contain the length of the character data and the length of the 4 byte llcp. This method does not handle scenarios which require extended length bytes.
        Parameters:
        codePoint - codepoint to write
        string - value
        byteMinLength - minimum length. String will be padded with spaces if value is too short. Assumes space character is one byte.
        byteLengthLimit - Limit to string length. SQLException will be thrown if we exceed this limit.
        sqlState - SQLState to throw with string as param if byteLengthLimit is exceeded.
        Throws:
        SqlException - if string exceeds byteLengthLimit
      • encodeString

        private int encodeString​(java.lang.String string)
                          throws SqlException
        Encode a string and put it into the buffer. A larger buffer will be allocated if the current buffer is too small to hold the entire string.
        Parameters:
        string - the string to encode
        Returns:
        the number of bytes in the encoded representation of the string
        Throws:
        SqlException
      • writeScalarBytes

        final void writeScalarBytes​(int codePoint,
                                    byte[] buff)
      • writeScalarBytes

        final void writeScalarBytes​(int codePoint,
                                    byte[] buff,
                                    int start,
                                    int length)
      • writeScalarPaddedBytes

        final void writeScalarPaddedBytes​(byte[] buff,
                                          int paddedLength,
                                          byte padByte)
      • flush

        protected void flush​(java.io.OutputStream socketOutputStream)
                      throws java.io.IOException
        Throws:
        java.io.IOException
      • sendBytes

        private void sendBytes​(java.io.OutputStream socketOutputStream)
                        throws java.io.IOException
        Throws:
        java.io.IOException
      • maskOutPassword

        private final void maskOutPassword()
      • writeByte

        private void writeByte​(byte v)
      • writeShort

        final void writeShort​(short v)
      • writeInt

        void writeInt​(int v)
      • writeLong6Bytes

        final void writeLong6Bytes​(long v)
        Writes a long into the buffer, using six bytes.
        Parameters:
        v - the value to write
        Throws:
        java.lang.IllegalArgumentException - if the long value is too large to be represented by six bytes.
      • writeLong

        final void writeLong​(long v)
      • writeShortFdocaData

        protected void writeShortFdocaData​(short v)
      • writeIntFdocaData

        protected void writeIntFdocaData​(int v)
      • writeLongFdocaData

        protected void writeLongFdocaData​(long v)
      • writeFloat

        protected void writeFloat​(float v)
      • writeDouble

        protected void writeDouble​(double v)
      • writeBigDecimal

        final void writeBigDecimal​(java.math.BigDecimal v,
                                   int declaredPrecision,
                                   int declaredScale)
                            throws SqlException
        Throws:
        SqlException
      • writeBoolean

        final void writeBoolean​(boolean v)
      • writeSingleorMixedCcsidLDString

        final void writeSingleorMixedCcsidLDString​(java.lang.String s,
                                                   java.nio.charset.Charset encoding)
                                            throws SqlException
        Throws:
        SqlException
      • writeLDBytes

        final void writeLDBytes​(byte[] bytes)
      • writeLDBytesX

        private final void writeLDBytesX​(int ldSize,
                                         byte[] bytes)
      • writeLDBytesXSubset

        private final void writeLDBytesXSubset​(int ldSize,
                                               int bytesToCopy,
                                               byte[] bytes)
      • buildLengthAndCodePointForLob

        private void buildLengthAndCodePointForLob​(int codePoint,
                                                   long leftToRead,
                                                   boolean writeNullByte,
                                                   int extendedLengthByteCount)
                                            throws DisconnectException
        Throws:
        DisconnectException
      • writeEXTDTAStatus

        private void writeEXTDTAStatus​(byte flag)
                                throws DisconnectException
        Writes the Derby-specific EXTDTA status flag to the send buffer.

        The existing buffer is flushed to make space for the flag if required.

        Parameters:
        flag - the Derby-specific EXTDTA status flag
        Throws:
        DisconnectException - if flushing the buffer fails
      • setDssLengthLocation

        public void setDssLengthLocation​(int location)
      • setCorrelationID

        public void setCorrelationID​(int id)
      • peekStream

        private static boolean peekStream​(java.io.BufferedInputStream in)
                                   throws java.io.IOException
        Throws:
        java.io.IOException