001
014
015 package com.liferay.portal.dao.shard;
016
017 import com.liferay.portal.kernel.bean.PortalBeanLocatorUtil;
018
019 import org.hibernate.HibernateException;
020 import org.hibernate.SessionFactory;
021 import org.hibernate.classic.Session;
022 import org.hibernate.engine.SessionFactoryImplementor;
023
024 import org.springframework.orm.hibernate3.SessionFactoryUtils;
025 import org.springframework.orm.hibernate3.SpringSessionContext;
026
027
030 public class ShardSpringSessionContext extends SpringSessionContext {
031
032 public ShardSpringSessionContext(SessionFactoryImplementor sessionFactory) {
033 super(null);
034 }
035
036 @Override
037 public Session currentSession() throws HibernateException {
038 try {
039 if (_sessionFactory == null) {
040 _sessionFactory = (SessionFactory)PortalBeanLocatorUtil.locate(
041 "liferayHibernateSessionFactory");
042 }
043
044 return (Session)SessionFactoryUtils.doGetSession(
045 _sessionFactory, false);
046 }
047 catch (IllegalStateException ise) {
048 throw new HibernateException(ise);
049 }
050 }
051
052 private SessionFactory _sessionFactory;
053
054 }