roller-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From snoopd...@apache.org
Subject svn commit: r189695 [20/67] - in /incubator/roller/trunk: ./ contrib/ contrib/lib/ contrib/plugins/ contrib/plugins/src/ contrib/plugins/src/org/ contrib/plugins/src/org/roller/ contrib/plugins/src/org/roller/presentation/ contrib/plugins/src/org/roller/presentation/velocity/ contrib/plugins/src/org/roller/presentation/velocity/plugins/ contrib/plugins/src/org/roller/presentation/velocity/plugins/acronyms/ contrib/plugins/src/org/roller/presentation/velocity/plugins/bookmarks/ contrib/plugins/src/org/roller/presentation/velocity/plugins/email/ contrib/plugins/src/org/roller/presentation/velocity/plugins/jspwiki/ contrib/plugins/src/org/roller/presentation/velocity/plugins/radeox/ contrib/plugins/src/org/roller/presentation/velocity/plugins/readmore/ contrib/plugins/src/org/roller/presentation/velocity/plugins/smileys/ contrib/plugins/src/org/roller/presentation/velocity/plugins/textile/ contrib/plugins/src/org/roller/presentation/velocity/plugins/topictag/ custom/ custom/src/ custom/web/ docs/ docs/images/ docs/installguide/ docs/installguide/old/ docs/userguide/ docs/userguide/images/ docs/userguide/old/ metadata/ metadata/database/ metadata/database/hibernate/ metadata/xdoclet/ nbproject/ personal/ personal/eclipse/ personal/testing/ sandbox/ sandbox/planetroller/ sandbox/planetroller/metadata/ sandbox/planetroller/metadata/database/ sandbox/planetroller/src/ sandbox/planetroller/src/org/ sandbox/planetroller/src/org/roller/ sandbox/planetroller/src/org/roller/tools/ sandbox/planetroller/src/org/roller/tools/planet/ sandbox/planetroller/templates/ sandbox/planetroller/test/ sandbox/planetroller/test/org/ sandbox/planetroller/test/org/roller/ sandbox/planetroller/test/org/roller/model/ sandbox/planetroller/test/org/roller/tools/ sandbox/planetroller/test/org/roller/tools/planet/ sandbox/planetroller/testdata/ sandbox/planetroller/testdata/cache/ sandbox/planetroller/testdata/output/ sandbox/standalone/ sandbox/standalone/jspwiki/ sandbox/standalone/jspwiki/default/ sandbox/standalone/jspwiki/default/images/ sandbox/standalone/lib/ sandbox/standalone/src/ sandbox/standalone/src/org/ sandbox/standalone/src/org/roller/ sandbox/standalone/src/org/roller/jspwiki/ sandbox/standalone/src/org/roller/tomcat/ sandbox/standalone/src/org/roller/util/ sandbox/standalone/tests/ sandbox/standalone/tests/org/ sandbox/standalone/tests/org/roller/ sandbox/standalone/tests/org/roller/util/ sandbox/standalone/tomcat/ src/ src/org/ src/org/roller/ src/org/roller/business/ src/org/roller/business/hibernate/ src/org/roller/business/search/ src/org/roller/business/search/operations/ src/org/roller/business/utils/ src/org/roller/config/ src/org/roller/config/runtime/ src/org/roller/model/ src/org/roller/pojos/ src/org/roller/presentation/ src/org/roller/presentation/atomapi/ src/org/roller/presentation/bookmarks/ src/org/roller/presentation/bookmarks/actions/ src/org/roller/presentation/bookmarks/formbeans/ src/org/roller/presentation/bookmarks/tags/ src/org/roller/presentation/filters/ src/org/roller/presentation/forms/ src/org/roller/presentation/newsfeeds/ src/org/roller/presentation/pagecache/ src/org/roller/presentation/pagecache/rollercache/ src/org/roller/presentation/pings/ src/org/roller/presentation/planet/ src/org/roller/presentation/tags/ src/org/roller/presentation/tags/calendar/ src/org/roller/presentation/tags/menu/ src/org/roller/presentation/util/ src/org/roller/presentation/velocity/ src/org/roller/presentation/weblog/ src/org/roller/presentation/weblog/actions/ src/org/roller/presentation/weblog/formbeans/ src/org/roller/presentation/weblog/tags/ src/org/roller/presentation/website/ src/org/roller/presentation/website/actions/ src/org/roller/presentation/website/formbeans/ src/org/roller/presentation/website/tags/ src/org/roller/presentation/xmlrpc/ src/org/roller/util/ src/org/roller/util/rome/ tests/ tests/org/ tests/org/roller/ tests/org/roller/ant/ tests/org/roller/business/ tests/org/roller/presentation/ tests/org/roller/presentation/atomapi/ tests/org/roller/presentation/bookmarks/ tests/org/roller/presentation/filters/ tests/org/roller/presentation/velocity/ tests/org/roller/presentation/velocity/plugins/ tests/org/roller/presentation/velocity/plugins/smileys/ tests/org/roller/presentation/velocity/plugins/textile/ tests/org/roller/presentation/weblog/ tests/org/roller/presentation/xmlrpc/ tests/org/roller/util/ tests/org/roller/util/rome/ tools/ tools/buildtime/ tools/buildtime/ant-1.6.2/ tools/buildtime/findbugs/ tools/buildtime/findbugs/lib/ tools/buildtime/findbugs/plugin/ tools/buildtime/mockrunner-0.3/ tools/buildtime/mockrunner-0.3/lib/ tools/buildtime/mockrunner-0.35/ tools/buildtime/mockrunner-0.35/lib/ tools/buildtime/tomcat-4.1.24/ tools/buildtime/xdoclet-1.2/ tools/buildtime/xdoclet-1.2/lib/ tools/hibernate-2.1/ tools/hibernate-2.1/lib/ tools/lib/ tools/standard-1.0.3/ tools/standard-1.0.3/lib/ tools/standard-1.0.3/tld/ tools/struts-1.2.4/ tools/struts-1.2.4/lib/ web/ web/WEB-INF/ web/WEB-INF/classes/ web/WEB-INF/classes/flavors/ web/WEB-INF/classes/themes/ web/bookmarks/ web/editor/ web/editor/images/ web/images/ web/images/editor/ web/images/midas/ web/images/preview/ web/images/smileys/ web/planet/ web/tags/ web/templates/ web/theme/ web/theme/images/ web/theme/lavender/ web/theme/scripts/ web/theme/scripts/classes/ web/themes/ web/themes/basic/ web/themes/berkley/ web/themes/berkley/images/ web/themes/brushedmetal/ web/themes/brushedmetal/images/ web/themes/cheb/ web/themes/cheb/images/ web/themes/cheb/scripts/ web/themes/clean/ web/themes/currency-i18n/ web/themes/currency-i18n/images/ web/themes/currency/ web/themes/currency/images/ web/themes/grey2/ web/themes/moonshine/ web/themes/movablemanila/ web/themes/movablemanila/images/ web/themes/pacifica/ web/themes/robot/ web/themes/rolling/ web/themes/rolling/images/ web/themes/sotto/ web/themes/sotto/images/ web/themes/sotto/styles/ web/themes/sunsets/ web/themes/sunsets/images/ web/themes/sunsets/scripts/ web/themes/sunsets/styles/ web/themes/werner/ web/themes/x2/ web/themes/x2/images/ web/themes/x2/scripts/ web/themes/x2/styles/ web/weblog/ web/website/
Date Thu, 09 Jun 2005 03:19:20 GMT
Added: incubator/roller/trunk/src/org/roller/business/hibernate/HibernateRollerImpl.java
URL: http://svn.apache.org/viewcvs/incubator/roller/trunk/src/org/roller/business/hibernate/HibernateRollerImpl.java?rev=189695&view=auto
==============================================================================
--- incubator/roller/trunk/src/org/roller/business/hibernate/HibernateRollerImpl.java (added)
+++ incubator/roller/trunk/src/org/roller/business/hibernate/HibernateRollerImpl.java Wed Jun  8 20:18:46 2005
@@ -0,0 +1,307 @@
+/*
+ * Created on Feb 23, 2003
+ */
+package org.roller.business.hibernate;
+
+import net.sf.hibernate.HibernateException;
+import net.sf.hibernate.SessionFactory;
+import net.sf.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.model.BookmarkManager;
+import org.roller.model.ConfigManager;
+import org.roller.model.AutoPingManager;
+import org.roller.model.PingQueueManager;
+import org.roller.model.PingTargetManager;
+import org.roller.model.PlanetManager;
+import org.roller.model.PropertiesManager;
+import org.roller.model.RefererManager;
+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
+ */
+public class HibernateRollerImpl extends org.roller.business.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);
+        }
+        
+        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) 
+        {
+            mLogger.debug("Instantiating HibernateRollerImpl");
+            me = new HibernateRollerImpl();
+        }
+        
+        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
+    {
+        mStrategy.commit();
+    }
+    
+	public void rollback()
+	{
+		try
+		{
+			mStrategy.rollback();
+		}
+		catch (Exception e)
+		{
+			mLogger.error(e);
+		}
+	}
+
+    /** 
+     * @see org.roller.model.Roller#getUserManager()
+     */
+    public UserManager getUserManager() throws RollerException
+    {
+        if ( mUserManager == null ) 
+        {
+            mUserManager = new HibernateUserManagerImpl(mStrategy);
+        }
+        return mUserManager;
+    }
+
+    /** 
+     * @see org.roller.model.Roller#getBookmarkManager()
+     */
+    public BookmarkManager getBookmarkManager() throws RollerException
+    {
+        if ( mBookmarkManager == null ) 
+        {
+            mBookmarkManager = new HibernateBookmarkManagerImpl(mStrategy);
+        }
+        return mBookmarkManager;
+    }
+
+    /** 
+     * @see org.roller.model.Roller#getWeblogManager()
+     */
+    public WeblogManager getWeblogManager() throws RollerException
+    {
+        if ( mWeblogManager == null ) 
+        {
+            mWeblogManager = new HibernateWeblogManagerImpl(mStrategy);
+        }
+        return mWeblogManager;
+    }
+
+    /** 
+     * @see org.roller.model.Roller#getRefererManager()
+     */
+    public RefererManager getRefererManager() throws RollerException
+    {
+        if ( mRefererManager == null ) 
+        {
+            mRefererManager = new HibernateRefererManagerImpl(mStrategy);
+        }
+        return mRefererManager;
+    }
+
+    /**
+     * @see org.roller.model.Roller#getConfigManager()
+     */
+    public ConfigManager getConfigManager() throws RollerException 
+    {
+        if (mConfigManager == null)
+        {
+            mConfigManager = new HibernateConfigManagerImpl(mStrategy);
+        }
+        return mConfigManager;
+    }
+    
+    /**
+     * @see org.roller.model.Roller#getPropertiesManager()
+     */
+    public PropertiesManager getPropertiesManager() throws RollerException 
+    {
+        if (mPropsManager == null)
+        {
+            mPropsManager = new HibernatePropertiesManagerImpl(mStrategy);
+        }
+        return mPropsManager;
+    }
+
+    /**
+     * @see org.roller.model.Roller#getPingTargetManager()
+     */
+    public PingQueueManager getPingQueueManager() throws RollerException
+    {
+        if (mPingQueueManager == null)
+        {
+            mPingQueueManager = new HibernatePingQueueManagerImpl(mStrategy);
+        }
+        return mPingQueueManager;
+    }
+
+    /**
+     * @see org.roller.model.Roller#getPlanetManager()
+     */
+    public PlanetManager getPlanetManager() throws RollerException
+    {
+        if ( planetManager == null ) 
+        {
+            planetManager = new HibernatePlanetManagerImpl(mStrategy,this);
+        }
+        return planetManager;
+    }
+
+
+    /**
+     * @see org.roller.model.Roller#getPingTargetManager()
+     */
+    public AutoPingManager getAutopingManager() throws RollerException
+    {
+        if (mAutoPingManager == null)
+        {
+            mAutoPingManager = new HibernateAutoPingManagerImpl(mStrategy);
+        }
+        return mAutoPingManager;
+    }
+
+
+    /**
+     * @see org.roller.model.Roller#getPingTargetManager()
+     */
+    public PingTargetManager getPingTargetManager() throws RollerException
+    {
+        if (mPingTargetManager == null)
+        {
+            mPingTargetManager = new HibernatePingTargetManagerImpl(mStrategy);
+        }
+        return mPingTargetManager;
+    }
+
+
+    /**
+     * @see org.roller.model.Roller#getPersistenceStrategy()
+     */
+    public PersistenceStrategy getPersistenceStrategy()
+    {
+        return mStrategy;
+    }
+    
+    /** 
+     * @see org.roller.model.Roller#upgradeDatabase(java.sql.Connection)
+     */
+    public void upgradeDatabase(Connection con) throws RollerException
+    {
+        UpgradeDatabase.upgradeDatabase(con); 
+    }
+
+    public void release()
+    {
+        super.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();
+        
+        try
+        {
+            if (mStrategy != null) mStrategy.release(); 
+        }
+        catch (Exception e)
+        {
+            mLogger.error(
+            "Exception with mSupport.release() [" + e + "]", e);
+        }
+    }
+
+    public void shutdown()
+    {
+        super.shutdown();
+        
+        try
+        {
+            release();
+            mSessionFactory.close();
+        }
+        catch (HibernateException e)
+        {
+            mLogger.error("Unable to close SessionFactory", e);
+        }
+    }
+}

