Top Fields Constructors Methods
org.apache.derby.client.net

pack-priv Class Request

extends Object
Class Inheritance
Known Direct Subclasses
org.apache.derby.client.net.NetConnectionRequest
Imports
org.apache.derby.client.am.DateTime, .DateTimeValue, .Decimal, .DisconnectException, .ClientMessageId, .SqlException, org.apache.derby.shared.common.reference.SQLState, .DRDAConstants, org.apache.derby.shared.common.sanity.SanityManager, java.io.BufferedInputStream, .IOException, .InputStream, .ObjectOutputStream, .OutputStream, .Reader, java.math.BigDecimal, java.nio.ByteBuffer, .CharBuffer, java.nio.charset.Charset, java.util.Hashtable, org.apache.derby.shared.common.error.ExceptionUtil

Field Summary

Modifier and TypeField and Description
protected ByteBuffer
private int
private int
private int[]
private static final int
protected NetAgent
protected boolean
protected int
protected int
private boolean
private int

Constructor Summary

AccessConstructor and Description
pack-priv
Request(NetAgent netAgent, int minSize)

Method Summary

Modifier and TypeMethod and Description
private final void
buildDss(boolean dssHasSameCorrelator, boolean chainedToNextStructure, boolean nextHasSameCorrelator, int dssType, int corrId, boolean simpleFinalizeBuildingNextDss)

private void
buildLengthAndCodePointForLob(int codePoint, long leftToRead, boolean writeNullByte, int extendedLengthByteCount)

private void
buildLengthAndCodePointForLob(int codePoint, boolean writeNullByte)

pack-priv final void
buildTripletHeader(int tripletLength, int tripletType, int tripletId)

private final int
private final void
protected final void
pack-priv final void
pack-priv final void
private final boolean
private int

Returns:

the number of bytes in the encoded representation of the string
encodeString
(String
the string to encode
string
)

Encode a string and put it into the buffer.

private final void
ensureLength(int length)

private final void
finalizeDssLength()

Signal the completion of a DSS Layer A object.

private final void
finalizePreviousChainedDss(boolean dssHasSameCorrelator)

protected void
flush(OutputStream socketOutputStream)

private final void
private final int
flushScalarStreamSegment(long leftToRead, int bytesToRead)

private final int
pack-priv final void
private final void
mark()

protected final void
protected final void
markLengthBytes(int codePoint)

private final void
private final void
padBytes(byte padByte, int length)

private final void
padScalarStreamForError(long
total number of bytes left to read
leftToRead
,
int
remaining bytes to read before flushing
bytesToRead
,
boolean
whether or not to wrote the Derby-specific trailing EXTDTA status flag (see DRDAConstants)
writeStatus
,
byte
the EXTDTA status (for this data value), ignored if writeStatus is false
status
)

Pads a value with zeros until it has reached its defined length.

private static boolean
private final int
protected final int
private final int
prepScalarStream(boolean chained, boolean chainedWithSameCorrelator, boolean writeNullByte, long leftToRead)

private void
sendBytes(OutputStream socketOutputStream)

public void
public void
setDssLengthLocation(int location)

protected final void
pack-priv final void
write1Byte(int value)

pack-priv final void
write2Bytes(int value)

pack-priv final void
write4Bytes(long value)

pack-priv final void
writeBigDecimal(BigDecimal v, int declaredPrecision, int declaredScale)

pack-priv final void
writeBoolean(boolean v)

private void
writeByte(byte v)

pack-priv final void
writeBytes(byte[] buf, int length)

pack-priv final void
writeBytes(byte[] buf)

pack-priv final void
writeCodePoint4Bytes(int codePoint, int value)

pack-priv final void
protected void
writeDouble(double v)

private void
writeEXTDTAStatus(byte
the Derby-specific EXTDTA status flag
flag
)

Writes the Derby-specific EXTDTA status flag to the send buffer.

private final void
writeExtendedLengthBytes(int extendedLengthByteCount, long length)

protected void
writeFloat(float v)

pack-priv void
writeInt(int v)

protected void
pack-priv final void
writeLDBytes(byte[] bytes)

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

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

pack-priv final void
writeLengthCodePoint(int length, int codePoint)

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

pack-priv final void
writeLidAndLengths(int[][] lidAndLengthOverrides, int count, int offset, boolean mddRequired, Hashtable<K, V> map)

pack-priv final void
writeLong(long v)

