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.FileWriter;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
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.format = format;
|
||||||
this.filename = filename;
|
this.filename = filename;
|
||||||
|
|
||||||
|
|
@ -88,12 +87,7 @@ public abstract class AbstractMarshaller<I extends Identifiable> {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
fileWriter = new FileWriter(file);
|
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) {
|
for (I object : exportList) {
|
||||||
String line = null;
|
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 Class<I> getObjectClass();
|
||||||
protected abstract void insertObjectIntoDB(I object);
|
protected abstract void insertIntoDb(I object);
|
||||||
|
|
||||||
public List<I> importEntities() {
|
|
||||||
List<I> objects = new ArrayList<>();
|
|
||||||
|
|
||||||
|
public void importFile() {
|
||||||
File file = new File(filename);
|
File file = new File(filename);
|
||||||
List<String> lines = null;
|
List<String> lines = null;
|
||||||
|
|
||||||
|
|
@ -170,12 +168,8 @@ public abstract class AbstractMarshaller<I extends Identifiable> {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
objects.add(object);
|
insertIntoDb(object);
|
||||||
insertObjectIntoDB(object);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return objects;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -133,7 +133,7 @@ public class Marshaller {
|
||||||
final AbstractMarshaller<I> marshaller = (AbstractMarshaller<I>)
|
final AbstractMarshaller<I> marshaller = (AbstractMarshaller<I>)
|
||||||
iterator.next();
|
iterator.next();
|
||||||
|
|
||||||
marshaller.init(format, filename + "__" + type.toString());
|
marshaller.prepare(format, filename + "__" + type.toString());
|
||||||
marshaller.exportList(list);
|
marshaller.exportList(list);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -185,8 +185,8 @@ public class Marshaller {
|
||||||
final AbstractMarshaller<I> marshaller = (AbstractMarshaller<I>)
|
final AbstractMarshaller<I> marshaller = (AbstractMarshaller<I>)
|
||||||
iterator.next();
|
iterator.next();
|
||||||
|
|
||||||
marshaller.init(format, filename);
|
marshaller.prepare(format, filename);
|
||||||
marshaller.importEntities();
|
marshaller.importFile();
|
||||||
}
|
}
|
||||||
} catch (ClassNotFoundException e) {
|
} catch (ClassNotFoundException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue