Source Code Cross Referenced for TesterConnection.java in  » Database-JDBC-Connection-Pool » Connection-Pool-DBCP » org » apache » commons » dbcp » 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 JDBC Connection Pool » Connection Pool DBCP » org.apache.commons.dbcp 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Licensed to the Apache Software Foundation (ASF) under one or more
003:         * contributor license agreements.  See the NOTICE file distributed with
004:         * this work for additional information regarding copyright ownership.
005:         * The ASF licenses this file to You under the Apache License, Version 2.0
006:         * (the "License"); you may not use this file except in compliance with
007:         * the License.  You may obtain a copy of the License at
008:         * 
009:         *      http://www.apache.org/licenses/LICENSE-2.0
010:         * 
011:         * Unless required by applicable law or agreed to in writing, software
012:         * distributed under the License is distributed on an "AS IS" BASIS,
013:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014:         * See the License for the specific language governing permissions and
015:         * limitations under the License.
016:         */
017:
018:        package org.apache.commons.dbcp;
019:
020:        import java.sql.CallableStatement;
021:        import java.sql.Connection;
022:        import java.sql.DatabaseMetaData;
023:        import java.sql.PreparedStatement;
024:        import java.sql.SQLException;
025:        import java.sql.SQLWarning;
026:        import java.sql.Statement;
027:        import java.util.Map;
028:
029:        /**
030:         * A dummy {@link Connection}, for testing purposes.
031:         * 
032:         * @author Rodney Waldhoff
033:         * @author Dirk Verbeeck
034:         * @version $Revision: 479137 $ $Date: 2006-11-25 08:51:48 -0700 (Sat, 25 Nov 2006) $
035:         */
036:        public class TesterConnection implements  Connection {
037:            protected boolean _open = true;
038:            protected boolean _autoCommit = true;
039:            protected int _transactionIsolation = 1;
040:            protected DatabaseMetaData _metaData = null;
041:            protected String _catalog = null;
042:            protected Map _typeMap = null;
043:            protected boolean _readOnly = false;
044:            protected SQLWarning warnings = null;
045:            protected String username = null;
046:            protected String password = null;
047:            protected Exception failure;
048:
049:            public TesterConnection(String username, String password) {
050:                this .username = username;
051:                this .password = password;
052:            }
053:
054:            public String getUsername() {
055:                return this .username;
056:            }
057:
058:            public void setWarnings(SQLWarning warning) {
059:                this .warnings = warning;
060:            }
061:
062:            public void clearWarnings() throws SQLException {
063:                checkOpen();
064:                warnings = null;
065:            }
066:
067:            public void close() throws SQLException {
068:                checkOpen();
069:                _open = false;
070:            }
071:
072:            public void commit() throws SQLException {
073:                checkOpen();
074:                if (isReadOnly()) {
075:                    throw new SQLException(
076:                            "Cannot commit a readonly connection");
077:                }
078:            }
079:
080:            public Statement createStatement() throws SQLException {
081:                checkOpen();
082:                return new TesterStatement(this );
083:            }
084:
085:            public Statement createStatement(int resultSetType,
086:                    int resultSetConcurrency) throws SQLException {
087:                checkOpen();
088:                return new TesterStatement(this );
089:            }
090:
091:            public boolean getAutoCommit() throws SQLException {
092:                checkOpen();
093:                return _autoCommit;
094:            }
095:
096:            public String getCatalog() throws SQLException {
097:                checkOpen();
098:                return _catalog;
099:            }
100:
101:            public DatabaseMetaData getMetaData() throws SQLException {
102:                checkOpen();
103:                return _metaData;
104:            }
105:
106:            public int getTransactionIsolation() throws SQLException {
107:                checkOpen();
108:                return _transactionIsolation;
109:            }
110:
111:            public Map getTypeMap() throws SQLException {
112:                checkOpen();
113:                return _typeMap;
114:            }
115:
116:            public SQLWarning getWarnings() throws SQLException {
117:                checkOpen();
118:                return warnings;
119:            }
120:
121:            public boolean isClosed() throws SQLException {
122:                checkFailure();
123:                return !_open;
124:            }
125:
126:            public boolean isReadOnly() throws SQLException {
127:                checkOpen();
128:                return _readOnly;
129:            }
130:
131:            public String nativeSQL(String sql) throws SQLException {
132:                checkOpen();
133:                return sql;
134:            }
135:
136:            public CallableStatement prepareCall(String sql)
137:                    throws SQLException {
138:                checkOpen();
139:                if ("warning".equals(sql)) {
140:                    setWarnings(new SQLWarning("warning in prepareCall"));
141:                }
142:                return null;
143:            }
144:
145:            public CallableStatement prepareCall(String sql, int resultSetType,
146:                    int resultSetConcurrency) throws SQLException {
147:                checkOpen();
148:                return null;
149:            }
150:
151:            public PreparedStatement prepareStatement(String sql)
152:                    throws SQLException {
153:                checkOpen();
154:                if ("null".equals(sql)) {
155:                    return null;
156:                }
157:                if ("invalid".equals(sql)) {
158:                    throw new SQLException("invalid query");
159:                }
160:                if ("broken".equals(sql)) {
161:                    throw new SQLException("broken connection");
162:                }
163:                return new TesterPreparedStatement(this , sql);
164:            }
165:
166:            public PreparedStatement prepareStatement(String sql,
167:                    int resultSetType, int resultSetConcurrency)
168:                    throws SQLException {
169:                checkOpen();
170:                return new TesterPreparedStatement(this , sql, resultSetType,
171:                        resultSetConcurrency);
172:            }
173:
174:            public void rollback() throws SQLException {
175:                checkOpen();
176:                if (isReadOnly()) {
177:                    throw new SQLException(
178:                            "Cannot rollback a readonly connection");
179:                }
180:            }
181:
182:            public void setAutoCommit(boolean autoCommit) throws SQLException {
183:                checkOpen();
184:                _autoCommit = autoCommit;
185:            }
186:
187:            public void setCatalog(String catalog) throws SQLException {
188:                checkOpen();
189:                _catalog = catalog;
190:            }
191:
192:            public void setReadOnly(boolean readOnly) throws SQLException {
193:                checkOpen();
194:                _readOnly = readOnly;
195:            }
196:
197:            public void setTransactionIsolation(int level) throws SQLException {
198:                checkOpen();
199:                _transactionIsolation = level;
200:            }
201:
202:            public void setTypeMap(Map map) throws SQLException {
203:                checkOpen();
204:                _typeMap = map;
205:            }
206:
207:            protected void checkOpen() throws SQLException {
208:                if (!_open) {
209:                    throw new SQLException("Connection is closed.");
210:                }
211:                checkFailure();
212:            }
213:
214:            protected void checkFailure() throws SQLException {
215:                if (failure != null) {
216:                    throw new SQLNestedException("TesterConnection failure",
217:                            failure);
218:                }
219:            }
220:
221:            public void setFailure(Exception failure) {
222:                this .failure = failure;
223:            }
224:
225:            // ------------------- JDBC 3.0 -----------------------------------------
226:            // Will be commented by the build process on a JDBC 2.0 system
227:
228:            /* JDBC_3_ANT_KEY_BEGIN */
229:
230:            public int getHoldability() throws SQLException {
231:                throw new SQLException("Not implemented.");
232:            }
233:
234:            public void setHoldability(int holdability) throws SQLException {
235:                throw new SQLException("Not implemented.");
236:            }
237:
238:            public java.sql.Savepoint setSavepoint() throws SQLException {
239:                throw new SQLException("Not implemented.");
240:            }
241:
242:            public java.sql.Savepoint setSavepoint(String name)
243:                    throws SQLException {
244:                throw new SQLException("Not implemented.");
245:            }
246:
247:            public void rollback(java.sql.Savepoint savepoint)
248:                    throws SQLException {
249:                throw new SQLException("Not implemented.");
250:            }
251:
252:            public void releaseSavepoint(java.sql.Savepoint savepoint)
253:                    throws SQLException {
254:                throw new SQLException("Not implemented.");
255:            }
256:
257:            public Statement createStatement(int resultSetType,
258:                    int resultSetConcurrency, int resultSetHoldability)
259:                    throws SQLException {
260:                throw new SQLException("Not implemented.");
261:            }
262:
263:            public PreparedStatement prepareStatement(String sql,
264:                    int resultSetType, int resultSetConcurrency,
265:                    int resultSetHoldability) throws SQLException {
266:                throw new SQLException("Not implemented.");
267:            }
268:
269:            public CallableStatement prepareCall(String sql, int resultSetType,
270:                    int resultSetConcurrency, int resultSetHoldability)
271:                    throws SQLException {
272:                throw new SQLException("Not implemented.");
273:            }
274:
275:            public PreparedStatement prepareStatement(String sql,
276:                    int autoGeneratedKeys) throws SQLException {
277:                throw new SQLException("Not implemented.");
278:            }
279:
280:            public PreparedStatement prepareStatement(String sql,
281:                    int columnIndexes[]) throws SQLException {
282:                throw new SQLException("Not implemented.");
283:            }
284:
285:            public PreparedStatement prepareStatement(String sql,
286:                    String columnNames[]) throws SQLException {
287:                throw new SQLException("Not implemented.");
288:            }
289:
290:            /* JDBC_3_ANT_KEY_END */
291:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.