Skip to content

Commit 7e2167f

Browse files
committed
Specific deprecations and consistent setter varargs in Hibernate support
Issue: SPR-11291
1 parent 09ad834 commit 7e2167f

File tree

10 files changed

+99
-76
lines changed

10 files changed

+99
-76
lines changed

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

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2013 the original author or authors.
2+
* Copyright 2002-2014 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.
@@ -126,7 +126,7 @@ public void setConfigLocation(Resource configLocation) {
126126
* resources are specified locally via this bean.
127127
* @see org.hibernate.cfg.Configuration#configure(java.net.URL)
128128
*/
129-
public void setConfigLocations(Resource[] configLocations) {
129+
public void setConfigLocations(Resource... configLocations) {
130130
this.configLocations = configLocations;
131131
}
132132

@@ -140,7 +140,7 @@ public void setConfigLocations(Resource[] configLocations) {
140140
* @see #setMappingLocations
141141
* @see org.hibernate.cfg.Configuration#addResource
142142
*/
143-
public void setMappingResources(String[] mappingResources) {
143+
public void setMappingResources(String... mappingResources) {
144144
this.mappingResources = mappingResources;
145145
}
146146

@@ -153,7 +153,7 @@ public void setMappingResources(String[] mappingResources) {
153153
* or to specify all mappings locally.
154154
* @see org.hibernate.cfg.Configuration#addInputStream
155155
*/
156-
public void setMappingLocations(Resource[] mappingLocations) {
156+
public void setMappingLocations(Resource... mappingLocations) {
157157
this.mappingLocations = mappingLocations;
158158
}
159159

@@ -166,7 +166,7 @@ public void setMappingLocations(Resource[] mappingLocations) {
166166
* or to specify all mappings locally.
167167
* @see org.hibernate.cfg.Configuration#addCacheableFile(java.io.File)
168168
*/
169-
public void setCacheableMappingLocations(Resource[] cacheableMappingLocations) {
169+
public void setCacheableMappingLocations(Resource... cacheableMappingLocations) {
170170
this.cacheableMappingLocations = cacheableMappingLocations;
171171
}
172172

@@ -177,7 +177,7 @@ public void setCacheableMappingLocations(Resource[] cacheableMappingLocations) {
177177
* or to specify all mappings locally.
178178
* @see org.hibernate.cfg.Configuration#addJar(java.io.File)
179179
*/
180-
public void setMappingJarLocations(Resource[] mappingJarLocations) {
180+
public void setMappingJarLocations(Resource... mappingJarLocations) {
181181
this.mappingJarLocations = mappingJarLocations;
182182
}
183183

@@ -188,7 +188,7 @@ public void setMappingJarLocations(Resource[] mappingJarLocations) {
188188
* or to specify all mappings locally.
189189
* @see org.hibernate.cfg.Configuration#addDirectory(java.io.File)
190190
*/
191-
public void setMappingDirectoryLocations(Resource[] mappingDirectoryLocations) {
191+
public void setMappingDirectoryLocations(Resource... mappingDirectoryLocations) {
192192
this.mappingDirectoryLocations = mappingDirectoryLocations;
193193
}
194194

@@ -237,7 +237,7 @@ public Properties getHibernateProperties() {
237237
* Specify annotated entity classes to register with this Hibernate SessionFactory.
238238
* @see org.hibernate.cfg.Configuration#addAnnotatedClass(Class)
239239
*/
240-
public void setAnnotatedClasses(Class<?>[] annotatedClasses) {
240+
public void setAnnotatedClasses(Class<?>... annotatedClasses) {
241241
this.annotatedClasses = annotatedClasses;
242242
}
243243

@@ -246,7 +246,7 @@ public void setAnnotatedClasses(Class<?>[] annotatedClasses) {
246246
* annotation metadata will be read.
247247
* @see org.hibernate.cfg.Configuration#addPackage(String)
248248
*/
249-
public void setAnnotatedPackages(String[] annotatedPackages) {
249+
public void setAnnotatedPackages(String... annotatedPackages) {
250250
this.annotatedPackages = annotatedPackages;
251251
}
252252

spring-orm-hibernate4/src/main/java/org/springframework/orm/hibernate4/support/OpenSessionInViewInterceptor.java

Lines changed: 13 additions & 8 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.
@@ -16,24 +16,23 @@
1616

1717
package org.springframework.orm.hibernate4.support;
1818

19-
import java.util.concurrent.Callable;
20-
2119
import org.apache.commons.logging.Log;
2220
import org.apache.commons.logging.LogFactory;
2321
import org.hibernate.FlushMode;
2422
import org.hibernate.HibernateException;
2523
import org.hibernate.Session;
2624
import org.hibernate.SessionFactory;
25+
2726
import org.springframework.dao.DataAccessException;
2827
import org.springframework.dao.DataAccessResourceFailureException;
2928
import org.springframework.orm.hibernate4.SessionFactoryUtils;
3029
import org.springframework.orm.hibernate4.SessionHolder;
3130
import org.springframework.transaction.support.TransactionSynchronizationManager;
3231
import org.springframework.ui.ModelMap;
3332
import org.springframework.web.context.request.AsyncWebRequestInterceptor;
34-
import org.springframework.web.context.request.NativeWebRequest;
3533
import org.springframework.web.context.request.WebRequest;
36-
import org.springframework.web.context.request.async.*;
34+
import org.springframework.web.context.request.async.WebAsyncManager;
35+
import org.springframework.web.context.request.async.WebAsyncUtils;
3736

3837
/**
3938
* Spring web request interceptor that binds a Hibernate {@code Session} to the
@@ -79,22 +78,28 @@ public class OpenSessionInViewInterceptor implements AsyncWebRequestInterceptor
7978
private SessionFactory sessionFactory;
8079

8180

81+
/**
82+
* Set the Hibernate SessionFactory that should be used to create
83+
* Hibernate Sessions.
84+
*/
8285
public void setSessionFactory(SessionFactory sessionFactory) {
8386
this.sessionFactory = sessionFactory;
8487
}
8588

89+
/**
90+
* Return the Hibernate SessionFactory that should be used to create
91+
* Hibernate Sessions.
92+
*/
8693
public SessionFactory getSessionFactory() {
8794
return this.sessionFactory;
8895
}
8996

9097

9198
/**
92-
* Open a new Hibernate {@code Session} according to the settings of this
93-
* {@code HibernateAccessor} and bind it to the thread via the
99+
* Open a new Hibernate {@code Session} according and bind it to the thread via the
94100
* {@link org.springframework.transaction.support.TransactionSynchronizationManager}.
95101
*/
96102
public void preHandle(WebRequest request) throws DataAccessException {
97-
98103
String participateAttributeName = getParticipateAttributeName();
99104

100105
WebAsyncManager asyncManager = WebAsyncUtils.getAsyncManager(request);

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

Lines changed: 6 additions & 6 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-2014 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.
@@ -289,7 +289,7 @@ public void setFilterName(String filter) {
289289
* @see org.hibernate.Session#enableFilter(String)
290290
* @see LocalSessionFactoryBean#setFilterDefinitions
291291
*/
292-
public void setFilterNames(String[] filterNames) {
292+
public void setFilterNames(String... filterNames) {
293293
this.filterNames = filterNames;
294294
}
295295

@@ -464,8 +464,8 @@ protected synchronized SQLExceptionTranslator getDefaultJdbcExceptionTranslator(
464464
protected void enableFilters(Session session) {
465465
String[] filterNames = getFilterNames();
466466
if (filterNames != null) {
467-
for (int i = 0; i < filterNames.length; i++) {
468-
session.enableFilter(filterNames[i]);
467+
for (String filterName : filterNames) {
468+
session.enableFilter(filterName);
469469
}
470470
}
471471
}
@@ -479,8 +479,8 @@ protected void enableFilters(Session session) {
479479
protected void disableFilters(Session session) {
480480
String[] filterNames = getFilterNames();
481481
if (filterNames != null) {
482-
for (int i = 0; i < filterNames.length; i++) {
483-
session.disableFilter(filterNames[i]);
482+
for (String filterName : filterNames) {
483+
session.disableFilter(filterName);
484484
}
485485
}
486486
}

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

Lines changed: 7 additions & 2 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-2014 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,7 +36,7 @@
3636
* Hibernate's own {@code SessionFactory.getCurrentSession()} method, to be
3737
* able to detect a thread-bound Session. Typically, the code will look like as follows:
3838
*
39-
* <pre>
39+
* <pre class="code">
4040
* public void doSomeDataAccessAction() {
4141
* Session session = this.sessionFactory.getCurrentSession();
4242
* ...
@@ -68,7 +68,12 @@
6868
* @see org.hibernate.SessionFactory#getCurrentSession()
6969
* @see HibernateTransactionManager
7070
* @see HibernateTemplate
71+
* @deprecated as of Spring 3.2.7, in favor of either HibernateTemplate usage or
72+
* native Hibernate API usage within transactions, in combination with a general
73+
* {@link org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor}.
74+
* Note: This class does not have an equivalent replacement in {@code orm.hibernate4}.
7175
*/
76+
@Deprecated
7277
public class HibernateInterceptor extends HibernateAccessor implements MethodInterceptor {
7378

7479
private boolean exceptionConversionEnabled = true;

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

Lines changed: 10 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-2014 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.
@@ -90,10 +90,13 @@ public interface HibernateOperations {
9090
* {@link List}.
9191
* <p>This is a convenience method for executing Hibernate find calls or
9292
* queries within an action.
93-
* @param action calback object that specifies the Hibernate action
93+
* @param action callback object that specifies the Hibernate action
9494
* @return a List result returned by the action, or {@code null}
9595
* @throws org.springframework.dao.DataAccessException in case of Hibernate errors
96+
* @deprecated as of Spring 3.2.7, in favor of using a regular {@link #execute}
97+
* call with a generic List type declared
9698
*/
99+
@Deprecated
97100
List executeFind(HibernateCallback<?> action) throws DataAccessException;
98101

99102

@@ -131,8 +134,7 @@ public interface HibernateOperations {
131134
* @throws org.springframework.dao.DataAccessException in case of Hibernate errors
132135
* @see org.hibernate.Session#get(Class, java.io.Serializable, org.hibernate.LockMode)
133136
*/
134-
<T> T get(Class<T> entityClass, Serializable id, LockMode lockMode)
135-
throws DataAccessException;
137+
<T> T get(Class<T> entityClass, Serializable id, LockMode lockMode) throws DataAccessException;
136138

137139
/**
138140
* Return the persistent instance of the given entity class
@@ -164,8 +166,7 @@ <T> T get(Class<T> entityClass, Serializable id, LockMode lockMode)
164166
* @throws org.springframework.dao.DataAccessException in case of Hibernate errors
165167
* @see org.hibernate.Session#get(Class, java.io.Serializable, org.hibernate.LockMode)
166168
*/
167-
Object get(String entityName, Serializable id, LockMode lockMode)
168-
throws DataAccessException;
169+
Object get(String entityName, Serializable id, LockMode lockMode) throws DataAccessException;
169170

170171
/**
171172
* Return the persistent instance of the given entity class
@@ -199,8 +200,7 @@ Object get(String entityName, Serializable id, LockMode lockMode)
199200
* @throws org.springframework.dao.DataAccessException in case of Hibernate errors
200201
* @see org.hibernate.Session#load(Class, java.io.Serializable)
201202
*/
202-
<T> T load(Class<T> entityClass, Serializable id, LockMode lockMode)
203-
throws DataAccessException;
203+
<T> T load(Class<T> entityClass, Serializable id, LockMode lockMode) throws DataAccessException;
204204

205205
/**
206206
* Return the persistent instance of the given entity class
@@ -234,8 +234,7 @@ <T> T load(Class<T> entityClass, Serializable id, LockMode lockMode)
234234
* @throws org.springframework.dao.DataAccessException in case of Hibernate errors
235235
* @see org.hibernate.Session#load(Class, java.io.Serializable)
236236
*/
237-
Object load(String entityName, Serializable id, LockMode lockMode)
238-
throws DataAccessException;
237+
Object load(String entityName, Serializable id, LockMode lockMode) throws DataAccessException;
239238

240239
/**
241240
* Return all persistent instances of the given entity class.
@@ -245,7 +244,7 @@ Object load(String entityName, Serializable id, LockMode lockMode)
245244
* @throws org.springframework.dao.DataAccessException if there is a Hibernate error
246245
* @see org.hibernate.Session#createCriteria
247246
*/
248-
<T>List<T> loadAll(Class<T> entityClass) throws DataAccessException;
247+
<T> List<T> loadAll(Class<T> entityClass) throws DataAccessException;
249248

250249
/**
251250
* Load the persistent instance with the given identifier

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

Lines changed: 9 additions & 8 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-2014 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.
@@ -132,7 +132,7 @@ public HibernateTemplate() {
132132

133133
/**
134134
* Create a new HibernateTemplate instance.
135-
* @param sessionFactory SessionFactory to create Sessions
135+
* @param sessionFactory the SessionFactory to create Sessions with
136136
*/
137137
public HibernateTemplate(SessionFactory sessionFactory) {
138138
setSessionFactory(sessionFactory);
@@ -141,7 +141,7 @@ public HibernateTemplate(SessionFactory sessionFactory) {
141141

142142
/**
143143
* Create a new HibernateTemplate instance.
144-
* @param sessionFactory SessionFactory to create Sessions
144+
* @param sessionFactory the SessionFactory to create Sessions with
145145
* @param allowCreate if a non-transactional Session should be created when no
146146
* transactional Session can be found for the current thread
147147
*/
@@ -339,6 +339,7 @@ public <T> T execute(HibernateCallback<T> action) throws DataAccessException {
339339
return doExecute(action, false, false);
340340
}
341341

342+
@Deprecated
342343
public List executeFind(HibernateCallback<?> action) throws DataAccessException {
343344
Object result = doExecute(action, false, false);
344345
if (result != null && !(result instanceof List)) {
@@ -480,17 +481,17 @@ else if (SessionFactoryUtils.hasTransactionalSession(getSessionFactory())) {
480481
* @see #prepareCriteria
481482
*/
482483
protected Session createSessionProxy(Session session) {
483-
Class[] sessionIfcs = null;
484-
Class mainIfc = (session instanceof org.hibernate.classic.Session ?
484+
Class<?>[] sessionIfcs;
485+
Class<?> mainIfc = (session instanceof org.hibernate.classic.Session ?
485486
org.hibernate.classic.Session.class : Session.class);
486487
if (session instanceof EventSource) {
487-
sessionIfcs = new Class[] {mainIfc, EventSource.class};
488+
sessionIfcs = new Class<?>[] {mainIfc, EventSource.class};
488489
}
489490
else if (session instanceof SessionImplementor) {
490-
sessionIfcs = new Class[] {mainIfc, SessionImplementor.class};
491+
sessionIfcs = new Class<?>[] {mainIfc, SessionImplementor.class};
491492
}
492493
else {
493-
sessionIfcs = new Class[] {mainIfc};
494+
sessionIfcs = new Class<?>[] {mainIfc};
494495
}
495496
return (Session) Proxy.newProxyInstance(
496497
session.getClass().getClassLoader(), sessionIfcs,

0 commit comments

Comments
 (0)