Skip to content

Commit

Permalink
Merge branch '3.8' of https://github.com/JumpMind/symmetric-ds.git in…
Browse files Browse the repository at this point in the history
…to 3.8
  • Loading branch information
jumpmind-josh committed Oct 28, 2017
2 parents a23fd54 + 975eea5 commit e7e5172
Show file tree
Hide file tree
Showing 24 changed files with 600 additions and 148 deletions.
Expand Up @@ -54,6 +54,7 @@
import org.jumpmind.properties.TypedProperties;
import org.jumpmind.security.SecurityConstants;
import org.jumpmind.symmetric.common.ParameterConstants;
import org.jumpmind.symmetric.common.ServerConstants;
import org.jumpmind.symmetric.common.SystemConstants;
import org.jumpmind.symmetric.transport.TransportManagerFactory;
import org.jumpmind.util.AppUtils;
Expand Down Expand Up @@ -121,7 +122,10 @@ public AbstractCommandLauncher(String app, String argSyntax, String messageKeyPr
this.app = app;
this.argSyntax = argSyntax;
this.messageKeyPrefix = messageKeyPrefix;
TransportManagerFactory.initHttps("all", true);
TypedProperties serverProperties = new TypedProperties(System.getProperties());
boolean allowSelfSignedCerts = serverProperties.is(ServerConstants.HTTPS_ALLOW_SELF_SIGNED_CERTS, true);
String allowServerNames = serverProperties.get(ServerConstants.HTTPS_ALLOW_SELF_SIGNED_CERTS, "all");
TransportManagerFactory.initHttps(allowServerNames, allowSelfSignedCerts);
}