Added: incubator/roller/trunk/src/org/roller/business/hibernate/HibernateStrategy.java
URL: http://svn.apache.org/viewcvs/incubator/roller/trunk/src/org/roller/business/hibernate/HibernateStrategy.java?rev=189695&view=auto
==============================================================================
--- incubator/roller/trunk/src/org/roller/business/hibernate/HibernateStrategy.java (added)
+++ incubator/roller/trunk/src/org/roller/business/hibernate/HibernateStrategy.java Wed Jun  8 20:18:46 2005
@@ -0,0 +1,463 @@
+/*
+ * Created on Mar 7, 2003
+ */
+package org.roller.business.hibernate;
+
+import java.util.List;
+
+import net.sf.hibernate.HibernateException;
+import net.sf.hibernate.ObjectNotFoundException;
+import net.sf.hibernate.Session;
+import net.sf.hibernate.SessionFactory;
+import net.sf.hibernate.type.Type;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.roller.RollerException;
+import org.roller.RollerPermissionsException;
+import org.roller.business.PersistenceStrategy;
+import org.roller.model.PersistenceSession;
+import org.roller.pojos.PersistentObject;
+import org.roller.pojos.UserData;
+
+
+///////////////////////////////////////////////////////////////////////////////
+/**
+ * Reusable Hibernate implementations of CRUD operations.
+ * @author David M Johnson
+ */
+public class HibernateStrategy implements PersistenceStrategy
+{
+    static final long serialVersionUID = 2561090040518169098L;    
+    private static SessionFactory mSessionFactory = null;
+    private static final ThreadLocal mSessionTLS = new ThreadLocal();
+    //private static final ThreadLocal mTransactionTLS = new ThreadLocal();
+
+    private static Log mLogger =
+        LogFactory.getFactory().getInstance(HibernateStrategy.class);
+
+    //-------------------------------------------------------------------------
+    /**
+     * Construct using Hibernate Session Factory.
+     */
+    public HibernateStrategy(SessionFactory factory) throws RollerException
+    {
+        mSessionFactory = factory;
+    }
+
+    //-------------------------------------------------------------------------
+    /** 
+     * Start new Roller persistence session on current thread. 
+     */
+    public void begin(UserData user) throws RollerException
+    {
+        getPersistenceSession(user, true); // force create of new session
+    }
+
+    //-------------------------------------------------------------------------
+    /** 
+     * Start new Roller persistence session on current thread. 
+     */
+    public void setUser(UserData user) throws RollerException
+    {
+        PersistenceSession pses = getPersistenceSession(user, false);
+        pses.setUser(user);
+    }
+
+    //-------------------------------------------------------------------------
+    /** 
+     * Start new Roller persistence session on current thread. 
+     */
+    public UserData getUser() throws RollerException
+    {
+        PersistenceSession pses = getPersistenceSession(null, false);
+        return pses.getUser();
+    }
+
+    //-------------------------------------------------------------------------
+    /** 
+     * Get existing persistence session on current thread. 
+     */
+    public Session getSession() throws RollerException
+    {
+        return (Session)(getPersistenceSession(
+           UserData.ANONYMOUS_USER, false).getSessionObject());
+    }
+    
+    //-------------------------------------------------------------------------
+    /** 
+     * Get existing or open new persistence session for current thread 
+     * @param createNew True if existing session on thread is an warn condition.
+     */
+    public PersistenceSession getPersistenceSession(UserData user, boolean createNew) 
+        throws RollerException
+    {
+        PersistenceSession ses = (PersistenceSession)mSessionTLS.get();
+        if (createNew && ses != null)
+        {
+            mLogger.warn("TLS not empty at beginnng of request");
+            release();
+            ses = null;
+        }
+        if (ses == null && user != null)
+        {
+            try
+            {
+                Session hses = mSessionFactory.openSession();
+                ses = new HibernatePersistenceSession(user, hses);
+            }
+            catch (Exception e)
+            {
+                mLogger.error(Messages.getString(
+                    "HibernateStrategy.exceptionOpeningSession"));
+                throw new RuntimeException();
+            }
+            mSessionTLS.set(ses);
+        }
+        else if (ses == null)
+        {
+            throw new RollerException(
+                "MUST specify user for new persistence session");
+        }
+        return ses;
+    }
+
+    //-------------------------------------------------------------------------
+    /** 
+     * This is called on error to start a new Hibernate session.
+     * Gavin: "make sure you never catch + handle an exception and
+     * then keep using the session (ObjectNotFoundException included!)
+     */
+    private void newSession()  throws RollerException
+    {
+        PersistenceSession pses = getPersistenceSession(null, false);       
+        UserData user = pses.getUser();
+        release();
+        getPersistenceSession(user, true);
+    }
+    
+    //-------------------------------------------------------------------------
+    /** 
+     * Release database session, rolls back any uncommitted changes. 
+     */
+    public void release() throws RollerException
+    {
+        PersistenceSession pses = (PersistenceSession)mSessionTLS.get();
+        if ( null == pses ) return; // there is no session to release
+        mSessionTLS.set(null); // sets thread's session to null
+        Session ses = (Session)pses.getSessionObject();
+        if (ses != null)
+        {
+            try
+            {
+                if (ses.isOpen())
+                {
+                    ses.close();   
+                }               
+            }
+            catch (Throwable he)
+            {
+            	    mLogger.error("ERROR cleaning up Hibernate session", he);
+            }
+        }
+        ses = null;
+    }
+
+    //-------------------------------------------------------------------------
+    /**
+     * Remove object from persistence storage.
+     * @param clazz Class of object to remove.
+     * @param id Id of object to remove.
+     * @throws RollerException Error deleting object.
+     */
+    public void remove( String id, Class clazz ) throws RollerException
+    {
+        if ( id == null )
+        {
+            throw new RollerException(Messages.getString(
+                "HibernateStrategy.nullNotValidId"));
+        }
+        if ( clazz == null )
+        {
+            throw new RollerException(Messages.getString(
+                "HibernateStrategy.nullNotValidClass"));
+        }
+
+        // Create persistent instance and delete it
+        PersistentObject obj;
+        try
+        {
+            obj = (PersistentObject)getSession().load(clazz,id);
+            if (obj.canSave()) 
+            {
+                getSession().delete(obj);
+            }
+            else
+            {
+                throw new RollerPermissionsException("DENIED: cannot remove");
+            }
+        }
+        catch (HibernateException e)
+        {
+            String msg = Messages.formatString(
+                "HibernateStrategy.exceptionRemoving",id,clazz.getName());
+            mLogger.error(msg, e);
+
+            newSession();
+            throw new RollerException(e);
+        }
+    }
+
+    //-------------------------------------------------------------------------
+    /**
+     * Remove object from persistence storage.
+     */
+    public void remove(PersistentObject po) throws RollerException
+    {
+        if (!po.canSave())
+        {
+            throw new RollerPermissionsException(
+                "DENIED: cannot remove: "+po.toString());
+        }
+        try
+        {
+            if (po.getId() != null) // no need to delete transient object
+            {
+                getSession().delete(po);
+            }
+        }
+        catch (HibernateException e)
+        {
+            String msg = Messages.formatString(
+                "HibernateStrategy.exceptionRemoving",po.getId());
+            mLogger.error(msg, e);
+            newSession();
+            throw new RollerException(e);
+        }
+    }
+
+    //-------------------------------------------------------------------------
+    /**
+     * Retrieve object, begins and ends its own transaction.
+     * @param clazz Class of object to retrieve.
+     * @param id Id of object to retrieve.
+     * @return Object Object retrieved.
+     * @throws RollerException Error retrieving object.
+     */
+    public PersistentObject load(String id, Class clazz)
+        throws RollerException
+    {
+        if ( id == null )
+        {
+            throw new RollerException(Messages.getString(
+                "HibernateStrategy.nullNotValidId"));
+        }
+
+        if ( clazz == null )
+        {
+            throw new RollerException(Messages.getString(
+                "HibernateStrategy.nullNotValidClass"));
+        }
+
+        Object obj = null;
+        Session ses = getSession();
+        try
+        {
+            obj = (PersistentObject)ses.load( clazz, id );
+        }
+        catch (Exception e)
+        {
+            if (mLogger.isDebugEnabled())
+            {
+                if (e instanceof ObjectNotFoundException)
+                {
+                    mLogger.debug("No " + clazz.getName() + " found for ID:" + id);
+                }
+                else
+                {
+                    String msg = Messages.formatString(
+                     "HibernateStrategy.exceptionRetrieving", id, clazz.getName());
+                    mLogger.debug(msg, e);
+                }
+            }
+            newSession();
+        }
+        return (PersistentObject)obj;
+    }
+
+    //-------------------------------------------------------------------------
+    /**
+     * Store object using an existing transaction.
+     */
+    public PersistentObject store(PersistentObject obj)
+        throws RollerException
+    {
+        if ( obj == null )
+        {
+            throw new RollerException(Messages.getString(
+                "HibernateStrategy.nullPassedIn"));
+        }
+        if (!obj.canSave())
+        {
+            throw new RollerPermissionsException(
+                "DENIED: cannot save: "+obj.toString());
+        }
+        Session ses = getSession();
+        try
+        {
+            // TODO: better to use ses.saveOrUpdate() here, if possible
+            if ( obj.getId() == null || obj.getId().trim().equals("") )
+            {
+                // Object has never been written to database, so save it.
+                // This makes obj into a persistent instance.
+                ses.save(obj);
+            }
+
+            if ( !ses.contains(obj) )
+            {
+                // Object has been written to database, but instance passed in
+                // is not a persistent instance, so must be loaded into session.
+                PersistentObject vo =
+                    (PersistentObject)ses.load(obj.getClass(),obj.getId());
+                vo.setData(obj);
+                obj = vo;
+            }
+        }
+        catch (HibernateException e)
+        {
+            String msg = Messages.formatString(
+                "HibernateStrategy.exceptionStoring",obj.getId());
+            mLogger.error(msg, e);
+            newSession();
+            throw new RollerException(msg,e);
+        }
+        return obj;
+    }
+
+    //-------------------------------------------------------------------------
+    /** 
+     * Execute Hibernate HSQL query 
+     */
+    public List query( String query, Object[] args, Object[] types)
+        throws RollerException
+    {
+        return query(query, args, (Type[])types);
+    }
+
+    //-------------------------------------------------------------------------
+    /** 
+     * Execute Hibernate HSQL query 
+     */
+    public List query( String query, Object[] args, Type[] types )
+        throws RollerException
+    {
+        if ( query == null )
+          {
+              throw new RollerException(Messages.getString(
+                "HibernateStrategy.nullNotValidQuery"));
+          }
+
+          if ( args == null )
+          {
+              throw new RollerException(Messages.getString(
+                "HibernateStrategy.nullNotValidArgArray"));
+          }
+
+          if ( types == null )
+          {
+              throw new RollerException(Messages.getString(
+                "HibernateStrategy.nullNotValidArrayType"));
+          }
+
+          try
+          {
+              if (query.indexOf("$") > -1)
+              {
+                  query = query.replaceAll("\\$\\d+", "\\?");
+              }
+              return getSession().find(query,args,types);
+          }
+          catch (Exception e)
+          {
+              String msg = Messages.getString("HibernateStrategy.duringQuery");
+              mLogger.error(msg, e);
+              newSession();
+              throw new RollerException(msg,e);
+          }
+    }
+
+    //-------------------------------------------------------------------------
+    /** 
+     * Execute Hibernate HSQL query 
+     */
+    public List query( String query )
+        throws RollerException
+    {
+        try
+        {
+            if (query.indexOf("$") > -1)
+            {
+                query = query.replaceAll("\\$\\d+", "\\?");
+            }
+            return getSession().find(query);
+        }
+        catch (Exception e)
+        {
+            String msg = Messages.getString("HibernateStrategy.duringQuery");
+            mLogger.error(msg, e);
+            newSession();
+            throw new RollerException(msg,e);
+        }
+    }
+
+    //-------------------------------------------------------------------------
+    /** 
+     * Commits current transaction, if there is one, does not release session. 
+     */
+    public void commit() throws RollerException
+    {
+        try
+        {
+            if (mSessionTLS.get()!=null)
+            {
+                getSession().flush();
+
+                // can't call commit when autocommit is true
+                if (!getSession().connection().getAutoCommit())
+                {
+                    getSession().connection().commit();
+                }
+            }
+        }
+        catch (Exception he) // HibernateExeption or SQLException
+        {
+            newSession();
+            throw new RollerException(he);
+        }
+    }
+
+    //-------------------------------------------------------------------------
+    /** 
+     * Rollback uncommitted changes, does not release session. 
+     */
+    public void rollback() throws RollerException
+    {
+        // Can't call rollback when autoCommit=true
+        try
+        {
+            if (!getSession().connection().getAutoCommit())
+            {
+                getSession().connection().rollback();
+            }
+        }
+        catch (Exception he)
+        {
+            newSession();            
+            if (mLogger.isDebugEnabled())
+            {
+                mLogger.debug("ERROR during rollback",he);
+            }
+        }
+    }
+}
+

