}
@Override
public void run() {
// NOTE: need to normalise every page title!!
SQLiteStatement stmt = null;
try {
// list of pages in each category:
do {
println(" creating category lists");
stmt = db.prepare("SELECT cat.title, page.title FROM categories as categories " +
"INNER JOIN pages AS cat ON categories.category == cat.id " +
"INNER JOIN pages AS page ON categories.page == page.id;");
String category0 = null;
List<String> catPageList = new ArrayList<String>(1000);
while (stmt.step()) {
final String stmtCat0 = stmt.columnString(0);
final String stmtPage0 = stmt.columnString(1);
final String stmtPage = wikiModel.normalisePageTitle(stmtPage0);
if (category0 == null) {
category0 = stmtCat0;
catPageList.add(stmtPage);
} else if (category0.equals(stmtCat0)) {
catPageList.add(stmtPage);
} else {
// write old, accumulate new
writeCatToScalaris(category0, catPageList);
category0 = stmtCat0;
catPageList.add(stmtPage);
}
}
if (category0 != null && !catPageList.isEmpty()) {
writeCatToScalaris(category0, catPageList);
}
stmt.dispose();
} while (false);
// list of pages a template is used in:
do {
println(" creating template lists");
stmt = db.prepare("SELECT tpl.title, page.title FROM templates as templates " +
"INNER JOIN pages AS tpl ON templates.template == tpl.id " +
"INNER JOIN pages AS page ON templates.page == page.id;");
String template0 = null;
List<String> tplPageList = new ArrayList<String>(1000);
while (stmt.step()) {
final String stmtTpl0 = stmt.columnString(0);
final String stmtPage0 = stmt.columnString(1);
final String stmtPage = wikiModel.normalisePageTitle(stmtPage0);
if (template0 == null) {
template0 = stmtTpl0;
tplPageList.add(stmtPage);
} else if (template0.equals(stmtTpl0)) {
tplPageList.add(stmtPage);
} else {
// write old, accumulate new
writeTplToScalaris(template0, tplPageList);
template0 = stmtTpl0;
tplPageList.add(stmtPage);
}
}
if (template0 != null && !tplPageList.isEmpty()) {
writeTplToScalaris(template0, tplPageList);
}
stmt.dispose();
} while (false);
// list of pages linking to other pages:
do {
println(" creating backlink lists");
stmt = db.prepare("SELECT lnkDest.title, lnkSrc.title FROM links as links " +
"INNER JOIN pages AS lnkDest ON links.lnkDest == lnkDest.id " +
"INNER JOIN pages AS lnkSrc ON links.lnkSrc == lnkSrc.id;");
String linkDest0 = null;
List<String> backLinksPageList = new ArrayList<String>(1000);
while (stmt.step()) {
final String stmtLnkDest0 = stmt.columnString(0);
final String stmtLnkSrc0 = stmt.columnString(1);
final String stmtLnkSrc = wikiModel.normalisePageTitle(stmtLnkSrc0);
if (linkDest0 == null) {
linkDest0 = stmtLnkDest0;
backLinksPageList.add(stmtLnkSrc);
} else if (linkDest0.equals(stmtLnkDest0)) {
backLinksPageList.add(stmtLnkSrc);
} else {
// write old, accumulate new
writeLnkToScalaris(linkDest0, backLinksPageList);
linkDest0 = stmtLnkDest0;
backLinksPageList.add(stmtLnkSrc);
}
}
if (linkDest0 != null && !backLinksPageList.isEmpty()) {
writeLnkToScalaris(linkDest0, backLinksPageList);
}
stmt.dispose();
} while (false);
} catch (SQLiteException e) {
System.err.println("sqlite error: " + e.toString());
throw new RuntimeException(e);
} finally {
if (stmt != null) {
stmt.dispose();
}
}
}