Source Code Cross Referenced for DBOutputPanel.java in  » Database-Client » squirrel-sql-2.6.5a » net » sourceforge » squirrel_sql » plugins » oracle » dboutput » 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 » squirrel sql 2.6.5a » net.sourceforge.squirrel_sql.plugins.oracle.dboutput 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package net.sourceforge.squirrel_sql.plugins.oracle.dboutput;
002:
003:        /*
004:         * Copyright (C) 2004 Jason Height
005:         * jmheight@users.sourceforge.net
006:         *
007:         * This library is free software; you can redistribute it and/or
008:         * modify it under the terms of the GNU Lesser General Public
009:         * License as published by the Free Software Foundation; either
010:         * version 2.1 of the License, or (at your option) any later version.
011:         *
012:         * This library is distributed in the hope that it will be useful,
013:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
014:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
015:         * Lesser General Public License for more details.
016:         *
017:         * You should have received a copy of the GNU Lesser General Public
018:         * License along with this library; if not, write to the Free Software
019:         * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
020:         */
021:
022:        import java.awt.BorderLayout;
023:        import java.sql.SQLException;
024:        import java.sql.CallableStatement;
025:        import java.util.Timer;
026:        import java.util.TimerTask;
027:
028:        import javax.swing.JPanel;
029:        import javax.swing.JScrollPane;
030:        import javax.swing.JTextArea;
031:        import javax.swing.SwingUtilities;
032:        import javax.swing.text.BadLocationException;
033:        import javax.swing.text.Document;
034:
035:        import net.sourceforge.squirrel_sql.fw.util.log.ILogger;
036:        import net.sourceforge.squirrel_sql.fw.util.log.LoggerController;
037:
038:        import net.sourceforge.squirrel_sql.client.IApplication;
039:        import net.sourceforge.squirrel_sql.client.session.ISession;
040:
041:        public class DBOutputPanel extends JPanel {
042:            /**
043:             * Logger for this class.
044:             */
045:            private static final ILogger s_log = LoggerController
046:                    .createLogger(DBOutputPanel.class);
047:
048:            /**
049:             * Current session.
050:             */
051:            private ISession _session;
052:
053:            private JTextArea _textArea;
054:            private Timer _refreshTimer = new Timer(true);
055:
056:            private boolean _autoRefresh = false;
057:            private int _refreshPeriod = 10;
058:
059:            public class RefreshTimerTask extends TimerTask {
060:                public void run() {
061:                    populateDBOutput();
062:                }
063:            }
064:
065:            /**
066:             * Ctor.
067:             *
068:             * @param autoRefeshPeriod
069:             * @param   session    Current session.
070:             * @throws IllegalArgumentException Thrown if a <TT>null</TT> <TT>ISession</TT> passed.
071:             */
072:            public DBOutputPanel(ISession session, int autoRefeshPeriod) {
073:                super ();
074:                _session = session;
075:                _refreshPeriod = autoRefeshPeriod;
076:                createGUI();
077:                initDBOutput();
078:            }
079:
080:            protected void initDBOutput() {
081:                try {
082:                    CallableStatement c = _session.getSQLConnection()
083:                            .getConnection().prepareCall(
084:                                    "{call dbms_output.enable()}");
085:                    c.execute();
086:                } catch (SQLException ex) {
087:                    _session.showErrorMessage(ex);
088:                }
089:            }
090:
091:            /**
092:             * Current session.
093:             */
094:            public ISession getSession() {
095:                return _session;
096:            }
097:
098:            private void resetTimer() {
099:                if (_refreshTimer != null) {
100:                    _refreshTimer.cancel();
101:                    //Nil out the timer so that it can be gc'd
102:                    _refreshTimer = null;
103:                }
104:                if (_autoRefresh && (_refreshPeriod > 0)) {
105:                    _refreshTimer = new Timer(true);
106:                    _refreshTimer.scheduleAtFixedRate(new RefreshTimerTask(),
107:                            _refreshPeriod * 1000, _refreshPeriod * 1000);
108:                }
109:            }
110:
111:            public void setAutoRefresh(boolean enable) {
112:                if (enable != _autoRefresh) {
113:                    _autoRefresh = enable;
114:                    resetTimer();
115:                }
116:            }
117:
118:            public boolean getAutoRefesh() {
119:                return _autoRefresh;
120:            }
121:
122:            public void setAutoRefreshPeriod(int seconds) {
123:                if (_refreshPeriod != seconds) {
124:                    _refreshPeriod = seconds;
125:                    resetTimer();
126:                }
127:            }
128:
129:            public int getAutoRefreshPeriod() {
130:                return _refreshPeriod;
131:            }
132:
133:            public void clearOutput() {
134:                Document doc = _textArea.getDocument();
135:                int length = doc.getLength();
136:                try {
137:                    doc.remove(0, length);
138:                } catch (BadLocationException ex) {
139:                    //Silently ignore, what could we do anyway?
140:                }
141:            }
142:
143:            public synchronized void populateDBOutput() {
144:                try {
145:                    final StringBuffer buf = new StringBuffer();
146:                    //In an effort to avoid non JDBC standard out parameter types ie
147:                    //oracle specific ones, the dbms_output.get_line is used rather than
148:                    //the dbms_output.getlines. The disadvantage is there are more trips
149:                    //to the server to return multiple lines.
150:                    CallableStatement c = _session.getSQLConnection()
151:                            .getConnection().prepareCall(
152:                                    "{call dbms_output.get_line(?, ?)}");
153:                    c.registerOutParameter(1, java.sql.Types.VARCHAR);
154:                    c.registerOutParameter(2, java.sql.Types.INTEGER);
155:                    //Get 10 lines at a time.
156:                    int status = 0;
157:                    while (status == 0) {
158:                        c.execute();
159:                        status = c.getInt(2);
160:                        if (status == 0) {
161:                            String str = c.getString(1);
162:                            if (str != null)
163:                                buf.append(str);
164:                            buf.append("\n");
165:                        }
166:                    }
167:                    c.close();
168:                    if (buf.length() > 0) {
169:                        final JTextArea store = _textArea;
170:                        SwingUtilities.invokeLater(new Runnable() {
171:                            public void run() {
172:                                store.append(buf.toString());
173:                            }
174:                        });
175:                    }
176:                } catch (SQLException ex) {
177:                    _session.showErrorMessage(ex);
178:                }
179:            }
180:
181:            private void createGUI() {
182:                final IApplication app = _session.getApplication();
183:                setLayout(new BorderLayout());
184:                _textArea = new JTextArea();
185:                _textArea.setEditable(false);
186:                add(new JScrollPane(_textArea,
187:                        JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
188:                        JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED));
189:            }
190:
191:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.