org.apache.derby.client.net
Class Request

java.lang.Object
  extended by org.apache.derby.client.net.Request
Direct Known Subclasses:
NetConnectionRequest

public class Request
extends java.lang.Object


Field Summary
protected  byte[] bytes_
           
protected  CcsidManager ccsidManager_
           
private  int correlationID_
           
private  int dssLengthLocation_
           
private  int[] markStack_
           
private static int MAX_MARKS_NESTING
           
protected  NetAgent netAgent_
           
protected  int offset_
           
protected  boolean passwordIncluded_
           
protected  int passwordLength_
           
protected  int passwordStart_
           
private  boolean simpleDssFinalize
           
private  int top_
           
 
Constructor Summary
Request(NetAgent netAgent, CcsidManager ccsidManager, int bufferSize)
           
Request(NetAgent netAgent, int minSize, CcsidManager ccsidManager)
           
 
Method Summary
private  void buildDss(boolean dssHasSameCorrelator, boolean chainedToNextStructure, boolean nextHasSameCorrelator, int dssType, int corrId, boolean simpleFinalizeBuildingNextDss)
           
private  void buildLengthAndCodePointForLob(int codePoint, boolean writeNullByte)
           
private  void buildLengthAndCodePointForLob(int codePoint, long leftToRead, boolean writeNullByte, int extendedLengthByteCount)
           
(package private)  void buildTripletHeader(int tripletLength, int tripletType, int tripletId)
           
private  int calculateExtendedLengthByteCount(long ddmSize)
           
protected  void clearBuffer()
           
protected  void createCommand()
           
(package private)  void createCommandData()
           
(package private)  void createEncryptedCommandData()
           
protected  void createXACommand()
           
protected  boolean doesRequestContainData()
           
protected  void ensureLength(int length)
           
protected  void finalizeDssLength()
          Signal the completion of a DSS Layer A object.
protected  void finalizePreviousChainedDss(boolean dssHasSameCorrelator)
           
protected  void flush(java.io.OutputStream socketOutputStream)
           
protected  void flushExistingDSS()
           
protected  int flushScalarStreamSegment()
           
protected  int flushScalarStreamSegment(long leftToRead, int bytesToRead)
           
(package private)  void initialize()
           
private  void mark()
           
protected  void markForCachingPKGNAMCSN()
           
protected  void markLengthBytes(int codePoint)
           
(package private)  void maskOutPassword()
           
(package private)  void padBytes(byte padByte, int length)
           
protected  void padScalarStreamForError(long leftToRead, int bytesToRead, boolean writeStatus, byte status)
          Pads a value with zeros until it has reached its defined length.
private static boolean peekStream(java.io.BufferedInputStream in)
           
private  int popMark()
           
protected  int popMarkForCachingPKGNAMCSN()
           
protected  int prepScalarStream(boolean chained, boolean chainedWithSameCorrelator, boolean writeNullByte, long leftToRead)
           
protected  void sendBytes(java.io.OutputStream socketOutputStream)
           
(package private)  void setCcsidMgr(CcsidManager ccsidManager)
           
 void setCorrelationID(int id)
           
 void setDssLengthLocation(int location)
           
protected  void updateLengthBytes()
           
(package private)  void write1Byte(int value)
           
(package private)  void write2Bytes(int value)
           
(package private)  void write4Bytes(long value)
           
(package private)  void writeBigDecimal(java.math.BigDecimal v, int declaredPrecision, int declaredScale)
           
(package private)  void writeBoolean(boolean v)
           
(package private)  void writeByte(byte v)
           
(package private)  void writeBytes(byte[] buf)
           
(package private)  void writeBytes(byte[] buf, int length)
           
(package private)  void writeCodePoint4Bytes(int codePoint, int value)
           
(package private)  void writeDate(DateTimeValue date)
           
(package private)  void writeDDMString(java.lang.String s)
           
protected  void writeDouble(double v)
           
private  void writeEXTDTAStatus(byte flag)
          Writes the Derby-specific EXTDTA status flag to the send buffer.
private  void writeExtendedLengthBytes(int extendedLengthByteCount, long length)
           
protected  void writeFloat(float v)
           
(package private)  void writeInt(int v)
           
protected  void writeIntFdocaData(int v)
           
(package private)  void writeLDBytes(byte[] bytes)
           
