Source Code Cross Referenced for jdbcDataSource.java in  » Database-DBMS » hsql » org » hsqldb » jdbc » 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 DBMS » hsql » org.hsqldb.jdbc 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /* Copyright (c) 2001-2005, The HSQL Development Group
002:         * All rights reserved.
003:         *
004:         * Redistribution and use in source and binary forms, with or without
005:         * modification, are permitted provided that the following conditions are met:
006:         *
007:         * Redistributions of source code must retain the above copyright notice, this
008:         * list of conditions and the following disclaimer.
009:         *
010:         * Redistributions in binary form must reproduce the above copyright notice,
011:         * this list of conditions and the following disclaimer in the documentation
012:         * and/or other materials provided with the distribution.
013:         *
014:         * Neither the name of the HSQL Development Group nor the names of its
015:         * contributors may be used to endorse or promote products derived from this
016:         * software without specific prior written permission.
017:         *
018:         * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
019:         * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
020:         * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
021:         * ARE DISCLAIMED. IN NO EVENT SHALL HSQL DEVELOPMENT GROUP, HSQLDB.ORG,
022:         * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
023:         * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
024:         * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
025:         * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
026:         * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
027:         * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
028:         * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
029:         */
030:
031:        package org.hsqldb.jdbc;
032:
033:        import java.io.PrintWriter;
034:        import java.io.Serializable;
035:        import java.sql.Connection;
036:        import java.sql.SQLException;
037:        import java.util.Properties;
038:
039:        import javax.naming.NamingException;
040:        import javax.naming.Reference;
041:        import javax.naming.Referenceable;
042:        import javax.naming.StringRefAddr;
043:        import javax.sql.DataSource;
044:
045:        import org.hsqldb.jdbcDriver;
046:
047:        // boucherb@users 20040411 - doc 1.7.2 - javadoc updates toward 1.7.2 final
048:
049:        /**
050:         * <p>A factory for connections to the physical data source that this
051:         * <code>DataSource</code> object represents.  An alternative to the
052:         * <code>DriverManager</code> facility, a <code>DataSource</code> object
053:         * is the preferred means of getting a connection. An object that implements
054:         * the <code>DataSource</code> interface will typically be
055:         * registered with a naming service based on the
056:         * Java<sup><font size=-2>TM</font></sup> Naming and Directory (JNDI) API.
057:         * <P>
058:         * The <code>DataSource</code> interface is implemented by a driver vendor.
059:         * There are three types of implementations:
060:         * <OL>
061:         *   <LI>Basic implementation -- produces a standard <code>Connection</code>
062:         *       object
063:         *   <LI>Connection pooling implementation -- produces a <code>Connection</code>
064:         *       object that will automatically participate in connection pooling.  This
065:         *       implementation works with a middle-tier connection pooling manager.
066:         *   <LI>Distributed transaction implementation -- produces a
067:         *       <code>Connection</code> object that may be used for distributed
068:         *       transactions and almost always participates in connection pooling.
069:         *       This implementation works with a middle-tier
070:         *       transaction manager and almost always with a connection
071:         *       pooling manager.
072:         * </OL>
073:         * <P>
074:         * A <code>DataSource</code> object has properties that can be modified
075:         * when necessary.  For example, if the data source is moved to a different
076:         * server, the property for the server can be changed.  The benefit is that
077:         * because the data source's properties can be changed, any code accessing
078:         * that data source does not need to be changed.
079:         * <P>
080:         * A driver that is accessed via a <code>DataSource</code> object does not
081:         * register itself with the <code>DriverManager</code>.  Rather, a
082:         * <code>DataSource</code> object is retrieved though a lookup operation
083:         * and then used to create a <code>Connection</code> object.  With a basic
084:         * implementation, the connection obtained through a <code>DataSource</code>
085:         * object is identical to a connection obtained through the
086:         * <code>DriverManager</code> facility.
087:         *
088:         * @since JDK 1.4
089:
090:         * @author deforest@users
091:         * @version 1.7.2
092:         */
093:        public class jdbcDataSource implements  Serializable, Referenceable,
094:                DataSource {
095:
096:            /**
097:             * Login timeout
098:             */
099:            private int loginTimeout = 0;
100:
101:            /**
102:             * Log writer
103:             */
104:            private transient PrintWriter logWriter;
105:
106:            /**
107:             * Default password to use for connections
108:             */
109:            private String password = "";
110:
111:            /**
112:             * Default user to use for connections
113:             */
114:            private String user = "";
115:
116:            /**
117:             * Database location
118:             */
119:            private String database = "";
120:
121:            /**
122:             * Constructor
123:             */
124:            public jdbcDataSource() {
125:            }
126:
127:            /**
128:             * <p>Attempts to establish a connection with the data source that
129:             * this <code>DataSource</code> object represents.
130:             *
131:             * @return  a connection to the data source
132:             * @exception SQLException if a database access error occurs
133:             */
134:            public Connection getConnection() throws SQLException {
135:                return getConnection(user, password);
136:            }
137:
138:            /**
139:             * <p>Attempts to establish a connection with the data source that
140:             * this <code>DataSource</code> object represents.
141:             *
142:             * @param username the database user on whose behalf the connection is
143:             *  being made
144:             * @param password the user's password
145:             * @return  a connection to the data source
146:             * @exception SQLException if a database access error occurs
147:             */
148:            public Connection getConnection(String username, String password)
149:                    throws SQLException {
150:
151:                Properties props = new Properties();
152:
153:                if (username != null) {
154:                    props.put("user", username);
155:                }
156:
157:                if (password != null) {
158:                    props.put("password", password);
159:                }
160:
161:                return jdbcDriver.getConnection(database, props);
162:            }
163:
164:            /**
165:             * Retrieves the jdbc database connection url attribute. <p>
166:             *
167:             * @return the jdbc database connection url attribute
168:             */
169:            public String getDatabase() {
170:                return database;
171:            }
172:
173:            /**
174:             * Gets the maximum time in seconds that this data source can wait
175:             * while attempting to connect to a database.  A value of zero
176:             * means that the timeout is the default system timeout
177:             * if there is one; otherwise, it means that there is no timeout.
178:             * When a <code>DataSource</code> object is created, the login timeout is
179:             * initially zero.
180:             *
181:             * @return the data source login time limit
182:             * @exception SQLException if a database access error occurs.
183:             * @see #setLoginTimeout
184:             */
185:            public int getLoginTimeout() throws SQLException {
186:                return 0;
187:            }
188:
189:            /**
190:             * <p>Retrieves the log writer for this <code>DataSource</code>
191:             * object.
192:             *
193:             * <p>The log writer is a character output stream to which all logging
194:             * and tracing messages for this data source will be
195:             * printed.  This includes messages printed by the methods of this
196:             * object, messages printed by methods of other objects manufactured
197:             * by this object, and so on.  Messages printed to a data source
198:             * specific log writer are not printed to the log writer associated
199:             * with the <code>java.sql.Drivermanager</code> class.  When a
200:             * <code>DataSource</code> object is
201:             * created, the log writer is initially null; in other words, the
202:             * default is for logging to be disabled.
203:             *
204:             * @return the log writer for this data source or null if
205:             *        logging is disabled
206:             * @exception SQLException if a database access error occurs
207:             * @see #setLogWriter
208:             */
209:            public java.io.PrintWriter getLogWriter() throws SQLException {
210:                return logWriter;
211:            }
212:
213:            // javadoc to be copied from javax.naming.Referenceable.getReference()
214:            public Reference getReference() throws NamingException {
215:
216:                String cname = "org.hsqldb.jdbc.jdbcDataSourceFactory";
217:                Reference ref = new Reference(getClass().getName(), cname, null);
218:
219:                ref.add(new StringRefAddr("database", getDatabase()));
220:                ref.add(new StringRefAddr("user", getUser()));
221:                ref.add(new StringRefAddr("password", password));
222:
223:                return ref;
224:            }
225:
226:            /**
227:             * Retrieves the user ID for the connection. <p>
228:             *
229:             * @return the user ID for the connection
230:             */
231:            public String getUser() {
232:                return user;
233:            }
234:
235:            /**
236:             * Assigns the value of this object's jdbc database connection
237:             * url attribute. <p>
238:             *
239:             * @param database the new value of this object's jdbc database connection
240:             *      url attribute
241:             */
242:            public void setDatabase(String database) {
243:                this .database = database;
244:            }
245:
246:            /**
247:             * <p>Sets the maximum time in seconds that this data source will wait
248:             * while attempting to connect to a database.  A value of zero
249:             * specifies that the timeout is the default system timeout
250:             * if there is one; otherwise, it specifies that there is no timeout.
251:             * When a <code>DataSource</code> object is created, the login timeout is
252:             * initially zero.
253:             *
254:             * @param seconds the data source login time limit
255:             * @exception SQLException if a database access error occurs.
256:             * @see #getLoginTimeout
257:             */
258:            public void setLoginTimeout(int seconds) throws SQLException {
259:                loginTimeout = 0;
260:            }
261:
262:            /**
263:             * <p>Sets the log writer for this <code>DataSource</code>
264:             * object to the given <code>java.io.PrintWriter</code> object.
265:             *
266:             * <p>The log writer is a character output stream to which all logging
267:             * and tracing messages for this data source will be
268:             * printed.  This includes messages printed by the methods of this
269:             * object, messages printed by methods of other objects manufactured
270:             * by this object, and so on.  Messages printed to a data source-
271:             * specific log writer are not printed to the log writer associated
272:             * with the <code>java.sql.Drivermanager</code> class. When a
273:             * <code>DataSource</code> object is created the log writer is
274:             * initially null; in other words, the default is for logging to be
275:             * disabled.
276:             *
277:             * @param logWriter the new log writer; to disable logging, set to null
278:             * @exception SQLException if a database access error occurs
279:             * @see #getLogWriter
280:             */
281:            public void setLogWriter(PrintWriter logWriter) throws SQLException {
282:                this .logWriter = logWriter;
283:            }
284:
285:            /**
286:             * Sets the password to use for connecting to the database
287:             * @param password the password
288:             */
289:            public void setPassword(String password) {
290:                this .password = password;
291:            }
292:
293:            /**
294:             * Sets the userid
295:             * @param user the user id
296:             */
297:            public void setUser(String user) {
298:                this.user = user;
299:            }
300:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.