}
}
}
public static void iterate(int iterations) {
PageMetaDAO pageMetaDAO = new PageMetaDAOImpl();
PageLinkDAO pageLinkDAO = new PageLinkDAOImpl();
PageDAO pageDAO = new PageDAOImpl();
for (int iteration = 0; iteration < iterations; iteration++) {
System.out.print("Performing iteration " + (iteration + 1) + " ... ");
int pages = 0;
try {
sessionStrategy.beginTransaction();
pages = pageDAO.count();
sessionStrategy.commitTransaction();
} finally {
sessionStrategy.rollbackIfActive();
}
int start = 0;
double pre = ((1.0 - DAMPING) / (double)pages) + DAMPING;
while (start < pages) {
List<Page> chunk = Collections.emptyList();
try {
sessionStrategy.beginTransaction();
chunk = pageDAO.findAll(start, CHUNK_SIZE);
sessionStrategy.commitTransaction();
} finally {
sessionStrategy.rollbackIfActive();
}
for (Page p : chunk) {
try {
sessionStrategy.beginTransaction();
double rank = pre;
PageMeta meta = pageMetaDAO.findByPage(p);
List<Page> linksIn = pageLinkDAO.findLinksInByPage(p);
if (linksIn == null || linksIn.size() == 0)
continue;
for (Page linkIn : linksIn) {
PageMeta linkInMeta = pageMetaDAO
.findByPage(linkIn);
List<Page> linksOut = pageLinkDAO
.findLinksOutByPage(linkIn);
if (linksOut != null && linksOut.size() != 0)
rank += (linkInMeta.getRank())
/ linksOut.size();
}
if (meta == null) {
meta = new PageMeta(p, new Date(0), 0, rank);
pageMetaDAO.create(meta);
} else
pageMetaDAO.updatePageRank(meta, rank);
sessionStrategy.commitTransaction();
} finally {
sessionStrategy.rollbackIfActive();