Skip to content

Commit

Permalink
Forward porting to 1.11.x: Enhancing SourceMySqldiffFile to be used from
Browse files Browse the repository at this point in the history
command line - TRUNK-4186
  • Loading branch information
dkayiwa committed Dec 19, 2013
1 parent 66ce8cd commit 0d981ac
Showing 1 changed file with 18 additions and 5 deletions.
Expand Up @@ -48,6 +48,10 @@
*/
public class SourceMySqldiffFile implements CustomTaskChange {

public static final String CONNECTION_USERNAME = "connection.username";

public static final String CONNECTION_PASSWORD = "connection.password";

private static Log log = LogFactory.getLog(SourceMySqldiffFile.class);

/**
Expand All @@ -67,9 +71,20 @@ public void execute(Database database) throws CustomChangeException {

Properties runtimeProperties = Context.getRuntimeProperties();

String username = runtimeProperties.getProperty(CONNECTION_USERNAME);
String password = runtimeProperties.getProperty(CONNECTION_PASSWORD);

if (username == null) {
username = System.getProperty(CONNECTION_USERNAME);
}
if (password == null) {
password = System.getProperty(CONNECTION_PASSWORD);
}

// if we're in a "generate sql file" mode, quit early
if (runtimeProperties.size() == 0)
if (username == null || password == null) {
return;
}

DatabaseConnection connection = database.getConnection();

Expand All @@ -87,8 +102,6 @@ public void execute(Database database) throws CustomChangeException {

// build the mysql command line string
List<String> commands = new ArrayList<String>();
String username = runtimeProperties.getProperty("connection.username");
String password = runtimeProperties.getProperty("connection.password");
String databaseName;
try {
commands.add("mysql");
Expand All @@ -109,8 +122,8 @@ public void execute(Database database) throws CustomChangeException {
}

// to be used in error messages if this fails
String errorCommand = "\"mysql -u" + runtimeProperties.getProperty("connection.username") + " -p -e\"source "
+ tmpOutputFile.getAbsolutePath() + "\"" + databaseName;
String errorCommand = "\"mysql -u" + username + " -p -e\"source " + tmpOutputFile.getAbsolutePath() + "\""
+ databaseName;

// run the command line string
StringBuffer output = new StringBuffer();
Expand Down

0 comments on commit 0d981ac

Please sign in to comment.