1
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
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 }