public interface XStreamLCRCallbackHandler
XStreamIn, XStreamOut, LCR| Modifier and Type | Method and Description |
|---|---|
ChunkColumnValue |
createChunk()
The callback method for constructing chunk data that is sent to an XStream inbound server.
|
LCR |
createLCR()
The callback method for creating an LCR and sending it to an XStream inbound server.
|
void |
processChunk(ChunkColumnValue chunk)
The callback method for processing chunk data received from an XStream outbound server for an LCR received through the processLCR callback method.
|
void |
processLCR(LCR lcr)
The callback method for processing an LCR recevied from an XStream outbound server.
|
void processLCR(LCR lcr) throws StreamsException
public void processLCR(LCR lcr)
throws StreamsException
{
// access LCR header info
String cmdtype = lcr.getCommandType();
String srcDB = lcr.getSourceDatabaseName();
String objOwner = lcr.getObjectOwner();
String objName = lcr.getObjectName();
String txnId = lcr.getTransactionId();
DATE srcTime = lcr.getSourceTime();
byte[] pos = lcr.getPosition());
...
// access scalar columns
if (lcr instanceof RowLCR)
{
if ((lcr.getCommandType()).compareTo(RowLCR.INSERT) == 0)
{
// access scalar columns in new column list
ColumnValue[] collist = ((RowLCR)lcr).getNewValues();
for (int i = 0; i < collist.length; i++)
{
String colName = collist[i].getColumnName();
Datum colData = collist[i].getColumnData();
if (colData instanceof NUMBER)
{
System.out.println(((NUMBER)coldata).intValue());
}
else if(colData instanceof CHAR)
{
System.out.println(((CHAR)colData).stringValue());
System.out.println(((CHAR)colData).oracleId());
}
...
}
if (((RowLCR)lcr).hasChunkData())
{
// prepare to retrieve all LOB columns through
// processChunk() callback method.
}
}
...
}
else
{
// handle DDL LCR.
}
}
lcr - the LCR received from an XStream outbound server.StreamsException - if error occurs when processing an LCR.void processChunk(ChunkColumnValue chunk) throws StreamsException
public void processChunk(ChunkColumnValue chunk)
throws StreamsException
{
// process the chunk data
Datum coldata = chunk.getColumnData();
String colname = chunk.getColumnName();
...
if (chunk.isLastChunk())
// do something for the column
if (chunk.isEndOfRow())
// do something for the entire row change, cleanup
}
chunk - the chunk received from an XStream outbound server.StreamsException - if error occurs when processing chunk data.LCR createLCR() throws StreamsException
public LCR createLCR()
throws StreamsException
{
// first construct the lcr with scalar columns
DefaultRowLCR alcr = new DefaultRowLCR();
alcr.setSourceDatabaseName("MY.TEST.DB");
alcr.setSourceTime(getCurrentDate());
alcr.setPosition(NUMBER.toBytes(1));
alcr.setCommandType("INSERT");
alcr.setObjectOwner("SCOTT");
alcr.setObjectName("TEST_TABLE");
alcr.setTransactionId("1.0.0");
ColumnValue[] newValues = new DefaultColumnValue[4];
try
{
CharacterSet mycharset =
CharacterSet.make(CharacterSet.AL16UTF16_CHARSET);
newValues[0] = new DefaultColumnValue("ID",new NUMBER(1));
newValues[1] = new DefaultColumnValue("CHAR_COLUMN",
new CHAR("chartest",mycharset));
DefaultChunkColumnValue chunk1 =
new DefaultChunkColumnValue("LOB1_COLUMN",
null, ChunkColumnValue.CLOB);
chunk1.setEmptyChunk(true);
newValues[2] = chunk1;
DefaultChunkColumnValue chunk2 =
new DefaultChunkColumnValue("LOB2_COLUMN",
null, ChunkColumnValue.BLOB);
chunk2.setEmptyChunk(true);
newValues[3] = chunk2;
}
catch(Exception e)
{
System.out.println("fail to construct a lcr: "+e.getMessage());
e.printStackTrace();
throw new StreamsException("fail to create an LCR");
}
alcr.setNewValues(newValues);
alcr.setChunkDataFlag(true);
// return this lcr to an XStream inbound Server
return alcr;
}
StreamsException - if error occurs when creating an LCR.ChunkColumnValue createChunk() throws StreamsException
public ChunkColumnValue createChunk()
throws StreamsException
{
// construct the chunk data
ChunkColumnValue chunk = new DefaultChunkColumnValue(...);
...
if (last chunk in the column)
chunk.setLastChunk(true)
if (last chunk for the entire row)
chunk.setEndOfRow(true);
return chunk;
}
StreamsException - if error occurs when creating chunk data.