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-94f89814c4dfpull/2/head
parent
5dec29593d
commit
cdb6bc9a0d
|
|
@ -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<I extends Identifiable> {
|
|||
|
||||
|
||||
|
||||
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<I extends Identifiable> {
|
|||
|
||||
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<I extends Identifiable> {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
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<I> getObjectClass();
|
||||
protected abstract void insertObjectIntoDB(I object);
|
||||
|
||||
public List<I> importEntities() {
|
||||
List<I> objects = new ArrayList<>();
|
||||
protected abstract void insertIntoDb(I object);
|
||||
|
||||
public void importFile() {
|
||||
File file = new File(filename);
|
||||
List<String> lines = null;
|
||||
|
||||
|
|
@ -170,12 +168,8 @@ public abstract class AbstractMarshaller<I extends Identifiable> {
|
|||
break;
|
||||
}
|
||||
|
||||
objects.add(object);
|
||||
insertObjectIntoDB(object);
|
||||
insertIntoDb(object);
|
||||
}
|
||||
}
|
||||
|
||||
return objects;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -133,7 +133,7 @@ public class Marshaller {
|
|||
final AbstractMarshaller<I> marshaller = (AbstractMarshaller<I>)
|
||||
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<I> marshaller = (AbstractMarshaller<I>)
|
||||
iterator.next();
|
||||
|
||||
marshaller.init(format, filename);
|
||||
marshaller.importEntities();
|
||||
marshaller.prepare(format, filename);
|
||||
marshaller.importFile();
|
||||
}
|
||||
} catch (ClassNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
|
|
|
|||
Loading…
Reference in New Issue