roller-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From snoopd...@apache.org
Subject svn commit: r543596 - in /roller/branches/roller_guice/apps/weblogger: src/java/org/apache/roller/weblogger/business/ src/java/org/apache/roller/weblogger/business/hibernate/ web/WEB-INF/classes/
Date Fri, 01 Jun 2007 20:28:57 GMT
Author: snoopdave
Date: Fri Jun  1 13:28:56 2007
New Revision: 543596

URL: http://svn.apache.org/viewvc?view=rev&rev=543596
Log:
Merging from trunk, still recovering from reorg

Added:
    roller/branches/roller_guice/apps/weblogger/src/java/org/apache/roller/weblogger/business/hibernate/HibernateModule.java
Modified:
    roller/branches/roller_guice/apps/weblogger/src/java/org/apache/roller/weblogger/business/RollerFactory.java
    roller/branches/roller_guice/apps/weblogger/src/java/org/apache/roller/weblogger/business/hibernate/HibernateAutoPingManagerImpl.java
    roller/branches/roller_guice/apps/weblogger/src/java/org/apache/roller/weblogger/business/hibernate/HibernateRollerImpl.java
    roller/branches/roller_guice/apps/weblogger/web/WEB-INF/classes/roller.properties

Modified: roller/branches/roller_guice/apps/weblogger/src/java/org/apache/roller/weblogger/business/RollerFactory.java
URL: http://svn.apache.org/viewvc/roller/branches/roller_guice/apps/weblogger/src/java/org/apache/roller/weblogger/business/RollerFactory.java?view=diff&rev=543596&r1=543595&r2=543596
==============================================================================
--- roller/branches/roller_guice/apps/weblogger/src/java/org/apache/roller/weblogger/business/RollerFactory.java
(original)
+++ roller/branches/roller_guice/apps/weblogger/src/java/org/apache/roller/weblogger/business/RollerFactory.java
Fri Jun  1 13:28:56 2007
@@ -18,6 +18,10 @@
 
 package org.apache.roller.weblogger.business;
 
+import com.google.inject.Binder;
+import com.google.inject.Guice;
+import com.google.inject.Injector;
+import com.google.inject.Module;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.roller.weblogger.config.RollerConfig;
@@ -26,78 +30,44 @@
 /**
  * Provides access to the Roller instance.
  */
-public abstract class RollerFactory {
-    
+public abstract class RollerFactory implements Module {
     private static Log log = LogFactory.getLog(RollerFactory.class);
+    private static Injector injector = null;
+       
     
     private static final String DEFAULT_IMPL =
-        "org.apache.roller.weblogger.business.jpa.JPARollerImpl";
-        //"org.apache.roller.weblogger.business.hibernate.HibernateRollerImpl";
-        //"org.apache.roller.weblogger.business.datamapper.jpa.JPARollerImpl";
+        "org.apache.roller.business.jpa.JPARollerImpl";
+        //"org.apache.roller.business.hibernate.HibernateRollerImpl";
+        //"org.apache.roller.business.datamapper.jpa.JPARollerImpl";
     
     private static Roller rollerInstance = null;
     
     
-    
+   
     // non-instantiable
     private RollerFactory() {
         // hello all you beautiful people
     }
     
+
+    static { 
+        String moduleClassname = RollerConfig.getProperty("guice.backend.module");
+        try {
+            Class moduleClass = Class.forName(moduleClassname);
+            Module module = (Module)moduleClass.newInstance();
+            injector = Guice.createInjector(module);
+        } catch (Throwable e) {                
+            // Fatal misconfiguration, cannot recover
+            throw new RuntimeException("Error instantiating backend module" + moduleClassname,
e);
+        }
+    }
+    
     
     /**
-     * Static accessor for the instance of Roller.
+     * Static accessor for the instance of Roller
      */
     public static Roller getRoller() {
-        
-        // check to see if we need to instantiate
-        if(rollerInstance == null) {
-            
-            // lookup value for the roller classname to use
-            String roller_classname =
-                    RollerConfig.getProperty("persistence.roller.classname");
-            if(roller_classname == null || roller_classname.trim().length() < 1)
-                roller_classname = DEFAULT_IMPL;
-            
-            try {
-                Class rollerClass = Class.forName(roller_classname);
-                java.lang.reflect.Method instanceMethod =
-                        rollerClass.getMethod("instantiate", (Class[])null);
-                
-                // do the invocation
-                rollerInstance = (Roller) instanceMethod.invoke(rollerClass, (Object[])null);
-                
-                log.info("Using Roller Impl: " + roller_classname);
-                
-            } catch (Throwable e) {
-                
-                // uh oh
-                log.error("Error instantiating " + roller_classname, e);
-                
-                try {
-                    // if we didn't already try DEFAULT_IMPL then try it now
-                    if( ! DEFAULT_IMPL.equals(roller_classname)) {
-                        
-                        log.info("** Trying DEFAULT_IMPL "+DEFAULT_IMPL+" **");
-                        
-                        Class rollerClass = Class.forName(DEFAULT_IMPL);
-                        java.lang.reflect.Method instanceMethod =
-                                rollerClass.getMethod("instantiate", (Class[])null);
-                        
-                        // do the invocation
-                        rollerInstance = (Roller) instanceMethod.invoke(rollerClass, (Object[])null);
-                    } else {
-                        // we just do this so that the logger gets the message
-                        throw new Exception("Doh! Couldn't instantiate a roller class");
-                    }
-                    
-                } catch (Exception re) {
-                    log.fatal("Failed to instantiate fallback roller impl", re);
-                }
-            }
-        }
-        
-        return rollerInstance;
-    }
-    
+        return injector.getInstance(Roller.class);
+    }    
 }
