Source Code Cross Referenced for DefaultConnectionManager.java in  » Rule-Engine » Mandarax » org » mandarax » sql » 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 » Rule Engine » Mandarax » org.mandarax.sql 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright (C) 2003 <a href="mailto:jochen.hiller@bauer-partner.com">Jochen Hiller</a>
003:         *
004:         * This library is free software; you can redistribute it and/or
005:         * modify it under the terms of the GNU Lesser General Public
006:         * License as published by the Free Software Foundation; either
007:         * version 2 of the License, or (at your option) any later version.
008:         *
009:         * This library is distributed in the hope that it will be useful,
010:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
011:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
012:         * Lesser General Public License for more details.
013:         *
014:         * You should have received a copy of the GNU Lesser General Public
015:         * License along with this library; if not, write to the Free Software
016:         * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
017:         */
018:        package org.mandarax.sql;
019:
020:        import java.io.PrintWriter;
021:        import java.sql.Connection;
022:        import java.sql.SQLException;
023:
024:        import javax.sql.DataSource;
025:
026:        import org.mandarax.util.logging.LogCategories;
027:
028:        /**
029:         * The DefaultConnectionManager implements the 
030:         * interface of the SQLConnectionManager. 
031:         * 
032:         * It supports specification of a plain SQL connection,
033:         * or usage of the J2EE compliant data sources.
034:         * If a plain SQL connection will be given during initialize,
035:         * a data source wrapper will be used for this connection. 
036:         * 
037:         * @see SQLConnectionManager
038:         * @see java.sql.Connection
039:         * @see javax.sql.DataSource
040:         * 
041:         * @author <a href="mailto:jochen.hiller@bauer-partner.com">Jochen Hiller</a>
042:         * @version 3.4 <7 March 05>
043:         * @since 2.2
044:         */
045:        public class DefaultConnectionManager implements  SQLConnectionManager {
046:
047:            // attributes
048:
049:            /** a data source */
050:            private DataSource dataSource = null;
051:
052:            // constructors
053:
054:            /**
055:             * Instantiates a new connection manager for a given SQL connection.
056:             * The connection will be wrapped through our data source
057:             * connection wrapper.
058:             * 
059:             * @param con the plain sql connection
060:             */
061:            public DefaultConnectionManager(Connection con) {
062:                if (con == null) {
063:                    throw new IllegalArgumentException("Connection is null");
064:                }
065:                this .dataSource = new ConnectionWrapperDataSource(con);
066:            }
067:
068:            /**
069:             * Instantiates a new connection manager for a given data source.
070:             * 
071:             * @param ds the given data source
072:             */
073:            public DefaultConnectionManager(DataSource ds) {
074:                if (ds == null) {
075:                    throw new IllegalArgumentException("DataSource is null");
076:                }
077:                this .dataSource = ds;
078:            }
079:
080:            // public methods
081:
082:            /**
083:             * Gets a data source from the connection manager.
084:             * 
085:             * @return a data source
086:             */
087:            public DataSource getDataSource() {
088:                LogCategories.LOG_SQL.debug("getDataSource()");
089:                return this .dataSource;
090:            }
091:
092:            /**
093:             * Releases a connection, give it back to connection manager.
094:             * 
095:             * @todo close the connection, dependent on a bool setting
096:             * @param con the connection to release 
097:             */
098:            public void releaseConnection(Connection con) throws SQLException {
099:                LogCategories.LOG_SQL.debug("releaseConnection ()");
100:                // nothing to do for the moment
101:            }
102:
103:            // inner classes
104:
105:            /**
106:             * A data source, which wraps a simple SQL connection.
107:             * 
108:             * Only in private scope.
109:             * 
110:             * @author <a href="mailto:jochen.hiller@bauer-partner.com">Jochen Hiller</a>
111:             * @version 3.4 <7 March 05>
112:             * @since 2.2
113:             */
114:            private class ConnectionWrapperDataSource implements  DataSource {
115:
116:                /** the connection to wrap */
117:                private Connection wrappedConnection;
118:
119:                /** the login timeout */
120:                private int loginTimeout;
121:
122:                /** the log print writer */
123:                private PrintWriter logPrintWriter;
124:
125:                /**
126:                 * Default constructor.
127:                 */
128:                public ConnectionWrapperDataSource(Connection con) {
129:                    super ();
130:                    wrappedConnection = con;
131:                }
132:
133:                /**
134:                 * Get a database connection.
135:                 * @return a database connection
136:                 */
137:                public Connection getConnection() throws SQLException {
138:                    return wrappedConnection;
139:                }
140:
141:                /**
142:                 * Get a database connection.
143:                 * 
144:                 * @todo support user/password
145:                 * @param userName a user name
146:                 * @param password a password
147:                 * @return a database connection
148:                 */
149:                public Connection getConnection(String userName, String password)
150:                        throws SQLException {
151:                    return getConnection();
152:                }
153:
154:                /**
155:                 * Get the login timeout.
156:                 * @return the login timeout (an integer).
157:                 */
158:                public int getLoginTimeout() throws SQLException {
159:                    return loginTimeout;
160:                }
161:
162:                /**
163:                 * Get a log writer.
164:                 * @return a log writer.
165:                 */
166:                public PrintWriter getLogWriter() throws SQLException {
167:                    return logPrintWriter;
168:                }
169:
170:                /**
171:                 * Set the login timeout.
172:                 * @param millis the time in milli seconds
173:                 */
174:                public void setLoginTimeout(int millis) throws SQLException {
175:                    loginTimeout = millis;
176:                }
177:
178:                /**
179:                 * Set the log writer.
180:                 * @param writer a writer
181:                 */
182:                public void setLogWriter(PrintWriter writer)
183:                        throws SQLException {
184:                    logPrintWriter = writer;
185:                }
186:            }
187:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.