pack-priv final void
writeLong6Bytes(long
the value to write
v
)

Writes a long into the buffer, using six bytes.

protected void
private final void
writePlainScalarStream(boolean chained, boolean chainedWithSameCorrelator, int codePoint, long
the byte length of the stream
length
,
InputStream
the stream to transfer
in
,
boolean
whether or not to write a NULL indicator
writeNullByte
,
int
one-based parameter index
parameterIndex
)

Writes a stream with a known length onto the wire.

private final void
writePlainScalarStream(boolean chained, boolean chainedWithSameCorrelator, int codePoint, InputStream
the stream to transfer
in
,
boolean
whether or not to write a NULL indicator
writeNullByte
,
int
one-based parameter index
parameterIndex
)

Writes a stream with unknown length onto the wire.

protected final void
writeScalar1Byte(int codePoint, int value)

pack-priv final void
writeScalar2Bytes(int codePoint, int value)

protected final void
writeScalar4Bytes(int codePoint, long value)

pack-priv final void
writeScalar8Bytes(int codePoint, long value)

pack-priv final void
writeScalarBytes(int codePoint, byte[] buff)

pack-priv final void
writeScalarBytes(int codePoint, byte[] buff, int start, int length)

pack-priv final void
writeScalarPaddedBytes(byte[] buff, int paddedLength, byte padByte)

pack-priv final void
writeScalarStream(boolean chained, boolean chainedWithSameCorrelator, int codePoint, InputStream in, boolean writeNullByte, int parameterIndex)

pack-priv final void
writeScalarStream(boolean chained, boolean chainedWithSameCorrelator, int codePoint, long length, InputStream in, boolean writeNullByte, int parameterIndex)

pack-priv final void
writeScalarStream(boolean chained, boolean chainedWithSameCorrelator, int codePoint, int length, Reader r, boolean writeNullByte, int parameterIndex)

pack-priv final void
writeScalarStream(boolean chained, boolean chainedWithSameCorrelator, int codePoint, Reader r, boolean writeNullByte, int parameterIndex)

pack-priv final void
writeScalarString(int
codepoint to write
codePoint
,
String
value to write
string
)

Write string with no minimum or maximum limit.

pack-priv final void
writeScalarString(int
codepoint to write
codePoint
,
String
value
string
,
int
minimum length. String will be padded with spaces if value is too short. Assumes space character is one byte.
byteMinLength
,
int
Limit to string length. SQLException will be thrown if we exceed this limit.
byteLengthLimit
,
String
SQLState to throw with string as param if byteLengthLimit is exceeded.
sqlState
)

insert a 4 byte length/codepoint pair plus ddm character data into the buffer.

pack-priv final void
writeShort(short v)

protected void
pack-priv final void
pack-priv final void
pack-priv final void
pack-priv final void
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

bufferback to summary
protected ByteBuffer buffer
correlationID_back to summary
private int correlationID_
dssLengthLocation_back to summary
private int dssLengthLocation_
markStack_back to summary
private int[] markStack_
MAX_MARKS_NESTINGback to summary
private static final int MAX_MARKS_NESTING
netAgent_back to summary
protected NetAgent netAgent_
passwordIncluded_back to summary
protected boolean passwordIncluded_
passwordLength_back to summary
protected int passwordLength_
passwordStart_back to summary
protected int passwordStart_
simpleDssFinalizeback to summary
private boolean simpleDssFinalize
top_back to summary
private int top_

Constructor Detail

Requestback to summary
pack-priv Request(NetAgent netAgent, int minSize)

Method Detail

