This commit is contained in:
jpraet
2014-03-30 13:25:34 +02:00
committed by Chris Schaefer
parent 24852e3cf8
commit b26d272d43
760 changed files with 8606 additions and 2349 deletions

View File

@@ -1,3 +1,18 @@
/*
* Copyright 2009-2014 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.batch.sample.common;
import java.util.HashMap;
@@ -61,10 +76,10 @@ public class ColumnRangePartitioner implements Partitioner {
*
* @see Partitioner#partition(int)
*/
@Override
public Map<String, ExecutionContext> partition(int gridSize) {
int min = jdbcTemplate.queryForObject("SELECT MIN(" + column + ") from " + table, Integer.class);
int max = jdbcTemplate.queryForObject("SELECT MAX(" + column + ") from " + table, Integer.class);
int targetSize = (max - min) / gridSize + 1;
Map<String, ExecutionContext> result = new HashMap<String, ExecutionContext>();

View File

@@ -26,6 +26,8 @@ import org.springframework.batch.item.ItemReader;
*
*/
public class InfiniteLoopReader implements ItemReader<Object> {
@Override
public Object read() throws Exception {
return new Object();
}

View File

@@ -50,6 +50,7 @@ public class InfiniteLoopWriter extends StepExecutionListenerSupport implements
super();
}
@Override
public void write(List<? extends Object> items) throws Exception {
try {
Thread.sleep(500);

View File

@@ -0,0 +1,20 @@
/*
* Copyright 2009 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.batch.sample.common;
public class OutputFileNameListener {
}

View File

@@ -1,3 +1,18 @@
/*
* Copyright 2009 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.batch.sample.common;
/**

View File

@@ -0,0 +1,56 @@
/*
* 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.batch.sample.common;
import javax.sql.DataSource;
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;
/**
* Thread-safe database {@link ItemReader} implementing the process indicator
* pattern.
*/
public class StagingItemListener extends StepListenerSupport<Long, Long> implements InitializingBean {
private JdbcOperations jdbcTemplate;
public void setDataSource(DataSource dataSource) {
jdbcTemplate = new JdbcTemplate(dataSource);
}
@Override
public final void afterPropertiesSet() throws Exception {
Assert.notNull(jdbcTemplate, "You must provide a DataSource.");
}
@Override
public void afterRead(Long id) {
int count = jdbcTemplate.update("UPDATE BATCH_STAGING SET PROCESSED=? WHERE ID=? AND PROCESSED=?",
StagingItemWriter.DONE, id, StagingItemWriter.NEW);
if (count != 1) {
throw new OptimisticLockingFailureException("The staging record with ID=" + id
+ " was updated concurrently when trying to mark as complete (updated " + count + " records.");
}
}
}

View File

@@ -1,3 +1,18 @@
/*
* Copyright 2009-2014 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.batch.sample.common;
import javax.sql.DataSource;
@@ -33,6 +48,7 @@ public class StagingItemProcessor<T> implements ItemProcessor<ProcessIndicatorIt
this.jdbcTemplate = new JdbcTemplate(dataSource);
}
@Override
public void afterPropertiesSet() throws Exception {
Assert.notNull(jdbcTemplate, "Either jdbcTemplate or dataSource must be set");
}
@@ -41,6 +57,7 @@ public class StagingItemProcessor<T> implements ItemProcessor<ProcessIndicatorIt
* Use the technical identifier to mark the input row as processed and
* return unwrapped item.
*/
@Override
public T process(ProcessIndicatorItemWrapper<T> wrapper) throws Exception {
int count = jdbcTemplate.update("UPDATE BATCH_STAGING SET PROCESSED=? WHERE ID=? AND PROCESSED=?",

View File

@@ -1,3 +1,18 @@
/*
* Copyright 2013 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.batch.sample.data;
import java.math.BigDecimal;

View File

@@ -18,6 +18,7 @@ package org.springframework.batch.sample.domain.football;
import java.io.Serializable;
@SuppressWarnings("serial")
public class Game implements Serializable {
private String id;
@@ -217,6 +218,7 @@ public class Game implements Serializable {
}
@Override
public String toString() {
return "Game: ID=" + id + " " + team + " vs. " + opponent +

View File

@@ -18,6 +18,7 @@ package org.springframework.batch.sample.domain.football;
import java.io.Serializable;
@SuppressWarnings("serial")
public class Player implements Serializable {
private String id;
@@ -27,6 +28,7 @@ public class Player implements Serializable {
private int birthYear;
private int debutYear;
@Override
public String toString() {
return "PLAYER:id=" + id + ",Last Name=" + lastName +

View File

@@ -0,0 +1,41 @@
/*
* Copyright 2006-2007 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.batch.sample.domain.football.internal;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.batch.repeat.RepeatContext;
import org.springframework.batch.repeat.exception.ExceptionHandler;
public class FootballExceptionHandler implements ExceptionHandler {
private static final Log logger = LogFactory
.getLog(FootballExceptionHandler.class);
@Override
public void handleException(RepeatContext context, Throwable throwable)
throws Throwable {
if (!(throwable instanceof NumberFormatException)) {
throw throwable;
} else {
logger.error("Number Format Exception!", throwable);
}
}
}

View File

@@ -22,6 +22,7 @@ import org.springframework.batch.sample.domain.football.Game;
public class GameFieldSetMapper implements FieldSetMapper<Game> {
@Override
public Game mapFieldSet(FieldSet fs) {
if(fs == null){

View File

@@ -29,6 +29,7 @@ public class JdbcGameDao extends JdbcDaoSupport implements ItemWriter<Game> {
private SimpleJdbcInsert insertGame;
@Override
protected void initDao() throws Exception {
super.initDao();
insertGame = new SimpleJdbcInsert(getDataSource()).withTableName("GAMES").usingColumns("player_id", "year_no",
@@ -36,6 +37,7 @@ public class JdbcGameDao extends JdbcDaoSupport implements ItemWriter<Game> {
"rushes", "rush_yards", "receptions", "receptions_yards", "total_td");
}
@Override
public void write(List<? extends Game> games) {
for (Game game : games) {

View File

@@ -36,7 +36,8 @@ public class JdbcPlayerDao implements PlayerDao {
private NamedParameterJdbcOperations namedParameterJdbcTemplate;
public void savePlayer(Player player) {
@Override
public void savePlayer(Player player) {
namedParameterJdbcTemplate.update(INSERT_PLAYER, new BeanPropertySqlParameterSource(player));
}

View File

@@ -35,6 +35,7 @@ public class JdbcPlayerSummaryDao implements ItemWriter<PlayerSummary> {
private NamedParameterJdbcOperations namedParameterJdbcTemplate;
@Override
public void write(List<? extends PlayerSummary> summaries) {
for (PlayerSummary summary : summaries) {

View File

@@ -22,6 +22,7 @@ import org.springframework.batch.sample.domain.football.Player;
public class PlayerFieldSetMapper implements FieldSetMapper<Player> {
@Override
public Player mapFieldSet(FieldSet fs) {
if(fs == null){

View File

@@ -26,6 +26,7 @@ public class PlayerItemWriter implements ItemWriter<Player> {
private PlayerDao playerDao;
@Override
public void write(List<? extends Player> players) throws Exception {
for (Player player : players) {
playerDao.savePlayer(player);

View File

@@ -32,6 +32,7 @@ public class PlayerSummaryMapper implements ParameterizedRowMapper<PlayerSummary
/* (non-Javadoc)
* @see org.springframework.jdbc.core.RowMapper#mapRow(java.sql.ResultSet, int)
*/
@Override
public PlayerSummary mapRow(ResultSet rs, int rowNum) throws SQLException {
PlayerSummary summary = new PlayerSummary();

View File

@@ -27,12 +27,13 @@ import org.springframework.jdbc.core.RowMapper;
* @author Lucas Ward
*
*/
public class PlayerSummaryRowMapper implements RowMapper {
public class PlayerSummaryRowMapper implements RowMapper<PlayerSummary> {
/* (non-Javadoc)
* @see org.springframework.jdbc.core.RowMapper#mapRow(java.sql.ResultSet, int)
*/
public Object mapRow(ResultSet rs, int rowNum) throws SQLException {
@Override
public PlayerSummary mapRow(ResultSet rs, int rowNum) throws SQLException {
PlayerSummary summary = new PlayerSummary();

View File

@@ -39,6 +39,7 @@ public class TestMailErrorHandler implements MailErrorHandler {
private List<MailMessage> failedMessages = new ArrayList<MailMessage>();
@Override
public void handle(MailMessage failedMessage, Exception ex) {
this.failedMessages.add(failedMessage);
LOGGER.error("Mail message failed: " + failedMessage, ex);

View File

@@ -43,14 +43,16 @@ public class TestMailSender implements MailSender {
received.clear();
}
@Override
public void send(SimpleMailMessage simpleMessage) throws MailException {
throw new UnsupportedOperationException("Not implememted. Use send(SimpleMailMessage[]).");
throw new UnsupportedOperationException("Not implemented. Use send(SimpleMailMessage[]).");
}
public void setSubjectsToFail(List<String> subjectsToFail) {
this.subjectsToFail = subjectsToFail;
}
@Override
public void send(SimpleMailMessage[] simpleMessages) throws MailException {
Map<Object, Exception> failedMessages = new LinkedHashMap<Object, Exception>();
for (SimpleMailMessage simpleMessage : simpleMessages) {

View File

@@ -33,7 +33,8 @@ public class UserMailItemProcessor implements
/**
* @see org.springframework.batch.item.ItemProcessor#process(java.lang.Object)
*/
public SimpleMailMessage process( User user ) throws Exception {
@Override
public SimpleMailMessage process( User user ) throws Exception {
SimpleMailMessage message = new SimpleMailMessage();
message.setTo( user.getEmail() );
message.setFrom( "communications@thecompany.com" );

View File

@@ -70,6 +70,7 @@ public class AggregateItemFieldSetMapper<T> implements FieldSetMapper<AggregateI
* Check mandatory properties (delegate).
* @see org.springframework.beans.factory.InitializingBean#afterPropertiesSet()
*/
@Override
public void afterPropertiesSet() throws Exception {
Assert.notNull(delegate, "A FieldSetMapper delegate must be provided.");
}
@@ -85,6 +86,7 @@ public class AggregateItemFieldSetMapper<T> implements FieldSetMapper<AggregateI
* delegate
* @throws BindException if one of the delegates does
*/
@Override
public AggregateItem<T> mapFieldSet(FieldSet fieldSet) throws BindException {
if (fieldSet.readString(0).equals(begin)) {

View File

@@ -32,8 +32,8 @@ import org.springframework.batch.item.ItemReader;
* {@link AggregateItem} which responds true to its query methods
* <code>is*()</code>.<br/><br/>
*
* This class is thread safe (it can be used concurrently by multiple threads)
* as long as the {@link ItemReader} is also thread safe.
* This class is thread-safe (it can be used concurrently by multiple threads)
* as long as the {@link ItemReader} is also thread-safe.
*
* @see AggregateItem#isHeader()
* @see AggregateItem#isFooter()
@@ -52,6 +52,7 @@ public class AggregateItemReader<T> implements ItemReader<List<T>> {
*
* @see org.springframework.batch.item.ItemReader#read()
*/
@Override
public List<T> read() throws Exception {
ResultHolder holder = new ResultHolder();

View File

@@ -59,6 +59,7 @@ public class OrderItemReader implements ItemReader<Order> {
* @throws Exception
* @see org.springframework.batch.item.ItemReader#read()
*/
@Override
public Order read() throws Exception {
recordFinished = false;

View File

@@ -34,6 +34,7 @@ public class OrderLineAggregator implements LineAggregator<Order> {
private Map<String, LineAggregator<Object>> aggregators;
@Override
public String aggregate(Order order) {
StringBuilder result = new StringBuilder();

View File

@@ -1,3 +1,18 @@
/*
* Copyright 2009-2014 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.batch.sample.domain.order.internal.extractor;
import org.springframework.batch.item.file.transform.FieldExtractor;
@@ -10,6 +25,7 @@ import org.springframework.batch.sample.domain.order.Order;
*/
public class AddressFieldExtractor implements FieldExtractor<Order> {
@Override
public Object[] extract(Order order) {
Address address = order.getBillingAddress();
return new Object[] { "ADDRESS:", address.getAddrLine1(), address.getCity(), address.getZipCode() };

View File

@@ -1,3 +1,18 @@
/*
* Copyright 2009-2014 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.batch.sample.domain.order.internal.extractor;
import org.springframework.batch.item.file.transform.FieldExtractor;
@@ -10,6 +25,7 @@ import org.springframework.batch.sample.domain.order.Order;
*/
public class BillingInfoFieldExtractor implements FieldExtractor<Order> {
@Override
public Object[] extract(Order order) {
BillingInfo billingInfo = order.getBilling();
return new Object[] { "BILLING:", billingInfo.getPaymentId(), billingInfo.getPaymentDesc() };

View File

@@ -1,3 +1,18 @@
/*
* Copyright 2009-2014 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.batch.sample.domain.order.internal.extractor;
import org.springframework.batch.item.file.transform.FieldExtractor;
@@ -10,6 +25,7 @@ import org.springframework.batch.sample.domain.order.Order;
*/
public class CustomerFieldExtractor implements FieldExtractor<Order> {
@Override
public Object[] extract(Order order) {
Customer customer = order.getCustomer();
return new Object[] { "CUSTOMER:", customer.getRegistrationId(), emptyIfNull(customer.getFirstName()),

View File

@@ -1,3 +1,18 @@
/*
* Copyright 2009-2014 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.batch.sample.domain.order.internal.extractor;
import org.springframework.batch.item.file.transform.FieldExtractor;
@@ -9,6 +24,7 @@ import org.springframework.batch.sample.domain.order.Order;
*/
public class FooterFieldExtractor implements FieldExtractor<Order> {
@Override
public Object[] extract(Order order) {
return new Object[] { "END_ORDER:", order.getTotalPrice() };
}

View File

@@ -1,3 +1,18 @@
/*
* Copyright 2009-2014 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.batch.sample.domain.order.internal.extractor;
import java.text.SimpleDateFormat;
@@ -12,6 +27,7 @@ import org.springframework.batch.sample.domain.order.Order;
public class HeaderFieldExtractor implements FieldExtractor<Order> {
private SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd");
@Override
public Object[] extract(Order order) {
return new Object[] { "BEGIN_ORDER:", order.getOrderId(), dateFormat.format(order.getOrderDate()) };
}

View File

@@ -1,3 +1,18 @@
/*
* Copyright 2009-2014 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.batch.sample.domain.order.internal.extractor;
import org.springframework.batch.item.file.transform.FieldExtractor;
@@ -9,6 +24,7 @@ import org.springframework.batch.sample.domain.order.LineItem;
*/
public class LineItemFieldExtractor implements FieldExtractor<LineItem> {
@Override
public Object[] extract(LineItem item) {
return new Object[] { "ITEM:", item.getItemId(), item.getPrice() };
}

View File

@@ -30,6 +30,7 @@ public class AddressFieldSetMapper implements FieldSetMapper<Address> {
public static final String STATE_COLUMN = "STATE";
public static final String COUNTRY_COLUMN = "COUNTRY";
@Override
public Address mapFieldSet(FieldSet fieldSet) {
Address address = new Address();

View File

@@ -25,6 +25,7 @@ public class BillingFieldSetMapper implements FieldSetMapper<BillingInfo> {
public static final String PAYMENT_TYPE_ID_COLUMN = "PAYMENT_TYPE_ID";
public static final String PAYMENT_DESC_COLUMN = "PAYMENT_DESC";
@Override
public BillingInfo mapFieldSet(FieldSet fieldSet) {
BillingInfo info = new BillingInfo();

View File

@@ -32,6 +32,7 @@ public class CustomerFieldSetMapper implements FieldSetMapper<Customer> {
public static final String REG_ID_COLUMN = "REG_ID";
public static final String VIP_COLUMN = "VIP";
@Override
public Customer mapFieldSet(FieldSet fieldSet) {
Customer customer = new Customer();

View File

@@ -25,6 +25,7 @@ public class HeaderFieldSetMapper implements FieldSetMapper<Order> {
public static final String ORDER_ID_COLUMN = "ORDER_ID";
public static final String ORDER_DATE_COLUMN = "ORDER_DATE";
@Override
public Order mapFieldSet(FieldSet fieldSet) {
Order order = new Order();
order.setOrderId(fieldSet.readLong(ORDER_ID_COLUMN));

View File

@@ -31,6 +31,7 @@ public class OrderItemFieldSetMapper implements FieldSetMapper<LineItem> {
public static final String PRICE_COLUMN = "PRICE";
public static final String ITEM_ID_COLUMN = "ITEM_ID";
@Override
public LineItem mapFieldSet(FieldSet fieldSet) {
LineItem item = new LineItem();

View File

@@ -26,6 +26,7 @@ public class ShippingFieldSetMapper implements FieldSetMapper<ShippingInfo> {
public static final String SHIPPING_TYPE_ID_COLUMN = "SHIPPING_TYPE_ID";
public static final String SHIPPER_ID_COLUMN = "SHIPPER_ID";
@Override
public ShippingInfo mapFieldSet(FieldSet fieldSet) {
ShippingInfo info = new ShippingInfo();

View File

@@ -1,3 +1,18 @@
/*
* Copyright 2014 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.batch.sample.domain.order.internal.validator;
import java.math.BigDecimal;
@@ -123,11 +138,11 @@ public class OrderValidator implements Validator {
//calculate total price
//discount coeficient = (100.00 - discountPerc) / 100.00
//discount coefficient = (100.00 - discountPerc) / 100.00
BigDecimal coef = BD_100.subtract(lineItem.getDiscountPerc())
.divide(BD_100, 4, BigDecimal.ROUND_HALF_UP);
//discountedPrice = (price * coef) - discountAmount
//discountedPrice = (price * coefficient) - discountAmount
//at least one of discountPerc and discountAmount is 0 - this is validated by ValidateDiscountsFunction
BigDecimal discountedPrice = lineItem.getPrice().multiply(coef)
.subtract(lineItem.getDiscountAmount());
@@ -253,13 +268,13 @@ public class OrderValidator implements Validator {
errors.rejectValue("customer.lastName", "error.customer.lastname");
}
if(customer.isRegistered() && (customer.getRegistrationId() < 0 || customer.getRegistrationId() >= 99999999l)) {
if(customer.isRegistered() && (customer.getRegistrationId() < 0 || customer.getRegistrationId() >= 99999999L)) {
errors.rejectValue("customer.registrationId", "error.customer.registrationid");
}
}
protected void validateOrder(Order item, Errors errors) {
if(item.getOrderId() < 0 || item.getOrderId() > 9999999999l) {
if(item.getOrderId() < 0 || item.getOrderId() > 9999999999L) {
errors.rejectValue("orderId", "error.order.id");
}

View File

@@ -25,9 +25,9 @@ import org.springframework.batch.sample.domain.person.Person;
public class PersonWriter implements ItemWriter<Person> {
private static Log log = LogFactory.getLog(PersonWriter.class);
@Override
public void write(List<? extends Person> data) {
@Override
public void write(List<? extends Person> data) {
log.debug("Processing: " + data);
}
}

View File

@@ -39,6 +39,7 @@ public class CompositeCustomerUpdateLineTokenizer extends StepExecutionListenerS
/* (non-Javadoc)
* @see org.springframework.batch.item.file.transform.LineTokenizer#tokenize(java.lang.String)
*/
@Override
public FieldSet tokenize(String line) {
if(line.charAt(0) == 'F'){

View File

@@ -42,6 +42,7 @@ public class CustomerCredit {
this.credit = credit;
}
@Override
public String toString() {
return "CustomerCredit [id=" + id + ",name=" + name + ", credit=" + credit + "]";
}
@@ -78,10 +79,12 @@ public class CustomerCredit {
return newCredit;
}
@Override
public boolean equals(Object o) {
return (o instanceof CustomerCredit) && ((CustomerCredit) o).id == id;
}
@Override
public int hashCode() {
return id;
}

View File

@@ -47,7 +47,8 @@ public class CustomerDebit {
this.name = name;
}
public String toString() {
@Override
public String toString() {
return "CustomerDebit [name=" + name + ", debit=" + debit + "]";
}

View File

@@ -20,7 +20,7 @@ import java.math.BigDecimal;
/**
* Immutable Value Object representing an update to the customer as stored in the database.
* This object has the customer name, credit ammount, and the operation to be performed
* This object has the customer name, credit amount, and the operation to be performed
* on them. In the case of an add, a new customer will be entered with the appropriate
* credit. In the case of an update, the customer's credit is considered an absolute update.
* Deletes are currently not supported, but can still be read in from a file.

View File

@@ -29,6 +29,7 @@ import org.springframework.batch.item.file.transform.FieldSet;
*/
public class CustomerUpdateFieldSetMapper implements FieldSetMapper<CustomerUpdate> {
@Override
public CustomerUpdate mapFieldSet(FieldSet fs) {
if (fs == null) {

View File

@@ -29,6 +29,7 @@ public class CustomerUpdateProcessor implements ItemProcessor<CustomerUpdate, Cu
private CustomerDao customerDao;
private InvalidCustomerLogger invalidCustomerLogger;
@Override
public CustomerUpdate process(CustomerUpdate item) throws Exception {
if(item.getOperation() == DELETE){

View File

@@ -28,6 +28,7 @@ public class CustomerUpdateWriter implements ItemWriter<CustomerUpdate> {
private CustomerDao customerDao;
@Override
public void write(List<? extends CustomerUpdate> items) throws Exception {
for(CustomerUpdate customerUpdate : items){
if(customerUpdate.getOperation() == CustomerOperation.ADD){

View File

@@ -24,6 +24,7 @@ import java.math.BigDecimal;
* @author Rob Harrop
* @author Dave Syer
*/
@SuppressWarnings("serial")
public class Trade implements Serializable {
private String isin = "";
private long quantity = 0;
@@ -97,7 +98,8 @@ public class Trade implements Serializable {
return customer;
}
public String toString() {
@Override
public String toString() {
return "Trade: [isin=" + this.isin + ",quantity=" + this.quantity + ",price="
+ this.price + ",customer=" + this.customer + "]";
}

View File

@@ -0,0 +1,49 @@
/*
* Copyright 2006-2007 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.batch.sample.domain.trade.internal;
import java.util.List;
import org.springframework.batch.item.ItemWriter;
import org.springframework.batch.sample.domain.trade.CustomerCredit;
import org.springframework.batch.sample.domain.trade.CustomerCreditDao;
/**
* Delegates actual writing to a custom DAO.
*
* @author Robert Kasanicky
*/
public class CustomerCreditItemWriter implements ItemWriter<CustomerCredit> {
private CustomerCreditDao customerCreditDao;
/**
* Public setter for the {@link CustomerCreditDao}.
* @param customerCreditDao the {@link CustomerCreditDao} to set
*/
public void setCustomerCreditDao(CustomerCreditDao customerCreditDao) {
this.customerCreditDao = customerCreditDao;
}
@Override
public void write(List<? extends CustomerCredit> customerCredits) throws Exception {
for (CustomerCredit customerCredit : customerCredits) {
customerCreditDao.writeCredit(customerCredit);
}
}
}

View File

@@ -22,13 +22,14 @@ import java.sql.SQLException;
import org.springframework.batch.sample.domain.trade.CustomerCredit;
import org.springframework.jdbc.core.RowMapper;
public class CustomerCreditRowMapper implements RowMapper {
public class CustomerCreditRowMapper implements RowMapper<CustomerCredit> {
public static final String ID_COLUMN = "id";
public static final String NAME_COLUMN = "name";
public static final String CREDIT_COLUMN = "credit";
public Object mapRow(ResultSet rs, int rowNum) throws SQLException {
@Override
public CustomerCredit mapRow(ResultSet rs, int rowNum) throws SQLException {
CustomerCredit customerCredit = new CustomerCredit();
customerCredit.setId(rs.getInt(ID_COLUMN));

View File

@@ -0,0 +1,41 @@
/*
* Copyright 2006-2007 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.batch.sample.domain.trade.internal;
import java.sql.ResultSet;
import java.sql.SQLException;
import org.springframework.batch.sample.domain.trade.CustomerDebit;
import org.springframework.jdbc.core.RowMapper;
public class CustomerDebitRowMapper implements RowMapper<CustomerDebit> {
public static final String CUSTOMER_COLUMN = "customer";
public static final String PRICE_COLUMN = "price";
@Override
public CustomerDebit mapRow(ResultSet rs, int ignoredRowNumber)
throws SQLException {
CustomerDebit customerDebit = new CustomerDebit();
customerDebit.setName(rs.getString(CUSTOMER_COLUMN));
customerDebit.setDebit(rs.getBigDecimal(PRICE_COLUMN));
return customerDebit;
}
}

View File

@@ -33,6 +33,7 @@ public class CustomerUpdateWriter implements ItemWriter<Trade> {
private CustomerDebitDao dao;
@Override
public void write(List<? extends Trade> trades) {
for (Trade trade : trades) {
CustomerDebit customerDebit = new CustomerDebit();

View File

@@ -40,6 +40,7 @@ public class FlatFileCustomerCreditDao implements CustomerCreditDao,
private volatile boolean opened = false;
@Override
public void writeCredit(CustomerCredit customerCredit) throws Exception {
if (!opened) {
@@ -78,6 +79,7 @@ public class FlatFileCustomerCreditDao implements CustomerCreditDao,
*
* @see org.springframework.beans.factory.DisposableBean#destroy()
*/
@Override
public void destroy() throws Exception {
close();
}

View File

@@ -32,6 +32,7 @@ public class GeneratingTradeItemReader implements ItemReader<Trade> {
private int counter = 0;
@Override
public Trade read() throws Exception {
if (counter < limit) {
counter++;

View File

@@ -38,6 +38,7 @@ public class HibernateAwareCustomerCreditItemWriter implements ItemWriter<Custom
private SessionFactory sessionFactory;
@Override
public void write(List<? extends CustomerCredit> items) throws Exception {
for (CustomerCredit credit : items) {
dao.writeCredit(credit);
@@ -61,6 +62,7 @@ public class HibernateAwareCustomerCreditItemWriter implements ItemWriter<Custom
this.sessionFactory = sessionFactory;
}
@Override
public void afterPropertiesSet() throws Exception {
Assert.state(sessionFactory != null, "Hibernate SessionFactory is required");
Assert.notNull(dao, "Delegate DAO must be set");

View File

@@ -55,6 +55,7 @@ public class HibernateCreditDao implements
*
* @see org.springframework.batch.sample.domain.trade.internal.CustomerCreditWriter#write(org.springframework.batch.sample.domain.CustomerCredit)
*/
@Override
public void writeCredit(CustomerCredit customerCredit) {
if (customerCredit.getId() == failOnFlush) {
// try to insert one with a duplicate ID
@@ -87,6 +88,7 @@ public class HibernateCreditDao implements
this.failOnFlush = failOnFlush;
}
@Override
public void onError(RepeatContext context, Throwable e) {
errors.add(e);
}
@@ -94,24 +96,28 @@ public class HibernateCreditDao implements
/* (non-Javadoc)
* @see org.springframework.batch.repeat.RepeatInterceptor#after(org.springframework.batch.repeat.RepeatContext, org.springframework.batch.repeat.ExitStatus)
*/
@Override
public void after(RepeatContext context, RepeatStatus result) {
}
/* (non-Javadoc)
* @see org.springframework.batch.repeat.RepeatInterceptor#before(org.springframework.batch.repeat.RepeatContext)
*/
@Override
public void before(RepeatContext context) {
}
/* (non-Javadoc)
* @see org.springframework.batch.repeat.RepeatInterceptor#close(org.springframework.batch.repeat.RepeatContext)
*/
@Override
public void close(RepeatContext context) {
}
/* (non-Javadoc)
* @see org.springframework.batch.repeat.RepeatInterceptor#open(org.springframework.batch.repeat.RepeatContext)
*/
@Override
public void open(RepeatContext context) {
}

View File

@@ -43,14 +43,15 @@ public class JdbcCustomerDao extends JdbcDaoSupport implements CustomerDao{
this.incrementer = incrementer;
}
@Override
public CustomerCredit getCustomerByName(String name) {
@SuppressWarnings("unchecked")
List<CustomerCredit> customers = (List<CustomerCredit>) getJdbcTemplate().query(GET_CUSTOMER_BY_NAME, new Object[]{name},
List<CustomerCredit> customers = getJdbcTemplate().query(GET_CUSTOMER_BY_NAME, new Object[]{name},
new RowMapper(){
new RowMapper<CustomerCredit>(){
public Object mapRow(ResultSet rs, int rowNum) throws SQLException {
@Override
public CustomerCredit mapRow(ResultSet rs, int rowNum) throws SQLException {
CustomerCredit customer = new CustomerCredit();
customer.setName(rs.getString("NAME"));
customer.setId(rs.getInt("ID"));
@@ -69,11 +70,13 @@ public class JdbcCustomerDao extends JdbcDaoSupport implements CustomerDao{
}
@Override
public void insertCustomer(String name, BigDecimal credit) {
getJdbcTemplate().update(INSERT_CUSTOMER, new Object[]{incrementer.nextIntValue(), name, credit});
}
@Override
public void updateCustomer(String name, BigDecimal credit) {
getJdbcTemplate().update(UPDATE_CUSTOMER, new Object[]{credit, name});
}

View File

@@ -36,7 +36,8 @@ public class JdbcCustomerDebitDao implements CustomerDebitDao {
private JdbcOperations jdbcTemplate;
public void write(CustomerDebit customerDebit) {
@Override
public void write(CustomerDebit customerDebit) {
jdbcTemplate.update(UPDATE_CREDIT, customerDebit.getDebit(), customerDebit.getName());
}

View File

@@ -40,19 +40,20 @@ public class JdbcTradeDao implements TradeDao {
private static final String INSERT_TRADE_RECORD = "INSERT INTO TRADE (id, version, isin, quantity, price, customer) VALUES (?, 0, ?, ? ,?, ?)";
/**
* handles the processing of sql query
* handles the processing of SQL query
*/
private JdbcOperations jdbcTemplate;
/**
* database is not expected to be setup for autoincrement
* database is not expected to be setup for auto increment
*/
private DataFieldMaxValueIncrementer incrementer;
/**
* @see TradeDao
*/
public void writeTrade(Trade trade) {
@Override
public void writeTrade(Trade trade) {
Long id = incrementer.nextLongValue();
log.debug("Processing: " + trade);
jdbcTemplate.update(INSERT_TRADE_RECORD,

View File

@@ -29,7 +29,8 @@ public class TradeFieldSetMapper implements FieldSetMapper<Trade> {
public static final int PRICE_COLUMN = 2;
public static final int CUSTOMER_COLUMN = 3;
public Trade mapFieldSet(FieldSet fieldSet) {
@Override
public Trade mapFieldSet(FieldSet fieldSet) {
Trade trade = new Trade();
trade.setIsin(fieldSet.readString(ISIN_COLUMN));

View File

@@ -40,6 +40,7 @@ public class TradeProcessor implements ItemProcessor<Trade, Trade> {
this.failure = failure;
}
@Override
public Trade process(Trade item) throws Exception {
if ((failedItem == null && index++ == failure) || (failedItem != null && failedItem.equals(item))) {
failedItem = item;

View File

@@ -22,7 +22,7 @@ import java.sql.SQLException;
import org.springframework.batch.sample.domain.trade.Trade;
import org.springframework.jdbc.core.RowMapper;
public class TradeRowMapper implements RowMapper {
public class TradeRowMapper implements RowMapper<Trade> {
public static final int ISIN_COLUMN = 1;
public static final int QUANTITY_COLUMN = 2;
@@ -31,7 +31,8 @@ public class TradeRowMapper implements RowMapper {
public static final int ID_COLUMN = 5;
public static final int VERSION_COLUMN = 6;
public Object mapRow(ResultSet rs, int rowNum) throws SQLException {
@Override
public Trade mapRow(ResultSet rs, int rowNum) throws SQLException {
Trade trade = new Trade(rs.getLong(ID_COLUMN));
trade.setIsin(rs.getString(ISIN_COLUMN));

View File

@@ -47,6 +47,7 @@ public class TradeWriter extends ItemStreamSupport implements ItemWriter<Trade>
private BigDecimal totalPrice = BigDecimal.ZERO;
@Override
public void write(List<? extends Trade> trades) {
for (Trade trade : trades) {

View File

@@ -31,7 +31,7 @@ import org.springframework.jmx.export.notification.NotificationPublisherAware;
* @author Dave Syer
* @since 1.0
*/
public class JobExecutionNotificationPublisher implements ApplicationListener, NotificationPublisherAware {
public class JobExecutionNotificationPublisher implements ApplicationListener<SimpleMessageApplicationEvent>, NotificationPublisherAware {
private static final Log LOG = LogFactory.getLog(JobExecutionNotificationPublisher.class);
private NotificationPublisher notificationPublisher;
@@ -43,6 +43,7 @@ public class JobExecutionNotificationPublisher implements ApplicationListener, N
*
* @see org.springframework.jmx.export.notification.NotificationPublisherAware#setNotificationPublisher(org.springframework.jmx.export.notification.NotificationPublisher)
*/
@Override
public void setNotificationPublisher(NotificationPublisher notificationPublisher) {
this.notificationPublisher = notificationPublisher;
}
@@ -54,12 +55,11 @@ public class JobExecutionNotificationPublisher implements ApplicationListener, N
*
* @see ApplicationListener#onApplicationEvent(ApplicationEvent)
*/
public void onApplicationEvent(ApplicationEvent applicationEvent) {
if (applicationEvent instanceof SimpleMessageApplicationEvent) {
String message = applicationEvent.toString();
LOG.info(message);
publish(message);
}
@Override
public void onApplicationEvent(SimpleMessageApplicationEvent applicationEvent) {
String message = applicationEvent.toString();
LOG.info(message);
publish(message);
}
/**

View File

@@ -22,6 +22,7 @@ import org.springframework.context.ApplicationEvent;
* @author Dave Syer
*
*/
@SuppressWarnings("serial")
public class SimpleMessageApplicationEvent extends ApplicationEvent {
private String message;
@@ -34,6 +35,7 @@ public class SimpleMessageApplicationEvent extends ApplicationEvent {
/* (non-Javadoc)
* @see java.util.EventObject#toString()
*/
@Override
public String toString() {
return "message=["+message+"], " + super.toString();
}

View File

@@ -35,6 +35,7 @@ public class StepExecutionApplicationEventAdvice implements ApplicationEventPubl
* (non-Javadoc)
* @see org.springframework.context.ApplicationEventPublisherAware#setApplicationEventPublisher(org.springframework.context.ApplicationEventPublisher)
*/
@Override
public void setApplicationEventPublisher(ApplicationEventPublisher applicationEventPublisher) {
this.applicationEventPublisher = applicationEventPublisher;
}

View File

@@ -38,6 +38,7 @@ public class DefaultJobLoader implements JobLoader, ApplicationContextAware {
private Map<String, String> configurations = new HashMap<String, String>();
@Override
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
this.applicationContext = applicationContext;
}
@@ -46,6 +47,7 @@ public class DefaultJobLoader implements JobLoader, ApplicationContextAware {
this.registry = registry;
}
@Override
public Map<String, String> getConfigurations() {
Map<String, String> result = new HashMap<String, String>(configurations);
for (String jobName : registry.getJobNames()) {
@@ -63,6 +65,8 @@ public class DefaultJobLoader implements JobLoader, ApplicationContextAware {
return result;
}
@Override
@SuppressWarnings("resource")
public void loadResource(String path) {
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(new String[] { path },
applicationContext);
@@ -72,6 +76,7 @@ public class DefaultJobLoader implements JobLoader, ApplicationContextAware {
}
}
@Override
public Object getJobConfiguration(String name) {
try {
return registry.getJob(name);
@@ -81,6 +86,7 @@ public class DefaultJobLoader implements JobLoader, ApplicationContextAware {
}
}
@Override
public Object getProperty(String path) {
int index = PropertyAccessorUtils.getFirstNestedPropertySeparatorIndex(path);
BeanWrapperImpl wrapper = createBeanWrapper(path, index);
@@ -88,6 +94,7 @@ public class DefaultJobLoader implements JobLoader, ApplicationContextAware {
return wrapper.getPropertyValue(key);
}
@Override
public void setProperty(String path, String value) {
int index = PropertyAccessorUtils.getFirstNestedPropertySeparatorIndex(path);
BeanWrapperImpl wrapper = createBeanWrapper(path, index);

View File

@@ -33,6 +33,7 @@ public class GeneratingTradeResettingListener extends StepExecutionListenerSuppo
private GeneratingTradeItemReader reader;
@Override
public ExitStatus afterStep(StepExecution stepExecution) {
this.reader.resetCounter();
return null;
@@ -42,6 +43,7 @@ public class GeneratingTradeResettingListener extends StepExecutionListenerSuppo
this.reader = reader;
}
@Override
public void afterPropertiesSet() throws Exception {
Assert.notNull(this.reader, "The 'reader' must be set.");
}

View File

@@ -33,6 +33,7 @@ public class LimitDecider implements JobExecutionDecider {
private int limit = 1;
@Override
public FlowExecutionStatus decide(JobExecution jobExecution, StepExecution stepExecution) {
if (++count >= limit) {
return new FlowExecutionStatus("COMPLETED");

View File

@@ -62,6 +62,7 @@ public class JobLauncherDetails extends QuartzJobBean {
this.jobLauncher = jobLauncher;
}
@Override
@SuppressWarnings("unchecked")
protected void executeInternal(JobExecutionContext context) {
Map<String, Object> jobDataMap = context.getMergedJobDataMap();

View File

@@ -1,3 +1,18 @@
/*
* Copyright 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.batch.sample.rabbitmq.amqp;
import org.springframework.amqp.core.AmqpTemplate;

View File

@@ -1,3 +1,18 @@
/*
* Copyright 2012-2014 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.batch.sample.rabbitmq.processor;
import org.springframework.batch.item.ItemProcessor;
@@ -11,7 +26,8 @@ import java.util.Date;
*/
public class MessageProcessor implements ItemProcessor<String, String> {
public String process(String message) throws Exception {
@Override
public String process(String message) throws Exception {
return "Message: \"" + message + "\" processed on: " + new Date();
}
}

View File

@@ -25,6 +25,7 @@ import org.springframework.batch.item.ItemWriter;
*/
public class DummyItemWriter implements ItemWriter<Object> {
@Override
public void write(List<? extends Object> item) throws Exception {
// NO-OP
Thread.sleep(500);

View File

@@ -43,6 +43,7 @@ public class ExceptionThrowingItemReaderProxy<T> implements ItemReader<T> {
this.throwExceptionOnRecordNumber = throwExceptionOnRecordNumber;
}
@Override
public T read() throws Exception {
counter++;

View File

@@ -31,11 +31,13 @@ import org.springframework.util.Assert;
public class HeaderCopyCallback implements LineCallbackHandler, FlatFileHeaderCallback {
private String header = "";
@Override
public void handleLine(String line) {
Assert.notNull(line);
this.header = line;
}
@Override
public void writeHeader(Writer writer) throws IOException {
writer.write("header from input: " + header);
}

View File

@@ -30,6 +30,7 @@ public class RetrySampleItemWriter<T> implements ItemWriter<T> {
private int counter = 0;
@Override
public void write(List<? extends T> items) throws Exception {
int current = counter;
counter += items.size();

View File

@@ -30,6 +30,7 @@ public class SummaryFooterCallback extends StepExecutionListenerSupport implemen
private StepExecution stepExecution;
@Override
public void writeFooter(Writer writer) throws IOException {
writer.write("footer - number of items written: " + stepExecution.getWriteCount());
}

View File

@@ -1,3 +1,18 @@
/*
* Copyright 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.batch.sample;
import static org.junit.Assert.assertTrue;

View File

@@ -1,3 +1,18 @@
/*
* Copyright 2008-2014 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.batch.sample;
import static org.junit.Assert.assertEquals;
@@ -57,6 +72,7 @@ public class CompositeItemWriterSampleFunctionalTests {
}
private void checkOutputTable(int before) {
@SuppressWarnings("serial")
final List<Trade> trades = new ArrayList<Trade>() {
{
add(new Trade("UK21341EAH41", 211, new BigDecimal("31.11"), "customer1"));
@@ -88,7 +104,7 @@ public class CompositeItemWriterSampleFunctionalTests {
}
private void checkOutputFile(String fileName) throws IOException {
@SuppressWarnings("unchecked")
@SuppressWarnings({ "unchecked", "resource" })
List<String> outputLines = IOUtils.readLines(new FileInputStream(fileName));
String output = "";

View File

@@ -1,3 +1,18 @@
/*
* Copyright 2007-2009 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.batch.sample;
import static org.junit.Assert.assertEquals;

View File

@@ -1,3 +1,18 @@
/*
* Copyright 2007-2014 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.batch.sample;
import static org.junit.Assert.assertTrue;

View File

@@ -1,3 +1,18 @@
/*
* Copyright 2008-2014 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.batch.sample;
import static org.junit.Assert.assertTrue;
@@ -50,6 +65,9 @@ public class HeaderFooterSampleFunctionalTests {
// footer contains the item count
int itemCount = lineCount - 1; // minus 1 due to header line
assertTrue(outputReader.readLine().contains(String.valueOf(itemCount)));
inputReader.close();
outputReader.close();
}
}

View File

@@ -1,3 +1,18 @@
/*
* Copyright 2007-2014 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.batch.sample;
import static org.junit.Assert.assertEquals;
@@ -101,12 +116,11 @@ public class HibernateFailureJobFunctionalTests {
/**
* All customers have the same credit
*/
@SuppressWarnings("unchecked")
protected void validatePreConditions() throws Exception {
ensureState();
creditsBeforeUpdate = (List<BigDecimal>) new TransactionTemplate(transactionManager).execute(new TransactionCallback() {
creditsBeforeUpdate = new TransactionTemplate(transactionManager).execute(new TransactionCallback<List<BigDecimal>>() {
@Override
public Object doInTransaction(TransactionStatus status) {
public List<BigDecimal> doInTransaction(TransactionStatus status) {
return jdbcTemplate.query(ALL_CUSTOMERS, new ParameterizedRowMapper<BigDecimal>() {
@Override
public BigDecimal mapRow(ResultSet rs, int rowNum) throws SQLException {
@@ -122,10 +136,11 @@ public class HibernateFailureJobFunctionalTests {
* customer table and reading the expected defaults.
*/
private void ensureState(){
new TransactionTemplate(transactionManager).execute(new TransactionCallback() {
new TransactionTemplate(transactionManager).execute(new TransactionCallback<Void>(){
@Override
public Object doInTransaction(TransactionStatus status) {
jdbcTemplate.update(DELETE_CUSTOMERS);
public Void doInTransaction(TransactionStatus status) {
jdbcTemplate.update(DELETE_CUSTOMERS);
for (String customer : customers) {
jdbcTemplate.update(customer);
}
@@ -140,9 +155,9 @@ public class HibernateFailureJobFunctionalTests {
protected void validatePostConditions() throws Exception {
final List<BigDecimal> matches = new ArrayList<BigDecimal>();
new TransactionTemplate(transactionManager).execute(new TransactionCallback() {
new TransactionTemplate(transactionManager).execute(new TransactionCallback<Void>() {
@Override
public Object doInTransaction(TransactionStatus status) {
public Void doInTransaction(TransactionStatus status) {
jdbcTemplate.query(ALL_CUSTOMERS, new RowCallbackHandler() {
private int i = 0;

View File

@@ -1,3 +1,18 @@
/*
* Copyright 2008-2009 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.batch.sample;
import static org.junit.Assert.assertEquals;

View File

@@ -1,3 +1,18 @@
/*
* Copyright 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.batch.sample;
import static org.junit.Assert.assertEquals;

View File

@@ -1,3 +1,18 @@
/*
* Copyright 2008-2009 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.batch.sample;
import static org.junit.Assert.assertEquals;

View File

@@ -1,3 +1,18 @@
/*
* Copyright 2008-2014 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.batch.sample;
import static org.junit.Assert.assertEquals;
@@ -172,7 +187,7 @@ public class SkipSampleFunctionalTests {
// Step2: 7 input records, 1 skipped on process, 1 on write => 5 written
// to output
// System.err.println(jdbcTemplate.queryForList("SELECT * FROM TRADE"));
assertEquals(5, jdbcTemplate.queryForInt("SELECT COUNT(*) from TRADE where VERSION=?", 1));
assertEquals(5, jdbcTemplate.queryForObject("SELECT COUNT(*) from TRADE where VERSION=?", Integer.class, 1).intValue());
// 1 record skipped in processing second step
assertEquals(1, SkipCheckingListener.getProcessSkips());
@@ -200,7 +215,7 @@ public class SkipSampleFunctionalTests {
assertEquals(5, JdbcTestUtils.countRowsInTable((JdbcTemplate) jdbcTemplate, "TRADE"));
// Step2: 5 input records => 5 written to output
assertEquals(5, jdbcTemplate.queryForInt("SELECT COUNT(*) from TRADE where VERSION=?", 1));
assertEquals(5, jdbcTemplate.queryForObject("SELECT COUNT(*) from TRADE where VERSION=?", Integer.class, 1).intValue());
// Neither step contained skips
assertEquals(0, JdbcTestUtils.countRowsInTable((JdbcTemplate) jdbcTemplate, "ERROR_LOG"));

View File

@@ -0,0 +1,33 @@
/*
* Copyright 2006-2009 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.batch.sample;
import org.junit.Ignore;
import org.junit.runner.RunWith;
import org.junit.runners.Suite;
import org.junit.runners.Suite.SuiteClasses;
/**
* Temporary test suite to find bug in build.
*
*/
@Ignore
@RunWith(Suite.class)
@SuiteClasses({SkipSampleFunctionalTests.class, CustomerFilterJobFunctionalTests.class})
public class TestSuite {
}

View File

@@ -1,3 +1,18 @@
/*
* Copyright 2009 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.batch.sample.common;
import static org.junit.Assert.assertEquals;

View File

@@ -1,9 +1,22 @@
/*
* Copyright 2008-2014 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.batch.sample.common;
import javax.sql.DataSource;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.batch.core.ExitStatus;
import org.springframework.batch.core.StepContribution;
import org.springframework.batch.core.StepExecution;
@@ -25,6 +38,7 @@ public class ErrorLogTasklet implements Tasklet, StepExecutionListener {
private StepExecution stepExecution;
private String stepName;
@Override
public RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext) throws Exception {
Assert.notNull(this.stepName, "Step name not set. Either this class was not registered as a listener "
+ "or the key 'stepName' was not found in the Job's ExecutionContext.");

View File

@@ -1,3 +1,18 @@
/*
* Copyright 2008-2014 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.batch.sample.common;
import static org.junit.Assert.assertEquals;
@@ -23,6 +38,7 @@ public class ExceptionThrowingItemReaderProxyTests {
RepeatSynchronizationManager.clear();
}
@SuppressWarnings("serial")
@Test
public void testProcess() throws Exception {

View File

@@ -1,3 +1,18 @@
/*
* Copyright 2009 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.batch.sample.common;
import static org.junit.Assert.assertEquals;

View File

@@ -1,3 +1,18 @@
/*
* Copyright 2008-2014 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.batch.sample.common;
import org.springframework.batch.core.ExitStatus;
@@ -7,6 +22,7 @@ import org.springframework.batch.core.job.flow.FlowExecutionStatus;
import org.springframework.batch.core.job.flow.JobExecutionDecider;
public class SkipCheckingDecider implements JobExecutionDecider {
@Override
public FlowExecutionStatus decide(JobExecution jobExecution, StepExecution stepExecution) {
if (!stepExecution.getExitStatus().getExitCode().equals(
@@ -17,4 +33,4 @@ public class SkipCheckingDecider implements JobExecutionDecider {
return new FlowExecutionStatus(ExitStatus.COMPLETED.getExitCode());
}
}
}
}

View File

@@ -1,3 +1,18 @@
/*
* Copyright 2008-2009 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.batch.sample.common;
import org.apache.commons.logging.Log;

View File

@@ -1,3 +1,18 @@
/*
* Copyright 2008-2014 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.batch.sample.common;
import static org.junit.Assert.assertEquals;
@@ -89,13 +104,14 @@ public class StagingItemReaderTests {
public void testUpdateProcessIndicatorAfterCommit() throws Exception {
TransactionTemplate txTemplate = new TransactionTemplate(transactionManager);
txTemplate.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRES_NEW);
txTemplate.execute(new TransactionCallback() {
public Object doInTransaction(TransactionStatus transactionStatus) {
txTemplate.execute(new TransactionCallback<Void>() {
@Override
public Void doInTransaction(TransactionStatus transactionStatus) {
try {
testReaderWithProcessorUpdatesProcessIndicator();
}
catch (Exception e) {
fail("Unxpected Exception: " + e);
fail("Unexpected Exception: " + e);
}
return null;
}
@@ -112,8 +128,9 @@ public class StagingItemReaderTests {
TransactionTemplate txTemplate = new TransactionTemplate(transactionManager);
txTemplate.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRES_NEW);
final Long idToUse = (Long) txTemplate.execute(new TransactionCallback() {
public Object doInTransaction(TransactionStatus transactionStatus) {
final Long idToUse = txTemplate.execute(new TransactionCallback<Long>() {
@Override
public Long doInTransaction(TransactionStatus transactionStatus) {
long id = jdbcTemplate.queryForObject("SELECT MIN(ID) from BATCH_STAGING where JOB_ID=?", Long.class, jobId);
String before = jdbcTemplate.queryForObject("SELECT PROCESSED from BATCH_STAGING where ID=?",

View File

@@ -60,7 +60,6 @@ public class StagingItemWriterTests {
public void testProcessInsertsNewItem() throws Exception {
int before = jdbcTemplate.queryForObject("SELECT COUNT(*) from BATCH_STAGING", Integer.class);
writer.write(Collections.singletonList("FOO"));
int after = jdbcTemplate.queryForObject("SELECT COUNT(*) from BATCH_STAGING", Integer.class);
assertEquals(before + 1, after);
}

View File

@@ -1,3 +1,18 @@
/*
* Copyright 2008-2014 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.batch.sample.domain.multiline;
import static org.junit.Assert.assertEquals;
@@ -51,6 +66,7 @@ public class AggregateItemFieldSetMapperTests {
@Test
public void testDelegate() throws Exception {
mapper.setDelegate(new FieldSetMapper<String>() {
@Override
public String mapFieldSet(FieldSet fs) {
return "foo";
}

View File

@@ -1,3 +1,18 @@
/*
* Copyright 2008-2014 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.batch.sample.domain.multiline;
import static org.junit.Assert.*;

View File

@@ -1,3 +1,18 @@
/*
* Copyright 2008-2014 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.batch.sample.domain.order;
import org.springframework.batch.item.file.mapping.FieldSetMapper;

View File

@@ -1,3 +1,18 @@
/*
* Copyright 2008-2014 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.batch.sample.domain.order;
import org.springframework.batch.item.file.mapping.FieldSetMapper;

Some files were not shown because too many files have changed in this diff Show More