diff --git a/ccm-core/src/main/java/org/libreccm/portation/AbstractMarshaller.java b/ccm-core/src/main/java/org/libreccm/portation/AbstractMarshaller.java index 90c39335d..4cc5848d1 100644 --- a/ccm-core/src/main/java/org/libreccm/portation/AbstractMarshaller.java +++ b/ccm-core/src/main/java/org/libreccm/portation/AbstractMarshaller.java @@ -29,7 +29,6 @@ import java.io.File; import java.io.FileWriter; import java.io.IOException; import java.nio.file.Files; -import java.util.ArrayList; import java.util.List; /** @@ -58,7 +57,7 @@ public abstract class AbstractMarshaller { - public void init(final Format format, String filename) { + public void prepare(final Format format, String filename) { this.format = format; this.filename = filename; @@ -88,12 +87,7 @@ public abstract class AbstractMarshaller { try { fileWriter = new FileWriter(file); - } catch (IOException e) { - log.error(String.format("Unable open a fileWriter for the file " + - "with the name %s.", file.getName())); - } - if (fileWriter != null) { for (I object : exportList) { String line = null; @@ -127,15 +121,19 @@ public abstract class AbstractMarshaller { } } } + + fileWriter.close(); + } catch (IOException e) { + log.error(String.format("Unable open a fileWriter for the file " + + "with the name %s.", file.getName())); } + } protected abstract Class getObjectClass(); - protected abstract void insertObjectIntoDB(I object); - - public List importEntities() { - List objects = new ArrayList<>(); + protected abstract void insertIntoDb(I object); + public void importFile() { File file = new File(filename); List lines = null; @@ -170,12 +168,8 @@ public abstract class AbstractMarshaller { break; } - objects.add(object); - insertObjectIntoDB(object); + insertIntoDb(object); } } - - return objects; } - } diff --git a/ccm-core/src/main/java/org/libreccm/portation/Marshaller.java b/ccm-core/src/main/java/org/libreccm/portation/Marshaller.java index 3ab84bb32..ed82939cc 100644 --- a/ccm-core/src/main/java/org/libreccm/portation/Marshaller.java +++ b/ccm-core/src/main/java/org/libreccm/portation/Marshaller.java @@ -133,7 +133,7 @@ public class Marshaller { final AbstractMarshaller marshaller = (AbstractMarshaller) iterator.next(); - marshaller.init(format, filename + "__" + type.toString()); + marshaller.prepare(format, filename + "__" + type.toString()); marshaller.exportList(list); } } @@ -185,8 +185,8 @@ public class Marshaller { final AbstractMarshaller marshaller = (AbstractMarshaller) iterator.next(); - marshaller.init(format, filename); - marshaller.importEntities(); + marshaller.prepare(format, filename); + marshaller.importFile(); } } catch (ClassNotFoundException e) { e.printStackTrace();