Spring3 整合Hibernate3.5 动态切换SessionFactory (切换数据库方言)(二)

2014-11-24 08:59:09 · 作者: · 浏览: 7
ation" })
public class DynamicSessionFactoryImpl implements DynamicSessionFactory {
private static final long serialVersionUID = 5384069312247414885L;
private Map targetSessionFactorys;
private SessionFactory defaultTargetSessionFactory;
/**
* @see com.hoo.framework.spring.support.core.DynamicSessionFactory#getHibernateSessionFactory()
* function: 重写这个方法,这里最关键
* @author hoojo
* @createDate 2013-10-18 上午10:45:25
*/
@Override
public SessionFactory getHibernateSessionFactory() {
SessionFactory targetSessionFactory = targetSessionFactorys.get(CustomerContextHolder.getCustomerType());
if (targetSessionFactory != null) {
return targetSessionFactory;
} else if (defaultTargetSessionFactory != null) {
return defaultTargetSessionFactory;
}
return null;
}
@Override
public void close() throws HibernateException {
this.getHibernateSessionFactory().close();
}
@Override
public boolean containsFetchProfileDefinition(String s) {
return this.getHibernateSessionFactory().containsFetchProfileDefinition(s);
}
@Override
public void evict(Class clazz) throws HibernateException {
this.getHibernateSessionFactory().evict(clazz);
}
@Override
public void evict(Class clazz, Serializable serializable) throws HibernateException {
this.getHibernateSessionFactory().evict(clazz, serializable);
}
@Override
public void evictCollection(String s) throws HibernateException {
this.getHibernateSessionFactory().evictCollection(s);
}
@Override
public void evictCollection(String s, Serializable serializable) throws HibernateException {
this.getHibernateSessionFactory().evictCollection(s, serializable);
}
@Override
public void evictEntity(String entity) throws HibernateException {
this.getHibernateSessionFactory().evictEntity(entity);
}
@Override
public void evictEntity(String entity, Serializable serializable) throws HibernateException {
this.getHibernateSessionFactory().evictEntity(entity, serializable);
}
@Override
public void evictQueries() throws HibernateException {
this.getHibernateSessionFactory().evictQueries();
}
@Override
public void evictQueries(String queries) throws HibernateException {
this.getHibernateSessionFactory().evictQueries(queries);
}
@Override
public Map getAllClassMetadata() {
return this.getHibernateSessionFactory().getAllClassMetadata();
}
@Override
public Map getAllCollectionMetadata() {
return this.getHibernateSessionFactory().getAllClassMetadata();
}
@Override
public Cache getCache() {
return this.getHibernateSessionFactory().getCache();
}
@Override
public ClassMetadata getClassMetadata(Class clazz) {
return this.getHibernateSessionFactory().getClassMetadata(clazz);
}
@Override
public ClassMetadata getClassMetadata(String classMetadata) {