roller-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From agillil...@apache.org
Subject svn commit: r392618 [3/5] - in /incubator/roller/branches/roller-newbackend/src/org/roller/business: ./ hibernate/ search/operations/
Date Sat, 08 Apr 2006 22:36:28 GMT
Modified: incubator/roller/branches/roller-newbackend/src/org/roller/business/hibernate/HibernateRefererManagerImpl.java
URL: http://svn.apache.org/viewcvs/incubator/roller/branches/roller-newbackend/src/org/roller/business/hibernate/HibernateRefererManagerImpl.java?rev=392618&r1=392617&r2=392618&view=diff
==============================================================================
--- incubator/roller/branches/roller-newbackend/src/org/roller/business/hibernate/HibernateRefererManagerImpl.java (original)
+++ incubator/roller/branches/roller-newbackend/src/org/roller/business/hibernate/HibernateRefererManagerImpl.java Sat Apr  8 15:36:25 2006
@@ -6,10 +6,11 @@
 import java.sql.Connection;
 import java.sql.PreparedStatement;
 import java.sql.ResultSet;
+import java.text.SimpleDateFormat;
 import java.util.ArrayList;
+import java.util.Date;
 import java.util.Iterator;
 import java.util.List;
-
 import org.apache.commons.lang.StringUtils;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
@@ -23,8 +24,6 @@
 import org.hibernate.criterion.Order;
 import org.hibernate.type.Type;
 import org.roller.RollerException;
-import org.roller.business.PersistenceStrategy;
-import org.roller.business.RefererManagerImpl;
 import org.roller.config.RollerRuntimeConfig;
 import org.roller.model.RefererManager;
 import org.roller.pojos.RefererData;
@@ -38,34 +37,182 @@
 import org.hibernate.dialect.SQLServerDialect;
 import org.hibernate.engine.SessionFactoryImplementor;
 import org.hibernate.dialect.Dialect;
+import org.roller.model.Roller;
+import org.roller.model.RollerFactory;
+import org.roller.model.UserManager;
+import org.roller.model.WeblogManager;
+import org.roller.util.DateUtil;
+import org.roller.util.LinkbackExtractor;
+import org.roller.util.Utilities;
 
 
 /**
- * Hibernate queries.
- * @author David M Johnson
+ * Hibernate implementation of the RefererManager.
  */