private  void writeLDBytesX(int ldSize, byte[] bytes)
           
private  void writeLDBytesXSubset(int ldSize, int bytesToCopy, byte[] bytes)
           
(package private)  void writeLengthCodePoint(int length, int codePoint)
           
(package private)  void writeLidAndLengths(int[][] lidAndLengthOverrides, int count, int offset)
           
(package private)  void writeLidAndLengths(int[][] lidAndLengthOverrides, int count, int offset, boolean mddRequired, java.util.Hashtable map)
           
(package private)  void writeLong(long v)
           
(package private)  void writeLong6Bytes(long v)
          Writes a long into the buffer, using six bytes.
protected  void writeLongFdocaData(long v)
           
private  void writePlainScalarStream(boolean chained, boolean chainedWithSameCorrelator, int codePoint, java.io.InputStream in, boolean writeNullByte, int parameterIndex)
          Writes a stream with unknown length onto the wire.
private  void writePlainScalarStream(boolean chained, boolean chainedWithSameCorrelator, int codePoint, long length, java.io.InputStream in, boolean writeNullByte, int parameterIndex)
          Writes a stream with a known length onto the wire.
protected  void writeScalar1Byte(int codePoint, int value)
           
(package private)  void writeScalar2Bytes(int codePoint, int value)
           
protected  void writeScalar4Bytes(int codePoint, long value)
           
(package private)  void writeScalar8Bytes(int codePoint, long value)
           
(package private)  void writeScalarBytes(int codePoint, byte[] buff)
           
(package private)  void writeScalarBytes(int codePoint, byte[] buf, int length)
           
(package private)  void writeScalarBytes(int codePoint, byte[] buff, int start, int length)
           
(package private)  void writeScalarHeader(int codePoint, int dataLength)
           
(package private)  void writeScalarPaddedBytes(byte[] buff, int paddedLength, byte padByte)
           
(package private)  void writeScalarPaddedBytes(int codePoint, byte[] buff, int paddedLength, byte padByte)
           
(package private)  void writeScalarPaddedString(java.lang.String string, int paddedLength)
           
(package private)  void writeScalarStream(boolean chained, boolean chainedWithSameCorrelator, int codePoint, java.io.InputStream in, boolean writeNullByte, int parameterIndex)
           
(package private)  void writeScalarStream(boolean chained, boolean chainedWithSameCorrelator, int codePoint, int length, java.io.Reader r, boolean writeNullByte, int parameterIndex)
           
(package private)  void writeScalarStream(boolean chained, boolean chainedWithSameCorrelator, int codePoint, long length, java.io.InputStream in, boolean writeNullByte, int parameterIndex)
           
(package private)  void writeScalarStream(boolean chained, boolean chainedWithSameCorrelator, int codePoint, java.io.Reader r, boolean writeNullByte, int parameterIndex)
           
(package private)  void writeScalarString(int codePoint, java.lang.String string)
          Write string with no minimum or maximum limit.
(package private)  void writeScalarString(int codePoint, java.lang.String string, int byteMinLength, int byteLengthLimit, java.lang.String sqlState)
          insert a 4 byte length/codepoint pair plus ddm character data into the buffer.
(package private)  void writeShort(short v)
           
protected  void writeShortFdocaData(short v)
           
(package private)  void writeSingleorMixedCcsidLDString(java.lang.String s, java.lang.String encoding)
           
(package private)  void writeTime(DateTimeValue time)
           
(package private)  void writeTimestamp(DateTimeValue timestamp)
           
(package private)  void writeUDT(java.lang.Object val)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

bytes_

protected byte[] bytes_

offset_

protected int offset_

MAX_MARKS_NESTING

private static final int MAX_MARKS_NESTING
See Also:
Constant Field Values

markStack_

private int[] markStack_

top_

private int top_

ccsidManager_

protected CcsidManager ccsidManager_

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,
        CcsidManager ccsidManager)

Request

Request(NetAgent netAgent,
        CcsidManager ccsidManager,
        int bufferSize)
Method Detail

clearBuffer

protected final void clearBuffer()

initialize

final void initialize()

setCcsidMgr

final void setCcsidMgr(CcsidManager ccsidManager)

ensureLength

protected final void ensureLength(int length)

createCommand

protected final void createCommand()

createXACommand

protected void createXACommand()

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)

