tableSet.add(nextToken);
}
}
/* 2) resolve dependencies */
ResolverResult resolverResult = null;
List<String> tableSequence;
if (needsSort) {
tableSequence = new ArrayList<String>();
Logger.info("Retrieving and sorting tables. This may take a while, please be patient.");
// get sorted tables
final SQLMetaData meta = new SQLMetaDataBuilder().getMetaData(session, tableSet.iterator());
final DependencyResolver dr = new DependencyResolver(meta.getTables());
resolverResult = dr.sortTables();
final Collection<Table> tabs = resolverResult.getTables();
final Iterator<Table> it = tabs.iterator();
while (it.hasNext()) {
tableSequence.add(it.next().getName());
}
} else {
tableSequence = new ArrayList<String>(tableSet);
}
/* 3) dump out */
if (tableSequence.size() > 1) {
Logger.info("%s tables to dump.", tableSequence.size());
}
final Iterator<String> it = tableSequence.iterator();
while (_running && it.hasNext()) {
final String table = it.next();
if (!alreadyDumped.contains(table)) {
final int result = dumpTable(session, table, null, out, FILE_ENCODING, alreadyDumped);
if (result != SUCCESS) {
dumpResult = result;
}
}
}
if (tableSequence.size() > 1) {
final long duration = System.currentTimeMillis() - startTime;
// TODO: move to Logger, timerenderer returns strings.
HenPlus.msg().print("Dumping " + tableSequence.size() + " tables took ");
TimeRenderer.printTime(duration, HenPlus.msg());
HenPlus.msg().println();
}
/* 4) warn about cycles */
if (resolverResult != null && resolverResult.getCyclicDependencies() != null
&& resolverResult.getCyclicDependencies().size() > 0) {
HenPlus.msg().println(
"-----------\n" + "NOTE: There have been cyclic dependencies between several tables detected.\n"
+ "These may cause trouble when dumping in the currently dumped data.");
// TODO: soll count nicht vielleicht hochgezählt werden
final int count = 0;
final StringBuilder sb = new StringBuilder();
for (Collection<Table> tables : resolverResult.getCyclicDependencies()) {
sb.append("Cycle ").append(count).append(": ");
for (Table table : tables) {
sb.append(table.getName()).append(" -> ");
}