Remove usage of deprecated APIs

Issue #3838
This commit is contained in:
Mahmoud Ben Hassine
2021-08-11 17:29:41 +02:00
parent 64c09c523e
commit 31899d5fc3
11 changed files with 54 additions and 55 deletions

View File

@@ -297,7 +297,7 @@ public class JdbcJobExecutionDao extends AbstractJdbcBatchMetadataDao implements
result.add(mapper.mapRow(rs, 0));
}
};
getJdbcTemplate().query(getQuery(GET_RUNNING_EXECUTIONS), new Object[] { jobName }, handler);
getJdbcTemplate().query(getQuery(GET_RUNNING_EXECUTIONS), handler, jobName);
return result;
}
@@ -386,7 +386,7 @@ public class JdbcJobExecutionDao extends AbstractJdbcBatchMetadataDao implements
}
};
getJdbcTemplate().query(getQuery(FIND_PARAMS_FROM_ID), new Object[] { executionId }, handler);
getJdbcTemplate().query(getQuery(FIND_PARAMS_FROM_ID), handler, executionId);
return new JobParameters(map);
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2006-2019 the original author or authors.
* Copyright 2006-2021 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.
@@ -235,7 +235,7 @@ JobInstanceDao, InitializingBean {
};
List<JobInstance> result = getJdbcTemplate().query(getQuery(FIND_LAST_JOBS_BY_NAME),
new Object[] { jobName }, extractor);
extractor, jobName);
return result;
}
@@ -252,8 +252,8 @@ JobInstanceDao, InitializingBean {
try {
return getJdbcTemplate().queryForObject(
getQuery(FIND_LAST_JOB_INSTANCE_BY_JOB_NAME),
new Object[] { jobName, jobName },
new JobInstanceRowMapper());
new JobInstanceRowMapper(),
jobName, jobName);
} catch (EmptyResultDataAccessException e) {
return null;
}
@@ -358,7 +358,7 @@ JobInstanceDao, InitializingBean {
@SuppressWarnings("unchecked")
List<JobInstance> result = (List<JobInstance>) getJdbcTemplate().query(getQuery(FIND_LAST_JOBS_LIKE_NAME),
new Object[] { jobName }, extractor);
extractor, jobName);
return result;
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2006-2020 the original author or authors.
* Copyright 2006-2021 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.
@@ -283,7 +283,7 @@ public class JdbcStepExecutionDao extends AbstractJdbcBatchMetadataDao implement
// Avoid concurrent modifications...
if (count == 0) {
int currentVersion = getJdbcTemplate().queryForObject(getQuery(CURRENT_VERSION_STEP_EXECUTION),
new Object[] { stepExecution.getId() }, Integer.class);
Integer.class, stepExecution.getId());
throw new OptimisticLockingFailureException("Attempt to update step execution id="
+ stepExecution.getId() + " with wrong version (" + stepExecution.getVersion()
+ "), where current version is " + currentVersion);
@@ -358,7 +358,7 @@ public class JdbcStepExecutionDao extends AbstractJdbcBatchMetadataDao implement
@Override
public int countStepExecutions(JobInstance jobInstance, String stepName) {
return getJdbcTemplate().queryForObject(getQuery(COUNT_STEP_EXECUTIONS), new Object[] { jobInstance.getInstanceId(), stepName }, Integer.class);
return getJdbcTemplate().queryForObject(getQuery(COUNT_STEP_EXECUTIONS), Integer.class, jobInstance.getInstanceId(), stepName);
}
private static class StepExecutionRowMapper implements RowMapper<StepExecution> {

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2006-2014 the original author or authors.
* Copyright 2006-2021 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.
@@ -16,6 +16,8 @@
package org.springframework.batch.core.repository.support;
import java.util.Properties;
import org.aopalliance.intercept.MethodInterceptor;
import org.aopalliance.intercept.MethodInvocation;
import org.springframework.aop.framework.ProxyFactory;
@@ -30,6 +32,8 @@ import org.springframework.batch.support.PropertiesConverter;
import org.springframework.beans.factory.FactoryBean;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.transaction.PlatformTransactionManager;
import org.springframework.transaction.TransactionManager;
import org.springframework.transaction.interceptor.NameMatchTransactionAttributeSource;
import org.springframework.transaction.interceptor.TransactionInterceptor;
import org.springframework.transaction.support.TransactionSynchronizationManager;
import org.springframework.util.Assert;
@@ -45,6 +49,7 @@ import org.springframework.util.Assert;
* @author Ben Hale
* @author Lucas Ward
* @author Robert Kasanicky
* @author Mahmoud Ben Hassine
*/
public abstract class AbstractJobRepositoryFactoryBean implements FactoryBean<JobRepository>, InitializingBean {
@@ -165,10 +170,13 @@ public abstract class AbstractJobRepositoryFactoryBean implements FactoryBean<Jo
private void initializeProxy() throws Exception {
if (proxyFactory == null) {
proxyFactory = new ProxyFactory();
TransactionInterceptor advice = new TransactionInterceptor(transactionManager,
PropertiesConverter.stringToProperties("create*=PROPAGATION_REQUIRES_NEW,"
+ isolationLevelForCreate + "\ngetLastJobExecution*=PROPAGATION_REQUIRES_NEW,"
+ isolationLevelForCreate + "\n*=PROPAGATION_REQUIRED"));
Properties transactionAttributes = new Properties();
transactionAttributes.setProperty("create*", "PROPAGATION_REQUIRES_NEW," + isolationLevelForCreate);
transactionAttributes.setProperty("getLastJobExecution*", "PROPAGATION_REQUIRES_NEW," + isolationLevelForCreate);
transactionAttributes.setProperty("*", "PROPAGATION_REQUIRED");
NameMatchTransactionAttributeSource transactionAttributeSource = new NameMatchTransactionAttributeSource();
transactionAttributeSource.setProperties(transactionAttributes);
TransactionInterceptor advice = new TransactionInterceptor((TransactionManager) transactionManager, transactionAttributeSource);
if (validateTransactionState) {
DefaultPointcutAdvisor advisor = new DefaultPointcutAdvisor(new MethodInterceptor() {
@Override

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2006-2018 the original author or authors.
* Copyright 2006-2021 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.
@@ -17,10 +17,9 @@ package org.springframework.batch.item.database;
import java.lang.reflect.Method;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import org.hibernate.Query;
import org.hibernate.query.Query;
import org.hibernate.ScrollMode;
import org.hibernate.ScrollableResults;
import org.hibernate.Session;
@@ -41,7 +40,6 @@ import org.springframework.util.StringUtils;
* @author Mahmoud Ben Hassine
*
*/
@SuppressWarnings("rawtypes")
public class HibernateItemReaderHelper<T> implements InitializingBean {
private SessionFactory sessionFactory;
@@ -120,7 +118,7 @@ public class HibernateItemReaderHelper<T> implements InitializingBean {
* @return a forward-only {@link ScrollableResults}
*/
public ScrollableResults getForwardOnlyCursor(int fetchSize, Map<String, Object> parameterValues) {
Query query = createQuery();
Query<? extends T> query = createQuery();
if (parameterValues != null) {
query.setProperties(parameterValues);
}
@@ -132,7 +130,8 @@ public class HibernateItemReaderHelper<T> implements InitializingBean {
*
* @return a Hibernate Query
*/
public Query createQuery() {
@SuppressWarnings("unchecked") // Hibernate APIs do not use a typed Query
public Query<? extends T> createQuery() {
if (useStatelessSession) {
if (statelessSession == null) {
@@ -219,13 +218,11 @@ public class HibernateItemReaderHelper<T> implements InitializingBean {
clear();
Query query = createQuery();
Query<? extends T> query = createQuery();
if (parameterValues != null) {
query.setProperties(parameterValues);
}
@SuppressWarnings("unchecked")
List<T> result = query.setFetchSize(fetchSize).setFirstResult(page * pageSize).setMaxResults(pageSize).list();
return result;
return query.setFetchSize(fetchSize).setFirstResult(page * pageSize).setMaxResults(pageSize).list();
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2006-2018 the original author or authors.
* Copyright 2006-2021 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.
@@ -202,8 +202,8 @@ public class JdbcPagingItemReader<T> extends AbstractPagingItemReader<T> impleme
getParameterMap(parameterValues, null), rowCallback);
}
else {
query = getJdbcTemplate().query(firstPageSql,
getParameterList(parameterValues, null).toArray(), rowCallback);
query = getJdbcTemplate().query(firstPageSql, rowCallback,
getParameterList(parameterValues, null).toArray());
}
}
else {
@@ -221,8 +221,8 @@ public class JdbcPagingItemReader<T> extends AbstractPagingItemReader<T> impleme
getParameterMap(parameterValues, startAfterValues), rowCallback);
}
else {
query = getJdbcTemplate().query(remainingPagesSql,
getParameterList(parameterValues, startAfterValues).toArray(), rowCallback);
query = getJdbcTemplate().query(remainingPagesSql, rowCallback,
getParameterList(parameterValues, startAfterValues).toArray());
}
}

View File

@@ -45,7 +45,7 @@ import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.mockito.Matchers.any;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2006-2007 the original author or authors.
* Copyright 2006-2021 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.
@@ -27,6 +27,7 @@ import javax.sql.DataSource;
/**
* @author Lucas Ward
* @author Mahmoud Ben Hassine
*
*/
public class CompositeKeyFooDao extends JdbcDaoSupport implements FooDao {
@@ -56,7 +57,7 @@ public class CompositeKeyFooDao extends JdbcDaoSupport implements FooDao {
};
return getJdbcTemplate().query("SELECT ID, NAME, VALUE from T_FOOS where ID = ? and VALUE = ?",
args, fooMapper).get(0);
fooMapper, args).get(0);
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2008-2014 the original author or authors.
* Copyright 2008-2021 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.
@@ -39,7 +39,7 @@ public class SingleKeyFooDao extends JdbcDaoSupport implements FooDao {
};
return getJdbcTemplate().query("SELECT ID, NAME, VALUE from T_FOOS where ID = ?",
new Object[] {key}, fooMapper).get(0);
fooMapper, key).get(0);
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2006-2007 the original author or authors.
* Copyright 2006-2021 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.
@@ -17,18 +17,16 @@
package org.springframework.batch.sample.domain.trade.internal;
import java.math.BigDecimal;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;
import org.springframework.batch.sample.domain.trade.CustomerCredit;
import org.springframework.batch.sample.domain.trade.CustomerDao;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.jdbc.core.support.JdbcDaoSupport;
import org.springframework.jdbc.support.incrementer.DataFieldMaxValueIncrementer;
/**
* @author Lucas Ward
* @author Mahmoud Ben Hassine
*
*/
public class JdbcCustomerDao extends JdbcDaoSupport implements CustomerDao{
@@ -46,20 +44,14 @@ public class JdbcCustomerDao extends JdbcDaoSupport implements CustomerDao{
@Override
public CustomerCredit getCustomerByName(String name) {
List<CustomerCredit> customers = getJdbcTemplate().query(GET_CUSTOMER_BY_NAME, new Object[]{name},
new RowMapper<CustomerCredit>(){
@Override
public CustomerCredit mapRow(ResultSet rs, int rowNum) throws SQLException {
CustomerCredit customer = new CustomerCredit();
customer.setName(rs.getString("NAME"));
customer.setId(rs.getInt("ID"));
customer.setCredit(rs.getBigDecimal("CREDIT"));
return customer;
}
});
List<CustomerCredit> customers = getJdbcTemplate().query(GET_CUSTOMER_BY_NAME,
(rs, rowNum) -> {
CustomerCredit customer = new CustomerCredit();
customer.setName(rs.getString("NAME"));
customer.setId(rs.getInt("ID"));
customer.setCredit(rs.getBigDecimal("CREDIT"));
return customer;
}, name);
if(customers.size() == 0){
return null;

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2006-2007 the original author or authors.
* Copyright 2006-2021 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.
@@ -35,9 +35,10 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
/**
* Functional test for graceful shutdown. A batch container is started in a new thread,
* then it's stopped using {@link JobExecution#stop()}.
* then it's stopped using {@link JobOperator#stop(long)}}.
*
* @author Lucas Ward
* @author Mahmoud Ben Hassine
*
*/
@RunWith(SpringJUnit4ClassRunner.class)