Source Code Cross Referenced for SQLCommand.java in  » Database-Client » SQLMinus » isql » commands » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Database Client » SQLMinus » isql.commands 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * $Author$
003:         * $Id$
004:         * This is free software, as software should be; you can redistribute 
005:         * it and/or modify it under the terms of the GNU Lesser General Public
006:         * License as published by the Free Software Foundation; either
007:         * version 2.1 of the License, or (at your option) any later version.
008:
009:         * See LICENSE.txt for the full license covering this software/program/code.
010:         */
011:
012:        package isql.commands;
013:
014:        import isql.Command;
015:        import util.PerlWrapper;
016:        import isql.*;
017:        import util.*;
018:        import javax.swing.*;
019:        import javax.swing.table.*;
020:        import java.awt.*;
021:        import java.util.*;
022:
023:        /**
024:         * The command object associated with our metadata, such as links for
025:         * tables, sort options etc.
026:         * I am wondering whether they should be separate classes, however,
027:         * would like them to be in one place.
028:         * @author rahul kumar <rahul_kumar@yahoo.com>
029:         * @see XXX
030:         */
031:
032:        public class SQLCommand implements  Command {
033:
034:            /** ctor/constructor.
035:             */
036:            public SQLCommand() {
037:            }
038:
039:            public String[] getCommandList() {
040:                return commands;
041:            }
042:
043:            /** execute the given sql statement wither in foreground, or background.
044:             * use background if sql is prepended with bg, or if user has set mode as bg.
045:             */
046:            public void execute(SQLForm form, String fword, String SQLString) {
047:                _form = form;
048:                tp = _form.tp;
049:                myjdbc = _form.myjdbc;
050:                boolean bg = false;
051:                // see if first word is background
052:                if (fword.equals("bg")) {
053:                    bg = true;
054:                    SQLString = SQLString.substring(3);
055:                }
056:
057:                if ("true".equalsIgnoreCase((String) _form.getAttribute("bg",
058:                        "false"))
059:                        || bg) {
060:                    _form.setErrorArea('\n' + "Running in background.");
061:                    new Thread(new SQLBG(this , SQLString)).start();
062:                    return;
063:                }
064:                execute_sql(SQLString);
065:            }
066:
067:            /** method that actually executes in background. 
068:             *    called either from bg thread or execute().
069:             */
070:            public void execute_sql(String SQLString) {
071:                //super.setCursor (java.awt.Cursor.WAIT_CURSOR);
072:                _form.waitCursor();
073:                if ("JTABLE".equalsIgnoreCase((String) _form.getAttribute(
074:                        "outputformat", "JTABLE"))) {
075:                    Object result = null;
076:                    try {
077:                        result = myjdbc.runSelect(SQLString);
078:                    } catch (Exception exc) {
079:                        //super.setCursor (java.awt.Cursor.DEFAULT_CURSOR);
080:                        _form.defaultCursor();
081:                        _form.popup(exc.toString());
082:                        return;
083:                    }
084:                    //tp.clearOutputArea(); // remarked 20011112
085:                    //tp.clearErrorArea();
086:                    if (result instanceof  Integer) {
087:                        _form.setErrorArea('\n' + result.toString()
088:                                + " row(s) affected.");
089:                        _form.popup(result.toString() + " row(s) affected.");
090:                    } else {
091:                        // RK added on 20040102 22:35:22 added check for
092:                        // null/blank
093:                        TableModel tm = (TableModel) result;
094:                        // RK added on 20040202 12:01:58
095:                        // since the sql is now replaced we would like to
096:                        // display the modified statement in history.
097:                        // unfortunately if we do it here, we can only show
098:                        // modifed for this option.
099:                        // we have started returning null if user cancels variable replace in SQL 
100:                        if (result != null) {
101:                            SQLString = ((TableMap) result).getSQL();
102:                            _form._currentSQL = SQLString;
103:                        }
104:                        if (tm == null || tm.getRowCount() == 0) {
105:                            _form.setErrorArea('\n' + "No result.");
106:                            _form.popup("No result.");
107:                        } else {
108:                            if ("single".equalsIgnoreCase((String) _form
109:                                    .getAttribute("tableview", "single"))) {
110:                                tp.updateTable((TableModel) result);
111:                                tp.makeTableAreaVisible();
112:                            } else { // multiple
113:                                String name = Actions.getTableFromSQL(
114:                                        _form._currentSQL, "???");
115:                                tp.makeFramesVisible();
116:                                tp.getWindowPanel().addFrame(
117:                                        (TableModel) result, name);
118:                            }
119:                        }// null tm
120:                    }
121:                } else { // TEXT format output
122:                    String result = myjdbc.runSQL(SQLString);
123:                    tp.appendOutputArea(result);
124:                    tp.makeOutputAreaVisible();
125:                }
126:
127:                // Put old SQL in scrap area 
128:                tp.putSQLInScrapArea(SQLString);
129:                //super.setCursor (java.awt.Cursor.DEFAULT_CURSOR);
130:                _form.defaultCursor();
131:
132:            }
133:
134:            public String getUsage(String s) {
135:                return "sql statement";
136:            }
137:
138:            // added bg just in case we want to execute one command in bg mode. we can save bg with some commands.
139:            String commands[] = { "", "bg", "select", "create", "update",
140:                    "delete", "alter", "drop" };
141:            SQLForm _form;
142:            SQLTabbedPane tp;
143:            SQLJDBC myjdbc;
144:
145:            ////// START INSTANCE VARIABLES //////
146:
147:            ////// START CONSTANTS AND CLASS LEVEL VARIABLES  //////
148:            static final String P = "SQLCommand"; // used in exception strings
149:
150:        } // end of class
151:
152:        class SQLBG implements  Runnable {
153:
154:            String SQLString;
155:            SQLCommand command;
156:
157:            public SQLBG(SQLCommand command, String SQLString) {
158:                this .SQLString = SQLString;
159:                this .command = command;
160:            }
161:
162:            public void run() {
163:                command.execute_sql(SQLString);
164:            }
165:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.