+

Modified: roller/branches/roller_guice/apps/weblogger/src/java/org/apache/roller/weblogger/business/hibernate/HibernateAutoPingManagerImpl.java
URL: http://svn.apache.org/viewvc/roller/branches/roller_guice/apps/weblogger/src/java/org/apache/roller/weblogger/business/hibernate/HibernateAutoPingManagerImpl.java?view=diff&rev=543596&r1=543595&r2=543596
==============================================================================
--- roller/branches/roller_guice/apps/weblogger/src/java/org/apache/roller/weblogger/business/hibernate/HibernateAutoPingManagerImpl.java
(original)
+++ roller/branches/roller_guice/apps/weblogger/src/java/org/apache/roller/weblogger/business/hibernate/HibernateAutoPingManagerImpl.java
Fri Jun  1 13:28:56 2007
@@ -16,12 +16,12 @@
  * directory of this distribution.
  */
 
-package org.apache.roller.weblogger.business.hibernate;
+package org.apache.roller.weblogger.business.hibernate; 
 
-import org.hibernate.Criteria;
-import org.hibernate.HibernateException;
-import org.hibernate.Session;
-import org.hibernate.criterion.Expression;
+import org.hibernate.Criteria; 
+import org.hibernate.HibernateException; 
+import org.hibernate.Session; 
+import org.hibernate.criterion.Expression; 
 import org.apache.roller.RollerException;
 import org.apache.roller.weblogger.pojos.AutoPing;
 import org.apache.roller.weblogger.pojos.PingTarget;
@@ -31,12 +31,12 @@
 import java.util.Collections;
 import java.util.Iterator;
 import java.util.List;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
+import org.apache.commons.logging.Log;  
+import org.apache.commons.logging.LogFactory;  
+import org.apache.roller.weblogger.business.Roller;
 import org.apache.roller.weblogger.config.PingConfig;
 import org.apache.roller.weblogger.business.pings.AutoPingManager;
 import org.apache.roller.weblogger.business.pings.PingQueueManager;
