Source Code Cross Referenced for ConnectionModel.java in  » Database-Client » ViennaSQL » uk » co » whisperingwind » vienna » 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 » ViennaSQL » uk.co.whisperingwind.vienna 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         ** $Id: ConnectionModel.java,v 1.10 2000/11/26 13:11:21 mrw Exp $
003:         **
004:         ** Mike Wilson, July 2000, mrw@whisperingwind.co.uk
005:         **
006:         ** (C) Copyright 2000, Mike Wilson, Reading, Berkshire, UK
007:         **
008:         ** This program is free software; you can redistribute it and/or modify
009:         ** it under the terms of the GNU General Public License as published by
010:         ** the Free Software Foundation; either version 2 of the License, or
011:         ** (at your option) any later version.
012:         ** 
013:         ** This program is distributed in the hope that it will be useful,
014:         ** but WITHOUT ANY WARRANTY; without even the implied warranty of
015:         ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
016:         ** GNU General Public License for more details.
017:         ** 
018:         ** You should have received a copy of the GNU Library General
019:         ** Public License along with this library; if not, write to the
020:         ** Free Software Foundation, Inc., 59 Temple Place - Suite 330,
021:         ** Boston, MA  02111-1307  USA.
022:         */
023:
024:        package uk.co.whisperingwind.vienna;
025:
026:        import java.sql.Connection;
027:        import java.sql.SQLException;
028:        import java.sql.DriverManager;
029:        import uk.co.whisperingwind.framework.Dialogs;
030:        import uk.co.whisperingwind.framework.Model;
031:        import uk.co.whisperingwind.framework.SwingThread;
032:
033:        /**
034:         ** Model for the JDBC connection details. Has fields for the user
035:         ** name, password, JDBC driver class and JDBC URL.
036:         */
037:
038:        class ConnectionModel extends Model {
039:            private Connection connection = null;
040:            private String connectionName = null;
041:            private String userName = "";
042:            private String password = "";
043:            private String driverClass = null;
044:            private String url = null;
045:            private boolean updated = false;
046:
047:            public ConnectionModel() {
048:                super ();
049:            }
050:
051:            public ConnectionModel(final ConnectionModel copy) {
052:                super ();
053:                connectionName = new String(copy.connectionName);
054:
055:                if (copy.userName != null)
056:                    userName = new String(copy.userName);
057:
058:                if (copy.password != null)
059:                    password = new String(copy.password);
060:
061:                driverClass = new String(copy.driverClass);
062:                url = new String(copy.url);
063:            }
064:
065:            public void setName(String newName) {
066:                connectionName = newName;
067:                fireEvent("connectionName", connectionName);
068:            }
069:
070:            public String getName() {
071:                return connectionName;
072:            }
073:
074:            public void setUserName(String newName) {
075:                userName = newName;
076:                fireEvent("userName", userName);
077:            }
078:
079:            public String getUserName() {
080:                return userName;
081:            }
082:
083:            public void setPassword(String newPassword) {
084:                password = newPassword;
085:                fireEvent("password", password);
086:            }
087:
088:            public String getPassword() {
089:                if (password == null)
090:                    return "";
091:                else
092:                    return password;
093:            }
094:
095:            public void setDriverClass(String newClass) {
096:                driverClass = newClass;
097:                fireEvent("driverClass", driverClass);
098:            }
099:
100:            public String getDriverClass() {
101:                return driverClass;
102:            }
103:
104:            public void setUrl(String newUrl) {
105:                url = newUrl;
106:                fireEvent("url", url);
107:            }
108:
109:            public String getUrl() {
110:                return url;
111:            }
112:
113:            /**
114:             ** Connect to the database URL. This is run in a separate thread
115:             ** so the GUI is alive while I am connecting (which can take several
116:             ** seconds).
117:             */
118:
119:            public void connect() {
120:                ConnectWorker connectWorker = new ConnectWorker();
121:                connectWorker.start();
122:            }
123:
124:            /*
125:             ** Disconnect from the database.
126:             */
127:
128:            public void disconnect() {
129:                if (isConnected()) {
130:                    connection = null;
131:                    setUserName(null);
132:                    setPassword(null);
133:                    setDriverClass(null);
134:                    setUrl(null);
135:                    updated = false;
136:
137:                    fireEvent("disconnect", null);
138:                }
139:            }
140:
141:            public void commit() {
142:                try {
143:                    connection.commit();
144:                    updated = false;
145:                } catch (SQLException ex) {
146:                    Dialogs.showError("Commit failed", ex.getMessage());
147:                }
148:            }
149:
150:            public void rollback() {
151:                try {
152:                    connection.rollback();
153:                    updated = false;
154:                } catch (SQLException ex) {
155:                    Dialogs.showError("Rollback failed", ex.getMessage());
156:                }
157:            }
158:
159:            public void setUpdated() {
160:                updated = true;
161:            }
162:
163:            public boolean isUpdated() {
164:                return updated;
165:            }
166:
167:            /*
168:             ** Returns true if I am connected to the database.
169:             */
170:
171:            public boolean isConnected() {
172:                return connection != null;
173:            }
174:
175:            /*
176:             ** Returns a Connection for use in queries. Will return null if I
177:             ** am not connected.
178:             */
179:
180:            public Connection getConnection() {
181:                return connection;
182:            }
183:
184:            /**
185:             ** Worker class to make the connection with the database server.
186:             ** This can run in a separate thread so the GUI remains responsive
187:             ** while the connection is made.
188:             */
189:
190:            private class ConnectWorker extends SwingThread {
191:                /**
192:                 ** Make the connection...
193:                 */
194:
195:                public void construct() {
196:                    if (driverClass != null) {
197:                        try {
198:                            Class.forName(driverClass);
199:                            connection = DriverManager.getConnection(url,
200:                                    userName, password);
201:                            connection.setAutoCommit(false);
202:                        } catch (SQLException ex) {
203:                            Dialogs.showError("Connect error", ex.getMessage());
204:                        } catch (java.lang.ClassNotFoundException ex) {
205:                            Dialogs.showError("Driver error", ex.getMessage());
206:                        }
207:                    }
208:                }
209:
210:                /**
211:                 ** This always runs in the event thread.
212:                 */
213:
214:                public void finished() {
215:                    fireEvent("connect", null);
216:                }
217:            }
218:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.