if (rowCount == 0) {
touchSet.add(groupColValue); // Add the CREATE table name: ${ICAO_ID} itself
if (!this.tableExists) {
command = "CREATE";
if (this.queryMeatStatement != null) { // delegate processing of message meat ...
ChangeEvent changeEvent = new ChangeEvent(groupColName, groupColValue, null, command, null);
String stmt = org.xmlBlaster.contrib.dbwatcher.DbWatcher.replaceVariable(this.queryMeatStatement, groupColValue);
count = changeListener.publishMessagesFromStmt(stmt, true, changeEvent, conn);
}
else { // send message directly
if (dataConverter != null && bout == null) {
bout = new ByteArrayOutputStream();
out = new BufferedOutputStream(bout);
dataConverter.setOutputStream(out, command, groupColValue, null);
dataConverter.done();
resultXml = bout.toString();
bout = null;
}
changeListener.hasChanged(
new ChangeEvent(groupColName, groupColValue,
resultXml, command, null));
}
this.tableExists = true;
}
}
if (first) {
command = (md5Map.get(newGroupColValue) != null) ? "UPDATE" : "INSERT";
}
rowCount++;
if (dataConverter != null && bout == null) {
bout = new ByteArrayOutputStream();
out = new BufferedOutputStream(bout);
dataConverter.setOutputStream(out, command, newGroupColValue, null);
}
if (!first && !groupColValue.equals(newGroupColValue)) {
first = false;
if (log.isLoggable(Level.FINE)) log.fine("Processing " + groupColName + "=" +
groupColValue + " next one to check is '" + newGroupColValue + "'");
String newMD5 = getMD5(buf.toString());
String old = (String)md5Map.get(groupColValue);
if (old == null || !old.equals(newMD5)) {
if (this.queryMeatStatement != null) { // delegate processing of message meat ...
ChangeEvent changeEvent = new ChangeEvent(groupColName, groupColValue, null, command, null);
String stmt = org.xmlBlaster.contrib.dbwatcher.DbWatcher.replaceVariable(this.queryMeatStatement, groupColValue);
count += changeListener.publishMessagesFromStmt(stmt, true, changeEvent, conn);
}
else { // send message directly
if (dataConverter != null) {
dataConverter.done();
resultXml = bout.toString();
}
changeListener.hasChanged(
new ChangeEvent(groupColName, groupColValue,
resultXml, command, null));
count++;
}
}
buf.setLength(0);
command = (md5Map.get(newGroupColValue) != null) ? "UPDATE" : "INSERT";
if (dataConverter != null) {
bout = new ByteArrayOutputStream();
out = new BufferedOutputStream(bout);
dataConverter.setOutputStream(out, command, newGroupColValue, null);
}
md5Map.put(groupColValue, newMD5);
}
groupColValue = newGroupColValue;
for (int i=1; i<=cols; i++) { // Add cols for later MD5 calculation
//System.out.println(">"+rs.getObject(i).toString()+"<"); ">oracle.sql.TIMESTAMP@157b46f<"
//System.out.println(">"+rs.getString(i)+"<"); ">2005-1-31.23.0. 47. 236121000<"
// -> getObject is not useful as it returns for same timestamp another object instance.
buf.append(rs.getString(i));
}
if (dataConverter != null) { // Create XML dump on demand
dataConverter.addInfo(conn, rs, I_DataConverter.ALL);
}
first = false;
}
String newMD5 = getMD5(buf.toString());
String old = (String)md5Map.get(groupColValue);
if (old == null || !old.equals(newMD5)) {
if (!this.tableExists) {
command = "CREATE";
this.tableExists = true;
}
else if (old == null)
command = "INSERT";
else
command = "UPDATE";
if (this.queryMeatStatement != null) { // delegate processing of message meat ...
ChangeEvent changeEvent = new ChangeEvent(groupColName, groupColValue, null, command, null);
String stmt = org.xmlBlaster.contrib.dbwatcher.DbWatcher.replaceVariable(this.queryMeatStatement, groupColValue);
count += changeListener.publishMessagesFromStmt(stmt, true, changeEvent, conn);
}
else { // send message directly
if (dataConverter != null) {
if (bout == null) {
bout = new ByteArrayOutputStream();
out = new BufferedOutputStream(bout);
dataConverter.setOutputStream(out, command, newGroupColValue, null);
dataConverter.addInfo(conn, rs, I_DataConverter.META_ONLY); // Add the meta info for a CREATE
}
dataConverter.done();
resultXml = bout.toString();
}
changeListener.hasChanged(
new ChangeEvent(groupColName, groupColValue, resultXml, command, null));
count++;
}
}
touchSet.add(groupColValue);
md5Map.put(groupColValue, newMD5);
buf.setLength(0);
// Check for DELETEd entries ...
String[] arr = (String[])md5Map.keySet().toArray(new String[md5Map.size()]);
for (int i=0; i<arr.length; i++) {
if (!touchSet.contains(arr[i])) {
String key = arr[i];
md5Map.remove(key);
command = "DELETE";
if (this.queryMeatStatement != null) { // delegate processing of message meat ...
ChangeEvent changeEvent = new ChangeEvent(groupColName, key, null, command, null);
String stmt = org.xmlBlaster.contrib.dbwatcher.DbWatcher.replaceVariable(this.queryMeatStatement, key);
count += changeListener.publishMessagesFromStmt(stmt, true, changeEvent, conn);
}
else { // send message directly
if (dataConverter != null) {
bout = new ByteArrayOutputStream();
out = new BufferedOutputStream(bout);
dataConverter.setOutputStream(out, command, key, null);
dataConverter.done();
resultXml = bout.toString();
}
changeListener.hasChanged(
new ChangeEvent(groupColName, key,
resultXml, command, null));
}
count++;
}
}