diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/repository/dao/JdbcJobExecutionDao.java b/spring-batch-core/src/main/java/org/springframework/batch/core/repository/dao/JdbcJobExecutionDao.java index 2c1f2a808..e5f031723 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/repository/dao/JdbcJobExecutionDao.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/repository/dao/JdbcJobExecutionDao.java @@ -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); } diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/repository/dao/JdbcJobInstanceDao.java b/spring-batch-core/src/main/java/org/springframework/batch/core/repository/dao/JdbcJobInstanceDao.java index d9de3e1a5..dff8c6ec9 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/repository/dao/JdbcJobInstanceDao.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/repository/dao/JdbcJobInstanceDao.java @@ -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 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 result = (List) getJdbcTemplate().query(getQuery(FIND_LAST_JOBS_LIKE_NAME), - new Object[] { jobName }, extractor); + extractor, jobName); return result; } diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/repository/dao/JdbcStepExecutionDao.java b/spring-batch-core/src/main/java/org/springframework/batch/core/repository/dao/JdbcStepExecutionDao.java index d5712fa22..41b2948a5 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/repository/dao/JdbcStepExecutionDao.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/repository/dao/JdbcStepExecutionDao.java @@ -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 { diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/repository/support/AbstractJobRepositoryFactoryBean.java b/spring-batch-core/src/main/java/org/springframework/batch/core/repository/support/AbstractJobRepositoryFactoryBean.java index 778e46604..67fac0007 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/repository/support/AbstractJobRepositoryFactoryBean.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/repository/support/AbstractJobRepositoryFactoryBean.java @@ -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, InitializingBean { @@ -165,10 +170,13 @@ public abstract class AbstractJobRepositoryFactoryBean implements FactoryBean implements InitializingBean { private SessionFactory sessionFactory; @@ -120,7 +118,7 @@ public class HibernateItemReaderHelper implements InitializingBean { * @return a forward-only {@link ScrollableResults} */ public ScrollableResults getForwardOnlyCursor(int fetchSize, Map parameterValues) { - Query query = createQuery(); + Query query = createQuery(); if (parameterValues != null) { query.setProperties(parameterValues); } @@ -132,7 +130,8 @@ public class HibernateItemReaderHelper implements InitializingBean { * * @return a Hibernate Query */ - public Query createQuery() { + @SuppressWarnings("unchecked") // Hibernate APIs do not use a typed Query + public Query createQuery() { if (useStatelessSession) { if (statelessSession == null) { @@ -219,13 +218,11 @@ public class HibernateItemReaderHelper implements InitializingBean { clear(); - Query query = createQuery(); + Query query = createQuery(); if (parameterValues != null) { query.setProperties(parameterValues); } - @SuppressWarnings("unchecked") - List result = query.setFetchSize(fetchSize).setFirstResult(page * pageSize).setMaxResults(pageSize).list(); - return result; + return query.setFetchSize(fetchSize).setFirstResult(page * pageSize).setMaxResults(pageSize).list(); } diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/JdbcPagingItemReader.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/JdbcPagingItemReader.java index 889cdcd7b..fd0f78050 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/JdbcPagingItemReader.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/JdbcPagingItemReader.java @@ -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 extends AbstractPagingItemReader 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 extends AbstractPagingItemReader impleme getParameterMap(parameterValues, startAfterValues), rowCallback); } else { - query = getJdbcTemplate().query(remainingPagesSql, - getParameterList(parameterValues, startAfterValues).toArray(), rowCallback); + query = getJdbcTemplate().query(remainingPagesSql, rowCallback, + getParameterList(parameterValues, startAfterValues).toArray()); } } diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/data/RepositoryItemReaderTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/data/RepositoryItemReaderTests.java index ccedb4ce7..b35698a50 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/data/RepositoryItemReaderTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/data/RepositoryItemReaderTests.java @@ -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; diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/CompositeKeyFooDao.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/CompositeKeyFooDao.java index 6f7e88b92..43b4adb48 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/CompositeKeyFooDao.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/CompositeKeyFooDao.java @@ -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); } } diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/SingleKeyFooDao.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/SingleKeyFooDao.java index 557da3a4d..62f2e0864 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/SingleKeyFooDao.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/SingleKeyFooDao.java @@ -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); } } diff --git a/spring-batch-samples/src/main/java/org/springframework/batch/sample/domain/trade/internal/JdbcCustomerDao.java b/spring-batch-samples/src/main/java/org/springframework/batch/sample/domain/trade/internal/JdbcCustomerDao.java index bea06a88c..faadc3b21 100644 --- a/spring-batch-samples/src/main/java/org/springframework/batch/sample/domain/trade/internal/JdbcCustomerDao.java +++ b/spring-batch-samples/src/main/java/org/springframework/batch/sample/domain/trade/internal/JdbcCustomerDao.java @@ -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 customers = getJdbcTemplate().query(GET_CUSTOMER_BY_NAME, new Object[]{name}, - - new RowMapper(){ - - @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 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; diff --git a/spring-batch-samples/src/test/java/org/springframework/batch/sample/DatabaseShutdownFunctionalTests.java b/spring-batch-samples/src/test/java/org/springframework/batch/sample/DatabaseShutdownFunctionalTests.java index efba4a834..dcf1e9ba8 100644 --- a/spring-batch-samples/src/test/java/org/springframework/batch/sample/DatabaseShutdownFunctionalTests.java +++ b/spring-batch-samples/src/test/java/org/springframework/batch/sample/DatabaseShutdownFunctionalTests.java @@ -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)