-public class HibernateRefererManagerImpl extends RefererManagerImpl
-        implements RefererManager {
+public class HibernateRefererManagerImpl implements RefererManager {
+    
     static final long serialVersionUID = -4966091850482256435L;
     
-    private static Log mLogger =
-            LogFactory.getFactory().getInstance(HibernateRefererManagerImpl.class);
+    private static Log log = LogFactory.getLog(HibernateRefererManagerImpl.class);
+    
+    protected static final String DAYHITS = "dayHits";
+    protected static final String TOTALHITS = "totalHits";
+    
+    private HibernatePersistenceStrategy strategy = null;
+    private Date mRefDate = new Date();
+    private SimpleDateFormat mDateFormat = DateUtil.get8charDateFormat();
     
-    //-------------------------------------------------- Startup and Shutdown
-    public HibernateRefererManagerImpl(PersistenceStrategy support)
-    throws RollerException {
-        super();
-        mStrategy = (HibernateStrategy)support;
-        mLogger.debug("Instantiating Referer Manager");
+    
+    public HibernateRefererManagerImpl(HibernatePersistenceStrategy strat) {
+        
+        log.debug("Instantiating Hibernate Referer Manager");
+        
+        strategy = strat;
     }
     
-    //-----------------------------------------------------------------------
+    
+    /**
+     * @see org.roller.pojos.RefererManager#storeReferer(org.roller.pojos.RefererData)
+     */
+    public void storeReferer(RefererData referer) throws RollerException {
+        strategy.storeAndCommit(referer);
+    }
+    
+    
+    /**
+     * @see org.roller.pojos.RefererManager#removeReferer(java.lang.String)
+     */
+    public void removeReferer(String id) throws RollerException {
+        strategy.removeAndCommit(id, RefererData.class);
+    }
+    
+    
+    // convenience method for removing a list of referers
+    private void removeReferers(List referers) throws RollerException {
+        
+        try {
+            // begin transaction
+            this.strategy.getSession().beginTransaction();
+            
+            // just go through the list and remove each auto ping
+            Iterator referer = referers.iterator();
+            while (referer.hasNext()) {
+                    this.strategy.remove((RefererData) referer.next());
+            }
+            
+            // commit changes
+            this.strategy.getSession().getTransaction().commit();
+        } catch (HibernateException ex) {
+            
+            try {
+                this.strategy.getSession().getTransaction().rollback();
+            } catch(HibernateException he) {
+                log.error("Error doing rollback", he);
+            }
+            
+            strategy.release();
+            
+            throw new RollerException(ex);
+        }
+    }
+    
+    
+    /**
+     * @see org.roller.pojos.RefererManager#getReferersToEntry(java.lang.String, java.lang.String)
+     */
+    public void removeReferersForEntry(String entryid) throws RollerException {
+        
+        if (null == entryid)
+            throw new RollerException("entryid is null");
+        
+        try {
+            // begin transaction
+            this.strategy.getSession().beginTransaction();
+            
+            Session session = ((HibernatePersistenceStrategy)strategy).getSession();
+            Criteria criteria = session.createCriteria(RefererData.class);
+            criteria.createAlias("weblogEntry","e");
+            criteria.add(Expression.eq("e.id", entryid));
+            this.removeReferers(criteria.list());
+        } catch (HibernateException e) {
+            throw new RollerException(e);
+        }
+    }
+    
+    
+    /**
+     * Clear referrer dayhits and remove referrers without excerpts.
+     *
+     * TODO: do we really need dialect specific queries?
+     */
+    public void clearReferrers() throws RollerException {
+        
+        if (log.isDebugEnabled()) {
+            log.debug("clearReferrers");
+        }
+        try {
+            // begin transaction
+            this.strategy.getSession().beginTransaction();
+            
+            Session session = ((HibernatePersistenceStrategy)strategy).getSession();
+            Dialect currentDialect = ((SessionFactoryImplementor)session.getSessionFactory()).getDialect();
+            String reset = "update RefererData set dayHits=0";
+            session.createQuery(reset).executeUpdate();
+            String delete = null;
+            if ( currentDialect instanceof SQLServerDialect || currentDialect instanceof OracleDialect ){
+                delete = "delete RefererData where excerpt is null or excerpt like ''";
+            } else {
+                delete = "delete RefererData where excerpt is null or excerpt=''";
+            }
+            session.createQuery(delete).executeUpdate();
+        } catch (Exception e) {
+            log.error("EXCEPTION resetting referers",e);
+        }
+    }
+    
+    
+    /**
+     * Clear referrer dayhits and remove referrers without excerpts.
+     *
+     * TODO: do we really need dialect specific queries?
+     */
+    public void clearReferrers(WebsiteData website) throws RollerException {
+        
+        if (log.isDebugEnabled()) {
+            log.debug("clearReferrers");
+        }
+        try {
+            // begin transaction
+            this.strategy.getSession().beginTransaction();
+            
+            Session session = ((HibernatePersistenceStrategy)strategy).getSession();
+            Dialect currentDialect = ((SessionFactoryImplementor)session.getSessionFactory()).getDialect();
+            String reset = "update RefererData set dayHits=0 where website=:site";
+            session.createQuery(reset)
+            .setParameter("site",website).executeUpdate();
+            String delete = null;
+            if ( currentDialect instanceof SQLServerDialect || currentDialect instanceof OracleDialect ){
+                delete = "delete RefererData where website=:site and (excerpt is null or excerpt like '')";
+            } else {
+                delete = "delete RefererData where website=:site and (excerpt is null or excerpt='')";
+            }
+            session.createQuery(delete)
+            .setParameter("site",website).executeUpdate();
+        } catch (Exception e) {
+            log.error("EXCEPTION resetting referers",e);
+        }
+    }
+    
+    
     /**
      * Apply ignoreWord/spam filters to all referers in system.
      */
     public void applyRefererFilters() throws RollerException {
         try {
-            Session session = ((HibernateStrategy)mStrategy).getSession();
+            // begin transaction
+            this.strategy.getSession().beginTransaction();
+            
+            Session session = ((HibernatePersistenceStrategy)strategy).getSession();
             Criteria criteria = session.createCriteria(RefererData.class);
             
             String spamwords = RollerRuntimeConfig.getProperty("spam.blacklist");
@@ -82,16 +229,14 @@
             .add(or)
             );
             
-            Iterator referers = criteria.list().iterator();
-            while (referers.hasNext()) {
-                removeReferer( ((RefererData)referers.next()).getId() );
-            }
+            this.removeReferers(criteria.list());
+            
         } catch (HibernateException e) {
             throw new RollerException(e);
         }
     }
     
-    //-----------------------------------------------------------------------
+    
     /**
      * Apply ignoreWord/spam filters to all referers in website.
      */
@@ -100,7 +245,10 @@
         if (null == website.getBlacklist()) return;
         
         try {
-            Session session = ((HibernateStrategy)mStrategy).getSession();
+            // begin transaction
+            this.strategy.getSession().beginTransaction();
+            
+            Session session = ((HibernatePersistenceStrategy)strategy).getSession();
             Criteria criteria = session.createCriteria(RefererData.class);
             
             String[] blacklist = StringUtils.split(
@@ -118,62 +266,67 @@
             .add(or)
             );
             
-            Iterator referers = criteria.list().iterator();
-            while (referers.hasNext()) {
-                removeReferer( ((RefererData)referers.next()).getId() );
-            }
+            this.removeReferers(criteria.list());
         } catch (HibernateException e) {
             throw new RollerException(e);
         }
     }
     
-    //-----------------------------------------------------------------------
     
     /**
      * Use Hibernate directly because Roller's Query API does too much allocation.
      */
     protected List getExistingReferers(WebsiteData website, String dateString,
             String permalink) throws RollerException {
-        Session session = ((HibernateStrategy)mStrategy).getSession();
-        Criteria criteria = session.createCriteria(RefererData.class);
-        criteria.add(Expression.conjunction()
-        .add(Expression.eq("website",website))
-        .add(Expression.eq("dateString",dateString))
-        .add(Expression.eq("refererPermalink",permalink)));
+        
         try {
+            // begin transaction
+            this.strategy.getSession().beginTransaction();
+            
+            Session session = ((HibernatePersistenceStrategy)strategy).getSession();
+            Criteria criteria = session.createCriteria(RefererData.class);
+            criteria.add(Expression.conjunction()
+            .add(Expression.eq("website",website))
+            .add(Expression.eq("dateString",dateString))
+            .add(Expression.eq("refererPermalink",permalink)));
+            
             return criteria.list();
         } catch (HibernateException e) {
             throw new RollerException(e);
         }
     }
     
-    //-----------------------------------------------------------------------
     
     /**
      * Use Hibernate directly because Roller's Query API does too much allocation.
      */
     protected List getMatchingReferers(WebsiteData website, String requestUrl,
             String refererUrl) throws RollerException {
-        Session session = ((HibernateStrategy)mStrategy).getSession();
-        Criteria criteria = session.createCriteria(RefererData.class);
-        criteria.add(Expression.conjunction()
-        .add(Expression.eq("website",website))
-        .add(Expression.eq("requestUrl",requestUrl))
-        .add(Expression.eq("refererUrl",refererUrl)));
+        
         try {
+            // begin transaction
+            this.strategy.getSession().beginTransaction();
+            
+            Session session = ((HibernatePersistenceStrategy)strategy).getSession();
+            Criteria criteria = session.createCriteria(RefererData.class);
+            criteria.add(Expression.conjunction()
+            .add(Expression.eq("website",website))
+            .add(Expression.eq("requestUrl",requestUrl))
+            .add(Expression.eq("refererUrl",refererUrl)));
+            
             return criteria.list();
         } catch (HibernateException e) {
             throw new RollerException(e);
         }
     }
     
-    //-----------------------------------------------------------------------
     
     /**
      * Use raw SQL because Hibernate can't handle sorting by sum.
+     *
+     * TODO: do we really need raw sql?  can't hibernate do this?
      */
     public List getDaysPopularWebsites(int max) throws RollerException {
-        // TODO Hibernate version of getDaysPopularWebsites
         // TODO Move to full use of mSupport
         String msg = "Getting popular websites";
         Session ses = null; // the session will eventually be release by RequestFilter
@@ -181,7 +334,7 @@
         try {
             List list = new ArrayList();
             
-            ses = ((HibernateStrategy)mStrategy).getSession();
+            ses = ((HibernatePersistenceStrategy)strategy).getSession();
             con = ses.connection();
             
             final PreparedStatement stmt;
@@ -191,57 +344,57 @@
             if (currentDialect instanceof HSQLDialect) {
                 // special handling for HSQLDB
                 stmt = con.prepareStatement(
-                    "select top ? w.id, w.name, w.handle, sum(r.dayhits) as s "+
-                    "from website as w, referer as r "+
-                    "where r.websiteid=w.id and w.isenabled=? and w.isactive=? " +
-                    "group by w.name, w.handle, w.id order by s desc");
+                        "select top ? w.id, w.name, w.handle, sum(r.dayhits) as s "+
+                        "from website as w, referer as r "+
+                        "where r.websiteid=w.id and w.isenabled=? and w.isactive=? " +
+                        "group by w.name, w.handle, w.id order by s desc");
                 stmt.setInt(1, max);
                 stmt.setBoolean(2, true);
                 stmt.setBoolean(3, true);
             } else if(currentDialect instanceof DerbyDialect) {
-	           // special handling for Derby
-				stmt = con.prepareStatement(
-				    "select w.id, w.name, w.handle, sum(r.dayhits) as s "+
-				    "from website as w, referer as r "+
-				    "where r.websiteid=w.id and w.isenabled=? and w.isactive=? " +
-				    "group by w.name, w.handle, w.id order by s desc");                      
-				stmt.setBoolean(1, true);				
+                // special handling for Derby
+                stmt = con.prepareStatement(
+                        "select w.id, w.name, w.handle, sum(r.dayhits) as s "+
+                        "from website as w, referer as r "+
+                        "where r.websiteid=w.id and w.isenabled=? and w.isactive=? " +
+                        "group by w.name, w.handle, w.id order by s desc");
+                stmt.setBoolean(1, true);
                 stmt.setBoolean(2, true);
                 stmt.setMaxRows(max);
             } else if(currentDialect instanceof DB2Dialect) {
                 // special handling for IBM DB2
                 stmt = con.prepareStatement(
-                    "select w.id, w.name, w.handle, sum(r.dayhits) as s "+
-                    "from website as w, referer as r "+
-                    "where r.websiteid=w.id and w.isenabled=? and w.isactive=? " +
-                    "group by w.name, w.handle, w.id order by s desc fetch first " +
-                    Integer.toString(max) + " rows only");
+                        "select w.id, w.name, w.handle, sum(r.dayhits) as s "+
+                        "from website as w, referer as r "+
+                        "where r.websiteid=w.id and w.isenabled=? and w.isactive=? " +
+                        "group by w.name, w.handle, w.id order by s desc fetch first " +
+                        Integer.toString(max) + " rows only");
                 stmt.setBoolean(1, true);
                 stmt.setBoolean(2, true);
             } else if (currentDialect instanceof OracleDialect) {
-				stmt = con.prepareStatement(
-                    "select w.id, w.name, w.handle, sum(r.dayhits) as s "+
-                    "from website w, referer r "+
-                    "where r.websiteid=w.id and w.isenabled=? and w.isactive=? and rownum <= ? " +
-                    "group by w.name, w.handle, w.id order by s desc");
-				stmt.setBoolean(1, true);
-				stmt.setBoolean(2, true);
-				stmt.setInt(3, max );
+                stmt = con.prepareStatement(
+                        "select w.id, w.name, w.handle, sum(r.dayhits) as s "+
+                        "from website w, referer r "+
+                        "where r.websiteid=w.id and w.isenabled=? and w.isactive=? and rownum <= ? " +
+                        "group by w.name, w.handle, w.id order by s desc");
+                stmt.setBoolean(1, true);
+                stmt.setBoolean(2, true);
+                stmt.setInt(3, max );
             } else if (currentDialect instanceof SQLServerDialect) {
-            	stmt = con.prepareStatement("select top " + max + " w.id, w.name, w.handle, sum(r.dayhits) as s " +
-            	     "from website as w, referer as r where r.websiteid=w.id and w.isenabled=? and w.isactive=? " +
-            	     "group by w.name, w.handle, w.id order by s desc");
-            	stmt.setBoolean(1, true);
+                stmt = con.prepareStatement("select top " + max + " w.id, w.name, w.handle, sum(r.dayhits) as s " +
+                        "from website as w, referer as r where r.websiteid=w.id and w.isenabled=? and w.isactive=? " +
+                        "group by w.name, w.handle, w.id order by s desc");
+                stmt.setBoolean(1, true);
                 stmt.setBoolean(2, true);
             } else { // for MySQL and PostgreSQL
                 stmt = con.prepareStatement(
-                    "select w.id, w.name, w.handle, sum(r.dayhits) as s "+
-                    "from website as w, referer as r "+
-                    "where r.websiteid=w.id and w.isenabled= ? and w.isactive=? " +
-                    // Ben Walding (a Postgres SQL user): Basically, you have
-                    // to have all non-aggregated columns that exist in your
-                    // 'SELECT' section, in the 'GROUP BY' section as well:
-                    "group by w.name, w.handle, w.id order by s desc limit ?");
+                        "select w.id, w.name, w.handle, sum(r.dayhits) as s "+
+                        "from website as w, referer as r "+
+                        "where r.websiteid=w.id and w.isenabled= ? and w.isactive=? " +
+                        // Ben Walding (a Postgres SQL user): Basically, you have
+                        // to have all non-aggregated columns that exist in your
+                        // 'SELECT' section, in the 'GROUP BY' section as well:
+                        "group by w.name, w.handle, w.id order by s desc limit ?");
                 stmt.setBoolean(1, true);
                 stmt.setBoolean(2, true);
                 stmt.setInt(3, max);
@@ -260,38 +413,39 @@
                             websiteHandle,
                             hits));
                     if(list.size() >= max) {
-                    	rs.close();
-                    	break;
+                        rs.close();
+                        break;
                     }
                 }
                 while ( rs.next() );
             }
             return list;
         } catch (Throwable pe) {
-            mLogger.error(msg, pe);
+            log.error(msg, pe);
             throw new RollerException(msg, pe);
-        }        
+        }
     }
     
