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.classic.Session;
021 import org.hibernate.engine.SessionFactoryImplementor;
022
023 import org.springframework.orm.hibernate3.SessionFactoryUtils;
024 import org.springframework.orm.hibernate3.SpringSessionContext;
025
026
029 public class ShardSpringSessionContext extends SpringSessionContext {
030
031 public ShardSpringSessionContext(SessionFactoryImplementor sessionFactory) {
032 super(null);
033 }
034
035 @Override
036 public Session currentSession() throws HibernateException {
037 try {
038 if (_shardSessionFactoryTargetSource == null) {
039 _shardSessionFactoryTargetSource =
040 (ShardSessionFactoryTargetSource)
041 PortalBeanLocatorUtil.locate(
042 "shardSessionFactoryTargetSource");
043 }
044
045 return (Session)SessionFactoryUtils.doGetSession(
046 _shardSessionFactoryTargetSource.getSessionFactory(), false);
047 }
048 catch (IllegalStateException ise) {
049 throw new HibernateException(ise);
050 }
051 }
052
053 private ShardSessionFactoryTargetSource _shardSessionFactoryTargetSource;
054
055 }