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