use of org.jumpmind.symmetric.io.DbCompareReport.TableReport in project symmetric-ds by JumpMind.
the class DbCompare method compare.
public DbCompareReport compare() {
dbValueComparator.setNumericScale(config.getNumericScale());
OutputStream sqlDiffOutput = getSqlDiffOutputStream();
DbCompareReport report = new DbCompareReport();
long start = System.currentTimeMillis();
List<DbCompareTables> tablesToCompare = getTablesToCompare();
report.printReportHeader(System.out);
for (DbCompareTables tables : tablesToCompare) {
try {
TableReport tableReport = compareTables(tables, sqlDiffOutput);
report.addTableReport(tableReport);
long elapsed = System.currentTimeMillis() - start;
log.info("Completed table {}. Elapsed time: {}", tableReport, DurationFormatUtils.formatDurationWords((elapsed), true, true));
report.printTableReport(tableReport, System.out);
} catch (Exception e) {
log.error("Exception while comparing " + tables.getSourceTable() + " to " + tables.getTargetTable(), e);
}
}
report.printReportFooter(System.out);
long totalTime = System.currentTimeMillis() - start;
log.info("dbcompare complete. Total Time: {}", DurationFormatUtils.formatDurationWords((totalTime), true, true));
return report;
}
use of org.jumpmind.symmetric.io.DbCompareReport.TableReport in project symmetric-ds by JumpMind.
the class DbCompare method compareTables.
protected TableReport compareTables(DbCompareTables tables, OutputStream sqlDiffOutput) {
String sourceSelect = getSourceComparisonSQL(tables, sourceEngine.getDatabasePlatform());
String targetSelect = getTargetComparisonSQL(tables, targetEngine.getDatabasePlatform());
CountingSqlReadCursor sourceCursor = new CountingSqlReadCursor(sourceEngine.getDatabasePlatform().getSqlTemplate().queryForCursor(sourceSelect, defaultRowMapper));
CountingSqlReadCursor targetCursor = new CountingSqlReadCursor(targetEngine.getDatabasePlatform().getSqlTemplate().queryForCursor(targetSelect, defaultRowMapper));
TableReport tableReport = new TableReport();
tableReport.setSourceTable(tables.getSourceTable().getName());
tableReport.setTargetTable(tables.getTargetTable().getName());
Row sourceRow = sourceCursor.next();
Row targetRow = targetCursor.next();
int counter = 0;
long startTime = System.currentTimeMillis();
DbCompareDiffWriter diffWriter = null;
OutputStream stream = null;
if (sqlDiffOutput != null) {
diffWriter = new DbCompareDiffWriter(targetEngine, tables, sqlDiffOutput);
} else {
stream = getSqlDiffOutputStream(tables);
diffWriter = new DbCompareDiffWriter(targetEngine, tables, stream);
}
try {
while (true) {
if (sourceRow == null && targetRow == null) {
break;
}
counter++;
if ((counter % 50000) == 0) {
long elapsed = System.currentTimeMillis() - startTime;
log.info("{} rows processed for table {}. Elapsed time {}. ({} ms.) Current report status {}", counter, tables.getSourceTable().getName(), DurationFormatUtils.formatDurationWords((elapsed), true, true), elapsed, tableReport);
}
DbCompareRow sourceCompareRow = sourceRow != null ? new DbCompareRow(sourceEngine, dbValueComparator, tables.getSourceTable(), sourceRow) : null;
DbCompareRow targetCompareRow = targetRow != null ? new DbCompareRow(targetEngine, dbValueComparator, tables.getTargetTable(), targetRow) : null;
int comparePk = comparePk(tables, sourceCompareRow, targetCompareRow);
if (comparePk == 0) {
Map<Column, String> deltas = sourceCompareRow.compareTo(tables, targetCompareRow);
if (deltas.isEmpty()) {
tableReport.countMatchedRow();
} else {
diffWriter.writeUpdate(targetCompareRow, deltas);
tableReport.countDifferentRow();
}
sourceRow = sourceCursor.next();
targetRow = targetCursor.next();
} else if (comparePk < 0) {
diffWriter.writeInsert(sourceCompareRow);
tableReport.countMissingRow();
sourceRow = sourceCursor.next();
} else {
diffWriter.writeDelete(targetCompareRow);
tableReport.countExtraRow();
targetRow = targetCursor.next();
}
tableReport.setSourceRows(sourceCursor.count);
tableReport.setTargetRows(targetCursor.count);
}
} finally {
if (stream != null) {
IOUtils.closeQuietly(stream);
}
IOUtils.closeQuietly(sourceCursor);
IOUtils.closeQuietly(targetCursor);
}
return tableReport;
}
Aggregations