// check cache first
// NOTE: if we ever allow changing handles then this needs updating
if(this.weblogHandleToIdMap.containsKey(handle)) {
Weblog weblog = this.getWeblog(
(String) this.weblogHandleToIdMap.get(handle));
if(weblog != null) {
// only return weblog if enabled status matches
if(enabled == null || enabled.equals(weblog.getEnabled())) {
log.debug("weblogHandleToId CACHE HIT - "+handle);
return weblog;
}
} else {
// mapping hit with lookup miss? mapping must be old, remove it
this.weblogHandleToIdMap.remove(handle);
}
}
Query query = strategy.getNamedQuery("Weblog.getByHandle");
query.setParameter(1, handle);
Weblog website = null;
try {
website = (Weblog)query.getSingleResult();
} catch (NoResultException e) {
website = null;
}
// add mapping to cache
if(website != null) {
log.debug("weblogHandleToId CACHE MISS - "+handle);
this.weblogHandleToIdMap.put(website.getHandle(), website.getId());
}
if(website != null &&
(enabled == null || enabled.equals(website.getEnabled()))) {
return website;
} else {
return null;
}
}