Class Request
- Direct Known Subclasses:
NetConnectionRequest
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected ByteBufferprivate intprivate intprivate int[]private static final intprotected NetAgentprotected booleanprotected intprotected intprivate booleanprivate int -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate final voidbuildDss(boolean dssHasSameCorrelator, boolean chainedToNextStructure, boolean nextHasSameCorrelator, int dssType, int corrId, boolean simpleFinalizeBuildingNextDss) private voidbuildLengthAndCodePointForLob(int codePoint, boolean writeNullByte) private voidbuildLengthAndCodePointForLob(int codePoint, long leftToRead, boolean writeNullByte, int extendedLengthByteCount) (package private) final voidbuildTripletHeader(int tripletLength, int tripletType, int tripletId) private final intcalculateExtendedLengthByteCount(long ddmSize) private final voidprotected final void(package private) final void(package private) final voidprivate final booleanprivate intencodeString(String string) Encode a string and put it into the buffer.private final voidensureLength(int length) private final voidSignal the completion of a DSS Layer A object.private final voidfinalizePreviousChainedDss(boolean dssHasSameCorrelator) protected voidflush(OutputStream socketOutputStream) private final voidprivate final intprivate final intflushScalarStreamSegment(long leftToRead, int bytesToRead) (package private) final voidprivate final voidmark()protected final voidprotected final voidmarkLengthBytes(int codePoint) private final voidprivate final voidpadBytes(byte padByte, int length) private final voidpadScalarStreamForError(long leftToRead, int bytesToRead, boolean writeStatus, byte status) Pads a value with zeros until it has reached its defined length.private static booleanprivate final intpopMark()protected final intprivate final intprepScalarStream(boolean chained, boolean chainedWithSameCorrelator, boolean writeNullByte, long leftToRead) private voidsendBytes(OutputStream socketOutputStream) voidsetCorrelationID(int id) voidsetDssLengthLocation(int location) protected final void(package private) final voidwrite1Byte(int value) (package private) final voidwrite2Bytes(int value) (package private) final voidwrite4Bytes(long value) (package private) final voidwriteBigDecimal(BigDecimal v, int declaredPrecision, int declaredScale) (package private) final voidwriteBoolean(boolean v) private voidwriteByte(byte v) (package private) final voidwriteBytes(byte[] buf) (package private) final voidwriteBytes(byte[] buf, int length) (package private) final voidwriteCodePoint4Bytes(int codePoint, int value) (package private) final voidwriteDate(DateTimeValue date) protected voidwriteDouble(double v) private voidwriteEXTDTAStatus(byte flag) Writes the Derby-specific EXTDTA status flag to the send buffer.private final voidwriteExtendedLengthBytes(int extendedLengthByteCount, long length) protected voidwriteFloat(float v) (package private) voidwriteInt(int v) protected voidwriteIntFdocaData(int v) (package private) final voidwriteLDBytes(byte[] bytes) private final voidwriteLDBytesX(int ldSize, byte[] bytes) private final voidwriteLDBytesXSubset(int ldSize, int bytesToCopy, byte[] bytes) (package private) final voidwriteLengthCodePoint(int length, int codePoint) private voidwriteLidAndLengths(int[][] lidAndLengthOverrides, int count, int offset) (package private) final voidwriteLidAndLengths(int[][] lidAndLengthOverrides, int count, int offset, boolean mddRequired, Hashtable map) (package private) final voidwriteLong(long v) (package private) final voidwriteLong6Bytes(long v) Writes a long into the buffer, using six bytes.protected voidwriteLongFdocaData(long v) private final voidwritePlainScalarStream(boolean chained, boolean chainedWithSameCorrelator, int codePoint, long length, InputStream in, boolean writeNullByte, int parameterIndex) Writes a stream with a known length onto the wire.private final voidwritePlainScalarStream(boolean chained, boolean chainedWithSameCorrelator, int codePoint, InputStream in, boolean writeNullByte, int parameterIndex) Writes a stream with unknown length onto the wire.protected final voidwriteScalar1Byte(int codePoint, int value) (package private) final voidwriteScalar2Bytes(int codePoint, int value) protected final voidwriteScalar4Bytes(int codePoint, long value) (package private) final voidwriteScalar8Bytes(int codePoint, long value) (package private) final voidwriteScalarBytes(int codePoint, byte[] buff) (package private) final voidwriteScalarBytes(int codePoint, byte[] buff, int start, int length) (package private) final voidwriteScalarPaddedBytes(byte[] buff, int paddedLength, byte padByte) (package private) final voidwriteScalarStream(boolean chained, boolean chainedWithSameCorrelator, int codePoint, int length, Reader r, boolean writeNullByte, int parameterIndex) (package private) final voidwriteScalarStream(boolean chained, boolean chainedWithSameCorrelator, int codePoint, long length, InputStream in, boolean writeNullByte, int parameterIndex) (package private) final voidwriteScalarStream(boolean chained, boolean chainedWithSameCorrelator, int codePoint, InputStream in, boolean writeNullByte, int parameterIndex) (package private) final voidwriteScalarStream(boolean chained, boolean chainedWithSameCorrelator, int codePoint, Reader r, boolean writeNullByte, int parameterIndex) (package private) final voidwriteScalarString(int codePoint, String string) Write string with no minimum or maximum limit.(package private) final voidwriteScalarString(int codePoint, String string, int byteMinLength, int byteLengthLimit, String sqlState) insert a 4 byte length/codepoint pair plus ddm character data into the buffer.(package private) final voidwriteShort(short v) protected voidwriteShortFdocaData(short v) (package private) final voidwriteSingleorMixedCcsidLDString(String s, Charset encoding) (package private) final voidwriteTime(DateTimeValue time) (package private) final voidwriteTimestamp(DateTimeValue timestamp) (package private) final void
-
Field Details
-
buffer
-
MAX_MARKS_NESTING
private static final int MAX_MARKS_NESTING- See Also:
-
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_
-
-
Constructor Details
-
Request
Request(NetAgent netAgent, int minSize)
-
-
Method Details
-
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, InputStream in, boolean writeNullByte, int parameterIndex) throws DisconnectException, SqlException - Throws:
DisconnectExceptionSqlException
-
writeScalarStream
final void writeScalarStream(boolean chained, boolean chainedWithSameCorrelator, int codePoint, long length, InputStream in, boolean writeNullByte, int parameterIndex) throws DisconnectException, SqlException - Throws:
DisconnectExceptionSqlException
-
writePlainScalarStream
private final void writePlainScalarStream(boolean chained, boolean chainedWithSameCorrelator, int codePoint, long length, 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, 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, Reader r, boolean writeNullByte, int parameterIndex) throws DisconnectException, SqlException - Throws:
DisconnectExceptionSqlException
-
writeScalarStream
final void writeScalarStream(boolean chained, boolean chainedWithSameCorrelator, int codePoint, Reader r, boolean writeNullByte, int parameterIndex) throws DisconnectException, SqlException - Throws:
DisconnectExceptionSqlException
-
prepScalarStream
private final int prepScalarStream(boolean chained, boolean chainedWithSameCorrelator, boolean writeNullByte, long leftToRead) throws DisconnectException - Throws:
DisconnectException
-
flushExistingDSS
- Throws:
DisconnectException
-
flushScalarStreamSegment
private final int flushScalarStreamSegment(long leftToRead, int bytesToRead) throws DisconnectException - Throws:
DisconnectException
-
flushScalarStreamSegment
- 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 ifwriteStatusisfalse- 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
- 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, 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
Write string with no minimum or maximum limit.- Parameters:
codePoint- codepoint to writestring- value to write- Throws:
SqlException
-
writeScalarString
final void writeScalarString(int codePoint, String string, int byteMinLength, int byteLengthLimit, 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
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
- Throws:
IOException
-
sendBytes
- Throws:
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:
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(BigDecimal v, int declaredPrecision, int declaredScale) throws SqlException - Throws:
SqlException
-
writeDate
- Throws:
SqlException
-
writeTime
-
writeTimestamp
- Throws:
SqlException
-
writeBoolean
final void writeBoolean(boolean v) -
writeSingleorMixedCcsidLDString
- 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
- 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
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
- Throws:
IOException
-