KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > logicalcobwebs > proxool > ProxoolAdapter


1 /*
2  * This software is released under a licence similar to the Apache Software Licence.
3  * See org.logicalcobwebs.proxool.package.html for details.
4  * The latest version is available at http://proxool.sourceforge.net
5  */

6 package org.logicalcobwebs.proxool;
7
8 import org.logicalcobwebs.dbscript.ConnectionAdapterIF;
9 import org.apache.commons.logging.Log;
10 import org.apache.commons.logging.LogFactory;
11
12 import java.sql.Connection JavaDoc;
13 import java.sql.DriverManager JavaDoc;
14 import java.sql.SQLException JavaDoc;
15 import java.util.Properties JavaDoc;
16
17 /**
18  * Provides Proxool connections to the {@link org.logicalcobwebs.dbscript.ScriptFacade ScriptFacade}
19  *
20  * @version $Revision: 1.22 $, $Date: 2006/01/18 14:40:06 $
21  * @author Bill Horsman (bill@logicalcobwebs.co.uk)
22  * @author $Author: billhorsman $ (current maintainer)
23  * @since Proxool 0.5
24  */

25 public class ProxoolAdapter implements ConnectionAdapterIF, ConfigurationListenerIF {
26
27     private static final Log LOG = LogFactory.getLog(ProxoolAdapter.class);
28
29     private String JavaDoc alias = String.valueOf(hashCode());
30
31     private String JavaDoc fullUrl;
32
33     private Properties JavaDoc changedInfo;
34
35     private Properties JavaDoc completeInfo;
36
37     /**
38      * Use this constructor if you want to define the alias
39      * @param alias the alias of the pool
40      */

41     public ProxoolAdapter(String JavaDoc alias) {
42         this.alias = alias;
43     }
44
45     /**
46      * Default constructor. Will use the hashCode as the alias for the pool
47      */

48     public ProxoolAdapter() {
49     }
50
51     public void definitionUpdated(ConnectionPoolDefinitionIF connectionPoolDefinition, Properties JavaDoc completeInfo, Properties JavaDoc changedInfo) {
52         setCompleteInfo(completeInfo);
53         setChangedInfo(changedInfo);
54         LOG.debug("Definition updated " + connectionPoolDefinition.getCompleteUrl());
55         if (changedInfo != null && changedInfo.size() > 0) {
56             LOG.debug(changedInfo.size() + " properties updated");
57         } else {
58             LOG.debug("No properties updated");
59         }
60     }
61
62     public Properties JavaDoc getChangedInfo() {
63         return changedInfo;
64     }
65
66     public void setChangedInfo(Properties JavaDoc changedInfo) {
67         this.changedInfo = changedInfo;
68     }
69
70     public Properties JavaDoc getCompleteInfo() {
71         return completeInfo;
72     }
73
74     public void setCompleteInfo(Properties JavaDoc completeInfo) {
75         this.completeInfo = completeInfo;
76     }
77
78     public String JavaDoc getName() {
79         return "proxool";
80     }
81
82     public void update(Properties JavaDoc info) throws SQLException JavaDoc, ProxoolException {
83         ProxoolFacade.updateConnectionPool(getFullUrl(), info);
84     }
85
86     public void update(String JavaDoc url) throws SQLException JavaDoc, ProxoolException {
87         ProxoolFacade.updateConnectionPool(url, null);
88     }
89
90     public void setup(String JavaDoc driver, String JavaDoc url, Properties JavaDoc info) throws SQLException JavaDoc, ProxoolException {
91
92         try {
93             Class.forName(ProxoolDriver.class.getName());
94         } catch (ClassNotFoundException JavaDoc e) {
95             throw new SQLException JavaDoc("Couldn't find " + driver);
96         }
97
98         fullUrl = TestHelper.buildProxoolUrl(alias, driver, url);
99         ProxoolFacade.registerConnectionPool(fullUrl, info);
100         ProxoolFacade.addConfigurationListener(alias, this);
101     }
102
103     public Connection JavaDoc getConnection()
104             throws SQLException JavaDoc {
105         return DriverManager.getConnection(ProxoolConstants.PROXOOL
106                 + ProxoolConstants.ALIAS_DELIMITER + alias);
107     }
108
109     public String JavaDoc getFullUrl() {
110         return fullUrl;
111     }
112
113     public void closeConnection(Connection JavaDoc connection) throws SQLException JavaDoc {
114         if (connection != null) {
115             connection.close();
116         }
117     }
118
119     public void tearDown() {
120         try {
121             ProxoolFacade.removeConnectionPool(alias);
122         } catch (ProxoolException e) {
123             LOG.error("Problem tearing down " + alias, e);
124         }
125     }
126
127 }
128
129 /*
130  Revision history:
131  $Log: ProxoolAdapter.java,v $
132  Revision 1.22 2006/01/18 14:40:06 billhorsman
133  Unbundled Jakarta's Commons Logging.
134
135  Revision 1.21 2003/03/04 10:24:40 billhorsman
136  removed try blocks around each test
137
138  Revision 1.20 2003/03/03 11:12:04 billhorsman
139  fixed licence
140
141  Revision 1.19 2003/03/01 15:27:24 billhorsman
142  checkstyle
143
144  Revision 1.18 2003/02/26 16:05:49 billhorsman
145  widespread changes caused by refactoring the way we
146  update and redefine pool definitions.
147
148  Revision 1.17 2003/02/19 15:14:24 billhorsman
149  fixed copyright (copy and paste error,
150  not copyright change)
151
152  Revision 1.16 2003/02/07 10:09:58 billhorsman
153  removed connectionPoolDefinition property. not needed.
154
155  Revision 1.15 2003/02/06 17:41:03 billhorsman
156  now uses imported logging
157
158  Revision 1.14 2003/01/23 11:13:40 billhorsman
159  use new setConfiguratorListener method
160
161  Revision 1.13 2003/01/18 15:13:13 billhorsman
162  Signature changes (new ProxoolException
163  thrown) on the ProxoolFacade API.
164
165  Revision 1.12 2003/01/17 00:38:12 billhorsman
166  wide ranging changes to clarify use of alias and url -
167  this has led to some signature changes (new exceptions
168  thrown) on the ProxoolFacade API.
169
170  Revision 1.11 2002/12/16 16:41:59 billhorsman
171  allow URL updates to pool
172
173  Revision 1.10 2002/12/12 10:49:43 billhorsman
174  now includes properties in definitionChanged event
175
176  Revision 1.9 2002/12/04 13:20:10 billhorsman
177  ConfigurationListenerIF test
178
179  Revision 1.8 2002/11/13 20:23:38 billhorsman
180  change method name, throw exceptions differently, trivial changes
181
182  Revision 1.7 2002/11/09 16:09:06 billhorsman
183  checkstyle
184
185  Revision 1.6 2002/11/09 16:02:05 billhorsman
186  fix doc
187
188  Revision 1.5 2002/11/09 14:45:35 billhorsman
189  only close connection if it is open
190
191  Revision 1.4 2002/11/07 18:56:59 billhorsman
192  allow explicit definition of alias
193
194  Revision 1.3 2002/11/02 14:22:16 billhorsman
195  Documentation
196
197  Revision 1.2 2002/11/02 12:46:42 billhorsman
198  improved debug
199
200  Revision 1.1 2002/11/02 11:37:48 billhorsman
201  New tests
202
203 */

204
Popular Tags