Added: incubator/roller/trunk/src/org/roller/business/hibernate/HibernateUserManagerImpl.java
URL: http://svn.apache.org/viewcvs/incubator/roller/trunk/src/org/roller/business/hibernate/HibernateUserManagerImpl.java?rev=189695&view=auto
==============================================================================
--- incubator/roller/trunk/src/org/roller/business/hibernate/HibernateUserManagerImpl.java (added)
+++ incubator/roller/trunk/src/org/roller/business/hibernate/HibernateUserManagerImpl.java Wed Jun  8 20:18:46 2005
@@ -0,0 +1,432 @@
+/*
+ * Created on Jun 16, 2004
+ */
+package org.roller.business.hibernate;
+
+import net.sf.hibernate.Criteria;
+import net.sf.hibernate.HibernateException;
+import net.sf.hibernate.Session;
+import net.sf.hibernate.expression.Expression;
+import net.sf.hibernate.expression.EqExpression;
+import net.sf.hibernate.expression.Order;
+
+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.UserManagerImpl;
+import org.roller.model.BookmarkManager;
+import org.roller.model.RollerFactory;
+import org.roller.model.WeblogManager;
+import org.roller.model.AutoPingManager;
+import org.roller.model.PingTargetManager;
+import org.roller.model.PingQueueManager;
+import org.roller.pojos.FolderData;
+import org.roller.pojos.PageData;
+import org.roller.pojos.RefererData;
+import org.roller.pojos.RoleData;
+import org.roller.pojos.UserCookieData;
+import org.roller.pojos.UserData;
+import org.roller.pojos.WeblogCategoryData;
+import org.roller.pojos.WeblogEntryData;
+import org.roller.pojos.WebsiteData;
+import org.roller.util.StringUtils;
+import org.roller.util.Utilities;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+/**
+ * Hibernate queries.
+ * @author David M Johnson
+ */
+public class HibernateUserManagerImpl extends UserManagerImpl
+{
+    static final long serialVersionUID = -5128460637997081121L;
+    
+    private static Log mLogger =
+        LogFactory.getFactory().getInstance(HibernateUserManagerImpl.class);
+    
+    /**
+     * @param strategy
+     */
+    public HibernateUserManagerImpl(PersistenceStrategy strategy)
+    {
+        super(strategy);
+        mLogger.debug("Instantiating User Manager");
+    }
+    
+    /** 
+     * Use Hibernate directly because Roller's Query API does too much allocation.
+     */
+    public PageData getPageByLink(WebsiteData website, String pagelink)
+                    throws RollerException
+    {
+        if (website == null)
+            throw new RollerException("userName is null");
+                                   
+        if (pagelink == null)
+            throw new RollerException("Pagelink is null");
+                                                                      
+        Session session = ((HibernateStrategy)mStrategy).getSession();
+        Criteria criteria = session.createCriteria(PageData.class);
+        criteria.add(Expression.eq("website",website));
+        criteria.add(Expression.eq("link",pagelink));        
+        criteria.setMaxResults(1);
+        try
+        {
+            List list = criteria.list();
+            return list.size()!=0 ? (PageData)list.get(0) : null;
+        }
+        catch (HibernateException e)
+        {
+            throw new RollerException(e);
+        }
+    }
+    
+    /** 
+     * Use Hibernate directly because Roller's Query API does too much allocation.
+     */
+    public WebsiteData getWebsite(String userName, boolean enabledOnly)
+                    throws RollerException
+    {
+        if (userName==null )
+            throw new RollerException("userName is null");
+
+        try
+        {
+            Session session = ((HibernateStrategy)mStrategy).getSession();
+            Criteria criteria = session.createCriteria(WebsiteData.class);
+            criteria.createAlias("user","u");
+    
+            if (enabledOnly) 
+            {
+                criteria.add(
+                   Expression.conjunction()
+                       .add(new EqExpression("u.userName",userName,true))
+                       .add(Expression.eq("isEnabled",Boolean.TRUE)));
+            }
+            else
+            {
+                criteria.add(
+                    Expression.conjunction()
+                       .add(new EqExpression("u.userName",userName,true)));
+            }
+        
+            List list = criteria.list();
+            return list.size()!=0 ? (WebsiteData)list.get(0) : null;
+        }
+        catch (HibernateException e)
+        {
+            throw new RollerException(e);
+        }
+    }
+    
+    /**
+     * @see org.roller.model.UserManager#removeLoginCookies(java.lang.String)
+     */
+    public void removeLoginCookies(String username) throws RollerException
+    {
+        Session session = ((HibernateStrategy)mStrategy).getSession();
+        Criteria criteria = session.createCriteria(UserCookieData.class); 
+        criteria.add(Expression.eq("username", username));        
+        List list;
+        try
+        {
+            list = criteria.list();
+        }
+        catch (HibernateException e)
+        {
+            throw new RollerException(e);
+        }
+        for (Iterator it = list.iterator(); it.hasNext();)
+        {
+            String id = ((UserCookieData) it.next()).getId();
+            mStrategy.remove(id, UserCookieData.class);
+        }        
+    }
+    
+    /**
+     * @see org.roller.model.UserManager#checkLoginCookie(java.lang.String)
+     */
+    public String checkLoginCookie(String value) throws RollerException 
+    {
+        try 
+        {
+            value = Utilities.decodeString(value);
+        } 
+        catch (IOException io) 
+        {
+            mLogger.warn("Failed to decode rememberMe cookieString");
+            return null;
+        }
+        
+        String[] values = StringUtils.split(value, "|");
+
+        if (mLogger.isDebugEnabled()) 
+        {
+            mLogger.debug("looking up cookieId: " + values[1]);
+        }
+
+        Session session = ((HibernateStrategy)mStrategy).getSession();
+        Criteria criteria = session.createCriteria(UserCookieData.class); 
+        criteria.add(Expression.eq("username", values[0]));
+        criteria.add(Expression.eq("cookieId", values[1])); 
+               
+        List list;
+        try
+        {
+            list = criteria.list();
+        }
+        catch (HibernateException e)
+        {
+            throw new RollerException(e);
+        }
+        UserCookieData cookie = (list.size() > 0) ? (UserCookieData)list.get(0) : null;
+
+        if (cookie != null) 
+        {
+            if (mLogger.isDebugEnabled()) 
+            {
+                mLogger.debug("cookieId lookup succeeded, generating new cookieId");
+            }
+            return saveLoginCookie(cookie);
+        } 
+        else 
+        {
+            if (mLogger.isDebugEnabled()) 
+            {
+                mLogger.debug("cookieId lookup failed, returning null");
+            }
+
+            return null;
+        }
+    }
+    
+    //------------------------------------------------------------------------    
+    /** 
+     * @see org.roller.model.UserManager#getPages(WebsiteData)
+     */
+    public List getPages(WebsiteData website) throws RollerException
+    {
+        if (website == null)
+            throw new RollerException("website is null");
+                                                                      
+        Session session = ((HibernateStrategy)mStrategy).getSession();
+        Criteria criteria = session.createCriteria(PageData.class);
+        criteria.add(Expression.eq("website",website)); 
+        criteria.addOrder(Order.asc("name"));
+        try
+        {
+            return criteria.list();
+        }
+        catch (HibernateException e)
+        {
+            throw new RollerException(e);
+        }
+    }
+    
+    /** 
+     * @see org.roller.model.UserManager#getPageByName(WebsiteData, java.lang.String)
+     */
+    public PageData getPageByName(WebsiteData website, String pagename) 
+        throws RollerException
+    {
+        if (website == null)
+            throw new RollerException("website is null");
+                                   
+        if (pagename == null)
+            throw new RollerException("Page name is null");
+                                   
+        Session session = ((HibernateStrategy)mStrategy).getSession();
+        Criteria criteria = session.createCriteria(PageData.class);
+        criteria.add(Expression.eq("website", website));
+        criteria.add(Expression.eq("name", pagename));
+        criteria.setMaxResults(1);
+        try
+        {
+            List list = criteria.list();
+            return list.size()!=0 ? (PageData)list.get(0) : null;
+        }
+        catch (HibernateException e)
+        {
+            throw new RollerException(e);
+        }
+    }
+    
+    /* 
+     * @see org.roller.business.UserManagerBase#getRoles(org.roller.pojos.UserData)
+     */
+    public List getUserRoles(UserData user) throws RollerException
+    {
+        
+        Session session = ((HibernateStrategy)mStrategy).getSession();
+        Criteria criteria = session.createCriteria(RoleData.class);
+        criteria.add(Expression.eq("user", user));
+        try
+        {
+            return criteria.list();
+        }
+        catch (HibernateException e)
+        {
+            throw new RollerException(e);
+        }
+    }
+
+    public List getUsers(boolean enabledOnly) throws RollerException
+    {
+        Session session = ((HibernateStrategy)mStrategy).getSession();
+        if (enabledOnly)
+        {
+            Criteria criteria = session.createCriteria(WebsiteData.class);            
+            criteria.add(Expression.eq("isEnabled", Boolean.TRUE));
+            try
+            {
+                List users = new ArrayList();
+                Iterator websites = criteria.list().iterator();
+                while (websites.hasNext())
+                {
+                    WebsiteData website = (WebsiteData) websites.next();
+                    users.add(website.getUser());
+                }
+                return users;
+            }
+            catch (HibernateException e)
+            {
+                throw new RollerException(e);
+            }
+        }
+        else
+        {
+            Criteria criteria = session.createCriteria(UserData.class);            
+            try
+            {
+                return criteria.list();
+            }
+            catch (HibernateException e)
+            {
+                throw new RollerException(e);
+            }
+        }
+    }
+
+    /** 
+     * @see org.roller.model.UserManager#removeUserWebsites(org.roller.pojos.UserData)
+     */
+    public void removeUserWebsites(UserData user) throws RollerException
+    {
+        Session session = ((HibernateStrategy)mStrategy).getSession();
+        Criteria criteria = session.createCriteria(WebsiteData.class);
+        criteria.add(Expression.eq("user", user));
+        try
+        {
+            List websites = criteria.list();
+            for (Iterator iter = websites.iterator(); iter.hasNext();) 
+            {
+                WebsiteData website = (WebsiteData)iter.next();
+                website.remove();
+            }            
+        }
+        catch (HibernateException e)
+        {
+            throw new RollerException(e);
+        }
+    }
+
+    /** 
+     * @see org.roller.model.UserManager#removeWebsiteContents(org.roller.pojos.WebsiteData)
+     */
+    public void removeWebsiteContents(WebsiteData website) 
+        throws RollerException
+    {
+        try
+        {
+            Session session = ((HibernateStrategy)mStrategy).getSession();
+
+            //UserManager umgr = RollerFactory.getRoller().getUserManager();
+            BookmarkManager bmgr = RollerFactory.getRoller().getBookmarkManager();
+            WeblogManager wmgr = RollerFactory.getRoller().getWeblogManager();
+            //PersistenceStrategy pstrat = RollerFactory.getRoller().getPersistenceStrategy();
+            //QueryFactory factory = pstrat.getQueryFactory();
+            
+            // remove folders (takes bookmarks with it)
+            FolderData rootFolder = bmgr.getRootFolder(website);
+            if (null != rootFolder)
+            { 
+                rootFolder.remove();
+                // Still cannot get all Bookmarks cleared!                
+//                Iterator allFolders = bmgr.getAllFolders(website).iterator();
+//                while (allFolders.hasNext()) 
+//                {
+//                    FolderData aFolder = (FolderData)allFolders.next();
+//                    bmgr.deleteFolderContents(aFolder);
+//                    aFolder.remove();
+//                }
+            }
+                        
+            // remove entries
+            Criteria entryQuery = session.createCriteria(WeblogEntryData.class);
+            entryQuery.add(Expression.eq("website", website));
+            List entries = entryQuery.list();
+            for (Iterator iter = entries.iterator(); iter.hasNext();) 
+            {
+                WeblogEntryData entry = (WeblogEntryData) iter.next();
+                entry.remove();
+            }
+            
+            // remove associated pages
+            Criteria pageQuery = session.createCriteria(PageData.class);
+            pageQuery.add(Expression.eq("website", website));
+            List pages = pageQuery.list();
+            for (Iterator iter = pages.iterator(); iter.hasNext();) 
+            {
+                PageData page = (PageData) iter.next();
+                page.remove();
+            }
+            
+            // remove associated referers
+            Criteria refererQuery = session.createCriteria(RefererData.class);
+            refererQuery.add(Expression.eq("website", website));
+            List referers = refererQuery.list();
+            for (Iterator iter = referers.iterator(); iter.hasNext();) 
+            {
+                RefererData referer = (RefererData) iter.next();
+                referer.remove();
+            }
+            
+            // remove categories
+            WeblogCategoryData rootCat = wmgr.getRootWeblogCategory(website);
+            if (null != rootCat)
+            {
+                rootCat.remove();
+                Iterator it = wmgr.getWeblogCategories(website).iterator();
+                while (it.hasNext()) 
+                {
+                     ((WeblogCategoryData)it.next()).remove();
+                }
+            }
+
+            // Remove the website's ping queue entries
+            PingQueueManager pingQueueMgr = RollerFactory.getRoller().getPingQueueManager();
+            pingQueueMgr.removeQueueEntriesByWebsite(website);
+
+            // Remove the website's custom ping targets
+            PingTargetManager pingTargetMgr = RollerFactory.getRoller().getPingTargetManager();
+            pingTargetMgr.removeCustomPingTargets(website);
+
+            // Remove the website's auto ping configurations
+            AutoPingManager autoPingMgr = RollerFactory.getRoller().getAutopingManager();
+            List autopings = autoPingMgr.getAutoPingsByWebsite(website);
+            autoPingMgr.removeAutoPings(autopings);
+
+        }
+        catch (HibernateException e)
+        {
+            throw new RollerException(e);
+        }
+    }
+
+}
+

