Skip to content

Commit

Permalink
Merge branch '3.10' of https://github.com/JumpMind/symmetric-ds.git i…
Browse files Browse the repository at this point in the history
…nto 3.10
  • Loading branch information
erilong committed Jul 20, 2019
2 parents 269bb0a + 7dad111 commit 824be79
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 1 deletion.
Expand Up @@ -20,6 +20,10 @@
*/
package org.jumpmind.symmetric;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;

import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.Options;
import org.apache.commons.dbcp.BasicDataSource;
Expand All @@ -28,6 +32,9 @@
public class DbSqlCommand extends AbstractCommandLauncher {

private static final String OPTION_SQL = "sql";
private static final String OPTION_SQLFILE = "sqlfile";

private Options localOptions;

public DbSqlCommand() {
super("dbsql", "", "DbSql.Option.");
Expand All @@ -48,6 +55,9 @@ protected void printHelp(CommandLine cmd, Options options) {
protected void buildOptions(Options options) {
super.buildOptions(options);
addOption(options, null, OPTION_SQL, true);
addOption(options, null, OPTION_SQLFILE, true);
// Need reference to it for later, if errors
localOptions = options;
}

@Override
Expand All @@ -72,6 +82,37 @@ protected boolean executeWithOptions(CommandLine line) throws Exception {
if (line.hasOption(OPTION_SQL)) {
String sql = line.getOptionValue(OPTION_SQL);
shell.runTool("-url", url, "-user", user, "-password", password, "-driver", driver, "-sql", sql);
} else if(line.hasOption(OPTION_SQLFILE)) {
File file = new File(line.getOptionValue(OPTION_SQLFILE));
if(file.exists()) {
BufferedReader br = null;
try {
br = new BufferedReader(new FileReader(file));
String sql = null;
while((sql = br.readLine()) != null) {
sql = sql.trim();
if(sql.endsWith(";")) {
sql = sql.substring(0,sql.length()-1);
}
if(sql.length() > 0) {
// Output the sql so the user knows the result of each sql statement
// The H2 shell tool outputs the result of the statement execution
System.out.println(sql);
shell.runTool("-url", url, "-user", user, "-password", password, "-driver", driver, "-sql", sql);
}
}
} finally {
if(br != null) {
br.close();
}
}
} else {
// Notify user about missing file name
System.err.println("-------------------------------------------------------------------------------");
System.err.println("File does not exist: " + file.getPath());
System.err.println("-------------------------------------------------------------------------------");
printHelp(line, localOptions);
}
} else {
shell.runTool("-url", url, "-user", user, "-password", password, "-driver", driver);
}
Expand Down
Expand Up @@ -187,6 +187,7 @@ DbCompare.Option.config=A reference to a properties file path containing additio
DbCompare.Option.date-time-format=A format to be used when comparing date time values. For example, using the format 'yyyy-MM-dd HH:mm:ss' would convert date time values into yyyy-MM-dd HH:mm:ss and then compare.

DbSql.Option.sql=Run this sql statement in the shell
DbSql.Option.sqlfile=Run each line-delimited sql statement in specified file

Jmx.Option.listbeans=List the JMX beans that are available
Jmx.Option.listmethods=List the JMX methods that are available on a specific bean. Requires that --bean be specified.
Expand Down
Expand Up @@ -49,6 +49,8 @@
*/
public interface IDataService {

public void insertTableReloadRequest(ISqlTransaction transaction, TableReloadRequest request);

public void insertTableReloadRequest(TableReloadRequest request);

public TableReloadRequest getTableReloadRequest(TableReloadRequestKey key);
Expand Down
Expand Up @@ -238,14 +238,37 @@ protected void deleteTableReloadRequest(ISqlTransaction sqlTransaction,
}

public void insertTableReloadRequest(TableReloadRequest request) {
ISqlTransaction transaction = null;
try {
transaction = engine.getDatabasePlatform().getSqlTemplate().startSqlTransaction();
insertTableReloadRequest(transaction, request);
transaction.commit();
} catch (Error ex) {
if (transaction != null) {
transaction.rollback();
}
throw ex;
} catch (RuntimeException ex) {
if (transaction != null) {
transaction.rollback();
}
throw ex;
} finally {
if (transaction != null) {
transaction.close();
}
}
}

public void insertTableReloadRequest(ISqlTransaction transaction, TableReloadRequest request) {
Date time = new Date();
request.setLastUpdateTime(time);
if (request.getCreateTime() == null) {
request.setCreateTime(time);
}
request.setCreateTime(new Date((request.getCreateTime().getTime() / 1000) * 1000));

sqlTemplate.update(
transaction.prepareAndExecute(
getSql("insertTableReloadRequest"),
new Object[] { request.getReloadSelect(), request.getBeforeCustomSql(),
request.getCreateTime(), request.getLastUpdateBy(),
Expand Down

0 comments on commit 824be79

Please sign in to comment.