-import org.apache.roller.weblogger.business.RollerFactory;
 
 
 /**
@@ -46,14 +46,17 @@
  */
 public class HibernateAutoPingManagerImpl implements AutoPingManager {
     
+    private Roller roller;
+    
     static final long serialVersionUID = 5420615676256979199L;
     
     private static Log log = LogFactory.getLog(HibernateAutoPingManagerImpl.class);
     
     private HibernatePersistenceStrategy strategy = null;
     
-    
-    public HibernateAutoPingManagerImpl(HibernatePersistenceStrategy strat) {
+    @com.google.inject.Inject    
+    public HibernateAutoPingManagerImpl(Roller roller, HibernatePersistenceStrategy strat)
{
+        this.roller = roller;
         this.strategy = strat;
     }
     
@@ -122,7 +125,7 @@
         }
         
         // TODO: new manager method for addQueueEntries(list)?
-        PingQueueManager pingQueueMgr = RollerFactory.getRoller().getPingQueueManager();
+        PingQueueManager pingQueueMgr = roller.getPingQueueManager();
         List applicableAutopings = getApplicableAutoPings(changedWeblogEntry);
         for (Iterator i = applicableAutopings.iterator(); i.hasNext(); ) {
             AutoPing autoPing = (AutoPing) i.next();

Added: roller/branches/roller_guice/apps/weblogger/src/java/org/apache/roller/weblogger/business/hibernate/HibernateModule.java
URL: http://svn.apache.org/viewvc/roller/branches/roller_guice/apps/weblogger/src/java/org/apache/roller/weblogger/business/hibernate/HibernateModule.java?view=auto&rev=543596
==============================================================================
--- roller/branches/roller_guice/apps/weblogger/src/java/org/apache/roller/weblogger/business/hibernate/HibernateModule.java
(added)
+++ roller/branches/roller_guice/apps/weblogger/src/java/org/apache/roller/weblogger/business/hibernate/HibernateModule.java
Fri Jun  1 13:28:56 2007
@@ -0,0 +1,71 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  The ASF licenses this file to You
+ * under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.  For additional information regarding
+ * copyright in this work, please see the NOTICE file in the top level
+ * directory of this distribution.
+ */
+
+package org.apache.roller.weblogger.business.hibernate;
+
+import com.google.inject.Binder;
+import com.google.inject.Module;
+import org.apache.roller.weblogger.business.BookmarkManager;
+import org.apache.roller.weblogger.business.FileManager;
+import org.apache.roller.weblogger.business.FileManagerImpl;
+import org.apache.roller.weblogger.business.PluginManager;
+import org.apache.roller.weblogger.business.PluginManagerImpl;
+import org.apache.roller.weblogger.business.PropertiesManager;
+import org.apache.roller.weblogger.business.Roller;
+import org.apache.roller.weblogger.business.UserManager;
+import org.apache.roller.weblogger.business.WeblogManager;
+import org.apache.roller.weblogger.business.pings.AutoPingManager;
+import org.apache.roller.weblogger.business.pings.PingQueueManager;
+import org.apache.roller.weblogger.business.pings.PingTargetManager;
+import org.apache.roller.weblogger.business.referrers.RefererManager;
+import org.apache.roller.weblogger.business.referrers.ReferrerQueueManager;
+import org.apache.roller.weblogger.business.referrers.ReferrerQueueManagerImpl;
+import org.apache.roller.weblogger.business.runnable.ThreadManager;
+import org.apache.roller.weblogger.business.runnable.ThreadManagerImpl;
+import org.apache.roller.weblogger.business.search.IndexManager;
+import org.apache.roller.weblogger.business.search.IndexManagerImpl;
+import org.apache.roller.weblogger.business.themes.ThemeManager;
+import org.apache.roller.weblogger.business.themes.ThemeManagerImpl;
+
+/**
+ * Guice module for configuring Hibernate as Roller-backend.
+ */
+public class HibernateModule implements Module {
+
+    public void configure(Binder binder) {
+        
+        binder.bind(Roller.class).to(HibernateRollerImpl.class);
+        
+        binder.bind(AutoPingManager.class).to(     HibernateAutoPingManagerImpl.class); 
 
+        binder.bind(BookmarkManager.class).to(     HibernateBookmarkManagerImpl.class); 

+        binder.bind(PingQueueManager.class).to(    HibernatePingQueueManagerImpl.class);
  
+        binder.bind(PingTargetManager.class).to(   HibernatePingTargetManagerImpl.class);

+        binder.bind(PropertiesManager.class).to(   HibernatePropertiesManagerImpl.class);
  
+        binder.bind(RefererManager.class).to(      HibernateRefererManagerImpl.class);
+        binder.bind(UserManager.class).to(         HibernateUserManagerImpl.class);   
+        binder.bind(WeblogManager.class).to(       HibernateWeblogManagerImpl.class);   
+        
+        binder.bind(ReferrerQueueManager.class).to(ReferrerQueueManagerImpl.class); 
+        binder.bind(FileManager.class).to(         FileManagerImpl.class);   
+        binder.bind(IndexManager.class).to(        IndexManagerImpl.class);
+        binder.bind(PluginManager.class).to(       PluginManagerImpl.class);    
+        binder.bind(ThemeManager.class).to(        ThemeManagerImpl.class);  
+        binder.bind(ThreadManager.class).to(       ThreadManagerImpl.class);  
+    }    
+}
+

Modified: roller/branches/roller_guice/apps/weblogger/src/java/org/apache/roller/weblogger/business/hibernate/HibernateRollerImpl.java
URL: http://svn.apache.org/viewvc/roller/branches/roller_guice/apps/weblogger/src/java/org/apache/roller/weblogger/business/hibernate/HibernateRollerImpl.java?view=diff&rev=543596&r1=543595&r2=543596
==============================================================================
--- roller/branches/roller_guice/apps/weblogger/src/java/org/apache/roller/weblogger/business/hibernate/HibernateRollerImpl.java
(original)
+++ roller/branches/roller_guice/apps/weblogger/src/java/org/apache/roller/weblogger/business/hibernate/HibernateRollerImpl.java
Fri Jun  1 13:28:56 2007
@@ -196,7 +196,7 @@
      */
     public AutoPingManager getAutopingManager() {
         if (autoPingManager == null) {
-            autoPingManager = new HibernateAutoPingManagerImpl(strategy);
+            autoPingManager = new HibernateAutoPingManagerImpl(this, strategy);
         }
         return autoPingManager;
     }

Modified: roller/branches/roller_guice/apps/weblogger/web/WEB-INF/classes/roller.properties
URL: http://svn.apache.org/viewvc/roller/branches/roller_guice/apps/weblogger/web/WEB-INF/classes/roller.properties?view=diff&rev=543596&r1=543595&r2=543596
==============================================================================
--- roller/branches/roller_guice/apps/weblogger/web/WEB-INF/classes/roller.properties (original)
+++ roller/branches/roller_guice/apps/weblogger/web/WEB-INF/classes/roller.properties Fri
Jun  1 13:28:56 2007
@@ -70,6 +70,8 @@
 mail.password
 
 #---------------------------------
+guice.backend.module=org.apache.roller.business.hibernate.HibernateModule
+
 # Hibernate dialect: You MUST override this to use a database other than MySQL4
 hibernate.dialect=org.hibernate.dialect.MySQLDialect
 



Mime
View raw message