Added: incubator/roller/trunk/src/org/roller/business/hibernate/HibernateWeblogManagerImpl.java
URL: http://svn.apache.org/viewcvs/incubator/roller/trunk/src/org/roller/business/hibernate/HibernateWeblogManagerImpl.java?rev=189695&view=auto
==============================================================================
--- incubator/roller/trunk/src/org/roller/business/hibernate/HibernateWeblogManagerImpl.java (added)
+++ incubator/roller/trunk/src/org/roller/business/hibernate/HibernateWeblogManagerImpl.java Wed Jun  8 20:18:46 2005
@@ -0,0 +1,807 @@
+/*
+ * Created on Jun 16, 2004
+ */
+package org.roller.business.hibernate;
+
+import net.sf.hibernate.Criteria;
+import net.sf.hibernate.HibernateException;
+import net.sf.hibernate.Session;
+import net.sf.hibernate.expression.Expression;
+import net.sf.hibernate.expression.Junction;
+import net.sf.hibernate.expression.Order;
+
+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.WeblogManagerImpl;
+import org.roller.model.Roller;
+import org.roller.model.RollerFactory;
+import org.roller.pojos.Assoc;
+import org.roller.pojos.CommentData;
+import org.roller.pojos.RefererData;
+import org.roller.pojos.WeblogCategoryAssoc;
+import org.roller.pojos.WeblogCategoryData;
+import org.roller.pojos.WeblogEntryData;
+import org.roller.pojos.WebsiteData;
+import org.roller.util.StringUtils;
+
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.List;
+
+/**
+ * Hibernate queries.
+ * @author David M Johnson
+ */
+public class HibernateWeblogManagerImpl extends WeblogManagerImpl
+{
+    static final long serialVersionUID = -3730860865389981439L;
+    
+    private static Log mLogger =
+        LogFactory.getFactory().getInstance(HibernateWeblogManagerImpl.class);
+
+    /**
+     * @param strategy
+     * @param roller
+     */
+    public HibernateWeblogManagerImpl(PersistenceStrategy strategy)
+    {
+        super(strategy);
+        mLogger.debug("Instantiating Weblog Manager");
+    }
+    
+    public List getComments(String entryId, boolean nospam) throws RollerException
+    {
+        if (entryId == null)
+            throw new RollerException("entryId is null");
+
+        try
+        {
+            Session session = ((HibernateStrategy)mStrategy).getSession();
+            Criteria criteria = session.createCriteria(CommentData.class);
+            criteria.createAlias("weblogEntry","e");
+            criteria.add(Expression.eq("e.id", entryId));
+            if (nospam)
+            {
+                criteria.add(
+                    Expression.not(Expression.eq("spam", Boolean.TRUE)));
+            }
+            criteria.addOrder(Order.asc("postTime"));            
+            return criteria.list();
+        }
+        catch (HibernateException e)
+        {
+            throw new RollerException(e);
+        }
+    }
+
+
+    /* 
+     * @see org.roller.model.WeblogManager#getNextEntry(org.roller.pojos.WeblogEntryData)
+     */
+    public List getNextPrevEntries(
+            WeblogEntryData current, String catName, int maxEntries, boolean next)
+        throws RollerException
+    {
+        if (catName != null && catName.trim().equals("/"))
+        {
+            catName = null;
+        }
+        Junction conjunction = Expression.conjunction();        
+        conjunction.add(Expression.eq("website", current.getWebsite()));
+        conjunction.add(Expression.eq("publishEntry", Boolean.TRUE));
+        
+        if (next)
+        {
+            conjunction.add(Expression.gt("pubTime", current.getPubTime()));
+        }
+        else
+        {
+            conjunction.add(Expression.lt("pubTime", current.getPubTime()));
+        }
+        
+        if (catName != null)
+        {
+            WeblogCategoryData category = 
+                getWeblogCategoryByPath(current.getWebsite(), null, catName);
+            if (category != null)
+            {
+                conjunction.add(Expression.eq("category", category));
+            }
+            else
+            {
+                throw new RollerException("Cannot find category: "+catName);
+            }
+        }
+
+        try
+        {
+            Session session = ((HibernateStrategy)mStrategy).getSession();
+            Criteria criteria = session.createCriteria(WeblogEntryData.class);
+            criteria.addOrder(Order.desc("pubTime"));
+            criteria.add(conjunction);
+            criteria.setMaxResults(maxEntries);
+            List results = criteria.list();
+            return results;
+        }
+        catch (HibernateException e)
+        {
+            throw new RollerException(e);
+        }
+    }
+    
+    /**
+     * @see org.roller.model.WeblogManager#getRootWeblogCategory(org.roller.pojos.WebsiteData)
+     */
+    public WeblogCategoryData getRootWeblogCategory(WebsiteData website)
+        throws RollerException
+    {
+        if (website == null)
+            throw new RollerException("website is null");
+
+        try
+        {
+            Session session = ((HibernateStrategy)mStrategy).getSession();
+            Criteria criteria = session.createCriteria(WeblogCategoryAssoc.class);
+            criteria.createAlias("category","c");
+            
+            criteria.add(Expression.eq("c.website", website));
+            criteria.add(Expression.isNull("ancestorCategory"));
+            criteria.add(Expression.eq("relation", WeblogCategoryAssoc.PARENT));
+            
+            criteria.setMaxResults(1);    
+            
+            List list = criteria.list();
+            return ((WeblogCategoryAssoc)list.get(0)).getCategory();
+        }
+        catch (HibernateException e)
+        {
+            throw new RollerException(e);
+        }
+    }
+    
+    /** 
+     * @see org.roller.model.WeblogManager#getWeblogCategories(
+     * org.roller.pojos.WebsiteData, boolean)
+     */
+    public List getWeblogCategories(WebsiteData website, boolean includeRoot) 
+        throws RollerException
+    {
+        if (website == null)
+            throw new RollerException("website is null");
+        
+        if (includeRoot) return getWeblogCategories(website);
+
+        try
+        {
+            Session session = ((HibernateStrategy)mStrategy).getSession();
+            Criteria criteria = session.createCriteria(WeblogCategoryAssoc.class); 
+            criteria.createAlias("category", "c");
+            criteria.add(Expression.eq("c.website", website));
+            criteria.add(Expression.isNotNull("ancestorCategory"));
+            criteria.add(Expression.eq("relation", "PARENT"));
+            Iterator assocs = criteria.list().iterator();
+            List cats = new ArrayList();
+            while (assocs.hasNext())
+            {
+                WeblogCategoryAssoc assoc = (WeblogCategoryAssoc) assocs.next();
+                cats.add(assoc.getCategory());
+            }
+            return cats;
+        }
+        catch (HibernateException e)
+        {
+            throw new RollerException(e);
+        }
+    }
+    
+    public List getWeblogCategories(WebsiteData website) throws RollerException
+    {
+        if (website == null)
+            throw new RollerException("website is null");
+
+        try
+        {
+            Session session = ((HibernateStrategy)mStrategy).getSession();
+            Criteria criteria = session.createCriteria(WeblogCategoryData.class);            
+            criteria.add(Expression.eq("website", website));            
+            return criteria.list();
+        }
+        catch (HibernateException e)
+        {
+            throw new RollerException(e);
+        }
+    }
+    
+    /** 
+     * @see org.roller.model.WeblogManager#getWeblogEntries(
+     * java.lang.String, 
+     * java.util.Date, 
+     * java.util.Date, 
+     * java.lang.String, 
+     * java.lang.String, 
+     * java.lang.Integer)
+     */
+    public List getWeblogEntries(
+                    WebsiteData website, 
+                    Date    startDate, 
+                    Date    endDate, 
+                    String  catName, 
+                    String  status, 
+                    Integer maxEntries,
+                    Boolean pinned) throws RollerException
+    {
+        WeblogCategoryData cat = null;        
+        if (StringUtils.isNotEmpty(catName) && website != null)
+        {    
+           cat = getWeblogCategoryByPath(website, catName);
+           if (cat == null) catName = null;
+        }
+        if (catName != null && catName.trim().equals("/"))
+        {
+            catName = null;
+        }
+                    
+        try
+        {
+            Session session = ((HibernateStrategy)mStrategy).getSession();
+            Criteria criteria = session.createCriteria(WeblogEntryData.class);
+            
+            if (website != null)
+            {
+                criteria.add(Expression.eq("website", website));
+            }
+            else 
+            {
+                criteria.createAlias("website","w");
+                criteria.add(Expression.eq("w.isEnabled", Boolean.TRUE));
+            }
+    
+            if (startDate != null)
+            {
+                criteria.add(
+                    Expression.ge("pubTime", startDate));
+            }
+            
+            if (endDate != null)
+            {
+                criteria.add(
+                    Expression.le("pubTime", endDate));
+            }
+                            
+            if (cat != null && website != null)
+            {
+                criteria.add(Expression.eq("category", cat));
+            }
+            
+            if (status != null && status.equals(DRAFT_ONLY))
+            {
+                criteria.add(
+                    Expression.eq("publishEntry", Boolean.FALSE));
+            }        
+            else if (status != null && status.equals(PUB_ONLY))
+            {
+                criteria.add(
+                    Expression.eq("publishEntry", Boolean.TRUE));
+            }
+
+            if (pinned != null)
+            {
+                criteria.add(Expression.eq("pinnedToMain", pinned));
+            }
+                            
+            criteria.addOrder(Order.desc("pubTime"));
+            
+            if (maxEntries != null) 
+            {
+                criteria.setMaxResults(maxEntries.intValue());
+            }            
+            return criteria.list();
+        }
+        catch (HibernateException e)
+        {
+            mLogger.error(e);
+            throw new RollerException(e);
+        }
+    }
+    
+    /** 
+     * Use Hibernate directly because Roller's Query API does too much allocation.
+     */
+    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");
+
+        Session session = ((HibernateStrategy)mStrategy).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);
+        try
+        {
+            List list = criteria.list();
+            return list.size()!=0 ? (WeblogEntryData)list.get(0) : null;
+        }
+        catch (HibernateException e)
+        {
+            throw new RollerException(e);
+        }
+    }
+    /**
+     * Gets the Date of the latest Entry publish time.
+     *
+     * @param userName User name of weblog or null for all users
+     * @param catName Category name of posts or null for all categories
+     * @return Date Of last publish time
+     * @throws RollerException
+     */
+    public Date getWeblogLastPublishTime( String userName, String catName )
+        throws RollerException
+    {
+        WeblogCategoryData cat = null;
+        Roller mRoller = RollerFactory.getRoller();
+        if (userName != null) 
+        {
+            WebsiteData website = mRoller.getUserManager().getWebsite(userName);
+            if (catName != null && website != null)
+            {    
+               cat = getWeblogCategoryByPath(website, null, catName);
+               if (cat == null) catName = null;
+            }
+            if (catName != null && catName.trim().equals("/"))
+            {
+                catName = null;
+            }
+        }
+        
+        Session session = ((HibernateStrategy)mStrategy).getSession();
+        Criteria criteria = session.createCriteria(WeblogEntryData.class);
+        criteria.add(Expression.eq("publishEntry", Boolean.TRUE));
+        criteria.add(Expression.le("pubTime", new Date()));
+
+        try
+        {
+            if ( userName != null )
+            {
+                WebsiteData website = mRoller.getUserManager().getWebsite(userName);
+                criteria.add(Expression.eq("website", website));
+            }
+
+            if ( cat != null )
+            {
+                criteria.add(Expression.eq("category", cat));
+            }
+            
+            criteria.addOrder(Order.desc("pubTime"));
+            criteria.setMaxResults(1);        
+            List list = criteria.list();
+            if (list.size() > 0)
+            {
+                return ((WeblogEntryData)list.get(0)).getPubTime();
+            }
+            else
+            {
+                return null;
+            }
+        }
+        catch (HibernateException e)
+        {
+            throw new RollerException(e);
+        }
+    }
+
+    public void moveWeblogCategoryContents(String srcId, String destId)
+        throws RollerException
+    {
+        WeblogCategoryData srcCd =
+            (WeblogCategoryData) mStrategy.load(
+                srcId, WeblogCategoryData.class);
+        
+        WeblogCategoryData destCd =
+            (WeblogCategoryData) mStrategy.load(
+                destId, WeblogCategoryData.class);
+        
+        if (destCd.descendentOf(srcCd))
+        {
+            throw new RollerException(
+                    "ERROR cannot move parent category into it's own child");
+        }
+        
+        // get all entries in category and subcats
+        List results = retrieveWeblogEntries(srcCd, true);    
+
+        // Loop through entries in src cat, assign them to dest cat
+        Iterator iter = results.iterator();
+        WebsiteData website = destCd.getWebsite();
+        while (iter.hasNext())
+        {
+            WeblogEntryData entry = (WeblogEntryData) iter.next();
+            entry.setCategory(destCd);
+            entry.setWebsite(website);
+            entry.save();
+        }
+        
+        // Make sure website's default and bloggerapi categories 
+        // are valid after the move
+        
+        if (srcCd.getWebsite().getDefaultCategory().getId().equals(srcId)
+            || srcCd.getWebsite().getDefaultCategory().descendentOf(srcCd)) 
+        {
+            srcCd.getWebsite().setDefaultCategory(destCd);
+        }
+        
+        if (srcCd.getWebsite().getBloggerCategory().getId().equals(srcId)
+            || srcCd.getWebsite().getBloggerCategory().descendentOf(srcCd)) 
+        {
+            srcCd.getWebsite().setBloggerCategory(destCd);
+        }
+    }
+    
+    public List retrieveWeblogEntries(WeblogCategoryData cat, boolean subcats) 
+        throws RollerException
+    {                
+        try
+        {
+            Session session = ((HibernateStrategy)mStrategy).getSession();
+            List entries = new LinkedList();
+            
+            if (subcats)
+            {   
+                // Get entries in subcategories
+                Criteria assocsQuery = 
+                    session.createCriteria(WeblogCategoryAssoc.class);
+                assocsQuery.add(Expression.eq("ancestorCategory", cat));                
+                Iterator assocs = assocsQuery.list().iterator();                
+                while (assocs.hasNext())
+                {
+                    WeblogCategoryAssoc assoc = (WeblogCategoryAssoc)assocs.next();
+                    Criteria entriesQuery = 
+                        session.createCriteria(WeblogEntryData.class);
+                    entriesQuery.add(
+                        Expression.eq("category", assoc.getCategory()));
+                    Iterator entryIter = entriesQuery.list().iterator();
+                    while (entryIter.hasNext())
+                    {
+                        WeblogEntryData entry = (WeblogEntryData)entryIter.next();
+                        entries.add(entry);
+                    }
+                }                
+            }
+            
+            // Get entries in category
+            Criteria entriesQuery = 
+                session.createCriteria(WeblogEntryData.class);
+            entriesQuery.add(Expression.eq("category", cat));                
+            Iterator entryIter = entriesQuery.list().iterator();
+            while (entryIter.hasNext())
+            {
+                WeblogEntryData entry = (WeblogEntryData)entryIter.next();
+                entries.add(entry);
+            }
+            return entries;
+        }
+        catch (HibernateException e)
+        {
+            throw new RollerException(e);
+        }
+    }
+
+    /** 
+     * @see org.roller.model.WeblogManager#removeWeblogEntryContents(
+     * org.roller.pojos.WeblogEntryData)
+     */
+    public void removeWeblogEntryContents(WeblogEntryData entry) 
+        throws RollerException
+    {        
+        try
+        {
+            Session session = ((HibernateStrategy)mStrategy).getSession();
+            
+            // remove referers
+            Criteria refererQuery = session.createCriteria(RefererData.class);
+            refererQuery.add(Expression.eq("weblogEntry", entry));
+            List entries = refererQuery.list();
+            for (Iterator iter = entries.iterator(); iter.hasNext();) 
+            {
+                RefererData referer = (RefererData) iter.next();
+                referer.remove();
+            }
+            
+            // remove comments
+            /*
+            Criteria commentQuery = session.createCriteria(RefererData.class);
+            commentQuery.add(Expression.eq("weblogEntry", entry));
+            List comments = commentQuery.list();
+            */
+            List comments = RollerFactory.getRoller().getWeblogManager().getComments(entry.getId(), false);
+            for (Iterator iter = comments.iterator(); iter.hasNext();) 
+            {
+                CommentData comment = (CommentData) iter.next();
+                comment.remove();
+            }
+        }
+        catch (HibernateException e)
+        {
+            throw new RollerException(e);
+        }
+    }
+
+    /** 
+     * @see org.roller.model.WeblogManager#createAnchor(
+     * org.roller.pojos.WeblogEntryData)
+     */
+    public String createAnchor(WeblogEntryData entry) throws RollerException
+    {        
+        try
+        {
+            // Check for uniqueness of anchor
+            String base = entry.createAnchorBase();
+            String name = base;
+            int count = 0;
+
+            while (true)
+            {
+                if (count > 0)
+                {
+                    name = base + count;
+                }
+                
+                Session session = ((HibernateStrategy)mStrategy).getSession();
+                Criteria criteria = session.createCriteria(WeblogEntryData.class);
+                criteria.add(Expression.eq("website", entry.getWebsite()));
+                criteria.add(Expression.eq("anchor", name));
+                             
+                List results = criteria.list();
+                
+                if (results.size() < 1)
+                {
+                    break;
+                }
+                else
+                {
+                    count++;
+                }
+            }
+            return name;
+        }
+        catch (HibernateException e)
+        {
+            throw new RollerException(e);
+        }
+    }
+
+    /** 
+     * @see org.roller.model.WeblogManager#checkWeblogCategoryName(org.roller.pojos.WeblogCategoryData)
+     */
+    public boolean isDuplicateWeblogCategoryName(WeblogCategoryData cat) 
+        throws RollerException
+    {        
+        // ensure that no sibling categories share the same name
+        WeblogCategoryData parent = 
+            null == cat.getId() ? (WeblogCategoryData)cat.getNewParent() : cat.getParent();
+           
+        if (null != parent) // don't worry about root
+        {
+            List sameNames;
+            try
+            {
+                Session session = ((HibernateStrategy)mStrategy).getSession();
+                Criteria criteria = session.createCriteria(WeblogCategoryAssoc.class);
+                criteria.createAlias("category", "c");
+                criteria.add(Expression.eq("c.name", cat.getName()));
+                criteria.add(Expression.eq("ancestorCategory", parent));
+                criteria.add(Expression.eq("relation", Assoc.PARENT));
+                sameNames = criteria.list();
+            }
+            catch (HibernateException e)
+            {
+                throw new RollerException(e);        
+            }
+            if (sameNames.size() > 1) 
+            {
+                return true;        
+            }           
+        }
+        return false;
+    }
+
+    /** 
+     * @see org.roller.model.WeblogManager#isWeblogCategoryInUse(org.roller.pojos.WeblogCategoryData)
+     */
+    public boolean isWeblogCategoryInUse(WeblogCategoryData cat) 
+        throws RollerException
+    {
+        try
+        {
+            Session session = ((HibernateStrategy)mStrategy).getSession();
+            Criteria criteria = session.createCriteria(WeblogEntryData.class);
+            criteria.add(Expression.eq("category", cat));   
+            criteria.setMaxResults(1); 
+            int entryCount = criteria.list().size();
+            
+            if (entryCount > 0)
+            {
+                return true;
+            }
+            
+            Iterator cats = cat.getWeblogCategories().iterator();
+            while (cats.hasNext())
+            {
+                WeblogCategoryData childCat = (WeblogCategoryData)cats.next();
+                if (childCat.isInUse())
+                {
+                    return true;
+                }
+            }
+            
+            if (cat.getWebsite().getBloggerCategory().equals(cat))
+            {
+                return true;
+            }
+            
+            if (cat.getWebsite().getDefaultCategory().equals(cat))
+            {
+                return true;
+            }
+            
+            return false;
+        }
+        catch (HibernateException e)
+        {
+            throw new RollerException(e);
+        }
+    }
+
+    public boolean isDescendentOf(
+            WeblogCategoryData child, WeblogCategoryData ancestor)
+            throws RollerException
+    {
+        boolean ret = false;
+        try
+        {
+            Session session = ((HibernateStrategy)mStrategy).getSession();
+            Criteria criteria = session.createCriteria(WeblogCategoryAssoc.class);
+            criteria.add(Expression.eq("category", child));
+            criteria.add(Expression.eq("ancestorCategory", ancestor));
+            ret = criteria.list().size() > 0;
+        }
+        catch (HibernateException e)
+        {
+            throw new RollerException(e);        
+        }
+        return ret;
+    }
+    
+    /** 
+     * @see org.roller.model.WeblogManager#getWeblogCategoryParentAssoc(
+     * org.roller.pojos.WeblogCategoryData)
+     */
+    public Assoc getWeblogCategoryParentAssoc(WeblogCategoryData cat) 
+        throws RollerException
+    {
+        try
+        {
+            Session session = ((HibernateStrategy)mStrategy).getSession();
+            Criteria criteria = session.createCriteria(WeblogCategoryAssoc.class);
+            criteria.add(Expression.eq("category", cat));
+            criteria.add(Expression.eq("relation", Assoc.PARENT));
+            List parents = criteria.list();
+            if (parents.size() > 1)
+            {
+                throw new RollerException("ERROR: more than one parent");
+            }
+            else if (parents.size() == 1)
+            {
+                return (Assoc) parents.get(0);
+            }
+            else
+            {
+                return null;
+            }
+        }
+        catch (HibernateException e)
+        {
+            throw new RollerException(e);
+        }
+    }
+
+    /** 
+     * @see org.roller.model.WeblogManager#getWeblogCategoryChildAssocs(
+     * org.roller.pojos.WeblogCategoryData)
+     */
+    public List getWeblogCategoryChildAssocs(WeblogCategoryData cat) 
+        throws RollerException
+    {
+        try
+        {
+            Session session = ((HibernateStrategy)mStrategy).getSession();
+            Criteria criteria = session.createCriteria(WeblogCategoryAssoc.class);
+            criteria.add(Expression.eq("ancestorCategory", cat));
+            criteria.add(Expression.eq("relation", Assoc.PARENT));
+            return criteria.list();
+        }
+        catch (HibernateException e)
+        {
+            throw new RollerException(e);
+        }
+    }
+
+    /** 
+     * @see org.roller.model.WeblogManager#getAllWeblogCategoryDecscendentAssocs(
+     * org.roller.pojos.WeblogCategoryData)
+     */
+    public List getAllWeblogCategoryDecscendentAssocs(WeblogCategoryData cat) 
+        throws RollerException
+    {
+        try
+        {
+            Session session = ((HibernateStrategy)mStrategy).getSession();
+            Criteria criteria = session.createCriteria(WeblogCategoryAssoc.class);
+            criteria.add(Expression.eq("ancestorCategory", cat));
+            return criteria.list();
+        }
+        catch (HibernateException e)
+        {
+            throw new RollerException(e);
+        }
+    }
+
+    /** 
+     * @see org.roller.model.WeblogManager#getWeblogCategoryAncestorAssocs(org.roller.pojos.WeblogCategoryData)
+     */
+    public List getWeblogCategoryAncestorAssocs(WeblogCategoryData cat) 
+        throws RollerException
+    {
+        try
+        {
+            Session session = ((HibernateStrategy)mStrategy).getSession();
+            Criteria criteria = session.createCriteria(WeblogCategoryAssoc.class);
+            criteria.add(Expression.eq("category", cat));
+            return criteria.list();
+        }
+        catch (HibernateException e)
+        {
+            throw new RollerException(e);
+        }
+    }
+    
+    /**
+     * Get the maxCount most recent non-spam Comments.  If a Website is presented 
+     * only Comments for that site will be returned.
+     * 
+     * @author lance.lavandowska
+     */
+    public List getRecentComments(WebsiteData website, int maxCount) throws RollerException
+    {
+        try
+        {
+            Session session = ((HibernateStrategy)mStrategy).getSession();
+            Criteria criteria = session.createCriteria(CommentData.class);
+            criteria.add( /* no spam ! */
+                Expression.not(Expression.eq("spam", Boolean.TRUE)));
+            if (website != null) 
+            {
+                criteria.createAlias("weblogEntry","e");
+                criteria.add(Expression.eq("e.website", website));
+            }
+            criteria.addOrder(Order.desc("postTime"));
+            criteria.setMaxResults(maxCount); 
+            return criteria.list();
+        }
+        catch (HibernateException e)
+        {
+            throw new RollerException(e);
+        }        
+    }
+
+}

