From: SVN by r. <sv...@ca...> - 2008-12-24 15:24:09
|
Author: roy Date: 2008-12-24 16:24:02 +0100 (Wed, 24 Dec 2008) New Revision: 340 Modified: src/main/java/nl/improved/sqlclient/AbstractSQLShellWindow.java Log: code cleanup made executebatch command a static command Modified: src/main/java/nl/improved/sqlclient/AbstractSQLShellWindow.java =================================================================== --- src/main/java/nl/improved/sqlclient/AbstractSQLShellWindow.java 2008-12-24 15:14:20 UTC (rev 339) +++ src/main/java/nl/improved/sqlclient/AbstractSQLShellWindow.java 2008-12-24 15:24:02 UTC (rev 340) @@ -18,7 +18,6 @@ import java.io.BufferedReader; import java.io.File; import java.io.FileInputStream; -import java.io.FileNotFoundException; import java.io.FileWriter; import java.io.IOException; import java.io.InputStream; @@ -168,7 +167,7 @@ commands.register("EXIT[\\s]*", new QuitCommand("exit")); commands.register("SAVE[\\s]*.*", new SaveCommand()); //commands.register("\\\\Q[\\s]*", new QuitCommand("\\q")); - commands.register("@.*", new ExecuteBatchCommand()); + commands.register("@.*", new ExecuteBatchCommand(this)); commands.register("(SELECT|UPDATE|ALTER|INSERT|DELETE).*;[\\s]*", new QueryCommand()); // keys @@ -459,9 +458,9 @@ } } }; - Thread t = new Thread(r); - t.setDaemon(true); - t.start(); + Thread thread = new Thread(r); + thread.setDaemon(true); + thread.start(); } /** @@ -697,8 +696,8 @@ insertText(newText); } } - } catch(Throwable t) { - error(t); + } catch(Throwable th) { + error(th); } repaint(); } @@ -2026,9 +2025,15 @@ } } - private class ExecuteBatchCommand implements Command { + public static class ExecuteBatchCommand implements Command { private boolean cancelled; private Command currentCommand; + private final AbstractSQLShellWindow sqlShell; + + public ExecuteBatchCommand(AbstractSQLShellWindow sqlShell) { + this.sqlShell = sqlShell; + } + @Override public CharSequence execute(SQLCommand sqlCommand) { cancelled = false; @@ -2038,7 +2043,7 @@ FileInputStream fin = null; try { fin = new FileInputStream(toFileName(command.substring(1))); - output("Reading file: "+ toFileName(command.substring(1))); + sqlShell.output("Reading file: "+ toFileName(command.substring(1))); BufferedReader reader = new BufferedReader(new InputStreamReader(fin)); StringBuffer cmd = new StringBuffer(); String line; @@ -2053,14 +2058,14 @@ if (line.endsWith(";")) { // Exec cmd String commandString = cmd.toString(); - currentCommand = createCommand(commandString); - output(commandString); - output(currentCommand.execute(new InputCommand(commandString))); + currentCommand = sqlShell.createCommand(commandString); + sqlShell.output(commandString); + sqlShell.output(currentCommand.execute(new InputCommand(commandString))); cmd=new StringBuffer(); new Thread() { @Override public void run() { - repaint(); + sqlShell.repaint(); } }.start(); } @@ -2070,7 +2075,7 @@ } return "File '" + toFileName(command.substring(1)) +"' executed successfully."; } catch(IOException e) { - error(e); + sqlShell.error(e); return "File '" + toFileName(command.substring(1)) +"' ended with errors."; } finally { if (fin != null) try { fin.close();}catch(Exception e) {/*ignore*/} |