Class Request
- java.lang.Object
-
- org.apache.derby.client.net.Request
-
- Direct Known Subclasses:
NetConnectionRequest
class Request extends java.lang.Object
-
-
Field Summary
Fields Modifier and Type Field Description protected java.nio.ByteBuffer
buffer
private int
correlationID_
private int
dssLengthLocation_
private int[]
markStack_
private static int
MAX_MARKS_NESTING
protected NetAgent
netAgent_
protected boolean
passwordIncluded_
protected int
passwordLength_
protected int
passwordStart_
private boolean
simpleDssFinalize
private int
top_
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description 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)
private void
clearBuffer()
protected void
createCommand()
(package private) void
createCommandData()
(package private) void
createEncryptedCommandData()
private boolean
doesRequestContainData()
private int
encodeString(java.lang.String string)
Encode a string and put it into the buffer.private void
ensureLength(int length)
private void
finalizeDssLength()
Signal the completion of a DSS Layer A object.private void
finalizePreviousChainedDss(boolean dssHasSameCorrelator)
protected void
flush(java.io.OutputStream socketOutputStream)
private void
flushExistingDSS()
private int
flushScalarStreamSegment()
private int
flushScalarStreamSegment(long leftToRead, int bytesToRead)
(package private) void
initialize()
private void
mark()
protected void
markForCachingPKGNAMCSN()
protected void
markLengthBytes(int codePoint)
private void
maskOutPassword()
private void
padBytes(byte padByte, int length)
private 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()
private int
prepScalarStream(boolean chained, boolean chainedWithSameCorrelator, boolean writeNullByte, long leftToRead)
private void
sendBytes(java.io.OutputStream socketOutputStream)
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)
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)
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)
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, long length, java.io.InputStream in, boolean writeNullByte, int parameterIndex)
Writes a stream with a known length onto the wire.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.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[] buff, int start, int length)
(package private) void
writeScalarPaddedBytes(byte[] buff, int paddedLength, byte padByte)
(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.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.nio.charset.Charset encoding)
(package private) void
writeTime(DateTimeValue time)
(package private) void
writeTimestamp(DateTimeValue timestamp)
(package private) void
writeUDT(java.lang.Object val)
-
-
-
Field Detail
-
buffer
protected java.nio.ByteBuffer buffer
-
MAX_MARKS_NESTING
private static final int MAX_MARKS_NESTING
- See Also:
- Constant Field Values
-
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)
-
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 streamin
- the stream to transferwriteNullByte
- whether or not to write a NULL indicatorparameterIndex
- one-based parameter index- Throws:
DisconnectException
- if a severe error condition is encountered, causing the connection to be brokenSqlException
-
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 transferwriteNullByte
- whether or not to write a NULL indicatorparameterIndex
- 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
private final int prepScalarStream(boolean chained, boolean chainedWithSameCorrelator, boolean writeNullByte, long leftToRead) throws DisconnectException
- Throws:
DisconnectException
-
flushExistingDSS
private final void flushExistingDSS() throws DisconnectException
- Throws:
DisconnectException
-
flushScalarStreamSegment
private final int flushScalarStreamSegment(long leftToRead, int bytesToRead) throws DisconnectException
- Throws:
DisconnectException
-
flushScalarStreamSegment
private final int flushScalarStreamSegment() 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 readbytesToRead
- remaining bytes to read before flushingwriteStatus
- whether or not to wrote the Derby-specific trailing EXTDTA status flag (see DRDAConstants)status
- the EXTDTA status (for this data value), ignored ifwriteStatus
isfalse
- 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()
-
updateLengthBytes
protected final void updateLengthBytes() throws SqlException
- Throws:
SqlException
-
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 writestring
- 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 writestring
- valuebyteMinLength
- 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
-
writeDate
final void writeDate(DateTimeValue date) throws SqlException
- Throws:
SqlException
-
writeTime
final void writeTime(DateTimeValue time)
-
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.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)
-
writeUDT
final void writeUDT(java.lang.Object val) 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
-
-