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 =
041 (SessionFactory)PortalBeanLocatorUtil.locate(
042 "liferayHibernateSessionFactory");
043 }
044
045 return (Session)SessionFactoryUtils.doGetSession(
046 _sessionFactory, false);
047 }
048 catch (IllegalStateException ise) {
049 throw new HibernateException(ise);
050 }
051 }
052
053 private SessionFactory _sessionFactory;
054
055 }