return this.getHibernateSessionFactory().getClassMetadata(classMetadata);
}
@Override
public CollectionMetadata getCollectionMetadata(String collectionMetadata) {
return this.getHibernateSessionFactory().getCollectionMetadata(collectionMetadata);
}
@Override
public Session getCurrentSession() throws HibernateException {
return this.getHibernateSessionFactory().getCurrentSession();
}
@Override
public Set getDefinedFilterNames() {
return this.getHibernateSessionFactory().getDefinedFilterNames();
}
@Override
public FilterDefinition getFilterDefinition(String definition) throws HibernateException {
return this.getHibernateSessionFactory().getFilterDefinition(definition);
}
@Override
public Statistics getStatistics() {
return this.getHibernateSessionFactory().getStatistics();
}
@Override
public TypeHelper getTypeHelper() {
return this.getHibernateSessionFactory().getTypeHelper();
}
@Override
public boolean isClosed() {
return this.getHibernateSessionFactory().isClosed();
}
@Override
public Session openSession() throws HibernateException {
return this.getHibernateSessionFactory().openSession();
}
@Override
public Session openSession(Interceptor interceptor) throws HibernateException {
return this.getHibernateSessionFactory().openSession(interceptor);
}
@Override
public Session openSession(Connection connection) {
return this.getHibernateSessionFactory().openSession(connection);
}
@Override
public Session openSession(Connection connection, Interceptor interceptor) {
return this.getHibernateSessionFactory().openSession(connection, interceptor);
}
@Override
public StatelessSession openStatelessSession() {
return this.getHibernateSessionFactory().openStatelessSession();
}
@Override
public StatelessSession openStatelessSession(Connection connection) {
return this.getHibernateSessionFactory().openStatelessSession(connection);
}
@Override
public Reference getReference() throws NamingException {
return this.getHibernateSessionFactory().getReference();
}
public void setTargetSessionFactorys(Map
this.targetSessionFactorys = targetSessionFactorys;
}
public void setDefaultTargetSessionFactory(SessionFactory defaultTargetSessionFactory) {
this.defaultTargetSessionFactory = defaultTargetSessionFactory;
}
}
上面最重要的就是getHibernateSessionFactory重写这个方法,其他方法和原来实现的无异。重写这个方法后利用CustomerContextHolder动态设置SessionFactory类型就可以动态的切换SessionFactory。
3、动态的事务管理器,因为我们这里是动态切换SessionFactory,所以事务这块也需要动态切换SessionFactory来完成事务的操作。
package com.hoo.framework.spring.support.tx;
import javax.sql.DataSource;
import org.hibernate.SessionFactory;
import org.springframework.orm.hibernate3.HibernateTransactionManager;
import org.springframework.orm.hibernate3.SessionFactoryUtils;
import com.hoo.fr