From cdb6bc9a0d5ea0bfd49bc1a2420a4de438a329d3 Mon Sep 17 00:00:00 2001 From: tosmers Date: Wed, 16 Mar 2016 14:17:26 +0000 Subject: [PATCH] adds implementation of secondary import methods executed through the AbstractMarshaller git-svn-id: https://svn.libreccm.org/ccm/ccm_ng@3927 8810af33-2d31-482b-a856-94f89814c4df --- .../portation/AbstractMarshaller.java | 26 +++++++------------ .../org/libreccm/portation/Marshaller.java | 6 ++--- 2 files changed, 13 insertions(+), 19 deletions(-) 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();