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


001:        package net.sourceforge.squirrel_sql.client.session;
002:
003:        import net.sourceforge.squirrel_sql.fw.util.IMessageHandler;
004:        import net.sourceforge.squirrel_sql.fw.util.StringManager;
005:        import net.sourceforge.squirrel_sql.fw.util.StringManagerFactory;
006:        import net.sourceforge.squirrel_sql.fw.util.log.ILogger;
007:        import net.sourceforge.squirrel_sql.fw.util.log.LoggerController;
008:
009:        import java.sql.Statement;
010:
011:        public class CancelStatementThread extends Thread {
012:            private static final StringManager s_stringMgr = StringManagerFactory
013:                    .getStringManager(CancelStatementThread.class);
014:
015:            private static final ILogger s_log = LoggerController
016:                    .createLogger(CancelStatementThread.class);
017:
018:            private Statement _stmt;
019:            private IMessageHandler _messageHandler;
020:            private boolean _threadFinished;
021:            private boolean _joinReturned;
022:
023:            public CancelStatementThread(Statement stmt,
024:                    IMessageHandler messageHandler) {
025:                _stmt = stmt;
026:                _messageHandler = messageHandler;
027:            }
028:
029:            public void tryCancel() {
030:                try {
031:                    start();
032:                    join(1500);
033:
034:                    synchronized (this ) {
035:                        _joinReturned = true;
036:                        if (false == _threadFinished) {
037:                            // i18n[CancelStatementThread.cancelTimedOut=Failed to cancel statement within one second. Perhaps your driver/database does not support cancelling statements. If cancelling succeeds later you'll get a further messages.]
038:                            String msg = s_stringMgr
039:                                    .getString("CancelStatementThread.cancelTimedOut");
040:                            _messageHandler.showErrorMessage(msg);
041:                            s_log.error(msg);
042:                        }
043:                    }
044:                } catch (InterruptedException e) {
045:                    throw new RuntimeException(e);
046:                }
047:            }
048:
049:            public void run() {
050:                String msg;
051:
052:                boolean cancelSucceeded = false;
053:                boolean closeSucceeded = false;
054:
055:                try {
056:                    if (_stmt != null) {
057:                        _stmt.cancel();
058:                    }
059:                    cancelSucceeded = true;
060:                } catch (Throwable t) {
061:                    // i18n[CancelStatementThread.cancelFailed=Failed to cancel statement. Perhaps the driver/RDDBMS does not support cancelling statements. See logs for further details ({0})]
062:                    msg = s_stringMgr.getString(
063:                            "CancelStatementThread.cancelFailed", t);
064:                    _messageHandler.showErrorMessage(msg);
065:                    s_log.error(msg, t);
066:                }
067:
068:                try {
069:                    // give the ResultSetReader some time to realize that the user requested
070:                    // cancel and stop fetching results.  This allows us to stop the query
071:                    // processing gracefully.
072:                    Thread.sleep(500);
073:                    if (_stmt != null) {
074:                        _stmt.close();
075:                    }
076:                    closeSucceeded = true;
077:                } catch (Throwable t) {
078:                    // i18n[CancelStatementThread.closeFailed=Failed to close statement. Propably the driver/RDDBMS does not support canceling statements. See logs for further details ({0})]
079:                    msg = s_stringMgr.getString(
080:                            "CancelStatementThread.closeFailed", t);
081:                    _messageHandler.showErrorMessage(msg);
082:                    s_log.error(msg, t);
083:                }
084:
085:                synchronized (this ) {
086:
087:                    if (cancelSucceeded && closeSucceeded) {
088:                        if (_joinReturned) {
089:                            // i18n[CancelStatementThread.cancelSucceededLate=Canceling statement succeeded now. But took longer than one second.]
090:                            msg = s_stringMgr
091:                                    .getString("CancelStatementThread.cancelSucceededLate");
092:                            _messageHandler.showMessage(msg);
093:                        } else {
094:                            // i18n[CancelStatementThread.cancelSucceeded=The database has been asked to cancel the statment.]
095:                            msg = s_stringMgr
096:                                    .getString("CancelStatementThread.cancelSucceeded");
097:                            _messageHandler.showMessage(msg);
098:                        }
099:                    }
100:
101:                    _threadFinished = true;
102:                }
103:
104:            }
105:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.