Added: incubator/roller/trunk/src/org/roller/business/hibernate/Messages.java
URL: http://svn.apache.org/viewcvs/incubator/roller/trunk/src/org/roller/business/hibernate/Messages.java?rev=189695&view=auto
==============================================================================
--- incubator/roller/trunk/src/org/roller/business/hibernate/Messages.java (added)
+++ incubator/roller/trunk/src/org/roller/business/hibernate/Messages.java Wed Jun  8 20:18:46 2005
@@ -0,0 +1,49 @@
+/*
+ * Created on Sep 14, 2003
+ */
+package org.roller.business.hibernate;
+
+import java.text.MessageFormat;
+import java.util.MissingResourceException;
+import java.util.ResourceBundle;
+
+/**
+ * @author dmj
+ */
+public class Messages
+{
+
+    private static final String BUNDLE_NAME = 
+        "org.roller.business.hibernate.messages"; //$NON-NLS-1$
+
+    private static final ResourceBundle RESOURCE_BUNDLE =
+        ResourceBundle.getBundle(BUNDLE_NAME);
+
+    private Messages()
+    {
+    }
+    
+    public static String formatString(String key, String[] args) {
+        return MessageFormat.format(getString(key), (Object[])args);    
+    }
+    
+    public static String formatString(String key, String arg0, String arg1) {
+        return MessageFormat.format(getString(key), (Object[])new String[]{arg0,arg1});            
+    }
+    
+    public static String formatString(String key, String arg) {
+        return MessageFormat.format(getString(key), (Object[])new String[]{arg});            
+    }
+    
+    public static String getString(String key)
+    {
+        try
+        {
+            return RESOURCE_BUNDLE.getString(key);
+        }
+        catch (MissingResourceException e)
+        {
+            return '!' + key + '!';
+        }
+    }
+}

