DBConnection dbConnection = dbservice.dbConnection(
sysconfig.getKamURL(),
sysconfig.getKamUser(),
sysconfig.getKamPassword());
KAMStore kAMStore = new KAMStoreImpl(dbConnection);
// See if we need to set up the KAM Store schemas
final KAMStoreSchemaService kamSchemaService =
new KAMStoreSchemaServiceImpl(dbservice);
// Load the KAM catalog schema, if it doesn't exist (see #88).
kamSchemaService.setupKAMCatalogSchema();
try {
if (mode == Mode.LIST) {
List<KamInfo> kamInfos = kAMStore.getCatalog();
printKamCatalogSummary(kamInfos);
} else if (mode == Mode.COMPARE) {
final KamComparisonXHTMLWriter xhtmlWriter =
createOutputFileWriter();
final String[] kamNames = new String[] { kam1Name, kam2Name };
// Get the KAM catalog information for each KAM.
final KamInfo[] kamInfos = new KamInfo[kamNames.length];
for (int i = 0; i < kamNames.length; ++i) {
final KamInfo kamInfo = kAMStore.getKamInfo(kamNames[i]);
if (kamInfo == null) {
reportable.error("No KAM found with name '"
+ kamNames[i] + "'");
bail(ExitCode.GENERAL_FAILURE);
}
kamInfos[i] = kamInfo;
}
// Create the KamComparison that will be displayed and/or written to the
// output file.
final KamComparison cmp = new KamComparison(kamNames);
for (KamInfo kamInfo : kamInfos) {
final String kamName = kamInfo.getName();
final KAMStoreStatisticsDaoImpl dao =
new KAMStoreStatisticsDaoImpl(
kamInfo.getKamDbObject().getSchemaName(),
dbConnection);
cmp.setKamNodeCount(kamName, dao.getKamNodeCount());
cmp.setKamEdgeCount(kamName, dao.getKamEdgeCount());
cmp.setBELDocumentCount(kamName, dao.getBELDocumentCount());
cmp.setNamespaceCount(kamName, dao.getNamespaceCount());
cmp.setAnnotationDefinitionCount(kamName,
dao.getAnnotationDefinitonCount());
cmp.setAnnotationCount(kamName, dao.getAnnotationCount());
cmp.setStatementCount(kamName, dao.getStatementCount());
cmp.setTermCount(kamName, dao.getTermCount());
cmp.setParameterCount(kamName, dao.getParameterCount());
cmp.setUniqueParameterCount(kamName,
dao.getUniqueParameterCount());
}
// Write to stdout.
writeComparison(cmp);
// Write the output to the output file.
if (xhtmlWriter != null) {
xhtmlWriter.writeKamComparison(cmp);
xhtmlWriter.close();
}
}
} finally {
kAMStore.teardown();
dbConnection.getConnection().close();
}
}