Skip to content

Commit 31899d5

Browse files
committed
Remove usage of deprecated APIs
Issue #3838
1 parent 64c09c5 commit 31899d5

File tree

11 files changed

+54
-55
lines changed

11 files changed

+54
-55
lines changed

spring-batch-core/src/main/java/org/springframework/batch/core/repository/dao/JdbcJobExecutionDao.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ public void processRow(ResultSet rs) throws SQLException {
297297
result.add(mapper.mapRow(rs, 0));
298298
}
299299
};
300-
getJdbcTemplate().query(getQuery(GET_RUNNING_EXECUTIONS), new Object[] { jobName }, handler);
300+
getJdbcTemplate().query(getQuery(GET_RUNNING_EXECUTIONS), handler, jobName);
301301

302302
return result;
303303
}
@@ -386,7 +386,7 @@ public void processRow(ResultSet rs) throws SQLException {
386386
}
387387
};
388388

389-
getJdbcTemplate().query(getQuery(FIND_PARAMS_FROM_ID), new Object[] { executionId }, handler);
389+
getJdbcTemplate().query(getQuery(FIND_PARAMS_FROM_ID), handler, executionId);
390390

391391
return new JobParameters(map);
392392
}

spring-batch-core/src/main/java/org/springframework/batch/core/repository/dao/JdbcJobInstanceDao.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2006-2019 the original author or authors.
2+
* Copyright 2006-2021 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.
@@ -235,7 +235,7 @@ public List<JobInstance> extractData(ResultSet rs) throws SQLException,
235235
};
236236

237237
List<JobInstance> result = getJdbcTemplate().query(getQuery(FIND_LAST_JOBS_BY_NAME),
238-
new Object[] { jobName }, extractor);
238+
extractor, jobName);
239239

240240
return result;
241241
}
@@ -252,8 +252,8 @@ public JobInstance getLastJobInstance(String jobName) {
252252
try {
253253
return getJdbcTemplate().queryForObject(
254254
getQuery(FIND_LAST_JOB_INSTANCE_BY_JOB_NAME),
255-
new Object[] { jobName, jobName },
256-
new JobInstanceRowMapper());
255+
new JobInstanceRowMapper(),
256+
jobName, jobName);
257257
} catch (EmptyResultDataAccessException e) {
258258
return null;
259259
}
@@ -358,7 +358,7 @@ public Object extractData(ResultSet rs) throws SQLException,
358358

359359
@SuppressWarnings("unchecked")
360360
List<JobInstance> result = (List<JobInstance>) getJdbcTemplate().query(getQuery(FIND_LAST_JOBS_LIKE_NAME),
361-
new Object[] { jobName }, extractor);
361+
extractor, jobName);
362362

363363
return result;
364364
}

