You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@roller.apache.org by sn...@apache.org on 2006/09/21 22:24:15 UTC
svn commit: r448662 - in /incubator/roller/trunk/sandbox/planetroller:
src/org/apache/roller/planet/ src/org/apache/roller/planet/business/
src/org/apache/roller/planet/business/hibernate/
src/org/apache/roller/planet/model/ src/org/apache/roller/plane...
Author: snoopdave
Date: Thu Sep 21 13:24:14 2006
New Revision: 448662
URL: http://svn.apache.org/viewvc?view=rev&rev=448662
Log:
Planet webapp now uses Planet and PlanetFactory to bootstrap the PlanetManager
Added:
incubator/roller/trunk/sandbox/planetroller/src/org/apache/roller/planet/
incubator/roller/trunk/sandbox/planetroller/src/org/apache/roller/planet/business/
incubator/roller/trunk/sandbox/planetroller/src/org/apache/roller/planet/business/hibernate/
incubator/roller/trunk/sandbox/planetroller/src/org/apache/roller/planet/business/hibernate/HibernatePlanetImpl.java
incubator/roller/trunk/sandbox/planetroller/src/org/apache/roller/planet/model/
incubator/roller/trunk/sandbox/planetroller/src/org/apache/roller/planet/model/Planet.java
incubator/roller/trunk/sandbox/planetroller/src/org/apache/roller/planet/model/PlanetFactory.java
incubator/roller/trunk/sandbox/planetroller/src/org/apache/roller/planet/utils/
incubator/roller/trunk/sandbox/planetroller/src/org/apache/roller/planet/utils/PlanetTool.java
- copied, changed from r448225, incubator/roller/trunk/sandbox/planetroller/src/org/apache/roller/tools/PlanetTool.java
Removed:
incubator/roller/trunk/sandbox/planetroller/src/org/apache/roller/tools/PlanetTool.java
Modified:
incubator/roller/trunk/sandbox/planetroller/web/WEB-INF/classes/hibernate.cfg.xml
incubator/roller/trunk/sandbox/planetroller/web/index.jsp
Added: incubator/roller/trunk/sandbox/planetroller/src/org/apache/roller/planet/business/hibernate/HibernatePlanetImpl.java
URL: http://svn.apache.org/viewvc/incubator/roller/trunk/sandbox/planetroller/src/org/apache/roller/planet/business/hibernate/HibernatePlanetImpl.java?view=auto&rev=448662
==============================================================================
--- incubator/roller/trunk/sandbox/planetroller/src/org/apache/roller/planet/business/hibernate/HibernatePlanetImpl.java (added)
+++ incubator/roller/trunk/sandbox/planetroller/src/org/apache/roller/planet/business/hibernate/HibernatePlanetImpl.java Thu Sep 21 13:24:14 2006
@@ -0,0 +1,96 @@
+/*
+* 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.planet.business.hibernate;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.roller.RollerException;
+import org.apache.roller.business.hibernate.HibernatePersistenceStrategy;
+import org.apache.roller.planet.business.hibernate.HibernatePlanetManagerImpl;
+import org.apache.roller.planet.model.PlanetManager;
+import org.apache.roller.planet.model.Planet;
+
+
+/**
+ * A Hibernate specific implementation of the Roller business layer.
+ */
+public class HibernatePlanetImpl implements Planet {
+
+ private static Log mLogger = LogFactory.getLog(HibernatePlanetImpl.class);
+
+ // our singleton instance
+ private static HibernatePlanetImpl me = null;
+
+ // a persistence utility class
+ private HibernatePersistenceStrategy strategy = null;
+
+ // references to the managers we maintain
+ private PlanetManager planetManager = null;
+
+
+ protected HibernatePlanetImpl() throws RollerException {
+ try {
+ strategy = new HibernatePersistenceStrategy();
+ } catch(Throwable t) {
+ // if this happens then we are screwed
+ mLogger.fatal("Error initializing Hibernate", t);
+ throw new RollerException(t);
+ }
+ }
+
+
+ /**
+ * Instantiates and returns an instance of HibernatePlanetImpl.
+ */
+ public static Planet instantiate() throws RollerException {
+ if (me == null) {
+ mLogger.debug("Instantiating HibernatePlanetImpl");
+ me = new HibernatePlanetImpl();
+ }
+
+ return me;
+ }
+
+
+ public PlanetManager getPlanetManager() throws RollerException {
+ if ( planetManager == null ) {
+ planetManager = new HibernatePlanetManagerImpl(strategy);
+ }
+ return planetManager;
+ }
+
+
+ public void flush() throws RollerException {
+ this.strategy.flush();
+ }
+
+
+ public void release() {
+
+ // tell Hibernate to close down
+ this.strategy.release();
+ }
+
+
+ public void shutdown() {
+
+ // do our own shutdown first
+ this.release();
+ }
+
+}
Added: incubator/roller/trunk/sandbox/planetroller/src/org/apache/roller/planet/model/Planet.java
URL: http://svn.apache.org/viewvc/incubator/roller/trunk/sandbox/planetroller/src/org/apache/roller/planet/model/Planet.java?view=auto&rev=448662
==============================================================================
--- incubator/roller/trunk/sandbox/planetroller/src/org/apache/roller/planet/model/Planet.java (added)
+++ incubator/roller/trunk/sandbox/planetroller/src/org/apache/roller/planet/model/Planet.java Thu Sep 21 13:24:14 2006
@@ -0,0 +1,53 @@
+/*
+* 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.planet.model;
+
+import org.apache.roller.RollerException;
+import org.apache.roller.planet.model.PlanetManager;
+
+
+/**
+ * The main entry point interface of the Roller business tier.
+ */
+public interface Planet {
+
+ /**
+ * Get PlanetManager associated with this Roller instance.
+ */
+ public PlanetManager getPlanetManager() throws RollerException;
+
+ /**
+ * Flush object states.
+ */
+ public void flush() throws RollerException;
+
+
+ /**
+ * Release all resources associated with Roller session.
+ */
+ public void release();
+
+
+ /**
+ * Release all resources necessary for this instance of Roller.
+ */
+ public void shutdown();
+
+}
+
Added: incubator/roller/trunk/sandbox/planetroller/src/org/apache/roller/planet/model/PlanetFactory.java
URL: http://svn.apache.org/viewvc/incubator/roller/trunk/sandbox/planetroller/src/org/apache/roller/planet/model/PlanetFactory.java?view=auto&rev=448662
==============================================================================
--- incubator/roller/trunk/sandbox/planetroller/src/org/apache/roller/planet/model/PlanetFactory.java (added)
+++ incubator/roller/trunk/sandbox/planetroller/src/org/apache/roller/planet/model/PlanetFactory.java Thu Sep 21 13:24:14 2006
@@ -0,0 +1,127 @@
+/*
+ * 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.planet.model;
+
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.roller.planet.config.PlanetConfig;
+import org.apache.commons.lang.StringUtils;
+
+/**
+ * Instantiates planet implementation.
+ */
+public abstract class PlanetFactory {
+ private static final String DEFAULT_IMPL =
+ "org.apache.roller.planet.business.hibernate.HibernatePlanetImpl";
+
+ private static Planet planetInstance = null;
+
+ private static Log mLogger =
+ LogFactory.getFactory().getInstance(PlanetFactory.class);
+
+ /**
+ * Let's just be doubling certain this class cannot be instantiated.
+ * @see java.lang.Object#Object()
+ */
+ private PlanetFactory() {
+ // hello planetary citizens
+ }
+
+ /**
+ * Static accessor for the instance of Planet
+ * held by this class.
+ *
+ * @return Planet
+ */
+ public static Planet getPlanet() {
+ // check to see if we need to instantiate
+ if(planetInstance == null) {
+ // lookup value for the planet classname to use
+ String planet_classname =
+ PlanetConfig.getProperty("persistence.planet.classname");
+
+ // now call setPlanet ourselves
+ PlanetFactory.setPlanet(planet_classname);
+ }
+
+ return planetInstance;
+ }
+
+
+ /**
+ * Construct the actual Planet implemenation for this instance.
+ *
+ * Use reflection to call the implementation's instantiate() method.
+ * Should this fail (either no implementation is specified or
+ * instantiate() throws an Exception) then the DEFAULT_IMPL will be tried.
+ * If this should fail then we are in trouble :/
+ *
+ * @param planet_classname The name of the Planet implementation class
+ * to instantiate.
+ */
+ public static void setPlanet(String planet_classname) {
+
+ if (StringUtils.isEmpty( planet_classname ))
+ planet_classname = DEFAULT_IMPL;
+
+ try {
+ Class planetClass = Class.forName(planet_classname);
+ java.lang.reflect.Method instanceMethod =
+ planetClass.getMethod("instantiate", (Class[])null);
+
+ // do the invocation
+ planetInstance = (Planet)
+ instanceMethod.invoke(planetClass, (Object[])null);
+
+ mLogger.info("Using Planet Impl: " + planet_classname);
+ } catch (Exception e) {
+ // uh oh
+ mLogger.error("Error instantiating " + planet_classname, e);
+ try {
+ // if we didn't already try DEFAULT_IMPL then try it now
+ if( ! DEFAULT_IMPL.equals(planet_classname)) {
+ mLogger.info("** Trying DEFAULT_IMPL "+DEFAULT_IMPL+" **");
+
+ Class planetClass = Class.forName(DEFAULT_IMPL);
+ java.lang.reflect.Method instanceMethod =
+ planetClass.getMethod("instantiate", (Class[])null);
+
+ // do the invocation
+ planetInstance = (Planet)
+ instanceMethod.invoke(planetClass, (Object[])null);
+ } else {
+ // we just do this so that the logger gets the message
+ throw new Exception("Doh! Couldn't instantiate the planet class");
+ }
+
+ } catch (Exception re) {
+ mLogger.fatal("Failed to instantiate fallback planet impl", re);
+ }
+ }
+
+ }
+
+
+ /**
+ * Set Planet to be returned by factory.
+ */
+ public static void setPlanet(Planet planet) {
+ if (planet != null) planetInstance = planet;
+ }
+}
Copied: incubator/roller/trunk/sandbox/planetroller/src/org/apache/roller/planet/utils/PlanetTool.java (from r448225, incubator/roller/trunk/sandbox/planetroller/src/org/apache/roller/tools/PlanetTool.java)
URL: http://svn.apache.org/viewvc/incubator/roller/trunk/sandbox/planetroller/src/org/apache/roller/planet/utils/PlanetTool.java?view=diff&rev=448662&p1=incubator/roller/trunk/sandbox/planetroller/src/org/apache/roller/tools/PlanetTool.java&r1=448225&p2=incubator/roller/trunk/sandbox/planetroller/src/org/apache/roller/planet/utils/PlanetTool.java&r2=448662
==============================================================================
--- incubator/roller/trunk/sandbox/planetroller/src/org/apache/roller/tools/PlanetTool.java (original)
+++ incubator/roller/trunk/sandbox/planetroller/src/org/apache/roller/planet/utils/PlanetTool.java Thu Sep 21 13:24:14 2006
@@ -15,7 +15,7 @@
* copyright in this work, please see the NOTICE file in the top level
* directory of this distribution.
*/
-package org.apache.roller.tools;
+package org.apache.roller.planet.utils;
import com.sun.syndication.feed.synd.SyndEntry;
import com.sun.syndication.feed.synd.SyndFeed;
@@ -60,10 +60,10 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import org.apache.roller.pojos.PlanetConfigData;
-import org.apache.roller.pojos.PlanetEntryData;
-import org.apache.roller.pojos.PlanetGroupData;
-import org.apache.roller.pojos.PlanetSubscriptionData;
+import org.apache.roller.planet.pojos.PlanetConfigData;
+import org.apache.roller.planet.pojos.PlanetEntryData;
+import org.apache.roller.planet.pojos.PlanetGroupData;
+import org.apache.roller.planet.pojos.PlanetSubscriptionData;
import org.apache.roller.util.Utilities;
import org.apache.roller.util.rome.DiskFeedInfoCache;
import org.apache.velocity.VelocityContext;
Modified: incubator/roller/trunk/sandbox/planetroller/web/WEB-INF/classes/hibernate.cfg.xml
URL: http://svn.apache.org/viewvc/incubator/roller/trunk/sandbox/planetroller/web/WEB-INF/classes/hibernate.cfg.xml?view=diff&rev=448662&r1=448661&r2=448662
==============================================================================
--- incubator/roller/trunk/sandbox/planetroller/web/WEB-INF/classes/hibernate.cfg.xml (original)
+++ incubator/roller/trunk/sandbox/planetroller/web/WEB-INF/classes/hibernate.cfg.xml Thu Sep 21 13:24:14 2006
@@ -74,32 +74,12 @@
<property name="hibernate.cache.use_structured_entries">true</property>
- <!-- Map Roller pojo classes -->
- <mapping resource="org/apache/roller/pojos/BookmarkData.hbm.xml" />
- <mapping resource="org/apache/roller/pojos/CommentData.hbm.xml" />
- <mapping resource="org/apache/roller/pojos/EntryAttributeData.hbm.xml" />
- <mapping resource="org/apache/roller/pojos/FolderAssoc.hbm.xml" />
- <mapping resource="org/apache/roller/pojos/FolderData.hbm.xml" />
- <mapping resource="org/apache/roller/pojos/WeblogTemplate.hbm.xml" />
- <mapping resource="org/apache/roller/pojos/PingCategoryRestrictionData.hbm.xml" />
- <mapping resource="org/apache/roller/pojos/AutoPingData.hbm.xml" />
- <mapping resource="org/apache/roller/pojos/PingQueueEntryData.hbm.xml" />
- <mapping resource="org/apache/roller/pojos/PingTargetData.hbm.xml" />
- <mapping resource="org/apache/roller/pojos/RefererData.hbm.xml" />
- <mapping resource="org/apache/roller/pojos/RoleData.hbm.xml" />
- <mapping resource="org/apache/roller/pojos/RollerConfigData.hbm.xml" />
- <mapping resource="org/apache/roller/pojos/UserData.hbm.xml" />
- <mapping resource="org/apache/roller/pojos/WeblogCategoryData.hbm.xml" />
- <mapping resource="org/apache/roller/pojos/WeblogCategoryAssoc.hbm.xml" />
- <mapping resource="org/apache/roller/pojos/WeblogEntryData.hbm.xml" />
- <mapping resource="org/apache/roller/pojos/WebsiteData.hbm.xml" />
- <mapping resource="org/apache/roller/pojos/RollerPropertyData.hbm.xml" />
- <mapping resource="org/apache/roller/pojos/PermissionsData.hbm.xml" />
- <mapping resource="org/apache/roller/pojos/PlanetConfigData.hbm.xml" />
- <mapping resource="org/apache/roller/pojos/PlanetGroupData.hbm.xml" />
- <mapping resource="org/apache/roller/pojos/PlanetEntryData.hbm.xml" />
- <mapping resource="org/apache/roller/pojos/PlanetSubscriptionData.hbm.xml" />
- <mapping resource="org/apache/roller/pojos/PlanetGroupSubscriptionAssoc.hbm.xml" />
+ <!-- Map Planet POJO classes -->
+ <mapping resource="org/apache/roller/planet/pojos/PlanetConfigData.hbm.xml" />
+ <mapping resource="org/apache/roller/planet/pojos/PlanetGroupData.hbm.xml" />
+ <mapping resource="org/apache/roller/planet/pojos/PlanetEntryData.hbm.xml" />
+ <mapping resource="org/apache/roller/planet/pojos/PlanetSubscriptionData.hbm.xml" />
+ <mapping resource="org/apache/roller/planet/pojos/PlanetGroupSubscriptionAssoc.hbm.xml" />
</session-factory>
</hibernate-configuration>
Modified: incubator/roller/trunk/sandbox/planetroller/web/index.jsp
URL: http://svn.apache.org/viewvc/incubator/roller/trunk/sandbox/planetroller/web/index.jsp?view=diff&rev=448662&r1=448661&r2=448662
==============================================================================
--- incubator/roller/trunk/sandbox/planetroller/web/index.jsp (original)
+++ incubator/roller/trunk/sandbox/planetroller/web/index.jsp Thu Sep 21 13:24:14 2006
@@ -1,7 +1,6 @@
<%@page contentType="text/html"%>
<%@page pageEncoding="UTF-8"%>
-<%@ page import="org.apache.roller.model.*" %>
-<%@ page import="org.apache.roller.pojos.*" %>
+<%@ page import="org.apache.roller.planet.model.*" %>
<%@ page import="java.io.*" %>
<%--
Licensed to the Apache Software Foundation (ASF) under one or more
@@ -34,7 +33,7 @@
</head>
<body>
<h1>Planet Roller webapp</h1>
- <p>Roller = <%= RollerFactory.getRoller() %></p>
+ <p>Planet = <%= PlanetFactory.getPlanet() %></p>
</body>
</html>