Added: incubator/roller/trunk/src/org/roller/business/hibernate/messages.properties
URL: http://svn.apache.org/viewcvs/incubator/roller/trunk/src/org/roller/business/hibernate/messages.properties?rev=189695&view=auto
==============================================================================
--- incubator/roller/trunk/src/org/roller/business/hibernate/messages.properties (added)
+++ incubator/roller/trunk/src/org/roller/business/hibernate/messages.properties Wed Jun  8 20:18:46 2005
@@ -0,0 +1,21 @@
+
+HibernateStrategy.openedSession=OPENED session:  
+HibernateStrategy.closedSession=OPENED session:  
+
+HibernateStrategy.exceptionOpeningSession=EXCEPTION opening session
+HibernateStrategy.exceptionClosingSession=EXCEPTION closing session
+
+HibernateStrategy.exceptionStoring=EXCEPTION storing object, id={0}, class={1}
+HibernateStrategy.exceptionRetrieving=EXCEPTION retrieving object, id={0}, class={1}
+HibernateStrategy.exceptionRemoving=EXCEPTION removing object, id={0}, class={1}
+
+HibernateStrategy.duringQuery=During QUERY
+
+HibernateStrategy.nullNotValidId=NULL is not a valid id
+HibernateStrategy.nullNotValidClass=NULL is not a valid class
+HibernateStrategy.nullNotValidQuery=NULL is not a valid query
+HibernateStrategy.nullNotValidArgArray=NULL is not a valid arg array
+HibernateStrategy.nullNotValidArrayType=NULL is not a valid type array
+
+HibernateStrategy.nullPassedIn=NULL passed into storeValueObject()
+

