LocalSessionFactoryBean's "entityCacheStrategies" works with region names on Hibernate 3.6 as well
This commit is contained in:
parent
1247d2085b
commit
91a53a36ec
|
|
@ -88,7 +88,7 @@ import org.springframework.util.StringUtils;
|
||||||
* {@link org.springframework.orm.hibernate3.support.OpenSessionInViewFilter} /
|
* {@link org.springframework.orm.hibernate3.support.OpenSessionInViewFilter} /
|
||||||
* {@link org.springframework.orm.hibernate3.support.OpenSessionInViewInterceptor}.
|
* {@link org.springframework.orm.hibernate3.support.OpenSessionInViewInterceptor}.
|
||||||
*
|
*
|
||||||
* <p><b>Requires Hibernate 3.2 or later, with Hibernate 3.3 being recommended.</b>
|
* <p><b>Requires Hibernate 3.2 or later; tested with 3.3, 3.5 and 3.6.</b>
|
||||||
* Note that this factory will use "on_close" as default Hibernate connection
|
* Note that this factory will use "on_close" as default Hibernate connection
|
||||||
* release mode, unless in the case of a "jtaTransactionManager" specified,
|
* release mode, unless in the case of a "jtaTransactionManager" specified,
|
||||||
* for the reason that this is appropriate for most Spring-based applications
|
* for the reason that this is appropriate for most Spring-based applications
|
||||||
|
|
@ -723,7 +723,12 @@ public class LocalSessionFactoryBean extends AbstractSessionFactoryBean implemen
|
||||||
String[] strategyAndRegion =
|
String[] strategyAndRegion =
|
||||||
StringUtils.commaDelimitedListToStringArray(this.entityCacheStrategies.getProperty(className));
|
StringUtils.commaDelimitedListToStringArray(this.entityCacheStrategies.getProperty(className));
|
||||||
if (strategyAndRegion.length > 1) {
|
if (strategyAndRegion.length > 1) {
|
||||||
config.setCacheConcurrencyStrategy(className, strategyAndRegion[0], strategyAndRegion[1]);
|
// method signature declares return type as Configuration on Hibernate 3.6
|
||||||
|
// but as void on Hibernate 3.3 and 3.5
|
||||||
|
Method setCacheConcurrencyStrategy = Configuration.class.getMethod(
|
||||||
|
"setCacheConcurrencyStrategy", String.class, String.class, String.class);
|
||||||
|
ReflectionUtils.invokeMethod(setCacheConcurrencyStrategy, config,
|
||||||
|
className, strategyAndRegion[0], strategyAndRegion[1]);
|
||||||
}
|
}
|
||||||
else if (strategyAndRegion.length > 0) {
|
else if (strategyAndRegion.length > 0) {
|
||||||
config.setCacheConcurrencyStrategy(className, strategyAndRegion[0]);
|
config.setCacheConcurrencyStrategy(className, strategyAndRegion[0]);
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2008 the original author or authors.
|
* Copyright 2002-2010 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|
@ -428,14 +428,12 @@ public class LocalSessionFactoryBeanTests extends TestCase {
|
||||||
registeredClassCache.setProperty(clazz, concurrencyStrategy);
|
registeredClassCache.setProperty(clazz, concurrencyStrategy);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Configuration setCollectionCacheConcurrencyStrategy(String collectionRole, String concurrencyStrategy) {
|
public Configuration setCollectionCacheConcurrencyStrategy(String collectionRole, String concurrencyStrategy) {
|
||||||
registeredCollectionCache.setProperty(collectionRole, concurrencyStrategy);
|
registeredCollectionCache.setProperty(collectionRole, concurrencyStrategy);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
protected SessionFactory newSessionFactory(Configuration config) {
|
protected SessionFactory newSessionFactory(Configuration config) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
@ -461,16 +459,15 @@ public class LocalSessionFactoryBeanTests extends TestCase {
|
||||||
LocalSessionFactoryBean sfb = new LocalSessionFactoryBean() {
|
LocalSessionFactoryBean sfb = new LocalSessionFactoryBean() {
|
||||||
protected Configuration newConfiguration() {
|
protected Configuration newConfiguration() {
|
||||||
return new Configuration() {
|
return new Configuration() {
|
||||||
|
// changed from return type 'void' to 'Configuration' in Hibernate 3.6
|
||||||
public void setCacheConcurrencyStrategy(String clazz, String concurrencyStrategy, String regionName) {
|
public void setCacheConcurrencyStrategy(String clazz, String concurrencyStrategy, String regionName) {
|
||||||
registeredClassCache.setProperty(clazz, concurrencyStrategy + "," + regionName);
|
registeredClassCache.setProperty(clazz, concurrencyStrategy + "," + regionName);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setCollectionCacheConcurrencyStrategy(String collectionRole, String concurrencyStrategy, String regionName) {
|
public void setCollectionCacheConcurrencyStrategy(String collectionRole, String concurrencyStrategy, String regionName) {
|
||||||
registeredCollectionCache.setProperty(collectionRole, concurrencyStrategy + "," + regionName);
|
registeredCollectionCache.setProperty(collectionRole, concurrencyStrategy + "," + regionName);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
protected SessionFactory newSessionFactory(Configuration config) {
|
protected SessionFactory newSessionFactory(Configuration config) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
@ -500,7 +497,6 @@ public class LocalSessionFactoryBeanTests extends TestCase {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
protected SessionFactory newSessionFactory(Configuration config) {
|
protected SessionFactory newSessionFactory(Configuration config) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
@ -526,7 +522,6 @@ public class LocalSessionFactoryBeanTests extends TestCase {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
protected SessionFactory newSessionFactory(Configuration config) {
|
protected SessionFactory newSessionFactory(Configuration config) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
@ -564,8 +559,10 @@ public class LocalSessionFactoryBeanTests extends TestCase {
|
||||||
public void testLocalSessionFactoryBeanWithTypeDefinitions() throws Exception {
|
public void testLocalSessionFactoryBeanWithTypeDefinitions() throws Exception {
|
||||||
XmlBeanFactory xbf = new XmlBeanFactory(new ClassPathResource("typeDefinitions.xml", getClass()));
|
XmlBeanFactory xbf = new XmlBeanFactory(new ClassPathResource("typeDefinitions.xml", getClass()));
|
||||||
TypeTestLocalSessionFactoryBean sf = (TypeTestLocalSessionFactoryBean) xbf.getBean("&sessionFactory");
|
TypeTestLocalSessionFactoryBean sf = (TypeTestLocalSessionFactoryBean) xbf.getBean("&sessionFactory");
|
||||||
TypeDef type1 = (TypeDef) sf.mappings.getTypeDef("type1");
|
// Requires re-compilation when switching to Hibernate 3.5/3.6
|
||||||
TypeDef type2 = (TypeDef) sf.mappings.getTypeDef("type2");
|
// since Mappings changed from a class to an interface
|
||||||
|
TypeDef type1 = sf.mappings.getTypeDef("type1");
|
||||||
|
TypeDef type2 = sf.mappings.getTypeDef("type2");
|
||||||
|
|
||||||
assertEquals("mypackage.MyTypeClass", type1.getTypeClass());
|
assertEquals("mypackage.MyTypeClass", type1.getTypeClass());
|
||||||
assertEquals(2, type1.getParameters().size());
|
assertEquals(2, type1.getParameters().size());
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue