// check cache first
// NOTE: if we ever allow changing anchors then this needs updating
if(this.entryAnchorToIdMap.containsKey(mappingKey)) {
WeblogEntryData entry = this.getWeblogEntry((String) this.entryAnchorToIdMap.get(mappingKey));
if(entry != null) {
log.debug("entryAnchorToIdMap CACHE HIT - "+mappingKey);
return entry;
} else {
// mapping hit with lookup miss? mapping must be old, remove it
this.entryAnchorToIdMap.remove(mappingKey);
}
}
// cache failed, do lookup
try {
Session session = ((HibernatePersistenceStrategy)this.strategy).getSession();
Criteria criteria = session.createCriteria(WeblogEntryData.class);
criteria.add(Expression.conjunction()
.add(Expression.eq("website",website))
.add(Expression.eq("anchor",anchor)));
criteria.addOrder(Order.desc("pubTime"));
criteria.setMaxResults(1);
List list = criteria.list();
WeblogEntryData entry = null;
if(list.size() != 0) {
entry = (WeblogEntryData) criteria.uniqueResult();
}
// add mapping to cache
if(entry != null) {
log.debug("entryAnchorToIdMap CACHE MISS - "+mappingKey);
this.entryAnchorToIdMap.put(mappingKey, entry.getId());
}
return entry;
} catch (HibernateException e) {
throw new RollerException(e);