001: /*
002: * This software is released under a licence similar to the Apache Software Licence.
003: * See org.logicalcobwebs.proxool.package.html for details.
004: * The latest version is available at http://proxool.sourceforge.net
005: */
006: package org.logicalcobwebs.proxool;
007:
008: import org.logicalcobwebs.dbscript.ConnectionAdapterIF;
009: import org.apache.commons.logging.Log;
010: import org.apache.commons.logging.LogFactory;
011:
012: import java.sql.Connection;
013: import java.sql.DriverManager;
014: import java.sql.SQLException;
015: import java.util.Properties;
016:
017: /**
018: * Provides Proxool connections to the {@link org.logicalcobwebs.dbscript.ScriptFacade ScriptFacade}
019: *
020: * @version $Revision: 1.22 $, $Date: 2006/01/18 14:40:06 $
021: * @author Bill Horsman (bill@logicalcobwebs.co.uk)
022: * @author $Author: billhorsman $ (current maintainer)
023: * @since Proxool 0.5
024: */
025: public class ProxoolAdapter implements ConnectionAdapterIF,
026: ConfigurationListenerIF {
027:
028: private static final Log LOG = LogFactory
029: .getLog(ProxoolAdapter.class);
030:
031: private String alias = String.valueOf(hashCode());
032:
033: private String fullUrl;
034:
035: private Properties changedInfo;
036:
037: private Properties completeInfo;
038:
039: /**
040: * Use this constructor if you want to define the alias
041: * @param alias the alias of the pool
042: */
043: public ProxoolAdapter(String alias) {
044: this .alias = alias;
045: }
046:
047: /**
048: * Default constructor. Will use the hashCode as the alias for the pool
049: */
050: public ProxoolAdapter() {
051: }
052:
053: public void definitionUpdated(
054: ConnectionPoolDefinitionIF connectionPoolDefinition,
055: Properties completeInfo, Properties changedInfo) {
056: setCompleteInfo(completeInfo);
057: setChangedInfo(changedInfo);
058: LOG.debug("Definition updated "
059: + connectionPoolDefinition.getCompleteUrl());
060: if (changedInfo != null && changedInfo.size() > 0) {
061: LOG.debug(changedInfo.size() + " properties updated");
062: } else {
063: LOG.debug("No properties updated");
064: }
065: }
066:
067: public Properties getChangedInfo() {
068: return changedInfo;
069: }
070:
071: public void setChangedInfo(Properties changedInfo) {
072: this .changedInfo = changedInfo;
073: }
074:
075: public Properties getCompleteInfo() {
076: return completeInfo;
077: }
078:
079: public void setCompleteInfo(Properties completeInfo) {
080: this .completeInfo = completeInfo;
081: }
082:
083: public String getName() {
084: return "proxool";
085: }
086:
087: public void update(Properties info) throws SQLException,
088: ProxoolException {
089: ProxoolFacade.updateConnectionPool(getFullUrl(), info);
090: }
091:
092: public void update(String url) throws SQLException,
093: ProxoolException {
094: ProxoolFacade.updateConnectionPool(url, null);
095: }
096:
097: public void setup(String driver, String url, Properties info)
098: throws SQLException, ProxoolException {
099:
100: try {
101: Class.forName(ProxoolDriver.class.getName());
102: } catch (ClassNotFoundException e) {
103: throw new SQLException("Couldn't find " + driver);
104: }
105:
106: fullUrl = TestHelper.buildProxoolUrl(alias, driver, url);
107: ProxoolFacade.registerConnectionPool(fullUrl, info);
108: ProxoolFacade.addConfigurationListener(alias, this );
109: }
110:
111: public Connection getConnection() throws SQLException {
112: return DriverManager.getConnection(ProxoolConstants.PROXOOL
113: + ProxoolConstants.ALIAS_DELIMITER + alias);
114: }
115:
116: public String getFullUrl() {
117: return fullUrl;
118: }
119:
120: public void closeConnection(Connection connection)
121: throws SQLException {
122: if (connection != null) {
123: connection.close();
124: }
125: }
126:
127: public void tearDown() {
128: try {
129: ProxoolFacade.removeConnectionPool(alias);
130: } catch (ProxoolException e) {
131: LOG.error("Problem tearing down " + alias, e);
132: }
133: }
134:
135: }
136:
137: /*
138: Revision history:
139: $Log: ProxoolAdapter.java,v $
140: Revision 1.22 2006/01/18 14:40:06 billhorsman
141: Unbundled Jakarta's Commons Logging.
142:
143: Revision 1.21 2003/03/04 10:24:40 billhorsman
144: removed try blocks around each test
145:
146: Revision 1.20 2003/03/03 11:12:04 billhorsman
147: fixed licence
148:
149: Revision 1.19 2003/03/01 15:27:24 billhorsman
150: checkstyle
151:
152: Revision 1.18 2003/02/26 16:05:49 billhorsman
153: widespread changes caused by refactoring the way we
154: update and redefine pool definitions.
155:
156: Revision 1.17 2003/02/19 15:14:24 billhorsman
157: fixed copyright (copy and paste error,
158: not copyright change)
159:
160: Revision 1.16 2003/02/07 10:09:58 billhorsman
161: removed connectionPoolDefinition property. not needed.
162:
163: Revision 1.15 2003/02/06 17:41:03 billhorsman
164: now uses imported logging
165:
166: Revision 1.14 2003/01/23 11:13:40 billhorsman
167: use new setConfiguratorListener method
168:
169: Revision 1.13 2003/01/18 15:13:13 billhorsman
170: Signature changes (new ProxoolException
171: thrown) on the ProxoolFacade API.
172:
173: Revision 1.12 2003/01/17 00:38:12 billhorsman
174: wide ranging changes to clarify use of alias and url -
175: this has led to some signature changes (new exceptions
176: thrown) on the ProxoolFacade API.
177:
178: Revision 1.11 2002/12/16 16:41:59 billhorsman
179: allow URL updates to pool
180:
181: Revision 1.10 2002/12/12 10:49:43 billhorsman
182: now includes properties in definitionChanged event
183:
184: Revision 1.9 2002/12/04 13:20:10 billhorsman
185: ConfigurationListenerIF test
186:
187: Revision 1.8 2002/11/13 20:23:38 billhorsman
188: change method name, throw exceptions differently, trivial changes
189:
190: Revision 1.7 2002/11/09 16:09:06 billhorsman
191: checkstyle
192:
193: Revision 1.6 2002/11/09 16:02:05 billhorsman
194: fix doc
195:
196: Revision 1.5 2002/11/09 14:45:35 billhorsman
197: only close connection if it is open
198:
199: Revision 1.4 2002/11/07 18:56:59 billhorsman
200: allow explicit definition of alias
201:
202: Revision 1.3 2002/11/02 14:22:16 billhorsman
203: Documentation
204:
205: Revision 1.2 2002/11/02 12:46:42 billhorsman
206: improved debug
207:
208: Revision 1.1 2002/11/02 11:37:48 billhorsman
209: New tests
210:
211: */
|