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.ByteBufferbufferprivate intcorrelationID_private intdssLengthLocation_private int[]markStack_private static intMAX_MARKS_NESTINGprotected NetAgentnetAgent_protected booleanpasswordIncluded_protected intpasswordLength_protected intpasswordStart_private booleansimpleDssFinalizeprivate inttop_
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private 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) voidbuildTripletHeader(int tripletLength, int tripletType, int tripletId)private intcalculateExtendedLengthByteCount(long ddmSize)private voidclearBuffer()protected voidcreateCommand()(package private) voidcreateCommandData()(package private) voidcreateEncryptedCommandData()private booleandoesRequestContainData()private intencodeString(java.lang.String string)Encode a string and put it into the buffer.private voidensureLength(int length)private voidfinalizeDssLength()Signal the completion of a DSS Layer A object.private voidfinalizePreviousChainedDss(boolean dssHasSameCorrelator)protected voidflush(java.io.OutputStream socketOutputStream)private voidflushExistingDSS()private intflushScalarStreamSegment()private intflushScalarStreamSegment(long leftToRead, int bytesToRead)(package private) voidinitialize()private voidmark()protected voidmarkForCachingPKGNAMCSN()protected voidmarkLengthBytes(int codePoint)private voidmaskOutPassword()private voidpadBytes(byte padByte, int length)private voidpadScalarStreamForError(long leftToRead, int bytesToRead, boolean writeStatus, byte status)Pads a value with zeros until it has reached its defined length.private static booleanpeekStream(java.io.BufferedInputStream in)private intpopMark()protected intpopMarkForCachingPKGNAMCSN()private intprepScalarStream(boolean chained, boolean chainedWithSameCorrelator, boolean writeNullByte, long leftToRead)private voidsendBytes(java.io.OutputStream socketOutputStream)voidsetCorrelationID(int id)voidsetDssLengthLocation(int location)protected voidupdateLengthBytes()(package private) voidwrite1Byte(int value)(package private) voidwrite2Bytes(int value)(package private) voidwrite4Bytes(long value)(package private) voidwriteBigDecimal(java.math.BigDecimal v, int declaredPrecision, int declaredScale)(package private) voidwriteBoolean(boolean v)private voidwriteByte(byte v)(package private) voidwriteBytes(byte[] buf)(package private) voidwriteBytes(byte[] buf, int length)(package private) voidwriteCodePoint4Bytes(int codePoint, int value)(package private) voidwriteDate(DateTimeValue date)protected voidwriteDouble(double v)private voidwriteEXTDTAStatus(byte flag)Writes the Derby-specific EXTDTA status flag to the send buffer.private voidwriteExtendedLengthBytes(int extendedLengthByteCount, long length)protected voidwriteFloat(float v)(package private) voidwriteInt(int v)protected voidwriteIntFdocaData(int v)(package private) voidwriteLDBytes(byte[] bytes)private voidwriteLDBytesX(int ldSize, byte[] bytes)private voidwriteLDBytesXSubset(int ldSize, int bytesToCopy, byte[] bytes)(package private) voidwriteLengthCodePoint(int length, int codePoint)private voidwriteLidAndLengths(int[][] lidAndLengthOverrides, int count, int offset)(package private) voidwriteLidAndLengths(int[][] lidAndLengthOverrides, int count, int offset, boolean mddRequired, java.util.Hashtable map)(package private) voidwriteLong(long v)(package private) voidwriteLong6Bytes(long v)Writes a long into the buffer, using six bytes.protected voidwriteLongFdocaData(long v)private voidwritePlainScalarStream(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 voidwritePlainScalarStream(boolean chained, boolean chainedWithSameCorrelator, int codePoint, java.io.InputStream in, boolean writeNullByte, int parameterIndex)Writes a stream with unknown length onto the wire.protected voidwriteScalar1Byte(int codePoint, int value)(package private) voidwriteScalar2Bytes(int codePoint, int value)protected voidwriteScalar4Bytes(int codePoint, long value)(package private) voidwriteScalar8Bytes(int codePoint, long value)(package private) voidwriteScalarBytes(int codePoint, byte[] buff)(package private) voidwriteScalarBytes(int codePoint, byte[] buff, int start, int length)(package private) voidwriteScalarPaddedBytes(byte[] buff, int paddedLength, byte padByte)(package private) voidwriteScalarStream(boolean chained, boolean chainedWithSameCorrelator, int codePoint, int length, java.io.Reader r, boolean writeNullByte, int parameterIndex)(package private) voidwriteScalarStream(boolean chained, boolean chainedWithSameCorrelator, int codePoint, long length, java.io.InputStream in, boolean writeNullByte, int parameterIndex)(package private) voidwriteScalarStream(boolean chained, boolean chainedWithSameCorrelator, int codePoint, java.io.InputStream in, boolean writeNullByte, int parameterIndex)(package private) voidwriteScalarStream(boolean chained, boolean chainedWithSameCorrelator, int codePoint, java.io.Reader r, boolean writeNullByte, int parameterIndex)(package private) voidwriteScalarString(int codePoint, java.lang.String string)Write string with no minimum or maximum limit.(package private) voidwriteScalarString(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) voidwriteShort(short v)protected voidwriteShortFdocaData(short v)(package private) voidwriteSingleorMixedCcsidLDString(java.lang.String s, java.nio.charset.Charset encoding)(package private) voidwriteTime(DateTimeValue time)(package private) voidwriteTimestamp(DateTimeValue timestamp)(package private) voidwriteUDT(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:
DisconnectExceptionSqlException
-
writeScalarStream
final void writeScalarStream(boolean chained, boolean chainedWithSameCorrelator, int codePoint, long length, java.io.InputStream in, boolean writeNullByte, int parameterIndex) throws DisconnectException, SqlException- Throws:
DisconnectExceptionSqlException
-
writePlainScalarStream
private final void writePlainScalarStream(boolean chained, boolean chainedWithSameCorrelator, int codePoint, long length, java.io.InputStream in, boolean writeNullByte, int parameterIndex) throws DisconnectException, SqlExceptionWrites 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 DisconnectExceptionWrites 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:
DisconnectExceptionSqlException
-
writeScalarStream
final void writeScalarStream(boolean chained, boolean chainedWithSameCorrelator, int codePoint, java.io.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
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 DisconnectExceptionPads 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
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 SqlExceptionWrite 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 SqlExceptioninsert 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 SqlExceptionEncode 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 DisconnectExceptionWrites 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
-
-