Skip to content

Commit

Permalink
Added run-ddl-xml and symmetric-default.properties
Browse files Browse the repository at this point in the history
  • Loading branch information
chenson42 committed Oct 27, 2007
1 parent 01b7573 commit 2041bb3
Showing 1 changed file with 38 additions and 11 deletions.
@@ -1,5 +1,5 @@
/*
* SymmetricDS is an open source database synchronization solution.
* symmetric is an open source database synchronization solution.
*
* Copyright (C) Chris Henson <chenson42@users.sourceforge.net>
*
Expand All @@ -21,6 +21,7 @@

import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;
Expand All @@ -33,11 +34,14 @@
import org.apache.commons.cli.ParseException;
import org.apache.commons.cli.PosixParser;
import org.apache.commons.lang.exception.ExceptionUtils;
import org.apache.ddlutils.Platform;
import org.apache.ddlutils.io.DatabaseIO;
import org.apache.ddlutils.model.Database;
import org.jumpmind.symmetric.common.Constants;
import org.jumpmind.symmetric.db.IDbDialect;

/**
* Run SymmetricDS utilities and/or launch an embedded version of Symmetric. If you run this
* Run symmetric utilities and/or launch an embedded version of Symmetric. If you run this
* program without any arguments 'help' will print out.
*/
public class SymmetricLauncher {
Expand All @@ -46,6 +50,8 @@ public class SymmetricLauncher {

private static final String OPTION_DDL_GEN = "generate-config-dll";

private static final String OPTION_RUN_DDL_XML = "run-dll-xml";

private static final String OPTION_PROPERTIES_GEN = "generate-default-properties";

private static final String OPTION_PROPERTIES_FILE = "properties";
Expand All @@ -57,12 +63,12 @@ public static void main(String[] args) throws Exception {
Options options = buildOptions();
try {
CommandLine line = parser.parse(options, args);

int serverPort = 31415;

if (line.hasOption(OPTION_PORT_SERVER)) {
serverPort = new Integer(line.getOptionValue(OPTION_PORT_SERVER));
}
}

if (line.hasOption(OPTION_PROPERTIES_GEN)) {
generateDefaultProperties(line.getOptionValue(OPTION_PROPERTIES_GEN));
Expand All @@ -84,19 +90,24 @@ public static void main(String[] args) throws Exception {
return;
}

if (line.hasOption(OPTION_RUN_DDL_XML)) {
runDdlXml(new SymmetricEngine(), line.getOptionValue(OPTION_RUN_DDL_XML));
return;
}

if (line.hasOption(OPTION_START_SERVER)) {
new SymmetricWebServer().start(serverPort);
return;
}

printHelp(options);

} catch (ParseException exp) {
System.err.println(exp.getMessage());
printHelp(options);
} catch (Exception ex) {
System.err.println(ExceptionUtils.getRootCause(ex).getMessage());
Throwable root = ExceptionUtils.getRootCause(ex);
System.err.println(root == null ? ex.getMessage() : root.getMessage());
printHelp(options);
}
}
Expand All @@ -106,23 +117,26 @@ private static void printHelp(Options options) {
}

private static Options buildOptions() {
Options options = new Options();
options.addOption("S", OPTION_START_SERVER, false, "Start an embedded instance of SymmetricDS.");
Options options = new Options();
options.addOption("S", OPTION_START_SERVER, false, "Start an embedded instance of symmetric.");
options.addOption("P", OPTION_PORT_SERVER, false,
"Optionally pass in the HTTP port number to use for the server instance.");

options
.addOption("c", OPTION_DDL_GEN, true,
"Output the DDL to create the SymmetricDS tables. Takes an argument of the name of the file to write the ddl to.");
"Output the DDL to create the symmetric tables. Takes an argument of the name of the file to write the ddl to.");
options
.addOption(
"p",
OPTION_PROPERTIES_FILE,
true,
"Takes an argument with the path to the properties file that will drive SymmetricDS. If this is not provided, SymmetricDS will use defaults, then override with the first symmetric.properties in your classpath, then override with symmetric.properties values in your user.home directory.");
"Takes an argument with the path to the properties file that will drive symmetric. If this is not provided, symmetric will use defaults, then override with the first symmetric.properties in your classpath, then override with symmetric.properties values in your user.home directory.");
options
.addOption("g", OPTION_PROPERTIES_GEN, true,
"Takes an argument with the path to a file which all the default overrideable properties will be written.");
options
.addOption("r", OPTION_RUN_DDL_XML, true,
"Takes an argument of a DdlUtils xml file and applies it to the database configured in your symmetric properties file.");

return options;
}
Expand All @@ -138,7 +152,8 @@ private static void generateDDL(SymmetricEngine engine, String fileName) throws
private static void generateDefaultProperties(String fileName) throws IOException {
File file = new File(fileName);
file.getParentFile().mkdirs();
BufferedReader is = new BufferedReader(new InputStreamReader(SymmetricLauncher.class.getResourceAsStream("/symmetric-default.properties"), Charset.defaultCharset()));
BufferedReader is = new BufferedReader(new InputStreamReader(SymmetricLauncher.class
.getResourceAsStream("/symmetric-default.properties"), Charset.defaultCharset()));
FileWriter os = new FileWriter(file, false);
String line = is.readLine();
while (line != null) {
Expand All @@ -150,4 +165,16 @@ private static void generateDefaultProperties(String fileName) throws IOExceptio
os.close();
}

private static void runDdlXml(SymmetricEngine engine, String fileName) throws FileNotFoundException {
IDbDialect dialect = (IDbDialect) engine.getApplicationContext().getBean(Constants.DB_DIALECT);
File file = new File(fileName);
if (file.exists() && file.isFile()) {
Platform pf = dialect.getPlatform();
Database db = new DatabaseIO().read(new File(fileName));
pf.createTables(db, true, true);
} else {
throw new FileNotFoundException("Could not find " + fileName);
}
}

}

0 comments on commit 2041bb3

Please sign in to comment.