/** * Apply comment defaults (defaultAllowComments and defaultCommentDays) to all existing entries in * a website using a single HQL query. * * @param website Website where comment defaults are from/to be applied. */ public void applyCommentDefaultsToEntries(WebsiteData website) throws RollerException { if (log.isDebugEnabled()) { log.debug("applyCommentDefaults"); } try { Session session = strategy.getSession(); String updateString = "update WeblogEntryData set " + "allowComments=:allowed, commentDays=:days, " + "pubTime=pubTime, updateTime=updateTime " // ensure timestamps are NOT reset + "where website=:site"; Query update = session.createQuery(updateString); update.setParameter("allowed", website.getDefaultAllowComments()); update.setParameter("days", new Integer(website.getDefaultCommentDays())); update.setParameter("site", website); update.executeUpdate(); } catch (Exception e) { log.error("EXCEPTION applying comment defaults", e); } }
public WeblogEntryData getWeblogEntryByAnchor(WebsiteData website, String anchor) throws RollerException { if (website == null) throw new RollerException("Website is null"); if (anchor == null) throw new RollerException("Anchor is null"); // mapping key is combo of weblog + anchor String mappingKey = website.getHandle() + ":" + anchor; // 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); } }
private Map getWeblogEntryMap( WebsiteData website, Date startDate, Date endDate, String catName, String status, boolean stringsOnly, String locale, int offset, int length) throws RollerException { TreeMap map = new TreeMap(reverseComparator); List entries = getWeblogEntries( website, null, startDate, endDate, catName, status, null, locale, offset, length); Calendar cal = Calendar.getInstance(); if (website != null) { cal.setTimeZone(website.getTimeZoneInstance()); } SimpleDateFormat formatter = DateUtil.get8charDateFormat(); for (Iterator wbItr = entries.iterator(); wbItr.hasNext(); ) { WeblogEntryData entry = (WeblogEntryData) wbItr.next(); Date sDate = DateUtil.getNoonOfDay(entry.getPubTime(), cal); if (stringsOnly) { if (map.get(sDate) == null) map.put(sDate, formatter.format(sDate)); } else { List dayEntries = (List) map.get(sDate); if (dayEntries == null) { dayEntries = new ArrayList(); map.put(sDate, dayEntries); } dayEntries.add(entry); } } return map; }