Skip to content

Commit

Permalink
Added command line option to load batches from a text file.
Browse files Browse the repository at this point in the history
  • Loading branch information
chenson42 committed Nov 4, 2007
1 parent c2fb7dc commit bc27674
Showing 1 changed file with 24 additions and 0 deletions.
Expand Up @@ -21,6 +21,7 @@

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileWriter;
import java.io.IOException;
Expand All @@ -43,6 +44,7 @@
import org.jumpmind.symmetric.db.SqlScript;
import org.jumpmind.symmetric.service.IBootstrapService;
import org.jumpmind.symmetric.service.IDataExtractorService;
import org.jumpmind.symmetric.service.IDataLoaderService;
import org.jumpmind.symmetric.service.IDataService;
import org.jumpmind.symmetric.service.IRegistrationService;
import org.jumpmind.symmetric.transport.IOutgoingTransport;
Expand Down Expand Up @@ -75,6 +77,8 @@ public class SymmetricLauncher {
private static final String OPTION_PROPERTIES_FILE = "properties";

private static final String OPTION_START_SERVER = "server";

private static final String OPTION_LOAD_BATCH = "load-batch";

public static void main(String[] args) throws Exception {
CommandLineParser parser = new PosixParser();
Expand Down Expand Up @@ -142,6 +146,10 @@ public static void main(String[] args) throws Exception {
runSql(new SymmetricEngine(), line.getOptionValue(OPTION_RUN_SQL));
return;
}

if (line.hasOption(OPTION_LOAD_BATCH)) {
loadBatch(new SymmetricEngine(), line.getOptionValue(OPTION_LOAD_BATCH));
}

if (line.hasOption(OPTION_START_SERVER)) {
new SymmetricWebServer().start(serverPort);
Expand Down Expand Up @@ -198,6 +206,8 @@ private static Options buildOptions() {
"Send an initial load of data to reload the passed in node id.");
options.addOption("d", OPTION_DUMP_BATCH, true,
"Print the contents of a batch out to the console. Takes the batch id as an argument.");
options.addOption("b", OPTION_LOAD_BATCH, true,
"Load the CSV contents of the specfied file.");

return options;
}
Expand All @@ -209,6 +219,20 @@ private static void dumpBatch(SymmetricEngine engine, String batchId) throws Exc
dataExtractorService.extractBatchRange(transport, batchId, batchId);
transport.close();
}

private static void loadBatch(SymmetricEngine engine, String fileName) throws Exception {
IDataLoaderService service = (IDataLoaderService)engine.getApplicationContext().getBean(Constants.DATALOADER_SERVICE);
File file = new File(fileName);
if (file.exists() && file.isFile()) {
FileInputStream in = new FileInputStream(file);
service.loadData(in, System.out);
System.out.flush();
in.close();

} else {
throw new FileNotFoundException("Could not find " + fileName);
}
}

private static void openRegistration(SymmetricEngine engine, String argument) {
argument = argument.replace('\"', ' ');
Expand Down

0 comments on commit bc27674

Please sign in to comment.