01: /**
02: * Copyright (c) 2000-2008 Liferay, Inc. All rights reserved.
03: *
04: * Permission is hereby granted, free of charge, to any person obtaining a copy
05: * of this software and associated documentation files (the "Software"), to deal
06: * in the Software without restriction, including without limitation the rights
07: * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
08: * copies of the Software, and to permit persons to whom the Software is
09: * furnished to do so, subject to the following conditions:
10: *
11: * The above copyright notice and this permission notice shall be included in
12: * all copies or substantial portions of the Software.
13: *
14: * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15: * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16: * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17: * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18: * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19: * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20: * SOFTWARE.
21: */package com.liferay.portal.service.persistence;
22:
23: import com.liferay.portal.spring.hibernate.HibernateUtil;
24:
25: import org.apache.commons.logging.Log;
26: import org.apache.commons.logging.LogFactory;
27:
28: import org.hibernate.HibernateException;
29: import org.hibernate.Session;
30: import org.hibernate.SessionFactory;
31: import org.hibernate.connection.ConnectionProvider;
32: import org.hibernate.dialect.Dialect;
33: import org.hibernate.engine.SessionFactoryImplementor;
34:
35: import org.springframework.jdbc.core.support.JdbcDaoSupport;
36:
37: /**
38: * <a href="BasePersistence.java.html"><b><i>View Source</i></b></a>
39: *
40: * @author Brian Wing Shun Chan
41: *
42: */
43: public class BasePersistence extends JdbcDaoSupport {
44:
45: public SessionFactory getSessionFactory() {
46: return _sessionFactory;
47: }
48:
49: public void setSessionFactory(SessionFactory sessionFactory) {
50: _sessionFactory = (SessionFactoryImplementor) sessionFactory;
51: _dialect = _sessionFactory.getDialect();
52:
53: if (_log.isDebugEnabled()) {
54: ConnectionProvider provider = _sessionFactory
55: .getConnectionProvider();
56:
57: _log.debug("Connection provider "
58: + provider.getClass().getName());
59: _log.debug("Dialect " + _dialect.getClass().getName());
60: }
61: }
62:
63: protected Dialect getDialect() {
64: return _dialect;
65: }
66:
67: public void closeSession(Session session) {
68: HibernateUtil.closeSession(session);
69: }
70:
71: protected Session openSession() throws HibernateException {
72: return HibernateUtil.openSession(_sessionFactory);
73: }
74:
75: protected Session openSession(SessionFactory sessionFactory)
76: throws HibernateException {
77:
78: return HibernateUtil.openSession(sessionFactory);
79: }
80:
81: private static Log _log = LogFactory.getLog(BasePersistence.class);
82:
83: private SessionFactoryImplementor _sessionFactory;
84: private Dialect _dialect;
85:
86: }
|