|
From: SVN by r. <sv...@ca...> - 2009-01-07 15:53:53
|
Author: roy
Date: 2009-01-07 16:53:45 +0100 (Wed, 07 Jan 2009)
New Revision: 345
Removed:
src/main/java/nl/improved/sqlclient/charva/SQLShellComponent.java
Modified:
sqlshell
sqlshell.bat
src/main/java/nl/improved/sqlclient/AbstractSQLShellWindow.java
src/main/java/nl/improved/sqlclient/SQLShell.java
src/main/java/nl/improved/sqlclient/charva/CharvaSQLShellWindow.java
Log:
use single startup file again (SQLShell)
implemented execution of statements without interface (via inputfile)
output errors if they appeared
fixed display problems after pageup/page-down when using charva
Modified: sqlshell
===================================================================
--- sqlshell 2009-01-07 15:52:30 UTC (rev 344)
+++ sqlshell 2009-01-07 15:53:45 UTC (rev 345)
@@ -15,11 +15,15 @@
# limitations under the License.
# Path to java executable
-#JAVA=$(which java)
-JAVA=${JAVA_HOME}/bin/java
+JAVA=$(which java)
+#JAVA=${JAVA_HOME}/bin/java
# Dir to use as base for relative locations
+CURDIR=$(pwd)
+TMPDIR=$(dirname $0)
+cd $TMPDIR
WORKINGDIR=$(pwd)
+cd $CURDIR
# The directory where the JCurses jar and library are located.
# Please note that JCurses requires the jcurses.jar and libjcurses.so to
@@ -46,4 +50,4 @@
#Enable the file below to use the jcurses version
#${JAVA} -cp ${CP} nl.improved.sqlclient.jcurses.SQLShell $@
#Charva version
-${JAVA} -Djava.library.path=${CHARVA} -cp ${CP} nl.improved.sqlclient.charva.SQLShellComponent $@
+${JAVA} -Djava.library.path=${CHARVA} -cp ${CP} nl.improved.sqlclient.SQLShell $@
Modified: sqlshell.bat
===================================================================
--- sqlshell.bat 2009-01-07 15:52:30 UTC (rev 344)
+++ sqlshell.bat 2009-01-07 15:53:45 UTC (rev 345)
@@ -13,7 +13,7 @@
REM limitations under the License.
REM Dir to use as base for relative locations
-set WORKINGDIR=c:\sqlshell\
+set WORKINGDIR=y:\sqlshell\sqlclient\
REM The directory where the JCurses jar and library are located.
REM Please note that JCurses requires tje jcurses.jar and libjcurses.so to
@@ -21,7 +21,7 @@
set JCURSES=%WORKINGDIR%\lib
REM Where to find the SQLShell classes
-set SQLSHELL=%WORKINGDIR%\sqlshell.jar
+set SQLSHELL=%WORKINGDIR%\target\sqlshell-0.6.jar
# REM providing drivers for the databases to support.
set DRIVERS="%WORKINGDIR%\lib\hsqldb-1.8.0.jar"
Modified: src/main/java/nl/improved/sqlclient/AbstractSQLShellWindow.java
===================================================================
--- src/main/java/nl/improved/sqlclient/AbstractSQLShellWindow.java 2009-01-07 15:52:30 UTC (rev 344)
+++ src/main/java/nl/improved/sqlclient/AbstractSQLShellWindow.java 2009-01-07 15:53:45 UTC (rev 345)
@@ -129,12 +129,11 @@
* All threads should stop when this is set to false
*/
private boolean run = true; // set to false on quit
-
+ private File errFile;
/**
* Constructor.
*/
public AbstractSQLShellWindow() {
- File errFile;
try {
errFile = File.createTempFile("sqlshell", ".err");
errFile.deleteOnExit();
@@ -381,7 +380,7 @@
@Override
public void execute() {
output("Abort requested");
- if (commandThread.isAlive() && commandThread.getCommand().abort()) {
+ if (commandThread != null && commandThread.isAlive() && commandThread.getCommand().abort()) {
output("Abort done..");
}
}
@@ -483,6 +482,7 @@
this.commandIndex = i;
}
+ public abstract void show();
/**
* Return the visible screen width.
@@ -577,6 +577,9 @@
}
}
+ protected File getErrFile() {
+ return errFile;
+ }
/**
* Returns a string representation of the current command.
@@ -1604,7 +1607,7 @@
* Returns the screen implementation.
* @return the screen.
*/
- protected Screen getScreen() {
+ public Screen getScreen() {
return screen;
}
Modified: src/main/java/nl/improved/sqlclient/SQLShell.java
===================================================================
--- src/main/java/nl/improved/sqlclient/SQLShell.java 2009-01-07 15:52:30 UTC (rev 344)
+++ src/main/java/nl/improved/sqlclient/SQLShell.java 2009-01-07 15:53:45 UTC (rev 345)
@@ -15,6 +15,17 @@
*/
package nl.improved.sqlclient;
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.FileReader;
+import java.io.IOException;
+import java.sql.SQLException;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import nl.improved.sqlclient.charva.CharvaSQLShellWindow;
+import nl.improved.sqlclient.commands.Command;
import nl.improved.sqlclient.jcurses.SQLShellWindow;
@@ -24,9 +35,91 @@
*/
public class SQLShell {
- public static void main(String[] args) throws InterruptedException {
- System.out.println("This class is no longer used. Please start nl.improved.sqlclient.jcurses.SQLShellWindow");
- Thread.sleep(2000);
- SQLShellWindow.main(args);
+ public static void main(String[] args) throws InterruptedException, IOException {
+ Map<String, String> argsMap = new HashMap<String, String>();
+ if (args.length > 0) {
+ if (args[0].equals("--help") || args.length %2 == 1) {
+ System.err.println("Usage: ");
+ System.exit(-1);
+ }
+ for (int i = 0; i < args.length; i+=2) {
+ argsMap.put(args[i], args[i+1]);
+ }
+ }
+ AbstractSQLShellWindow sqlshellWindow;
+ if (argsMap.get("-i") != null) {
+ sqlshellWindow = new AbstractSQLShellWindow() {
+ @Override
+ public int getScreenWidth() {
+ return 1024;
+ }
+ @Override
+ public int getScreenHeight() {
+ return Integer.MAX_VALUE;
+ }
+ @Override
+ public void paint(Screen screen) {
+
+ }
+
+ @Override
+ public void beep() {
+
+ }
+
+ @Override
+ public void debug(String debug) {
+
+ }
+
+ @Override
+ public String select(List<String> items, Point p) {
+ return null;
+ }
+
+ @Override
+ protected String[] getLoginCredentials(String username, String password) throws SQLException {
+ return new String[]{username, password};
+ }
+
+ @Override
+ public void show() {
+ }
+ };
+ Command cmd = new nl.improved.sqlclient.AbstractSQLShellWindow.ExecuteBatchCommand(sqlshellWindow);
+ CharSequence output = cmd.execute(new SQLCommand("@"+ argsMap.get("-i")));
+ if (!argsMap.containsKey("-o")) {
+ for (CharSequence s : sqlshellWindow.getScreen().getScreenBuffer()) {
+ System.out.println(s);
+ }
+ System.out.println(output);
+ } else {
+ File f = new File(argsMap.get("-o"));
+ FileOutputStream fout = new FileOutputStream(f);
+ for (CharSequence s : sqlshellWindow.getScreen().getScreenBuffer()) {
+ fout.write(s.toString().getBytes());
+ fout.write('\n');
+ }
+ fout.write(output.toString().getBytes());
+ fout.write('\n');
+ }
+ } else {
+ //sqlshellWindow = new SQLShellWindow();
+ try {
+ sqlshellWindow = new CharvaSQLShellWindow();
+ } catch(Error e) {
+ sqlshellWindow = new SQLShellWindow();
+ }
+ }
+ sqlshellWindow.show();
+ File errFile = sqlshellWindow.getErrFile();
+ if (errFile != null && errFile.length() > 0L) {
+ System.out.println("There where errors during execution of sqlshell:");
+ BufferedReader reader = new BufferedReader(new FileReader(errFile));
+ String line;
+ while ( (line = reader.readLine()) != null) {
+ System.out.println(line);
+ }
+ }
}
}
Modified: src/main/java/nl/improved/sqlclient/charva/CharvaSQLShellWindow.java
===================================================================
--- src/main/java/nl/improved/sqlclient/charva/CharvaSQLShellWindow.java 2009-01-07 15:52:30 UTC (rev 344)
+++ src/main/java/nl/improved/sqlclient/charva/CharvaSQLShellWindow.java 2009-01-07 15:53:45 UTC (rev 345)
@@ -5,12 +5,15 @@
package nl.improved.sqlclient.charva;
+import charva.awt.Dimension;
import charva.awt.Toolkit;
import charva.awt.event.ActionEvent;
import charva.awt.event.ActionListener;
import charva.awt.event.KeyEvent;
+import charvax.swing.JFrame;
import charvax.swing.JMenuItem;
import charvax.swing.JPopupMenu;
+import charvax.swing.JTextArea;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
@@ -32,16 +35,23 @@
* The sqlshell window implementation for charva.
* @author roy
*/
-class CharvaSQLShellWindow extends AbstractSQLShellWindow {
- private SQLShellComponent textComponent;
+public class CharvaSQLShellWindow extends AbstractSQLShellWindow {
+ private JTextArea textComponent;
private OutputStream debugOut;
/**
* Constructor.
* @param textComponent the text component for rendering the text
*/
- public CharvaSQLShellWindow(SQLShellComponent textComponent) {
- this.textComponent = textComponent;
+ public CharvaSQLShellWindow() {
+ this.textComponent = new JTextArea() {
+
+ @Override
+ public void processKeyEvent(KeyEvent ke) {
+ keyTyped(ke);
+ }
+
+ };
try {
File tmpFile = File.createTempFile("charva", ".out");
tmpFile.deleteOnExit();
@@ -62,9 +72,9 @@
@Override
public int getScreenHeight() {
if (textComponent == null) {
- return Toolkit.getDefaultToolkit().getScreenRows();
+ return Toolkit.getDefaultToolkit().getScreenRows()-1;
}
- return textComponent.getHeight();
+ return textComponent.getHeight()-1;
}
/**
@@ -76,6 +86,7 @@
@Override
public void paint(Screen screen) {
+ debug("PageUpCount: "+ screen.getPageUpCount());
if (screen.getPageUpCount() > 0) {
paintSlow(screen);
return;
@@ -122,11 +133,11 @@
}
}
}
- if (newText.toString().startsWith(textComponent.getText())) {
+ /*if (newText.toString().startsWith(textComponent.getText())) {
textComponent.append(newText.substring(textComponent.getText().length()));
- } else {
+ } else {*/
textComponent.replaceRange(newText.toString(), 0, textComponent.getText().length());
- }
+ //}
Point cursorPos = screen.getCursorPosition();
try {
int start = textComponent.getLineStartOffset(totalLineCount - (commandLines.size() - cursorPos.y));
@@ -334,4 +345,23 @@
return selectedValue;
}
}
+
+ public void show() {
+ JFrame frame = new JFrame() {
+
+ @Override
+ public void draw() {
+ //super.draw();
+ }
+
+ };
+ frame.setLayout(null); // null layout
+ frame.add(this.textComponent);
+ this.textComponent.setBounds(new charva.awt.Point(0,0), new Dimension(Toolkit.getDefaultToolkit().getScreenColumns()
+ , Toolkit.getDefaultToolkit().getScreenRows() +1));
+ frame.add(this.textComponent);
+ repaintScreen();
+ frame.pack();
+ frame.show();
+ }
}
Deleted: src/main/java/nl/improved/sqlclient/charva/SQLShellComponent.java
===================================================================
--- src/main/java/nl/improved/sqlclient/charva/SQLShellComponent.java 2009-01-07 15:52:30 UTC (rev 344)
+++ src/main/java/nl/improved/sqlclient/charva/SQLShellComponent.java 2009-01-07 15:53:45 UTC (rev 345)
@@ -1,188 +0,0 @@
-/*
- * To change this template, choose Tools | Templates
- * and open the template in the editor.
- */
-
-package nl.improved.sqlclient.charva;
-
-import java.util.Map;
-import java.util.HashMap;
-import charva.awt.Dimension;
-import charva.awt.Point;
-import charva.awt.Toolkit;
-import charva.awt.event.KeyEvent;
-import charva.awt.event.MouseEvent;
-import charvax.swing.JFrame;
-import charvax.swing.JTextArea;
-import java.awt.datatransfer.Clipboard;
-import java.awt.datatransfer.DataFlavor;
-import java.awt.datatransfer.Transferable;
-import java.awt.datatransfer.UnsupportedFlavorException;
-import java.io.IOException;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-import nl.improved.sqlclient.SQLCommand;
-import nl.improved.sqlclient.SQLProperties;
-import nl.improved.sqlclient.SQLUtil;
-
-/**
- *
- * @author roy
- */
-public class SQLShellComponent extends JTextArea {
-
- private CharvaSQLShellWindow sqlshellWindow = new CharvaSQLShellWindow(this);
- private Point startPos;
-
- public SQLShellComponent() {
- setEditable(false);
- setEnabled(true);
- setBorder(null);
- }
- @Override
- public void processKeyEvent(KeyEvent evt) {
- //super.processKeyEvent(arg0);
- sqlshellWindow.keyTyped(evt);
- }
-
- void setSelection(int pStart, int pEnd) {
- if (!"all".equals(SQLProperties.getProperty(SQLProperties.PropertyName.MOUSE_HANDLING))) {
- return;
- }
- int start, end;
- if (pEnd < pStart) {
- end = pStart;
- start = pEnd;
- } else {
- start = pStart;
- end = pEnd;
- }
- end = Math.min(getText().length(), end);
- sqlshellWindow.debug("SET SELECTION: "+ start +" -> "+ end);
- sqlshellWindow.debug("SET TO CLIPBOARD: "+ getText().substring(start, end));
- Clipboard clipBoard = java.awt.Toolkit.getDefaultToolkit().getSystemClipboard();
- final String text = getText().substring(start, Math.min(getText().length(), end));
- Transferable tf = new Transferable() {
-
- public DataFlavor[] getTransferDataFlavors() {
- return new DataFlavor[] {DataFlavor.stringFlavor};
- }
-
- public boolean isDataFlavorSupported(DataFlavor flavor) {
- return DataFlavor.stringFlavor == flavor;
- }
-
- public Object getTransferData(DataFlavor flavor) throws UnsupportedFlavorException, IOException {
- return text;
- }
- };
- clipBoard.setContents(tf, null);
- }
-
- @Override
- public void processMouseEvent(MouseEvent evt) {
- super.processMouseEvent(evt);
- if (evt.getModifiers() == MouseEvent.MOUSE_CLICKED) {
- if (evt.getButton() == MouseEvent.BUTTON1) {
- if (evt.getClickCount() == 2) { // double click.. select word under char
- try {
- int line = getLineStartOffset(evt.getY()-1);
- String text = getText();
- int start, end;
- for (start = line + evt.getX(); start > 0; start--) {
- if (SQLUtil.isBreakCharacter(text.charAt(start))) {
- break;
- }
- }
- for (end = line + evt.getX(); end < text.length(); end++) {
- if (SQLUtil.isBreakCharacter(text.charAt(end))) {
- break;
- }
- }
- setSelection(start, end);
- } catch(Exception e) { }
- }
- }
- } else if (evt.getModifiers() == MouseEvent.MOUSE_PRESSED) {
- sqlshellWindow.debug("PRESSED");
- if (evt.getButton() == MouseEvent.BUTTON1) {
- if (startPos == null) {
- startPos = new Point(evt.getX()-1, evt.getY()-1);
- } else {
- try {
- Point endPos = new Point(evt.getX()-1, evt.getY()-1);
- int start = getLineStartOffset(startPos.y) + startPos.x;
- int end = getLineStartOffset(endPos.y) + endPos.x;
- setSelection(start, end);
- startPos = null;
- } catch(Exception e) {}
- }
- }
- if (evt.getButton() == MouseEvent.BUTTON2) { // paste from clipboard
- String mouseHandling = SQLProperties.getProperty(SQLProperties.PropertyName.MOUSE_HANDLING);
- if ("all".equals(mouseHandling) || "paste".equals(mouseHandling)) {
- Clipboard clipBoard = java.awt.Toolkit.getDefaultToolkit().getSystemClipboard();
- try {
- String clipBoardContents = (String) clipBoard.getData(DataFlavor.stringFlavor);
- //sqlshellWindow.debug(clipBoardContents);
- sqlshellWindow.insertText(clipBoardContents);
- sqlshellWindow.repaintScreen();
- } catch (UnsupportedFlavorException ex) {
- Logger.getLogger(SQLShellComponent.class.getName()).log(Level.SEVERE, null, ex);
- } catch (IOException ex) {
- Logger.getLogger(SQLShellComponent.class.getName()).log(Level.SEVERE, null, ex);
- }
- }
- }
- } else if (evt.getModifiers() == MouseEvent.MOUSE_RELEASED) {
- sqlshellWindow.debug("RELEASED: " + startPos);
- Point endPos = new Point(evt.getX()-1, evt.getY()-1);
- if (startPos != null) {
- try {
- int start = getLineStartOffset(startPos.y) + startPos.x;
- int end = getLineStartOffset(endPos.y) + endPos.x;
- setSelection(start, end);
- startPos = null;
- } catch(Exception e) { /* ignore */ }
- }
- }
- }
-
-
- public static void main(String[] args) {
- Map argsMap = new HashMap<String, String>();
- if (args.length > 0) {
- if (args[0].equals("--help") || args.length %2 == 1) {
- System.err.println("Usage: ");
- System.exit(-1);
- }
- for (int i = 0; i < args.length; i+=2) {
- argsMap.put(args[i], args[i+1]);
- }
- }
- JFrame frame = new JFrame() {
-
- @Override
- public void draw() {
- //super.draw();
- }
-
- };
- SQLShellComponent component = new SQLShellComponent();
- frame.setLayout(null); // null layout
- frame.add(component);
- component.setBounds(new Point(0,0), new Dimension(Toolkit.getDefaultToolkit().getScreenColumns()
- , Toolkit.getDefaultToolkit().getScreenRows() +1));
- frame.add(component);
- component.sqlshellWindow.repaintScreen();
- frame.pack();
- if (argsMap.get("-i") != null) {
- new nl.improved.sqlclient.AbstractSQLShellWindow.ExecuteBatchCommand(component.sqlshellWindow).execute(new SQLCommand("@"+ argsMap.get("-i")));
- }
- if (argsMap.get("-q") != null) {
- return;
- }
- frame.show();
- }
-
-}
|