spring-batch-core/src/main/java/org/springframework/batch/core/repository/dao/JdbcStepExecutionDao.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2006-2020 the original author or authors.
2+
* Copyright 2006-2021 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.
@@ -283,7 +283,7 @@ public void updateStepExecution(StepExecution stepExecution) {
283283
// Avoid concurrent modifications...
284284
if (count == 0) {
285285
int currentVersion = getJdbcTemplate().queryForObject(getQuery(CURRENT_VERSION_STEP_EXECUTION),
286-
new Object[] { stepExecution.getId() }, Integer.class);
286+
Integer.class, stepExecution.getId());
287287
throw new OptimisticLockingFailureException("Attempt to update step execution id="
288288
+ stepExecution.getId() + " with wrong version (" + stepExecution.getVersion()
289289
+ "), where current version is " + currentVersion);
@@ -358,7 +358,7 @@ public void addStepExecutions(JobExecution jobExecution) {
358358

359359
@Override
360360
public int countStepExecutions(JobInstance jobInstance, String stepName) {
361-
return getJdbcTemplate().queryForObject(getQuery(COUNT_STEP_EXECUTIONS), new Object[] { jobInstance.getInstanceId(), stepName }, Integer.class);
361+
return getJdbcTemplate().queryForObject(getQuery(COUNT_STEP_EXECUTIONS), Integer.class, jobInstance.getInstanceId(), stepName);
362362
}
363363

364364
private static class StepExecutionRowMapper implements RowMapper<StepExecution> {

spring-batch-core/src/main/java/org/springframework/batch/core/repository/support/AbstractJobRepositoryFactoryBean.java

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2006-2014 the original author or authors.
2+
* Copyright 2006-2021 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,6 +16,8 @@
1616

1717
package org.springframework.batch.core.repository.support;
1818

19+
import java.util.Properties;
20+
1921
import org.aopalliance.intercept.MethodInterceptor;
2022
import org.aopalliance.intercept.MethodInvocation;
2123
import org.springframework.aop.framework.ProxyFactory;
@@ -30,6 +32,8 @@
3032
import org.springframework.beans.factory.FactoryBean;
3133
import org.springframework.beans.factory.InitializingBean;
3234
import org.springframework.transaction.PlatformTransactionManager;
35+
import org.springframework.transaction.TransactionManager;
36+
import org.springframework.transaction.interceptor.NameMatchTransactionAttributeSource;
3337
import org.springframework.transaction.interceptor.TransactionInterceptor;
3438
import org.springframework.transaction.support.TransactionSynchronizationManager;
3539
import org.springframework.util.Assert;
@@ -45,6 +49,7 @@
4549
* @author Ben Hale
4650
* @author Lucas Ward
4751
* @author Robert Kasanicky
52+
* @author Mahmoud Ben Hassine
4853
*/
4954
public abstract class AbstractJobRepositoryFactoryBean implements FactoryBean<JobRepository>, InitializingBean {
5055

@@ -165,10 +170,13 @@ public JobRepository getJobRepository() throws Exception {
165170
private void initializeProxy() throws Exception {
166171
if (proxyFactory == null) {
167172
proxyFactory = new ProxyFactory();
168-
TransactionInterceptor advice = new TransactionInterceptor(transactionManager,
169-
PropertiesConverter.stringToProperties("create*=PROPAGATION_REQUIRES_NEW,"
170-
+ isolationLevelForCreate + "\ngetLastJobExecution*=PROPAGATION_REQUIRES_NEW,"
171-
+ isolationLevelForCreate + "\n*=PROPAGATION_REQUIRED"));
173+
Properties transactionAttributes = new Properties();
174+
transactionAttributes.setProperty("create*", "PROPAGATION_REQUIRES_NEW," + isolationLevelForCreate);
175+
transactionAttributes.setProperty("getLastJobExecution*", "PROPAGATION_REQUIRES_NEW," + isolationLevelForCreate);
176+
transactionAttributes.setProperty("*", "PROPAGATION_REQUIRED");
177+
NameMatchTransactionAttributeSource transactionAttributeSource = new NameMatchTransactionAttributeSource();
178+
transactionAttributeSource.setProperties(transactionAttributes);
179+
TransactionInterceptor advice = new TransactionInterceptor((TransactionManager) transactionManager, transactionAttributeSource);
172180
if (validateTransactionState) {
173181
DefaultPointcutAdvisor advisor = new DefaultPointcutAdvisor(new MethodInterceptor() {
174182
@Override

spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/HibernateItemReaderHelper.java

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2006-2018 the original author or authors.
2+
* Copyright 2006-2021 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.
@@ -17,10 +17,9 @@
1717

1818
import java.lang.reflect.Method;
1919
import java.util.Collection;
20-
import java.util.List;
2120
import java.util.Map;
2221

23-
import org.hibernate.Query;
22+
import org.hibernate.query.Query;
2423
import org.hibernate.ScrollMode;
2524
import org.hibernate.ScrollableResults;
2625
import org.hibernate.Session;
@@ -41,7 +40,6 @@
4140
* @author Mahmoud Ben Hassine
4241
*
4342
*/
44-
@SuppressWarnings("rawtypes")
4543
public class HibernateItemReaderHelper<T> implements InitializingBean {
4644

4745
private SessionFactory sessionFactory;
@@ -120,7 +118,7 @@ public void afterPropertiesSet() throws Exception {
120118
* @return a forward-only {@link ScrollableResults}
121119
*/
122120
public ScrollableResults getForwardOnlyCursor(int fetchSize, Map<String, Object> parameterValues) {
123-
Query query = createQuery();
121+
Query<? extends T> query = createQuery();
124122
if (parameterValues != null) {
125123
query.setProperties(parameterValues);
126124
}
@@ -132,7 +130,8 @@ public ScrollableResults getForwardOnlyCursor(int fetchSize, Map<String, Object>
132130
*
133131
* @return a Hibernate Query
134132
*/
135-
public Query createQuery() {
133+
@SuppressWarnings("unchecked") // Hibernate APIs do not use a typed Query
134+
public Query<? extends T> createQuery() {
136135

137136
if (useStatelessSession) {
138137
if (statelessSession == null) {
@@ -219,13 +218,11 @@ public Collection<? extends T> readPage(int page, int pageSize, int fetchSize, M
219218

220219
clear();
221220

222-
Query query = createQuery();
221+
Query<? extends T> query = createQuery();
223222
if (parameterValues != null) {
224223
query.setProperties(parameterValues);
225224
}
226-
@SuppressWarnings("unchecked")
227-
List<T> result = query.setFetchSize(fetchSize).setFirstResult(page * pageSize).setMaxResults(pageSize).list();
228-
return result;
225+
return query.setFetchSize(fetchSize).setFirstResult(page * pageSize).setMaxResults(pageSize).list();
229226

230227
}
231228

spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/JdbcPagingItemReader.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2006-2018 the original author or authors.
2+
* Copyright 2006-2021 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.
@@ -202,8 +202,8 @@ protected void doReadPage() {
202202
getParameterMap(parameterValues, null), rowCallback);
203203
}
204204
else {
205-
query = getJdbcTemplate().query(firstPageSql,
206-
getParameterList(parameterValues, null).toArray(), rowCallback);
205+
query = getJdbcTemplate().query(firstPageSql, rowCallback,
206+
getParameterList(parameterValues, null).toArray());
207207
}
208208
}
209209
else {
@@ -221,8 +221,8 @@ protected void doReadPage() {
221221
getParameterMap(parameterValues, startAfterValues), rowCallback);
222222
}
223223
else {
224-
query = getJdbcTemplate().query(remainingPagesSql,
225-
getParameterList(parameterValues, startAfterValues).toArray(), rowCallback);
224+
query = getJdbcTemplate().query(remainingPagesSql, rowCallback,
225+
getParameterList(parameterValues, startAfterValues).toArray());
226226
}
227227
}
228228

spring-batch-infrastructure/src/test/java/org/springframework/batch/item/data/RepositoryItemReaderTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
import static org.junit.Assert.assertSame;
4646
import static org.junit.Assert.assertTrue;
4747
import static org.junit.Assert.fail;
48-
import static org.mockito.Matchers.any;
48+
import static org.mockito.ArgumentMatchers.any;
4949
import static org.mockito.Mockito.mock;
5050
import static org.mockito.Mockito.never;
5151
import static org.mockito.Mockito.verify;

spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/CompositeKeyFooDao.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2006-2007 the original author or authors.
2+
* Copyright 2006-2021 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.
@@ -27,6 +27,7 @@
2727

2828
/**
2929
* @author Lucas Ward
30+
* @author Mahmoud Ben Hassine
3031
*
3132
*/
3233
public class CompositeKeyFooDao extends JdbcDaoSupport implements FooDao {
@@ -56,7 +57,7 @@ public Foo mapRow(ResultSet rs, int rowNum) throws SQLException {
5657
};
5758

5859
return getJdbcTemplate().query("SELECT ID, NAME, VALUE from T_FOOS where ID = ? and VALUE = ?",
59-
args, fooMapper).get(0);
60+
fooMapper, args).get(0);
6061
}
6162

6263
}

spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/SingleKeyFooDao.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2008-2014 the original author or authors.
2+
* Copyright 2008-2021 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.
@@ -39,7 +39,7 @@ public Foo mapRow(ResultSet rs, int rowNum) throws SQLException {
3939
};
4040

4141
return getJdbcTemplate().query("SELECT ID, NAME, VALUE from T_FOOS where ID = ?",
42-
new Object[] {key}, fooMapper).get(0);
42+
fooMapper, key).get(0);
4343

4444
}
4545
}

spring-batch-samples/src/main/java/org/springframework/batch/sample/domain/trade/internal/JdbcCustomerDao.java

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2006-2007 the original author or authors.
2+
* Copyright 2006-2021 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.
@@ -17,18 +17,16 @@
1717
package org.springframework.batch.sample.domain.trade.internal;
1818

1919
import java.math.BigDecimal;
20-
import java.sql.ResultSet;
21-
import java.sql.SQLException;
2220
import java.util.List;
2321

2422
import org.springframework.batch.sample.domain.trade.CustomerCredit;
2523
import org.springframework.batch.sample.domain.trade.CustomerDao;
26-
import org.springframework.jdbc.core.RowMapper;
2724
import org.springframework.jdbc.core.support.JdbcDaoSupport;
2825
import org.springframework.jdbc.support.incrementer.DataFieldMaxValueIncrementer;
2926

3027
/**
3128
* @author Lucas Ward
29+
* @author Mahmoud Ben Hassine
3230
*
3331
*/
3432
public class JdbcCustomerDao extends JdbcDaoSupport implements CustomerDao{
@@ -46,20 +44,14 @@ public void setIncrementer(DataFieldMaxValueIncrementer incrementer) {
4644
@Override
4745
public CustomerCredit getCustomerByName(String name) {
4846

49-
List<CustomerCredit> customers = getJdbcTemplate().query(GET_CUSTOMER_BY_NAME, new Object[]{name},
50-
51-
new RowMapper<CustomerCredit>(){
52-
53-
@Override
54-
public CustomerCredit mapRow(ResultSet rs, int rowNum) throws SQLException {
55-
CustomerCredit customer = new CustomerCredit();
56-
customer.setName(rs.getString("NAME"));
57-
customer.setId(rs.getInt("ID"));
58-
customer.setCredit(rs.getBigDecimal("CREDIT"));
59-
return customer;
60-
}
61-
62-
});
47+
List<CustomerCredit> customers = getJdbcTemplate().query(GET_CUSTOMER_BY_NAME,
48+
(rs, rowNum) -> {
49+
CustomerCredit customer = new CustomerCredit();
50+
customer.setName(rs.getString("NAME"));
51+
customer.setId(rs.getInt("ID"));
52+
customer.setCredit(rs.getBigDecimal("CREDIT"));
53+
return customer;
54+
}, name);
6355

6456
if(customers.size() == 0){
6557
return null;

spring-batch-samples/src/test/java/org/springframework/batch/sample/DatabaseShutdownFunctionalTests.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2006-2007 the original author or authors.
2+
* Copyright 2006-2021 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.
@@ -35,9 +35,10 @@
3535

3636
/**
3737
* Functional test for graceful shutdown. A batch container is started in a new thread,
38-
* then it's stopped using {@link JobExecution#stop()}.
38+
* then it's stopped using {@link JobOperator#stop(long)}}.
3939
*
4040
* @author Lucas Ward
41+
* @author Mahmoud Ben Hassine
4142
*
4243
*/
4344
@RunWith(SpringJUnit4ClassRunner.class)

0 commit comments

Comments
 (0)