RESOLVED - BATCH-821: remove EventSerializer/Deserializer abstractions and use Marshaller/Unmarshaller directly
This commit is contained in:
@@ -9,7 +9,6 @@ import junit.framework.TestCase;
|
||||
import org.springframework.batch.io.oxm.domain.Trade;
|
||||
import org.springframework.batch.item.ExecutionContext;
|
||||
import org.springframework.batch.item.xml.StaxEventItemReader;
|
||||
import org.springframework.batch.item.xml.oxm.UnmarshallingEventReaderDeserializer;
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.oxm.Unmarshaller;
|
||||
@@ -25,9 +24,8 @@ public abstract class AbstractStaxEventReaderItemReaderTests extends TestCase {
|
||||
source.setResource(resource);
|
||||
|
||||
source.setFragmentRootElementName("trade");
|
||||
UnmarshallingEventReaderDeserializer<Trade> deserializer = new UnmarshallingEventReaderDeserializer<Trade>(
|
||||
getUnmarshaller());
|
||||
source.setFragmentDeserializer(deserializer);
|
||||
|
||||
source.setUnmarshaller(getUnmarshaller());
|
||||
|
||||
source.open(new ExecutionContext());
|
||||
|
||||
|
||||
@@ -13,7 +13,6 @@ import org.custommonkey.xmlunit.XMLUnit;
|
||||
import org.springframework.batch.io.oxm.domain.Trade;
|
||||
import org.springframework.batch.item.ExecutionContext;
|
||||
import org.springframework.batch.item.xml.StaxEventItemWriter;
|
||||
import org.springframework.batch.item.xml.oxm.MarshallingEventWriterSerializer;
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
import org.springframework.core.io.FileSystemResource;
|
||||
import org.springframework.core.io.Resource;
|
||||
@@ -57,8 +56,7 @@ public abstract class AbstractStaxEventWriterItemWriterTests extends TestCase {
|
||||
resource = new FileSystemResource(outputFile);
|
||||
writer.setResource(resource);
|
||||
|
||||
MarshallingEventWriterSerializer<Trade> mapper = new MarshallingEventWriterSerializer<Trade>(getMarshaller());
|
||||
writer.setSerializer(mapper);
|
||||
writer.setMarshaller(getMarshaller());
|
||||
|
||||
writer.open(new ExecutionContext());
|
||||
}
|
||||
|
||||
@@ -15,8 +15,10 @@ import org.springframework.batch.item.xml.stax.FragmentEventReader;
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.dao.DataAccessResourceFailureException;
|
||||
import org.springframework.oxm.Unmarshaller;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.ClassUtils;
|
||||
import org.springframework.xml.transform.StaxSource;
|
||||
|
||||
/**
|
||||
* Item reader for reading XML input based on StAX.
|
||||
@@ -37,7 +39,7 @@ public class StaxEventItemReader<T> extends AbstractItemReaderItemStream<T> impl
|
||||
|
||||
private XMLEventReader eventReader;
|
||||
|
||||
private EventReaderDeserializer<? extends T> eventReaderDeserializer;
|
||||
private Unmarshaller unmarshaller;
|
||||
|
||||
private Resource resource;
|
||||
|
||||
@@ -54,11 +56,11 @@ public class StaxEventItemReader<T> extends AbstractItemReaderItemStream<T> impl
|
||||
}
|
||||
|
||||
/**
|
||||
* @param eventReaderDeserializer maps xml fragments corresponding to
|
||||
* @param unmarshaller maps xml fragments corresponding to
|
||||
* records to objects
|
||||
*/
|
||||
public void setFragmentDeserializer(EventReaderDeserializer<? extends T> eventReaderDeserializer) {
|
||||
this.eventReaderDeserializer = eventReaderDeserializer;
|
||||
public void setUnmarshaller(Unmarshaller unmarshaller) {
|
||||
this.unmarshaller = unmarshaller;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -79,7 +81,7 @@ public class StaxEventItemReader<T> extends AbstractItemReaderItemStream<T> impl
|
||||
* @throws IllegalStateException if the Resource does not exist.
|
||||
*/
|
||||
public void afterPropertiesSet() throws Exception {
|
||||
Assert.notNull(eventReaderDeserializer, "The FragmentDeserializer must not be null.");
|
||||
Assert.notNull(unmarshaller, "The Unmarshaller must not be null.");
|
||||
Assert.hasLength(fragmentRootElementName, "The FragmentRootElementName must not be null");
|
||||
}
|
||||
|
||||
@@ -151,7 +153,11 @@ public class StaxEventItemReader<T> extends AbstractItemReaderItemStream<T> impl
|
||||
|
||||
if (moveCursorToNextFragment(fragmentReader)) {
|
||||
fragmentReader.markStartFragment();
|
||||
item = eventReaderDeserializer.deserializeFragment(fragmentReader);
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
T mappedFragment = (T) unmarshaller.unmarshal(new StaxSource(fragmentReader));
|
||||
|
||||
item = mappedFragment;
|
||||
fragmentReader.markFragmentProcessed();
|
||||
}
|
||||
|
||||
|
||||
@@ -22,6 +22,7 @@ import org.apache.commons.logging.LogFactory;
|
||||
import org.springframework.batch.item.ExecutionContext;
|
||||
import org.springframework.batch.item.FlushFailedException;
|
||||
import org.springframework.batch.item.ItemStream;
|
||||
import org.springframework.batch.item.ItemStreamException;
|
||||
import org.springframework.batch.item.ItemWriter;
|
||||
import org.springframework.batch.item.util.ExecutionContextUserSupport;
|
||||
import org.springframework.batch.item.util.FileUtils;
|
||||
@@ -30,9 +31,12 @@ import org.springframework.batch.support.transaction.TransactionAwareBufferedWri
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.dao.DataAccessResourceFailureException;
|
||||
import org.springframework.oxm.Marshaller;
|
||||
import org.springframework.oxm.XmlMappingException;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.ClassUtils;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
import org.springframework.xml.transform.StaxResult;
|
||||
|
||||
/**
|
||||
* An implementation of {@link ItemWriter} which uses StAX and
|
||||
@@ -70,8 +74,8 @@ public class StaxEventItemWriter<T> extends ExecutionContextUserSupport implemen
|
||||
// file system resource
|
||||
private Resource resource;
|
||||
|
||||
// xml serializer
|
||||
private EventWriterSerializer<? super T> serializer;
|
||||
// xml marshaller
|
||||
private Marshaller marshaller;
|
||||
|
||||
// encoding to be used while reading from the resource
|
||||
private String encoding = DEFAULT_ENCODING;
|
||||
@@ -123,12 +127,12 @@ public class StaxEventItemWriter<T> extends ExecutionContextUserSupport implemen
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Object to XML serializer.
|
||||
* Set Object to XML marshaller.
|
||||
*
|
||||
* @param serializer the Object to XML serializer
|
||||
* @param marshaller the Object to XML marshaller
|
||||
*/
|
||||
public void setSerializer(EventWriterSerializer<? super T> serializer) {
|
||||
this.serializer = serializer;
|
||||
public void setMarshaller(Marshaller marshaller) {
|
||||
this.marshaller = marshaller;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -232,7 +236,7 @@ public class StaxEventItemWriter<T> extends ExecutionContextUserSupport implemen
|
||||
* @see org.springframework.beans.factory.InitializingBean#afterPropertiesSet()
|
||||
*/
|
||||
public void afterPropertiesSet() throws Exception {
|
||||
Assert.notNull(serializer);
|
||||
Assert.notNull(marshaller);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -256,7 +260,12 @@ public class StaxEventItemWriter<T> extends ExecutionContextUserSupport implemen
|
||||
open(startAtPosition);
|
||||
|
||||
if (startAtPosition == 0) {
|
||||
write(headers);
|
||||
try {
|
||||
doWrite(headers);
|
||||
}
|
||||
catch (IOException e) {
|
||||
throw new ItemStreamException("Failed to write headers", e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -331,7 +340,7 @@ public class StaxEventItemWriter<T> extends ExecutionContextUserSupport implemen
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
writer.flush();
|
||||
|
||||
}
|
||||
@@ -390,13 +399,22 @@ public class StaxEventItemWriter<T> extends ExecutionContextUserSupport implemen
|
||||
* Write the value objects and flush them to the file.
|
||||
*
|
||||
* @param items the value object
|
||||
* @throws IOException
|
||||
* @throws XmlMappingException
|
||||
*/
|
||||
public void write(List<? extends T> items) {
|
||||
public void write(List<? extends T> items) throws XmlMappingException, IOException {
|
||||
|
||||
currentRecordCount+=items.size();
|
||||
currentRecordCount += items.size();
|
||||
|
||||
for (T item : items) {
|
||||
serializer.serializeObject(eventWriter, item);
|
||||
doWrite(items);
|
||||
|
||||
}
|
||||
|
||||
private void doWrite(List<?> objects) throws XmlMappingException, IOException {
|
||||
for (Object object : objects) {
|
||||
Assert.state(marshaller.supports(object.getClass()),
|
||||
"Marshaller must support the class of the marshalled object");
|
||||
marshaller.marshal(object, new StaxResult(eventWriter));
|
||||
}
|
||||
try {
|
||||
eventWriter.flush();
|
||||
@@ -404,7 +422,6 @@ public class StaxEventItemWriter<T> extends ExecutionContextUserSupport implemen
|
||||
catch (XMLStreamException e) {
|
||||
throw new FlushFailedException("Failed to flush the events", e);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,24 +1,28 @@
|
||||
package org.springframework.batch.item.file;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.internal.runners.JUnit4ClassRunner;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Comparator;
|
||||
|
||||
import javax.xml.stream.XMLEventReader;
|
||||
import javax.xml.stream.XMLStreamException;
|
||||
import javax.xml.stream.events.Attribute;
|
||||
import javax.xml.stream.events.StartElement;
|
||||
import javax.xml.transform.Source;
|
||||
|
||||
import org.junit.internal.runners.JUnit4ClassRunner;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.batch.item.CommonItemStreamItemReaderTests;
|
||||
import org.springframework.batch.item.ExecutionContext;
|
||||
import org.springframework.batch.item.ItemReader;
|
||||
import org.springframework.batch.item.sample.Foo;
|
||||
import org.springframework.batch.item.xml.EventReaderDeserializer;
|
||||
import org.springframework.batch.item.xml.StaxEventItemReader;
|
||||
import org.springframework.core.io.ByteArrayResource;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.oxm.Unmarshaller;
|
||||
import org.springframework.oxm.XmlMappingException;
|
||||
import org.springframework.xml.transform.StaxSource;
|
||||
|
||||
@RunWith(JUnit4ClassRunner.class)
|
||||
public class MultiResourceItemReaderXmlTests extends CommonItemStreamItemReaderTests {
|
||||
@@ -29,8 +33,10 @@ public class MultiResourceItemReaderXmlTests extends CommonItemStreamItemReaderT
|
||||
StaxEventItemReader<Foo> reader = new StaxEventItemReader<Foo>();
|
||||
|
||||
reader.setFragmentRootElementName("foo");
|
||||
reader.setFragmentDeserializer(new EventReaderDeserializer<Foo>() {
|
||||
public Foo deserializeFragment(XMLEventReader eventReader) {
|
||||
reader.setUnmarshaller(new Unmarshaller() {
|
||||
public Object unmarshal(Source source) throws XmlMappingException, IOException {
|
||||
StaxSource staxSource = (StaxSource) source;
|
||||
XMLEventReader eventReader = staxSource.getXMLEventReader();
|
||||
Attribute attr;
|
||||
try {
|
||||
assertTrue(eventReader.nextEvent().isStartDocument());
|
||||
@@ -44,6 +50,12 @@ public class MultiResourceItemReaderXmlTests extends CommonItemStreamItemReaderT
|
||||
foo.setValue(Integer.parseInt(attr.getValue()));
|
||||
return foo;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public boolean supports(Class clazz) {
|
||||
return true;
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
reader.setSaveState(true);
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
package org.springframework.batch.item.xml;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.internal.runners.JUnit4ClassRunner;
|
||||
|
||||
@@ -8,12 +11,16 @@ import javax.xml.stream.XMLEventReader;
|
||||
import javax.xml.stream.XMLStreamException;
|
||||
import javax.xml.stream.events.Attribute;
|
||||
import javax.xml.stream.events.StartElement;
|
||||
import javax.xml.transform.Source;
|
||||
|
||||
import org.springframework.batch.item.CommonItemStreamItemReaderTests;
|
||||
import org.springframework.batch.item.ExecutionContext;
|
||||
import org.springframework.batch.item.ItemReader;
|
||||
import org.springframework.batch.item.sample.Foo;
|
||||
import org.springframework.core.io.ByteArrayResource;
|
||||
import org.springframework.oxm.Unmarshaller;
|
||||
import org.springframework.oxm.XmlMappingException;
|
||||
import org.springframework.xml.transform.StaxSource;
|
||||
|
||||
@RunWith(JUnit4ClassRunner.class)
|
||||
public class StaxEventItemReaderCommonTests extends CommonItemStreamItemReaderTests {
|
||||
@@ -24,8 +31,10 @@ public class StaxEventItemReaderCommonTests extends CommonItemStreamItemReaderTe
|
||||
StaxEventItemReader<Foo> reader = new StaxEventItemReader<Foo>();
|
||||
reader.setResource(new ByteArrayResource(FOOS.getBytes()));
|
||||
reader.setFragmentRootElementName("foo");
|
||||
reader.setFragmentDeserializer(new EventReaderDeserializer<Foo>() {
|
||||
public Foo deserializeFragment(XMLEventReader eventReader) {
|
||||
reader.setUnmarshaller(new Unmarshaller() {
|
||||
public Object unmarshal(Source source) throws XmlMappingException, IOException {
|
||||
StaxSource staxSource = (StaxSource) source;
|
||||
XMLEventReader eventReader = staxSource.getXMLEventReader();
|
||||
Attribute attr;
|
||||
try {
|
||||
assertTrue(eventReader.nextEvent().isStartDocument());
|
||||
@@ -39,6 +48,12 @@ public class StaxEventItemReaderCommonTests extends CommonItemStreamItemReaderTe
|
||||
foo.setValue(Integer.parseInt(attr.getValue()));
|
||||
return foo;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public boolean supports(Class clazz) {
|
||||
return true;
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
reader.setSaveState(true);
|
||||
|
||||
@@ -11,6 +11,7 @@ import javax.xml.stream.XMLInputFactory;
|
||||
import javax.xml.stream.XMLStreamException;
|
||||
import javax.xml.stream.events.EndElement;
|
||||
import javax.xml.stream.events.XMLEvent;
|
||||
import javax.xml.transform.Source;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
@@ -19,7 +20,10 @@ import org.springframework.batch.item.ItemStreamException;
|
||||
import org.springframework.core.io.AbstractResource;
|
||||
import org.springframework.core.io.ByteArrayResource;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.oxm.Unmarshaller;
|
||||
import org.springframework.oxm.XmlMappingException;
|
||||
import org.springframework.util.ClassUtils;
|
||||
import org.springframework.xml.transform.StaxSource;
|
||||
|
||||
/**
|
||||
* Tests for {@link StaxEventItemReader}.
|
||||
@@ -34,7 +38,7 @@ public class StaxEventItemReaderTests extends TestCase {
|
||||
// test xml input
|
||||
private String xml = "<root> <fragment> <misc1/> </fragment> <misc2/> <fragment> testString </fragment> </root>";
|
||||
|
||||
private EventReaderDeserializer<List<XMLEvent>> deserializer = new MockFragmentDeserializer();
|
||||
private Unmarshaller unmarshaller = new MockFragmentUnmarshaller();
|
||||
|
||||
private static final String FRAGMENT_ROOT_ELEMENT = "fragment";
|
||||
|
||||
@@ -62,7 +66,7 @@ public class StaxEventItemReaderTests extends TestCase {
|
||||
}
|
||||
|
||||
source = createNewInputSouce();
|
||||
source.setFragmentDeserializer(null);
|
||||
source.setUnmarshaller(null);
|
||||
try {
|
||||
source.afterPropertiesSet();
|
||||
fail();
|
||||
@@ -74,12 +78,12 @@ public class StaxEventItemReaderTests extends TestCase {
|
||||
|
||||
/**
|
||||
* Regular usage scenario. ItemReader should pass XML fragments to
|
||||
* deserializer wrapped with StartDocument and EndDocument events.
|
||||
* unmarshaller wrapped with StartDocument and EndDocument events.
|
||||
*/
|
||||
public void testFragmentWrapping() throws Exception {
|
||||
source.afterPropertiesSet();
|
||||
source.open(executionContext);
|
||||
// see asserts in the mock deserializer
|
||||
// see asserts in the mock unmarshaller
|
||||
assertNotNull(source.read());
|
||||
assertNotNull(source.read());
|
||||
assertNull(source.read()); // there are only two fragments
|
||||
@@ -163,7 +167,7 @@ public class StaxEventItemReaderTests extends TestCase {
|
||||
newSource.setResource(resource);
|
||||
|
||||
newSource.setFragmentRootElementName(FRAGMENT_ROOT_ELEMENT);
|
||||
newSource.setFragmentDeserializer(deserializer);
|
||||
newSource.setUnmarshaller(unmarshaller);
|
||||
|
||||
newSource.open(executionContext);
|
||||
|
||||
@@ -239,27 +243,52 @@ public class StaxEventItemReaderTests extends TestCase {
|
||||
newSource.setResource(resource);
|
||||
|
||||
newSource.setFragmentRootElementName(FRAGMENT_ROOT_ELEMENT);
|
||||
newSource.setFragmentDeserializer(deserializer);
|
||||
newSource.setUnmarshaller(unmarshaller);
|
||||
newSource.setSaveState(true);
|
||||
|
||||
return newSource;
|
||||
}
|
||||
|
||||
/**
|
||||
* A simple XMLEvent deserializer mock - check for the start and end
|
||||
* A simple XMLEvent unmarshaller mock - check for the start and end
|
||||
* document events for the fragment root & end tags + skips the fragment
|
||||
* contents.
|
||||
*/
|
||||
private static class MockFragmentDeserializer implements EventReaderDeserializer<List<XMLEvent>> {
|
||||
private static class MockFragmentUnmarshaller implements Unmarshaller {
|
||||
|
||||
/**
|
||||
* Skips the XML fragment contents.
|
||||
*/
|
||||
private List<XMLEvent> readRecordsInsideFragment(XMLEventReader eventReader) throws XMLStreamException {
|
||||
XMLEvent eventInsideFragment;
|
||||
List<XMLEvent> events = new ArrayList<XMLEvent>();
|
||||
do {
|
||||
eventInsideFragment = eventReader.peek();
|
||||
if (eventInsideFragment instanceof EndElement
|
||||
&& ((EndElement) eventInsideFragment).getName().getLocalPart().equals(FRAGMENT_ROOT_ELEMENT)) {
|
||||
break;
|
||||
}
|
||||
events.add(eventReader.nextEvent());
|
||||
} while (eventInsideFragment != null);
|
||||
|
||||
return events;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public boolean supports(Class clazz) {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* A simple mapFragment implementation checking the
|
||||
* StaxEventReaderItemReader basic read functionality.
|
||||
*
|
||||
* @param eventReader
|
||||
* @param source
|
||||
* @return list of the events from fragment body
|
||||
*/
|
||||
public List<XMLEvent> deserializeFragment(XMLEventReader eventReader) {
|
||||
public Object unmarshal(Source source) throws XmlMappingException, IOException {
|
||||
StaxSource staxSource = (StaxSource) source;
|
||||
XMLEventReader eventReader = staxSource.getXMLEventReader();
|
||||
List<XMLEvent> fragmentContent;
|
||||
try {
|
||||
// first event should be StartDocument
|
||||
@@ -290,24 +319,6 @@ public class StaxEventItemReaderTests extends TestCase {
|
||||
return fragmentContent;
|
||||
}
|
||||
|
||||
/**
|
||||
* Skips the XML fragment contents.
|
||||
*/
|
||||
private List<XMLEvent> readRecordsInsideFragment(XMLEventReader eventReader) throws XMLStreamException {
|
||||
XMLEvent eventInsideFragment;
|
||||
List<XMLEvent> events = new ArrayList<XMLEvent>();
|
||||
do {
|
||||
eventInsideFragment = eventReader.peek();
|
||||
if (eventInsideFragment instanceof EndElement
|
||||
&& ((EndElement) eventInsideFragment).getName().getLocalPart().equals(FRAGMENT_ROOT_ELEMENT)) {
|
||||
break;
|
||||
}
|
||||
events.add(eventReader.nextEvent());
|
||||
} while (eventInsideFragment != null);
|
||||
|
||||
return events;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private static class MockStaxEventItemReader extends StaxEventItemReader<List<XMLEvent>> {
|
||||
|
||||
@@ -21,7 +21,6 @@ import org.apache.commons.io.FileUtils;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.springframework.batch.item.ExecutionContext;
|
||||
import org.springframework.batch.item.xml.oxm.MarshallingEventWriterSerializer;
|
||||
import org.springframework.core.io.FileSystemResource;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.oxm.Marshaller;
|
||||
@@ -202,8 +201,7 @@ public class StaxEventItemWriterTests {
|
||||
source.setResource(resource);
|
||||
|
||||
Marshaller marshaller = new SimpleMarshaller();
|
||||
MarshallingEventWriterSerializer<Object> serializer = new MarshallingEventWriterSerializer<Object>(marshaller);
|
||||
source.setSerializer(serializer);
|
||||
source.setMarshaller(marshaller);
|
||||
|
||||
source.setEncoding("UTF-8");
|
||||
source.setRootTagName("root");
|
||||
|
||||
@@ -17,7 +17,6 @@ import org.apache.commons.io.FileUtils;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.springframework.batch.item.ExecutionContext;
|
||||
import org.springframework.batch.item.xml.oxm.MarshallingEventWriterSerializer;
|
||||
import org.springframework.batch.support.transaction.ResourcelessTransactionManager;
|
||||
import org.springframework.core.io.FileSystemResource;
|
||||
import org.springframework.core.io.Resource;
|
||||
@@ -74,7 +73,12 @@ public class TransactionalStaxEventItemWriterTests {
|
||||
writer.open(executionContext);
|
||||
new TransactionTemplate(transactionManager).execute(new TransactionCallback() {
|
||||
public Object doInTransaction(TransactionStatus status) {
|
||||
writer.write(items);
|
||||
try {
|
||||
writer.write(items);
|
||||
}
|
||||
catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
});
|
||||
@@ -94,7 +98,12 @@ public class TransactionalStaxEventItemWriterTests {
|
||||
try {
|
||||
new TransactionTemplate(transactionManager).execute(new TransactionCallback() {
|
||||
public Object doInTransaction(TransactionStatus status) {
|
||||
writer.write(items);
|
||||
try {
|
||||
writer.write(items);
|
||||
}
|
||||
catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
throw new RuntimeException("Planned");
|
||||
}
|
||||
});
|
||||
@@ -107,7 +116,12 @@ public class TransactionalStaxEventItemWriterTests {
|
||||
writer.open(executionContext);
|
||||
new TransactionTemplate(transactionManager).execute(new TransactionCallback() {
|
||||
public Object doInTransaction(TransactionStatus status) {
|
||||
writer.write(items);
|
||||
try {
|
||||
writer.write(items);
|
||||
}
|
||||
catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
});
|
||||
@@ -127,7 +141,12 @@ public class TransactionalStaxEventItemWriterTests {
|
||||
writer.open(executionContext);
|
||||
new TransactionTemplate(transactionManager).execute(new TransactionCallback() {
|
||||
public Object doInTransaction(TransactionStatus status) {
|
||||
writer.write(items);
|
||||
try {
|
||||
writer.write(items);
|
||||
}
|
||||
catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
});
|
||||
@@ -137,7 +156,12 @@ public class TransactionalStaxEventItemWriterTests {
|
||||
try {
|
||||
new TransactionTemplate(transactionManager).execute(new TransactionCallback() {
|
||||
public Object doInTransaction(TransactionStatus status) {
|
||||
writer.write(items);
|
||||
try {
|
||||
writer.write(items);
|
||||
}
|
||||
catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
throw new RuntimeException("Planned");
|
||||
}
|
||||
});
|
||||
@@ -189,8 +213,7 @@ public class TransactionalStaxEventItemWriterTests {
|
||||
source.setResource(resource);
|
||||
|
||||
Marshaller marshaller = new SimpleMarshaller();
|
||||
MarshallingEventWriterSerializer<Object> serializer = new MarshallingEventWriterSerializer<Object>(marshaller);
|
||||
source.setSerializer(serializer);
|
||||
source.setMarshaller(marshaller);
|
||||
|
||||
source.setEncoding("UTF-8");
|
||||
source.setRootTagName("root");
|
||||
|
||||
@@ -21,18 +21,7 @@
|
||||
value="trade" />
|
||||
<property name="resource"
|
||||
value="data/staxJob/input/20070918.testStream.xmlFileStep.xml" />
|
||||
<property name="fragmentDeserializer">
|
||||
<bean
|
||||
class="org.springframework.batch.item.xml.oxm.UnmarshallingEventReaderDeserializer">
|
||||
<constructor-arg>
|
||||
<bean
|
||||
class="org.springframework.oxm.xstream.XStreamMarshaller">
|
||||
<property name="aliases"
|
||||
ref="aliases" />
|
||||
</bean>
|
||||
</constructor-arg>
|
||||
</bean>
|
||||
</property>
|
||||
<property name="unmarshaller" ref="tradeMarshaller"/>
|
||||
</bean>
|
||||
</property>
|
||||
<property name="itemWriter" ref="tradeStaxWriter" />
|
||||
@@ -44,20 +33,14 @@
|
||||
id="tradeStaxWriter">
|
||||
<property name="resource"
|
||||
value="file:target/test-outputs/20070918.testStream.xmlFileStep.output.xml" />
|
||||
<property name="serializer" ref="tradeMarshallingSerializer" />
|
||||
<property name="marshaller" ref="tradeMarshaller" />
|
||||
<property name="rootTagName" value="trades" />
|
||||
<property name="overwriteOutput" value="true" />
|
||||
</bean>
|
||||
|
||||
<bean
|
||||
class="org.springframework.batch.item.xml.oxm.MarshallingEventWriterSerializer"
|
||||
id="tradeMarshallingSerializer">
|
||||
<constructor-arg>
|
||||
<bean
|
||||
class="org.springframework.oxm.xstream.XStreamMarshaller">
|
||||
<property name="aliases" ref="aliases" />
|
||||
</bean>
|
||||
</constructor-arg>
|
||||
|
||||
<bean id="tradeMarshaller"
|
||||
class="org.springframework.oxm.xstream.XStreamMarshaller">
|
||||
<property name="aliases" ref="aliases" />
|
||||
</bean>
|
||||
|
||||
<util:map id="aliases">
|
||||
|
||||
Reference in New Issue
Block a user