You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@roller.apache.org by ag...@apache.org on 2006/05/16 00:44:17 UTC
svn commit: r406760 - in /incubator/roller/trunk/src/org/apache/roller:
business/hibernate/HibernateBookmarkManagerImpl.java
business/hibernate/HibernateUserManagerImpl.java
business/hibernate/HibernateWeblogManagerImpl.java
util/cache/CacheManager.java
Author: agilliland
Date: Mon May 15 15:44:16 2006
New Revision: 406760
URL: http://svn.apache.org/viewcvs?rev=406760&view=rev
Log:
removing old last expired cache from CacheManager and replacing it with the usage of the new weblog last modified attribute.
also updated various saveXXX() and removeXXX() manager methods to trigger an update to the weblog last modified date.
Modified:
incubator/roller/trunk/src/org/apache/roller/business/hibernate/HibernateBookmarkManagerImpl.java
incubator/roller/trunk/src/org/apache/roller/business/hibernate/HibernateUserManagerImpl.java
incubator/roller/trunk/src/org/apache/roller/business/hibernate/HibernateWeblogManagerImpl.java
incubator/roller/trunk/src/org/apache/roller/util/cache/CacheManager.java
Modified: incubator/roller/trunk/src/org/apache/roller/business/hibernate/HibernateBookmarkManagerImpl.java
URL: http://svn.apache.org/viewcvs/incubator/roller/trunk/src/org/apache/roller/business/hibernate/HibernateBookmarkManagerImpl.java?rev=406760&r1=406759&r2=406760&view=diff
==============================================================================
--- incubator/roller/trunk/src/org/apache/roller/business/hibernate/HibernateBookmarkManagerImpl.java (original)
+++ incubator/roller/trunk/src/org/apache/roller/business/hibernate/HibernateBookmarkManagerImpl.java Mon May 15 15:44:16 2006
@@ -20,7 +20,6 @@
*/
package org.apache.roller.business.hibernate;
-import java.io.IOException;
import java.io.StringReader;
import org.hibernate.Criteria;
import org.hibernate.HibernateException;
@@ -39,9 +38,9 @@
import org.apache.commons.logging.LogFactory;
import org.jdom.Document;
import org.jdom.Element;
-import org.jdom.JDOMException;
import org.jdom.input.SAXBuilder;
import org.apache.roller.model.BookmarkManager;
+import org.apache.roller.model.RollerFactory;
import org.apache.roller.util.Utilities;
@@ -70,6 +69,9 @@
public void saveBookmark(BookmarkData bookmark) throws RollerException {
this.strategy.store(bookmark);
+
+ // update weblog last modified date. date updated by saveWebsite()
+ RollerFactory.getRoller().getUserManager().saveWebsite(bookmark.getWebsite());
}
@@ -84,6 +86,9 @@
public void removeBookmark(BookmarkData bookmark) throws RollerException {
this.strategy.remove(bookmark);
+
+ // update weblog last modified date. date updated by saveWebsite()
+ RollerFactory.getRoller().getUserManager().saveWebsite(bookmark.getWebsite());
}
//------------------------------------------------------------ Folder CRUD
@@ -96,12 +101,18 @@
}
this.strategy.store(folder);
+
+ // update weblog last modified date. date updated by saveWebsite()
+ RollerFactory.getRoller().getUserManager().saveWebsite(folder.getWebsite());
}
public void removeFolder(FolderData folder) throws RollerException {
this.strategy.remove(folder);
+
+ // update weblog last modified date. date updated by saveWebsite()
+ RollerFactory.getRoller().getUserManager().saveWebsite(folder.getWebsite());
}
Modified: incubator/roller/trunk/src/org/apache/roller/business/hibernate/HibernateUserManagerImpl.java
URL: http://svn.apache.org/viewcvs/incubator/roller/trunk/src/org/apache/roller/business/hibernate/HibernateUserManagerImpl.java?rev=406760&r1=406759&r2=406760&view=diff
==============================================================================
--- incubator/roller/trunk/src/org/apache/roller/business/hibernate/HibernateUserManagerImpl.java (original)
+++ incubator/roller/trunk/src/org/apache/roller/business/hibernate/HibernateUserManagerImpl.java Mon May 15 15:44:16 2006
@@ -87,6 +87,8 @@
* Update existing website.
*/
public void saveWebsite(WebsiteData website) throws RollerException {
+
+ website.setLastModified(new java.util.Date());
strategy.store(website);
}
@@ -213,8 +215,11 @@
/**
* @see org.apache.roller.model.UserManager#storePage(org.apache.roller.pojos.WeblogTemplate)
*/
- public void savePage(WeblogTemplate data) throws RollerException {
- this.strategy.store(data);
+ public void savePage(WeblogTemplate page) throws RollerException {
+ this.strategy.store(page);
+
+ // update weblog last modified date. date updated by saveWebsite()
+ RollerFactory.getRoller().getUserManager().saveWebsite(page.getWebsite());
}
Modified: incubator/roller/trunk/src/org/apache/roller/business/hibernate/HibernateWeblogManagerImpl.java
URL: http://svn.apache.org/viewcvs/incubator/roller/trunk/src/org/apache/roller/business/hibernate/HibernateWeblogManagerImpl.java?rev=406760&r1=406759&r2=406760&view=diff
==============================================================================
--- incubator/roller/trunk/src/org/apache/roller/business/hibernate/HibernateWeblogManagerImpl.java (original)
+++ incubator/roller/trunk/src/org/apache/roller/business/hibernate/HibernateWeblogManagerImpl.java Mon May 15 15:44:16 2006
@@ -91,6 +91,9 @@
throw new RollerException("Duplicate category name");
}
+ // update weblog last modified date. date updated by saveWebsite()
+ RollerFactory.getRoller().getUserManager().saveWebsite(cat.getWebsite());
+
this.strategy.store(cat);
}
@@ -116,6 +119,9 @@
cat.getWebsite().setDefaultCategory(rootCat);
this.strategy.store(cat.getWebsite());
}
+
+ // update weblog last modified date. date updated by saveWebsite()
+ RollerFactory.getRoller().getUserManager().saveWebsite(cat.getWebsite());
}
@@ -168,11 +174,17 @@
public void saveComment(CommentData comment) throws RollerException {
this.strategy.store(comment);
+
+ // update weblog last modified date. date updated by saveWebsite()
+ RollerFactory.getRoller().getUserManager().saveWebsite(comment.getWeblogEntry().getWebsite());
}
public void removeComment(CommentData comment) throws RollerException {
this.strategy.remove(comment);
+
+ // update weblog last modified date. date updated by saveWebsite()
+ RollerFactory.getRoller().getUserManager().saveWebsite(comment.getWeblogEntry().getWebsite());
}
@@ -185,6 +197,11 @@
this.strategy.store(entry);
+ // update weblog last modified date. date updated by saveWebsite()
+ if(entry.isPublished()) {
+ RollerFactory.getRoller().getUserManager().saveWebsite(entry.getWebsite());
+ }
+
if(entry.isPublished()) {
// Queue applicable pings for this update.
RollerFactory.getRoller().getAutopingManager().queueApplicableAutoPings(entry);
@@ -225,6 +242,11 @@
// remove entry
this.strategy.remove(entry);
+
+ // update weblog last modified date. date updated by saveWebsite()
+ if(entry.isPublished()) {
+ RollerFactory.getRoller().getUserManager().saveWebsite(entry.getWebsite());
+ }
// remove entry from cache mapping
this.entryAnchorToIdMap.remove(entry.getWebsite().getHandle()+":"+entry.getAnchor());
Modified: incubator/roller/trunk/src/org/apache/roller/util/cache/CacheManager.java
URL: http://svn.apache.org/viewcvs/incubator/roller/trunk/src/org/apache/roller/util/cache/CacheManager.java?rev=406760&r1=406759&r2=406760&view=diff
==============================================================================
--- incubator/roller/trunk/src/org/apache/roller/util/cache/CacheManager.java (original)
+++ incubator/roller/trunk/src/org/apache/roller/util/cache/CacheManager.java Mon May 15 15:44:16 2006
@@ -26,9 +26,12 @@
import java.util.Set;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import org.apache.roller.RollerException;
import org.apache.roller.business.runnable.ContinuousWorkerThread;
import org.apache.roller.business.runnable.Job;
import org.apache.roller.config.RollerConfig;
+import org.apache.roller.model.RollerFactory;
+import org.apache.roller.model.UserManager;
import org.apache.roller.pojos.BookmarkData;
import org.apache.roller.pojos.CommentData;
import org.apache.roller.pojos.FolderData;
@@ -57,16 +60,13 @@
*/
public class CacheManager {
- private static Log mLogger = LogFactory.getLog(CacheManager.class);
+ private static Log log = LogFactory.getLog(CacheManager.class);
private static final String DEFAULT_FACTORY =
"org.apache.roller.util.cache.ExpiringLRUCacheFactoryImpl";
// a reference to the cache factory in use
- private static CacheFactory mCacheFactory = null;
-
- // maintain a cache of the last expired time for each weblog
- private static Cache lastExpiredCache = null;
+ private static CacheFactory cacheFactory = null;
// a list of all cache handlers who have obtained a cache
private static Set cacheHandlers = new HashSet();
@@ -81,38 +81,26 @@
// use reflection to instantiate our factory class
try {
Class factoryClass = Class.forName(classname);
- mCacheFactory = (CacheFactory) factoryClass.newInstance();
+ cacheFactory = (CacheFactory) factoryClass.newInstance();
} catch(ClassCastException cce) {
- mLogger.error("It appears that your factory does not implement "+
+ log.error("It appears that your factory does not implement "+
"the CacheFactory interface",cce);
} catch(Exception e) {
- mLogger.error("Unable to instantiate cache factory ["+classname+"]"+
+ log.error("Unable to instantiate cache factory ["+classname+"]"+
" falling back on default", e);
}
- if(mCacheFactory == null) try {
+ if(cacheFactory == null) try {
// hmm ... failed to load the specified cache factory
// lets try our default
Class factoryClass = Class.forName(DEFAULT_FACTORY);
- mCacheFactory = (CacheFactory) factoryClass.newInstance();
+ cacheFactory = (CacheFactory) factoryClass.newInstance();
} catch(Exception e) {
- mLogger.fatal("Failed to instantiate a cache factory", e);
+ log.fatal("Failed to instantiate a cache factory", e);
}
- mLogger.info("Cache Manager Initialized.");
- mLogger.info("Default cache factory = "+mCacheFactory.getClass().getName());
-
-
- // setup our cache for expiration dates
- // TODO: this really should not be something that is cached here
- // a better approach would be to add a weblog.lastChanged field
- // and track this along with the WebsiteData object
- String lastExpCacheFactory = RollerConfig.getProperty("cache.lastExpired.factory");
- Map lastExpProps = new HashMap();
- if(lastExpCacheFactory != null) {
- lastExpProps.put("factory", lastExpCacheFactory);
- }
- lastExpiredCache = CacheManager.constructCache(null, lastExpProps);
+ log.info("Cache Manager Initialized.");
+ log.info("Cache Factory = "+cacheFactory.getClass().getName());
// add custom handlers
@@ -129,10 +117,10 @@
cacheHandlers.add(customHandler);
} catch(ClassCastException cce) {
- mLogger.error("It appears that your handler does not implement "+
+ log.error("It appears that your handler does not implement "+
"the CacheHandler interface",cce);
} catch(Exception e) {
- mLogger.error("Unable to instantiate cache handler ["+cHandlers[i]+"]", e);
+ log.error("Unable to instantiate cache handler ["+cHandlers[i]+"]", e);
}
}
}
@@ -190,7 +178,7 @@
*/
public static Cache constructCache(CacheHandler handler, Map properties) {
- mLogger.debug("Constructing new cache with props "+properties);
+ log.debug("Constructing new cache with props "+properties);
Cache cache = null;
@@ -206,17 +194,17 @@
// now ask for a new cache
cache = factory.constructCache(properties);
} catch(ClassCastException cce) {
- mLogger.error("It appears that your factory ["+classname+
+ log.error("It appears that your factory ["+classname+
"] does not implement the CacheFactory interface",cce);
} catch(Exception e) {
- mLogger.error("Unable to instantiate cache factory ["+classname+
+ log.error("Unable to instantiate cache factory ["+classname+
"] falling back on default", e);
}
}
if(cache == null) {
// ask our default cache factory for a new cache instance
- cache = mCacheFactory.constructCache(properties);
+ cache = cacheFactory.constructCache(properties);
}
// register the handler for this new cache
@@ -241,7 +229,7 @@
*/
public static void registerHandler(CacheHandler handler) {
- mLogger.debug("Registering handler "+handler);
+ log.debug("Registering handler "+handler);
if(handler != null) {
cacheHandlers.add(handler);
@@ -251,9 +239,7 @@
public static void invalidate(WeblogEntryData entry) {
- mLogger.debug("invalidating entry = "+entry.getAnchor());
-
- setLastExpiredDate(entry.getWebsite().getHandle());
+ log.debug("invalidating entry = "+entry.getAnchor());
Iterator handlers = cacheHandlers.iterator();
while(handlers.hasNext()) {
@@ -264,9 +250,7 @@
public static void invalidate(WebsiteData website) {
- mLogger.debug("invalidating website = "+website.getHandle());
-
- setLastExpiredDate(website.getHandle());
+ log.debug("invalidating website = "+website.getHandle());
Iterator handlers = cacheHandlers.iterator();
while(handlers.hasNext()) {
@@ -277,9 +261,7 @@
public static void invalidate(BookmarkData bookmark) {
- mLogger.debug("invalidating bookmark = "+bookmark.getId());
-
- setLastExpiredDate(bookmark.getWebsite().getHandle());
+ log.debug("invalidating bookmark = "+bookmark.getId());
Iterator handlers = cacheHandlers.iterator();
while(handlers.hasNext()) {
@@ -290,9 +272,7 @@
public static void invalidate(FolderData folder) {
- mLogger.debug("invalidating folder = "+folder.getId());
-
- setLastExpiredDate(folder.getWebsite().getHandle());
+ log.debug("invalidating folder = "+folder.getId());
Iterator handlers = cacheHandlers.iterator();
while(handlers.hasNext()) {
@@ -303,9 +283,7 @@
public static void invalidate(CommentData comment) {
- mLogger.debug("invalidating comment = "+comment.getId());
-
- setLastExpiredDate(comment.getWeblogEntry().getWebsite().getHandle());
+ log.debug("invalidating comment = "+comment.getId());
Iterator handlers = cacheHandlers.iterator();
while(handlers.hasNext()) {
@@ -316,7 +294,7 @@
public static void invalidate(RefererData referer) {
- mLogger.debug("invalidating referer = "+referer.getId());
+ log.debug("invalidating referer = "+referer.getId());
// NOTE: Invalidating an entire website for each referer is not
// good for our caching. This may need reevaluation later.
@@ -331,7 +309,7 @@
public static void invalidate(UserData user) {
- mLogger.debug("invalidating user = "+user.getUserName());
+ log.debug("invalidating user = "+user.getUserName());
Iterator handlers = cacheHandlers.iterator();
while(handlers.hasNext()) {
@@ -342,9 +320,7 @@
public static void invalidate(WeblogCategoryData category) {
- mLogger.debug("invalidating category = "+category.getId());
-
- setLastExpiredDate(category.getWebsite().getHandle());
+ log.debug("invalidating category = "+category.getId());
Iterator handlers = cacheHandlers.iterator();
while(handlers.hasNext()) {
@@ -355,9 +331,7 @@
public static void invalidate(WeblogTemplate template) {
- mLogger.debug("invalidating template = "+template.getId());
-
- setLastExpiredDate(template.getWebsite().getHandle());
+ log.debug("invalidating template = "+template.getId());
Iterator handlers = cacheHandlers.iterator();
while(handlers.hasNext()) {
@@ -371,9 +345,6 @@
*/
public static void clear() {
- // update all expired dates
- lastExpiredCache.clear();
-
// loop through all handlers and trigger a clear
CacheHandler handler = null;
Iterator handlers = cacheHandlers.iterator();
@@ -390,9 +361,6 @@
*/
public static void clear(String handlerClass) {
- // update all expired dates
- lastExpiredCache.clear();
-
// loop through all handlers to find the one we want
CacheHandler handler = null;
Iterator handlers = cacheHandlers.iterator();
@@ -406,16 +374,23 @@
}
- public static void setLastExpiredDate(String weblogHandle) {
- lastExpiredCache.put("lastExpired:"+weblogHandle, new Date());
- }
-
-
/**
* Get the date of the last time the specified weblog was invalidated.
+ *
+ * There is some potential for a performance hit to do this lookup, but
+ * we assume that our WebsiteData objects are cached up the @$$ ;)
*/
public static Date getLastExpiredDate(String weblogHandle) {
- return (Date) lastExpiredCache.get("lastExpired:"+weblogHandle);
+
+ try {
+ UserManager userMgr = RollerFactory.getRoller().getUserManager();
+ WebsiteData weblog = userMgr.getWebsiteByHandle(weblogHandle);
+ return weblog.getLastModified();
+ } catch (RollerException ex) {
+ log.error("Error setting last modified date", ex);
+ }
+
+ return null;
}