1   /**
2    * Copyright (c) 2000-2009 Liferay, Inc. All rights reserved.
3    *
4    * The contents of this file are subject to the terms of the Liferay Enterprise
5    * Subscription License ("License"). You may not use this file except in
6    * compliance with the License. You can obtain a copy of the License by
7    * contacting Liferay, Inc. See the License for the specific language governing
8    * permissions and limitations under the License, including but not limited to
9    * distribution rights of the Software.
10   *
11   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
12   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
13   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
14   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
15   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
16   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
17   * SOFTWARE.
18   */
19  
20  package com.liferay.portal.dao.orm.hibernate;
21  
22  import com.liferay.portal.kernel.dao.orm.Dialect;
23  import com.liferay.portal.kernel.dao.orm.ORMException;
24  import com.liferay.portal.kernel.dao.orm.Session;
25  import com.liferay.portal.kernel.dao.orm.SessionFactory;
26  import com.liferay.portal.kernel.log.Log;
27  import com.liferay.portal.kernel.log.LogFactoryUtil;
28  import com.liferay.portal.util.PropsValues;
29  
30  import org.hibernate.engine.SessionFactoryImplementor;
31  
32  /**
33   * <a href="SessionFactoryImpl.java.html"><b><i>View Source</i></b></a>
34   *
35   * @author Brian Wing Shun Chan
36   *
37   */
38  public class SessionFactoryImpl implements SessionFactory {
39  
40      public void closeSession(Session session) throws ORMException {
41          if (!PropsValues.SPRING_HIBERNATE_SESSION_DELEGATED) {
42              session.close();
43          }
44      }
45  
46      public Dialect getDialect() throws ORMException {
47          return new DialectImpl(_sessionFactoryImplementor.getDialect());
48      }
49  
50      public SessionFactoryImplementor getSessionFactoryImplementor() {
51          return _sessionFactoryImplementor;
52      }
53  
54      public Session openSession() throws ORMException {
55          org.hibernate.Session session = null;
56  
57          if (PropsValues.SPRING_HIBERNATE_SESSION_DELEGATED) {
58              session = _sessionFactoryImplementor.getCurrentSession();
59          }
60          else {
61              session = _sessionFactoryImplementor.openSession();
62          }
63  
64          if (_log.isDebugEnabled()) {
65              LiferayClassicSession classicSession =
66                  (LiferayClassicSession)session;
67  
68              org.hibernate.impl.SessionImpl sessionImpl =
69                  (org.hibernate.impl.SessionImpl)
70                      classicSession.getHibernateClassicSession();
71  
72              _log.debug(
73                  "Session is using connection release mode " +
74                      sessionImpl.getConnectionReleaseMode());
75          }
76  
77          return new SessionImpl(session);
78      }
79  
80      public void setSessionFactoryImplementor(
81          SessionFactoryImplementor sessionFactoryImplementor) {
82  
83          _sessionFactoryImplementor = sessionFactoryImplementor;
84      }
85  
86      private static Log _log = LogFactoryUtil.getLog(SessionFactoryImpl.class);
87  
88      private SessionFactoryImplementor _sessionFactoryImplementor;
89  
90  }