protected static void initFromServerProperties() {
Expand Down
Expand Up @@ -37,6 +37,7 @@
import org.jumpmind.symmetric.io.DbCompare;
import org.jumpmind.symmetric.io.DbCompareConfig;
import org.jumpmind.symmetric.io.DbCompareReport;
import org.jumpmind.symmetric.util.SymmetricUtils;

public class DbCompareCommand extends AbstractCommandLauncher {

Expand All @@ -58,10 +59,12 @@ protected boolean requiresPropertiesFile(CommandLine line) {

@Override
protected boolean executeWithOptions(CommandLine line) throws Exception {

DbCompareConfig config = new DbCompareConfig();

String source = line.getOptionValue('s');
if (source == null) {
source = line.getOptionValue(OPTION_SOURCE);
source = getOptionValue(OPTION_SOURCE, "source", line, config);
}
if (StringUtils.isEmpty(source)) {
throw new ParseException(String.format("-source properties file is required."));
Expand All @@ -74,7 +77,7 @@ protected boolean executeWithOptions(CommandLine line) throws Exception {

String target = line.getOptionValue('t');
if (target == null) {
target = line.getOptionValue(OPTION_TARGET);
target = getOptionValue(OPTION_TARGET, "target", line, config);
}
if (StringUtils.isEmpty(target)) {
throw new ParseException(String.format("-target properties file is required."));
Expand All @@ -85,29 +88,30 @@ protected boolean executeWithOptions(CommandLine line) throws Exception {
throw new SymmetricException("Target properties file '" + targetProperties + "' does not exist.");
}

DbCompareConfig config = new DbCompareConfig();

if (line.hasOption(OPTION_OUTPUT_SQL)) {
config.setSqlDiffFileName(line.getOptionValue(OPTION_OUTPUT_SQL));
}
if (line.hasOption(OPTION_USE_SYM_CONFIG)) {
config.setUseSymmetricConfig(Boolean.valueOf(line.getOptionValue(OPTION_USE_SYM_CONFIG)));
}
if (line.hasOption(OPTION_EXCLUDE)) {
config.setExcludedTableNames(Arrays.asList(line.getOptionValue(OPTION_EXCLUDE).split(",")));
config.setOutputSql(getOptionValue(OPTION_OUTPUT_SQL, "outputSql", line, config));
config.setUseSymmetricConfig(Boolean.valueOf(getOptionValue(OPTION_USE_SYM_CONFIG, "useSymmetricConfig", line, config)));
String excludedTableNames = getOptionValue(OPTION_EXCLUDE, "excludedTableNames", line, config);
if (excludedTableNames != null) {
config.setExcludedTableNames(Arrays.asList(excludedTableNames.split(",")));
}
if (line.hasOption(OPTION_TARGET_TABLES)) {
config.setTargetTableNames(Arrays.asList(line.getOptionValue(OPTION_TARGET_TABLES).split(",")));
String targetTables = getOptionValue(OPTION_TARGET_TABLES, "targetTableNames", line, config);
if (targetTables != null) {
config.setTargetTableNames(Arrays.asList(targetTables.split(",")));
}

config.setWhereClauses(parseWhereClauses(line));
config.setTablesToExcludedColumns(parseExcludedColumns(line));

if (!CollectionUtils.isEmpty(line.getArgList())) {
config.setIncludedTableNames(Arrays.asList(line.getArgList().get(0).toString().split(",")));
String sourceTables = getOptionValue(OPTION_SOURCE_TABLES, "sourceTableNames", line, config);
if (sourceTables == null && !CollectionUtils.isEmpty(line.getArgList())) {
sourceTables = line.getArgList().get(0).toString();
}

if (sourceTables != null) {
config.setSourceTableNames(Arrays.asList(sourceTables.split(",")));
}

String numericScaleArg = line.getOptionValue(OPTION_NUMERIC_SCALE);
String numericScaleArg = getOptionValue(OPTION_NUMERIC_SCALE, "numericScale", line, config);
if (!StringUtils.isEmpty(numericScaleArg)) {
try {
config.setNumericScale(Integer.parseInt(numericScaleArg.trim()));
Expand All @@ -124,6 +128,26 @@ protected boolean executeWithOptions(CommandLine line) throws Exception {

return false;
}

protected String getOptionValue(String optionName, String internalName, CommandLine line, DbCompareConfig config) {
String optionValue = line.hasOption(optionName) ? line.getOptionValue(optionName) : null;
if (optionValue == null) {
Properties props = getConfigProperties(line);
optionValue = props.getProperty(optionName);
if (optionValue == null) {
String optionNameUnderScore = optionName.replace('-', '_');
optionValue = props.getProperty(optionNameUnderScore);
if (optionValue != null) {
config.setConfigSource(internalName, line.getOptionValue(OPTION_CONFIG_PROPERTIES));
}
} else {
config.setConfigSource(internalName, line.getOptionValue(OPTION_CONFIG_PROPERTIES));
}
} else {
config.setConfigSource(internalName, "command-line");
}
return optionValue;
}

public static void main(String[] args) throws Exception {
new DbCompareCommand().execute(args);
Expand All @@ -138,6 +162,8 @@ protected static void initFromServerProperties() {

private static final String OPTION_EXCLUDE = "exclude";

private static final String OPTION_SOURCE_TABLES = "source-tables";

private static final String OPTION_TARGET_TABLES = "target-tables";

private static final String OPTION_USE_SYM_CONFIG = "use-sym-config";
Expand Down Expand Up @@ -213,6 +239,7 @@ protected Properties getConfigProperties(CommandLine line) {
Properties props = new Properties();
try {
props.load(new FileInputStream(configPropertiesFile));
SymmetricUtils.replaceSystemAndEnvironmentVariables(props);
configProperties = props;
return configProperties;
} catch (Exception ex) {
Expand Down
Expand Up @@ -37,7 +37,7 @@ public class NuoDbSymmetricDialect extends AbstractSymmetricDialect implements I

static final String SQL_DROP_FUNCTION = "drop function $(functionName)";

static final String SQL_FUNCTION_INSTALLED = "select count(*) from system.functions where functionname='$(functionName)' and schema in (select database() from system.dual)" ;
static final String SQL_FUNCTION_INSTALLED = "select count(*) from system.functions where functionname='$(functionName)' and schema in (select current_schema from system.dual)" ;

static final String SYNC_TRIGGERS_DISABLED_USER_VARIABLE = "sync_triggers_disabled";

Expand All @@ -62,34 +62,35 @@ public String getTransactionTriggerExpression(String defaultCatalog, String defa

@Override
public void createRequiredDatabaseObjects() {
String function = this.parameterService.getTablePrefix() + "_get_session_variable";
if(!installed(SQL_FUNCTION_INSTALLED, function)){
String sql = "create function $(functionName)(akey string) returns string " +
" as " +
" VAR l_out string = NULL; " +
" try " +
" l_out = (SELECT context_value from session_cache where name = akey); " +
" catch(error) " +
" create temp table if not exists session_cache (name string primary key, context_value string) on commit preserve rows; " +
" end_try; " +
" return l_out; " +
" END_FUNCTION;";
String function = parameterService.getTablePrefix() + "_get_session_variable";
if (!installed(SQL_FUNCTION_INSTALLED, function)) {
String sql = "create function $(functionName)(akey string) returns string as\n" +
"VAR l_out string = NULL;\n" +
"try\n" +
"l_out = (SELECT context_value from " + parameterService.getTablePrefix() + "_session_cache where name = akey);\n" +
"catch(error)\n" +
"create temp table if not exists " + parameterService.getTablePrefix() + "_session_cache\n" +
"(name string primary key, context_value string) on commit preserve rows;\n" +
"end_try;\n" +
"return l_out;\n" +
"END_FUNCTION;";
install(sql, function);
}
function = this.parameterService.getTablePrefix() + "_set_session_variable";
if(!installed(SQL_FUNCTION_INSTALLED, function)){
String sql = "create function $(functionName)(akey string, avalue string) returns string " +
" as " +
" VAR l_new string = NULL; " +
" try " +
" INSERT INTO session_cache (name, context_value) values (akey, avalue) ON DUPLICATE KEY UPDATE context_value = avalue; " +
" catch(error) " +
" create temp table if not exists session_cache (name string primary key, context_value string) on commit preserve rows; " +
" INSERT INTO session_cache VALUES (akey, avalue); "+
" l_new = error; "+
" end_try; " +
" return l_new; " +
" END_FUNCTION;";
function = parameterService.getTablePrefix() + "_set_session_variable";
if (!installed(SQL_FUNCTION_INSTALLED, function)) {
String sql = "create function $(functionName)(akey string, avalue string) returns string as\n" +
"VAR l_new string = NULL;\n" +
"try\n" +
"INSERT INTO " + parameterService.getTablePrefix() + "_session_cache (name, context_value) \n" +
"values (akey, avalue) ON DUPLICATE KEY UPDATE context_value = avalue;\n" +
"catch(error)\n" +
"create temp table if not exists " + parameterService.getTablePrefix() + "_session_cache\n" +
"(name string primary key, context_value string) on commit preserve rows;\n" +
"INSERT INTO " + parameterService.getTablePrefix() + "_session_cache VALUES (akey, avalue);\n" +
"l_new = error;\n"+
"end_try;\n" +
"return l_new;\n" +
"END_FUNCTION;";
install(sql, function);
}
}
Expand Down Expand Up @@ -162,7 +163,7 @@ public void enableSyncTriggers(ISqlTransaction transaction) {
}

public String getSyncTriggersExpression() {
return this.parameterService.getTablePrefix()+ "_get_session_variable('" + SYNC_TRIGGERS_DISABLED_USER_VARIABLE + "') is null";
return "$(defaultSchema)" + parameterService.getTablePrefix()+ "_get_session_variable('" + SYNC_TRIGGERS_DISABLED_USER_VARIABLE + "') is null";
}

public void cleanDatabase() {
Expand Down

0 comments on commit e7e5172

Please sign in to comment.