shadowDataMiner.start();
Database shadowDb = new ShadowSchemaMiner().mine(true);
for (Table table : shadowDb.getTableList()) {
SourceResultSet sourceRs = sourceDataMiner.mine(table);
ShadowResultSet shadowRs = shadowDataMiner.mine(table);
sourceRsHasRecords = sourceRs.next();
shadowRsHasRecords = shadowRs.next();
String tempSourcePk = null;
boolean sourceRsMovedNext = true;
while (sourceRsHasRecords || shadowRsHasRecords) {
if (sourceRsHasRecords && !shadowRsHasRecords) {
String sourcePk = sourceRs.getString("PK");
insert(table, sourcePk, sourceRs);
} else if (!sourceRsHasRecords && shadowRsHasRecords) {
delete(table, shadowRs);
} else if (sourceRsHasRecords && shadowRsHasRecords) {
String sourcePk;
if (!sourceRsMovedNext) {
sourcePk = tempSourcePk;
} else {
sourcePk = sourceRs.getString("PK");
}
tempSourcePk = sourcePk;
String shadowPk = shadowRs.getCell("PK").getData();
if (sourcePk.compareTo(shadowPk) < 0) {
insert(table, sourcePk, sourceRs);
sourceRsMovedNext = true;
} else if (sourcePk.compareTo(shadowPk) > 0) {
delete(table, shadowRs);
sourceRsMovedNext = false;
} else if (sourcePk.compareTo(shadowPk) == 0) {
update(table, sourcePk, sourceRs, shadowRs);
sourceRsMovedNext = true;
}
}
}
sourceRs.close();
shadowRs.close();
}
sourceDataMiner.finish();
shadowDataMiner.finish();
}