buildDssback to summary
private final void buildDss(boolean dssHasSameCorrelator, boolean chainedToNextStructure, boolean nextHasSameCorrelator, int dssType, int corrId, boolean simpleFinalizeBuildingNextDss)
buildLengthAndCodePointForLobback to summary
private void buildLengthAndCodePointForLob(int codePoint, long leftToRead, boolean writeNullByte, int extendedLengthByteCount) throws DisconnectException
buildLengthAndCodePointForLobback to summary
private void buildLengthAndCodePointForLob(int codePoint, boolean writeNullByte) throws DisconnectException
buildTripletHeaderback to summary
pack-priv final void buildTripletHeader(int tripletLength, int tripletType, int tripletId)
calculateExtendedLengthByteCountback to summary
private final int calculateExtendedLengthByteCount(long ddmSize)
clearBufferback to summary
private final void clearBuffer()
createCommandback to summary
protected final void createCommand()
createCommandDataback to summary
pack-priv final void createCommandData()
createEncryptedCommandDataback to summary
pack-priv final void createEncryptedCommandData()
doesRequestContainDataback to summary
private final boolean doesRequestContainData()
encodeStringback to summary
private int encodeString(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:String

the string to encode

Returns:int

the number of bytes in the encoded representation of the string

ensureLengthback to summary
private final void ensureLength(int length)
finalizeDssLengthback to summary
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.

finalizePreviousChainedDssback to summary
private final void finalizePreviousChainedDss(boolean dssHasSameCorrelator)
flushback to summary
protected void flush(OutputStream socketOutputStream) throws IOException
flushExistingDSSback to summary
private final void flushExistingDSS() throws DisconnectException
flushScalarStreamSegmentback to summary
private final int flushScalarStreamSegment(long leftToRead, int bytesToRead) throws DisconnectException
flushScalarStreamSegmentback to summary
private final int flushScalarStreamSegment() throws DisconnectException
initializeback to summary
pack-priv final void initialize()
markback to summary
private final void mark()
markForCachingPKGNAMCSNback to summary
protected final void markForCachingPKGNAMCSN()
markLengthBytesback to summary
protected final void markLengthBytes(int codePoint)
maskOutPasswordback to summary
private final void maskOutPassword()
padBytesback to summary
private final void padBytes(byte padByte, int length)
padScalarStreamForErrorback to summary
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:long

total number of bytes left to read

bytesToRead:int

remaining bytes to read before flushing

writeStatus:boolean

whether or not to wrote the Derby-specific trailing EXTDTA status flag (see DRDAConstants)

status:byte

the EXTDTA status (for this data value), ignored if writeStatus is false

Exceptions
DisconnectException:
if flushing the buffer fails
peekStreamback to summary
private static boolean peekStream(BufferedInputStream in) throws IOException
popMarkback to summary
private final int popMark()
popMarkForCachingPKGNAMCSNback to summary
protected final int popMarkForCachingPKGNAMCSN()
prepScalarStreamback to summary
private final int prepScalarStream(boolean chained, boolean chainedWithSameCorrelator, boolean writeNullByte, long leftToRead) throws DisconnectException
sendBytesback to summary
private void sendBytes(OutputStream socketOutputStream) throws IOException
setCorrelationIDback to summary
public void setCorrelationID(int id)
setDssLengthLocationback to summary
public void setDssLengthLocation(int location)
updateLengthBytesback to summary
protected final void updateLengthBytes() throws SqlException
write1Byteback to summary
pack-priv final void write1Byte(int value)
write2Bytesback to summary
pack-priv final void write2Bytes(int value)
write4Bytesback to summary
pack-priv final void write4Bytes(long value)
writeBigDecimalback to summary
pack-priv final void writeBigDecimal(BigDecimal v, int declaredPrecision, int declaredScale) throws SqlException
writeBooleanback to summary
pack-priv final void writeBoolean(boolean v)
writeByteback to summary
private void writeByte(byte v)
writeBytesback to summary
pack-priv final void writeBytes(byte[] buf, int length)
writeBytesback to summary
pack-priv final void writeBytes(byte[] buf)
writeCodePoint4Bytesback to summary
pack-priv final void writeCodePoint4Bytes(int codePoint, int value)
writeDateback to summary
pack-priv final void writeDate(DateTimeValue date) throws SqlException
writeDoubleback to summary
protected void writeDouble(double v)
writeEXTDTAStatusback to summary
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:byte

the Derby-specific EXTDTA status flag

Exceptions
DisconnectException:
if flushing the buffer fails
writeExtendedLengthBytesback to summary
private final void writeExtendedLengthBytes(int extendedLengthByteCount, long length)
writeFloatback to summary
protected void writeFloat(float v)
writeIntback to summary
pack-priv void writeInt(int v)
writeIntFdocaDataback to summary
protected void writeIntFdocaData(int v)
writeLDBytesback to summary
pack-priv final void writeLDBytes(byte[] bytes)
writeLDBytesXback to summary
private final void writeLDBytesX(int ldSize, byte[] bytes)
writeLDBytesXSubsetback to summary
private final void writeLDBytesXSubset(int ldSize, int bytesToCopy, byte[] bytes)
writeLengthCodePointback to summary
pack-priv final void writeLengthCodePoint(int length, int codePoint)
writeLidAndLengthsback to summary
private void writeLidAndLengths(int[][] lidAndLengthOverrides, int count, int offset)
writeLidAndLengthsback to summary
pack-priv final void writeLidAndLengths(int[][] lidAndLengthOverrides, int count, int offset, boolean mddRequired, Hashtable<K, V> map)
writeLongback to summary
pack-priv final void writeLong(long v)
writeLong6Bytesback to summary
pack-priv final void writeLong6Bytes(long v)

Writes a long into the buffer, using six bytes.

Parameters
v:long

the value to write

Exceptions
IllegalArgumentException:
if the long value is too large to be represented by six bytes.
writeLongFdocaDataback to summary
protected void writeLongFdocaData(long v)
writePlainScalarStreamback to summary
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:long

the byte length of the stream

in:InputStream

the stream to transfer

writeNullByte:boolean

whether or not to write a NULL indicator

parameterIndex:int

one-based parameter index

Exceptions
DisconnectException:
if a severe error condition is encountered, causing the connection to be broken
writePlainScalarStreamback to summary
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:InputStream

the stream to transfer

writeNullByte:boolean

whether or not to write a NULL indicator

parameterIndex:int

one-based parameter index

Exceptions
DisconnectException:
if a severe error condition is encountered, causing the connection to be broken
writeScalar1Byteback to summary
protected final void writeScalar1Byte(int codePoint, int value)
writeScalar2Bytesback to summary
pack-priv final void writeScalar2Bytes(int codePoint, int value)
writeScalar4Bytesback to summary
protected final void writeScalar4Bytes(int codePoint, long value)
writeScalar8Bytesback to summary
pack-priv final void writeScalar8Bytes(int codePoint, long value)
writeScalarBytesback to summary
pack-priv final void writeScalarBytes(int codePoint, byte[] buff)
writeScalarBytesback to summary
pack-priv final void writeScalarBytes(int codePoint, byte[] buff, int start, int length)
writeScalarPaddedBytesback to summary
pack-priv final void writeScalarPaddedBytes(byte[] buff, int paddedLength, byte padByte)
writeScalarStreamback to summary
pack-priv final void writeScalarStream(boolean chained, boolean chainedWithSameCorrelator, int codePoint, InputStream in, boolean writeNullByte, int parameterIndex) throws DisconnectException, SqlException
writeScalarStreamback to summary
pack-priv final void writeScalarStream(boolean chained, boolean chainedWithSameCorrelator, int codePoint, long length, InputStream in, boolean writeNullByte, int parameterIndex) throws DisconnectException, SqlException
writeScalarStreamback to summary
pack-priv final void writeScalarStream(boolean chained, boolean chainedWithSameCorrelator, int codePoint, int length, Reader r, boolean writeNullByte, int parameterIndex) throws DisconnectException, SqlException
writeScalarStreamback to summary
pack-priv final void writeScalarStream(boolean chained, boolean chainedWithSameCorrelator, int codePoint, Reader r, boolean writeNullByte, int parameterIndex) throws DisconnectException, SqlException
writeScalarStringback to summary
pack-priv final void writeScalarString(int codePoint, String string) throws SqlException

Write string with no minimum or maximum limit.

Parameters
codePoint:int

codepoint to write

string:String

value to write

writeScalarStringback to summary
pack-priv 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:int

codepoint to write

string:String

value

byteMinLength:int

minimum length. String will be padded with spaces if value is too short. Assumes space character is one byte.

byteLengthLimit:int

Limit to string length. SQLException will be thrown if we exceed this limit.

sqlState:String

SQLState to throw with string as param if byteLengthLimit is exceeded.

Exceptions
SqlException:
if string exceeds byteLengthLimit
writeShortback to summary
pack-priv final void writeShort(short v)
writeShortFdocaDataback to summary
protected void writeShortFdocaData(short v)
writeSingleorMixedCcsidLDStringback to summary
pack-priv final void writeSingleorMixedCcsidLDString(String s, Charset encoding) throws SqlException
writeTimeback to summary
pack-priv final void writeTime(DateTimeValue time)
writeTimestampback to summary
pack-priv final void writeTimestamp(DateTimeValue timestamp) throws SqlException
writeUDTback to summary
pack-priv final void writeUDT(Object val) throws SqlException