writeScalarStream

final void writeScalarStream(boolean chained,
                             boolean chainedWithSameCorrelator,
                             int codePoint,
                             java.io.InputStream in,
                             boolean writeNullByte,
                             int parameterIndex)
                      throws DisconnectException,
                             SqlException
Throws:
DisconnectException
SqlException

writeScalarStream

final void writeScalarStream(boolean chained,
                             boolean chainedWithSameCorrelator,
                             int codePoint,
                             long length,
                             java.io.InputStream in,
                             boolean writeNullByte,
                             int parameterIndex)
                      throws DisconnectException,
                             SqlException
Throws:
DisconnectException
SqlException

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

writeScalarStream

final void writeScalarStream(boolean chained,
                             boolean chainedWithSameCorrelator,
                             int codePoint,
                             int length,
                             java.io.Reader r,
                             boolean writeNullByte,
                             int parameterIndex)
                      throws DisconnectException,
                             SqlException
Throws:
DisconnectException
SqlException

writeScalarStream

final void writeScalarStream(boolean chained,
                             boolean chainedWithSameCorrelator,
                             int codePoint,
                             java.io.Reader r,
                             boolean writeNullByte,
                             int parameterIndex)
                      throws DisconnectException,
                             SqlException
Throws:
DisconnectException
SqlException

prepScalarStream

protected final int prepScalarStream(boolean chained,
                                     boolean chainedWithSameCorrelator,
                                     boolean writeNullByte,
                                     long leftToRead)
                              throws DisconnectException
Throws:
DisconnectException

flushExistingDSS

protected final void flushExistingDSS()
                               throws DisconnectException
Throws:
DisconnectException

flushScalarStreamSegment

protected final int flushScalarStreamSegment(long leftToRead,
                                             int bytesToRead)
                                      throws DisconnectException
Throws:
DisconnectException

flushScalarStreamSegment

protected final int flushScalarStreamSegment()
                                      throws DisconnectException
Throws:
DisconnectException

padScalarStreamForError

protected 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

protected final void finalizePreviousChainedDss(boolean dssHasSameCorrelator)

doesRequestContainData

protected final boolean doesRequestContainData()

finalizeDssLength

protected 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()

updateLengthBytes

protected final void updateLengthBytes()
                                throws SqlException
Throws:
SqlException

calculateExtendedLengthByteCount

private final int calculateExtendedLengthByteCount(long ddmSize)

padBytes

final void padBytes(byte padByte,
                    int length)

write1Byte

final void write1Byte(int value)

buildTripletHeader

final void buildTripletHeader(int tripletLength,
                              int tripletType,
                              int tripletId)

writeLidAndLengths

final 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)

writeScalarBytes

final void writeScalarBytes(int codePoint,
                            byte[] buf,
                            int length)

writeScalarHeader

final void writeScalarHeader(int codePoint,
                             int dataLength)

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

writeScalarPaddedString

final void writeScalarPaddedString(java.lang.String string,
                                   int paddedLength)
                            throws SqlException
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(int codePoint,
                                  byte[] buff,
                                  int paddedLength,
                                  byte padByte)

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

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

maskOutPassword

final void maskOutPassword()

writeByte

final 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

writeDate

final void writeDate(DateTimeValue date)
              throws SqlException
Throws:
SqlException

writeTime

final void writeTime(DateTimeValue time)
              throws SqlException
Throws:
SqlException

writeTimestamp

final void writeTimestamp(DateTimeValue timestamp)
                   throws SqlException
Throws:
SqlException

writeBoolean

final void writeBoolean(boolean v)

writeSingleorMixedCcsidLDString

final void writeSingleorMixedCcsidLDString(java.lang.String s,
                                           java.lang.String 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)

writeUDT

final void writeUDT(java.lang.Object val)
             throws SqlException
Throws:
SqlException

writeDDMString

final void writeDDMString(java.lang.String s)
                   throws SqlException
Throws:
SqlException

buildLengthAndCodePointForLob

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

buildLengthAndCodePointForLob

private void buildLengthAndCodePointForLob(int codePoint,
                                           boolean writeNullByte)
                                    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

Built on Thu 2011-03-10 11:54:14+0000, from revision ???

Apache Derby V10.6 Internals - Copyright © 2004,2007 The Apache Software Foundation. All Rights Reserved.