|
|||||||||
| Home >> All >> org >> apache >> derby >> impl >> [ drda overview ] | PREV CLASS NEXT CLASS | ||||||||
SUMMARY: JAVADOC | SOURCE | DOWNLOAD | NESTED | FIELD | CONSTR | METHOD |
DETAIL: FIELD | CONSTR | METHOD | ||||||||
org.apache.derby.impl.drda
Class DDMWriter

java.lang.Objectorg.apache.derby.impl.drda.DDMWriter
- class DDMWriter
- extends java.lang.Object
The DDMWriter is used to write DRDA protocol. The DRDA Protocol is described in the DDMReader class. For more details, see DRDA Volume 3 (Distributed Data Management(DDM) Architecture (DDS definition)
| Field Summary | |
private DRDAConnThread |
agent
|
private byte[] |
bytes
|
private CcsidManager |
ccsidManager
|
private int |
correlationID
|
private static int |
DEFAULT_BUFFER_SIZE
|
private int |
dssLengthLocation
|
private DssTrace |
dssTrace
|
private boolean |
isContinuationDss
|
private boolean |
isDRDAProtocol
|
private int |
lastDSSBeforeMark
|
private int[] |
markStack
|
private static int |
MAX_MARKS_NESTING
|
private int |
nextCorrelationID
|
private int |
offset
|
private int |
prevHdrLocation
|
private byte |
previousChainByte
|
private int |
previousCorrId
|
private int |
top
|
(package private) static java.math.BigDecimal |
ZERO
|
| Constructor Summary | |
(package private) |
DDMWriter(CcsidManager ccsidManager,
DRDAConnThread agent,
DssTrace dssTrace)
|
(package private) |
DDMWriter(int minSize,
CcsidManager ccsidManager,
DRDAConnThread agent,
DssTrace dssTrace)
|
| Method Summary | |
private void |
beginDss(boolean chainedToNextStructure,
int dssType)
Begins a DSS stream (for writing LOB data). |
private void |
beginDss(int dssType,
boolean ensureLen)
Write DSS header DSS Header format is 2 bytes - length 1 byte - 'D0' - indicates DDM data 1 byte - DSS format |---|---------|----------| | 0 | flags | type | |---|---------|----------| | 0 | 1 2 3 | 4 5 6 7 | |---|---------|----------| bit 0 - '0' bit 1 - '0' - unchained, '1' - chained bit 2 - '0' - do not continue on error, '1' - continue on error bit 3 - '0' - next DSS has different correlator, '1' - next DSS has same correlator type - 1 - Request DSS - 2 - Reply DSS - 3 - Object DSS - 4 - Communications DSS - 5 - Request DSS where no reply is expected |
private int |
bigDecimalToPackedDecimalBytes(java.math.BigDecimal b,
int precision,
int scale)
Write a Java java.math.BigDecimal to packed decimal bytes. |
private int |
calculateExtendedLengthByteCount(long ddmSize)
Calculate extended length byte count which follows the DSS header for extended DDM. |
protected void |
clearBuffer()
Clear the entire send buffer |
protected void |
clearDdm()
Erase all writes for the current ddm and reset the top |
protected void |
clearDSSesBackToMark(int mark)
Does a logical "clear" of everything written to the buffer after the received mark. |
protected byte[] |
copyDataToEnd(int start)
Copy Data to End Create a buffer and copy from the position given to the end of data |
protected void |
createDssObject()
Create DSS data object |
protected void |
createDssReply()
Create DSS reply object |
protected void |
createDssRequest()
Create DSS request object NOTE: This is _ONLY_ used for testing the protocol (via the TestProto.java file in this package)! We should never create a DSS request in normal DRDA processing (we should only create DSS replies and DSS objects). |
protected boolean |
doesRequestContainData()
|
protected void |
endDdm()
End the current DDM |
protected void |
endDdmAndDss()
End final DDM and DSS header by writing the length in the length location |
protected void |
endDss()
End DSS header by writing the length in the length location and setting the chain bit. |
private void |
endDss(boolean finalizeLength)
End DSS header by writing the length in the length location and setting the chain bit. |
protected void |
endDss(byte chainByte)
End DSS header by writing the length in the length location and setting the chain bit. |
private void |
ensureLength(int length)
Ensure that there is space in the buffer |
protected void |
finalizeChain(byte currChainByte,
java.io.OutputStream socketOutputStream)
Finalize the current DSS chain and send it if needed. |
private void |
finalizeDssLength()
Finish a DSS Layer A object. |
protected void |
flush()
Flush buffer to outputstream |
protected void |
flush(java.io.OutputStream socketOutputStream)
Flush buffer to specified stream |
protected int |
flushScalarStreamSegment(int leftToRead,
int bytesToRead)
|
private int |
getCorrelationID()
Looks at chaining info for previous DSS written, and use that to figure out what the correlation id for the current DSS should be. |
protected int |
getOffset()
Get offset |
private void |
markDssAsContinued(boolean forLob)
Mark the DSS that we're currently writing as a continued DSS, which is done by setting the high-order bit to "1", per DDM spec. |
protected int |
markDSSClearPoint()
Takes note of the location of the most recently completed DSS in the buffer, and then returns the current offset. |
private static int |
min(int i,
int j)
|
protected void |
padBytes(byte val,
int length)
Write pad bytes using spaceChar |
protected void |
padScalarStreamForError(int leftToRead,
int bytesToRead)
|
protected int |
prepScalarStream(boolean chainedWithSameCorrelator,
int codePoint,
boolean writeNullByte,
int leftToRead)
|
protected void |
reset(DssTrace dssTrace)
reset values for sending next message |
protected void |
resetChainState()
Reset any chaining state that needs to be reset at time of the send |
private void |
sendBytes(java.io.OutputStream socketOutputStream)
|
protected void |
setCMDProtocol()
set protocol to CMD protocol |
protected void |
setOffset(int value)
Set offset |
protected void |
startDdm(int codePoint)
Mark the location of the length bytes for the collection so they can be updated later |
protected void |
startDdm(int length,
int codePoint)
Write length and codepoint |
protected java.lang.String |
toDebugString(java.lang.String indent)
|
protected void |
writeBigDecimal(java.math.BigDecimal v,
int precision,
int scale)
Write big decimal to buffer |
protected void |
writeBoolean(boolean v)
Write platform boolean |
protected void |
writeByte(int value)
Write byte |
protected void |
writeBytes(byte[] buf)
Write byte array |
protected void |
writeBytes(byte[] buf,
int length)
Write byte array |
protected void |
writeBytes(byte[] buf,
int start,
int length)
Write byte array |
(package private) void |
writeCodePoint4Bytes(int codePoint,
int value)
Write code point and 4 bytes |
protected void |
writeDouble(double v)
Write platform double |
protected void |
writeExtendedLength(long size)
|
private void |
writeExtendedLengthBytes(int extendedLengthByteCount,
long length)
|
protected void |
writeFloat(float v)
Write platform float |
protected void |
writeInt(int v)
Write platform int |
protected void |
writeLDBytes(byte[] buf)
|
protected void |
writeLDBytes(byte[] buf,
int index)
|
protected void |
writeLDString(java.lang.String s)
Write length delimited string |
protected void |
writeLDString(java.lang.String s,
int index)
Write length delimited string |
(package private) void |
writeLengthCodePoint(int length,
int codePoint)
|
protected void |
writeLong(long v)
Write platform long |
protected void |
writeNetworkInt(int value)
Write network int |
protected void |
writeNetworkShort(int value)
Write network short |
(package private) void |
writeScalar1Byte(int codePoint,
int value)
Write scalar 1 byte object includes length, codepoint and value |
protected void |
writeScalar2Bytes(int value)
|
protected void |
writeScalar2Bytes(int codePoint,
int value)
Write scalar 2 byte object includes length, codepoint and value |
protected void |
writeScalarBytes(int codePoint,
byte[] buf)
Write scalar byte array object includes length, codepoint and value |
protected void |
writeScalarBytes(int codePoint,
byte[] buf,
int length)
Write scalar byte array object includes length, codepoint and value |
protected void |
writeScalarBytes(int codePoint,
byte[] buf,
int start,
int length)
Write scalar byte array object includes length, codepoint and value |
protected void |
writeScalarHeader(int codePoint,
int dataLength)
Write scalar object header includes length and codepoint |
protected void |
writeScalarPaddedBytes(byte[] buf,
int paddedLength,
byte padByte)
Write padded scalar byte array object value |
protected void |
writeScalarPaddedBytes(int codePoint,
byte[] buf,
int paddedLength,
byte padByte)
Write padded scalar byte array object includes length, codepoint and value |
(package private) void |
writeScalarPaddedString(int codePoint,
java.lang.String string,
int paddedLength)
Write padded scalar string object includes length, codepoint and value the string is converted into the appropriate codeset (EBCDIC) |
protected void |
writeScalarPaddedString(java.lang.String string,
int paddedLength)
Write padded scalar string object value the string is converted into the appropriate codeset (EBCDIC) |
protected int |
writeScalarStream(boolean chainedWithSameCorrelator,
int codePoint,
int length,
java.io.InputStream in,
boolean writeNullByte)
|
(package private) void |
writeScalarString(int codePoint,
java.lang.String string)
Write scalar string object includes length, codepoint and value the string is converted into the appropriate codeset (EBCDIC) |
protected void |
writeShort(boolean b)
Write boolean as short |
protected void |
writeShort(int v)
Write platform short |
protected void |
writeString(java.lang.String s)
Write string with default encoding |
protected void |
writeString(java.lang.String s,
int length)
Write string with default encoding and specified length |
static java.lang.String |
zeroPadString(java.lang.String s,
int precision)
Prepend zeros to numeric string |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
MAX_MARKS_NESTING
private static final int MAX_MARKS_NESTING
- See Also:
- Constant Field Values
DEFAULT_BUFFER_SIZE
private static final int DEFAULT_BUFFER_SIZE
- See Also:
- Constant Field Values
ZERO
static final java.math.BigDecimal ZERO
bytes
private byte[] bytes
offset
private int offset
markStack
private int[] markStack
top
private int top
ccsidManager
private CcsidManager ccsidManager
agent
private DRDAConnThread agent
dssLengthLocation
private int dssLengthLocation
correlationID
private int correlationID
nextCorrelationID
private int nextCorrelationID
isDRDAProtocol
private boolean isDRDAProtocol
dssTrace
private DssTrace dssTrace
prevHdrLocation
private int prevHdrLocation
previousCorrId
private int previousCorrId
previousChainByte
private byte previousChainByte
isContinuationDss
private boolean isContinuationDss
lastDSSBeforeMark
private int lastDSSBeforeMark
| Constructor Detail |
DDMWriter
DDMWriter(int minSize,
CcsidManager ccsidManager,
DRDAConnThread agent,
DssTrace dssTrace)
DDMWriter
DDMWriter(CcsidManager ccsidManager, DRDAConnThread agent, DssTrace dssTrace)
| Method Detail |
reset
protected void reset(DssTrace dssTrace)
- reset values for sending next message
setCMDProtocol
protected void setCMDProtocol()
- set protocol to CMD protocol
createDssReply
protected void createDssReply()
- Create DSS reply object
createDssRequest
protected void createDssRequest()
- Create DSS request object
NOTE: This is _ONLY_ used for testing the protocol
(via the TestProto.java file in this package)!
We should never create a DSS request in normal
DRDA processing (we should only create DSS replies
and DSS objects).
createDssObject
protected void createDssObject()
- Create DSS data object
markDssAsContinued
private void markDssAsContinued(boolean forLob)
- Mark the DSS that we're currently writing as
a continued DSS, which is done by setting
the high-order bit to "1", per DDM spec.
This means:
1. One or more continuation DSSes will immediately
follow the current (continued) DSS.
2. All continuation DSSes will have a 2-byte
continuation header, followed by data; in
other words, chaining state, correlation
id, dss format info, and code point will
NOT be included. All of that info is
present ONLY in the FIRST DSS in the
list of continued DSSes.
NOTE: A DSS can be a "continuation" DSS _and_
a "continued" DSS at the same time. However,
the FIRST DSS to be continued canNOT be
a continuation DSS.
endDss
protected void endDss(byte chainByte)
- End DSS header by writing the length in the length location
and setting the chain bit. Unlike the other two endDss
methods, this one overrides the default chaining byte
(which is set in beginDss) with the chaining byte that
is passed in. NOTE: This method is only used in
association with createDssRequest, and thus is for
TESTING purposes only (via TestProto.java). No calls
should be made to this method in normal DRDA processing
(because for normal processing, chaining must be
determined automatically based on DSS requests).
endDss
protected void endDss()
- End DSS header by writing the length in the length location
and setting the chain bit.
endDss
private void endDss(boolean finalizeLength)
- End DSS header by writing the length in the length location
and setting the chain bit.
endDdmAndDss
protected void endDdmAndDss()
- End final DDM and DSS header by writing the length in the length location
copyDataToEnd
protected byte[] copyDataToEnd(int start)
- Copy Data to End
Create a buffer and copy from the position given to the end of data
startDdm
protected void startDdm(int codePoint)
- Mark the location of the length bytes for the collection so they
can be updated later
clearDdm
protected void clearDdm()
- Erase all writes for the current ddm and reset the
top
clearBuffer
protected void clearBuffer()
- Clear the entire send buffer
endDdm
protected void endDdm()
- End the current DDM
getOffset
protected int getOffset()
- Get offset
setOffset
protected void setOffset(int value)
- Set offset
writeByte
protected void writeByte(int value)
- Write byte
writeNetworkShort
protected void writeNetworkShort(int value)
- Write network short
writeNetworkInt
protected void writeNetworkInt(int value)
- Write network int
writeBytes
protected void writeBytes(byte[] buf,
int length)
- Write byte array
writeBytes
protected void writeBytes(byte[] buf,
int start,
int length)
- Write byte array
writeBytes
protected void writeBytes(byte[] buf)
- Write byte array
writeLDBytes
protected void writeLDBytes(byte[] buf)
writeLDBytes
protected void writeLDBytes(byte[] buf,
int index)
writeCodePoint4Bytes
void writeCodePoint4Bytes(int codePoint,
int value)
- Write code point and 4 bytes
writeScalar1Byte
void writeScalar1Byte(int codePoint,
int value)
- Write scalar 1 byte object includes length, codepoint and value
writeScalar2Bytes
protected void writeScalar2Bytes(int codePoint,
int value)
- Write scalar 2 byte object includes length, codepoint and value
writeScalar2Bytes
protected void writeScalar2Bytes(int value)
startDdm
protected void startDdm(int length,
int codePoint)
- Write length and codepoint
writeScalarBytes
protected void writeScalarBytes(int codePoint,
byte[] buf,
int length)
- Write scalar byte array object includes length, codepoint and value
writeScalarStream
protected int writeScalarStream(boolean chainedWithSameCorrelator,
int codePoint,
int length,
java.io.InputStream in,
boolean writeNullByte)
throws DRDAProtocolException
beginDss
private void beginDss(boolean chainedToNextStructure,
int dssType)
- Begins a DSS stream (for writing LOB data).
prepScalarStream
protected int prepScalarStream(boolean chainedWithSameCorrelator,
int codePoint,
boolean writeNullByte,
int leftToRead)
throws DRDAProtocolException
doesRequestContainData
protected boolean doesRequestContainData()
flushScalarStreamSegment
protected int flushScalarStreamSegment(int leftToRead,
int bytesToRead)
throws DRDAProtocolException
padScalarStreamForError
protected void padScalarStreamForError(int leftToRead,
int bytesToRead)
throws DRDAProtocolException
writeExtendedLengthBytes
private void writeExtendedLengthBytes(int extendedLengthByteCount,
long length)
writeLengthCodePoint
void writeLengthCodePoint(int length,
int codePoint)
writeScalarHeader
protected void writeScalarHeader(int codePoint,
int dataLength)
- Write scalar object header includes length and codepoint
writeScalarString
void writeScalarString(int codePoint,
java.lang.String string)
- Write scalar string object includes length, codepoint and value
the string is converted into the appropriate codeset (EBCDIC)
writeScalarPaddedString
void writeScalarPaddedString(int codePoint,
java.lang.String string,
int paddedLength)
- Write padded scalar string object includes length, codepoint and value
the string is converted into the appropriate codeset (EBCDIC)
writeScalarPaddedString
protected void writeScalarPaddedString(java.lang.String string, int paddedLength)
- Write padded scalar string object value
the string is converted into the appropriate codeset (EBCDIC)
writeScalarPaddedBytes
protected void writeScalarPaddedBytes(int codePoint,
byte[] buf,
int paddedLength,
byte padByte)
- Write padded scalar byte array object includes length, codepoint and value
writeScalarPaddedBytes
protected void writeScalarPaddedBytes(byte[] buf,
int paddedLength,
byte padByte)
- Write padded scalar byte array object value
writeScalarBytes
protected void writeScalarBytes(int codePoint,
byte[] buf)
- Write scalar byte array object includes length, codepoint and value
writeScalarBytes
protected void writeScalarBytes(int codePoint,
byte[] buf,
int start,
int length)
- Write scalar byte array object includes length, codepoint and value
writeShort
protected void writeShort(int v)
- Write platform short
writeShort
protected void writeShort(boolean b)
- Write boolean as short
writeInt
protected void writeInt(int v)
- Write platform int
writeLong
protected void writeLong(long v)
- Write platform long
writeFloat
protected void writeFloat(float v)
- Write platform float
writeDouble
protected void writeDouble(double v)
- Write platform double
writeBigDecimal
protected void writeBigDecimal(java.math.BigDecimal v, int precision, int scale) throws java.sql.SQLException
- Write big decimal to buffer
writeBoolean
protected void writeBoolean(boolean v)
- Write platform boolean
writeLDString
protected void writeLDString(java.lang.String s) throws DRDAProtocolException
- Write length delimited string
writeLDString
protected void writeLDString(java.lang.String s, int index) throws DRDAProtocolException
- Write length delimited string
writeString
protected void writeString(java.lang.String s) throws DRDAProtocolException
- Write string with default encoding
writeString
protected void writeString(java.lang.String s, int length) throws DRDAProtocolException
- Write string with default encoding and specified length
padBytes
protected void padBytes(byte val,
int length)
- Write pad bytes using spaceChar
flush
protected void flush()
throws java.io.IOException
- Flush buffer to outputstream
flush
protected void flush(java.io.OutputStream socketOutputStream) throws java.io.IOException
- Flush buffer to specified stream
beginDss
private void beginDss(int dssType,
boolean ensureLen)
- Write DSS header
DSS Header format is
2 bytes - length
1 byte - 'D0' - indicates DDM data
1 byte - DSS format
|---|---------|----------|
| 0 | flags | type |
|---|---------|----------|
| 0 | 1 2 3 | 4 5 6 7 |
|---|---------|----------|
bit 0 - '0'
bit 1 - '0' - unchained, '1' - chained
bit 2 - '0' - do not continue on error, '1' - continue on error
bit 3 - '0' - next DSS has different correlator, '1' - next DSS has
same correlator
type - 1 - Request DSS
- 2 - Reply DSS
- 3 - Object DSS
- 4 - Communications DSS
- 5 - Request DSS where no reply is expected
finalizeDssLength
private void finalizeDssLength()
- Finish a DSS Layer A object.
The length of dss object will be calculated based on the difference between the
start of the dss, saved on the beginDss call, 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.
writeExtendedLength
protected void writeExtendedLength(long size)
calculateExtendedLengthByteCount
private int calculateExtendedLengthByteCount(long ddmSize)
- Calculate extended length byte count which follows the DSS header
for extended DDM.
ensureLength
private void ensureLength(int length)
- Ensure that there is space in the buffer
bigDecimalToPackedDecimalBytes
private int bigDecimalToPackedDecimalBytes(java.math.BigDecimal b, int precision, int scale) throws java.sql.SQLException
- Write a Java
java.math.BigDecimalto packed decimal bytes.
zeroPadString
public static java.lang.String zeroPadString(java.lang.String s, int precision)
- Prepend zeros to numeric string
sendBytes
private void sendBytes(java.io.OutputStream socketOutputStream) throws java.io.IOException
min
private static int min(int i,
int j)
toDebugString
protected java.lang.String toDebugString(java.lang.String indent)
resetChainState
protected void resetChainState()
- Reset any chaining state that needs to be reset
at time of the send
getCorrelationID
private int getCorrelationID()
- Looks at chaining info for previous DSS written, and use
that to figure out what the correlation id for the current
DSS should be. Return that correlation id.
finalizeChain
protected void finalizeChain(byte currChainByte,
java.io.OutputStream socketOutputStream)
throws DRDAProtocolException
- Finalize the current DSS chain and send it if
needed.
Updates the chaining state of the most recently-written-
to-buffer DSS to correspond to the most recently-read-
from-client request. If that chaining state indicates
we've reached the end of a chain, then we go ahead
and send the buffer across the wire.
markDSSClearPoint
protected int markDSSClearPoint()
- Takes note of the location of the most recently completed
DSS in the buffer, and then returns the current offset.
This method is used in conjunction with "clearDSSesBackToMark"
to allow for DRDAConnThread to "back-out" DSSes in the
event of errors.
clearDSSesBackToMark
protected void clearDSSesBackToMark(int mark)
- Does a logical "clear" of everything written to the buffer after
the received mark. It's assumed that this method will be used
in error cases when we've started writing one or more DSSes,
but then hit an error and need to back out. After backing out,
we'll always need to write _something_ back to the client to
indicate an error (typically, we just write an SQLCARD) but what
exactly gets written is handled in DRDAConnThread. Here, we
just do the necessary prep so that whatever comes next will
succeed.
|
|||||||||
| Home >> All >> org >> apache >> derby >> impl >> [ drda overview ] | PREV CLASS NEXT CLASS | ||||||||
SUMMARY: JAVADOC | SOURCE | DOWNLOAD | NESTED | FIELD | CONSTR | METHOD |
DETAIL: FIELD | CONSTR | METHOD | ||||||||
JAVADOC
org.apache.derby.impl.drda.DDMWriter