Skip to content

Commit 541f3ed

Browse files
committed
Fully upgraded orm.hibernate3 package to require Hibernate 3.6+ now
1 parent e11cf5f commit 541f3ed

File tree

5 files changed

+20
-82
lines changed

5 files changed

+20
-82
lines changed

spring-orm/src/main/java/org/springframework/orm/hibernate3/FilterDefinitionFactoryBean.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,7 @@ public void setFilterName(String filterName) {
8585
/**
8686
* Set the parameter types for the filter,
8787
* with parameter names as keys and type names as values.
88-
* See {@code org.hibernate.type.TypeFactory#heuristicType(String)} (Hibernate 3.x)
89-
* or {@code org.hibernate.type.TypeResolver#heuristicType(String)} (Hibernate 4.x)
88+
* See {@code org.hibernate.type.TypeResolver#heuristicType(String)}.
9089
*/
9190
public void setParameterTypes(Map<String, String> parameterTypes) {
9291
if (parameterTypes != null) {

spring-orm/src/main/java/org/springframework/orm/hibernate3/HibernateTransactionManager.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@
110110
* support nested transactions! Hence, do not expect Hibernate access code to
111111
* semantically participate in a nested transaction.</i>
112112
*
113-
* <p>Requires Hibernate 3.2 or later, as of Spring 3.0.
113+
* <p>Requires Hibernate 3.6 or later, as of Spring 4.0.
114114
*
115115
* @author Juergen Hoeller
116116
* @since 1.2

spring-orm/src/main/java/org/springframework/orm/hibernate3/LocalRegionFactoryProxy.java

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2012 the original author or authors.
2+
* Copyright 2002-2013 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -36,9 +36,6 @@
3636
* RegionFactory instance, determined by LocalSessionFactoryBean's
3737
* "cacheRegionFactory" property.
3838
*
39-
* <p>Compatible with Hibernate 3.3 as well as Hibernate 3.5's version
40-
* of the RegionFactory SPI.
41-
*
4239
* @author Juergen Hoeller
4340
* @since 3.0
4441
* @see LocalSessionFactoryBean#setCacheRegionFactory
@@ -83,13 +80,7 @@ public boolean isMinimalPutsEnabledByDefault() {
8380
}
8481

8582
public AccessType getDefaultAccessType() {
86-
try {
87-
Method method = RegionFactory.class.getMethod("getDefaultAccessType");
88-
return (AccessType) ReflectionUtils.invokeMethod(method, this.regionFactory);
89-
}
90-
catch (NoSuchMethodException ex) {
91-
throw new IllegalStateException("getDefaultAccessType requires Hibernate 3.5+");
92-
}
83+
return this.regionFactory.getDefaultAccessType();
9384
}
9485

9586
public long nextTimestamp() {

spring-orm/src/main/java/org/springframework/orm/hibernate3/LocalSessionFactoryBean.java

Lines changed: 8 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2012 the original author or authors.
2+
* Copyright 2002-2013 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -18,15 +18,13 @@
1818

1919
import java.io.File;
2020
import java.lang.reflect.Array;
21-
import java.lang.reflect.Method;
2221
import java.sql.Connection;
2322
import java.sql.SQLException;
2423
import java.sql.Statement;
2524
import java.util.Collection;
2625
import java.util.Enumeration;
2726
import java.util.Map;
2827
import java.util.Properties;
29-
3028
import javax.sql.DataSource;
3129
import javax.transaction.TransactionManager;
3230

@@ -37,13 +35,15 @@
3735
import org.hibernate.cache.RegionFactory;
3836
import org.hibernate.cfg.Configuration;
3937
import org.hibernate.cfg.Environment;
38+
import org.hibernate.cfg.Mappings;
4039
import org.hibernate.cfg.NamingStrategy;
4140
import org.hibernate.dialect.Dialect;
4241
import org.hibernate.engine.FilterDefinition;
4342
import org.hibernate.engine.SessionFactoryImplementor;
4443
import org.hibernate.event.EventListeners;
4544
import org.hibernate.tool.hbm2ddl.DatabaseMetadata;
4645
import org.hibernate.transaction.JTATransactionFactory;
46+
4747
import org.springframework.beans.BeanUtils;
4848
import org.springframework.beans.factory.BeanClassLoaderAware;
4949
import org.springframework.core.io.ClassPathResource;
@@ -53,7 +53,6 @@
5353
import org.springframework.jdbc.support.JdbcUtils;
5454
import org.springframework.jdbc.support.lob.LobHandler;
5555
import org.springframework.util.ClassUtils;
56-
import org.springframework.util.ReflectionUtils;
5756
import org.springframework.util.StringUtils;
5857

5958
/**
@@ -89,7 +88,7 @@
8988
* {@link org.springframework.orm.hibernate3.support.OpenSessionInViewFilter} /
9089
* {@link org.springframework.orm.hibernate3.support.OpenSessionInViewInterceptor}.
9190
*
92-
* <p><b>Requires Hibernate 3.2 or later; tested with 3.3, 3.5 and 3.6.</b>
91+
* <p><b>Requires Hibernate 3.6 or later.</b>
9392
* Note that this factory will use "on_close" as default Hibernate connection
9493
* release mode, unless in the case of a "jtaTransactionManager" specified,
9594
* for the reason that this is appropriate for most Spring-based applications
@@ -583,15 +582,9 @@ protected SessionFactory buildSessionFactory() throws Exception {
583582

584583
if (this.typeDefinitions != null) {
585584
// Register specified Hibernate type definitions.
586-
// Use reflection for compatibility with both Hibernate 3.3 and 3.5:
587-
// the returned Mappings object changed from a class to an interface.
588-
Method createMappings = Configuration.class.getMethod("createMappings");
589-
Method addTypeDef = createMappings.getReturnType().getMethod(
590-
"addTypeDef", String.class, String.class, Properties.class);
591-
Object mappings = ReflectionUtils.invokeMethod(createMappings, config);
585+
Mappings mappings = config.createMappings();
592586
for (TypeDefinitionBean typeDef : this.typeDefinitions) {
593-
ReflectionUtils.invokeMethod(addTypeDef, mappings,
594-
typeDef.getTypeName(), typeDef.getTypeClass(), typeDef.getParameters());
587+
mappings.addTypeDef(typeDef.getTypeName(), typeDef.getTypeClass(), typeDef.getParameters());
595588
}
596589
}
597590

@@ -628,8 +621,7 @@ else if (config.getProperty(Environment.TRANSACTION_MANAGER_STRATEGY) != null) {
628621

629622
if (this.cacheRegionFactory != null) {
630623
// Expose Spring-provided Hibernate RegionFactory.
631-
config.setProperty(Environment.CACHE_REGION_FACTORY,
632-
"org.springframework.orm.hibernate3.LocalRegionFactoryProxy");
624+
config.setProperty(Environment.CACHE_REGION_FACTORY, LocalRegionFactoryProxy.class.getName());
633625
}
634626

635627
if (this.mappingResources != null) {
@@ -685,12 +677,7 @@ else if (config.getProperty(Environment.TRANSACTION_MANAGER_STRATEGY) != null) {
685677
String[] strategyAndRegion =
686678
StringUtils.commaDelimitedListToStringArray(this.entityCacheStrategies.getProperty(className));
687679
if (strategyAndRegion.length > 1) {
688-
// method signature declares return type as Configuration on Hibernate 3.6
689-
// but as void on Hibernate 3.3 and 3.5
690-
Method setCacheConcurrencyStrategy = Configuration.class.getMethod(
691-
"setCacheConcurrencyStrategy", String.class, String.class, String.class);
692-
ReflectionUtils.invokeMethod(setCacheConcurrencyStrategy, config,
693-
className, strategyAndRegion[0], strategyAndRegion[1]);
680+
config.setCacheConcurrencyStrategy(className, strategyAndRegion[0], strategyAndRegion[1]);
694681
}
695682
else if (strategyAndRegion.length > 0) {
696683
config.setCacheConcurrencyStrategy(className, strategyAndRegion[0]);

spring-orm/src/main/java/org/springframework/orm/hibernate3/annotation/AnnotationSessionFactoryBean.java

Lines changed: 8 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323

2424
import org.hibernate.HibernateException;
2525
import org.hibernate.MappingException;
26-
import org.hibernate.cfg.AnnotationConfiguration;
2726
import org.hibernate.cfg.Configuration;
2827

2928
import org.springframework.context.ResourceLoaderAware;
@@ -44,8 +43,8 @@
4443
* Subclass of Spring's standard LocalSessionFactoryBean for Hibernate,
4544
* supporting JDK 1.5+ annotation metadata for mappings.
4645
*
47-
* <p>Note: This class requires Hibernate 3.2 or later, with the
48-
* Java Persistence API and the Hibernate Annotations add-on present.
46+
* <p>Note: As of Spring 4.0, this class requires Hibernate 3.6 or later,
47+
* with the Java Persistence API present.
4948
*
5049
* <p>Example for an AnnotationSessionFactoryBean bean definition:
5150
*
@@ -97,24 +96,10 @@ public class AnnotationSessionFactoryBean extends LocalSessionFactoryBean implem
9796
private ResourcePatternResolver resourcePatternResolver = new PathMatchingResourcePatternResolver();
9897

9998

100-
public AnnotationSessionFactoryBean() {
101-
setConfigurationClass(AnnotationConfiguration.class);
102-
}
103-
104-
105-
@Override
106-
public void setConfigurationClass(Class<?> configurationClass) {
107-
if (configurationClass == null || !AnnotationConfiguration.class.isAssignableFrom(configurationClass)) {
108-
throw new IllegalArgumentException(
109-
"AnnotationSessionFactoryBean only supports AnnotationConfiguration or subclasses");
110-
}
111-
super.setConfigurationClass(configurationClass);
112-
}
113-
11499
/**
115100
* Specify annotated classes, for which mappings will be read from
116101
* class-level JDK 1.5+ annotation metadata.
117-
* @see org.hibernate.cfg.AnnotationConfiguration#addAnnotatedClass(Class)
102+
* @see org.hibernate.cfg.Configuration#addAnnotatedClass(Class)
118103
*/
119104
public void setAnnotatedClasses(Class[] annotatedClasses) {
120105
this.annotatedClasses = annotatedClasses;
@@ -123,7 +108,7 @@ public void setAnnotatedClasses(Class[] annotatedClasses) {
123108
/**
124109
* Specify the names of annotated packages, for which package-level
125110
* JDK 1.5+ annotation metadata will be read.
126-
* @see org.hibernate.cfg.AnnotationConfiguration#addPackage(String)
111+
* @see org.hibernate.cfg.Configuration#addPackage(String)
127112
*/
128113
public void setAnnotatedPackages(String[] annotatedPackages) {
129114
this.annotatedPackages = annotatedPackages;
@@ -163,25 +148,24 @@ public void setResourceLoader(ResourceLoader resourceLoader) {
163148
*/
164149
@Override
165150
protected void postProcessMappings(Configuration config) throws HibernateException {
166-
AnnotationConfiguration annConfig = (AnnotationConfiguration) config;
167151
if (this.annotatedClasses != null) {
168152
for (Class annotatedClass : this.annotatedClasses) {
169-
annConfig.addAnnotatedClass(annotatedClass);
153+
config.addAnnotatedClass(annotatedClass);
170154
}
171155
}
172156
if (this.annotatedPackages != null) {
173157
for (String annotatedPackage : this.annotatedPackages) {
174-
annConfig.addPackage(annotatedPackage);
158+
config.addPackage(annotatedPackage);
175159
}
176160
}
177-
scanPackages(annConfig);
161+
scanPackages(config);
178162
}
179163

180164
/**
181165
* Perform Spring-based scanning for entity classes.
182166
* @see #setPackagesToScan
183167
*/
184-
protected void scanPackages(AnnotationConfiguration config) {
168+
protected void scanPackages(Configuration config) {
185169
if (this.packagesToScan != null) {
186170
try {
187171
for (String pkg : this.packagesToScan) {
@@ -227,27 +211,4 @@ private boolean matchesEntityTypeFilter(MetadataReader reader, MetadataReaderFac
227211
return false;
228212
}
229213

230-
231-
/**
232-
* This default implementation delegates to {@link #postProcessAnnotationConfiguration}.
233-
*/
234-
@Override
235-
protected void postProcessConfiguration(Configuration config) throws HibernateException {
236-
postProcessAnnotationConfiguration((AnnotationConfiguration) config);
237-
}
238-
239-
/**
240-
* To be implemented by subclasses which want to to perform custom
241-
* post-processing of the AnnotationConfiguration object after this
242-
* FactoryBean performed its default initialization.
243-
* <p>Note: As of Hibernate 3.6, AnnotationConfiguration's features
244-
* have been rolled into Configuration itself. Simply overriding
245-
* {@link #postProcessConfiguration(org.hibernate.cfg.Configuration)}
246-
* becomes an option as well then.
247-
* @param config the current AnnotationConfiguration object
248-
* @throws HibernateException in case of Hibernate initialization errors
249-
*/
250-
protected void postProcessAnnotationConfiguration(AnnotationConfiguration config) throws HibernateException {
251-
}
252-
253214
}

0 commit comments

Comments
 (0)