Initial move over from i21 repo.
This commit is contained in:
@@ -0,0 +1,64 @@
|
||||
/*
|
||||
* 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;
|
||||
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.ResultSetMetaData;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.batch.io.file.FieldSet;
|
||||
|
||||
/**
|
||||
* ResultSetExtractor implementation that returns list of FieldSets
|
||||
* for given ResultSet.
|
||||
*
|
||||
* @author peter.zozom
|
||||
*
|
||||
*/
|
||||
public final class FieldSetResultSetExtractor {
|
||||
|
||||
// utility class not meant for instantiation
|
||||
private FieldSetResultSetExtractor(){}
|
||||
|
||||
/**
|
||||
* Processes single row in ResultSet and returns its FieldSet representation.
|
||||
* @param rs ResultSet ResultSet to extract data from.
|
||||
* @return FieldSet representation of current row in ResultSet
|
||||
* @throws SQLException
|
||||
*/
|
||||
public static FieldSet getFieldSet(ResultSet rs) throws SQLException {
|
||||
ResultSetMetaData metaData = rs.getMetaData();
|
||||
int columnCount = metaData.getColumnCount();
|
||||
|
||||
FieldSet fs = null;
|
||||
|
||||
List tokens = new ArrayList();
|
||||
List names = new ArrayList();
|
||||
|
||||
for (int i = 1; i <= columnCount; i++) {
|
||||
tokens.add(rs.getString(i));
|
||||
names.add(metaData.getColumnName(i));
|
||||
}
|
||||
|
||||
fs = new FieldSet((String[])tokens.toArray(new String[0]), (String[])names.toArray(new String[0]));
|
||||
|
||||
return fs;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
* 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.advice;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.aspectj.lang.JoinPoint;
|
||||
|
||||
|
||||
/**
|
||||
* Wraps calls for 'Processing' methods which output a single Object to write
|
||||
* the string representation of the object to the log.
|
||||
*
|
||||
* @author Lucas Ward
|
||||
*/
|
||||
public class MethodExecutionLogAdvice {
|
||||
|
||||
private static Log log = LogFactory.getLog(MethodExecutionLogAdvice.class);
|
||||
|
||||
/**
|
||||
* Wraps original method and adds logging both before and after method
|
||||
*/
|
||||
public void doBasicLogging(JoinPoint jp) throws Throwable {
|
||||
|
||||
log.info("Processed method "+jp);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
/*
|
||||
* 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.advice;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.aspectj.lang.JoinPoint;
|
||||
|
||||
|
||||
/**
|
||||
* Wraps calls for 'Processing' methods which output a single Object to write
|
||||
* the string representation of the object to the log.
|
||||
*
|
||||
* @author Lucas Ward
|
||||
*/
|
||||
public class ProcessorLogAdvice {
|
||||
|
||||
private static Log log = LogFactory.getLog(ProcessorLogAdvice.class);
|
||||
|
||||
/**
|
||||
* Wraps original method and adds logging both before and after method
|
||||
*/
|
||||
public void doBasicLogging(JoinPoint pjp) throws Throwable {
|
||||
Object[] args = pjp.getArgs();
|
||||
StringBuffer output = new StringBuffer();
|
||||
|
||||
for(int i = 0; i < args.length; i++){
|
||||
output.append(args[i] + " ");
|
||||
}
|
||||
|
||||
log.info("Processed: " + output.toString());
|
||||
}
|
||||
|
||||
public void doStronglyTypedLogging(Object item){
|
||||
log.info("Processed: " + item);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
* 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.advice;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.aspectj.lang.JoinPoint;
|
||||
import org.springframework.batch.sample.domain.Trade;
|
||||
|
||||
|
||||
/**
|
||||
* Wraps calls for 'Processing' methods which output a single Object to write
|
||||
* the string representation of the object to the log.
|
||||
*
|
||||
* @author Lucas Ward
|
||||
*/
|
||||
public class TradeWriterLogAdvice {
|
||||
|
||||
private static Log log = LogFactory.getLog(TradeWriterLogAdvice.class);
|
||||
|
||||
/**
|
||||
* Wraps original method and adds logging both before and after method
|
||||
*/
|
||||
public void doBasicLogging(JoinPoint pjp, Trade trade) throws Throwable {
|
||||
|
||||
log.info("Processed: " + trade.toString());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
* 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.dao;
|
||||
|
||||
import org.springframework.batch.item.ResourceLifecycle;
|
||||
import org.springframework.batch.sample.domain.CustomerCredit;
|
||||
|
||||
/**
|
||||
* Interface for writing customer's credit information to output.
|
||||
*
|
||||
* @author Robert Kasanicky
|
||||
*/
|
||||
public interface CustomerCreditWriter extends ResourceLifecycle{
|
||||
|
||||
void write(CustomerCredit customerCredit);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
/*
|
||||
* 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.dao;
|
||||
|
||||
import org.springframework.batch.sample.domain.CustomerDebit;
|
||||
|
||||
public interface CustomerDebitWriter {
|
||||
|
||||
void write(CustomerDebit customerDebit);
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
/*
|
||||
* 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.dao;
|
||||
|
||||
import org.springframework.batch.io.OutputSource;
|
||||
import org.springframework.batch.sample.domain.CustomerCredit;
|
||||
import org.springframework.beans.factory.DisposableBean;
|
||||
|
||||
|
||||
/**
|
||||
* Writes customer's credit information in a file.
|
||||
*
|
||||
* @see CustomerCreditWriter
|
||||
* @author Robert Kasanicky
|
||||
*/
|
||||
public class FlatFileCustomerCreditWriter implements CustomerCreditWriter, DisposableBean {
|
||||
|
||||
private OutputSource outputSource;
|
||||
|
||||
private String separator = "\t";
|
||||
|
||||
private volatile boolean opened = false;
|
||||
|
||||
public void write(CustomerCredit customerCredit) {
|
||||
|
||||
if (!opened) {
|
||||
open();
|
||||
}
|
||||
|
||||
String line = "" + customerCredit.getName() + separator + customerCredit.getCredit();
|
||||
|
||||
outputSource.write(line);
|
||||
}
|
||||
|
||||
public void setSeparator(String separator) {
|
||||
this.separator = separator;
|
||||
}
|
||||
|
||||
public void setOutputSource(OutputSource outputSource) {
|
||||
this.outputSource = outputSource;
|
||||
}
|
||||
|
||||
public void open() {
|
||||
outputSource.open();
|
||||
opened = true;
|
||||
}
|
||||
|
||||
public void close() {
|
||||
outputSource.close();
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.springframework.beans.factory.DisposableBean#destroy()
|
||||
*/
|
||||
public void destroy() throws Exception {
|
||||
close();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
/*
|
||||
* 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.dao;
|
||||
|
||||
import org.springframework.batch.io.OutputSource;
|
||||
import org.springframework.batch.io.file.support.transform.Converter;
|
||||
import org.springframework.batch.sample.domain.Order;
|
||||
import org.springframework.beans.factory.DisposableBean;
|
||||
|
||||
|
||||
/**
|
||||
* Writes <code>Order</code> objects to a file.
|
||||
*
|
||||
* @see OrderWriter
|
||||
*
|
||||
* @author Dave Syer
|
||||
*/
|
||||
public class FlatFileOrderWriter implements OrderWriter, DisposableBean {
|
||||
/**
|
||||
* Takes care of writing to a file
|
||||
*/
|
||||
private OutputSource outputSource;
|
||||
|
||||
/**
|
||||
* Converter for order
|
||||
*/
|
||||
private Converter converter = new OrderConverter();
|
||||
|
||||
/**
|
||||
* Public setter for the converter.
|
||||
*
|
||||
* @param converter the converter to set
|
||||
*/
|
||||
public void setConverter(Converter converter) {
|
||||
this.converter = converter;
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes information from an Order object to a file
|
||||
*/
|
||||
public void write(Order data) {
|
||||
outputSource.write(converter.convert(data));
|
||||
}
|
||||
|
||||
public void open() {
|
||||
outputSource.open();
|
||||
}
|
||||
|
||||
public void close() {
|
||||
outputSource.close();
|
||||
}
|
||||
|
||||
/**
|
||||
* Calls close to ensure that bean factories can close and always release
|
||||
* resources.
|
||||
*
|
||||
* @see org.springframework.beans.factory.DisposableBean#destroy()
|
||||
*/
|
||||
public void destroy() throws Exception {
|
||||
close();
|
||||
}
|
||||
|
||||
public void setOutputSource(OutputSource outputSource) {
|
||||
this.outputSource = outputSource;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
* 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.dao;
|
||||
|
||||
import org.springframework.batch.sample.domain.CustomerDebit;
|
||||
import org.springframework.jdbc.core.JdbcOperations;
|
||||
|
||||
|
||||
/**
|
||||
* Reduces customer's credit by the provided amount.
|
||||
*
|
||||
* @author Robert Kasanicky
|
||||
*/
|
||||
public class JdbcCustomerDebitWriter implements CustomerDebitWriter {
|
||||
|
||||
private static final String UPDATE_CREDIT = "UPDATE customer SET credit= credit-? WHERE name=?";
|
||||
|
||||
private JdbcOperations jdbcTemplate;
|
||||
|
||||
public void write(CustomerDebit customerDebit) {
|
||||
jdbcTemplate.update(UPDATE_CREDIT,
|
||||
new Object[] { customerDebit.getDebit(), customerDebit.getName() });
|
||||
}
|
||||
|
||||
public void setJdbcTemplate(JdbcOperations jdbcTemplate) {
|
||||
this.jdbcTemplate = jdbcTemplate;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
/*
|
||||
* 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.dao;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.springframework.batch.sample.domain.Trade;
|
||||
import org.springframework.jdbc.core.JdbcOperations;
|
||||
import org.springframework.jdbc.support.incrementer.DataFieldMaxValueIncrementer;
|
||||
|
||||
|
||||
/**
|
||||
* Writes a Trade object to a database
|
||||
*
|
||||
* @author Robert Kasanicky
|
||||
*/
|
||||
public class JdbcTradeWriter implements TradeWriter {
|
||||
private Log log = LogFactory.getLog(JdbcTradeWriter.class);
|
||||
/**
|
||||
* template for inserting a row
|
||||
*/
|
||||
private static final String INSERT_TRADE_RECORD = "INSERT INTO trade (id, isin, quantity, price, customer) VALUES (?, ?, ? ,?, ?)";
|
||||
|
||||
/**
|
||||
* handles the processing of sql query
|
||||
*/
|
||||
private JdbcOperations jdbcTemplate;
|
||||
|
||||
/**
|
||||
* database is not expected to be setup for autoincrementation
|
||||
*/
|
||||
private DataFieldMaxValueIncrementer incrementer;
|
||||
|
||||
/**
|
||||
* @see TradeWriter
|
||||
*/
|
||||
public void writeTrade(Trade trade) {
|
||||
Long id = new Long(incrementer.nextLongValue());
|
||||
log.debug("Processing: " + trade);
|
||||
jdbcTemplate.update(INSERT_TRADE_RECORD,
|
||||
new Object[] {
|
||||
id, trade.getIsin(), new Long(trade.getQuantity()), trade.getPrice(),
|
||||
trade.getCustomer()
|
||||
});
|
||||
}
|
||||
|
||||
public void setJdbcTemplate(JdbcOperations jdbcTemplate) {
|
||||
this.jdbcTemplate = jdbcTemplate;
|
||||
}
|
||||
|
||||
public void setIncrementer(DataFieldMaxValueIncrementer incrementer) {
|
||||
this.incrementer = incrementer;
|
||||
}
|
||||
|
||||
public void write(Object output) {
|
||||
this.writeTrade((Trade)output);
|
||||
}
|
||||
|
||||
public void close() {
|
||||
}
|
||||
|
||||
public void open() {
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,117 @@
|
||||
/*
|
||||
* 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.dao;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.springframework.batch.io.file.support.transform.Converter;
|
||||
import org.springframework.batch.io.file.support.transform.LineAggregator;
|
||||
import org.springframework.batch.sample.domain.Address;
|
||||
import org.springframework.batch.sample.domain.BillingInfo;
|
||||
import org.springframework.batch.sample.domain.Customer;
|
||||
import org.springframework.batch.sample.domain.LineItem;
|
||||
import org.springframework.batch.sample.domain.Order;
|
||||
|
||||
|
||||
/**
|
||||
* Converts <code>Order</code> object to a String.
|
||||
* @author Dave Syer
|
||||
*/
|
||||
public class OrderConverter implements Converter {
|
||||
|
||||
/**
|
||||
* Aggregators for all types of lines in the output file
|
||||
*/
|
||||
private Map aggregators;
|
||||
|
||||
/**
|
||||
* Converts information from an Order object to a collection of Strings for output.
|
||||
*/
|
||||
public Object convert(Object data) {
|
||||
Order order = (Order) data;
|
||||
|
||||
List result = new ArrayList();
|
||||
|
||||
result.add(getAggregator("header").aggregate(OrderFormatterUtils.headerArgs(order)));
|
||||
result.add(getAggregator("customer").aggregate(OrderFormatterUtils.customerArgs(order)));
|
||||
result.add(getAggregator("address").aggregate(OrderFormatterUtils.billingAddressArgs(order)));
|
||||
result.add(getAggregator("billing").aggregate(OrderFormatterUtils.billingInfoArgs(order)));
|
||||
|
||||
List items = order.getLineItems();
|
||||
LineItem item;
|
||||
|
||||
for (int i = 0; i < items.size(); i++) {
|
||||
item = (LineItem) items.get(i);
|
||||
result.add(getAggregator("item").aggregate(OrderFormatterUtils.lineItemArgs(item)));
|
||||
}
|
||||
|
||||
result.add(getAggregator("footer").aggregate(OrderFormatterUtils.footerArgs(order)));
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public void setAggregators(Map aggregators) {
|
||||
this.aggregators = aggregators;
|
||||
}
|
||||
|
||||
private LineAggregator getAggregator(String name) {
|
||||
return (LineAggregator) aggregators.get(name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Utility class encapsulating formatting of <code>Order</code> and its nested objects.
|
||||
*/
|
||||
private static class OrderFormatterUtils {
|
||||
|
||||
private static SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd");
|
||||
|
||||
static String[] headerArgs(Order order) {
|
||||
return new String[] { "BEGIN_ORDER:", String.valueOf(order.getOrderId()), dateFormat.format(order.getOrderDate()) };
|
||||
}
|
||||
|
||||
static String[] footerArgs(Order order) {
|
||||
return new String[] { "END_ORDER:", order.getTotalPrice().toString() };
|
||||
}
|
||||
|
||||
static String[] customerArgs(Order order) {
|
||||
Customer customer = order.getCustomer();
|
||||
|
||||
return new String[] { "CUSTOMER:", String.valueOf(customer.getRegistrationId()), customer.getFirstName(),
|
||||
customer.getMiddleName(), customer.getLastName() };
|
||||
}
|
||||
|
||||
static String[] lineItemArgs(LineItem item) {
|
||||
return new String[] { "ITEM:", String.valueOf(item.getItemId()), item.getPrice().toString() };
|
||||
}
|
||||
|
||||
static String[] billingAddressArgs(Order order) {
|
||||
Address address = order.getBillingAddress();
|
||||
|
||||
return new String[] { "ADDRESS:", address.getAddrLine1(), address.getCity(), address.getZipCode() };
|
||||
}
|
||||
|
||||
static String[] billingInfoArgs(Order order) {
|
||||
BillingInfo billingInfo = order.getBilling();
|
||||
|
||||
return new String[] { "BILLING:", billingInfo.getPaymentId(), billingInfo.getPaymentDesc() };
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
/*
|
||||
* 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.dao;
|
||||
|
||||
import org.springframework.batch.item.ResourceLifecycle;
|
||||
import org.springframework.batch.sample.domain.Order;
|
||||
|
||||
/**
|
||||
* Interface for writing <code>Order</code> objects.
|
||||
*/
|
||||
public interface OrderWriter extends ResourceLifecycle {
|
||||
|
||||
public void write(Order order);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
/*
|
||||
* 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.dao;
|
||||
|
||||
import org.springframework.batch.io.OutputSource;
|
||||
import org.springframework.batch.sample.domain.Trade;
|
||||
|
||||
|
||||
/**
|
||||
* Simple interface for writing a Trade object
|
||||
* to an arbitraty output
|
||||
*
|
||||
* @author Robert Kasanicky
|
||||
*/
|
||||
public interface TradeWriter extends OutputSource{
|
||||
/**
|
||||
* Write a trade object to some kind of output,
|
||||
* different implementations can write to file, database etc.
|
||||
*/
|
||||
void writeTrade(Trade trade);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,103 @@
|
||||
/*
|
||||
* 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;
|
||||
|
||||
import org.apache.commons.lang.builder.EqualsBuilder;
|
||||
import org.apache.commons.lang.builder.HashCodeBuilder;
|
||||
import org.apache.commons.lang.builder.ToStringBuilder;
|
||||
|
||||
public class Address {
|
||||
public static final String LINE_ID_BILLING_ADDR = "BAD";
|
||||
public static final String LINE_ID_SHIPPING_ADDR = "SAD";
|
||||
private String addressee;
|
||||
private String addrLine1;
|
||||
private String addrLine2;
|
||||
private String city;
|
||||
private String zipCode;
|
||||
private String state;
|
||||
private String country;
|
||||
|
||||
public String getAddrLine1() {
|
||||
return addrLine1;
|
||||
}
|
||||
|
||||
public void setAddrLine1(String addrLine1) {
|
||||
this.addrLine1 = addrLine1;
|
||||
}
|
||||
|
||||
public String getAddrLine2() {
|
||||
return addrLine2;
|
||||
}
|
||||
|
||||
public void setAddrLine2(String addrLine2) {
|
||||
this.addrLine2 = addrLine2;
|
||||
}
|
||||
|
||||
public String getAddressee() {
|
||||
return addressee;
|
||||
}
|
||||
|
||||
public void setAddressee(String addressee) {
|
||||
this.addressee = addressee;
|
||||
}
|
||||
|
||||
public String getCity() {
|
||||
return city;
|
||||
}
|
||||
|
||||
public void setCity(String city) {
|
||||
this.city = city;
|
||||
}
|
||||
|
||||
public String getCountry() {
|
||||
return country;
|
||||
}
|
||||
|
||||
public void setCountry(String country) {
|
||||
this.country = country;
|
||||
}
|
||||
|
||||
public String getState() {
|
||||
return state;
|
||||
}
|
||||
|
||||
public void setState(String state) {
|
||||
this.state = state;
|
||||
}
|
||||
|
||||
public String getZipCode() {
|
||||
return zipCode;
|
||||
}
|
||||
|
||||
public void setZipCode(String zipCode) {
|
||||
this.zipCode = zipCode;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return ToStringBuilder.reflectionToString(this);
|
||||
}
|
||||
|
||||
public boolean equals(Object o) {
|
||||
return EqualsBuilder.reflectionEquals(this, o);
|
||||
}
|
||||
|
||||
public int hashCode() {
|
||||
return HashCodeBuilder.reflectionHashCode(this);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
/*
|
||||
* 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;
|
||||
|
||||
import org.apache.commons.lang.builder.EqualsBuilder;
|
||||
import org.apache.commons.lang.builder.HashCodeBuilder;
|
||||
import org.apache.commons.lang.builder.ToStringBuilder;
|
||||
|
||||
public class BillingInfo {
|
||||
public static final String LINE_ID_BILLING_INFO = "BIN";
|
||||
private String paymentId;
|
||||
private String paymentDesc;
|
||||
|
||||
public String getPaymentDesc() {
|
||||
return paymentDesc;
|
||||
}
|
||||
|
||||
public void setPaymentDesc(String paymentDesc) {
|
||||
this.paymentDesc = paymentDesc;
|
||||
}
|
||||
|
||||
public String getPaymentId() {
|
||||
return paymentId;
|
||||
}
|
||||
|
||||
public void setPaymentId(String paymentId) {
|
||||
this.paymentId = paymentId;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return ToStringBuilder.reflectionToString(this);
|
||||
}
|
||||
|
||||
public boolean equals(Object o) {
|
||||
return EqualsBuilder.reflectionEquals(this, o);
|
||||
}
|
||||
|
||||
public int hashCode() {
|
||||
return HashCodeBuilder.reflectionHashCode(this);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
/*
|
||||
* 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;
|
||||
|
||||
import org.apache.commons.lang.builder.EqualsBuilder;
|
||||
import org.apache.commons.lang.builder.HashCodeBuilder;
|
||||
import org.apache.commons.lang.builder.ToStringBuilder;
|
||||
|
||||
public class Child {
|
||||
|
||||
private String name;
|
||||
|
||||
public void setName(String name){
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getName(){
|
||||
return name;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return ToStringBuilder.reflectionToString(this);
|
||||
}
|
||||
|
||||
public boolean equals(Object o) {
|
||||
return EqualsBuilder.reflectionEquals(this, o);
|
||||
}
|
||||
|
||||
public int hashCode() {
|
||||
return HashCodeBuilder.reflectionHashCode(this);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,115 @@
|
||||
/*
|
||||
* 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;
|
||||
|
||||
import org.apache.commons.lang.builder.EqualsBuilder;
|
||||
import org.apache.commons.lang.builder.HashCodeBuilder;
|
||||
import org.apache.commons.lang.builder.ToStringBuilder;
|
||||
|
||||
public class Customer {
|
||||
public static final String LINE_ID_BUSINESS_CUST = "BCU";
|
||||
public static final String LINE_ID_NON_BUSINESS_CUST = "NCU";
|
||||
private boolean businessCustomer;
|
||||
private boolean registered;
|
||||
private long registrationId;
|
||||
|
||||
//non-business customer
|
||||
private String firstName;
|
||||
private String lastName;
|
||||
private String middleName;
|
||||
private boolean vip;
|
||||
|
||||
//business customer
|
||||
private String companyName;
|
||||
|
||||
public boolean isBusinessCustomer() {
|
||||
return businessCustomer;
|
||||
}
|
||||
|
||||
public void setBusinessCustomer(boolean bussinessCustomer) {
|
||||
this.businessCustomer = bussinessCustomer;
|
||||
}
|
||||
|
||||
public String getCompanyName() {
|
||||
return companyName;
|
||||
}
|
||||
|
||||
public void setCompanyName(String companyName) {
|
||||
this.companyName = companyName;
|
||||
}
|
||||
|
||||
public String getFirstName() {
|
||||
return firstName;
|
||||
}
|
||||
|
||||
public void setFirstName(String firstName) {
|
||||
this.firstName = firstName;
|
||||
}
|
||||
|
||||
public boolean isRegistered() {
|
||||
return registered;
|
||||
}
|
||||
|
||||
public void setRegistered(boolean registered) {
|
||||
this.registered = registered;
|
||||
}
|
||||
|
||||
public String getLastName() {
|
||||
return lastName;
|
||||
}
|
||||
|
||||
public void setLastName(String lastName) {
|
||||
this.lastName = lastName;
|
||||
}
|
||||
|
||||
public String getMiddleName() {
|
||||
return middleName;
|
||||
}
|
||||
|
||||
public void setMiddleName(String middleName) {
|
||||
this.middleName = middleName;
|
||||
}
|
||||
|
||||
public long getRegistrationId() {
|
||||
return registrationId;
|
||||
}
|
||||
|
||||
public void setRegistrationId(long registrationId) {
|
||||
this.registrationId = registrationId;
|
||||
}
|
||||
|
||||
public boolean isVip() {
|
||||
return vip;
|
||||
}
|
||||
|
||||
public void setVip(boolean vip) {
|
||||
this.vip = vip;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return ToStringBuilder.reflectionToString(this);
|
||||
}
|
||||
|
||||
public boolean equals(Object o) {
|
||||
return EqualsBuilder.reflectionEquals(this, o);
|
||||
}
|
||||
|
||||
public int hashCode() {
|
||||
return HashCodeBuilder.reflectionHashCode(this);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
/*
|
||||
* 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;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
import org.apache.commons.lang.builder.EqualsBuilder;
|
||||
import org.apache.commons.lang.builder.HashCodeBuilder;
|
||||
|
||||
|
||||
public class CustomerCredit {
|
||||
private String name;
|
||||
private BigDecimal credit;
|
||||
|
||||
public String toString() {
|
||||
return "CustomerCredit [name=" + name + ", credit=" + credit + "]";
|
||||
}
|
||||
|
||||
public BigDecimal getCredit() {
|
||||
return credit;
|
||||
}
|
||||
|
||||
public void setCredit(BigDecimal credit) {
|
||||
this.credit = credit;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public boolean equals(Object o) {
|
||||
return EqualsBuilder.reflectionEquals(this, o);
|
||||
}
|
||||
|
||||
public int hashCode() {
|
||||
return HashCodeBuilder.reflectionHashCode(this);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
/*
|
||||
* 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;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
import org.apache.commons.lang.builder.EqualsBuilder;
|
||||
import org.apache.commons.lang.builder.HashCodeBuilder;
|
||||
|
||||
|
||||
public class CustomerDebit {
|
||||
private String name;
|
||||
private BigDecimal debit;
|
||||
|
||||
public CustomerDebit() {
|
||||
}
|
||||
|
||||
CustomerDebit(String name, BigDecimal debit) {
|
||||
this.name = name;
|
||||
this.debit = debit;
|
||||
}
|
||||
|
||||
public BigDecimal getDebit() {
|
||||
return debit;
|
||||
}
|
||||
|
||||
public void setDebit(BigDecimal debit) {
|
||||
this.debit = debit;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return "CustomerDebit [name=" + name + ", debit=" + debit + "]";
|
||||
}
|
||||
|
||||
public boolean equals(Object o) {
|
||||
return EqualsBuilder.reflectionEquals(this, o);
|
||||
}
|
||||
|
||||
public int hashCode() {
|
||||
return HashCodeBuilder.reflectionHashCode(this);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,113 @@
|
||||
/*
|
||||
* 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;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
import org.apache.commons.lang.builder.EqualsBuilder;
|
||||
import org.apache.commons.lang.builder.HashCodeBuilder;
|
||||
import org.apache.commons.lang.builder.ToStringBuilder;
|
||||
|
||||
|
||||
public class LineItem {
|
||||
public static final String LINE_ID_ITEM = "LIT";
|
||||
private long itemId;
|
||||
private BigDecimal price;
|
||||
private BigDecimal discountPerc;
|
||||
private BigDecimal discountAmount;
|
||||
private BigDecimal shippingPrice;
|
||||
private BigDecimal handlingPrice;
|
||||
private int quantity;
|
||||
private BigDecimal totalPrice;
|
||||
|
||||
public BigDecimal getDiscountAmount() {
|
||||
return discountAmount;
|
||||
}
|
||||
|
||||
public void setDiscountAmount(BigDecimal discountAmount) {
|
||||
this.discountAmount = discountAmount;
|
||||
}
|
||||
|
||||
public BigDecimal getDiscountPerc() {
|
||||
return discountPerc;
|
||||
}
|
||||
|
||||
public void setDiscountPerc(BigDecimal discountPerc) {
|
||||
this.discountPerc = discountPerc;
|
||||
}
|
||||
|
||||
public BigDecimal getHandlingPrice() {
|
||||
return handlingPrice;
|
||||
}
|
||||
|
||||
public void setHandlingPrice(BigDecimal handlingPrice) {
|
||||
this.handlingPrice = handlingPrice;
|
||||
}
|
||||
|
||||
public long getItemId() {
|
||||
return itemId;
|
||||
}
|
||||
|
||||
public void setItemId(long itemId) {
|
||||
this.itemId = itemId;
|
||||
}
|
||||
|
||||
public BigDecimal getPrice() {
|
||||
return price;
|
||||
}
|
||||
|
||||
public void setPrice(BigDecimal price) {
|
||||
this.price = price;
|
||||
}
|
||||
|
||||
public int getQuantity() {
|
||||
return quantity;
|
||||
}
|
||||
|
||||
public void setQuantity(int quantity) {
|
||||
this.quantity = quantity;
|
||||
}
|
||||
|
||||
public BigDecimal getShippingPrice() {
|
||||
return shippingPrice;
|
||||
}
|
||||
|
||||
public void setShippingPrice(BigDecimal shippingPrice) {
|
||||
this.shippingPrice = shippingPrice;
|
||||
}
|
||||
|
||||
public BigDecimal getTotalPrice() {
|
||||
return totalPrice;
|
||||
}
|
||||
|
||||
public void setTotalPrice(BigDecimal totalPrice) {
|
||||
this.totalPrice = totalPrice;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return ToStringBuilder.reflectionToString(this);
|
||||
}
|
||||
|
||||
public boolean equals(Object o) {
|
||||
return EqualsBuilder.reflectionEquals(this, o);
|
||||
}
|
||||
|
||||
public int hashCode() {
|
||||
return HashCodeBuilder.reflectionHashCode(this);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,148 @@
|
||||
/*
|
||||
* 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;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.commons.lang.builder.EqualsBuilder;
|
||||
import org.apache.commons.lang.builder.HashCodeBuilder;
|
||||
import org.apache.commons.lang.builder.ToStringBuilder;
|
||||
|
||||
|
||||
public class Order {
|
||||
public static final String LINE_ID_HEADER = "HEA";
|
||||
public static final String LINE_ID_FOOTER = "FOT";
|
||||
|
||||
//header
|
||||
private long orderId;
|
||||
private Date orderDate;
|
||||
|
||||
//footer
|
||||
private int totalLines;
|
||||
private int totalItems;
|
||||
private BigDecimal totalPrice;
|
||||
private Customer customer;
|
||||
private Address billingAddress;
|
||||
private Address shippingAddress;
|
||||
private BillingInfo billing;
|
||||
private ShippingInfo shipping;
|
||||
|
||||
//order items
|
||||
private List lineItems;
|
||||
|
||||
public BillingInfo getBilling() {
|
||||
return billing;
|
||||
}
|
||||
|
||||
public void setBilling(BillingInfo billing) {
|
||||
this.billing = billing;
|
||||
}
|
||||
|
||||
public Address getBillingAddress() {
|
||||
return billingAddress;
|
||||
}
|
||||
|
||||
public void setBillingAddress(Address billingAddress) {
|
||||
this.billingAddress = billingAddress;
|
||||
}
|
||||
|
||||
public Customer getCustomer() {
|
||||
return customer;
|
||||
}
|
||||
|
||||
public void setCustomer(Customer customer) {
|
||||
this.customer = customer;
|
||||
}
|
||||
|
||||
public List getLineItems() {
|
||||
return lineItems;
|
||||
}
|
||||
|
||||
public void setLineItems(List lineItems) {
|
||||
this.lineItems = lineItems;
|
||||
}
|
||||
|
||||
public Date getOrderDate() {
|
||||
return orderDate;
|
||||
}
|
||||
|
||||
public void setOrderDate(Date orderDate) {
|
||||
this.orderDate = orderDate;
|
||||
}
|
||||
|
||||
public long getOrderId() {
|
||||
return orderId;
|
||||
}
|
||||
|
||||
public void setOrderId(long orderId) {
|
||||
this.orderId = orderId;
|
||||
}
|
||||
|
||||
public ShippingInfo getShipping() {
|
||||
return shipping;
|
||||
}
|
||||
|
||||
public void setShipping(ShippingInfo shipping) {
|
||||
this.shipping = shipping;
|
||||
}
|
||||
|
||||
public Address getShippingAddress() {
|
||||
return shippingAddress;
|
||||
}
|
||||
|
||||
public void setShippingAddress(Address shippingAddress) {
|
||||
this.shippingAddress = shippingAddress;
|
||||
}
|
||||
|
||||
public BigDecimal getTotalPrice() {
|
||||
return totalPrice;
|
||||
}
|
||||
|
||||
public void setTotalPrice(BigDecimal totalPrice) {
|
||||
this.totalPrice = totalPrice;
|
||||
}
|
||||
|
||||
public int getTotalItems() {
|
||||
return totalItems;
|
||||
}
|
||||
|
||||
public void setTotalItems(int totalItems) {
|
||||
this.totalItems = totalItems;
|
||||
}
|
||||
|
||||
public int getTotalLines() {
|
||||
return totalLines;
|
||||
}
|
||||
|
||||
public void setTotalLines(int totalLines) {
|
||||
this.totalLines = totalLines;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return ToStringBuilder.reflectionToString(this);
|
||||
}
|
||||
|
||||
public boolean equals(Object o) {
|
||||
return EqualsBuilder.reflectionEquals(this, o);
|
||||
}
|
||||
|
||||
public int hashCode() {
|
||||
return HashCodeBuilder.reflectionHashCode(this);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,126 @@
|
||||
/*
|
||||
* 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;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.commons.lang.builder.EqualsBuilder;
|
||||
import org.apache.commons.lang.builder.HashCodeBuilder;
|
||||
import org.apache.commons.lang.builder.ToStringBuilder;
|
||||
|
||||
public class Person {
|
||||
|
||||
private String title = "";
|
||||
private String firstName = "";
|
||||
private String last_name = "";
|
||||
private int age = 0;
|
||||
private Address address = new Address();
|
||||
private List children = new ArrayList();
|
||||
|
||||
public Person(){
|
||||
children.add(new Child());
|
||||
children.add(new Child());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the address
|
||||
*/
|
||||
public Address getAddress() {
|
||||
return address;
|
||||
}
|
||||
/**
|
||||
* @param address the address to set
|
||||
*/
|
||||
public void setAddress(Address address) {
|
||||
this.address = address;
|
||||
}
|
||||
/**
|
||||
* @return the age
|
||||
*/
|
||||
public int getAge() {
|
||||
return age;
|
||||
}
|
||||
/**
|
||||
* @param age the age to set
|
||||
*/
|
||||
public void setAge(int age) {
|
||||
this.age = age;
|
||||
}
|
||||
/**
|
||||
* @return the firstName
|
||||
*/
|
||||
public String getFirstName() {
|
||||
return firstName;
|
||||
}
|
||||
/**
|
||||
* @param firstName the firstName to set
|
||||
*/
|
||||
public void setFirstName(String firstName) {
|
||||
this.firstName = firstName;
|
||||
}
|
||||
/**
|
||||
* @return the children
|
||||
*/
|
||||
public List getChildren() {
|
||||
return children;
|
||||
}
|
||||
/**
|
||||
* @param children the children to set
|
||||
*/
|
||||
public void setChildren(List children) {
|
||||
this.children = children;
|
||||
}
|
||||
/**
|
||||
* Intentionally non-standard method name for testing purposes
|
||||
* @return the last_name
|
||||
*/
|
||||
public String getLast_name() {
|
||||
return last_name;
|
||||
}
|
||||
/**
|
||||
* Intentionally non-standard method name for testing purposes
|
||||
* @param last_name the last_name to set
|
||||
*/
|
||||
public void setLast_name(String last_name) {
|
||||
this.last_name = last_name;
|
||||
}
|
||||
/**
|
||||
* @return the person_title
|
||||
*/
|
||||
public String getTitle() {
|
||||
return title;
|
||||
}
|
||||
/**
|
||||
* @param person_title the person_title to set
|
||||
*/
|
||||
public void setTitle(String title) {
|
||||
this.title = title;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return ToStringBuilder.reflectionToString(this);
|
||||
}
|
||||
|
||||
public boolean equals(Object o) {
|
||||
return EqualsBuilder.reflectionEquals(this, o);
|
||||
}
|
||||
|
||||
public int hashCode() {
|
||||
return HashCodeBuilder.reflectionHashCode(this);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
/*
|
||||
* 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;
|
||||
|
||||
import org.apache.commons.lang.builder.EqualsBuilder;
|
||||
import org.apache.commons.lang.builder.HashCodeBuilder;
|
||||
|
||||
public class ShippingInfo {
|
||||
public static final String LINE_ID_SHIPPING_INFO = "SIN";
|
||||
private String shipperId;
|
||||
private String shippingTypeId;
|
||||
private String shippingInfo;
|
||||
|
||||
public String getShipperId() {
|
||||
return shipperId;
|
||||
}
|
||||
|
||||
public void setShipperId(String shipperId) {
|
||||
this.shipperId = shipperId;
|
||||
}
|
||||
|
||||
public String getShippingInfo() {
|
||||
return shippingInfo;
|
||||
}
|
||||
|
||||
public void setShippingInfo(String shippingInfo) {
|
||||
this.shippingInfo = shippingInfo;
|
||||
}
|
||||
|
||||
public String getShippingTypeId() {
|
||||
return shippingTypeId;
|
||||
}
|
||||
|
||||
public void setShippingTypeId(String shippingTypeId) {
|
||||
this.shippingTypeId = shippingTypeId;
|
||||
}
|
||||
|
||||
public boolean equals(Object o) {
|
||||
return EqualsBuilder.reflectionEquals(this, o);
|
||||
}
|
||||
|
||||
public int hashCode() {
|
||||
return HashCodeBuilder.reflectionHashCode(this);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,88 @@
|
||||
/*
|
||||
* 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;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
import org.apache.commons.lang.builder.EqualsBuilder;
|
||||
import org.apache.commons.lang.builder.HashCodeBuilder;
|
||||
|
||||
|
||||
/**
|
||||
* @author Rob Harrop
|
||||
*/
|
||||
public class Trade {
|
||||
private String isin = "";
|
||||
private long quantity = 0;
|
||||
private BigDecimal price = new BigDecimal(0);
|
||||
private String customer = "";
|
||||
|
||||
public Trade() {
|
||||
}
|
||||
|
||||
public Trade(String isin, long quantity, BigDecimal price, String customer){
|
||||
this.isin = isin;
|
||||
this.quantity = quantity;
|
||||
this.price = price;
|
||||
this.customer = customer;
|
||||
}
|
||||
|
||||
public void setCustomer(String customer) {
|
||||
this.customer = customer;
|
||||
}
|
||||
|
||||
public void setIsin(String isin) {
|
||||
this.isin = isin;
|
||||
}
|
||||
|
||||
public void setPrice(BigDecimal price) {
|
||||
this.price = price;
|
||||
}
|
||||
|
||||
public void setQuantity(long quantity) {
|
||||
this.quantity = quantity;
|
||||
}
|
||||
|
||||
public String getIsin() {
|
||||
return isin;
|
||||
}
|
||||
|
||||
public BigDecimal getPrice() {
|
||||
return price;
|
||||
}
|
||||
|
||||
public long getQuantity() {
|
||||
return quantity;
|
||||
}
|
||||
|
||||
public String getCustomer() {
|
||||
return customer;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return "Trade: [isin=" + this.isin + ",quantity=" + this.quantity + ",price="
|
||||
+ this.price + ",customer=" + this.customer + "]";
|
||||
}
|
||||
|
||||
public boolean equals(Object o) {
|
||||
return EqualsBuilder.reflectionEquals(this, o);
|
||||
}
|
||||
|
||||
public int hashCode() {
|
||||
return HashCodeBuilder.reflectionHashCode(this);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
/*
|
||||
* 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.xml;
|
||||
|
||||
import org.apache.commons.lang.builder.ToStringBuilder;
|
||||
|
||||
|
||||
/**
|
||||
* An XML customer.
|
||||
*
|
||||
* This is a complex type.
|
||||
*/
|
||||
public class Customer {
|
||||
private String name;
|
||||
private String address;
|
||||
private int age;
|
||||
private int moo;
|
||||
private int poo;
|
||||
|
||||
public String getAddress() {
|
||||
return address;
|
||||
}
|
||||
|
||||
public void setAddress(String address) {
|
||||
this.address = address;
|
||||
}
|
||||
|
||||
public int getAge() {
|
||||
return age;
|
||||
}
|
||||
|
||||
public void setAge(int age) {
|
||||
this.age = age;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public int getMoo() {
|
||||
return moo;
|
||||
}
|
||||
|
||||
public void setMoo(int moo) {
|
||||
this.moo = moo;
|
||||
}
|
||||
|
||||
public int getPoo() {
|
||||
return poo;
|
||||
}
|
||||
|
||||
public void setPoo(int poo) {
|
||||
this.poo = poo;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return ToStringBuilder.reflectionToString(this);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
/*
|
||||
* 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.xml;
|
||||
|
||||
|
||||
/**
|
||||
* An XML line-item.
|
||||
*
|
||||
* This is a complex type.
|
||||
*/
|
||||
public class LineItem {
|
||||
private String description;
|
||||
private double perUnitOunces;
|
||||
private double price;
|
||||
private int quantity;
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
public void setDescription(String description) {
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
public double getPerUnitOunces() {
|
||||
return perUnitOunces;
|
||||
}
|
||||
|
||||
public void setPerUnitOunces(double perUnitOunces) {
|
||||
this.perUnitOunces = perUnitOunces;
|
||||
}
|
||||
|
||||
public double getPrice() {
|
||||
return price;
|
||||
}
|
||||
|
||||
public void setPrice(double price) {
|
||||
this.price = price;
|
||||
}
|
||||
|
||||
public int getQuantity() {
|
||||
return quantity;
|
||||
}
|
||||
|
||||
public void setQuantity(int quantity) {
|
||||
this.quantity = quantity;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
/*
|
||||
* 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.xml;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.commons.lang.builder.ToStringBuilder;
|
||||
|
||||
|
||||
/**
|
||||
* An XML order.
|
||||
*
|
||||
* This is a complex type.
|
||||
*/
|
||||
public class Order {
|
||||
private Customer customer;
|
||||
private Date date;
|
||||
private List lineItems;
|
||||
private Shipper shipper;
|
||||
|
||||
public Customer getCustomer() {
|
||||
return customer;
|
||||
}
|
||||
|
||||
public void setCustomer(Customer customer) {
|
||||
this.customer = customer;
|
||||
}
|
||||
|
||||
public Date getDate() {
|
||||
return date;
|
||||
}
|
||||
|
||||
public void setDate(Date date) {
|
||||
this.date = date;
|
||||
}
|
||||
|
||||
public List getLineItems() {
|
||||
return lineItems;
|
||||
}
|
||||
|
||||
public void setLineItems(List lineItems) {
|
||||
this.lineItems = lineItems;
|
||||
}
|
||||
|
||||
public Shipper getShipper() {
|
||||
return shipper;
|
||||
}
|
||||
|
||||
public void setShipper(Shipper shipper) {
|
||||
this.shipper = shipper;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return ToStringBuilder.reflectionToString(this);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
* 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.xml;
|
||||
|
||||
|
||||
/**
|
||||
* An XML shipper.
|
||||
*
|
||||
* This is a complex type.
|
||||
*/
|
||||
public class Shipper {
|
||||
private String name;
|
||||
private double perOunceRate;
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public double getPerOunceRate() {
|
||||
return perOunceRate;
|
||||
}
|
||||
|
||||
public void setPerOunceRate(double perOunceRate) {
|
||||
this.perOunceRate = perOunceRate;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
* 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.launch;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
|
||||
|
||||
public class QuartzBatchLauncher {
|
||||
private static Log log = LogFactory.getLog(QuartzBatchLauncher.class);
|
||||
|
||||
public static void main(String[] args) throws IOException {
|
||||
if (args[0] == null) {
|
||||
log.error("Missing argument: provide a path to configuration file");
|
||||
System.exit(-1);
|
||||
}
|
||||
|
||||
new ClassPathXmlApplicationContext(args[0] + ".xml");
|
||||
|
||||
log.info("Quartz context initialized");
|
||||
}
|
||||
}
|
||||
@@ -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.mapping;
|
||||
|
||||
import org.springframework.batch.io.file.FieldSet;
|
||||
import org.springframework.batch.io.file.FieldSetMapper;
|
||||
import org.springframework.batch.sample.domain.Address;
|
||||
|
||||
|
||||
|
||||
public class AddressFieldSetMapper implements FieldSetMapper {
|
||||
|
||||
public static final String ADDRESSEE_COLUMN = "ADDRESSEE";
|
||||
public static final String ADDRESS_LINE1_COLUMN = "ADDR_LINE1";
|
||||
public static final String ADDRESS_LINE2_COLUMN = "ADDR_LINE2";
|
||||
public static final String CITY_COLUMN = "CITY";
|
||||
public static final String ZIP_CODE_COLUMN = "ZIP_CODE";
|
||||
public static final String STATE_COLUMN = "STATE";
|
||||
public static final String COUNTRY_COLUMN = "COUNTRY";
|
||||
|
||||
|
||||
public Object mapLine(FieldSet fieldSet) {
|
||||
Address address = new Address();
|
||||
|
||||
address.setAddressee(fieldSet.readString(ADDRESSEE_COLUMN));
|
||||
address.setAddrLine1(fieldSet.readString(ADDRESS_LINE1_COLUMN));
|
||||
address.setAddrLine2(fieldSet.readString(ADDRESS_LINE2_COLUMN));
|
||||
address.setCity(fieldSet.readString(CITY_COLUMN));
|
||||
address.setZipCode(fieldSet.readString(ZIP_CODE_COLUMN));
|
||||
address.setState(fieldSet.readString(STATE_COLUMN));
|
||||
address.setCountry(fieldSet.readString(COUNTRY_COLUMN));
|
||||
|
||||
return address;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
* 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.mapping;
|
||||
|
||||
import org.springframework.batch.io.file.FieldSet;
|
||||
import org.springframework.batch.io.file.FieldSetMapper;
|
||||
import org.springframework.batch.sample.domain.BillingInfo;
|
||||
|
||||
|
||||
|
||||
public class BillingFieldSetMapper implements FieldSetMapper {
|
||||
|
||||
public static final String PAYMENT_TYPE_ID_COLUMN = "PAYMENT_TYPE_ID";
|
||||
public static final String PAYMENT_DESC_COLUMN = "PAYMENT_DESC";
|
||||
|
||||
public Object mapLine(FieldSet fieldSet) {
|
||||
BillingInfo info = new BillingInfo();
|
||||
|
||||
info.setPaymentId(fieldSet.readString(PAYMENT_TYPE_ID_COLUMN));
|
||||
info.setPaymentDesc(fieldSet.readString(PAYMENT_DESC_COLUMN));
|
||||
|
||||
return info;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package org.springframework.batch.sample.mapping;
|
||||
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
|
||||
import org.springframework.batch.sample.domain.CustomerCredit;
|
||||
import org.springframework.jdbc.core.RowMapper;
|
||||
|
||||
public class CustomerCreditRowMapper implements RowMapper {
|
||||
|
||||
public static final String NAME_COLUMN = "name";
|
||||
public static final String CREDIT_COLUMN = "credit";
|
||||
|
||||
public Object mapRow(ResultSet rs, int rowNum) throws SQLException {
|
||||
CustomerCredit customerCredit = new CustomerCredit();
|
||||
|
||||
customerCredit.setName(rs.getString(NAME_COLUMN));
|
||||
customerCredit.setCredit(rs.getBigDecimal(CREDIT_COLUMN));
|
||||
|
||||
return customerCredit;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
/*
|
||||
* 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.mapping;
|
||||
|
||||
import org.springframework.batch.io.file.FieldSet;
|
||||
import org.springframework.batch.io.file.FieldSetMapper;
|
||||
import org.springframework.batch.sample.domain.Customer;
|
||||
|
||||
|
||||
|
||||
public class CustomerFieldSetMapper implements FieldSetMapper {
|
||||
|
||||
public static final String LINE_ID_COLUMN = "LINE_ID";
|
||||
public static final String COMPANY_NAME_COLUMN = "COMPANY_NAME";
|
||||
public static final String LAST_NAME_COLUMN = "LAST_NAME";
|
||||
public static final String FIRST_NAME_COLUMN = "FIRST_NAME";
|
||||
public static final String MIDDLE_NAME_COLUMN = "MIDDLE_NAME";
|
||||
public static final String TRUE_SYMBOL = "T";
|
||||
public static final String REGISTERED_COLUMN = "REGISTERED";
|
||||
public static final String REG_ID_COLUMN = "REG_ID";
|
||||
public static final String VIP_COLUMN = "VIP";
|
||||
|
||||
public Object mapLine(FieldSet fieldSet) {
|
||||
Customer customer = new Customer();
|
||||
|
||||
if (Customer.LINE_ID_BUSINESS_CUST.equals(fieldSet.readString(LINE_ID_COLUMN))) {
|
||||
customer.setCompanyName(fieldSet.readString(COMPANY_NAME_COLUMN));
|
||||
//business customer must be always registered
|
||||
customer.setRegistered(true);
|
||||
}
|
||||
|
||||
if (Customer.LINE_ID_NON_BUSINESS_CUST.equals(fieldSet.readString(LINE_ID_COLUMN))) {
|
||||
customer.setLastName(fieldSet.readString(LAST_NAME_COLUMN));
|
||||
customer.setFirstName(fieldSet.readString(FIRST_NAME_COLUMN));
|
||||
customer.setMiddleName(fieldSet.readString(MIDDLE_NAME_COLUMN));
|
||||
customer.setRegistered(TRUE_SYMBOL.equals(fieldSet.readString(REGISTERED_COLUMN)));
|
||||
}
|
||||
|
||||
customer.setRegistrationId(fieldSet.readLong(REG_ID_COLUMN));
|
||||
customer.setVip(TRUE_SYMBOL.equals(fieldSet.readString(VIP_COLUMN)));
|
||||
|
||||
return customer;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
/*
|
||||
* 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.mapping;
|
||||
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
|
||||
import org.springframework.batch.sample.domain.CustomerDebit;
|
||||
import org.springframework.jdbc.core.RowMapper;
|
||||
|
||||
|
||||
public class CustomerUpdateMapper implements RowMapper {
|
||||
|
||||
public static final String CUSTOMER_COLUMN = "customer";
|
||||
public static final String PRICE_COLUMN = "price";
|
||||
|
||||
public Object 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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
* 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.mapping;
|
||||
|
||||
import org.springframework.batch.io.file.FieldSet;
|
||||
import org.springframework.batch.io.file.FieldSetMapper;
|
||||
import org.springframework.batch.sample.domain.Order;
|
||||
|
||||
|
||||
|
||||
public class HeaderFieldSetMapper implements FieldSetMapper {
|
||||
|
||||
public static final String ORDER_ID_COLUMN = "ORDER_ID";
|
||||
public static final String ORDER_DATE_COLUMN = "ORDER_DATE";
|
||||
|
||||
public Object mapLine(FieldSet fieldSet) {
|
||||
Order order = new Order();
|
||||
order.setOrderId(fieldSet.readLong(ORDER_ID_COLUMN));
|
||||
order.setOrderDate(fieldSet.readDate(ORDER_DATE_COLUMN));
|
||||
|
||||
return order;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
/*
|
||||
* 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.mapping;
|
||||
|
||||
import org.springframework.batch.io.file.FieldSet;
|
||||
import org.springframework.batch.io.file.FieldSetMapper;
|
||||
import org.springframework.batch.sample.domain.LineItem;
|
||||
|
||||
|
||||
public class OrderItemFieldSetMapper implements FieldSetMapper {
|
||||
|
||||
public static final String TOTAL_PRICE_COLUMN = "TOTAL_PRICE";
|
||||
public static final String QUANTITY_COLUMN = "QUANTITY";
|
||||
public static final String HANDLING_PRICE_COLUMN = "HANDLING_PRICE";
|
||||
public static final String SHIPPING_PRICE_COLUMN = "SHIPPING_PRICE";
|
||||
public static final String DISCOUNT_AMOUNT_COLUMN = "DISCOUNT_AMOUNT";
|
||||
public static final String DISCOUNT_PERC_COLUMN = "DISCOUNT_PERC";
|
||||
public static final String PRICE_COLUMN = "PRICE";
|
||||
public static final String ITEM_ID_COLUMN = "ITEM_ID";
|
||||
|
||||
|
||||
public Object mapLine(FieldSet fieldSet) {
|
||||
LineItem item = new LineItem();
|
||||
|
||||
item.setItemId(fieldSet.readLong(ITEM_ID_COLUMN));
|
||||
item.setPrice(fieldSet.readBigDecimal(PRICE_COLUMN));
|
||||
item.setDiscountPerc(fieldSet.readBigDecimal(DISCOUNT_PERC_COLUMN));
|
||||
item.setDiscountAmount(fieldSet.readBigDecimal(DISCOUNT_AMOUNT_COLUMN));
|
||||
item.setShippingPrice(fieldSet.readBigDecimal(SHIPPING_PRICE_COLUMN));
|
||||
item.setHandlingPrice(fieldSet.readBigDecimal(HANDLING_PRICE_COLUMN));
|
||||
item.setQuantity(fieldSet.readInt(QUANTITY_COLUMN));
|
||||
item.setTotalPrice(fieldSet.readBigDecimal(TOTAL_PRICE_COLUMN));
|
||||
|
||||
return item;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
/*
|
||||
* 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.mapping;
|
||||
|
||||
import org.springframework.batch.io.file.FieldSet;
|
||||
import org.springframework.batch.io.file.FieldSetMapper;
|
||||
import org.springframework.batch.sample.domain.ShippingInfo;
|
||||
|
||||
|
||||
|
||||
public class ShippingFieldSetMapper implements FieldSetMapper {
|
||||
|
||||
public static final String ADDITIONAL_SHIPPING_INFO_COLUMN = "ADDITIONAL_SHIPPING_INFO";
|
||||
public static final String SHIPPING_TYPE_ID_COLUMN = "SHIPPING_TYPE_ID";
|
||||
public static final String SHIPPER_ID_COLUMN = "SHIPPER_ID";
|
||||
|
||||
public Object mapLine(FieldSet fieldSet) {
|
||||
ShippingInfo info = new ShippingInfo();
|
||||
|
||||
info.setShipperId(fieldSet.readString(SHIPPER_ID_COLUMN));
|
||||
info.setShippingTypeId(fieldSet.readString(SHIPPING_TYPE_ID_COLUMN));
|
||||
info.setShippingInfo(fieldSet.readString(ADDITIONAL_SHIPPING_INFO_COLUMN));
|
||||
|
||||
return info;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
* 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.mapping;
|
||||
|
||||
import org.springframework.batch.io.file.FieldSet;
|
||||
import org.springframework.batch.io.file.FieldSetMapper;
|
||||
import org.springframework.batch.sample.domain.Trade;
|
||||
|
||||
|
||||
|
||||
public class TradeFieldSetMapper implements FieldSetMapper {
|
||||
|
||||
public static final int ISIN_COLUMN = 0;
|
||||
public static final int QUANTITY_COLUMN = 1;
|
||||
public static final int PRICE_COLUMN = 2;
|
||||
public static final int CUSTOMER_COLUMN = 3;
|
||||
|
||||
public Object mapLine(FieldSet fieldSet) {
|
||||
|
||||
Trade trade = new Trade();
|
||||
trade.setIsin(fieldSet.readString(0));
|
||||
trade.setQuantity(fieldSet.readLong(1));
|
||||
trade.setPrice(fieldSet.readBigDecimal(2));
|
||||
trade.setCustomer(fieldSet.readString(3));
|
||||
|
||||
return trade;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
* 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.mapping;
|
||||
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
|
||||
import org.springframework.batch.sample.domain.Trade;
|
||||
import org.springframework.jdbc.core.RowMapper;
|
||||
|
||||
public class TradeRowMapper implements RowMapper {
|
||||
|
||||
public static final int ISIN_COLUMN = 1;
|
||||
public static final int QUANTITY_COLUMN = 2;
|
||||
public static final int PRICE_COLUMN = 3;
|
||||
public static final int CUSTOMER_COLUMN = 4;
|
||||
|
||||
public Object mapRow(ResultSet rs, int rowNum) throws SQLException {
|
||||
Trade trade = new Trade();
|
||||
|
||||
trade.setIsin(rs.getString(ISIN_COLUMN));
|
||||
trade.setQuantity(rs.getLong(QUANTITY_COLUMN));
|
||||
trade.setPrice(rs.getBigDecimal(PRICE_COLUMN));
|
||||
trade.setCustomer(rs.getString(CUSTOMER_COLUMN));
|
||||
|
||||
return trade;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,101 @@
|
||||
/*
|
||||
* 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.module;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.springframework.batch.io.file.FieldSet;
|
||||
import org.springframework.batch.io.file.FieldSetInputSource;
|
||||
import org.springframework.batch.io.file.FieldSetMapper;
|
||||
import org.springframework.batch.item.provider.AbstractItemProvider;
|
||||
|
||||
|
||||
public class CollectionItemProvider extends AbstractItemProvider {
|
||||
|
||||
private static final Log log = LogFactory.getLog(CollectionItemProvider.class);
|
||||
|
||||
private FieldSetInputSource inputSource;
|
||||
|
||||
//collects simple records
|
||||
private Collection multiRecord;
|
||||
|
||||
//marks we have finished reading one whole multiRecord
|
||||
private boolean recordFinished;
|
||||
|
||||
//mapps a sigle line to a simple record
|
||||
private FieldSetMapper fieldSetMapper;
|
||||
|
||||
public Object next() {
|
||||
recordFinished = false;
|
||||
|
||||
while (!recordFinished) {
|
||||
process(inputSource.readFieldSet());
|
||||
}
|
||||
|
||||
if (multiRecord != null) {
|
||||
Collection result = new ArrayList(multiRecord);
|
||||
multiRecord = null;
|
||||
|
||||
return result;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private void process(FieldSet fieldSet) {
|
||||
//finish processing if we hit the end of file
|
||||
if (fieldSet == null) {
|
||||
log.debug("FINISHED");
|
||||
recordFinished = true;
|
||||
multiRecord = null;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
//start a new collection
|
||||
if (fieldSet.readString(0).equals("BEGIN")) {
|
||||
log.debug("STARTING NEW RECORD");
|
||||
multiRecord = new ArrayList();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
//mark we are finished with current collection
|
||||
if (fieldSet.readString(0).equals("END")) {
|
||||
log.debug("END OF RECORD");
|
||||
recordFinished = true;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
//add a simple record to the current collection
|
||||
log.debug("MAPPING: " + fieldSet);
|
||||
multiRecord.add(fieldSetMapper.mapLine(fieldSet));
|
||||
}
|
||||
|
||||
public void setInputSource(FieldSetInputSource inputTemplate) {
|
||||
this.inputSource = inputTemplate;
|
||||
}
|
||||
|
||||
public void setFieldSetMapper(FieldSetMapper mapper) {
|
||||
this.fieldSetMapper = mapper;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
/*
|
||||
* 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.module;
|
||||
|
||||
|
||||
import org.springframework.batch.core.tasklet.Tasklet;
|
||||
import org.springframework.batch.execution.tasklet.RestartableItemProviderTasklet;
|
||||
import org.springframework.batch.io.exception.BatchCriticalException;
|
||||
|
||||
/**
|
||||
* Hacked {@link Tasklet} that throws exception on a given record number
|
||||
* (useful for testing restart).
|
||||
*
|
||||
* @author Robert Kasanicky
|
||||
*
|
||||
*/
|
||||
public class ExceptionRestartableTasklet extends RestartableItemProviderTasklet {
|
||||
|
||||
private int counter = 0;
|
||||
private int throwExceptionOnRecordNumber = 4;
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see Tasklet#execute()
|
||||
*/
|
||||
public boolean execute() throws Exception {
|
||||
|
||||
counter++;
|
||||
if (counter == throwExceptionOnRecordNumber) {
|
||||
throw new BatchCriticalException();
|
||||
}
|
||||
|
||||
return super.execute();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param throwExceptionOnRecordNumber The number of record on which exception should be thrown
|
||||
*/
|
||||
public void setThrowExceptionOnRecordNumber(int throwExceptionOnRecordNumber) {
|
||||
this.throwExceptionOnRecordNumber = throwExceptionOnRecordNumber;
|
||||
}
|
||||
|
||||
public int getThrowExceptionOnRecordNumber() {
|
||||
return throwExceptionOnRecordNumber;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
/*
|
||||
* 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.module;
|
||||
|
||||
import java.util.Properties;
|
||||
|
||||
import org.springframework.batch.core.tasklet.Tasklet;
|
||||
import org.springframework.batch.statistics.StatisticsProvider;
|
||||
import org.springframework.batch.support.PropertiesConverter;
|
||||
|
||||
/**
|
||||
* Simple module implementation that will always return true to indicate
|
||||
* that processing should continue. This is useful for testing graceful
|
||||
* shutdown of jobs.
|
||||
*
|
||||
* @author Lucas Ward
|
||||
*
|
||||
*/
|
||||
public class InfiniteLoopTasklet implements Tasklet, StatisticsProvider {
|
||||
|
||||
private int count = 0;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public InfiniteLoopTasklet() {
|
||||
super();
|
||||
}
|
||||
|
||||
public boolean execute() throws Exception {
|
||||
Thread.sleep(500);
|
||||
count++;
|
||||
return true;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.springframework.batch.statistics.StatisticsProvider#getStatistics()
|
||||
*/
|
||||
public Properties getStatistics() {
|
||||
return PropertiesConverter.stringToProperties("count="+count);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,209 @@
|
||||
/*
|
||||
* 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.module;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.springframework.batch.core.configuration.StepConfiguration;
|
||||
import org.springframework.batch.core.runtime.StepExecutionContext;
|
||||
import org.springframework.batch.io.file.FieldSet;
|
||||
import org.springframework.batch.io.file.FieldSetInputSource;
|
||||
import org.springframework.batch.io.file.FieldSetMapper;
|
||||
import org.springframework.batch.item.provider.AbstractItemProvider;
|
||||
import org.springframework.batch.item.validator.Validator;
|
||||
import org.springframework.batch.sample.domain.Address;
|
||||
import org.springframework.batch.sample.domain.BillingInfo;
|
||||
import org.springframework.batch.sample.domain.Customer;
|
||||
import org.springframework.batch.sample.domain.LineItem;
|
||||
import org.springframework.batch.sample.domain.Order;
|
||||
import org.springframework.batch.sample.domain.ShippingInfo;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @author peter.zozom
|
||||
*
|
||||
*/
|
||||
public class OrderItemProvider extends AbstractItemProvider {
|
||||
private static Log log = LogFactory.getLog(OrderItemProvider.class);
|
||||
private FieldSetInputSource inputSource;
|
||||
private Order order;
|
||||
private boolean recordFinished;
|
||||
private FieldSetMapper headerMapper;
|
||||
private FieldSetMapper customerMapper;
|
||||
private FieldSetMapper addressMapper;
|
||||
private FieldSetMapper billingMapper;
|
||||
private FieldSetMapper itemMapper;
|
||||
private FieldSetMapper shippingMapper;
|
||||
private Validator validator;
|
||||
|
||||
/**
|
||||
* @see org.springframework.batch.item.ItemProvider#next()
|
||||
*/
|
||||
public Object next() {
|
||||
recordFinished = false;
|
||||
|
||||
while (!recordFinished) {
|
||||
process(inputSource.readFieldSet());
|
||||
}
|
||||
|
||||
if (order!=null) {
|
||||
log.info("Mapped: "+order);
|
||||
validator.validate(order);
|
||||
}
|
||||
|
||||
Object result = order;
|
||||
order = null;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.springframework.batch.execution.io.FieldSetCallback#process(StepConfiguration, StepExecutionContext)
|
||||
*/
|
||||
private void process(FieldSet fieldSet) {
|
||||
//finish processing if we hit the end of file
|
||||
if (fieldSet == null) {
|
||||
log.debug("FINISHED");
|
||||
recordFinished = true;
|
||||
order = null;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
String lineId = fieldSet.readString(0);
|
||||
|
||||
//start a new Order
|
||||
if (Order.LINE_ID_HEADER.equals(lineId)) {
|
||||
log.debug("STARTING NEW RECORD");
|
||||
order = (Order) headerMapper.mapLine(fieldSet);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
//mark we are finished with current Order
|
||||
if (Order.LINE_ID_FOOTER.equals(lineId)) {
|
||||
log.debug("END OF RECORD");
|
||||
|
||||
//Do mapping for footer here, because mapper does not allow to pass an Order object as input.
|
||||
//Mapper always creates new object
|
||||
order.setTotalPrice(fieldSet.readBigDecimal("TOTAL_PRICE"));
|
||||
order.setTotalLines(fieldSet.readInt("TOTAL_LINE_ITEMS"));
|
||||
order.setTotalItems(fieldSet.readInt("TOTAL_ITEMS"));
|
||||
|
||||
recordFinished = true;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (Customer.LINE_ID_BUSINESS_CUST.equals(lineId)) {
|
||||
log.debug("MAPPING CUSTOMER");
|
||||
|
||||
if (order.getCustomer() == null) {
|
||||
order.setCustomer((Customer) customerMapper.mapLine(fieldSet));
|
||||
order.getCustomer().setBusinessCustomer(true);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (Customer.LINE_ID_NON_BUSINESS_CUST.equals(lineId)) {
|
||||
log.debug("MAPPING CUSTOMER");
|
||||
|
||||
if (order.getCustomer() == null) {
|
||||
order.setCustomer((Customer) customerMapper.mapLine(fieldSet));
|
||||
order.getCustomer().setBusinessCustomer(false);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (Address.LINE_ID_BILLING_ADDR.equals(lineId)) {
|
||||
log.debug("MAPPING BILLING ADDRESS");
|
||||
order.setBillingAddress((Address) addressMapper.mapLine(fieldSet));
|
||||
return;
|
||||
}
|
||||
|
||||
if (Address.LINE_ID_SHIPPING_ADDR.equals(lineId)) {
|
||||
log.debug("MAPPING SHIPPING ADDRESS");
|
||||
order.setShippingAddress((Address) addressMapper.mapLine(fieldSet));
|
||||
return;
|
||||
}
|
||||
|
||||
if (BillingInfo.LINE_ID_BILLING_INFO.equals(lineId)) {
|
||||
log.debug("MAPPING BILLING INFO");
|
||||
order.setBilling((BillingInfo) billingMapper.mapLine(fieldSet));
|
||||
return;
|
||||
}
|
||||
|
||||
if (ShippingInfo.LINE_ID_SHIPPING_INFO.equals(lineId)) {
|
||||
log.debug("MAPPING SHIPPING INFO");
|
||||
order.setShipping((ShippingInfo) shippingMapper.mapLine(fieldSet));
|
||||
return;
|
||||
}
|
||||
|
||||
if (LineItem.LINE_ID_ITEM.equals(lineId)) {
|
||||
log.debug("MAPPING LINE ITEM");
|
||||
|
||||
if (order.getLineItems() == null) {
|
||||
order.setLineItems(new ArrayList());
|
||||
}
|
||||
|
||||
order.getLineItems().add(itemMapper.mapLine(fieldSet));
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
log.debug("Could not map LINE_ID="+lineId);
|
||||
|
||||
}
|
||||
|
||||
public void setAddressMapper(FieldSetMapper addressMapper) {
|
||||
this.addressMapper = addressMapper;
|
||||
}
|
||||
|
||||
public void setBillingMapper(FieldSetMapper billingMapper) {
|
||||
this.billingMapper = billingMapper;
|
||||
}
|
||||
|
||||
public void setCustomerMapper(FieldSetMapper customerMapper) {
|
||||
this.customerMapper = customerMapper;
|
||||
}
|
||||
|
||||
public void setHeaderMapper(FieldSetMapper headerMapper) {
|
||||
this.headerMapper = headerMapper;
|
||||
}
|
||||
|
||||
public void setInputSource(FieldSetInputSource inputTemplate) {
|
||||
this.inputSource = inputTemplate;
|
||||
}
|
||||
|
||||
public void setItemMapper(FieldSetMapper itemMapper) {
|
||||
this.itemMapper = itemMapper;
|
||||
}
|
||||
|
||||
public void setShippingMapper(FieldSetMapper shippingMapper) {
|
||||
this.shippingMapper = shippingMapper;
|
||||
}
|
||||
|
||||
public void setValidator(Validator validator) {
|
||||
this.validator = validator;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,135 @@
|
||||
/*
|
||||
* 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.module;
|
||||
|
||||
import java.util.Properties;
|
||||
|
||||
import org.springframework.batch.execution.tasklet.ReadProcessTasklet;
|
||||
import org.springframework.batch.io.file.FieldSet;
|
||||
import org.springframework.batch.io.file.FieldSetMapper;
|
||||
import org.springframework.batch.io.file.support.DefaultFlatFileInputSource;
|
||||
import org.springframework.batch.sample.dao.TradeWriter;
|
||||
import org.springframework.batch.sample.domain.Trade;
|
||||
import org.springframework.batch.statistics.StatisticsProvider;
|
||||
|
||||
/**
|
||||
* Simple implementation of a {@link ReadProcessTasklet}, which illustrates the
|
||||
* case when reading and processing of input is not separated. This can be
|
||||
* viable in cases, when the input reading and processing logic need not to be
|
||||
* reused in different contexts. In general it is recommended to separate these
|
||||
* two concerns.
|
||||
*
|
||||
* Note this class is NOT thread-safe, contrast to 'standard' module
|
||||
* implementations provided by the framework.
|
||||
*
|
||||
* @author Robert Kasanicky
|
||||
* @author Lucas Ward
|
||||
*/
|
||||
public class SimpleTradeTasklet extends ReadProcessTasklet implements StatisticsProvider {
|
||||
/**
|
||||
* reads the data from input file
|
||||
*/
|
||||
private DefaultFlatFileInputSource inputSource;
|
||||
|
||||
/**
|
||||
* maps a line to a Trade object
|
||||
*/
|
||||
private FieldSetMapper tradeFieldSetMapper = new TradeFieldSetMapper();
|
||||
|
||||
/**
|
||||
* writes a Trade object to output
|
||||
*/
|
||||
private TradeWriter tradeWriter;
|
||||
|
||||
/**
|
||||
* domain object being processed
|
||||
*/
|
||||
private Trade trade;
|
||||
|
||||
/**
|
||||
* number of trade objects processed
|
||||
*/
|
||||
private int tradeCount = 0;
|
||||
|
||||
/**
|
||||
* Read method, all reading from any input source(s) should be done here.
|
||||
* The input template is read using the readAndMap method, which accepts a
|
||||
* FieldSetMapper. This call returns an object (which should be a Trade
|
||||
* value object) then will be stored in a class-level variable for use by
|
||||
* the process method.
|
||||
*/
|
||||
public boolean read() {
|
||||
trade = (Trade) tradeFieldSetMapper.mapLine(inputSource.readFieldSet());
|
||||
|
||||
if (trade == null) {
|
||||
// no Trade object returned, reading input is finished
|
||||
return false;
|
||||
}
|
||||
|
||||
tradeCount++;
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Process the data obtained during the read() method. Because this is a
|
||||
* simple example job, the data is simply written out without any
|
||||
* processing.
|
||||
*/
|
||||
public void process() {
|
||||
tradeWriter.writeTrade(trade);
|
||||
}
|
||||
|
||||
/**
|
||||
* Inner class which implements the FieldSetMapper interface. It contains
|
||||
* one method, mapLine, which accepts a FieldSet as a parameter. This method
|
||||
* will be called by the inputSource when it is passed in.
|
||||
*
|
||||
*/
|
||||
private static class TradeFieldSetMapper implements FieldSetMapper {
|
||||
public Object mapLine(FieldSet fieldSet) {
|
||||
|
||||
if (fieldSet == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
Trade trade = new Trade();
|
||||
trade.setIsin(fieldSet.readString("ISIN"));
|
||||
trade.setQuantity(fieldSet.readLong(1));
|
||||
trade.setPrice(fieldSet.readBigDecimal(2));
|
||||
trade.setCustomer(fieldSet.readString(3));
|
||||
|
||||
return trade;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public void setInputSource(DefaultFlatFileInputSource inputTemplate) {
|
||||
this.inputSource = inputTemplate;
|
||||
}
|
||||
|
||||
public void setTradeDao(TradeWriter tradeWriter) {
|
||||
this.tradeWriter = tradeWriter;
|
||||
}
|
||||
|
||||
public Properties getStatistics() {
|
||||
Properties statistics = new Properties();
|
||||
statistics.setProperty("Trade.Count", String.valueOf(tradeCount));
|
||||
statistics.putAll(inputSource.getStatistics());
|
||||
return statistics;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
/*
|
||||
* 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.module;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.springframework.batch.io.exception.TransactionInvalidException;
|
||||
import org.springframework.batch.io.file.FieldSetInputSource;
|
||||
import org.springframework.batch.io.file.FieldSetMapper;
|
||||
import org.springframework.batch.item.provider.AbstractItemProvider;
|
||||
|
||||
/**
|
||||
* @author peter.zozom
|
||||
*
|
||||
*/
|
||||
public class SkipSampleItemProvider extends AbstractItemProvider {
|
||||
|
||||
private static Log log = LogFactory.getLog(SkipSampleItemProvider.class);
|
||||
|
||||
private int counter = 0;
|
||||
|
||||
private int exceptionOnrecordNumber = 14;
|
||||
|
||||
private FieldSetInputSource inputSource;
|
||||
|
||||
private FieldSetMapper fieldSetMapper;
|
||||
|
||||
public Object next() {
|
||||
counter++;
|
||||
|
||||
if (counter == exceptionOnrecordNumber) {
|
||||
// this causes rollback of current transaction
|
||||
log.debug("Throwing TransactionInvalidException to cause transaction rollback...");
|
||||
throw new TransactionInvalidException("Error processing line: " + counter + ". Rollbacking...");
|
||||
}
|
||||
|
||||
return fieldSetMapper.mapLine(inputSource.readFieldSet());
|
||||
}
|
||||
|
||||
public void setInputSource(FieldSetInputSource inputTemplate) {
|
||||
this.inputSource = inputTemplate;
|
||||
}
|
||||
|
||||
public void setFieldSetMapper(FieldSetMapper fieldSetMapper) {
|
||||
this.fieldSetMapper = fieldSetMapper;
|
||||
}
|
||||
|
||||
public void setThrowExceptionOnRecordNumber(int exceptionOnrecordNumber) {
|
||||
this.exceptionOnrecordNumber = exceptionOnrecordNumber;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
* 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.module.process;
|
||||
|
||||
import org.springframework.batch.item.ItemProcessor;
|
||||
import org.springframework.batch.sample.dao.CustomerCreditWriter;
|
||||
import org.springframework.batch.sample.domain.CustomerCredit;
|
||||
|
||||
|
||||
|
||||
public class CustomerCreditUpdateProcessor implements ItemProcessor {
|
||||
private double creditFilter = 800;
|
||||
private CustomerCreditWriter writer;
|
||||
|
||||
public void process(Object data) {
|
||||
CustomerCredit customerCredit = (CustomerCredit) data;
|
||||
|
||||
if (customerCredit.getCredit().doubleValue() > creditFilter) {
|
||||
writer.write(customerCredit);
|
||||
}
|
||||
}
|
||||
|
||||
public void setCreditFilter(double creditFilter) {
|
||||
this.creditFilter = creditFilter;
|
||||
}
|
||||
|
||||
public void setWriter(CustomerCreditWriter writer) {
|
||||
this.writer = writer;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
/*
|
||||
* 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.module.process;
|
||||
|
||||
import org.springframework.batch.item.ItemProcessor;
|
||||
import org.springframework.batch.sample.dao.JdbcCustomerDebitWriter;
|
||||
import org.springframework.batch.sample.domain.CustomerDebit;
|
||||
import org.springframework.batch.sample.domain.Trade;
|
||||
|
||||
|
||||
/**
|
||||
* Transforms Trade to a CustomerDebit and asks dao object to write the result.
|
||||
*
|
||||
* @author Robert Kasanicky
|
||||
*/
|
||||
public class CustomerUpdateProcessor implements ItemProcessor {
|
||||
private JdbcCustomerDebitWriter dao;
|
||||
|
||||
public void process(Object data) {
|
||||
Trade trade = (Trade) data;
|
||||
CustomerDebit customerDebit = new CustomerDebit();
|
||||
customerDebit.setName(trade.getCustomer());
|
||||
customerDebit.setDebit(trade.getPrice());
|
||||
dao.write(customerDebit);
|
||||
}
|
||||
|
||||
public void setDao(JdbcCustomerDebitWriter outputSource) {
|
||||
this.dao = outputSource;
|
||||
}
|
||||
|
||||
public void close() {
|
||||
}
|
||||
|
||||
public void init() {
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package org.springframework.batch.sample.module.process;
|
||||
|
||||
import org.springframework.batch.io.file.support.FlatFileOutputSource;
|
||||
import org.springframework.batch.item.ItemProcessor;
|
||||
|
||||
public class DefaultFlatFileProcessor implements ItemProcessor{
|
||||
|
||||
private FlatFileOutputSource flatFileOutputSource;
|
||||
|
||||
public void process(Object data) throws Exception {
|
||||
flatFileOutputSource.write(""+data);
|
||||
}
|
||||
|
||||
public void setFlatFileOutputSource(FlatFileOutputSource flatFileOutputSource) {
|
||||
this.flatFileOutputSource = flatFileOutputSource;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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.module.process;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.springframework.batch.item.ItemProcessor;
|
||||
|
||||
/**
|
||||
* Dummy processor useful for development and testing.
|
||||
*
|
||||
* @author Robert Kasanicky
|
||||
*/
|
||||
public class DummyProcessor implements ItemProcessor {
|
||||
|
||||
private static final Log log = LogFactory.getLog(DummyProcessor.class);
|
||||
|
||||
public void process(Object object) {
|
||||
log.debug("PROCESSING: " + object);
|
||||
}
|
||||
|
||||
public void close() {
|
||||
}
|
||||
|
||||
public void init() {
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
* 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.module.process;
|
||||
|
||||
import org.springframework.batch.io.exception.BatchCriticalException;
|
||||
import org.springframework.batch.item.ItemProcessor;
|
||||
import org.springframework.batch.sample.dao.OrderWriter;
|
||||
import org.springframework.batch.sample.domain.Order;
|
||||
|
||||
|
||||
|
||||
public class OrderProcessor implements ItemProcessor {
|
||||
private OrderWriter writer;
|
||||
private Order order;
|
||||
|
||||
public void process(Object data) {
|
||||
if (!(data instanceof Order)) {
|
||||
throw new BatchCriticalException("OrderProcessor can process only Order objects");
|
||||
}
|
||||
|
||||
order = (Order) data;
|
||||
writer.write(order);
|
||||
}
|
||||
|
||||
public void setWriter(OrderWriter reportService) {
|
||||
this.writer = reportService;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
* 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.module.process;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.springframework.batch.item.ItemProcessor;
|
||||
import org.springframework.batch.sample.domain.Person;
|
||||
|
||||
|
||||
|
||||
public class PersonProcessor implements ItemProcessor {
|
||||
private static Log log = LogFactory.getLog(PersonProcessor.class);
|
||||
|
||||
public void process(Object data) {
|
||||
if (!(data instanceof Person)) {
|
||||
log.warn("PersonProcessor can process only Person objects, skipping record");
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
log.debug("Processing: " + data);
|
||||
}
|
||||
|
||||
public void close() {
|
||||
}
|
||||
|
||||
public void init() {
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
/*
|
||||
* 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.module.process;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.springframework.batch.item.ItemProcessor;
|
||||
import org.springframework.batch.sample.dao.TradeWriter;
|
||||
import org.springframework.batch.sample.domain.Trade;
|
||||
|
||||
|
||||
|
||||
public class TradeProcessor implements ItemProcessor {
|
||||
private static Log log = LogFactory.getLog(TradeProcessor.class);
|
||||
private TradeWriter writer;
|
||||
|
||||
public void process(Object data) {
|
||||
if (!(data instanceof Trade)) {
|
||||
log.warn("TradeProcessor can process only Trade objects, skipping record");
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
Trade trade = (Trade) data;
|
||||
log.debug(data);
|
||||
|
||||
//TODO put some processing of the trade object here
|
||||
writer.writeTrade(trade);
|
||||
}
|
||||
|
||||
public void setWriter(TradeWriter dao) {
|
||||
this.writer = dao;
|
||||
}
|
||||
|
||||
public void close() {
|
||||
}
|
||||
|
||||
public void init() {
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
/*
|
||||
* 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.validation.valang.custom;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
import org.springmodules.validation.valang.functions.AbstractFunction;
|
||||
import org.springmodules.validation.valang.functions.Function;
|
||||
|
||||
|
||||
/**
|
||||
* Returns Boolean.TRUE if given value is future date, else it returns Boolean.FALSE
|
||||
* @author peter.zozom
|
||||
*/
|
||||
public class FutureDateFunction extends AbstractFunction {
|
||||
/**
|
||||
* @param arguments
|
||||
* @param line
|
||||
* @param column
|
||||
*/
|
||||
public FutureDateFunction(Function[] arguments, int line, int column) {
|
||||
super(arguments, line, column);
|
||||
definedExactNumberOfArguments(1);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.springmodules.validation.valang.functions.AbstractFunction#doGetResult(java.lang.Object)
|
||||
*/
|
||||
protected Object doGetResult(final Object target) throws Exception {
|
||||
//get argument
|
||||
final Object value = getArguments()[0].getResult(target);
|
||||
|
||||
Boolean result = Boolean.FALSE;
|
||||
|
||||
if (value instanceof Date) {
|
||||
final Date now = new Date(System.currentTimeMillis());
|
||||
final Date date = (Date) value;
|
||||
result = (now.compareTo(date) < 0) ? Boolean.TRUE : Boolean.FALSE;
|
||||
} else {
|
||||
throw new Exception("No Date value for validation");
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
/*
|
||||
* 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.validation.valang.custom;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.batch.sample.domain.LineItem;
|
||||
import org.springmodules.validation.valang.functions.AbstractFunction;
|
||||
import org.springmodules.validation.valang.functions.Function;
|
||||
|
||||
|
||||
/**
|
||||
* Validates total items count in Order.
|
||||
*
|
||||
* @author peter.zozom
|
||||
*/
|
||||
public class TotalOrderItemsFunction extends AbstractFunction {
|
||||
public TotalOrderItemsFunction(Function[] arguments, int line, int column) {
|
||||
super(arguments, line, column);
|
||||
definedExactNumberOfArguments(2);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.springmodules.validation.valang.functions.AbstractFunction#doGetResult(java.lang.Object)
|
||||
*/
|
||||
protected Object doGetResult(Object target) throws Exception {
|
||||
//get arguments
|
||||
int count = ((Integer) getArguments()[0].getResult(target)).intValue();
|
||||
Object value = getArguments()[1].getResult(target);
|
||||
|
||||
Boolean result;
|
||||
|
||||
//count items in list of order lines
|
||||
if (value instanceof List) {
|
||||
int totalItems = 0;
|
||||
|
||||
for (Iterator i = ((List) value).iterator(); i.hasNext();) {
|
||||
LineItem item = (LineItem) i.next();
|
||||
totalItems += item.getQuantity();
|
||||
}
|
||||
|
||||
result = (totalItems == count) ? Boolean.TRUE : Boolean.FALSE;
|
||||
} else {
|
||||
throw new Exception("No list for validation");
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
/*
|
||||
* 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.validation.valang.custom;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.batch.sample.domain.LineItem;
|
||||
import org.springmodules.validation.valang.functions.AbstractFunction;
|
||||
import org.springmodules.validation.valang.functions.Function;
|
||||
|
||||
|
||||
/**
|
||||
* @author peter.zozom
|
||||
*
|
||||
*/
|
||||
public class ValidateDiscountsFunction extends AbstractFunction {
|
||||
private static final BigDecimal BD_0 = new BigDecimal(0.0);
|
||||
private static final BigDecimal BD_PERC_MAX = new BigDecimal(100.0);
|
||||
|
||||
public ValidateDiscountsFunction(Function[] arguments, int line, int column) {
|
||||
super(arguments, line, column);
|
||||
definedExactNumberOfArguments(1);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.springmodules.validation.valang.functions.AbstractFunction#doGetResult(java.lang.Object)
|
||||
*/
|
||||
protected Object doGetResult(Object target) throws Exception {
|
||||
List lineItems = (List) getArguments()[0].getResult(target);
|
||||
|
||||
for (Iterator i = lineItems.iterator(); i.hasNext();) {
|
||||
LineItem item = (LineItem) i.next();
|
||||
|
||||
if (BD_0.compareTo(item.getDiscountPerc()) != 0) {
|
||||
//DiscountPerc must be between 0.0 and 100.0
|
||||
if ((BD_0.compareTo(item.getDiscountPerc()) > 0)
|
||||
|| (BD_PERC_MAX.compareTo(item.getDiscountPerc()) < 0)
|
||||
|| (BD_0.compareTo(item.getDiscountAmount()) != 0)) { //only one of DiscountAmount and DiscountPerc should be non-zero
|
||||
|
||||
return Boolean.FALSE;
|
||||
}
|
||||
} else {
|
||||
//DiscountAmount must be between 0.0 and item.price
|
||||
if ((BD_0.compareTo(item.getDiscountAmount()) > 0)
|
||||
|| (item.getPrice().compareTo(item.getDiscountAmount()) < 0)) {
|
||||
return Boolean.FALSE;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return Boolean.TRUE;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
/*
|
||||
* 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.validation.valang.custom;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.batch.sample.domain.LineItem;
|
||||
import org.springmodules.validation.valang.functions.AbstractFunction;
|
||||
import org.springmodules.validation.valang.functions.Function;
|
||||
|
||||
|
||||
/**
|
||||
* @author peter.zozom
|
||||
*
|
||||
*/
|
||||
public class ValidateHandlingPricesFunction extends AbstractFunction {
|
||||
private static final BigDecimal BD_MIN = new BigDecimal(0.0);
|
||||
private static final BigDecimal BD_MAX = new BigDecimal(99999999.99);
|
||||
|
||||
public ValidateHandlingPricesFunction(Function[] arguments, int line, int column) {
|
||||
super(arguments, line, column);
|
||||
definedExactNumberOfArguments(1);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.springmodules.validation.valang.functions.AbstractFunction#doGetResult(java.lang.Object)
|
||||
*/
|
||||
protected Object doGetResult(Object target) throws Exception {
|
||||
List lineItems = (List) getArguments()[0].getResult(target);
|
||||
|
||||
for (Iterator i = lineItems.iterator(); i.hasNext();) {
|
||||
LineItem item = (LineItem) i.next();
|
||||
|
||||
if ((BD_MIN.compareTo(item.getHandlingPrice()) > 0)
|
||||
|| (BD_MAX.compareTo(item.getHandlingPrice()) < 0)) {
|
||||
return Boolean.FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
return Boolean.TRUE;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
/*
|
||||
* 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.validation.valang.custom;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.batch.sample.domain.LineItem;
|
||||
import org.springmodules.validation.valang.functions.AbstractFunction;
|
||||
import org.springmodules.validation.valang.functions.Function;
|
||||
|
||||
|
||||
/**
|
||||
* @author peter.zozom
|
||||
*
|
||||
*/
|
||||
public class ValidateIdsFunction extends AbstractFunction {
|
||||
private static final long MAX_ID = 9999999999L;
|
||||
|
||||
public ValidateIdsFunction(Function[] arguments, int line, int column) {
|
||||
super(arguments, line, column);
|
||||
definedExactNumberOfArguments(1);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.springmodules.validation.valang.functions.AbstractFunction#doGetResult(java.lang.Object)
|
||||
*/
|
||||
protected Object doGetResult(Object target) throws Exception {
|
||||
List lineItems = (List) getArguments()[0].getResult(target);
|
||||
|
||||
for (Iterator i = lineItems.iterator(); i.hasNext();) {
|
||||
LineItem item = (LineItem) i.next();
|
||||
|
||||
if ((item.getItemId() <= 0) || (item.getItemId() > MAX_ID)) {
|
||||
return Boolean.FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
return Boolean.TRUE;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
/*
|
||||
* 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.validation.valang.custom;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.batch.sample.domain.LineItem;
|
||||
import org.springmodules.validation.valang.functions.AbstractFunction;
|
||||
import org.springmodules.validation.valang.functions.Function;
|
||||
|
||||
|
||||
/**
|
||||
* @author peter.zozom
|
||||
*
|
||||
*/
|
||||
public class ValidatePricesFunction extends AbstractFunction {
|
||||
private static final BigDecimal BD_MIN = new BigDecimal(0.0);
|
||||
private static final BigDecimal BD_MAX = new BigDecimal(99999999.99);
|
||||
|
||||
public ValidatePricesFunction(Function[] arguments, int line, int column) {
|
||||
super(arguments, line, column);
|
||||
definedExactNumberOfArguments(1);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.springmodules.validation.valang.functions.AbstractFunction#doGetResult(java.lang.Object)
|
||||
*/
|
||||
protected Object doGetResult(Object target) throws Exception {
|
||||
List lineItems = (List) getArguments()[0].getResult(target);
|
||||
|
||||
for (Iterator i = lineItems.iterator(); i.hasNext();) {
|
||||
LineItem item = (LineItem) i.next();
|
||||
|
||||
if ((BD_MIN.compareTo(item.getPrice()) > 0) || (BD_MAX.compareTo(item.getPrice()) < 0)) {
|
||||
return Boolean.FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
return Boolean.TRUE;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
/*
|
||||
* 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.validation.valang.custom;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.batch.sample.domain.LineItem;
|
||||
import org.springmodules.validation.valang.functions.AbstractFunction;
|
||||
import org.springmodules.validation.valang.functions.Function;
|
||||
|
||||
|
||||
/**
|
||||
* @author peter.zozom
|
||||
*
|
||||
*/
|
||||
public class ValidateQuantitiesFunction extends AbstractFunction {
|
||||
private static final int MAX_QUANTITY = 9999;
|
||||
|
||||
public ValidateQuantitiesFunction(Function[] arguments, int line, int column) {
|
||||
super(arguments, line, column);
|
||||
definedExactNumberOfArguments(1);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.springmodules.validation.valang.functions.AbstractFunction#doGetResult(java.lang.Object)
|
||||
*/
|
||||
protected Object doGetResult(Object target) throws Exception {
|
||||
List lineItems = (List) getArguments()[0].getResult(target);
|
||||
|
||||
for (Iterator i = lineItems.iterator(); i.hasNext();) {
|
||||
LineItem item = (LineItem) i.next();
|
||||
|
||||
if ((item.getQuantity() <= 0) || (item.getQuantity() > MAX_QUANTITY)) {
|
||||
return Boolean.FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
return Boolean.TRUE;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
/*
|
||||
* 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.validation.valang.custom;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.batch.sample.domain.LineItem;
|
||||
import org.springmodules.validation.valang.functions.AbstractFunction;
|
||||
import org.springmodules.validation.valang.functions.Function;
|
||||
|
||||
|
||||
/**
|
||||
* @author peter.zozom
|
||||
*
|
||||
*/
|
||||
public class ValidateShippingPricesFunction extends AbstractFunction {
|
||||
private static final BigDecimal BD_MIN = new BigDecimal(0.0);
|
||||
private static final BigDecimal BD_MAX = new BigDecimal(99999999.99);
|
||||
|
||||
public ValidateShippingPricesFunction(Function[] arguments, int line, int column) {
|
||||
super(arguments, line, column);
|
||||
definedExactNumberOfArguments(1);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.springmodules.validation.valang.functions.AbstractFunction#doGetResult(java.lang.Object)
|
||||
*/
|
||||
protected Object doGetResult(Object target) throws Exception {
|
||||
List lineItems = (List) getArguments()[0].getResult(target);
|
||||
|
||||
for (Iterator i = lineItems.iterator(); i.hasNext();) {
|
||||
LineItem item = (LineItem) i.next();
|
||||
|
||||
if ((BD_MIN.compareTo(item.getShippingPrice()) > 0)
|
||||
|| (BD_MAX.compareTo(item.getShippingPrice()) < 0)) {
|
||||
return Boolean.FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
return Boolean.TRUE;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,84 @@
|
||||
/*
|
||||
* 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.validation.valang.custom;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.batch.sample.domain.LineItem;
|
||||
import org.springmodules.validation.valang.functions.AbstractFunction;
|
||||
import org.springmodules.validation.valang.functions.Function;
|
||||
|
||||
|
||||
/**
|
||||
* @author peter.zozom
|
||||
*
|
||||
*/
|
||||
public class ValidateTotalPricesFunction extends AbstractFunction {
|
||||
private static final BigDecimal BD_MIN = new BigDecimal(0.0);
|
||||
private static final BigDecimal BD_MAX = new BigDecimal(99999999.99);
|
||||
private static final BigDecimal BD_100 = new BigDecimal(100.00);
|
||||
|
||||
public ValidateTotalPricesFunction(Function[] arguments, int line, int column) {
|
||||
super(arguments, line, column);
|
||||
definedExactNumberOfArguments(1);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.springmodules.validation.valang.functions.AbstractFunction#doGetResult(java.lang.Object)
|
||||
*/
|
||||
protected Object doGetResult(Object target) throws Exception {
|
||||
List lineItems = (List) getArguments()[0].getResult(target);
|
||||
|
||||
for (Iterator i = lineItems.iterator(); i.hasNext();) {
|
||||
LineItem item = (LineItem) i.next();
|
||||
|
||||
if ((BD_MIN.compareTo(item.getTotalPrice()) > 0)
|
||||
|| (BD_MAX.compareTo(item.getTotalPrice()) < 0)) {
|
||||
return Boolean.FALSE;
|
||||
}
|
||||
|
||||
//calculate total price
|
||||
|
||||
//discount coeficient = (100.00 - discountPerc) / 100.00
|
||||
BigDecimal coef = BD_100.subtract(item.getDiscountPerc())
|
||||
.divide(BD_100, 4, BigDecimal.ROUND_HALF_UP);
|
||||
|
||||
//discountedPrice = (price * coef) - discountAmount
|
||||
//at least one of discountPerc and discountAmount is 0 - this is validated by ValidateDiscountsFunction
|
||||
BigDecimal discountedPrice = item.getPrice().multiply(coef)
|
||||
.subtract(item.getDiscountAmount());
|
||||
|
||||
//price for single item = discountedPrice + shipping + handling
|
||||
BigDecimal singleItemPrice = discountedPrice.add(item.getShippingPrice())
|
||||
.add(item.getHandlingPrice());
|
||||
|
||||
//total price = singleItemPrice * quantity
|
||||
BigDecimal quantity = new BigDecimal(item.getQuantity());
|
||||
BigDecimal totalPrice = singleItemPrice.multiply(quantity)
|
||||
.setScale(2, BigDecimal.ROUND_HALF_UP);
|
||||
|
||||
//calculatedPrice should equal to item.totalPrice
|
||||
if (totalPrice.compareTo(item.getTotalPrice()) != 0) {
|
||||
return Boolean.FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
return Boolean.TRUE;
|
||||
}
|
||||
}
|
||||
23
samples/src/main/resources/batch.properties
Normal file
23
samples/src/main/resources/batch.properties
Normal file
@@ -0,0 +1,23 @@
|
||||
# Placeholders batch.*
|
||||
# for HSQLDB:
|
||||
batch.jdbc.driver=org.hsqldb.jdbcDriver
|
||||
batch.jdbc.url=jdbc:hsqldb:mem:testdb
|
||||
# use this one for a separate server process (so you can inspect the results)
|
||||
# batch.jdbc.url=jdbc:hsqldb:hsql://localhost:9005/samples
|
||||
batch.jdbc.user=sa
|
||||
batch.jdbc.password=
|
||||
batch.schema=
|
||||
batch.jndi.name=
|
||||
batch.naming.factory.initial=
|
||||
batch.naming.provider.url=
|
||||
batch.database.vendor=HSQLDB
|
||||
batch.database.incrementer.class=org.springframework.jdbc.support.incrementer.HsqlMaxValueIncrementer
|
||||
|
||||
# Other platforms:
|
||||
# org.springframework.jdbc.support.incrementer.DB2SequenceMaxValueIncrementer
|
||||
# org.springframework.jdbc.support.incrementer.PostgreSQLSequenceMaxValueIncrementer
|
||||
|
||||
# Bean Properties for override
|
||||
# for HSQLDB:
|
||||
incrementerParent.columnName=ID
|
||||
|
||||
11
samples/src/main/resources/beanRefContext.xml
Normal file
11
samples/src/main/resources/beanRefContext.xml
Normal file
@@ -0,0 +1,11 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">
|
||||
|
||||
<bean id="simple-container" class="org.springframework.context.support.ClassPathXmlApplicationContext">
|
||||
<constructor-arg>
|
||||
<value>simple-container-definition.xml</value>
|
||||
</constructor-arg>
|
||||
</bean>
|
||||
|
||||
</beans>
|
||||
36
samples/src/main/resources/business-schema-hsqldb.sql
Normal file
36
samples/src/main/resources/business-schema-hsqldb.sql
Normal file
@@ -0,0 +1,36 @@
|
||||
DROP TABLE TRADE IF EXISTS;
|
||||
DROP TABLE TRADE_SEQ IF EXISTS;
|
||||
DROP TABLE CUSTOMER IF EXISTS;
|
||||
DROP TABLE CUSTOMER_SEQ IF EXISTS;
|
||||
|
||||
CREATE TABLE TRADE (
|
||||
ID BIGINT PRIMARY KEY,
|
||||
VERSION BIGINT,
|
||||
ISIN VARCHAR(45) NOT NULL,
|
||||
QUANTITY BIGINT,
|
||||
PRICE FLOAT,
|
||||
CUSTOMER VARCHAR(45)
|
||||
);
|
||||
|
||||
|
||||
CREATE TABLE TRADE_SEQ (
|
||||
ID BIGINT IDENTITY
|
||||
);
|
||||
|
||||
CREATE TABLE CUSTOMER (
|
||||
ID INTEGER PRIMARY KEY,
|
||||
VERSION BIGINT,
|
||||
NAME VARCHAR(45),
|
||||
CREDIT FLOAT
|
||||
);
|
||||
|
||||
CREATE TABLE CUSTOMER_SEQ (
|
||||
ID BIGINT IDENTITY
|
||||
);
|
||||
|
||||
INSERT INTO customer (id, version, name, credit) VALUES (1, 0, 'customer1', 100000);
|
||||
INSERT INTO customer (id, version, name, credit) VALUES (2, 0, 'customer2', 100000);
|
||||
INSERT INTO customer (id, version, name, credit) VALUES (3, 0, 'customer3', 100000);
|
||||
INSERT INTO customer (id, version, name, credit) VALUES (4, 0, 'customer4', 100000);
|
||||
|
||||
|
||||
16
samples/src/main/resources/data-source-context-init.xml
Normal file
16
samples/src/main/resources/data-source-context-init.xml
Normal file
@@ -0,0 +1,16 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">
|
||||
|
||||
<bean id="dataSourceInitializer" class="test.jdbc.datasource.InitializingDataSourceFactoryBean" autowire-candidate="false">
|
||||
<property name="dataSource" ref="dataSource"/>
|
||||
<property name="initScripts">
|
||||
<list>
|
||||
<value>schema-hsqldb.sql</value>
|
||||
<value>business-schema-hsqldb.sql</value>
|
||||
</list>
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
</beans>
|
||||
66
samples/src/main/resources/data-source-context.xml
Normal file
66
samples/src/main/resources/data-source-context.xml
Normal file
@@ -0,0 +1,66 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:util="http://www.springframework.org/schema/util"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
|
||||
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-2.0.xsd">
|
||||
|
||||
<!-- Initialise the database before every test case: -->
|
||||
<import resource="data-source-context-init.xml" />
|
||||
|
||||
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
|
||||
<property name="driverClassName" value="${batch.jdbc.driver}" />
|
||||
<property name="url" value="${batch.jdbc.url}" />
|
||||
<property name="username" value="${batch.jdbc.user}" />
|
||||
<property name="password" value="${batch.jdbc.password}" />
|
||||
</bean>
|
||||
|
||||
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
|
||||
<property name="dataSource" ref="dataSource" />
|
||||
</bean>
|
||||
|
||||
<!-- Use this to set additional properties on beans at run time -->
|
||||
<bean class="org.springframework.beans.factory.config.PropertyOverrideConfigurer">
|
||||
<property name="location" value="classpath:batch.properties" />
|
||||
<!-- Allow system properties (-D) to override those from file -->
|
||||
<property name="localOverride" value="true"/>
|
||||
<property name="properties">
|
||||
<bean class="java.lang.System" factory-method="getProperties"/>
|
||||
</property>
|
||||
<property name="ignoreInvalidKeys" value="true" />
|
||||
</bean>
|
||||
|
||||
<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
|
||||
<property name="location" value="classpath:batch.properties" />
|
||||
<property name="ignoreUnresolvablePlaceholders" value="false" />
|
||||
</bean>
|
||||
|
||||
<bean id="incrementerParent" class="${batch.database.incrementer.class}" abstract="true">
|
||||
<property name="dataSource" ref="dataSource" />
|
||||
</bean>
|
||||
|
||||
<bean id="jobIncrementer" parent="incrementerParent">
|
||||
<property name="incrementerName" value="BATCH_JOB_SEQ" />
|
||||
</bean>
|
||||
|
||||
<bean id="jobExecutionIncrementer" parent="incrementerParent">
|
||||
<property name="incrementerName" value="BATCH_JOB_EXECUTION_SEQ" />
|
||||
</bean>
|
||||
|
||||
<bean id="stepIncrementer" parent="incrementerParent">
|
||||
<property name="incrementerName" value="BATCH_STEP_SEQ" />
|
||||
</bean>
|
||||
|
||||
<bean id="stepExecutionIncrementer" parent="incrementerParent">
|
||||
<property name="incrementerName" value="BATCH_STEP_EXECUTION_SEQ" />
|
||||
</bean>
|
||||
|
||||
<bean id="partitionIncrementer" parent="incrementerParent">
|
||||
<property name="incrementerName" value="BATCH_PARTITION_SEQ" />
|
||||
</bean>
|
||||
|
||||
<bean id="partitionInstanceIncrementer" parent="incrementerParent">
|
||||
<property name="incrementerName" value="BATCH_PARTITION_EXECUTION_SEQ" />
|
||||
</bean>
|
||||
|
||||
</beans>
|
||||
@@ -0,0 +1,3 @@
|
||||
123451234567890123451234567890123456789012345123456789012345678901234567890
|
||||
Mr Tomas Slanina 29 BratislavaPeter Charles
|
||||
Mr George W. Bush 31 Washington
|
||||
@@ -0,0 +1,5 @@
|
||||
UK21341EAH4121131.11customer1
|
||||
UK21341EAH4221232.11customer2
|
||||
UK21341EAH4321333.11customer3
|
||||
UK21341EAH4421434.11customer4
|
||||
UK21341EAH4521535.11customer5
|
||||
@@ -0,0 +1,5 @@
|
||||
UK21341EAH4121131.11customer1
|
||||
UK21341EAH4221232.11customer2
|
||||
UK21341EAH4321333.11customer3
|
||||
UK21341EAH4421434.11customer4
|
||||
UK21341EAH4521535.11customer5
|
||||
@@ -0,0 +1,9 @@
|
||||
BEGIN
|
||||
UK21341EAH4597898.34customer1
|
||||
UK21341EAH4611218.12customer2
|
||||
END
|
||||
BEGIN
|
||||
UK21341EAH4724512.78customer2
|
||||
UK21341EAH4810809.25customer3
|
||||
UK21341EAH4985423.39customer4
|
||||
END
|
||||
@@ -0,0 +1,20 @@
|
||||
RECORDTYPE1
|
||||
a,b,c
|
||||
d,e
|
||||
END
|
||||
|
||||
RECORDTYPE2
|
||||
1:2:3
|
||||
4
|
||||
5:6
|
||||
END
|
||||
|
||||
PERSON
|
||||
john, william, smith #name
|
||||
55 #age
|
||||
END
|
||||
|
||||
ANIMAL
|
||||
tiger #spieces
|
||||
1 #quantity
|
||||
END
|
||||
@@ -0,0 +1,22 @@
|
||||
FHE;20070215-0001;2007-02-15
|
||||
HEA;0013100345;2007-02-15
|
||||
NCU;Smith;Peter;;T;20014539;F
|
||||
BAD;;Oak Street 31/A;;Small Town;00235;IL;US
|
||||
SAD;Smith, Elizabeth;Elm Street 17;;Some City;30011;FL;United States
|
||||
BIN;VISA;VISA-12345678903
|
||||
LIT;1044391041;37.49;0;0;4.99;2.99;1;45.47
|
||||
LIT;2134776319;221.99;5;0;7.99;2.99;1;221.87
|
||||
SIN;UPS;EXP;DELIVER ONLY ON WEEKDAYS
|
||||
FOT;2;2;267.34
|
||||
HEA;0013100346;2007-02-15
|
||||
BCU;Acme Factory of England;72155919;T
|
||||
BAD;;St. Andrews Road 31;;London;55342;;UK
|
||||
BIN;AMEX;AMEX-72345678903
|
||||
LIT;1044319101;1070.50;5;0;7.99;2.99;12;12335.46
|
||||
LIT;2134727219;21.79;5;0;7.99;2.99;12;380.17
|
||||
LIT;1044339301;79.95;0;5.5;4.99;2.99;4;329.72
|
||||
LIT;2134747319;55.29;10;0;7.99;2.99;6;364.45
|
||||
LIT;1044359501;339.99;10;0;7.99;2.99;2;633.94
|
||||
SIN;FEDX;AMS;
|
||||
FOT;5;36;14043.74
|
||||
FFT;2;14311.08
|
||||
@@ -0,0 +1,51 @@
|
||||
# FHE;ORDER_BATCH_ID(S8-4);ORDER_BATCH_DATE(YYYY-MM-DD)
|
||||
#
|
||||
# HEA;ORDER_ID(N10);ORDER_DATE(YYYY-MM-DD)
|
||||
# [excl] NCU;LAST_NAME(S35);FIRST_NAME(S35);MIDDLE_NAME(S35);REGISTERED(T/F);REG_ID(N8);VIP(T/F)
|
||||
# [excl] BCU;COMPANY_NAME(S50);REG_ID(N8);VIP(T/F)
|
||||
# BAD;ADDRESSEE(S60);ADDR_LINE1(S50);ADDR_LINE2(S50);CITY(S30);ZIP_CODE(S5);STATE(S2);COUNTRY(S50)
|
||||
# [opt] SAD;ADDRESSEE(S60);ADDR_LINE1(S50);ADDR_LINE2(S50);CITY(S30);ZIP_CODE(S5);STATE(S2);COUNTRY(S50)
|
||||
# BIN;PAYMENT_TYPE_ID(S4);PAYMENT_DESC(S30);
|
||||
# LIT;ITEM_ID(N10);PRICE(N8.2);DISCOUNT_PERC(N3.2);DISCOUNT_AMOUNT(N8.2);SHIPPING_PRICE(N8.2);HANDLING_PRICE(N8.2);QUANTITY(N4);TOTAL_PRICE(N8.2)
|
||||
# ... (1 .. n) ...
|
||||
# SIN;SHIPPER_ID(S4);SHIPPING_TYPE_ID(S3);ADDITIONAL_SHIPPING_INFO(S100)
|
||||
# FOT;TOTAL_LINE_ITEMS(N6);TOTAL_ITEMS(N6);TOTAL_PRICE(S8.2)
|
||||
#
|
||||
# FFT;TOTAL_ORDERS(N6);TOTAL_PRICE(N10.2)
|
||||
#
|
||||
# LINE_ID Description LINE MANDATORY OPTIONAL FIELDS*
|
||||
# FHE File Header YES NONE
|
||||
# HEA Record Header YES NONE
|
||||
# NCU Non-Business Customer EXCL WITH BCU MIDDLE_NAME, REG_ID (if REGISTERED is 'F')
|
||||
# BCU Business Customer EXCL WITH NCU NONE
|
||||
# BAD Billing Address YES ADDRESSEE, ADDR_LINE2, STATE (if COUNTRY is not 'United States')
|
||||
# SAD Shipping Address NO ADDR_LINE2, STATE (if COUNTRY is not 'United States')
|
||||
# BIN Billing Info YES NONE
|
||||
# LIT Line Item YES (1 to N lines) DISCOUNT_PERC and DISCOUNT_AMOUNT are mutualy exclusive (only one of them can be non zero)
|
||||
# SIN Shipping Info YES ADDITIONAL_SHIPPING_INFO
|
||||
# FOT Record Footer YES NONE
|
||||
# FFT File Footer YES NONE
|
||||
#
|
||||
# * if field is optional at least empty field must be provided (';;')
|
||||
FHE;20070215-0001;2007-02-15
|
||||
HEA;0013100345;2007-02-15
|
||||
NCU;Smith;Peter;;T;20014539;F
|
||||
BAD;;Oak Street 31/A;;Small Town;00235;IL;US
|
||||
SAD;Smith, Elizabeth;Elm Street 17;;Some City;30011;FL;United States
|
||||
BIN;VISA;VISA-12345678903
|
||||
LIT;1044391041;37.49;0;0;4.99;2.99;1;45.47
|
||||
LIT;2134776319;221.99;5;0;7.99;2.99;1;221.87
|
||||
SIN;UPS;EXP;DELIVER ONLY ON WEEKDAYS
|
||||
FOT;2;2;267.34
|
||||
HEA;0013100346;2007-02-15
|
||||
BCU;Acme Factory of England;72155919;T
|
||||
BAD;;St. Andrews Road 31;;London;55342;;UK
|
||||
BIN;AMEX;AMEX-72345678903
|
||||
LIT;1044319101;1070.50;5;0;7.99;2.99;12;12335.46
|
||||
LIT;2134727619;21.79;5;0;7.99;2.99;12;380.17
|
||||
LIT;1044339101;79.95;0;5.5;4.99;2.99;4;329.72
|
||||
LIT;2134747619;55.29;10;0;7.99;2.99;6;364.45
|
||||
LIT;1044359101;339.99;10;0;7.99;2.99;2;633.94
|
||||
SIN;FEDX;AMS;
|
||||
FOT;5;36;14043.74
|
||||
FFT;2;14311.08
|
||||
@@ -0,0 +1,5 @@
|
||||
UK21341EAH4597898.34customer1
|
||||
UK21341EAH4611218.12customer2
|
||||
UK21341EAH4724512.78customer2
|
||||
UK21341EAH4810819.25customer3
|
||||
UK21341EAH4985423.39customer4
|
||||
@@ -0,0 +1,5 @@
|
||||
UK21341EAH4597898.34customer1
|
||||
UK21341EAH4611218.12customer2
|
||||
UK21341EAH4724512.78customer2
|
||||
UK21341EAH48108109.25customer3
|
||||
UK21341EAH49854123.39customer4
|
||||
@@ -0,0 +1,5 @@
|
||||
UK21341EAH4121131.11customer1
|
||||
UK21341EAH4221232.11customer2
|
||||
UK21341EAH4321333.11customer3
|
||||
UK21341EAH4421434.11customer4
|
||||
UK21341EAH4521535.11customer5
|
||||
@@ -0,0 +1,5 @@
|
||||
UK21341EAH4597898.34customer1
|
||||
UK21341EAH4611218.12customer2
|
||||
UK21341EAH4724512.78customer2
|
||||
UK21341EAH48108109.25customer3
|
||||
UK21341EAH49854123.39customer4
|
||||
@@ -0,0 +1,5 @@
|
||||
UK21341EAH45,978,98.34,customer1
|
||||
UK21341EAH46,112,18.12,customer2
|
||||
UK21341EAH47,245,12.78,customer2
|
||||
UK21341EAH48,108,109.25,customer3
|
||||
UK21341EAH49,854,123.39,customer4
|
||||
@@ -0,0 +1,5 @@
|
||||
UK21341EAH45,978,98.34
|
||||
UK21341EAH46,112,18.12
|
||||
UK21341EAH47,245,12.78
|
||||
UK21341EAH48,108,109.25
|
||||
UK21341EAH49,854,123.39
|
||||
|
@@ -0,0 +1,88 @@
|
||||
<purchase-orders xmlns="http://adsj.accenture.com/purchaseorders"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://adsj.accenture.com/purchaseorders purchaseorders.xsd">
|
||||
<order>
|
||||
<customer>
|
||||
<name>Gladys Kravitz</name>
|
||||
<address>Anytown, PA</address>
|
||||
<age>34</age>
|
||||
<moo>0</moo>
|
||||
<poo>0</poo>
|
||||
</customer>
|
||||
<date>2003-01-07 14:16:00 GMT</date>
|
||||
<lineItems>
|
||||
<lineItem>
|
||||
<description>Burnham's Celestial Handbook, Vol 1</description>
|
||||
<perUnitOunces>5</perUnitOunces>
|
||||
<price>21.79</price>
|
||||
<quantity>2</quantity>
|
||||
</lineItem>
|
||||
<lineItem>
|
||||
<description>Burnham's Celestial Handbook, Vol 2</description>
|
||||
<perUnitOunces>5</perUnitOunces>
|
||||
<price>19.89</price>
|
||||
<quantity>2</quantity>
|
||||
</lineItem>
|
||||
</lineItems>
|
||||
<shipper>
|
||||
<name>ZipShip</name>
|
||||
<perOunceRate>0.74</perOunceRate>
|
||||
</shipper>
|
||||
</order>
|
||||
<order>
|
||||
<customer>
|
||||
<name>John Smith</name>
|
||||
<address>Chicago, IL</address>
|
||||
<age>46</age>
|
||||
<moo>0</moo>
|
||||
<poo>0</poo>
|
||||
</customer>
|
||||
<date>2003-01-07 14:16:02 GMT</date>
|
||||
<lineItems>
|
||||
<lineItem>
|
||||
<description>XmlBeans in Action</description>
|
||||
<perUnitOunces>3</perUnitOunces>
|
||||
<price>41.29</price>
|
||||
<quantity>1</quantity>
|
||||
</lineItem>
|
||||
<lineItem>
|
||||
<description>JSR-173</description>
|
||||
<perUnitOunces>1</perUnitOunces>
|
||||
<price>11.99</price>
|
||||
<quantity>5</quantity>
|
||||
</lineItem>
|
||||
<lineItem>
|
||||
<description>Teach Yourself XML in 21 days</description>
|
||||
<perUnitOunces>1</perUnitOunces>
|
||||
<price>35.49</price>
|
||||
<quantity>1</quantity>
|
||||
</lineItem>
|
||||
</lineItems>
|
||||
<shipper>
|
||||
<name>ZipShip</name>
|
||||
<perOunceRate>0.74</perOunceRate>
|
||||
</shipper>
|
||||
</order>
|
||||
<order>
|
||||
<customer>
|
||||
<name>Peter Newman</name>
|
||||
<address>Cleveland, OH</address>
|
||||
<age>23</age>
|
||||
<moo>0</moo>
|
||||
<poo>0</poo>
|
||||
</customer>
|
||||
<date>2003-01-07 14:16:35 GMT</date>
|
||||
<lineItems>
|
||||
<lineItem>
|
||||
<description>Java 6</description>
|
||||
<perUnitOunces>2</perUnitOunces>
|
||||
<price>12.79</price>
|
||||
<quantity>3</quantity>
|
||||
</lineItem>
|
||||
</lineItems>
|
||||
<shipper>
|
||||
<name>UPS</name>
|
||||
<perOunceRate>0.69</perOunceRate>
|
||||
</shipper>
|
||||
</order>
|
||||
</purchase-orders>
|
||||
@@ -0,0 +1,50 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<xs:schema
|
||||
xmlns:xs="http://www.w3.org/2001/XMLSchema"
|
||||
xmlns:po="http://adsj.accenture.com/purchaseorders"
|
||||
targetNamespace="http://adsj.accenture.com/purchaseorders"
|
||||
elementFormDefault="qualified">
|
||||
<xs:element name="purchase-orders">
|
||||
<xs:complexType>
|
||||
<xs:sequence>
|
||||
<xs:element name="order" type="po:order" minOccurs="0" maxOccurs="unbounded"/>
|
||||
</xs:sequence>
|
||||
</xs:complexType>
|
||||
</xs:element>
|
||||
<xs:complexType name="order">
|
||||
<xs:sequence>
|
||||
<xs:element name="customer" type="po:customer"/>
|
||||
<xs:element name="date" type="xs:string"/>
|
||||
<xs:element name="lineItems" type="po:lineItems"/>
|
||||
<xs:element name="shipper" type="po:shipper" minOccurs="0" maxOccurs="1"/>
|
||||
</xs:sequence>
|
||||
</xs:complexType>
|
||||
<xs:complexType name="customer">
|
||||
<xs:sequence>
|
||||
<xs:element name="name" type="xs:string"/>
|
||||
<xs:element name="address" type="xs:string"/>
|
||||
<xs:element name="age" type="xs:int"/>
|
||||
<xs:element name="moo" type="xs:int" default="100"/>
|
||||
<xs:element name="poo" type="xs:int" default="200"/>
|
||||
</xs:sequence>
|
||||
</xs:complexType>
|
||||
<xs:complexType name="lineItems">
|
||||
<xs:sequence>
|
||||
<xs:element name="lineItem" type="po:lineItem" minOccurs="0" maxOccurs="unbounded"/>
|
||||
</xs:sequence>
|
||||
</xs:complexType>
|
||||
<xs:complexType name="lineItem">
|
||||
<xs:sequence>
|
||||
<xs:element name="description" type="xs:string"/>
|
||||
<xs:element name="perUnitOunces" type="xs:decimal"/>
|
||||
<xs:element name="price" type="xs:decimal"/>
|
||||
<xs:element name="quantity" type="xs:integer"/>
|
||||
</xs:sequence>
|
||||
</xs:complexType>
|
||||
<xs:complexType name="shipper">
|
||||
<xs:sequence>
|
||||
<xs:element name="name" type="xs:string"/>
|
||||
<xs:element name="perOunceRate" type="xs:decimal"/>
|
||||
</xs:sequence>
|
||||
</xs:complexType>
|
||||
</xs:schema>
|
||||
@@ -0,0 +1 @@
|
||||
<?xml version='1.0' encoding='utf-8'?><purchaseOrders xsi:schemaLocation="http://adsj.accenture.com/purchaseorders purchaseorders.xsd" xmlns="http://adsj.accenture.com/purchaseorders" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><order><customer><name>Gladys Kravitz</name><address>Anytown, PA</address><age>34</age><moo>0</moo><poo>0</poo></customer><date>2003-01-07 14:16:00.0 GMT</date><lineItems><lineItem><description>Burnham's Celestial Handbook, Vol 1</description><perUnitOunces>5.0</perUnitOunces><price>21.79</price><quantity>2</quantity></lineItem><lineItem><description>Burnham's Celestial Handbook, Vol 2</description><perUnitOunces>5.0</perUnitOunces><price>19.89</price><quantity>2</quantity></lineItem></lineItems></order><order><customer><name>John Smith</name><address>Chicago, IL</address><age>46</age><moo>0</moo><poo>0</poo></customer><date>2003-01-07 14:16:02.0 GMT</date><lineItems><lineItem><description>XmlBeans in Action</description><perUnitOunces>3.0</perUnitOunces><price>41.29</price><quantity>1</quantity></lineItem><lineItem><description>JSR-173</description><perUnitOunces>1.0</perUnitOunces><price>11.99</price><quantity>5</quantity></lineItem><lineItem><description>Teach Yourself XML in 21 days</description><perUnitOunces>1.0</perUnitOunces><price>35.49</price><quantity>1</quantity></lineItem></lineItems></order><order><customer><name>Peter Newman</name><address>Cleveland, OH</address><age>23</age><moo>0</moo><poo>0</poo></customer><date>2003-01-07 14:16:35.0 GMT</date><lineItems><lineItem><description>Java 6</description><perUnitOunces>2.0</perUnitOunces><price>12.79</price><quantity>3</quantity></lineItem></lineItems></order></purchaseOrders>
|
||||
86
samples/src/main/resources/jobs/adhocLoopJob.xml
Normal file
86
samples/src/main/resources/jobs/adhocLoopJob.xml
Normal file
@@ -0,0 +1,86 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:aop="http://www.springframework.org/schema/aop"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans
|
||||
http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
|
||||
http://www.springframework.org/schema/aop
|
||||
http://www.springframework.org/schema/aop/spring-aop-2.0.xsd">
|
||||
|
||||
<!-- The module used in this job will run in an infinite loop. This is useful for testing graceful shutdown from
|
||||
multiple environments. -->
|
||||
|
||||
<import resource="../simple-container-definition.xml" />
|
||||
|
||||
<bean
|
||||
class="org.springframework.batch.execution.configuration.JobConfigurationRegistryBeanPostProcessor">
|
||||
<property name="jobConfigurationRegistry" ref="jobConfigurationRegistry" />
|
||||
</bean>
|
||||
|
||||
<bean id="batchContainerOverride" parent="batchContainer">
|
||||
<property name="jobExecutor">
|
||||
<bean parent="jobExecutor">
|
||||
<property name="stepExecutorResolver">
|
||||
<bean
|
||||
class="org.springframework.batch.execution.step.DefaultStepExecutorFactory">
|
||||
<property name="stepExecutorName" value="notifyingStepExecutor" />
|
||||
</bean>
|
||||
</property>
|
||||
</bean>
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
<bean id="batchBootstrap"
|
||||
class="org.springframework.batch.execution.bootstrap.TaskExecutorJobLauncher">
|
||||
<property name="batchContainer" ref="batchContainerOverride" />
|
||||
<property name="taskExecutor">
|
||||
<bean class="org.springframework.core.task.SimpleAsyncTaskExecutor" />
|
||||
</property>
|
||||
<property name="autoStart" value="false" />
|
||||
</bean>
|
||||
|
||||
<bean id="jobConfiguration" parent="simpleJob">
|
||||
<property name="steps">
|
||||
<bean id="step1" parent="simpleStep">
|
||||
<constructor-arg>
|
||||
<bean id="module" class="org.springframework.batch.sample.module.InfiniteLoopTasklet" scope="step">
|
||||
<aop:scoped-proxy />
|
||||
</bean>
|
||||
</constructor-arg>
|
||||
<property name="commitInterval" value="2" />
|
||||
</bean>
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
<bean id="notifyingStepExecutor" parent="stepExecutor" scope="prototype">
|
||||
<property name="stepOperations">
|
||||
<bean class="org.springframework.batch.repeat.support.RepeatTemplate">
|
||||
<property name="interceptor">
|
||||
<bean
|
||||
class="org.springframework.batch.repeat.interceptor.ApplicationEventPublisherRepeatInterceptor" />
|
||||
</property>
|
||||
</bean>
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
<bean class="org.springframework.jmx.export.MBeanExporter">
|
||||
<property name="beans">
|
||||
<map>
|
||||
<entry key="spring:service=lifecycle,bean=batchBootstrap">
|
||||
<ref bean="batchBootstrap" />
|
||||
</entry>
|
||||
</map>
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
<bean id="logAdvice" class="org.springframework.batch.sample.advice.MethodExecutionLogAdvice" />
|
||||
|
||||
<aop:config>
|
||||
<aop:aspect ref="logAdvice">
|
||||
|
||||
<aop:after pointcut="execution( * org.springframework.batch.sample..InfiniteLoopTasklet+.execute(..))"
|
||||
method="doBasicLogging" />
|
||||
|
||||
</aop:aspect>
|
||||
</aop:config>
|
||||
|
||||
</beans>
|
||||
133
samples/src/main/resources/jobs/beanWrapperMapperSampleJob.xml
Normal file
133
samples/src/main/resources/jobs/beanWrapperMapperSampleJob.xml
Normal file
@@ -0,0 +1,133 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:aop="http://www.springframework.org/schema/aop"
|
||||
xmlns:tx="http://www.springframework.org/schema/tx" xmlns:p="http://www.springframework.org/schema/p"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="
|
||||
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
|
||||
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd
|
||||
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd">
|
||||
|
||||
<import resource="../simple-container-definition.xml" />
|
||||
|
||||
<bean class="org.springframework.batch.execution.configuration.JobConfigurationRegistryBeanPostProcessor">
|
||||
<property name="jobConfigurationRegistry" ref="jobConfigurationRegistry"/>
|
||||
</bean>
|
||||
|
||||
<bean id="jobConfiguration" parent="simpleJob" p:name="beanWrapperMapperSampleJob">
|
||||
<property name="steps">
|
||||
<list>
|
||||
<bean id="step1" parent="simpleStep">
|
||||
<constructor-arg>
|
||||
<bean
|
||||
class="org.springframework.batch.execution.tasklet.RestartableItemProviderTasklet">
|
||||
<property name="itemProvider">
|
||||
<bean
|
||||
class="org.springframework.batch.execution.tasklet.support.DefaultFlatFileItemProvider">
|
||||
<property name="source" ref="fileInputTemplate" />
|
||||
<property name="mapper" ref="fieldSetMapper" />
|
||||
<property name="validator" ref="fixedValidator" />
|
||||
</bean>
|
||||
</property>
|
||||
<property name="itemProcessor">
|
||||
<bean class="org.springframework.batch.sample.module.process.TradeProcessor">
|
||||
<property name="writer" ref="tradeDao" />
|
||||
</bean>
|
||||
</property>
|
||||
</bean>
|
||||
</constructor-arg>
|
||||
</bean>
|
||||
<bean id="step2" parent="simpleStep">
|
||||
<constructor-arg>
|
||||
<bean
|
||||
class="org.springframework.batch.execution.tasklet.RestartableItemProviderTasklet">
|
||||
<property name="itemProvider">
|
||||
<bean
|
||||
class="org.springframework.batch.execution.tasklet.support.DefaultFlatFileItemProvider">
|
||||
<property name="source" ref="fileInputTemplate2" />
|
||||
<property name="mapper" ref="fieldSetMapper2" />
|
||||
</bean>
|
||||
</property>
|
||||
<property name="itemProcessor">
|
||||
<bean class="org.springframework.batch.sample.module.process.PersonProcessor" />
|
||||
</property>
|
||||
</bean>
|
||||
</constructor-arg>
|
||||
</bean>
|
||||
|
||||
</list>
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
<!-- INFRASTRUCTURE SETUP -->
|
||||
|
||||
<bean id="fileInputTemplate" class="org.springframework.batch.io.file.support.DefaultFlatFileInputSource">
|
||||
<property name="resource" ref="fileLocator" />
|
||||
<property name="tokenizer" ref="fixedFileDescriptor" />
|
||||
</bean>
|
||||
|
||||
<bean id="fileInputTemplate2" class="org.springframework.batch.io.file.support.DefaultFlatFileInputSource">
|
||||
<property name="resource" ref="fileLocator2" />
|
||||
<property name="tokenizer" ref="fixedFileDescriptor2" />
|
||||
<!-- <property name="validator" ref="fixedValidator" />-->
|
||||
</bean>
|
||||
|
||||
<bean id="fixedFileDescriptor"
|
||||
class="org.springframework.batch.io.file.support.transform.FixedLengthTokenizer">
|
||||
<property name="names" value="ISIN,Quantity,price, CUSTOMER" />
|
||||
<property name="lengths" value="12, 3, 5, 9" />
|
||||
</bean>
|
||||
|
||||
<bean id="fixedFileDescriptor2"
|
||||
class="org.springframework.batch.io.file.support.transform.FixedLengthTokenizer">
|
||||
<property name="names" value="Title, FirstName, LastName, Age, Address.AddrLine1, children[0].name, children[1].name" />
|
||||
<property name="lengths" value="5, 15, 20, 5, 10, 10, 10" />
|
||||
</bean>
|
||||
|
||||
<bean id="fixedValidator" class="org.springframework.batch.item.validator.SpringValidator">
|
||||
<property name="validator">
|
||||
<bean id="tradeValidator" class="org.springmodules.validation.valang.ValangValidator">
|
||||
<property name="valang">
|
||||
<value>
|
||||
<![CDATA[
|
||||
{ isin : length(?) < 13 : 'ISIN too long' : 'isin_length' : 12}
|
||||
]]>
|
||||
</value>
|
||||
</property>
|
||||
</bean>
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
<bean id="tradeDao" class="org.springframework.batch.sample.dao.JdbcTradeWriter">
|
||||
<property name="jdbcTemplate" ref="jdbcTemplate" />
|
||||
<property name="incrementer">
|
||||
<bean parent="incrementerParent">
|
||||
<property name="incrementerName" value="TRADE_SEQ" />
|
||||
</bean>
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
|
||||
|
||||
<bean id="fileLocator" class="org.springframework.core.io.ClassPathResource">
|
||||
<constructor-arg type="java.lang.String"
|
||||
value="data/beanWrapperMapperSampleJob/input/20070122.teststream.ImportTradeDataStep.txt" />
|
||||
</bean>
|
||||
|
||||
<bean id="fileLocator2" class="org.springframework.core.io.ClassPathResource">
|
||||
<constructor-arg type="java.lang.String"
|
||||
value="data/beanWrapperMapperSampleJob/input/20070122.teststream.ImportPersonDataStep.txt" />
|
||||
</bean>
|
||||
|
||||
<bean id="fieldSetMapper" class="org.springframework.batch.io.file.support.mapping.BeanWrapperFieldSetMapper">
|
||||
<property name="prototypeBeanName" value="trade"/>
|
||||
</bean>
|
||||
|
||||
<bean id="fieldSetMapper2" class="org.springframework.batch.io.file.support.mapping.BeanWrapperFieldSetMapper">
|
||||
<property name="prototypeBeanName" value="person"/>
|
||||
</bean>
|
||||
|
||||
<bean id="trade" class="org.springframework.batch.sample.domain.Trade" scope="prototype"/>
|
||||
|
||||
<bean id="person" class="org.springframework.batch.sample.domain.Person" scope="prototype"/>
|
||||
|
||||
</beans>
|
||||
103
samples/src/main/resources/jobs/compositeProcessorSample.xml
Normal file
103
samples/src/main/resources/jobs/compositeProcessorSample.xml
Normal file
@@ -0,0 +1,103 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:aop="http://www.springframework.org/schema/aop"
|
||||
xmlns:tx="http://www.springframework.org/schema/tx" xmlns:p="http://www.springframework.org/schema/p"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="
|
||||
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
|
||||
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd
|
||||
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd">
|
||||
|
||||
<import resource="../simple-container-definition.xml" />
|
||||
|
||||
<bean class="org.springframework.batch.execution.configuration.JobConfigurationRegistryBeanPostProcessor">
|
||||
<property name="jobConfigurationRegistry" ref="jobConfigurationRegistry"/>
|
||||
</bean>
|
||||
|
||||
<bean id="jobConfiguration" parent="simpleJob">
|
||||
<property name="name" value="parallelProcessorSample" />
|
||||
<property name="steps">
|
||||
<bean id="step1" parent="simpleStep">
|
||||
<constructor-arg>
|
||||
<bean
|
||||
class="org.springframework.batch.execution.tasklet.RestartableItemProviderTasklet">
|
||||
<property name="itemProvider">
|
||||
<bean
|
||||
class="org.springframework.batch.execution.tasklet.support.DefaultFlatFileItemProvider">
|
||||
<property name="source" ref="fileInputTemplate" />
|
||||
<property name="mapper" ref="fieldSetMapper" />
|
||||
<property name="validator" ref="fixedValidator" />
|
||||
</bean>
|
||||
</property>
|
||||
<property name="itemProcessor">
|
||||
<bean class="org.springframework.batch.execution.tasklet.support.CompositeItemProcessor" >
|
||||
<property name="itemProcessors" >
|
||||
<list>
|
||||
<bean class="org.springframework.batch.sample.module.process.TradeProcessor">
|
||||
<property name="writer" ref="tradeDao" />
|
||||
</bean>
|
||||
|
||||
<bean class="org.springframework.batch.execution.tasklet.support.OutputSourceItemProcessor">
|
||||
<property name="outputSource" ref="flatFileOutputSource" />
|
||||
</bean>
|
||||
</list>
|
||||
</property>
|
||||
</bean>
|
||||
</property>
|
||||
</bean>
|
||||
</constructor-arg>
|
||||
</bean>
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
<!-- INFRASTRUCTURE SETUP -->
|
||||
|
||||
<bean id="fileInputTemplate" class="org.springframework.batch.io.file.support.DefaultFlatFileInputSource">
|
||||
<property name="resource" ref="fileLocator" />
|
||||
<property name="tokenizer" ref="fixedFileDescriptor" />
|
||||
</bean>
|
||||
|
||||
<bean id="fixedFileDescriptor" class="org.springframework.batch.io.file.support.transform.FixedLengthTokenizer">
|
||||
<property name="names" value="ISIN, Quantity, Price, Customer" />
|
||||
<property name="lengths" value="12, 3, 5, 9" />
|
||||
</bean>
|
||||
|
||||
<bean id="fixedValidator" class="org.springframework.batch.item.validator.SpringValidator">
|
||||
<property name="validator">
|
||||
<bean id="tradeValidator" class="org.springmodules.validation.valang.ValangValidator">
|
||||
<property name="valang">
|
||||
<value>
|
||||
<![CDATA[
|
||||
{ isin : length(?) < 13 : 'ISIN too long' : 'isin_length' : 12}
|
||||
]]>
|
||||
</value>
|
||||
</property>
|
||||
</bean>
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
<bean id="tradeDao" class="org.springframework.batch.sample.dao.JdbcTradeWriter">
|
||||
<property name="jdbcTemplate" ref="jdbcTemplate" />
|
||||
<property name="incrementer">
|
||||
<bean parent="incrementerParent">
|
||||
<property name="incrementerName" value="TRADE_SEQ" />
|
||||
</bean>
|
||||
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
<bean class="org.springframework.batch.io.file.support.FlatFileOutputSource" id="flatFileOutputSource">
|
||||
<property name="resource" ref="customerFileLocator" />
|
||||
</bean>
|
||||
|
||||
<bean id="customerFileLocator" class="org.springframework.core.io.FileSystemResource">
|
||||
<constructor-arg type="java.lang.String" value="20070122.testStream.ParallelCustomerReportStep.TEMP.txt" />
|
||||
</bean>
|
||||
|
||||
<bean id="fileLocator" class="org.springframework.core.io.ClassPathResource">
|
||||
<constructor-arg type="java.lang.String"
|
||||
value="data/fixedLengthImportJob/input/20070122.teststream.ImportTradeDataStep.txt" />
|
||||
</bean>
|
||||
|
||||
<bean id="fieldSetMapper" class="org.springframework.batch.sample.mapping.TradeFieldSetMapper" />
|
||||
|
||||
</beans>
|
||||
87
samples/src/main/resources/jobs/fixedLengthImportJob.xml
Normal file
87
samples/src/main/resources/jobs/fixedLengthImportJob.xml
Normal file
@@ -0,0 +1,87 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:aop="http://www.springframework.org/schema/aop"
|
||||
xmlns:tx="http://www.springframework.org/schema/tx" xmlns:p="http://www.springframework.org/schema/p"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="
|
||||
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
|
||||
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd
|
||||
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd">
|
||||
|
||||
<import resource="../simple-container-definition.xml" />
|
||||
|
||||
<bean class="org.springframework.batch.execution.configuration.JobConfigurationRegistryBeanPostProcessor">
|
||||
<property name="jobConfigurationRegistry" ref="jobConfigurationRegistry"/>
|
||||
</bean>
|
||||
|
||||
<bean id="jobConfiguration" parent="simpleJob">
|
||||
<property name="name" value="fixedLengthImportJob" />
|
||||
<property name="steps">
|
||||
<bean id="step1" parent="simpleStep">
|
||||
<constructor-arg>
|
||||
<bean
|
||||
class="org.springframework.batch.execution.tasklet.RestartableItemProviderTasklet">
|
||||
<property name="itemProvider">
|
||||
<bean
|
||||
class="org.springframework.batch.execution.tasklet.support.DefaultFlatFileItemProvider">
|
||||
<property name="source" ref="fileInputTemplate" />
|
||||
<property name="mapper" ref="fieldSetMapper" />
|
||||
<property name="validator" ref="fixedValidator" />
|
||||
</bean>
|
||||
</property>
|
||||
<property name="itemProcessor">
|
||||
<bean class="org.springframework.batch.sample.module.process.TradeProcessor">
|
||||
<property name="writer" ref="tradeDao" />
|
||||
</bean>
|
||||
</property>
|
||||
</bean>
|
||||
</constructor-arg>
|
||||
</bean>
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
<!-- INFRASTRUCTURE SETUP -->
|
||||
|
||||
<bean id="fileInputTemplate" class="org.springframework.batch.io.file.support.DefaultFlatFileInputSource">
|
||||
<property name="resource" ref="fileLocator" />
|
||||
<property name="tokenizer" ref="fixedFileDescriptor" />
|
||||
</bean>
|
||||
|
||||
<bean id="fixedFileDescriptor" class="org.springframework.batch.io.file.support.transform.FixedLengthTokenizer">
|
||||
<property name="names" value="ISIN, Quantity, Price, Customer" />
|
||||
<property name="lengths" value="12, 3, 5, 9" />
|
||||
</bean>
|
||||
|
||||
<bean id="fixedValidator" class="org.springframework.batch.item.validator.SpringValidator">
|
||||
<property name="validator">
|
||||
<bean id="tradeValidator" class="org.springmodules.validation.valang.ValangValidator">
|
||||
<property name="valang">
|
||||
<value>
|
||||
<![CDATA[
|
||||
{ isin : length(?) < 13 : 'ISIN too long' : 'isin_length' : 12}
|
||||
]]>
|
||||
</value>
|
||||
</property>
|
||||
</bean>
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
<bean id="tradeDao" class="org.springframework.batch.sample.dao.JdbcTradeWriter">
|
||||
<property name="jdbcTemplate" ref="jdbcTemplate" />
|
||||
<property name="incrementer">
|
||||
<bean parent="incrementerParent">
|
||||
<property name="incrementerName" value="TRADE_SEQ" />
|
||||
</bean>
|
||||
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
|
||||
|
||||
<bean id="fileLocator" class="org.springframework.core.io.ClassPathResource">
|
||||
<constructor-arg type="java.lang.String"
|
||||
value="data/fixedLengthImportJob/input/20070122.teststream.ImportTradeDataStep.txt" />
|
||||
</bean>
|
||||
|
||||
<bean id="fieldSetMapper" class="org.springframework.batch.sample.mapping.TradeFieldSetMapper" />
|
||||
|
||||
</beans>
|
||||
29
samples/src/main/resources/jobs/infiniteLoopJob.xml
Normal file
29
samples/src/main/resources/jobs/infiniteLoopJob.xml
Normal file
@@ -0,0 +1,29 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:aop="http://www.springframework.org/schema/aop"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans
|
||||
http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
|
||||
http://www.springframework.org/schema/aop
|
||||
http://www.springframework.org/schema/aop/spring-aop-2.0.xsd">
|
||||
|
||||
<!-- The module used in this job will run in an infinite loop. This is useful for testing graceful shutdown from
|
||||
multiple environments. -->
|
||||
|
||||
<import resource="../simple-container-definition.xml" />
|
||||
|
||||
<bean class="org.springframework.batch.execution.configuration.JobConfigurationRegistryBeanPostProcessor">
|
||||
<property name="jobConfigurationRegistry" ref="jobConfigurationRegistry"/>
|
||||
</bean>
|
||||
|
||||
<bean id="jobConfiguration" parent="simpleJob">
|
||||
<property name="steps">
|
||||
<bean id="step1" parent="simpleStep">
|
||||
<constructor-arg>
|
||||
<bean id="module" class="org.springframework.batch.sample.module.InfiniteLoopTasklet"/>
|
||||
</constructor-arg>
|
||||
<property name="commitInterval" value="2" />
|
||||
</bean>
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
</beans>
|
||||
78
samples/src/main/resources/jobs/multilineJob.xml
Normal file
78
samples/src/main/resources/jobs/multilineJob.xml
Normal file
@@ -0,0 +1,78 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:aop="http://www.springframework.org/schema/aop"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans
|
||||
http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
|
||||
http://www.springframework.org/schema/aop
|
||||
http://www.springframework.org/schema/aop/spring-aop-2.0.xsd">
|
||||
|
||||
<import resource="../simple-container-definition.xml" />
|
||||
|
||||
<bean class="org.springframework.batch.execution.configuration.JobConfigurationRegistryBeanPostProcessor">
|
||||
<property name="jobConfigurationRegistry" ref="jobConfigurationRegistry"/>
|
||||
</bean>
|
||||
|
||||
<bean id="jobConfiguration" parent="simpleJob">
|
||||
<property name="name" value="multilineJob" />
|
||||
<property name="steps">
|
||||
<bean id="step1" parent="simpleStep">
|
||||
<constructor-arg>
|
||||
<bean
|
||||
class="org.springframework.batch.execution.tasklet.RestartableItemProviderTasklet">
|
||||
<property name="itemProvider">
|
||||
<bean class="org.springframework.batch.sample.module.CollectionItemProvider">
|
||||
<property name="inputSource" ref="fileInputTemplate" />
|
||||
<property name="fieldSetMapper" ref="tradeLineMapper" />
|
||||
</bean>
|
||||
</property>
|
||||
<property name="itemProcessor">
|
||||
<bean class="org.springframework.batch.sample.module.process.DefaultFlatFileProcessor">
|
||||
<property name="flatFileOutputSource">
|
||||
<bean class="org.springframework.batch.io.file.support.FlatFileOutputSource" >
|
||||
<property name="resource" value="file:20070122.testStream.multilineStep.txt" />
|
||||
</bean>
|
||||
</property>
|
||||
</bean>
|
||||
</property>
|
||||
</bean>
|
||||
</constructor-arg>
|
||||
</bean>
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
<bean id="fileInputTemplate" class="org.springframework.batch.io.file.support.DefaultFlatFileInputSource">
|
||||
<property name="resource" value="classpath:data/multilineJob/input/20070122.teststream.multilineStep.txt" />
|
||||
<property name="tokenizer" ref="fixedFileDescriptor" />
|
||||
<!-- <property name="validator" ref="fixedValidator" /> -->
|
||||
</bean>
|
||||
|
||||
<bean id="tradeLineMapper" class="org.springframework.batch.sample.mapping.TradeFieldSetMapper" />
|
||||
|
||||
<bean id="fixedFileDescriptor"
|
||||
class="org.springframework.batch.io.file.support.transform.PrefixMatchingCompositeLineTokenizer">
|
||||
<property name="tokenizers">
|
||||
<map>
|
||||
<entry key="BEGIN" value-ref="beginRecordDescriptor" />
|
||||
<entry key="END" value-ref="endRecordDescriptor" />
|
||||
<entry key="" value-ref="tradeRecordDescriptor" />
|
||||
</map>
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
<bean id="beginRecordDescriptor"
|
||||
class="org.springframework.batch.io.file.support.transform.FixedLengthTokenizer">
|
||||
<property name="lengths" value="5" />
|
||||
</bean>
|
||||
|
||||
<bean id="endRecordDescriptor"
|
||||
class="org.springframework.batch.io.file.support.transform.FixedLengthTokenizer">
|
||||
<property name="lengths" value="3" />
|
||||
</bean>
|
||||
|
||||
<bean id="tradeRecordDescriptor"
|
||||
class="org.springframework.batch.io.file.support.transform.FixedLengthTokenizer">
|
||||
<property name="names" value="ISIN,Quantity,Price,Customer" />
|
||||
<property name="lengths" value="12,3,5,9" />
|
||||
</bean>
|
||||
|
||||
</beans>
|
||||
@@ -0,0 +1,71 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans
|
||||
http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">
|
||||
|
||||
<bean id="orderFileDescriptor"
|
||||
class="org.springframework.batch.io.file.support.transform.PrefixMatchingCompositeLineTokenizer">
|
||||
<property name="tokenizers">
|
||||
<map>
|
||||
<entry key="HEA" value-ref="headerRecordDescriptor" />
|
||||
<entry key="FOT" value-ref="footerRecordDescriptor" />
|
||||
<entry key="BCU" value-ref="businessCustomerLineDescriptor" />
|
||||
<entry key="NCU" value-ref="customerLineDescriptor" />
|
||||
<entry key="BAD" value-ref="billingAddressLineDescriptor" />
|
||||
<entry key="SAD" value-ref="shippingAddressLineDescriptor" />
|
||||
<entry key="BIN" value-ref="billingLineDescriptor" />
|
||||
<entry key="SIN" value-ref="shippingLineDescriptor" />
|
||||
<entry key="LIT" value-ref="itemLineDescriptor" />
|
||||
<entry key="" value-ref="defaultLineDescriptor" />
|
||||
</map>
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
<bean id="defaultLineDescriptor"
|
||||
class="org.springframework.batch.io.file.support.transform.FixedLengthTokenizer">
|
||||
<property name="lengths" value="120"/>
|
||||
</bean>
|
||||
|
||||
<bean id="parentLineDescriptor" abstract="true"
|
||||
class="org.springframework.batch.io.file.support.transform.DelimitedLineTokenizer">
|
||||
<property name="delimiter" value=";"/>
|
||||
</bean>
|
||||
|
||||
<bean id="headerRecordDescriptor" parent="parentLineDescriptor">
|
||||
<property name="names" value="LINE_ID,ORDER_ID,ORDER_DATE" />
|
||||
</bean>
|
||||
|
||||
<bean id="footerRecordDescriptor" parent="parentLineDescriptor">
|
||||
<property name="names" value="LINE_ID,TOTAL_LINE_ITEMS,TOTAL_ITEMS,TOTAL_PRICE" />
|
||||
</bean>
|
||||
|
||||
<bean id="businessCustomerLineDescriptor" parent="parentLineDescriptor">
|
||||
<property name="names" value="LINE_ID,COMPANY_NAME,REG_ID,VIP" />
|
||||
</bean>
|
||||
|
||||
<bean id="customerLineDescriptor" parent="parentLineDescriptor">
|
||||
<property name="names" value="LINE_ID,LAST_NAME,FIRST_NAME,MIDDLE_NAME,REGISTERED,REG_ID,VIP" />
|
||||
</bean>
|
||||
|
||||
<bean id="billingAddressLineDescriptor" parent="parentLineDescriptor">
|
||||
<property name="names" value="LINE_ID,ADDRESSEE,ADDR_LINE1,ADDR_LINE2,CITY,ZIP_CODE,STATE,COUNTRY" />
|
||||
</bean>
|
||||
|
||||
<bean id="shippingAddressLineDescriptor" parent="parentLineDescriptor">
|
||||
<property name="names" value="LINE_ID,ADDRESSEE,ADDR_LINE1,ADDR_LINE2,CITY,ZIP_CODE,STATE,COUNTRY" />
|
||||
</bean>
|
||||
|
||||
<bean id="billingLineDescriptor" parent="parentLineDescriptor">
|
||||
<property name="names" value="LINE_ID,PAYMENT_TYPE_ID,PAYMENT_DESC" />
|
||||
</bean>
|
||||
|
||||
<bean id="shippingLineDescriptor" parent="parentLineDescriptor">
|
||||
<property name="names" value="LINE_ID,SHIPPER_ID,SHIPPING_TYPE_ID,ADDITIONAL_SHIPPING_INFO" />
|
||||
</bean>
|
||||
|
||||
<bean id="itemLineDescriptor" parent="parentLineDescriptor">
|
||||
<property name="names"
|
||||
value="LINE_ID,ITEM_ID,PRICE,DISCOUNT_PERC,DISCOUNT_AMOUNT,SHIPPING_PRICE,HANDLING_PRICE,QUANTITY,TOTAL_PRICE" />
|
||||
</bean>
|
||||
|
||||
</beans>
|
||||
21
samples/src/main/resources/jobs/multilineOrderIo.xml
Normal file
21
samples/src/main/resources/jobs/multilineOrderIo.xml
Normal file
@@ -0,0 +1,21 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:p="http://www.springframework.org/schema/p"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans
|
||||
http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">
|
||||
|
||||
<bean id="fileInputTemplate" class="org.springframework.batch.io.file.support.DefaultFlatFileInputSource">
|
||||
<property name="resource" ref="fileInputLocator" />
|
||||
<property name="tokenizer" ref="orderFileDescriptor" />
|
||||
</bean>
|
||||
|
||||
<bean id="flatFileOutputSource" class="org.springframework.batch.io.file.support.FlatFileOutputSource">
|
||||
<property name="resource" ref="fileOutputLocator" />
|
||||
</bean>
|
||||
|
||||
<bean id="delimitedLineAggregator" class="org.springframework.batch.io.file.support.transform.DelimitedLineTokenizer" />
|
||||
|
||||
<bean id="fixedLineAggregator" class="org.springframework.batch.io.file.support.transform.FixedLengthLineAggregator" />
|
||||
|
||||
</beans>
|
||||
152
samples/src/main/resources/jobs/multilineOrderJob.xml
Normal file
152
samples/src/main/resources/jobs/multilineOrderJob.xml
Normal file
@@ -0,0 +1,152 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:aop="http://www.springframework.org/schema/aop"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans
|
||||
http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
|
||||
http://www.springframework.org/schema/aop
|
||||
http://www.springframework.org/schema/aop/spring-aop-2.0.xsd">
|
||||
|
||||
<import resource="multilineOrderInputDescriptors.xml" />
|
||||
<import resource="multilineOrderOutputDescriptors.xml" />
|
||||
<import resource="multilineOrderIo.xml" />
|
||||
<import resource="../simple-container-definition.xml" />
|
||||
|
||||
<bean
|
||||
class="org.springframework.batch.execution.configuration.JobConfigurationRegistryBeanPostProcessor">
|
||||
<property name="jobConfigurationRegistry" ref="jobConfigurationRegistry" />
|
||||
</bean>
|
||||
|
||||
<bean id="jobConfiguration" parent="simpleJob">
|
||||
<property name="name" value="multilineOrderJob" />
|
||||
<property name="steps">
|
||||
<bean id="step1" parent="simpleStep">
|
||||
<constructor-arg>
|
||||
<bean
|
||||
class="org.springframework.batch.execution.tasklet.RestartableItemProviderTasklet">
|
||||
<property name="itemProvider">
|
||||
<bean class="org.springframework.batch.sample.module.OrderItemProvider">
|
||||
<property name="inputSource" ref="fileInputTemplate" />
|
||||
<property name="headerMapper" ref="headerFieldSetMapper" />
|
||||
<property name="customerMapper" ref="customerFieldSetMapper" />
|
||||
<property name="addressMapper" ref="addressFieldSetMapper" />
|
||||
<property name="billingMapper" ref="billingFieldSetMapper" />
|
||||
<property name="itemMapper" ref="orderItemFieldSetMapper" />
|
||||
<property name="shippingMapper" ref="shippingFieldSetMapper" />
|
||||
<property name="validator" ref="validator" />
|
||||
</bean>
|
||||
</property>
|
||||
<property name="itemProcessor">
|
||||
<bean class="org.springframework.batch.sample.module.process.OrderProcessor">
|
||||
<property name="writer">
|
||||
<bean class="org.springframework.batch.sample.dao.FlatFileOrderWriter">
|
||||
<property name="outputSource" ref="flatFileOutputSource" />
|
||||
<property name="converter">
|
||||
<bean class="org.springframework.batch.sample.dao.OrderConverter">
|
||||
<property name="aggregators" ref="outputDescriptors" />
|
||||
</bean>
|
||||
</property>
|
||||
</bean>
|
||||
</property>
|
||||
</bean>
|
||||
</property>
|
||||
</bean>
|
||||
</constructor-arg>
|
||||
</bean>
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
<bean id="headerFieldSetMapper" class="org.springframework.batch.sample.mapping.HeaderFieldSetMapper" />
|
||||
<bean id="customerFieldSetMapper" class="org.springframework.batch.sample.mapping.CustomerFieldSetMapper" />
|
||||
<bean id="addressFieldSetMapper" class="org.springframework.batch.sample.mapping.AddressFieldSetMapper" />
|
||||
<bean id="billingFieldSetMapper" class="org.springframework.batch.sample.mapping.BillingFieldSetMapper" />
|
||||
<bean id="orderItemFieldSetMapper" class="org.springframework.batch.sample.mapping.OrderItemFieldSetMapper" />
|
||||
<bean id="shippingFieldSetMapper" class="org.springframework.batch.sample.mapping.ShippingFieldSetMapper" />
|
||||
|
||||
<bean id="validator" class="org.springframework.batch.item.validator.SpringValidator">
|
||||
<property name="validator">
|
||||
<bean id="orderValidator" class="org.springmodules.validation.valang.ValangValidator">
|
||||
<property name="valang">
|
||||
<value>
|
||||
<![CDATA[
|
||||
{ orderId : ? > 0 AND ? <= 9999999999 : 'Incorrect order ID' : 'error.order.id' }
|
||||
{ orderDate : isFutureDate(?) = FALSE : 'Future date is not allowed' : 'error.order.date.future' }
|
||||
{ totalLines : ? = size(lineItems) : 'Bad count of order lines' : 'error.order.lines.badcount'}
|
||||
|
||||
{ customer.registered : customer.businessCustomer = FALSE OR ? = TRUE : 'Business customer must be registered' : 'error.customer.registration'}
|
||||
{ customer.companyName : customer.businessCustomer = FALSE OR ? HAS TEXT : 'Company name for business customer is mandatory' : 'error.customer.companyname'}
|
||||
{ customer.firstName : customer.businessCustomer = TRUE OR ? HAS TEXT : 'Firstname for non-business customer is mandatory' : 'error.customer.firstname'}
|
||||
{ customer.lastName : customer.businessCustomer = TRUE OR ? HAS TEXT : 'Lastname name for non-business customer is mandatory' : 'error.customer.lastname'}
|
||||
{ customer.registrationId : customer.registered = FALSE OR (? > 0 AND ? < 99999999) : 'Incorrect registration ID' : 'error.customer.registrationid'}
|
||||
|
||||
{ billingAddress.addressee : ? HAS NO TEXT OR length(?) <= 60 : 'Maximum length for Addressee is 60 characters' : 'error.baddress.addresse.length'}
|
||||
{ billingAddress.addrLine1 : ? HAS TEXT AND length(?) <= 50 : 'Address line1 is mandatory and maximum length for address line1 is 50 characters' : 'error.baddress.addrline1.length'}
|
||||
{ billingAddress.addrLine2 : ? HAS NO TEXT OR length(?) <= 50 : 'Maximum length for address line2 is 50 characters' : 'error.baddress.addrline2.length'}
|
||||
{ billingAddress.city : ? HAS TEXT AND length(?) <= 30 : 'City is mandatory and maximum length for city is 30 characters' : 'error.baddress.city.length'}
|
||||
{ billingAddress.zipCode : ? HAS TEXT AND length(?) <= 50 : 'Zipcode is mandatory and maximum length for zipcode is 5 characters' : 'error.baddress.zipcode.length'}
|
||||
{ billingAddress.zipCode : match('[0-9]{5}',?) = TRUE : 'ZipCode must contain exactly 5 digits' : 'error.baddress.zipcode.format'}
|
||||
{ billingAddress.state : (? HAS NO TEXT AND billingAddress.country != 'United States') OR (? HAS TEXT AND length(?) <= 2) : 'Maximum length for state is 2 characters' : 'error.baddress.state.length'}
|
||||
{ billingAddress.country : ? HAS TEXT AND length(?) <= 50 : 'Country is mandatory and maximum length for country is 50 characters' : 'error.baddress.country.length'}
|
||||
|
||||
{ shippingAddress.addressee : shippingAddress IS NULL OR (? HAS TEXT AND length(?) <= 60) : 'Addressee is mandatory and maximum length for addressee is 60 characters' : 'error.saddress.addresse.length'}
|
||||
{ shippingAddress.addrLine1 : shippingAddress IS NULL OR (? HAS TEXT AND length(?) <= 50) : 'Address line1 is mandatory and maximum length for address line1 is 50 characters' : 'error.baddress.addrline1.length'}
|
||||
{ shippingAddress.addrLine2 : shippingAddress IS NULL OR (? HAS NO TEXT OR length(?) <= 50) : 'Maximum length for address line2 is 50 characters' : 'error.baddress.addrline2.length'}
|
||||
{ shippingAddress.city : shippingAddress IS NULL OR (? HAS TEXT AND length(?) <= 30) : 'City is mandatory and maximum length for city is 30 characters' : 'error.baddress.city.length'}
|
||||
{ shippingAddress.zipCode : shippingAddress IS NULL OR (? HAS TEXT AND length(?) <= 50) : 'Zipcode is mandatory and maximum length for zipcode is 5 characters' : 'error.baddress.zipcode.length'}
|
||||
{ shippingAddress.zipCode : shippingAddress IS NULL OR (match('[0-9]{5}',?) = TRUE) : 'Zipcode must contain exactly 5 digits' : 'error.baddress.zipcode.format'}
|
||||
{ shippingAddress.state : shippingAddress IS NULL OR ((? HAS NO TEXT AND billingAddress.country != 'United States') OR (? HAS TEXT AND length(?) <= 2)) : 'Maximum length for state is 2 characters' : 'error.baddress.state.length'}
|
||||
{ shippingAddress.country : shippingAddress IS NULL OR (? HAS TEXT AND length(?) <= 50) : 'Country is mandatory and maximum length for country is 50 characters' : 'error.baddress.country.length'}
|
||||
|
||||
{ billing.paymentId : ? IN 'VISA','AMEX','ECMC','DCIN','PAYP' : 'Invalid payment type' : 'error.billing.type' }
|
||||
{ billing.paymentDesc : match('[A-Z]{4}-[0-9]{10,11}',?) = TRUE : 'Invalid format of payment description' : 'error.billing.desc' }
|
||||
|
||||
{ shipping.shipperId : ? IN 'FEDX', 'UPS', 'DHL', 'DPD' : 'Invalid shipper ID' : 'error.shipping.shipper'}
|
||||
{ shipping.shippingTypeId : ? IN 'STD', 'EXP', 'AMS', 'AME' : 'Invalid shipping type' : 'error.shipping.type' }
|
||||
{ shipping.shippingInfo : ? HAS NO TEXT OR length(?) <= 100 : 'Maximum length for additional shipping info is 100 characters' }
|
||||
|
||||
{ lineItems : validateTotalItemsCount(totalItems,?) = TRUE : 'Bad count of total line items' : 'error.lineitems.badcount' }
|
||||
{ lineItems : validateIds(?) = TRUE : 'One or more invalid item IDs' : 'error.lineitems.id' }
|
||||
{ lineItems : validatePrices(?) = TRUE : 'One or more invalid item prices' : 'error.lineitems.price' }
|
||||
{ lineItems : validateDiscounts(?) = TRUE : 'One or more invalid item discounts' : 'error.lineitems.discount' }
|
||||
{ lineItems : validateShippingPrices(?) = TRUE : 'One or more invalid item shipping prices' : 'error.lineitems.shipping' }
|
||||
{ lineItems : validateHandlingPrices(?) = TRUE : 'One or more invalid item handling prices' : 'error.lineitems.handling' }
|
||||
{ lineItems : validateQuantities(?) = TRUE : 'One or more invalid item quantities' : 'error.lineitems.quantity' }
|
||||
{ lineItems : validateTotalPrices(?) = TRUE : 'One or more invalid item total prices' : 'error.lineitems.totalprice' }
|
||||
]]>
|
||||
</value>
|
||||
</property>
|
||||
<property name="customFunctions">
|
||||
<map>
|
||||
<entry key="isFutureDate"
|
||||
value="org.springframework.batch.sample.validation.valang.custom.FutureDateFunction" />
|
||||
<entry key="validateTotalItemsCount"
|
||||
value="org.springframework.batch.sample.validation.valang.custom.TotalOrderItemsFunction" />
|
||||
<entry key="validateIds"
|
||||
value="org.springframework.batch.sample.validation.valang.custom.ValidateIdsFunction" />
|
||||
<entry key="validatePrices"
|
||||
value="org.springframework.batch.sample.validation.valang.custom.ValidatePricesFunction" />
|
||||
<entry key="validateDiscounts"
|
||||
value="org.springframework.batch.sample.validation.valang.custom.ValidateDiscountsFunction" />
|
||||
<entry key="validateShippingPrices"
|
||||
value="org.springframework.batch.sample.validation.valang.custom.ValidateShippingPricesFunction" />
|
||||
<entry key="validateHandlingPrices"
|
||||
value="org.springframework.batch.sample.validation.valang.custom.ValidateHandlingPricesFunction" />
|
||||
<entry key="validateQuantities"
|
||||
value="org.springframework.batch.sample.validation.valang.custom.ValidateQuantitiesFunction" />
|
||||
<entry key="validateTotalPrices"
|
||||
value="org.springframework.batch.sample.validation.valang.custom.ValidateTotalPricesFunction" />
|
||||
</map>
|
||||
</property>
|
||||
</bean>
|
||||
</property>
|
||||
</bean>
|
||||
<!-- "{" <key> : <rule> : <message> : [ <error_code> [ : <error_parameters> ] ] "}" -->
|
||||
|
||||
<bean id="fileInputLocator" class="org.springframework.core.io.ClassPathResource">
|
||||
<constructor-arg type="java.lang.String"
|
||||
value="data/multilineOrderJob/input/20070122.teststream.multilineOrderStep.txt" />
|
||||
</bean>
|
||||
|
||||
<bean id="fileOutputLocator" class="org.springframework.core.io.FileSystemResource">
|
||||
<constructor-arg type="java.lang.String" value="20070122.teststream.multilineOrderStep.TEMP.txt" />
|
||||
</bean>
|
||||
</beans>
|
||||
@@ -0,0 +1,39 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:p="http://www.springframework.org/schema/p" xmlns:util="http://www.springframework.org/schema/util"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans
|
||||
http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
|
||||
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-2.0.xsd">
|
||||
|
||||
<util:map id="outputDescriptors">
|
||||
<entry key="header" value-ref="outputHeader" />
|
||||
<entry key="footer" value-ref="outputFooter" />
|
||||
<entry key="customer" value-ref="outputCustomer" />
|
||||
<entry key="address" value-ref="outputAddress" />
|
||||
<entry key="billing" value-ref="outputBilling" />
|
||||
<entry key="item" value-ref="outputLineItem" />
|
||||
</util:map>
|
||||
|
||||
<bean id="outputHeader" class="org.springframework.batch.io.file.support.transform.FixedLengthLineAggregator"
|
||||
p:lengths="12,10,30" />
|
||||
|
||||
<bean id="outputFooter"
|
||||
class="org.springframework.batch.io.file.support.transform.FixedLengthLineAggregator"
|
||||
p:lengths="10,20" />
|
||||
|
||||
<bean id="outputCustomer" class="org.springframework.batch.io.file.support.transform.FixedLengthLineAggregator"
|
||||
p:lengths="9,10,10,10,10" />
|
||||
|
||||
<bean id="outputAddress"
|
||||
class="org.springframework.batch.io.file.support.transform.FixedLengthLineAggregator"
|
||||
p:lengths="8,20,10,10" />
|
||||
|
||||
<bean id="outputBilling"
|
||||
class="org.springframework.batch.io.file.support.transform.FixedLengthLineAggregator"
|
||||
p:lengths="8,10,20" />
|
||||
|
||||
<bean id="outputLineItem"
|
||||
class="org.springframework.batch.io.file.support.transform.FixedLengthLineAggregator"
|
||||
p:lengths="5,10,10" />
|
||||
|
||||
</beans>
|
||||
84
samples/src/main/resources/jobs/quartzBatch.xml
Normal file
84
samples/src/main/resources/jobs/quartzBatch.xml
Normal file
@@ -0,0 +1,84 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:p="http://www.springframework.org/schema/p"
|
||||
xmlns:aop="http://www.springframework.org/schema/aop"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans
|
||||
http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
|
||||
http://www.springframework.org/schema/aop
|
||||
http://www.springframework.org/schema/aop/spring-aop-2.0.xsd">
|
||||
|
||||
<!-- TODO update! -->
|
||||
|
||||
<!-- LAUNCHERS -->
|
||||
|
||||
<bean id="tradeLauncher"
|
||||
class="org.springframework.scheduling.quartz.JobDetailBean">
|
||||
<property name="jobClass" value="com.accenture.adsj.refapp.batch.launch.QuartzBatchJobLauncher" />
|
||||
<property name="jobDataAsMap">
|
||||
<map>
|
||||
<entry key="batchRoot" value="src/main/resources/testBatchRoot" />
|
||||
<entry key="hostName" value="localhost" />
|
||||
<entry key="jobName" value="tradeJob" />
|
||||
<entry key="jobStream" value="testStream" />
|
||||
<entry key="userName" value="robert.kasanicky" />
|
||||
<entry key="jobRun" value="1" />
|
||||
</map>
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
<bean id="fixedLengthImportLauncher"
|
||||
class="org.springframework.scheduling.quartz.JobDetailBean">
|
||||
<property name="jobClass" value="com.accenture.adsj.refapp.batch.launch.QuartzBatchJobLauncher" />
|
||||
<property name="jobDataAsMap">
|
||||
<map>
|
||||
<entry key="batchRoot" value="src/main/resources/testBatchRoot" />
|
||||
<entry key="hostName" value="localhost" />
|
||||
<entry key="jobName" value="fixedLengthImportJob"/>
|
||||
<entry key="jobStream" value="testStream" />
|
||||
<entry key="userName" value="robert.kasanicky" />
|
||||
<entry key="jobRun" value="1" />
|
||||
</map>
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
|
||||
<!-- TRIGGERS -->
|
||||
|
||||
<bean id="tradeSimpleTrigger"
|
||||
class="org.springframework.scheduling.quartz.SimpleTriggerBean">
|
||||
<property name="jobDetail" ref="tradeLauncher" />
|
||||
<property name="startDelay" value="20000" />
|
||||
<property name="repeatInterval" value="30000" />
|
||||
<property name="repeatCount" value="2" />
|
||||
</bean>
|
||||
|
||||
<bean id="fixedLengthImportSimpleTrigger"
|
||||
class="org.springframework.scheduling.quartz.SimpleTriggerBean">
|
||||
<property name="jobDetail" ref="fixedLengthImportLauncher" />
|
||||
<property name="startDelay" value="1000" />
|
||||
<property name="repeatInterval" value="1000000" />
|
||||
</bean>
|
||||
|
||||
<bean id="tradeCronTrigger"
|
||||
class="org.springframework.scheduling.quartz.CronTriggerBean">
|
||||
<property name="jobDetail" ref="tradeLauncher" />
|
||||
<!-- run every morning at 6 AM -->
|
||||
<property name="cronExpression" value="0 0 6 * * ?" />
|
||||
</bean>
|
||||
|
||||
|
||||
<!-- SCHEDULER -->
|
||||
|
||||
<bean id="quartzScheduler"
|
||||
class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
|
||||
<property name="triggers">
|
||||
<list>
|
||||
<ref bean="tradeCronTrigger" />
|
||||
<ref bean="tradeSimpleTrigger" />
|
||||
<ref bean="fixedLengthImportSimpleTrigger" />
|
||||
</list>
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
</beans>
|
||||
87
samples/src/main/resources/jobs/restartSample.xml
Normal file
87
samples/src/main/resources/jobs/restartSample.xml
Normal file
@@ -0,0 +1,87 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:aop="http://www.springframework.org/schema/aop"
|
||||
xmlns:tx="http://www.springframework.org/schema/tx" xmlns:p="http://www.springframework.org/schema/p"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="
|
||||
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
|
||||
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd
|
||||
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd">
|
||||
|
||||
<import resource="../simple-container-definition.xml" />
|
||||
|
||||
<bean class="org.springframework.batch.execution.configuration.JobConfigurationRegistryBeanPostProcessor">
|
||||
<property name="jobConfigurationRegistry" ref="jobConfigurationRegistry"/>
|
||||
</bean>
|
||||
|
||||
<bean id="jobConfiguration" parent="simpleJob" p:name="restartSample">
|
||||
<property name="steps">
|
||||
<bean id="step1" parent="simpleStep">
|
||||
<constructor-arg>
|
||||
<bean class="org.springframework.batch.sample.module.ExceptionRestartableTasklet">
|
||||
<property name="itemProvider">
|
||||
<bean
|
||||
class="org.springframework.batch.execution.tasklet.support.DefaultFlatFileItemProvider">
|
||||
<property name="source" ref="fileInputTemplate" />
|
||||
<property name="mapper" ref="fieldSetMapper" />
|
||||
<property name="validator" ref="fixedValidator" />
|
||||
</bean>
|
||||
</property>
|
||||
<property name="itemProcessor">
|
||||
<bean class="org.springframework.batch.sample.module.process.TradeProcessor">
|
||||
<property name="writer" ref="tradeDao" />
|
||||
</bean>
|
||||
</property>
|
||||
</bean>
|
||||
</constructor-arg>
|
||||
<property name="commitInterval" value="2" />
|
||||
</bean>
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
|
||||
|
||||
<!-- INFRASTRUCTURE SETUP -->
|
||||
|
||||
<bean id="fileInputTemplate" class="org.springframework.batch.io.file.support.DefaultFlatFileInputSource">
|
||||
<property name="resource" ref="fileLocator" />
|
||||
<property name="tokenizer" ref="fixedFileDescriptor" />
|
||||
</bean>
|
||||
|
||||
<bean id="fixedFileDescriptor" class="org.springframework.batch.io.file.support.transform.FixedLengthTokenizer">
|
||||
<property name="names" value="ISIN, Quantity, Price, Customer" />
|
||||
<property name="lengths" value="12, 3, 5, 9" />
|
||||
</bean>
|
||||
|
||||
<bean id="fixedValidator" class="org.springframework.batch.item.validator.SpringValidator">
|
||||
<property name="validator">
|
||||
<bean id="tradeValidator" class="org.springmodules.validation.valang.ValangValidator">
|
||||
<property name="valang">
|
||||
<value>
|
||||
<![CDATA[
|
||||
{ isin : length(?) < 13 : 'ISIN too long' : 'isin_length' : 12}
|
||||
]]>
|
||||
</value>
|
||||
</property>
|
||||
</bean>
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
<bean id="tradeDao" class="org.springframework.batch.sample.dao.JdbcTradeWriter">
|
||||
<property name="jdbcTemplate" ref="jdbcTemplate" />
|
||||
<property name="incrementer">
|
||||
<bean parent="incrementerParent">
|
||||
<property name="incrementerName" value="TRADE_SEQ" />
|
||||
</bean>
|
||||
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
<bean id="fileLocator" class="org.springframework.core.io.ClassPathResource">
|
||||
<constructor-arg type="java.lang.String"
|
||||
value="data/fixedLengthImportJob/input/20070122.teststream.ImportTradeDataStep.txt" />
|
||||
</bean>
|
||||
|
||||
<bean id="fieldSetMapper" class="org.springframework.batch.sample.mapping.TradeFieldSetMapper" />
|
||||
|
||||
|
||||
</beans>
|
||||
72
samples/src/main/resources/jobs/simpleTaskletJob.xml
Normal file
72
samples/src/main/resources/jobs/simpleTaskletJob.xml
Normal file
@@ -0,0 +1,72 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:aop="http://www.springframework.org/schema/aop"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans
|
||||
http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
|
||||
http://www.springframework.org/schema/aop
|
||||
http://www.springframework.org/schema/aop/spring-aop-2.0.xsd">
|
||||
|
||||
|
||||
<import resource="../simple-container-definition.xml" />
|
||||
|
||||
<bean class="org.springframework.batch.execution.configuration.JobConfigurationRegistryBeanPostProcessor">
|
||||
<property name="jobConfigurationRegistry" ref="jobConfigurationRegistry"/>
|
||||
</bean>
|
||||
|
||||
<bean id="jobConfiguration" parent="simpleJob">
|
||||
<property name="name" value="simpleTaskletJob" />
|
||||
<property name="steps">
|
||||
<list>
|
||||
<bean id="step1" parent="simpleStep">
|
||||
<constructor-arg>
|
||||
<bean id="tradeTasklet" class="org.springframework.batch.sample.module.SimpleTradeTasklet">
|
||||
<property name="inputSource" ref="fileInputSource" />
|
||||
<property name="tradeDao" ref="tradeDao" />
|
||||
</bean>
|
||||
</constructor-arg>
|
||||
<property name="commitInterval" value="2" />
|
||||
</bean>
|
||||
</list>
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
|
||||
|
||||
<bean id="tradeDao" class="org.springframework.batch.sample.dao.JdbcTradeWriter">
|
||||
<property name="jdbcTemplate" ref="jdbcTemplate" />
|
||||
<property name="incrementer">
|
||||
<bean parent="incrementerParent">
|
||||
<property name="incrementerName" value="TRADE_SEQ" />
|
||||
</bean>
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
<bean id="fileInputSource" class="org.springframework.batch.io.file.support.DefaultFlatFileInputSource">
|
||||
<property name="resource" ref="fileLocator" />
|
||||
<property name="tokenizer" ref="fixedFileDescriptor" />
|
||||
</bean>
|
||||
|
||||
<bean id="fixedFileDescriptor" class="org.springframework.batch.io.file.support.transform.FixedLengthTokenizer">
|
||||
<property name="names" value="ISIN, Quantity, Price, Customer" />
|
||||
<property name="lengths" value="12, 3, 5, 9" />
|
||||
</bean>
|
||||
|
||||
<bean id="fileLocator" class="org.springframework.core.io.ClassPathResource">
|
||||
<constructor-arg type="java.lang.String"
|
||||
value="data/simpleTaskletJob/input/20070122.teststream.ImportTradeDataStep.txt" />
|
||||
</bean>
|
||||
|
||||
<bean id="tradeLogAdvice"
|
||||
class="org.springframework.batch.sample.advice.TradeWriterLogAdvice" />
|
||||
|
||||
<aop:config>
|
||||
<aop:aspect id="tradeWriterLogging" ref="tradeLogAdvice">
|
||||
|
||||
<aop:after
|
||||
pointcut="execution( * org.springframework.batch.sample.dao.TradeWriter+.writeTrade(org.springframework.batch.sample.domain.Trade)) and args(trade)"
|
||||
method="doBasicLogging" />
|
||||
|
||||
</aop:aspect>
|
||||
</aop:config>
|
||||
|
||||
</beans>
|
||||
110
samples/src/main/resources/jobs/tradeJob.xml
Normal file
110
samples/src/main/resources/jobs/tradeJob.xml
Normal file
@@ -0,0 +1,110 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:p="http://www.springframework.org/schema/p" xmlns:aop="http://www.springframework.org/schema/aop"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans
|
||||
http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
|
||||
http://www.springframework.org/schema/aop
|
||||
http://www.springframework.org/schema/aop/spring-aop-2.0.xsd">
|
||||
|
||||
<import resource="../simple-container-definition.xml" />
|
||||
|
||||
<import resource="tradeJobIo.xml" />
|
||||
<!--import resource="tradeJobAop.xml" /-->
|
||||
|
||||
<bean class="org.springframework.batch.execution.configuration.JobConfigurationRegistryBeanPostProcessor">
|
||||
<property name="jobConfigurationRegistry" ref="jobConfigurationRegistry" />
|
||||
</bean>
|
||||
|
||||
<bean id="jobConfiguration" parent="simpleJob">
|
||||
<property name="name" value="tradeJob" />
|
||||
<property name="steps">
|
||||
<list>
|
||||
<bean id="step1" parent="simpleStep">
|
||||
<constructor-arg>
|
||||
<bean class="org.springframework.batch.execution.tasklet.RestartableItemProviderTasklet">
|
||||
<property name="itemProvider">
|
||||
<bean
|
||||
class="org.springframework.batch.execution.tasklet.support.DefaultFlatFileItemProvider">
|
||||
<property name="source" ref="fileInputTemplate" />
|
||||
<property name="mapper">
|
||||
<bean class="org.springframework.batch.sample.mapping.TradeFieldSetMapper" />
|
||||
</property>
|
||||
<property name="validator" ref="tradeValidator" />
|
||||
</bean>
|
||||
</property>
|
||||
<property name="itemProcessor">
|
||||
<bean class="org.springframework.batch.sample.module.process.TradeProcessor"
|
||||
p:writer-ref="tradeDao" />
|
||||
</property>
|
||||
</bean>
|
||||
</constructor-arg>
|
||||
</bean>
|
||||
<bean id="step2" parent="simpleStep">
|
||||
<constructor-arg>
|
||||
<bean class="org.springframework.batch.execution.tasklet.RestartableItemProviderTasklet">
|
||||
<property name="itemProvider">
|
||||
<bean
|
||||
class="org.springframework.batch.execution.tasklet.support.InputSourceItemProvider">
|
||||
<property name="inputSource">
|
||||
<bean class="org.springframework.batch.io.sql.SqlCursorInputSource">
|
||||
<constructor-arg>
|
||||
<ref bean="dataSource" />
|
||||
</constructor-arg>
|
||||
<property name="sql"
|
||||
value="SELECT id, quantity, price, customer from TRADE" />
|
||||
<property name="mapper">
|
||||
<bean class="org.springframework.batch.sample.mapping.TradeRowMapper" />
|
||||
</property>
|
||||
</bean>
|
||||
</property>
|
||||
</bean>
|
||||
</property>
|
||||
<property name="itemProcessor">
|
||||
<bean class="org.springframework.batch.sample.module.process.CustomerUpdateProcessor"
|
||||
p:dao-ref="customerDao" />
|
||||
</property>
|
||||
</bean>
|
||||
</constructor-arg>
|
||||
</bean>
|
||||
<bean id="step3" parent="simpleStep">
|
||||
<constructor-arg>
|
||||
<bean class="org.springframework.batch.execution.tasklet.RestartableItemProviderTasklet">
|
||||
<property name="itemProvider">
|
||||
<bean
|
||||
class="org.springframework.batch.execution.tasklet.support.InputSourceItemProvider">
|
||||
<property name="inputSource">
|
||||
<bean class="org.springframework.batch.io.sql.SqlCursorInputSource">
|
||||
<constructor-arg>
|
||||
<ref bean="dataSource" />
|
||||
</constructor-arg>
|
||||
<property name="sql" value="SELECT id, name, credit FROM customer " />
|
||||
<property name="mapper">
|
||||
<bean
|
||||
class="org.springframework.batch.sample.mapping.CustomerCreditRowMapper" />
|
||||
</property>
|
||||
</bean>
|
||||
</property>
|
||||
</bean>
|
||||
</property>
|
||||
<property name="itemProcessor">
|
||||
<bean
|
||||
class="org.springframework.batch.sample.module.process.CustomerCreditUpdateProcessor"
|
||||
p:writer-ref="customerReportOutputSource" />
|
||||
</property>
|
||||
</bean>
|
||||
</constructor-arg>
|
||||
</bean>
|
||||
</list>
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
<bean id="fileLocator" class="org.springframework.core.io.ClassPathResource">
|
||||
<constructor-arg type="java.lang.String"
|
||||
value="data/tradeJob/input/20070122.teststream.ImportTradeDataStep.txt" />
|
||||
</bean>
|
||||
|
||||
<bean id="customerFileLocator" class="org.springframework.core.io.FileSystemResource">
|
||||
<constructor-arg type="java.lang.String" value="20070122.testStream.CustomerReportStep.TEMP.txt" />
|
||||
</bean>
|
||||
|
||||
</beans>
|
||||
52
samples/src/main/resources/jobs/tradeJobIo.xml
Normal file
52
samples/src/main/resources/jobs/tradeJobIo.xml
Normal file
@@ -0,0 +1,52 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:p="http://www.springframework.org/schema/p" xmlns:aop="http://www.springframework.org/schema/aop"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans
|
||||
http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
|
||||
http://www.springframework.org/schema/aop
|
||||
http://www.springframework.org/schema/aop/spring-aop-2.0.xsd">
|
||||
|
||||
|
||||
<bean class="org.springframework.batch.sample.dao.JdbcTradeWriter" id="tradeDao"
|
||||
p:jdbcTemplate-ref="jdbcTemplate">
|
||||
<property name="incrementer">
|
||||
<bean parent="incrementerParent">
|
||||
<property name="incrementerName" value="TRADE_SEQ" />
|
||||
</bean>
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
<bean class="org.springframework.batch.sample.dao.JdbcCustomerDebitWriter" id="customerDao" p:jdbcTemplate-ref="jdbcTemplate" />
|
||||
|
||||
<bean class="org.springframework.batch.sample.dao.FlatFileCustomerCreditWriter" id="customerReportOutputSource"
|
||||
p:outputSource-ref="customerFlatFileOutputSource" />
|
||||
|
||||
<bean class="org.springframework.batch.io.file.support.FlatFileOutputSource" id="customerFlatFileOutputSource">
|
||||
<property name="resource" ref="customerFileLocator" />
|
||||
</bean>
|
||||
|
||||
<bean class="org.springframework.batch.io.file.support.DefaultFlatFileInputSource" id="fileInputTemplate">
|
||||
<property name="resource" ref="fileLocator" />
|
||||
<property name="tokenizer" ref="tradeFileDescriptor" />
|
||||
</bean>
|
||||
|
||||
<bean id="tradeFileDescriptor"
|
||||
class="org.springframework.batch.io.file.support.transform.DelimitedLineTokenizer">
|
||||
<property name="names" value="ISIN, Quantity, Price, Customer" />
|
||||
</bean>
|
||||
|
||||
<bean id="tradeValidator" class="org.springframework.batch.item.validator.SpringValidator">
|
||||
<property name="validator">
|
||||
<bean class="org.springmodules.validation.valang.ValangValidator">
|
||||
<property name="valang">
|
||||
<value>
|
||||
<![CDATA[
|
||||
{ isin : length(?) < 13 : 'ISIN too long' : 'isin_length' : 12}
|
||||
]]>
|
||||
</value>
|
||||
</property>
|
||||
</bean>
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
</beans>
|
||||
120
samples/src/main/resources/jobs/xmlJob.xml
Normal file
120
samples/src/main/resources/jobs/xmlJob.xml
Normal file
@@ -0,0 +1,120 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:aop="http://www.springframework.org/schema/aop"
|
||||
xmlns:tx="http://www.springframework.org/schema/tx" xmlns:p="http://www.springframework.org/schema/p"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="
|
||||
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
|
||||
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd
|
||||
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd">
|
||||
|
||||
<import resource="../simple-container-definition.xml" />
|
||||
|
||||
<bean class="org.springframework.batch.execution.configuration.JobConfigurationRegistryBeanPostProcessor">
|
||||
<property name="jobConfigurationRegistry" ref="jobConfigurationRegistry"/>
|
||||
</bean>
|
||||
|
||||
<bean id="jobConfiguration" parent="simpleJob">
|
||||
<property name="name" value="xmlJob" />
|
||||
<property name="steps">
|
||||
<bean id="step1" parent="simpleStep">
|
||||
<constructor-arg>
|
||||
<bean
|
||||
class="org.springframework.batch.execution.tasklet.RestartableItemProviderTasklet">
|
||||
<property name="itemProvider">
|
||||
<bean
|
||||
class="org.springframework.batch.execution.tasklet.support.InputSourceItemProvider">
|
||||
<property name="inputSource">
|
||||
<bean class="org.springframework.batch.io.xml.XmlInputSource">
|
||||
<property name="name" value="XmlFileInputSource" />
|
||||
<property name="resource"
|
||||
value="data/xmlJob/input/20070122.testStream.xmlFileStep.xml" />
|
||||
<property name="validating" value="true" />
|
||||
<property name="inputFactory">
|
||||
<bean class="org.springframework.batch.io.xml.xstream.XStreamFactory">
|
||||
<property name="config" ref="streamConfig2" />
|
||||
</bean>
|
||||
</property>
|
||||
</bean>
|
||||
</property>
|
||||
</bean>
|
||||
</property>
|
||||
<property name="itemProcessor">
|
||||
<bean class="org.springframework.batch.execution.tasklet.support.OutputSourceItemProcessor">
|
||||
<property name="outputSource">
|
||||
<bean class="org.springframework.batch.io.xml.XmlOutputSource" scope="step">
|
||||
<aop:scoped-proxy/>
|
||||
<property name="name" value="XmlFileOutputSource" />
|
||||
<property name="resource" value="file:20070122.testStream.xmlFileStep.xml" />
|
||||
<property name="outputFactory">
|
||||
<bean class="org.springframework.batch.io.xml.xstream.XStreamFactory">
|
||||
<property name="config" ref="streamConfig" />
|
||||
</bean>
|
||||
</property>
|
||||
</bean>
|
||||
</property>
|
||||
</bean>
|
||||
</property>
|
||||
</bean>
|
||||
</constructor-arg>
|
||||
</bean>
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
<bean id="streamConfig" class="org.springframework.batch.io.xml.xstream.XStreamConfigurationFactoryBean">
|
||||
<property name="configFile" value="xstream-config.xml" />
|
||||
</bean>
|
||||
|
||||
<bean id="streamConfig2" class="org.springframework.batch.io.xml.xstream.XStreamConfiguration">
|
||||
<property name="rootElementName" value="purchaseOrders" />
|
||||
<property name="rootElementAttributes">
|
||||
<map>
|
||||
<entry key="xmlns" value="http://adsj.accenture.com/purchaseorders" />
|
||||
<entry key="xmlns:xsi" value="http://www.w3.org/2001/XMLSchema-instance" />
|
||||
<entry key="xsi:schemaLocation" value="http://adsj.accenture.com/purchaseorders purchaseorders.xsd" />
|
||||
</map>
|
||||
</property>
|
||||
<property name="fieldAliases">
|
||||
<list>
|
||||
<bean class="org.springframework.batch.io.xml.xstream.FieldAlias">
|
||||
<property name="aliasName" value="org.springframework.batch.sample.domain.xml.Customer" />
|
||||
<property name="type" value="org.springframework.batch.sample.domain.xml.Order" />
|
||||
<property name="fieldName" value="customer" />
|
||||
</bean>
|
||||
<bean class="org.springframework.batch.io.xml.xstream.FieldAlias">
|
||||
<property name="aliasName" value="org.springframework.batch.sample.domain.xml.Shipper" />
|
||||
<property name="type" value="org.springframework.batch.sample.domain.xml.Order" />
|
||||
<property name="fieldName" value="shiper" />
|
||||
</bean>
|
||||
</list>
|
||||
</property>
|
||||
<property name="mappings">
|
||||
<list>
|
||||
<bean class="org.springframework.batch.io.xml.xstream.Mapping">
|
||||
<property name="namespaceURI" value="http://adsj.accenture.com/purchaseorders" />
|
||||
<property name="localPart" value="order" />
|
||||
<property name="prefix" value="" />
|
||||
<property name="className" value="org.springframework.batch.sample.domain.xml.Order" />
|
||||
</bean>
|
||||
<bean class="org.springframework.batch.io.xml.xstream.Mapping">
|
||||
<property name="namespaceURI" value="http://adsj.accenture.com/purchaseorders" />
|
||||
<property name="localPart" value="customer" />
|
||||
<property name="prefix" value="" />
|
||||
<property name="className" value="org.springframework.batch.sample.domain.xml.Customer" />
|
||||
</bean>
|
||||
<bean class="org.springframework.batch.io.xml.xstream.Mapping">
|
||||
<property name="namespaceURI" value="http://adsj.accenture.com/purchaseorders" />
|
||||
<property name="localPart" value="shipper" />
|
||||
<property name="prefix" value="" />
|
||||
<property name="className" value="org.springframework.batch.sample.domain.xml.Shipper" />
|
||||
</bean>
|
||||
<bean class="org.springframework.batch.io.xml.xstream.Mapping">
|
||||
<property name="namespaceURI" value="http://adsj.accenture.com/purchaseorders" />
|
||||
<property name="localPart" value="lineItem" />
|
||||
<property name="prefix" value="" />
|
||||
<property name="className" value="org.springframework.batch.sample.domain.xml.LineItem" />
|
||||
</bean>
|
||||
</list>
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
</beans>
|
||||
21
samples/src/main/resources/log4j.properties
Normal file
21
samples/src/main/resources/log4j.properties
Normal file
@@ -0,0 +1,21 @@
|
||||
### direct log messages to stdout ###
|
||||
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
|
||||
log4j.appender.stdout.Target=System.out
|
||||
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
|
||||
log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n
|
||||
|
||||
### set log levels - for more verbose logging change 'info' to 'debug' ###
|
||||
|
||||
log4j.rootLogger=info, stdout
|
||||
|
||||
### enable the following line if you want to track down connection ###
|
||||
### leakages when using DriverManagerConnectionProvider ###
|
||||
#log4j.logger.org.hibernate.connection.DriverManagerConnectionProvider=trace
|
||||
|
||||
### enable spring
|
||||
log4j.logger.org.springframework=error
|
||||
log4j.logger.org.springframework.batch=info
|
||||
|
||||
### debug your specific package or classes with the following example
|
||||
log4j.logger.org.springframework.batch.sample.module.OrderDataProvider=debug
|
||||
log4j.logger.org.springframework.batch.container.common.module.process.support.DefaultXmlDataProvider=debug
|
||||
150
samples/src/main/resources/simple-container-definition.xml
Normal file
150
samples/src/main/resources/simple-container-definition.xml
Normal file
@@ -0,0 +1,150 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:aop="http://www.springframework.org/schema/aop"
|
||||
xmlns:tx="http://www.springframework.org/schema/tx" xmlns:p="http://www.springframework.org/schema/p"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="
|
||||
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
|
||||
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd
|
||||
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd">
|
||||
|
||||
<import resource="data-source-context.xml" />
|
||||
<import resource="data-source-context-init.xml" />
|
||||
|
||||
<bean class="org.springframework.beans.factory.config.CustomScopeConfigurer">
|
||||
<property name="scopes">
|
||||
<map>
|
||||
<entry key="step">
|
||||
<bean class="org.springframework.batch.execution.scope.StepScope" />
|
||||
</entry>
|
||||
</map>
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
<bean id="batchContainer" class="org.springframework.batch.execution.facade.SimpleJobExecutorFacade">
|
||||
<property name="jobRepository" ref="simpleJobRepository" />
|
||||
<property name="jobConfigurationLocator" ref="jobConfigurationRegistry"/>
|
||||
<property name="jobExecutor" ref="jobExecutor" />
|
||||
</bean>
|
||||
|
||||
<bean class="org.springframework.batch.execution.bootstrap.SimpleJobLauncher">
|
||||
<property name="batchContainer" ref="batchContainer" />
|
||||
</bean>
|
||||
|
||||
<bean id="jobConfigurationRegistry" class="org.springframework.batch.execution.configuration.MapJobConfigurationRegistry"/>
|
||||
|
||||
<aop:config>
|
||||
<aop:advisor pointcut="execution(* org.springframework.batch.container..*Repository+.*(..))"
|
||||
advice-ref="txAdvice" />
|
||||
</aop:config>
|
||||
<tx:advice id="txAdvice" transaction-manager="transactionManager">
|
||||
<tx:attributes>
|
||||
<tx:method name="*" />
|
||||
</tx:attributes>
|
||||
</tx:advice>
|
||||
|
||||
<bean id="jobExecutor" class="org.springframework.batch.execution.job.DefaultJobExecutor">
|
||||
<property name="jobRepository" ref="simpleJobRepository" />
|
||||
<property name="stepExecutorResolver">
|
||||
<bean class="org.springframework.batch.execution.step.DefaultStepExecutorFactory">
|
||||
<property name="stepExecutorName" value="stepExecutor" />
|
||||
</bean>
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
<bean id="stepExecutor" class="org.springframework.batch.execution.step.simple.SimpleStepExecutor"
|
||||
scope="prototype">
|
||||
<property name="transactionManager" ref="transactionManager" />
|
||||
<property name="repository" ref="simpleJobRepository" />
|
||||
</bean>
|
||||
|
||||
<bean id="simpleJobRepository" class="org.springframework.batch.execution.repository.SimpleJobRepository">
|
||||
<constructor-arg ref="jobDao" />
|
||||
<constructor-arg ref="stepDao" />
|
||||
</bean>
|
||||
|
||||
<bean id="jobDao" class="org.springframework.batch.execution.repository.dao.SqlJobDao">
|
||||
<property name="jdbcTemplate" ref="jdbcTemplate" />
|
||||
<property name="jobIncrementer" ref="jobIncrementer" />
|
||||
<property name="jobExecutionIncrementer" ref="jobExecutionIncrementer" />
|
||||
</bean>
|
||||
|
||||
<bean id="stepDao" class="org.springframework.batch.execution.repository.dao.SqlStepDao">
|
||||
<property name="jdbcTemplate" ref="jdbcTemplate" />
|
||||
<property name="stepIncrementer" ref="stepIncrementer" />
|
||||
<property name="stepExecutionIncrementer" ref="stepExecutionIncrementer" />
|
||||
</bean>
|
||||
|
||||
<bean id="jobRuntimeInformationFactory"
|
||||
class="org.springframework.batch.execution.runtime.ScheduledJobIdentifierFactory">
|
||||
<property name="jobStream" value="TestStream" />
|
||||
<property name="scheduleDate" value="20070505" />
|
||||
<property name="jobRun" value="1" />
|
||||
</bean>
|
||||
|
||||
<bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
|
||||
<property name="dataSource" ref="dataSource" />
|
||||
</bean>
|
||||
|
||||
<bean class="org.springframework.beans.factory.config.CustomEditorConfigurer">
|
||||
<property name="customEditors">
|
||||
<map>
|
||||
<entry key="int[]">
|
||||
<bean class="org.springframework.batch.support.IntArrayPropertyEditor" />
|
||||
</entry>
|
||||
</map>
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
<bean id="simpleJob" class="org.springframework.batch.core.configuration.JobConfiguration"
|
||||
abstract="true">
|
||||
<property name="name" value="simpleJob" />
|
||||
<property name="restartable" value="true" />
|
||||
</bean>
|
||||
|
||||
<bean id="simpleStep" class="org.springframework.batch.execution.step.simple.SimpleStepConfiguration"
|
||||
abstract="true">
|
||||
<property name="allowStartIfComplete" value="true" />
|
||||
<property name="saveRestartData" value="false" />
|
||||
<property name="exceptionHandler">
|
||||
<bean
|
||||
class="org.springframework.batch.repeat.exception.handler.SimpleLimitExceptionHandler">
|
||||
<property name="limit" value="5" />
|
||||
<property name="useParent" value="true"/>
|
||||
</bean>
|
||||
</property>
|
||||
<property name="commitInterval" value="1" />
|
||||
</bean>
|
||||
|
||||
<bean class="org.springframework.beans.factory.config.CustomEditorConfigurer">
|
||||
<property name="customEditors">
|
||||
<map>
|
||||
<entry key="int[]">
|
||||
<bean class="org.springframework.batch.support.IntArrayPropertyEditor" />
|
||||
</entry>
|
||||
<entry key="java.util.Date">
|
||||
<bean class="org.springframework.beans.propertyeditors.CustomDateEditor">
|
||||
<constructor-arg>
|
||||
<bean class="java.text.SimpleDateFormat">
|
||||
<constructor-arg value="yyyyMMdd" />
|
||||
</bean>
|
||||
</constructor-arg>
|
||||
<constructor-arg value="false" />
|
||||
</bean>
|
||||
</entry>
|
||||
</map>
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
<bean id="itemProcessorLogAdvice" class="org.springframework.batch.sample.advice.ProcessorLogAdvice" />
|
||||
|
||||
<aop:config>
|
||||
<aop:aspect id="moduleLogging" ref="itemProcessorLogAdvice">
|
||||
|
||||
<aop:after
|
||||
pointcut="execution( * org.springframework.batch.item.ItemProcessor+.process(Object)) and args(item)"
|
||||
method="doStronglyTypedLogging" />
|
||||
|
||||
</aop:aspect>
|
||||
</aop:config>
|
||||
|
||||
</beans>
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user