Browse Source

LocalSessionFactoryBean's "entityCacheStrategies" works with region names on Hibernate 3.6 as well

pull/1234/head
Juergen Hoeller 14 years ago
parent
commit
91a53a36ec
  1. 9
      org.springframework.orm/src/main/java/org/springframework/orm/hibernate3/LocalSessionFactoryBean.java
  2. 15
      org.springframework.orm/src/test/java/org/springframework/orm/hibernate3/LocalSessionFactoryBeanTests.java

9
org.springframework.orm/src/main/java/org/springframework/orm/hibernate3/LocalSessionFactoryBean.java

@ -88,7 +88,7 @@ import org.springframework.util.StringUtils; @@ -88,7 +88,7 @@ import org.springframework.util.StringUtils;
* {@link org.springframework.orm.hibernate3.support.OpenSessionInViewFilter} /
* {@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
* release mode, unless in the case of a "jtaTransactionManager" specified,
* for the reason that this is appropriate for most Spring-based applications
@ -723,7 +723,12 @@ public class LocalSessionFactoryBean extends AbstractSessionFactoryBean implemen @@ -723,7 +723,12 @@ public class LocalSessionFactoryBean extends AbstractSessionFactoryBean implemen
String[] strategyAndRegion =
StringUtils.commaDelimitedListToStringArray(this.entityCacheStrategies.getProperty(className));
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) {
config.setCacheConcurrencyStrategy(className, strategyAndRegion[0]);

15
org.springframework.orm/src/test/java/org/springframework/orm/hibernate3/LocalSessionFactoryBeanTests.java

@ -1,5 +1,5 @@ @@ -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");
* you may not use this file except in compliance with the License.
@ -428,14 +428,12 @@ public class LocalSessionFactoryBeanTests extends TestCase { @@ -428,14 +428,12 @@ public class LocalSessionFactoryBeanTests extends TestCase {
registeredClassCache.setProperty(clazz, concurrencyStrategy);
return this;
}
public Configuration setCollectionCacheConcurrencyStrategy(String collectionRole, String concurrencyStrategy) {
registeredCollectionCache.setProperty(collectionRole, concurrencyStrategy);
return this;
}
};
}
protected SessionFactory newSessionFactory(Configuration config) {
return null;
}
@ -461,16 +459,15 @@ public class LocalSessionFactoryBeanTests extends TestCase { @@ -461,16 +459,15 @@ public class LocalSessionFactoryBeanTests extends TestCase {
LocalSessionFactoryBean sfb = new LocalSessionFactoryBean() {
protected Configuration newConfiguration() {
return new Configuration() {
// changed from return type 'void' to 'Configuration' in Hibernate 3.6
public void setCacheConcurrencyStrategy(String clazz, String concurrencyStrategy, String regionName) {
registeredClassCache.setProperty(clazz, concurrencyStrategy + "," + regionName);
}
public void setCollectionCacheConcurrencyStrategy(String collectionRole, String concurrencyStrategy, String regionName) {
registeredCollectionCache.setProperty(collectionRole, concurrencyStrategy + "," + regionName);
}
};
}
protected SessionFactory newSessionFactory(Configuration config) {
return null;
}
@ -500,7 +497,6 @@ public class LocalSessionFactoryBeanTests extends TestCase { @@ -500,7 +497,6 @@ public class LocalSessionFactoryBeanTests extends TestCase {
}
};
}
protected SessionFactory newSessionFactory(Configuration config) {
return null;
}
@ -526,7 +522,6 @@ public class LocalSessionFactoryBeanTests extends TestCase { @@ -526,7 +522,6 @@ public class LocalSessionFactoryBeanTests extends TestCase {
}
};
}
protected SessionFactory newSessionFactory(Configuration config) {
return null;
}
@ -564,8 +559,10 @@ public class LocalSessionFactoryBeanTests extends TestCase { @@ -564,8 +559,10 @@ public class LocalSessionFactoryBeanTests extends TestCase {
public void testLocalSessionFactoryBeanWithTypeDefinitions() throws Exception {
XmlBeanFactory xbf = new XmlBeanFactory(new ClassPathResource("typeDefinitions.xml", getClass()));
TypeTestLocalSessionFactoryBean sf = (TypeTestLocalSessionFactoryBean) xbf.getBean("&sessionFactory");
TypeDef type1 = (TypeDef) sf.mappings.getTypeDef("type1");
TypeDef type2 = (TypeDef) sf.mappings.getTypeDef("type2");
// Requires re-compilation when switching to Hibernate 3.5/3.6
// 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(2, type1.getParameters().size());

Loading…
Cancel
Save