BATCH-173 Misc Bug fixes.

This commit is contained in:
lucasward
2007-10-18 03:53:10 +00:00
parent 2c7d52a5ae
commit 63bd6a5e65
16 changed files with 1626 additions and 1613 deletions

View File

@@ -27,6 +27,8 @@ package org.springframework.batch.io.exception;
*/
public class FlatFileParsingException extends ParsingException {
private static final long serialVersionUID = 2529197834044942724L;
private String input;
private int lineNumber;

View File

@@ -24,6 +24,8 @@ package org.springframework.batch.io.exception;
*/
public class ParsingException extends RuntimeException {
private static final long serialVersionUID = 2953386084409312312L;
public ParsingException(String message) {
super(message);
}

View File

@@ -1,186 +1,183 @@
/*
* 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.io.file.support.transform;
import java.util.ArrayList;
import java.util.List;
import org.springframework.batch.io.exception.BatchConfigurationException;
import org.springframework.util.StringUtils;
/**
*
* @author Rob Harrop
* @author Dave Syer
*
*/
public class DelimitedLineTokenizer extends AbstractLineTokenizer {
/**
* Convenient constant for the common case of a tab delimiter.
*/
public static final char DELIMITER_TAB = '\t';
/**
* Convenient constant for the common case of a comma delimiter.
*/
public static final char DELIMITER_COMMA = ',';
/**
* Convenient constant for the common case of a " character used to escape
* delimiters or line endings.
*/
public static final char DEFAULT_QUOTE_CHARACTER = '"';
// the delimiter character used when reading input.
private char delimiter;
private char quoteCharacter = DEFAULT_QUOTE_CHARACTER;
/**
* Create a new instance of the {@link DelimitedLineTokenizer} class for the
* common case where the delimiter is a {@link #DELIMITER_COMMA comma}.
*
* @see #DelimitedLineTokenizer(char)
* @see #DELIMITER_COMMA
*/
public DelimitedLineTokenizer() {
this(DELIMITER_COMMA);
}
/**
* Create a new instance of the {@link DelimitedLineTokenizer} class.
*
* @param delimiter the desired delimiter
*/
public DelimitedLineTokenizer(char delimiter) {
if (delimiter == DEFAULT_QUOTE_CHARACTER) {
throw new BatchConfigurationException("'" + DEFAULT_QUOTE_CHARACTER
+ "' is not allowed as delimiter for tokenizers.");
}
this.delimiter = delimiter;
}
/**
* Setter for the delimiter character.
* @param delimiter
*/
public void setDelimiter(char delimiter) {
this.delimiter = delimiter;
}
/**
* Public setter for the quoteCharacter. The quote character can be used to
* extend a field across line endings or to enclose a String which contains
* the delimiter. Inside a quoted token the quote character can be used to
* escape itself, thus "a""b""c" is tokenized to a"b"c.
*
* @param quoteCharacter the quoteCharacter to set
*
* @see #DEFAULT_QUOTE_CHARACTER
*/
public void setQuoteCharacter(char quoteCharacter) {
this.quoteCharacter = quoteCharacter;
}
/**
* Yields the tokens resulting from the splitting of the supplied
* <code>line</code>.
*
* @param line the line to be tokenised (can be <code>null</code>)
*
* @return the resulting tokens
*/
public List doTokenize(String line) {
List tokens = new ArrayList();
char[] chars = line.toCharArray();
boolean inQuoted = false;
char lastChar = 0;
int lastCut = 0;
int length = chars.length;
// TODO if line was null there would be exception while getting chars
// value
if (line != null) {
for (int i = 0; i < length; i++) {
char currentChar = chars[i];
boolean isEnd = (i == (length - 1));
if ((isDelimiterCharacter(currentChar) && !inQuoted) || isEnd) {
int endPosition = (isEnd ? (length - lastCut) : (i - lastCut));
if (isEnd && isDelimiterCharacter(currentChar)) {
endPosition--;
}
String value = null;
if (isQuoteCharacter(lastChar) || isQuoteCharacter(currentChar)) {
value = new String(chars, lastCut + 1, endPosition - 2);
value = StringUtils.replace(value, "" + quoteCharacter + quoteCharacter, "" + quoteCharacter);
}
else {
value = new String(chars, lastCut, endPosition);
}
tokens.add(value);
if (isEnd && (isDelimiterCharacter(currentChar))) {
tokens.add("");
}
lastCut = i + 1;
}
else if (isQuoteCharacter(currentChar)) {
inQuoted = !inQuoted;
}
lastChar = currentChar;
}
}
return tokens;
}
/**
* Is the supplied character the delimiter character?
*
* @param c the character to be checked
* @return <code>true</code> if the supplied character is the delimiter
* character
* @see DelimitedLineTokenizer#DelimitedLineTokenizer(char)
*/
private boolean isDelimiterCharacter(char c) {
return c == this.delimiter;
}
/**
* Is the supplied character a quote character?
*
* @param c the character to be checked
* @return <code>true</code> if the supplied character is an quote
* character
* @see #setQuoteCharacter(char)
*/
protected boolean isQuoteCharacter(char c) {
return c == quoteCharacter;
}
}
/*
* 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.io.file.support.transform;
import java.util.ArrayList;
import java.util.List;
import org.springframework.batch.io.exception.BatchConfigurationException;
import org.springframework.util.StringUtils;
/**
*
* @author Rob Harrop
* @author Dave Syer
*
*/
public class DelimitedLineTokenizer extends AbstractLineTokenizer {
/**
* Convenient constant for the common case of a tab delimiter.
*/
public static final char DELIMITER_TAB = '\t';
/**
* Convenient constant for the common case of a comma delimiter.
*/
public static final char DELIMITER_COMMA = ',';
/**
* Convenient constant for the common case of a " character used to escape
* delimiters or line endings.
*/
public static final char DEFAULT_QUOTE_CHARACTER = '"';
// the delimiter character used when reading input.
private char delimiter;
private char quoteCharacter = DEFAULT_QUOTE_CHARACTER;
/**
* Create a new instance of the {@link DelimitedLineTokenizer} class for the
* common case where the delimiter is a {@link #DELIMITER_COMMA comma}.
*
* @see #DelimitedLineTokenizer(char)
* @see #DELIMITER_COMMA
*/
public DelimitedLineTokenizer() {
this(DELIMITER_COMMA);
}
/**
* Create a new instance of the {@link DelimitedLineTokenizer} class.
*
* @param delimiter the desired delimiter
*/
public DelimitedLineTokenizer(char delimiter) {
if (delimiter == DEFAULT_QUOTE_CHARACTER) {
throw new BatchConfigurationException("'" + DEFAULT_QUOTE_CHARACTER
+ "' is not allowed as delimiter for tokenizers.");
}
this.delimiter = delimiter;
}
/**
* Setter for the delimiter character.
* @param delimiter
*/
public void setDelimiter(char delimiter) {
this.delimiter = delimiter;
}
/**
* Public setter for the quoteCharacter. The quote character can be used to
* extend a field across line endings or to enclose a String which contains
* the delimiter. Inside a quoted token the quote character can be used to
* escape itself, thus "a""b""c" is tokenized to a"b"c.
*
* @param quoteCharacter the quoteCharacter to set
*
* @see #DEFAULT_QUOTE_CHARACTER
*/
public void setQuoteCharacter(char quoteCharacter) {
this.quoteCharacter = quoteCharacter;
}
/**
* Yields the tokens resulting from the splitting of the supplied
* <code>line</code>.
*
* @param line the line to be tokenized
*
* @return the resulting tokens
*/
protected List doTokenize(String line) {
List tokens = new ArrayList();
//line is never null in current implementation
//line is checked in parent: AbstractLineTokenizer.tokenize()
char[] chars = line.toCharArray();
boolean inQuoted = false;
char lastChar = 0;
int lastCut = 0;
int length = chars.length;
for (int i = 0; i < length; i++) {
char currentChar = chars[i];
boolean isEnd = (i == (length - 1));
if ((isDelimiterCharacter(currentChar) && !inQuoted) || isEnd) {
int endPosition = (isEnd ? (length - lastCut) : (i - lastCut));
if (isEnd && isDelimiterCharacter(currentChar)) {
endPosition--;
}
String value = null;
if (isQuoteCharacter(lastChar) || isQuoteCharacter(currentChar)) {
value = new String(chars, lastCut + 1, endPosition - 2);
value = StringUtils.replace(value, "" + quoteCharacter + quoteCharacter, "" + quoteCharacter);
}
else {
value = new String(chars, lastCut, endPosition);
}
tokens.add(value);
if (isEnd && (isDelimiterCharacter(currentChar))) {
tokens.add("");
}
lastCut = i + 1;
}
else if (isQuoteCharacter(currentChar)) {
inQuoted = !inQuoted;
}
lastChar = currentChar;
}
return tokens;
}
/**
* Is the supplied character the delimiter character?
*
* @param c the character to be checked
* @return <code>true</code> if the supplied character is the delimiter
* character
* @see DelimitedLineTokenizer#DelimitedLineTokenizer(char)
*/
private boolean isDelimiterCharacter(char c) {
return c == this.delimiter;
}
/**
* Is the supplied character a quote character?
*
* @param c the character to be checked
* @return <code>true</code> if the supplied character is an quote
* character
* @see #setQuoteCharacter(char)
*/
protected boolean isQuoteCharacter(char c) {
return c == quoteCharacter;
}
}

View File

@@ -159,7 +159,7 @@ public abstract class AbstractDrivingQueryInputSource implements InputSource, Re
keys = restoreKeys(data);
if(keys != null & keys.size() > 0){
if(keys != null && keys.size() > 0){
keysIterator = keys.listIterator();
initialized = true;
}

View File

@@ -1,135 +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.io.file.support.mapping;
import java.math.BigDecimal;
import java.util.Date;
public class TestObject {
String varString;
boolean varBoolean;
char varChar;
byte varByte;
short varShort;
int varInt;
long varLong;
float varFloat;
double varDouble;
BigDecimal varBigDecimal;
Date varDate;
public Date getVarDate() {
return varDate;
}
public void setVarDate(Date varDate) {
this.varDate = varDate;
}
public TestObject() {
}
public BigDecimal getVarBigDecimal() {
return varBigDecimal;
}
public void setVarBigDecimal(BigDecimal varBigDecimal) {
this.varBigDecimal = varBigDecimal;
}
public boolean isVarBoolean() {
return varBoolean;
}
public void setVarBoolean(boolean varBoolean) {
this.varBoolean = varBoolean;
}
public byte getVarByte() {
return varByte;
}
public void setVarByte(byte varByte) {
this.varByte = varByte;
}
public char getVarChar() {
return varChar;
}
public void setVarChar(char varChar) {
this.varChar = varChar;
}
public double getVarDouble() {
return varDouble;
}
public void setVarDouble(double varDouble) {
this.varDouble = varDouble;
}
public float getVarFloat() {
return varFloat;
}
public void setVarFloat(float varFloat) {
this.varFloat = varFloat;
}
public long getVarLong() {
return varLong;
}
public void setVarLong(long varLong) {
this.varLong = varLong;
}
public short getVarShort() {
return varShort;
}
public void setVarShort(short varShort) {
this.varShort = varShort;
}
public String getVarString() {
return varString;
}
public void setVarString(String varString) {
this.varString = varString;
}
public int getVarInt() {
return varInt;
}
public void setVarInt(int varInt) {
this.varInt = varInt;
}
}
/*
* 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.io.file.support.mapping;
import java.math.BigDecimal;
import java.util.Date;
public class TestObject {
String varString;
boolean varBoolean;
char varChar;
byte varByte;
short varShort;
int varInt;
long varLong;
float varFloat;
double varDouble;
BigDecimal varBigDecimal;
Date varDate;
public Date getVarDate() {
return (Date)varDate.clone();
}
public void setVarDate(Date varDate) {
this.varDate = varDate == null ? null : (Date)varDate.clone();
}
public TestObject() {
}
public BigDecimal getVarBigDecimal() {
return varBigDecimal;
}
public void setVarBigDecimal(BigDecimal varBigDecimal) {
this.varBigDecimal = varBigDecimal;
}
public boolean isVarBoolean() {
return varBoolean;
}
public void setVarBoolean(boolean varBoolean) {
this.varBoolean = varBoolean;
}
public byte getVarByte() {
return varByte;
}
public void setVarByte(byte varByte) {
this.varByte = varByte;
}
public char getVarChar() {
return varChar;
}
public void setVarChar(char varChar) {
this.varChar = varChar;
}
public double getVarDouble() {
return varDouble;
}
public void setVarDouble(double varDouble) {
this.varDouble = varDouble;
}
public float getVarFloat() {
return varFloat;
}
public void setVarFloat(float varFloat) {
this.varFloat = varFloat;
}
public long getVarLong() {
return varLong;
}
public void setVarLong(long varLong) {
this.varLong = varLong;
}
public short getVarShort() {
return varShort;
}
public void setVarShort(short varShort) {
this.varShort = varShort;
}
public String getVarString() {
return varString;
}
public void setVarString(String varString) {
this.varString = varString;
}
public int getVarInt() {
return varInt;
}
public void setVarInt(int varInt) {
this.varInt = varInt;
}
}

View File

@@ -24,12 +24,12 @@ import javax.xml.stream.XMLStreamException;
import javax.xml.stream.events.XMLEvent;
import javax.xml.transform.Result;
import junit.framework.TestCase;
import org.springframework.dao.DataAccessResourceFailureException;
import org.springframework.oxm.Marshaller;
import org.springframework.oxm.XmlMappingException;
import junit.framework.TestCase;
/**
*
*
@@ -67,7 +67,7 @@ public class MarshallingObjectToXmlSerializerTests extends TestCase {
}
}
private class MockMarshaller implements Marshaller{
private static class MockMarshaller implements Marshaller{
private Object marshalledObject;
private boolean throwException = false;
@@ -93,7 +93,7 @@ public class MarshallingObjectToXmlSerializerTests extends TestCase {
}
}
private class StubXmlEventWriter implements XMLEventWriter{
private static class StubXmlEventWriter implements XMLEventWriter{
public void add(XMLEvent arg0) throws XMLStreamException { }

View File

@@ -1,83 +1,83 @@
/*
* 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.io.sample.domain;
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;
/**
* 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 boolean equals(Object obj) {
return EqualsBuilder.reflectionEquals(obj, this);
}
public int hashCode() {
return HashCodeBuilder.reflectionHashCode(this);
}
public String toString() {
return ToStringBuilder.reflectionToString(this);
}
}
/*
* 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.io.sample.domain;
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;
/**
* 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)date.clone();
}
public void setDate(Date date) {
this.date = date == null ? null : (Date)date.clone();
}
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 boolean equals(Object obj) {
return EqualsBuilder.reflectionEquals(obj, this);
}
public int hashCode() {
return HashCodeBuilder.reflectionHashCode(this);
}
public String toString() {
return ToStringBuilder.reflectionToString(this);
}
}

View File

@@ -22,7 +22,6 @@ import java.util.List;
import java.util.Properties;
import org.springframework.batch.io.InputSource;
import org.springframework.batch.io.sql.CompositeKeySqlDrivingQueryInputSource;
import org.springframework.batch.restart.GenericRestartData;
import org.springframework.batch.restart.RestartData;
import org.springframework.jdbc.core.RowMapper;
@@ -48,7 +47,7 @@ public class CompositeKeySqlDrivingQueryInputSourceIntegrationTests extends
return fooInputSource;
}
private class FooRestartDataConverter implements CompositeKeyRestartDataConverter{
private static class FooRestartDataConverter implements CompositeKeyRestartDataConverter{
private static final String ID_RESTART_KEY = "FooRestartDataConverter.id";
private static final String VALUE_RESTART_KEY = "FooRestartDataConverter.value";
@@ -70,7 +69,7 @@ public class CompositeKeySqlDrivingQueryInputSourceIntegrationTests extends
}
}
private class FooCompositeKeyMapper implements RowMapper{
private static class FooCompositeKeyMapper implements RowMapper{
public Object mapRow(ResultSet rs, int rowNum) throws SQLException {
List key = new ArrayList();
key.add(new Long(rs.getLong(1)));

View File

@@ -13,7 +13,8 @@ public class SingleKeySqlDrivingQueryInputSourceIntegrationTests extends Abstrac
*/
protected InputSource createInputSource() throws Exception {
SingleKeySqlDrivingQueryInputSource inputSource = new SingleKeySqlDrivingQueryInputSource(getJdbcTemplate(), "SELECT ID from T_FOOS order by ID");
SingleKeySqlDrivingQueryInputSource inputSource = new SingleKeySqlDrivingQueryInputSource(getJdbcTemplate(),
"SELECT ID from T_FOOS order by ID");
inputSource.setRestartQuery("SELECT ID from T_FOOS where ID > ? order by ID");
return new FooInputSource(inputSource, getJdbcTemplate());

View File

@@ -19,12 +19,12 @@ import javax.xml.stream.XMLEventReader;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.events.XMLEvent;
import junit.framework.TestCase;
import org.easymock.MockControl;
import com.bea.xml.stream.events.StartDocumentEvent;
import junit.framework.TestCase;
/**
* @author Lucas Ward
*
@@ -126,7 +126,7 @@ public class AbstractEventReaderWrapperTests extends TestCase {
mockEventReaderControl.verify();
}
private class StubEventReader extends AbstractEventReaderWrapper{
private static class StubEventReader extends AbstractEventReaderWrapper{
public StubEventReader(XMLEventReader wrappedEventReader) {
super(wrappedEventReader);
}

View File

@@ -126,7 +126,7 @@ public class AbstractEventWriterWrapperTests extends TestCase {
mockEventWriterControl.verify();
}
private class StubEventWriter extends AbstractEventWriterWrapper{
private static class StubEventWriter extends AbstractEventWriterWrapper{
public StubEventWriter(XMLEventWriter wrappedEventWriter) {
super(wrappedEventWriter);
}

View File

@@ -347,7 +347,7 @@ public class StaxEventReaderInputSourceTests extends TestCase {
}
private class MockStaxEventReaderInputSource extends StaxEventReaderInputSource {
private static class MockStaxEventReaderInputSource extends StaxEventReaderInputSource {
private boolean openCalled = false;

View File

@@ -22,7 +22,6 @@ import junit.framework.TestCase;
import org.springframework.batch.io.InputSource;
import org.springframework.batch.io.Skippable;
import org.springframework.batch.item.provider.InputSourceItemProvider;
import org.springframework.batch.restart.GenericRestartData;
import org.springframework.batch.restart.RestartData;
import org.springframework.batch.restart.Restartable;
@@ -99,7 +98,7 @@ public class InputSourceItemProviderTests extends TestCase {
assertEquals("after skip", itemProvider.next());
}
private class MockInputSource implements InputSource, StatisticsProvider, Restartable, Skippable {
private static class MockInputSource implements InputSource, StatisticsProvider, Restartable, Skippable {
private Object value;

View File

@@ -15,13 +15,13 @@
*/
package org.springframework.batch.item.provider;
import junit.framework.TestCase;
import org.easymock.MockControl;
import org.springframework.batch.io.InputSource;
import org.springframework.batch.io.exception.ValidationException;
import org.springframework.batch.item.validator.Validator;
import junit.framework.TestCase;
/**
* @author Lucas Ward
*
@@ -99,7 +99,7 @@ public class ValidatingItemProviderTests extends TestCase {
validatorControl.verify();
}
private class MockInputSource implements InputSource{
private static class MockInputSource implements InputSource{
Object value;