Added: incubator/roller/trunk/src/org/roller/business/hibernate/package.html
URL: http://svn.apache.org/viewcvs/incubator/roller/trunk/src/org/roller/business/hibernate/package.html?rev=189695&view=auto
==============================================================================
--- incubator/roller/trunk/src/org/roller/business/hibernate/package.html (added)
+++ incubator/roller/trunk/src/org/roller/business/hibernate/package.html Wed Jun  8 20:18:46 2005
@@ -0,0 +1,9 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
+<html>
+<head>
+  <title></title>
+</head>
+<body>
+Hibernate implementation of the Roller backend.
+</body>
+</html>

Added: incubator/roller/trunk/src/org/roller/business/package.html
URL: http://svn.apache.org/viewcvs/incubator/roller/trunk/src/org/roller/business/package.html?rev=189695&view=auto
==============================================================================
--- incubator/roller/trunk/src/org/roller/business/package.html (added)
+++ incubator/roller/trunk/src/org/roller/business/package.html Wed Jun  8 20:18:46 2005
@@ -0,0 +1,11 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
+<html>
+<head>
+  <title></title>
+</head>
+<body>
+Abstract implementation of the Roller backend interfaces defined in the
+org.roller.model package. The Roller presentation layer should not use
+any of the org.roller.business.* classes directly.
+</body>
+</html>

Added: incubator/roller/trunk/src/org/roller/business/search/FieldConstants.java
URL: http://svn.apache.org/viewcvs/incubator/roller/trunk/src/org/roller/business/search/FieldConstants.java?rev=189695&view=auto
==============================================================================
--- incubator/roller/trunk/src/org/roller/business/search/FieldConstants.java (added)
+++ incubator/roller/trunk/src/org/roller/business/search/FieldConstants.java Wed Jun  8 20:18:46 2005
@@ -0,0 +1,33 @@
+/*
+ * Created on Jul 19, 2003
+ *
+ * Authored by: Mindaugas Idzelis  (min@idzelis.com)
+ */
+package org.roller.business.search;
+
+
+/**
+ * @author aim4min
+ *
+ * To change the template for this generated type comment go to
+ * Window>Preferences>Java>Code Generation>Code and Comments
+ */
+public final class FieldConstants
+{
+    //~ Static fields/initializers =============================================
+
+    public static final String ANCHOR = "anchor";
+    public static final String UPDATED = "updated";
+    public static final String ID = "id";
+    public static final String USERNAME = "username";
+    public static final String CATEGORY = "cat";
+    public static final String TITLE = "title";
+    public static final String PUBLISHED = "published";
+    public static final String CONTENT = "content";
+    public static final String CONTENT_STORED = "content_stored";
+    public static final String C_CONTENT = "comment";
+    public static final String C_EMAIL = "email";
+    public static final String C_NAME = "name";
+    public static final String CONSTANT = "constant";
+    public static final String CONSTANT_V = "v"; //must be lowercase, or match the transform rules of the analyzer
+}

Added: incubator/roller/trunk/src/org/roller/business/search/IndexUtil.java
URL: http://svn.apache.org/viewcvs/incubator/roller/trunk/src/org/roller/business/search/IndexUtil.java?rev=189695&view=auto
==============================================================================
--- incubator/roller/trunk/src/org/roller/business/search/IndexUtil.java (added)
+++ incubator/roller/trunk/src/org/roller/business/search/IndexUtil.java Wed Jun  8 20:18:46 2005
@@ -0,0 +1,49 @@
+/*
+ * Created on Jul 20, 2003
+ *
+ * Authored by: Mindaugas Idzelis  (min@idzelis.com)
+ */
+package org.roller.business.search;
+
+import org.apache.lucene.analysis.Analyzer;
+import org.apache.lucene.analysis.Token;
+import org.apache.lucene.analysis.TokenStream;
+import org.apache.lucene.index.Term;
+import org.roller.business.IndexManagerImpl;
+
+import java.io.IOException;
+import java.io.StringReader;
+
+/**
+ * @author aim4min
+ *
+ * Class containing helper methods. 
+ */
+public class IndexUtil {
+
+	/**
+	 * Create a lucene term from the first token of the input string. 
+	 * 
+	 * @param field The lucene document field to create a term with
+	 * @param input The input you wish to convert into a term
+	 * @return Lucene search term
+	 */
+	public static final Term getTerm(String field, String input) {
+		if (input==null || field==null) return null;
+		Analyzer analyer = IndexManagerImpl.getAnalyzer();
+		TokenStream tokens = analyer.tokenStream(field,
+			new StringReader(input));
+		
+		Token token = null;
+		Term term = null;
+		try {
+			token = tokens.next();
+		} catch (IOException e) {}
+		if (token!=null) {
+			String termt = token.termText();
+			term = new Term(field,termt);
+		}
+		return term;
+	}
+
+}

