Skip to content

Commit fbf15a4

Browse files
committed
Remove usage of DataAccessResourceFailureException in xml reader and writer
Resolves spring-projects#4132
1 parent 0b2a2c2 commit fbf15a4

File tree

4 files changed

+18
-20
lines changed

4 files changed

+18
-20
lines changed

spring-batch-infrastructure/src/main/java/org/springframework/batch/item/xml/StaxEventItemWriter.java

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@
5252
import org.springframework.batch.support.transaction.TransactionAwareBufferedWriter;
5353
import org.springframework.beans.factory.InitializingBean;
5454
import org.springframework.core.io.WritableResource;
55-
import org.springframework.dao.DataAccessResourceFailureException;
5655
import org.springframework.oxm.Marshaller;
5756
import org.springframework.oxm.XmlMappingException;
5857
import org.springframework.util.Assert;
@@ -458,7 +457,7 @@ private void open(long position) {
458457
setPosition(position);
459458
}
460459
catch (IOException ioe) {
461-
throw new DataAccessResourceFailureException("Unable to write to file resource: [" + resource + "]", ioe);
460+
throw new ItemStreamException("Unable to write to file resource: [" + resource + "]", ioe);
462461
}
463462

464463
XMLOutputFactory outputFactory = createXmlOutputFactory();
@@ -506,14 +505,14 @@ public void run() {
506505
}
507506
}
508507
catch (XMLStreamException xse) {
509-
throw new DataAccessResourceFailureException("Unable to write to file resource: [" + resource + "]", xse);
508+
throw new ItemStreamException("Unable to write to file resource: [" + resource + "]", xse);
510509
}
511510
catch (UnsupportedEncodingException e) {
512-
throw new DataAccessResourceFailureException(
511+
throw new ItemStreamException(
513512
"Unable to write to file resource: [" + resource + "] with encoding=[" + encoding + "]", e);
514513
}
515514
catch (IOException e) {
516-
throw new DataAccessResourceFailureException("Unable to write to file resource: [" + resource + "]", e);
515+
throw new ItemStreamException("Unable to write to file resource: [" + resource + "]", e);
517516
}
518517
}
519518

@@ -673,7 +672,7 @@ protected void endDocument(XMLEventWriter writer) throws XMLStreamException {
673672
bufferedWriter.write("</" + nsPrefix + getRootTagName() + ">");
674673
}
675674
catch (IOException ioe) {
676-
throw new DataAccessResourceFailureException("Unable to close file resource: [" + resource + "]", ioe);
675+
throw new XMLStreamException("Unable to close file resource: [" + resource + "]", ioe);
677676
}
678677
}
679678

@@ -825,7 +824,7 @@ private long getPosition() {
825824
}
826825
}
827826
catch (Exception e) {
828-
throw new DataAccessResourceFailureException("Unable to write to file resource: [" + resource + "]", e);
827+
throw new ItemStreamException("Unable to write to file resource: [" + resource + "]", e);
829828
}
830829

831830
return position;
@@ -842,7 +841,7 @@ private void setPosition(long newPosition) {
842841
channel.position(newPosition);
843842
}
844843
catch (IOException e) {
845-
throw new DataAccessResourceFailureException("Unable to write to file resource: [" + resource + "]", e);
844+
throw new ItemStreamException("Unable to write to file resource: [" + resource + "]", e);
846845
}
847846

848847
}

spring-batch-infrastructure/src/main/java/org/springframework/batch/item/xml/stax/DefaultFragmentEventReader.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2006-2007 the original author or authors.
2+
* Copyright 2006-2022 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -28,7 +28,7 @@
2828
import javax.xml.stream.events.StartElement;
2929
import javax.xml.stream.events.XMLEvent;
3030

31-
import org.springframework.dao.DataAccessResourceFailureException;
31+
import org.springframework.batch.item.ItemStreamException;
3232

