roller-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From snoopd...@apache.org
Subject svn commit: r366209 - in /incubator/roller/trunk/sandbox/jdobackend/src/org/roller/business/jdo: JDORollerImpl.java JDOStrategy.java
Date Thu, 05 Jan 2006 16:00:37 GMT
Author: snoopdave
Date: Thu Jan  5 08:00:35 2006
New Revision: 366209

URL: http://svn.apache.org/viewcvs?rev=366209&view=rev
Log:
First JDORoller patch

Modified:
    incubator/roller/trunk/sandbox/jdobackend/src/org/roller/business/jdo/JDORollerImpl.java
    incubator/roller/trunk/sandbox/jdobackend/src/org/roller/business/jdo/JDOStrategy.java

Modified: incubator/roller/trunk/sandbox/jdobackend/src/org/roller/business/jdo/JDORollerImpl.java
URL: http://svn.apache.org/viewcvs/incubator/roller/trunk/sandbox/jdobackend/src/org/roller/business/jdo/JDORollerImpl.java?rev=366209&r1=366208&r2=366209&view=diff
==============================================================================
--- incubator/roller/trunk/sandbox/jdobackend/src/org/roller/business/jdo/JDORollerImpl.java
(original)
+++ incubator/roller/trunk/sandbox/jdobackend/src/org/roller/business/jdo/JDORollerImpl.java
Thu Jan  5 08:00:35 2006
@@ -5,15 +5,16 @@
 
 import java.sql.Connection;
 
+import javax.jdo.JDOHelper;
+import javax.jdo.PersistenceManagerFactory;
+
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
-import org.hibernate.SessionFactory;
 import org.roller.RollerException;
 import org.roller.business.PersistenceStrategy;
 import org.roller.business.utils.UpgradeDatabase;
 import org.roller.model.AutoPingManager;
 import org.roller.model.BookmarkManager;
-import org.roller.model.ConfigManager;
 import org.roller.model.PingQueueManager;
 import org.roller.model.PingTargetManager;
 import org.roller.model.PlanetManager;