-    //-----------------------------------------------------------------------
     
     /**
      * Use raw SQL because Hibernate can't handle the query.
      */
-    protected int getHits(WebsiteData website, String type)
-    throws RollerException {
+    protected int getHits(WebsiteData website, String type) throws RollerException {
         int hits = 0;
-        if (mLogger.isDebugEnabled()) {
-            mLogger.debug("getHits: " + website.getName());
+        if (log.isDebugEnabled()) {
+            log.debug("getHits: " + website.getName());
         }
         
         Object[] args = { Boolean.TRUE, website.getId() };
         Type[] types = { Hibernate.BOOLEAN, Hibernate.STRING };
         
         // For a query like this, Hibernate returns a list of lists
-        Session session = ((HibernateStrategy)mStrategy).getSession();
+        Session session = ((HibernatePersistenceStrategy)strategy).getSession();
         List results;
         try {
+            // begin transaction
+            this.strategy.getSession().beginTransaction();
+            
             Query q = session.createQuery(
                     "select sum(h.dayHits),sum(h.totalHits) from h in class " +
                     "org.roller.pojos.RefererData " +
@@ -318,6 +472,7 @@
         return hits;
     }
     
+    
     /**
      * @see org.roller.pojos.RefererManager#getReferers(java.lang.String)
      */
@@ -325,40 +480,45 @@
         if (website==null )
             throw new RollerException("website is null");
         
-        Session session = ((HibernateStrategy)mStrategy).getSession();
-        Criteria criteria = session.createCriteria(RefererData.class);
-        criteria.add(Expression.eq("website",website));
-        criteria.addOrder(Order.desc("totalHits"));
         try {
+            // begin transaction
+            this.strategy.getSession().beginTransaction();
+            
+            Session session = ((HibernatePersistenceStrategy)strategy).getSession();
+            Criteria criteria = session.createCriteria(RefererData.class);
+            criteria.add(Expression.eq("website",website));
+            criteria.addOrder(Order.desc("totalHits"));
+            
             return criteria.list();
         } catch (HibernateException e) {
             throw new RollerException(e);
         }
     }
-        
-    //-----------------------------------------------------------------------
+    
     
     /**
      * @see org.roller.pojos.RefererManager#getTodaysReferers(String)
      */
-    public List getTodaysReferers(WebsiteData website)
-    throws RollerException {
+    public List getTodaysReferers(WebsiteData website) throws RollerException {
         if (website==null )
             throw new RollerException("website is null");
         
-        Session session = ((HibernateStrategy)mStrategy).getSession();
-        Criteria criteria = session.createCriteria(RefererData.class);
-        criteria.add(Expression.eq("website", website));
-        criteria.add(Expression.gt("dayHits", new Integer(0)));
-        criteria.addOrder(Order.desc("dayHits"));
         try {
+            // begin transaction
+            this.strategy.getSession().beginTransaction();
+            
+            Session session = ((HibernatePersistenceStrategy)strategy).getSession();
+            Criteria criteria = session.createCriteria(RefererData.class);
+            criteria.add(Expression.eq("website", website));
+            criteria.add(Expression.gt("dayHits", new Integer(0)));
+            criteria.addOrder(Order.desc("dayHits"));
+            
             return criteria.list();
         } catch (HibernateException e) {
             throw new RollerException(e);
         }
     }
     
-    //-----------------------------------------------------------------------
     
     /**
      * Returns referers for a specified day. Duplicate enties are not
@@ -367,27 +527,30 @@
      * org.roller.pojos.WebsiteData, java.lang.String)
      */
     public List getReferersToDate(WebsiteData website, String date)
-    throws RollerException {
+            throws RollerException {
         if (website==null )
             throw new RollerException("website is null");
         
         if (date==null )
             throw new RollerException("Date is null");
         
-        Session session = ((HibernateStrategy)mStrategy).getSession();
-        Criteria criteria = session.createCriteria(RefererData.class);
-        criteria.add(Expression.eq("website", website));
-        criteria.add(Expression.eq("dateString", date));
-        criteria.add(Expression.eq("duplicate", Boolean.FALSE));
-        criteria.addOrder(Order.desc("totalHits"));
         try {
+            // begin transaction
+            this.strategy.getSession().beginTransaction();
+            
+            Session session = ((HibernatePersistenceStrategy)strategy).getSession();
+            Criteria criteria = session.createCriteria(RefererData.class);
+            criteria.add(Expression.eq("website", website));
+            criteria.add(Expression.eq("dateString", date));
+            criteria.add(Expression.eq("duplicate", Boolean.FALSE));
+            criteria.addOrder(Order.desc("totalHits"));
+            
             return criteria.list();
         } catch (HibernateException e) {
             throw new RollerException(e);
         }
     }
     
-    //-----------------------------------------------------------------------
     
     /**
      * @see org.roller.pojos.RefererManager#getReferersToEntry(
@@ -398,7 +561,10 @@
             throw new RollerException("entryid is null");
         
         try {
-            Session session = ((HibernateStrategy)mStrategy).getSession();
+            // begin transaction
+            this.strategy.getSession().beginTransaction();
+            
+            Session session = ((HibernatePersistenceStrategy)strategy).getSession();
             Criteria criteria = session.createCriteria(RefererData.class);
             criteria.createAlias("weblogEntry","e");
             
@@ -414,62 +580,42 @@
         }
     }
     
-    //-----------------------------------------------------------------------
     
     /**
-     * @see org.roller.pojos.RefererManager#getReferersToEntry(
-     * java.lang.String, java.lang.String)
+     * Query for collection of referers.
      */
-    public void removeReferersForEntry(String entryid) throws RollerException {
-        if (null == entryid)
-            throw new RollerException("entryid is null");
+    protected List getReferersToWebsite(WebsiteData website, String refererUrl)
+            throws RollerException {
         
         try {
-            Session session = ((HibernateStrategy)mStrategy).getSession();
+            // begin transaction
+            this.strategy.getSession().beginTransaction();
+            
+            Session session = ((HibernatePersistenceStrategy)strategy).getSession();
             Criteria criteria = session.createCriteria(RefererData.class);
-            criteria.createAlias("weblogEntry","e");
-            criteria.add(Expression.eq("e.id", entryid));
+            criteria.add(Expression.eq("website", website));
+            criteria.add(Expression.eq("refererUrl", refererUrl));
             
-            Iterator referers = criteria.list().iterator();
-            while (referers.hasNext()) {
-                removeReferer( ((RefererData)referers.next()).getId() );
-            }
-        } catch (HibernateException e) {
-            throw new RollerException(e);
-        }
-    }
-    
-    //-----------------------------------------------------------------------
-    
-    /**
-     * Query for collection of referers.
-     */
-    protected List getReferersToWebsite(WebsiteData website, String refererUrl)
-    throws RollerException {
-        Session session = ((HibernateStrategy)mStrategy).getSession();
-        Criteria criteria = session.createCriteria(RefererData.class);
-        criteria.add(Expression.eq("website", website));
-        criteria.add(Expression.eq("refererUrl", refererUrl));
-        try {
             return criteria.list();
         } catch (HibernateException e) {
             throw new RollerException(e);
         }
     }
     
-    //-----------------------------------------------------------------------
     
     /**
      * Query for collection of referers.
      */
-    protected List getReferersWithSameTitle(
-            WebsiteData website,
-            String requestUrl,
-            String title,
-            String excerpt)
+    protected List getReferersWithSameTitle(WebsiteData website,
+                                            String requestUrl,
+                                            String title,
+                                            String excerpt)
             throws RollerException {
         try {
-            Session session = ((HibernateStrategy)mStrategy).getSession();
+            // begin transaction
+            this.strategy.getSession().beginTransaction();
+            
+            Session session = ((HibernatePersistenceStrategy)strategy).getSession();
             Criteria criteria = session.createCriteria(RefererData.class);
             
             Junction conjunction = Expression.conjunction();
@@ -489,57 +635,308 @@
         }
     }
     
+    
+    public int getDayHits(WebsiteData website) throws RollerException {
+        return getHits(website, DAYHITS);
+    }
+    
+    
+    public int getTotalHits(WebsiteData website) throws RollerException {
+        return getHits(website, TOTALHITS);
+    }
+    
+    
     /**
-     * Clear referrer dayhits and remove referrers without excerpts.
+     * @see org.roller.pojos.RefererManager#retrieveReferer(java.lang.String)
      */
-    public void clearReferrers() throws RollerException {
-
-        if (mLogger.isDebugEnabled()) {
-            mLogger.debug("clearReferrers");
-        }       
+    public RefererData retrieveReferer(String id) throws RollerException {
+        return (RefererData)strategy.load(id,RefererData.class);
+    }
+    
+    
+    public List getEntryReferers(String entryId, boolean authorized)
+            throws RollerException {
+        //TODO: Redesign this so this is performed using the DB query, and
+        // not in java code for perf/memory reasons
+        List authorizedvisible = new ArrayList();
+        List referers = getReferersToEntry(entryId);
+        for (Iterator rItr = referers.iterator(); rItr.hasNext();) {
+            RefererData referer = (RefererData) rItr.next();
+            if ( referer.getVisible().booleanValue() || authorized ) {
+                authorizedvisible.add( referer );
+            }
+        }
+        
+        return authorizedvisible;
+    }
+    
+    
+    public void processReferrer(String requestUrl,
+                                String referrerUrl,
+                                String weblogHandle,
+                                String entryAnchor,
+                                String dateString) {
+        
+        log.debug("processing referrer ["+referrerUrl+
+                "] accessing ["+requestUrl+"]");
+        
+        if (weblogHandle == null)
+            return;
+        
+        String selfSiteFragment = "/page/"+weblogHandle;
+        WebsiteData weblog = null;
+        WeblogEntryData entry = null;
+        
+        // lookup the weblog now
         try {
-            Session session = ((HibernateStrategy)mStrategy).getSession();
-            Dialect currentDialect = ((SessionFactoryImplementor)session.getSessionFactory()).getDialect();
-            String reset = "update RefererData set dayHits=0";
-            session.createQuery(reset).executeUpdate();
-            String delete = null;
-            if ( currentDialect instanceof SQLServerDialect || currentDialect instanceof OracleDialect ){
-            	delete = "delete RefererData where excerpt is null or excerpt like ''";
+            UserManager userMgr = RollerFactory.getRoller().getUserManager();
+            weblog = userMgr.getWebsiteByHandle(weblogHandle);
+            if (weblog == null) return;
+            
+            // now lookup weblog entry if possible
+            if (entryAnchor != null) {
+                WeblogManager weblogMgr = RollerFactory.getRoller().getWeblogManager();
+                entry = weblogMgr.getWeblogEntryByAnchor(weblog, entryAnchor);
+            }
+        } catch (RollerException re) {
+            // problem looking up website, gotta bail
+            log.error("Error looking up website object", re);
+            return;
+        }
+        
+        try {
+            List matchRef = null;
+            
+            // try to find existing RefererData for referrerUrl
+            if (referrerUrl == null || referrerUrl.trim().length() < 8) {
+                referrerUrl = "direct";
+                
+                // Get referer specified by referer URL of direct
+                matchRef = getReferersToWebsite(weblog, referrerUrl);
             } else {
-            	delete = "delete RefererData where excerpt is null or excerpt=''";	
+                referrerUrl = Utilities.stripJsessionId(referrerUrl);
+                
+                // Query for referer with same referer and request URLs
+                matchRef = getMatchingReferers(weblog, requestUrl, referrerUrl);
+                
+                // If referer was not found, try adding or leaving off 'www'
+                if ( matchRef.size() == 0 ) {
+                    String secondTryUrl = null;
+                    if ( referrerUrl.startsWith("http://www") ) {
+                        secondTryUrl = "http://"+referrerUrl.substring(11);
+                    } else {
+                        secondTryUrl = "http://www"+referrerUrl.substring(7);
+                    }
+                    
+                    matchRef = getMatchingReferers(weblog, requestUrl, secondTryUrl);
+                    if ( matchRef.size() == 1 ) {
+                        referrerUrl = secondTryUrl;
+                    }
+                }
             }
-            session.createQuery(delete).executeUpdate();
-        } catch (Exception e) {
-            mLogger.error("EXCEPTION resetting referers",e);
+            
+            if (matchRef.size() == 1) {
+                // Referer was found in database, so bump up hit count
+                RefererData ref = (RefererData)matchRef.get(0);
+                
+                ref.setDayHits(new Integer(ref.getDayHits().intValue() + 1));
+                ref.setTotalHits(new Integer(ref.getTotalHits().intValue() + 1));
+                
+                log.debug("Incrementing hit count on existing referer: "+referrerUrl);
+                
+                storeReferer(ref);
+                
+            } else if (matchRef.size() == 0) {
+                
+                // Referer was not found in database, so new Referer object
+                Integer one = new Integer(1);
+                RefererData ref =
+                        new RefererData(
+                        null,
+                        weblog,
+                        entry,
+                        dateString,
+                        referrerUrl,
+                        null,
+                        requestUrl,
+                        null,
+                        "", // Read comment above regarding Derby bug
+                        Boolean.FALSE,
+                        Boolean.FALSE,
+                        one,
+                        one);
+                
+                if (log.isDebugEnabled()) {
+                    log.debug("newReferer="+ref.getRefererUrl());
+                }
+                
+                String refurl = ref.getRefererUrl();
+                
+                // If not a direct or search engine then search for linkback
+                boolean doLinkbackExtraction =
+                        RollerRuntimeConfig.getBooleanProperty("site.linkbacks.enabled");
+                if (doLinkbackExtraction
+                        && entry != null
+                        && !refurl.equals("direct")
+                        && !refurl.startsWith("http://google")
+                        && !refurl.startsWith("http://www.google")
+                        && !refurl.startsWith("http://search.netscape")
+                        && !refurl.startsWith("http://www.blinkpro")
+                        && !refurl.startsWith("http://search.msn")
+                        && !refurl.startsWith("http://search.yahoo")
+                        && !refurl.startsWith("http://uk.search.yahoo")
+                        && !refurl.startsWith("http://www.javablogs.com")
+                        && !refurl.startsWith("http://www.teoma")
+                        ) {
+                    // Launch thread to extract referer linkback
+                    
+                    try {
+                        Roller mRoller = RollerFactory.getRoller();
+                        mRoller.getThreadManager().executeInBackground(
+                                new LinkbackExtractorRunnable(ref));
+                    } catch (InterruptedException e) {
+                        log.warn("Interrupted during linkback extraction",e);
+                    }
+                } else {
+                    storeReferer(ref);
+                }
+            }
+        } catch (RollerException pe) {
+            log.error(pe);
+        } catch (NullPointerException npe) {
+            log.error(npe);
         }
-    }  
+    }
+    
     
     /**
-     * Clear referrer dayhits and remove referrers without excerpts.
-     */
-    public void clearReferrers(WebsiteData website) throws RollerException {
-
-        if (mLogger.isDebugEnabled()) {
-            mLogger.debug("clearReferrers");
-        }       
-        try {
-            Session session = ((HibernateStrategy)mStrategy).getSession();
-            Dialect currentDialect = ((SessionFactoryImplementor)session.getSessionFactory()).getDialect();
-            String reset = "update RefererData set dayHits=0 where website=:site";
-            session.createQuery(reset)
-                .setParameter("site",website).executeUpdate();
-            String delete = null;
-            if ( currentDialect instanceof SQLServerDialect || currentDialect instanceof OracleDialect ){
-            	delete = "delete RefererData where website=:site and (excerpt is null or excerpt like '')";
-            } else {
-            	delete = "delete RefererData where website=:site and (excerpt is null or excerpt='')";            	
+     * Use LinkbackExtractor to parse title and excerpt from referer
+     */
+    class LinkbackExtractorRunnable implements Runnable {
+        
+        private RefererData mReferer = null;
+        
+        public LinkbackExtractorRunnable( RefererData referer) {
+            mReferer = referer;
+        }
+        
+        public void run() {
+            
+            try {
+                LinkbackExtractor lb = new LinkbackExtractor(
+                        mReferer.getRefererUrl(),mReferer.getRequestUrl());
+                
+                if ( lb.getTitle()!=null && lb.getExcerpt()!=null ) {
+                    mReferer.setTitle(lb.getTitle());
+                    mReferer.setExcerpt(lb.getExcerpt());
+                    
+                    if ( lb.getPermalink() != null ) {
+                        // The presence of a permalink indicates that this
+                        // linkback was parsed out of an RSS feed and is
+                        // presumed to be a good linkback.
+                        
+                        mReferer.setRefererPermalink(lb.getPermalink());
+                        
+                        // See if this request/permalink is in the DB
+                        List matchRef = getExistingReferers(
+                                mReferer.getWebsite(),
+                                mReferer.getDateString(),
+                                mReferer.getRefererPermalink());
+                        
+                        // If it is the first, then set it to be visible
+                        if ( matchRef.size() == 0 ) {
+                            mReferer.setVisible(Boolean.TRUE);
+                        } else {
+                            // We can't throw away duplicates or we will
+                            // end up reparsing them everytime a hit comes
+                            // in from one of them, but we can mark them
+                            // as duplicates.
+                            mReferer.setDuplicate(Boolean.TRUE);
+                        }
+                        
+                        storeReferer(mReferer);
+                        
+                    }
+                    
+                    else {
+                        // Store the new referer
+                        storeReferer(mReferer);
+                        
+                        // Hacky Referer URL weighting kludge:
+                        //
+                        // If there are multple referers to a request URL,
+                        // then we want to pick the best one. The others
+                        // are marked as duplicates. To do this we use a
+                        // weight. The weight formula is:
+                        //
+                        // w = URL length + (100 if URL contains anchor)
+                        
+                        // LOOP: find the referer with the highest weight
+                        Boolean visible = Boolean.FALSE;
+                        List refs= getReferersWithSameTitle(
+                                mReferer.getWebsite(),
+                                mReferer.getRequestUrl(),
+                                lb.getTitle(),
+                                lb.getExcerpt());
+                        RefererData chosen = null;
+                        int maxweight = 0;
+                        for (Iterator rdItr = refs.iterator();rdItr.hasNext();) {
+                            RefererData referer = (RefererData) rdItr.next();
+                            
+                            int weight = referer.getRefererUrl().length();
+                            if (referer.getRefererUrl().indexOf('#') != -1) {
+                                weight += 100;
+                            }
+                            
+                            if ( weight > maxweight ) {
+                                chosen = referer;
+                                maxweight = weight;
+                            }
+                            
+                            if (referer.getVisible().booleanValue()) {
+                                // If any are visible then chosen
+                                // replacement must be visible as well.
+                                visible = Boolean.TRUE;
+                            }
+                            
+                        }
+                        
+                        // LOOP: to mark all of the lower weight ones
+                        // as duplicates
+                        for (Iterator rdItr = refs.iterator();rdItr.hasNext();) {
+                            RefererData referer = (RefererData) rdItr.next();
+                            
+                            if (referer != chosen) {
+                                referer.setDuplicate(Boolean.TRUE);
+                            } else {
+                                referer.setDuplicate(Boolean.FALSE);
+                                referer.setVisible(visible);
+                            }
+                            storeReferer(referer);
+                        }
+                        
+                        
+                    }
+                } else {
+                    // It is not a linkback, but store it anyway
+                    storeReferer(mReferer);
+                    
+                    log.info("No excerpt found at refering URL "
+                            + mReferer.getRefererUrl());
+                }
+            } catch (Exception e) {
+                log.error("Processing linkback",e);
+            } finally {
+                strategy.release();
             }
-            session.createQuery(delete)
-                .setParameter("site",website).executeUpdate();
-        } catch (Exception e) {
-            mLogger.error("EXCEPTION resetting referers",e);
+            
         }
-    }  
+        
+    }
+    
+    
+    public void release() {}
+    
 }
 
 

Modified: incubator/roller/branches/roller-newbackend/src/org/roller/business/hibernate/HibernateRollerImpl.java
URL: http://svn.apache.org/viewcvs/incubator/roller/branches/roller-newbackend/src/org/roller/business/hibernate/HibernateRollerImpl.java?rev=392618&r1=392617&r2=392618&view=diff
==============================================================================
--- incubator/roller/branches/roller-newbackend/src/org/roller/business/hibernate/HibernateRollerImpl.java (original)
+++ incubator/roller/branches/roller-newbackend/src/org/roller/business/hibernate/HibernateRollerImpl.java Sat Apr  8 15:36:25 2006
@@ -3,14 +3,10 @@
  */
 package org.roller.business.hibernate;
 
-import org.hibernate.HibernateException;
-import org.hibernate.SessionFactory;
-import org.hibernate.cfg.Configuration;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.roller.RollerException;
-import org.roller.business.PersistenceStrategy;
-import org.roller.business.utils.UpgradeDatabase;
+import org.roller.business.RollerImpl;
 import org.roller.model.BookmarkManager;
 import org.roller.model.ConfigManager;
 import org.roller.model.AutoPingManager;
@@ -22,66 +18,51 @@
 import org.roller.model.Roller;
 import org.roller.model.UserManager;
 import org.roller.model.WeblogManager;
-import org.roller.pojos.UserData;
 
-import java.sql.Connection;
 
 /**
- * Implements Roller, the entry point interface for the Roller business tier APIs.
- * Hibernate specific implementation.
- *
- * @author David M Johnson
+ * A Hibernate specific implementation of the Roller business layer.
  */
-public class HibernateRollerImpl extends org.roller.business.RollerImpl
-{
+public class HibernateRollerImpl extends RollerImpl {
+    
     static final long serialVersionUID = 5256135928578074652L;
-
-    private static Log mLogger = 
-        LogFactory.getFactory().getInstance(HibernateRollerImpl.class);
     
-    protected BookmarkManager mBookmarkManager;   
-    protected ConfigManager   mConfigManager = null;
-    protected PropertiesManager mPropsManager = null;
-    protected PlanetManager   planetManager = null;
-    protected RefererManager  mRefererManager;
-    protected UserManager     mUserManager;
-    protected WeblogManager   mWeblogManager;
-    protected PingQueueManager mPingQueueManager;
-    protected AutoPingManager mAutoPingManager;
-    protected PingTargetManager mPingTargetManager;
-    protected static HibernateRollerImpl me;
-    protected PersistenceStrategy mStrategy = null;
-    protected static SessionFactory mSessionFactory;
-
-
-    protected HibernateRollerImpl() throws RollerException
-    {
-        mLogger.debug("Initializing sessionFactory for Hibernate");
-        
-        try 
-        {
-            Configuration config = new Configuration();
-            config.configure("/hibernate.cfg.xml");
-            mSessionFactory = config.buildSessionFactory();
-        } 
-        catch (HibernateException e) 
-        {
-            mLogger.error("Error Setting up SessionFactory",e);
-            throw new RollerException(e);
+    private static Log mLogger = LogFactory.getLog(HibernateRollerImpl.class);
+    
+    // our singleton instance
+    private static HibernateRollerImpl me = null;
+    
+    // a persistence utility class
+    private HibernatePersistenceStrategy strategy = null;
+    
+    // references to the managers we maintain
+    private BookmarkManager bookmarkManager = null;
+    private ConfigManager configManager = null;
+    private PropertiesManager propertiesManager = null;
+    private PlanetManager planetManager = null;
+    private RefererManager refererManager = null;
+    private UserManager userManager = null;
+    private WeblogManager weblogManager = null;
+    private PingQueueManager pingQueueManager = null;
+    private AutoPingManager autoPingManager = null;
+    private PingTargetManager pingTargetManager = null;
+    
+    
+    protected HibernateRollerImpl() throws RollerException {
+        try {
+            strategy = new HibernatePersistenceStrategy();
+        } catch(Throwable t) {
+            // if this happens then we are screwed
+            throw new RollerException(t);
         }
-        
-        mStrategy = new HibernateStrategy(mSessionFactory);    
     }
-
+    
     
     /**
      * Instantiates and returns an instance of HibernateRollerImpl.
-     * @see org.roller.model.RollerFactory
      */
-    public static Roller instantiate() throws RollerException
-    {
-        if (me == null) 
-        {
+    public static Roller instantiate() throws RollerException {
+        if (me == null) {
             mLogger.debug("Instantiating HibernateRollerImpl");
             me = new HibernateRollerImpl();
         }
@@ -89,219 +70,145 @@
         return me;
     }
     
-
-    public void begin() throws RollerException
-    {
-        mStrategy.begin(UserData.ANONYMOUS_USER);
-    }
-    
-    public void begin(UserData user) throws RollerException
-    {
-        mStrategy.begin(user);
-    }
-    
-    public UserData getUser() throws RollerException
-    {
-        return mStrategy.getUser();
-    }
     
-    public void setUser(UserData user) throws RollerException
-    {
-        mStrategy.setUser(user);
+    public void commit() throws RollerException {
+        //strategy.commit();
     }
     
-    public void commit() throws RollerException
-    {
-        mStrategy.commit();
-    }
     
-	public void rollback()
-	{
-		try
-		{
-			mStrategy.rollback();
-		}
-		catch (Throwable e)
-		{
-			mLogger.error(e);
-		}
-	}
-
-    /** 
+    /**
      * @see org.roller.model.Roller#getUserManager()
      */
-    public UserManager getUserManager() throws RollerException
-    {
-        if ( mUserManager == null ) 
-        {
-            mUserManager = new HibernateUserManagerImpl(mStrategy);
+    public UserManager getUserManager() throws RollerException {
+        if ( userManager == null ) {
+            userManager = new HibernateUserManagerImpl(strategy);
         }
-        return mUserManager;
+        return userManager;
     }
-
-    /** 
+    
+    /**
      * @see org.roller.model.Roller#getBookmarkManager()
      */
-    public BookmarkManager getBookmarkManager() throws RollerException
-    {
-        if ( mBookmarkManager == null ) 
-        {
-            mBookmarkManager = new HibernateBookmarkManagerImpl(mStrategy);
+    public BookmarkManager getBookmarkManager() throws RollerException {
+        if ( bookmarkManager == null ) {
+            bookmarkManager = new HibernateBookmarkManagerImpl(strategy);
         }
-        return mBookmarkManager;
+        return bookmarkManager;
     }
-
-    /** 
+    
+    /**
      * @see org.roller.model.Roller#getWeblogManager()
      */
-    public WeblogManager getWeblogManager() throws RollerException
-    {
-        if ( mWeblogManager == null ) 
-        {
-            mWeblogManager = new HibernateWeblogManagerImpl(mStrategy);
+    public WeblogManager getWeblogManager() throws RollerException {
+        if ( weblogManager == null ) {
+            weblogManager = new HibernateWeblogManagerImpl(strategy);
         }
-        return mWeblogManager;
+        return weblogManager;
     }
-
-    /** 
+    
+    /**
      * @see org.roller.model.Roller#getRefererManager()
      */
-    public RefererManager getRefererManager() throws RollerException
-    {
-        if ( mRefererManager == null ) 
-        {
-            mRefererManager = new HibernateRefererManagerImpl(mStrategy);
+    public RefererManager getRefererManager() throws RollerException {
+        if ( refererManager == null ) {
+            refererManager = new HibernateRefererManagerImpl(strategy);
         }
-        return mRefererManager;
+        return refererManager;
     }
-
+    
     /**
      * @see org.roller.model.Roller#getConfigManager()
      */
-    public ConfigManager getConfigManager() throws RollerException 
-    {
-        if (mConfigManager == null)
-        {
-            mConfigManager = new HibernateConfigManagerImpl(mStrategy);
+    public ConfigManager getConfigManager() throws RollerException {
+        if (configManager == null) {
+            configManager = new HibernateConfigManagerImpl(strategy);
         }
-        return mConfigManager;
+        return configManager;
     }
     
     /**
      * @see org.roller.model.Roller#getPropertiesManager()
      */
-    public PropertiesManager getPropertiesManager() throws RollerException 
-    {
-        if (mPropsManager == null)
-        {
-            mPropsManager = new HibernatePropertiesManagerImpl(mStrategy);
+    public PropertiesManager getPropertiesManager() throws RollerException {
+        if (propertiesManager == null) {
+            propertiesManager = new HibernatePropertiesManagerImpl(strategy);
         }
-        return mPropsManager;
+        return propertiesManager;
     }
-
+    
     /**
      * @see org.roller.model.Roller#getPingTargetManager()
      */
-    public PingQueueManager getPingQueueManager() throws RollerException
-    {
-        if (mPingQueueManager == null)
-        {
-            mPingQueueManager = new HibernatePingQueueManagerImpl(mStrategy);
+    public PingQueueManager getPingQueueManager() throws RollerException {
+        if (pingQueueManager == null) {
+            pingQueueManager = new HibernatePingQueueManagerImpl(strategy);
         }
-        return mPingQueueManager;
+        return pingQueueManager;
     }
-
+    
     /**
      * @see org.roller.model.Roller#getPlanetManager()
      */
-    public PlanetManager getPlanetManager() throws RollerException
-    {
-        if ( planetManager == null ) 
-        {
-            planetManager = new HibernatePlanetManagerImpl(mStrategy,this);
+    public PlanetManager getPlanetManager() throws RollerException {
+        if ( planetManager == null ) {
+            planetManager = new HibernatePlanetManagerImpl(strategy,this);
         }
         return planetManager;
     }
-
-
+    
+    
     /**
      * @see org.roller.model.Roller#getPingTargetManager()
      */
-    public AutoPingManager getAutopingManager() throws RollerException
-    {
-        if (mAutoPingManager == null)
-        {
-            mAutoPingManager = new HibernateAutoPingManagerImpl(mStrategy);
+    public AutoPingManager getAutopingManager() throws RollerException {
+        if (autoPingManager == null) {
+            autoPingManager = new HibernateAutoPingManagerImpl(strategy);
         }
-        return mAutoPingManager;
+        return autoPingManager;
     }
-
-
+    
+    
     /**
      * @see org.roller.model.Roller#getPingTargetManager()
      */
-    public PingTargetManager getPingTargetManager() throws RollerException
-    {
-        if (mPingTargetManager == null)
-        {
-            mPingTargetManager = new HibernatePingTargetManagerImpl(mStrategy);
+    public PingTargetManager getPingTargetManager() throws RollerException {
+        if (pingTargetManager == null) {
+            pingTargetManager = new HibernatePingTargetManagerImpl(strategy);
         }
-        return mPingTargetManager;
-    }
-
-
-    /**
-     * @see org.roller.model.Roller#getPersistenceStrategy()
-     */
-    public PersistenceStrategy getPersistenceStrategy()
-    {
-        return mStrategy;
+        return pingTargetManager;
     }
     
-    /** 
-     * @see org.roller.model.Roller#upgradeDatabase(java.sql.Connection)
-     */
-    public void upgradeDatabase(Connection con) throws RollerException
-    {
-        UpgradeDatabase.upgradeDatabase(con); 
-    }
-
-    public void release()
-    {
-        super.release();
+    
+    public void release() {
         
-        if (mBookmarkManager != null) mBookmarkManager.release();
-        if (mConfigManager != null) mConfigManager.release();
-        if (mRefererManager != null) mRefererManager.release();
-        if (mUserManager != null) mUserManager.release();
-        if (mWeblogManager != null) mWeblogManager.release();
-        if (mPingTargetManager != null) mPingTargetManager.release();
-        if (mPingQueueManager != null) mPingQueueManager.release();
-        if (mAutoPingManager != null) mAutoPingManager.release();
+        // release our own stuff first
+        if (bookmarkManager != null) bookmarkManager.release();
+        if (configManager != null) configManager.release();
+        if (refererManager != null) refererManager.release();
+        if (userManager != null) userManager.release();
+        if (weblogManager != null) weblogManager.release();
+        if (pingTargetManager != null) pingTargetManager.release();
+        if (pingQueueManager != null) pingQueueManager.release();
+        if (autoPingManager != null) autoPingManager.release();
         
-        try
-        {
-            if (mStrategy != null) mStrategy.release(); 
-        }
-        catch (Throwable e)
-        {
-            mLogger.error(
-            "Exception with mSupport.release() [" + e + "]", e);
+        try {
+            if (strategy != null) strategy.release();
+        } catch (Throwable e) {
+            mLogger.error("Error calling Roller.release()", e);
         }
+        
+        // then let parent do its thing
+        super.release();
     }
-
-    public void shutdown()
-    {
-        super.shutdown();
+    
+    
+    public void shutdown() {
         
-        try
-        {
-            release();
-            mSessionFactory.close();
-        }
-        catch (HibernateException e)
-        {
-            mLogger.error("Unable to close SessionFactory", e);
-        }
+        // do our own shutdown first
+        this.release();
+        
+        // then let parent do its thing
+        super.shutdown();
     }
+    
 }



Mime
View raw message