add support to run scripts on usage DB

This commit is contained in:
kishan 2011-04-05 15:04:48 +05:30
parent 9a560173eb
commit 5401ee84ba
2 changed files with 39 additions and 0 deletions

View File

@ -161,6 +161,15 @@ public class Transaction {
}
}
public static Connection getStandaloneUsageConnection() {
try {
return s_usageDS.getConnection();
} catch (SQLException e) {
s_logger.warn("Unexpected exception: ", e);
return null;
}
}
protected static boolean checkAnnotation(int stack, Transaction txn) {
final StackTraceElement[] stacks = Thread.currentThread().getStackTrace();
StackElement se = txn.peekInStack(CURRENT_TXN);

View File

@ -58,4 +58,34 @@ public class DbTestUtils {
}
}
public static void executeUsageScript(String file, boolean autoCommit, boolean stopOnError) {
File cleanScript = PropertiesUtil.findConfigFile(file);
if (cleanScript == null) {
throw new RuntimeException("Unable to clean the database because I can't find " + file);
}
Connection conn = Transaction.getStandaloneUsageConnection();
ScriptRunner runner = new ScriptRunner(conn, autoCommit, stopOnError);
FileReader reader;
try {
reader = new FileReader(cleanScript);
} catch (FileNotFoundException e) {
throw new RuntimeException("Unable to read " + file, e);
}
try {
runner.runScript(reader);
} catch (IOException e) {
throw new RuntimeException("Unable to read " + file, e);
} catch (SQLException e) {
throw new RuntimeException("Unable to execute " + file, e);
}
try {
conn.close();
} catch (SQLException e) {
throw new RuntimeException("Unable to close DB connection", e);
}
}
}