@@ -31,27 +32,16 @@
  * @author Dave Johnson
  */
 public class JDORollerImpl extends org.roller.business.RollerImpl {
-    private static Log              mLogger        = LogFactory
-                                                           .getFactory()
-                                                           .getInstance(
-                                                                   JDORollerImpl.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;
+    private static Log mLogger = LogFactory.getFactory()
+            .getInstance(JDORollerImpl.class);
+
     protected static JDORollerImpl  me;
     protected PersistenceStrategy   mStrategy      = null;
-    protected static SessionFactory mSessionFactory;
 
     protected JDORollerImpl() throws RollerException {
-        mStrategy = new JDOStrategy();
+        PersistenceManagerFactory pmf = 
+                JDOHelper.getPersistenceManagerFactory("JDOPMF.properties");
+        mStrategy = new JDOStrategy(pmf);
     }
 
     public static Roller instantiate() throws RollerException {
@@ -62,133 +52,50 @@
         return me;
     }
 
-    public void begin() throws RollerException {
-        mStrategy.begin(UserData.ANONYMOUS_USER);
-    }
 
-    public void begin(UserData user) throws RollerException {
-        mStrategy.begin(user);
+    /** */
+    protected UserManager createUserManager() {
+        return new JDOUserManagerImpl(mStrategy);
     }
 
-    public UserData getUser() throws RollerException {
-        return mStrategy.getUser();
+    /** */
+    protected BookmarkManager createBookmarkManager() {
+        return new JDOBookmarkManagerImpl(mStrategy);
     }
 
-    public void setUser(UserData user) throws RollerException {
-        mStrategy.setUser(user);
+    /** */
+    protected WeblogManager createWeblogManager() {
+        return new JDOWeblogManagerImpl(mStrategy);
     }
 
-    public void commit() throws RollerException {
-        mStrategy.commit();
+    /** */
+    protected RefererManager createRefererManager() {
+        return new JDORefererManagerImpl();
     }
 
-    public void rollback() {
-        try {
-            mStrategy.rollback();
-        }
-        catch (Throwable e) {
-            mLogger.error(e);
-        }
+    /** */
+    protected PropertiesManager createPropertiesManager() {
+        return new JDOPropertiesManagerImpl(mStrategy);
     }
 
-    /**
-     * @see org.roller.model.Roller#getUserManager()
-     */
-    public UserManager getUserManager() throws RollerException {
-        if (mUserManager == null) {
-            mUserManager = new JDOUserManagerImpl(mStrategy);
-        }
-        return mUserManager;
+    /** */
+    protected PingQueueManager createPingQueueManager() {
+        return new JDOPingQueueManagerImpl(mStrategy);
     }
 
-    /**
-     * @see org.roller.model.Roller#getBookmarkManager()
-     */
-    public BookmarkManager getBookmarkManager() throws RollerException {
-        if (mBookmarkManager == null) {
-            mBookmarkManager = new JDOBookmarkManagerImpl(mStrategy);
-        }
-        return mBookmarkManager;
+    /** */
+    protected PlanetManager createPlanetManager() {
+        return new JDOPlanetManagerImpl(mStrategy, this);
     }
 
-    /**
-     * @see org.roller.model.Roller#getWeblogManager()
-     */
-    public WeblogManager getWeblogManager() throws RollerException {
-        if (mWeblogManager == null) {
-            mWeblogManager = new JDOWeblogManagerImpl(mStrategy);
-        }
-        return mWeblogManager;
+    /** */
+    protected  AutoPingManager createAutoPingManager() {
+        return new JDOAutoPingManagerImpl(mStrategy);
     }
 
-    /**
-     * @see org.roller.model.Roller#getRefererManager()
-     */
-    public RefererManager getRefererManager() throws RollerException {
-        if (mRefererManager == null) {
-            mRefererManager = new JDORefererManagerImpl();
-        }
-        return mRefererManager;
-    }
-
-    /**
-     * @see org.roller.model.Roller#getConfigManager()
-     */
-    public ConfigManager getConfigManager() throws RollerException {
-        if (mConfigManager == null) {
-            mConfigManager = new JDOConfigManagerImpl(mStrategy);
-        }
-        return mConfigManager;
-    }
-
-    /**
-     * @see org.roller.model.Roller#getPropertiesManager()
-     */
-    public PropertiesManager getPropertiesManager() throws RollerException {
-        if (mPropsManager == null) {
-            mPropsManager = new JDOPropertiesManagerImpl(mStrategy);
-        }
-        return mPropsManager;
-    }
-
-    /**
-     * @see org.roller.model.Roller#getPingTargetManager()
-     */
-    public PingQueueManager getPingQueueManager() throws RollerException {
-        if (mPingQueueManager == null) {
-            mPingQueueManager = new JDOPingQueueManagerImpl(mStrategy);
-        }
-        return mPingQueueManager;
-    }
-
-    /**
-     * @see org.roller.model.Roller#getPlanetManager()
-     */
-    public PlanetManager getPlanetManager() throws RollerException {
-        if (planetManager == null) {
-            planetManager = new JDOPlanetManagerImpl(mStrategy, this);
-        }
-        return planetManager;
-    }
-
-    /**
-     * @see org.roller.model.Roller#getPingTargetManager()
-     */
-    public AutoPingManager getAutopingManager() throws RollerException {
-        if (mAutoPingManager == null) {
-            mAutoPingManager = new JDOAutoPingManagerImpl(mStrategy);
-        }
-        return mAutoPingManager;
-    }
-
-    /**
-     * @see org.roller.model.Roller#getPingTargetManager()
-     */
-    public PingTargetManager getPingTargetManager() throws RollerException {
-        if (mPingTargetManager == null) {
-            mPingTargetManager = new JDOPingTargetManagerImpl(mStrategy);
-        }
-        return mPingTargetManager;
+    /** */
+    protected PingTargetManager createPingTargetManager() {
+        return new JDOPingTargetManagerImpl(mStrategy);
     }
 
     /**
@@ -198,40 +105,9 @@
         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 (Throwable e) {
-            mLogger.error("Exception with mSupport.release() [" + e + "]", e);
-        }
+        // nothing else to do for now
     }
 
     public void shutdown() {
@@ -241,7 +117,7 @@
             release();
         }
         catch (Exception e) {
-            mLogger.error("Unable to close SessionFactory", e);
+            mLogger.error("Unable to close PersistenceManagerFactory", e);
         }
     }
 }

Modified: incubator/roller/trunk/sandbox/jdobackend/src/org/roller/business/jdo/JDOStrategy.java
URL: http://svn.apache.org/viewcvs/incubator/roller/trunk/sandbox/jdobackend/src/org/roller/business/jdo/JDOStrategy.java?rev=366209&r1=366208&r2=366209&view=diff
==============================================================================
--- incubator/roller/trunk/sandbox/jdobackend/src/org/roller/business/jdo/JDOStrategy.java
(original)
+++ incubator/roller/trunk/sandbox/jdobackend/src/org/roller/business/jdo/JDOStrategy.java
Thu Jan  5 08:00:35 2006
@@ -5,6 +5,9 @@
 
 import java.util.List;
 
+import javax.jdo.PersistenceManager;
+import javax.jdo.PersistenceManagerFactory;
+
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.roller.RollerException;
@@ -19,17 +22,16 @@
  */
 public class JDOStrategy implements PersistenceStrategy {
     private static final ThreadLocal mSessionTLS = new ThreadLocal();
-
-    private static Log               mLogger     = LogFactory
-                                                         .getFactory()
-                                                         .getInstance(
-                                                                 JDOStrategy.class);
+    private PersistenceManagerFactory mPMF = null;
+    private static Log mLogger = LogFactory
+            .getFactory().getInstance(JDOStrategy.class);
 
     //-------------------------------------------------------------------------
     /**
-     * Construct using Hibernate Session Factory.
+     * Construct using JDO PersistenceManagerFactory.
      */
-    public JDOStrategy() throws RollerException {
+    public JDOStrategy(PersistenceManagerFactory pmf) throws RollerException {
+        this.mPMF = pmf;
     }
 
     //-------------------------------------------------------------------------
@@ -76,7 +78,34 @@
      */
     public PersistenceSession getPersistenceSession(UserData user,
             boolean createNew) throws RollerException {
-        return null;
+        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
+            {
+                PersistenceManager pm = mPMF.getPersistenceManager();
+                ses = new JDOPersistenceSession(user, pm);
+            }
+            catch (Throwable e)
+            {
+                mLogger.error(
+                    "JDOStrategy.exceptionGetPersistenceManager");
+                throw new RuntimeException();
+            }
+            mSessionTLS.set(ses);
+        }
+        else if (ses == null)
+        {
+            throw new RollerException(
+                "MUST specify user for new persistence session");
+        }
+        return ses;
     }
 
     //-------------------------------------------------------------------------



Mime
View raw message