3333
/**
3434
* Default implementation of {@link FragmentEventReader}
@@ -71,7 +71,7 @@ public DefaultFragmentEventReader(XMLEventReader wrappedEventReader) {
7171
startDocumentEvent = (StartDocument) wrappedEventReader.peek();
7272
}
7373
catch (XMLStreamException e) {
74-
throw new DataAccessResourceFailureException("Error reading start document from event reader", e);
74+
throw new ItemStreamException("Error reading start document from event reader", e);
7575
}
7676

7777
endDocumentEvent = XMLEventFactory.newInstance().createEndDocument();
@@ -91,7 +91,7 @@ public boolean hasNext() {
9191
}
9292
}
9393
catch (XMLStreamException e) {
94-
throw new DataAccessResourceFailureException("Error reading XML stream", e);
94+
throw new ItemStreamException("Error reading XML stream", e);
9595
}
9696
return false;
9797
}
@@ -102,7 +102,7 @@ public Object next() {
102102
return nextEvent();
103103
}
104104
catch (XMLStreamException e) {
105-
throw new DataAccessResourceFailureException("Error reading XML stream", e);
105+
throw new ItemStreamException("Error reading XML stream", e);
106106
}
107107
}
108108

@@ -185,7 +185,7 @@ public void markFragmentProcessed() {
185185
}
186186
}
187187
catch (XMLStreamException e) {
188-
throw new DataAccessResourceFailureException("Error reading XML stream", e);
188+
throw new ItemStreamException("Error reading XML stream", e);
189189
}
190190
}
191191
fakeDocumentEnd = false;

spring-batch-infrastructure/src/main/java/org/springframework/batch/item/xml/stax/UnopenedElementClosingEventWriter.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2014 the original author or authors.
2+
* Copyright 2014-2022 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -26,7 +26,6 @@
2626
import javax.xml.stream.XMLStreamException;
2727
import javax.xml.stream.events.XMLEvent;
2828

29-
import org.springframework.dao.DataAccessResourceFailureException;
3029
import org.springframework.util.StringUtils;
3130

3231
/**
@@ -68,7 +67,7 @@ public void add(XMLEvent event) throws XMLStreamException {
6867
ioWriter.flush();
6968
}
7069
catch (IOException ioe) {
71-
throw new DataAccessResourceFailureException("Unable to close tag: " + element, ioe);
70+
throw new XMLStreamException("Unable to close tag: " + element, ioe);
7271
}
7372
}
7473
else {

spring-batch-infrastructure/src/test/java/org/springframework/batch/item/xml/stax/UnopenedElementClosingEventWriterTests.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2014 the original author or authors.
2+
* Copyright 2014-2022 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -27,14 +27,14 @@
2727
import javax.xml.namespace.QName;
2828
import javax.xml.stream.XMLEventFactory;
2929
import javax.xml.stream.XMLEventWriter;
30+
import javax.xml.stream.XMLStreamException;
3031
import javax.xml.stream.events.EndElement;
3132
import javax.xml.stream.events.StartElement;
3233
import javax.xml.stream.events.XMLEvent;
3334

3435
import org.junit.Before;
3536
import org.junit.Test;
3637
import org.mockito.Mockito;
37-
import org.springframework.dao.DataAccessResourceFailureException;
3838

3939
/**
4040
* Tests for {@link UnopenedElementClosingEventWriter}
@@ -122,7 +122,7 @@ public void testOtherEvent() throws Exception {
122122
verify(wrappedWriter).add(event);
123123
}
124124

125-
@Test(expected = DataAccessResourceFailureException.class)
125+
@Test(expected = XMLStreamException.class)
126126
public void testIOException() throws Exception {
127127
EndElement endElementB = eventFactory.createEndElement(unopenedB, null);
128128
Mockito.doThrow(new IOException("Simulated IOException")).when(ioWriter).write("</unopened-b>");

0 commit comments

Comments
 (0)