BATCH-1928: Converted to using JdbcOperations over JdbcTemplate
This commit is contained in:
@@ -7,19 +7,20 @@ import javax.sql.DataSource;
|
||||
|
||||
import org.springframework.batch.core.partition.support.Partitioner;
|
||||
import org.springframework.batch.item.ExecutionContext;
|
||||
import org.springframework.jdbc.core.JdbcOperations;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
|
||||
/**
|
||||
* Simple minded partitioner for a range of values of a column in a database
|
||||
* table. Works best if the values are uniformly distributed (e.g.
|
||||
* auto-generated primary key values).
|
||||
*
|
||||
*
|
||||
* @author Dave Syer
|
||||
*
|
||||
*
|
||||
*/
|
||||
public class ColumnRangePartitioner implements Partitioner {
|
||||
|
||||
private JdbcTemplate jdbcTemplate;
|
||||
private JdbcOperations jdbcTemplate;
|
||||
|
||||
private String table;
|
||||
|
||||
@@ -27,7 +28,7 @@ public class ColumnRangePartitioner implements Partitioner {
|
||||
|
||||
/**
|
||||
* The name of the SQL table the data are in.
|
||||
*
|
||||
*
|
||||
* @param table the name of the table
|
||||
*/
|
||||
public void setTable(String table) {
|
||||
@@ -36,7 +37,7 @@ public class ColumnRangePartitioner implements Partitioner {
|
||||
|
||||
/**
|
||||
* The name of the column to partition.
|
||||
*
|
||||
*
|
||||
* @param column the column name.
|
||||
*/
|
||||
public void setColumn(String column) {
|
||||
@@ -45,7 +46,7 @@ public class ColumnRangePartitioner implements Partitioner {
|
||||
|
||||
/**
|
||||
* The data source for connecting to the database.
|
||||
*
|
||||
*
|
||||
* @param dataSource a {@link DataSource}
|
||||
*/
|
||||
public void setDataSource(DataSource dataSource) {
|
||||
@@ -57,7 +58,7 @@ public class ColumnRangePartitioner implements Partitioner {
|
||||
* are uniformly distributed. The execution context values will have keys
|
||||
* <code>minValue</code> and <code>maxValue</code> specifying the range of
|
||||
* values to consider in each partition.
|
||||
*
|
||||
*
|
||||
* @see Partitioner#partition(int)
|
||||
*/
|
||||
public Map<String, ExecutionContext> partition(int gridSize) {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2006-2007 the original author or authors.
|
||||
* Copyright 2006-2012 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.
|
||||
@@ -22,6 +22,7 @@ import org.springframework.batch.core.listener.StepListenerSupport;
|
||||
import org.springframework.batch.item.ItemReader;
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
import org.springframework.dao.OptimisticLockingFailureException;
|
||||
import org.springframework.jdbc.core.JdbcOperations;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
@@ -31,7 +32,7 @@ import org.springframework.util.Assert;
|
||||
*/
|
||||
public class StagingItemListener extends StepListenerSupport<Long, Long> implements InitializingBean {
|
||||
|
||||
private JdbcTemplate jdbcTemplate;
|
||||
private JdbcOperations jdbcTemplate;
|
||||
|
||||
public void setDataSource(DataSource dataSource) {
|
||||
jdbcTemplate = new JdbcTemplate(dataSource);
|
||||
|
||||
@@ -5,26 +5,27 @@ import javax.sql.DataSource;
|
||||
import org.springframework.batch.item.ItemProcessor;
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
import org.springframework.dao.OptimisticLockingFailureException;
|
||||
import org.springframework.jdbc.core.JdbcOperations;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
* Marks the input row as 'processed'. (This change will rollback if there is
|
||||
* problem later)
|
||||
*
|
||||
*
|
||||
* @param <T> item type
|
||||
*
|
||||
*
|
||||
* @see StagingItemReader
|
||||
* @see StagingItemWriter
|
||||
* @see ProcessIndicatorItemWrapper
|
||||
*
|
||||
*
|
||||
* @author Robert Kasanicky
|
||||
*/
|
||||
public class StagingItemProcessor<T> implements ItemProcessor<ProcessIndicatorItemWrapper<T>, T>, InitializingBean {
|
||||
|
||||
private JdbcTemplate jdbcTemplate;
|
||||
private JdbcOperations jdbcTemplate;
|
||||
|
||||
public void setJdbcTemplate(JdbcTemplate jdbcTemplate) {
|
||||
public void setJdbcTemplate(JdbcOperations jdbcTemplate) {
|
||||
this.jdbcTemplate = jdbcTemplate;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2006-2007 the original author or authors.
|
||||
* Copyright 2006-2012 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.
|
||||
@@ -34,14 +34,15 @@ import org.springframework.batch.support.SerializationUtils;
|
||||
import org.springframework.beans.factory.DisposableBean;
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
import org.springframework.dao.DataAccessException;
|
||||
import org.springframework.jdbc.core.simple.ParameterizedRowMapper;
|
||||
import org.springframework.jdbc.core.JdbcOperations;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
import org.springframework.jdbc.core.simple.ParameterizedRowMapper;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
* Thread-safe database {@link ItemReader} implementing the process indicator
|
||||
* pattern.
|
||||
*
|
||||
*
|
||||
* To achieve restartability use together with {@link StagingItemProcessor}.
|
||||
*/
|
||||
public class StagingItemReader<T> implements ItemReader<ProcessIndicatorItemWrapper<T>>, StepExecutionListener,
|
||||
@@ -57,7 +58,7 @@ public class StagingItemReader<T> implements ItemReader<ProcessIndicatorItemWrap
|
||||
|
||||
private volatile Iterator<Long> keys;
|
||||
|
||||
private JdbcTemplate jdbcTemplate;
|
||||
private JdbcOperations jdbcTemplate;
|
||||
|
||||
public void setDataSource(DataSource dataSource) {
|
||||
jdbcTemplate = new JdbcTemplate(dataSource);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2006-2007 the original author or authors.
|
||||
* Copyright 2006-2012 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,13 +16,14 @@
|
||||
|
||||
package org.springframework.batch.sample.domain.football.internal;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
|
||||
import org.springframework.batch.sample.domain.football.Player;
|
||||
import org.springframework.batch.sample.domain.football.PlayerDao;
|
||||
import org.springframework.jdbc.core.namedparam.BeanPropertySqlParameterSource;
|
||||
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcOperations;
|
||||
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
|
||||
/**
|
||||
* @author Lucas Ward
|
||||
*
|
||||
@@ -33,7 +34,7 @@ public class JdbcPlayerDao implements PlayerDao {
|
||||
"INSERT into PLAYERS (player_id, last_name, first_name, pos, year_of_birth, year_drafted)" +
|
||||
" values (:id, :lastName, :firstName, :position, :birthYear, :debutYear)";
|
||||
|
||||
private NamedParameterJdbcTemplate namedParameterJdbcTemplate;
|
||||
private NamedParameterJdbcOperations namedParameterJdbcTemplate;
|
||||
|
||||
public void savePlayer(Player player) {
|
||||
namedParameterJdbcTemplate.update(INSERT_PLAYER, new BeanPropertySqlParameterSource(player));
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2006-2007 the original author or authors.
|
||||
* Copyright 2006-2012 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.
|
||||
@@ -18,13 +18,14 @@ package org.springframework.batch.sample.domain.football.internal;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
|
||||
import org.springframework.batch.item.ItemWriter;
|
||||
import org.springframework.batch.sample.domain.football.PlayerSummary;
|
||||
import org.springframework.jdbc.core.namedparam.MapSqlParameterSource;
|
||||
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcOperations;
|
||||
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
|
||||
public class JdbcPlayerSummaryDao implements ItemWriter<PlayerSummary> {
|
||||
|
||||
private static final String INSERT_SUMMARY = "INSERT into PLAYER_SUMMARY(ID, YEAR_NO, COMPLETES, ATTEMPTS, PASSING_YARDS, PASSING_TD, "
|
||||
@@ -32,7 +33,7 @@ public class JdbcPlayerSummaryDao implements ItemWriter<PlayerSummary> {
|
||||
+ "values(:id, :year, :completes, :attempts, :passingYards, :passingTd, "
|
||||
+ ":interceptions, :rushes, :rushYards, :receptions, :receptionYards, :totalTd)";
|
||||
|
||||
private NamedParameterJdbcTemplate namedParameterJdbcTemplate;
|
||||
private NamedParameterJdbcOperations namedParameterJdbcTemplate;
|
||||
|
||||
public void write(List<? extends PlayerSummary> summaries) {
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2006-2007 the original author or authors.
|
||||
* Copyright 2006-2012 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.
|
||||
@@ -21,19 +21,20 @@ import javax.sql.DataSource;
|
||||
import org.springframework.batch.sample.domain.trade.CustomerDebit;
|
||||
import org.springframework.batch.sample.domain.trade.CustomerDebitDao;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.jdbc.core.JdbcOperations;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
|
||||
|
||||
/**
|
||||
* Reduces customer's credit by the provided amount.
|
||||
*
|
||||
*
|
||||
* @author Robert Kasanicky
|
||||
*/
|
||||
public class JdbcCustomerDebitDao implements CustomerDebitDao {
|
||||
|
||||
|
||||
private static final String UPDATE_CREDIT = "UPDATE CUSTOMER SET credit= credit-? WHERE name=?";
|
||||
|
||||
private JdbcTemplate jdbcTemplate;
|
||||
|
||||
private JdbcOperations jdbcTemplate;
|
||||
|
||||
public void write(CustomerDebit customerDebit) {
|
||||
jdbcTemplate.update(UPDATE_CREDIT, customerDebit.getDebit(), customerDebit.getName());
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2006-2007 the original author or authors.
|
||||
* Copyright 2006-2012 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.
|
||||
@@ -22,6 +22,7 @@ import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.springframework.batch.sample.domain.trade.Trade;
|
||||
import org.springframework.batch.sample.domain.trade.TradeDao;
|
||||
import org.springframework.jdbc.core.JdbcOperations;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
import org.springframework.jdbc.support.incrementer.DataFieldMaxValueIncrementer;
|
||||
|
||||
@@ -41,7 +42,7 @@ public class JdbcTradeDao implements TradeDao {
|
||||
/**
|
||||
* handles the processing of sql query
|
||||
*/
|
||||
private JdbcTemplate jdbcTemplate;
|
||||
private JdbcOperations jdbcTemplate;
|
||||
|
||||
/**
|
||||
* database is not expected to be setup for autoincrement
|
||||
|
||||
Reference in New Issue
Block a user