clearBadRows();
}
public static void clearBadRows() {
PageLinkDAO pageLinkDAO = new PageLinkDAOImpl();
PageDAO pageDAO = new PageDAOImpl();
int count = -1;
try {
sessionStrategy.beginTransaction();
count = pageLinkDAO.count();
sessionStrategy.commitTransaction();
} finally {
sessionStrategy.rollbackIfActive();
}
int start = 0;
long erased = 0;
while (start < count) {
List<PageLink> chunk = null;
try {
sessionStrategy.beginTransaction();
chunk = pageLinkDAO.findDistinctSources(start, CHUNK_SIZE);
sessionStrategy.commitTransaction();
} finally {
sessionStrategy.rollbackIfActive();
}
for (PageLink pl : chunk) {
try {
sessionStrategy.beginTransaction();
Page found = pageDAO.findById(pl.getSourcePageId());
if (found == null) {
pageLinkDAO.delete(pl);
erased++;
} else {
Page found2 = pageDAO.findByTitleAndNamespace(pl.getDestinationTitle(), pl.getDestinationNamespace());
if (found2 == null) {
pageLinkDAO.delete(pl);
erased++;
}