Exceptions hierarchy (for future work with transactions)
This commit is contained in:
@@ -0,0 +1,11 @@
|
|||||||
|
package me.bearns.fias.exceptions;
|
||||||
|
|
||||||
|
public class UnmarshallingException extends CommonException {
|
||||||
|
public UnmarshallingException(Exception e) {
|
||||||
|
super(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
public UnmarshallingException(String s) {
|
||||||
|
super(s);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,5 +1,7 @@
|
|||||||
package me.bearns.fias.service;
|
package me.bearns.fias.service;
|
||||||
|
|
||||||
|
import me.bearns.fias.exceptions.CommonException;
|
||||||
|
import me.bearns.fias.exceptions.UnmarshallingException;
|
||||||
import me.bearns.fias.util.UnmarshallerParameters;
|
import me.bearns.fias.util.UnmarshallerParameters;
|
||||||
|
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
@@ -7,5 +9,5 @@ import java.util.function.Predicate;
|
|||||||
|
|
||||||
public interface StreamSaver {
|
public interface StreamSaver {
|
||||||
|
|
||||||
public void process(InputStream is, UnmarshallerParameters conf, Predicate filter);
|
public void process(InputStream is, UnmarshallerParameters conf, Predicate filter) throws CommonException;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
package me.bearns.fias.service;
|
package me.bearns.fias.service;
|
||||||
|
|
||||||
|
import me.bearns.fias.exceptions.CommonException;
|
||||||
|
import me.bearns.fias.exceptions.UnmarshallingException;
|
||||||
import me.bearns.fias.util.UnmarshallerParameters;
|
import me.bearns.fias.util.UnmarshallerParameters;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
@@ -17,7 +19,7 @@ import java.util.function.Predicate;
|
|||||||
@Component
|
@Component
|
||||||
public class StreamSaverImpl implements StreamSaver{
|
public class StreamSaverImpl implements StreamSaver{
|
||||||
@Override
|
@Override
|
||||||
public void process(InputStream is, UnmarshallerParameters conf, Predicate filter) {
|
public void process(InputStream is, UnmarshallerParameters conf, Predicate filter) throws CommonException {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// create xml event reader for input stream
|
// create xml event reader for input stream
|
||||||
@@ -34,9 +36,7 @@ public class StreamSaverImpl implements StreamSaver{
|
|||||||
long countRead=0, countWrite=0, countErrors=0;
|
long countRead=0, countWrite=0, countErrors=0;
|
||||||
|
|
||||||
// loop though the xml stream
|
// loop though the xml stream
|
||||||
while (true) {
|
while ((e = xmlEventReader.peek()) != null) {
|
||||||
|
|
||||||
if (!((e = xmlEventReader.peek()) != null)) break;
|
|
||||||
|
|
||||||
countRead++;
|
countRead++;
|
||||||
|
|
||||||
@@ -78,9 +78,11 @@ public class StreamSaverImpl implements StreamSaver{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (XMLStreamException ex) {
|
} catch (XMLStreamException ex) {
|
||||||
ex.printStackTrace(); //createXMLEventReader & peak
|
//todo log
|
||||||
|
throw new UnmarshallingException(ex); //createXMLEventReader & peak
|
||||||
} catch (JAXBException ex) {
|
} catch (JAXBException ex) {
|
||||||
ex.printStackTrace(); //createUnmarshaller();
|
//todo log
|
||||||
|
throw new UnmarshallingException(ex); //createUnmarshaller();
|
||||||
}
|
}
|
||||||
|
|
||||||
//write to DB from cache
|
//write to DB from cache
|
||||||
|
|||||||
Reference in New Issue
Block a user