001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. The ASF licenses this file to You
004: * under the Apache License, Version 2.0 (the "License"); you may not
005: * use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License. For additional information regarding
015: * copyright in this work, please see the NOTICE file in the top level
016: * directory of this distribution.
017: */
018:
019: package org.apache.roller.business.hibernate;
020:
021: import org.apache.commons.lang.StringUtils;
022: import org.apache.commons.logging.Log;
023: import org.apache.commons.logging.LogFactory;
024: import org.apache.roller.RollerException;
025: import org.apache.roller.business.RollerImpl;
026: import org.apache.roller.config.RollerConfig;
027: import org.apache.roller.business.BookmarkManager;
028: import org.apache.roller.business.ConfigManager;
029: import org.apache.roller.business.pings.AutoPingManager;
030: import org.apache.roller.business.pings.PingQueueManager;
031: import org.apache.roller.business.pings.PingTargetManager;
032: import org.apache.roller.planet.business.PlanetManager;
033: import org.apache.roller.business.PropertiesManager;
034: import org.apache.roller.business.referrers.RefererManager;
035: import org.apache.roller.business.Roller;
036: import org.apache.roller.business.UserManager;
037: import org.apache.roller.business.WeblogManager;
038: import org.apache.roller.business.runnable.ThreadManager;
039:
040: /**
041: * A Hibernate specific implementation of the Roller business layer.
042: */
043: public class HibernateRollerImpl extends RollerImpl {
044:
045: static final long serialVersionUID = 5256135928578074652L;
046:
047: private static Log mLogger = LogFactory
048: .getLog(HibernateRollerImpl.class);
049:
050: // our singleton instance
051: private static HibernateRollerImpl me = null;
052:
053: // a persistence utility class
054: private HibernatePersistenceStrategy strategy = null;
055:
056: // references to the managers we maintain
057: private BookmarkManager bookmarkManager = null;
058: private ConfigManager configManager = null;
059: private PropertiesManager propertiesManager = null;
060: private PlanetManager planetManager = null;
061: private RefererManager refererManager = null;
062: private UserManager userManager = null;
063: private WeblogManager weblogManager = null;
064: private PingQueueManager pingQueueManager = null;
065: private AutoPingManager autoPingManager = null;
066: private PingTargetManager pingTargetManager = null;
067: private ThreadManager threadManager = null;
068:
069: protected HibernateRollerImpl() throws RollerException {
070: try {
071: if (StringUtils.isNotEmpty(RollerConfig
072: .getProperty("jdbc.driverClass"))) {
073: // create and configure for JDBC access
074: strategy = new HibernatePersistenceStrategy(
075: RollerConfig
076: .getProperty("hibernate.configResource"),
077: RollerConfig.getProperty("hibernate.dialect"),
078: RollerConfig.getProperty("jdbc.driverClass"),
079: RollerConfig.getProperty("jdbc.connectionURL"),
080: RollerConfig.getProperty("jdbc.username"),
081: RollerConfig.getProperty("jdbc.password"));
082: } else {
083: // create an configure via config resource only
084: strategy = new HibernatePersistenceStrategy(
085: RollerConfig
086: .getProperty("hibernate.configResource"),
087: RollerConfig.getProperty("hibernate.dialect"));
088: }
089: } catch (Throwable t) {
090: // if this happens then we are screwed
091: mLogger.fatal("Error initializing Hibernate", t);
092: throw new RollerException(t);
093: }
094: }
095:
096: /**
097: * Instantiates and returns an instance of HibernateRollerImpl.
098: */
099: public static Roller instantiate() throws RollerException {
100: if (me == null) {
101: mLogger.debug("Instantiating HibernateRollerImpl");
102: me = new HibernateRollerImpl();
103: }
104:
105: return me;
106: }
107:
108: public void flush() throws RollerException {
109: this .strategy.flush();
110: }
111:
112: public void release() {
113:
114: // release our own stuff first
115: if (bookmarkManager != null)
116: bookmarkManager.release();
117: if (configManager != null)
118: configManager.release();
119: if (refererManager != null)
120: refererManager.release();
121: if (userManager != null)
122: userManager.release();
123: if (weblogManager != null)
124: weblogManager.release();
125: if (pingTargetManager != null)
126: pingTargetManager.release();
127: if (pingQueueManager != null)
128: pingQueueManager.release();
129: if (autoPingManager != null)
130: autoPingManager.release();
131: if (threadManager != null)
132: threadManager.release();
133:
134: // tell Hibernate to close down
135: this .strategy.release();
136:
137: // then let parent do its thing
138: super .release();
139: }
140:
141: public void shutdown() {
142:
143: // do our own shutdown first
144: this .release();
145:
146: // then let parent do its thing
147: super .shutdown();
148: }
149:
150: /**
151: * @see org.apache.roller.model.Roller#getUserManager()
152: */
153: public UserManager getUserManager() throws RollerException {
154: if (userManager == null) {
155: userManager = new HibernateUserManagerImpl(strategy);
156: }
157: return userManager;
158: }
159:
160: /**
161: * @see org.apache.roller.model.Roller#getBookmarkManager()
162: */
163: public BookmarkManager getBookmarkManager() throws RollerException {
164: if (bookmarkManager == null) {
165: bookmarkManager = new HibernateBookmarkManagerImpl(strategy);
166: }
167: return bookmarkManager;
168: }
169:
170: /**
171: * @see org.apache.roller.model.Roller#getWeblogManager()
172: */
173: public WeblogManager getWeblogManager() throws RollerException {
174: if (weblogManager == null) {
175: weblogManager = new HibernateWeblogManagerImpl(strategy);
176: }
177: return weblogManager;
178: }
179:
180: /**
181: * @see org.apache.roller.model.Roller#getRefererManager()
182: */
183: public RefererManager getRefererManager() throws RollerException {
184: if (refererManager == null) {
185: refererManager = new HibernateRefererManagerImpl(strategy);
186: }
187: return refererManager;
188: }
189:
190: /**
191: * @see org.apache.roller.model.Roller#getConfigManager()
192: */
193: public ConfigManager getConfigManager() throws RollerException {
194: if (configManager == null) {
195: configManager = new HibernateConfigManagerImpl(strategy);
196: }
197: return configManager;
198: }
199:
200: /**
201: * @see org.apache.roller.model.Roller#getPropertiesManager()
202: */
203: public PropertiesManager getPropertiesManager()
204: throws RollerException {
205: if (propertiesManager == null) {
206: propertiesManager = new HibernatePropertiesManagerImpl(
207: strategy);
208: }
209: return propertiesManager;
210: }
211:
212: /**
213: * @see org.apache.roller.model.Roller#getPingTargetManager()
214: */
215: public PingQueueManager getPingQueueManager()
216: throws RollerException {
217: if (pingQueueManager == null) {
218: pingQueueManager = new HibernatePingQueueManagerImpl(
219: strategy);
220: }
221: return pingQueueManager;
222: }
223:
224: /**
225: * @see org.apache.roller.model.Roller#getPlanetManager()
226: */
227: public PlanetManager getPlanetManager() throws RollerException {
228: if (planetManager == null) {
229: planetManager = new HibernateRollerPlanetManagerImpl(
230: strategy);
231: }
232: return planetManager;
233: }
234:
235: /**
236: * @see org.apache.roller.model.Roller#getPingTargetManager()
237: */
238: public AutoPingManager getAutopingManager() throws RollerException {
239: if (autoPingManager == null) {
240: autoPingManager = new HibernateAutoPingManagerImpl(strategy);
241: }
242: return autoPingManager;
243: }
244:
245: /**
246: * @see org.apache.roller.model.Roller#getPingTargetManager()
247: */
248: public PingTargetManager getPingTargetManager()
249: throws RollerException {
250: if (pingTargetManager == null) {
251: pingTargetManager = new HibernatePingTargetManagerImpl(
252: strategy);
253: }
254: return pingTargetManager;
255: }
256:
257: /**
258: * @see org.apache.roller.model.Roller#getThreadManager()
259: */
260: public ThreadManager getThreadManager() throws RollerException {
261: if (threadManager == null) {
262: threadManager = new HibernateThreadManagerImpl(strategy);
263: }
264: return threadManager;
265: }
266:
267: }
|