Added: incubator/roller/trunk/src/org/roller/business/search/operations/AddEntryOperation.java
URL: http://svn.apache.org/viewcvs/incubator/roller/trunk/src/org/roller/business/search/operations/AddEntryOperation.java?rev=189695&view=auto
==============================================================================
--- incubator/roller/trunk/src/org/roller/business/search/operations/AddEntryOperation.java (added)
+++ incubator/roller/trunk/src/org/roller/business/search/operations/AddEntryOperation.java Wed Jun  8 20:18:46 2005
@@ -0,0 +1,70 @@
+/*
+ * Created on Jul 16, 2003
+ *
+ * Authored by: Mindaugas Idzelis  (min@idzelis.com)
+ */
+package org.roller.business.search.operations;
+
+import java.io.IOException;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.lucene.index.IndexWriter;
+import org.roller.business.IndexManagerImpl;
+import org.roller.pojos.WeblogEntryData;
+
+
+/**
+ * @author aim4min
+ *
+ * An operation that adds a new log entry into the index.
+ */
+public class AddEntryOperation extends WriteToIndexOperation
+{
+    //~ Static fields/initializers =============================================
+
+    private static Log mLogger =
+        LogFactory.getFactory().getInstance(AddEntryOperation.class);
+
+    //~ Instance fields ========================================================
+
+    private WeblogEntryData data;
+
+    //~ Constructors ===========================================================
+
+    /**
+     * Adds a web log entry into the index.
+     */
+    public AddEntryOperation(IndexManagerImpl mgr, WeblogEntryData data)
+    {
+        super(mgr);
+        this.data = data;
+    }
+
+    //~ Methods ================================================================
+
+    /* (non-Javadoc)
+     * @see java.lang.Runnable#run()
+     */
+    public void doRun()
+    {    	
+        IndexWriter writer = beginWriting();
+
+        try
+        {
+            if (writer != null)
+            {
+                writer.addDocument(getDocument(data));
+            }
+        }
+        catch (IOException e)
+        {
+            mLogger.error("Problems adding doc to index", e);
+        }
+        finally
+        {
+            endWriting();
+        }    	
+    }
+    
+}

Added: incubator/roller/trunk/src/org/roller/business/search/operations/IndexOperation.java
URL: http://svn.apache.org/viewcvs/incubator/roller/trunk/src/org/roller/business/search/operations/IndexOperation.java?rev=189695&view=auto
==============================================================================
--- incubator/roller/trunk/src/org/roller/business/search/operations/IndexOperation.java (added)
+++ incubator/roller/trunk/src/org/roller/business/search/operations/IndexOperation.java Wed Jun  8 20:18:46 2005
@@ -0,0 +1 @@
+/*
 * Created on Jul 16, 2003
 * Authored by: Mindaugas Idzelis  (min@idzelis.com)
 */
package org.roller.business.search.operations;

import java.io.IOException;
import java.util.Iterator;
import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.lucene.document.Document;
import org.apache.lucene.document.Field;
import org.apache.lucene.index.IndexReader;
import org.apache.lucene.index.IndexWriter;
import org.roller.business.IndexManagerImpl;
import org.roller.business.search.FieldConstants;
import org.roller.pojos.CommentData;
import org.roller.pojos.WeblogCategoryData;
import org.roller.pojos.WeblogEntryData;
import org.roller.util.Utilities;

/**
 * @author aim4min
 * 
 * This is the base class for all index operation. These operations include:
 * 
 * SearchOperation AddWeblogOperation RemoveWeblogOperation
 * RebuildUserIndexOperation
 *  
 */
public abstract class IndexOperation implements Runnable
{
    private static Log mLogger =
        LogFactory.getFactory().getInstance(IndexOperation.class);

    //~ Instance fields
    // ========================================================
    protected IndexManagerImpl manager;

    private IndexReader reader;

    private IndexWriter writer;

    //~ Constructors
    // ===========================================================

    public IndexOperation(IndexManagerImpl manager)
    {
        this.manager = manager;
    }

    //~ Methods
    // ================================================================

    protected Document getDocument(WeblogEntryData data)
    {
        StringBuffer commentEmail = new StringBuffer();
        StringBuffer commentContent = new StringBuffer();
        StringBuffer commentName = new StringBuffer();

        List comments = data.getComments();
        if (comments != null)
        {
            for (Iterator cItr = comments.iterator(); cItr.hasNext();)
            {
                CommentData comment = (CommentData) cItr.next();
                if (comment.getSpam() == null
                        || !comment.getSpam().booleanValue())
                {
                    if (comment.getContent() != null)
                    {
                        commentContent.append(comment.getContent());
                        commentContent.append(",");
                    }
                    if (comment.getEmail() != null)
                    {
                        commentEmail.append(comment.getEmail());
                        commentEmail.append(",");
                    }
                    if (comment.getName() != null)
                    {
                        commentName.append(comment.getName());
                        commentName.append(",");
                    }
                }
            }
        }

        Document doc = new Document();
        doc.add(Field.Keyword(FieldConstants.ID, data.getId()));
        doc.add(Field.UnIndexed(FieldConstants.ANCHOR, data.getAnchor()));
        doc.add(Field.Text(FieldConstants.USERNAME, data.getWebsite().getUser()
                .getUserName()));
        doc.add(Field.Text(FieldConstants.TITLE, data.getTitle()));

        // index the entry text, but don't store it - moved to end of block
        doc.add(Field.UnStored(FieldConstants.CONTENT, data.getText()));

        // store an abbreviated version of the entry text, but don't index
        doc.add(Field.UnIndexed(FieldConstants.CONTENT_STORED, Utilities
                .truncateNicely(Utilities.removeHTML(data.getText()), 240, 260,
                        "...")));

        doc.add(Field.Keyword(FieldConstants.UPDATED, data.getUpdateTime()
                .toString()));
        doc.add(Field.Keyword(FieldConstants.PUBLISHED, data.getPubTime()
                .toString()));

        // index Comments
        doc.add(Field.UnStored(FieldConstants.C_CONTENT, commentContent
                .toString()));
        doc
                .add(Field.UnStored(FieldConstants.C_EMAIL, commentEmail
                        .toString()));
        doc.add(Field.UnStored(FieldConstants.C_NAME, commentName.toString()));

        doc.add(Field.UnStored(FieldConstants.CONSTANT,
                FieldConstants.CONSTANT_V));

        // index Category
        WeblogCategoryData categorydata = data.getCategory();
        Field category = (categorydata == null) ? Field.UnStored(
                FieldConstants.CATEGORY, "") : Field.Text(
                FieldConstants.CATEGORY, categorydata.getName());
        doc.add(category);

        return doc;
    }

    protected IndexReader beginDeleting()
    {
        try
        {
            reader = IndexReader.open(manager.getIndexDirectory());
        }
        catch (IOException e)
        {
        }

        return reader;
    }

    protected void endDeleting()
    {
        if (reader != null)
        {
            try
            {
                reader.close();
            }
            catch (IOException e)
            {
            }
        }
    }

    protected IndexWriter beginWriting()
    {
        try
        {
            writer = new IndexWriter(manager.getIndexDirectory(),
                    IndexManagerImpl.getAnalyzer(), false);
        }
        catch (IOException e)
        {
            mLogger.error("ERROR creating writer");
        }

        return writer;
    }

    protected void endWriting()
    {
        if (writer != null)
        {
            try
            {
                writer.close();
            }
            catch (IOException e)
            {
                mLogger.error("ERROR closing writer",e);
            }
        }
    }

    public void run()
    {
        doRun();
    }

    protected abstract void doRun();
}
\ No newline at end of file

Added: incubator/roller/trunk/src/org/roller/business/search/operations/ReIndexEntryOperation.java
URL: http://svn.apache.org/viewcvs/incubator/roller/trunk/src/org/roller/business/search/operations/ReIndexEntryOperation.java?rev=189695&view=auto
==============================================================================
--- incubator/roller/trunk/src/org/roller/business/search/operations/ReIndexEntryOperation.java (added)
+++ incubator/roller/trunk/src/org/roller/business/search/operations/ReIndexEntryOperation.java Wed Jun  8 20:18:46 2005
@@ -0,0 +1,88 @@
+/*
+ * Created on Jul 16, 2003
+ *
+ * Authored by: Mindaugas Idzelis  (min@idzelis.com)
+ */
+package org.roller.business.search.operations;
+
+import java.io.IOException;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.lucene.index.IndexWriter;
+import org.apache.lucene.index.IndexReader;
+import org.roller.business.IndexManagerImpl;
+import org.roller.pojos.WeblogEntryData;
+import org.apache.lucene.index.Term;
+import org.roller.business.search.FieldConstants;
+
+/**
+ * @author aim4min
+ *
+ * An operation that adds a new log entry into the index.
+ */
+public class ReIndexEntryOperation extends WriteToIndexOperation
+{
+    //~ Static fields/initializers =============================================
+
+    private static Log mLogger =
+        LogFactory.getFactory().getInstance(AddEntryOperation.class);
+
+    //~ Instance fields ========================================================
+
+    private WeblogEntryData data;
+
+    //~ Constructors ===========================================================
+
+    /**
+     * Adds a web log entry into the index.
+     */
+    public ReIndexEntryOperation(IndexManagerImpl mgr, WeblogEntryData data)
+    {
+        super(mgr);
+        this.data = data;
+    }
+
+    //~ Methods ================================================================
+
+    /* (non-Javadoc)
+     * @see java.lang.Runnable#run()
+     */
+    public void doRun()
+    {    	
+        IndexReader reader = beginDeleting();
+        try
+        {
+            if (reader != null)
+            {
+                Term term = new Term(FieldConstants.ID, data.getId());
+                reader.delete(term);
+            }
+        }
+        catch (IOException e)
+        {
+            mLogger.error("Error deleting doc from index", e);
+        }
+        finally
+        {
+            endDeleting();
+        }
+        
+        IndexWriter writer = beginWriting();
+        try
+        {
+            if (writer != null)
+            {
+                writer.addDocument(getDocument(data));
+            }
+        }
+        catch (IOException e)
+        {
+            mLogger.error("Problems adding doc to index", e);
+        }
+        finally
+        {
+            endWriting();
+        }    	
+    }    
+}



Mime
View raw message