001: /*
002: * Distributed as part of c3p0 v.0.9.1.2
003: *
004: * Copyright (C) 2005 Machinery For Change, Inc.
005: *
006: * Author: Steve Waldman <swaldman@mchange.com>
007: *
008: * This library is free software; you can redistribute it and/or modify
009: * it under the terms of the GNU Lesser General Public License version 2.1, as
010: * published by the Free Software Foundation.
011: *
012: * This software is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
015: * GNU Lesser General Public License for more details.
016: *
017: * You should have received a copy of the GNU Lesser General Public License
018: * along with this software; see the file LICENSE. If not, write to the
019: * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
020: * Boston, MA 02111-1307, USA.
021: */
022:
023: package com.mchange.v2.c3p0;
024:
025: import com.mchange.v2.c3p0.impl.*;
026:
027: import java.beans.PropertyVetoException;
028: import java.io.PrintWriter;
029: import java.io.Serializable;
030: import java.sql.SQLException;
031: import java.util.Arrays;
032: import java.util.Collection;
033: import java.util.Hashtable;
034: import javax.naming.NamingException;
035: import javax.naming.Reference;
036: import javax.naming.Referenceable;
037: import javax.sql.ConnectionPoolDataSource;
038: import javax.sql.PooledConnection;
039: import com.mchange.v2.beans.BeansUtils;
040: import com.mchange.v2.log.MLevel;
041: import com.mchange.v2.log.MLog;
042: import com.mchange.v2.log.MLogger;
043: import com.mchange.v2.naming.JavaBeanReferenceMaker;
044: import com.mchange.v2.naming.JavaBeanObjectFactory;
045: import com.mchange.v2.naming.ReferenceMaker;
046:
047: public final class JndiRefConnectionPoolDataSource extends
048: IdentityTokenResolvable implements ConnectionPoolDataSource,
049: Serializable, Referenceable {
050: final static MLogger logger = MLog
051: .getLogger(JndiRefConnectionPoolDataSource.class);
052:
053: final static Collection IGNORE_PROPS = Arrays.asList(new String[] {
054: "reference", "pooledConnection" });
055:
056: JndiRefForwardingDataSource jrfds;
057: WrapperConnectionPoolDataSource wcpds;
058:
059: String identityToken;
060:
061: public JndiRefConnectionPoolDataSource() {
062: this (true);
063: }
064:
065: public JndiRefConnectionPoolDataSource(boolean autoregister) {
066: jrfds = new JndiRefForwardingDataSource();
067: wcpds = new WrapperConnectionPoolDataSource();
068: wcpds.setNestedDataSource(jrfds);
069:
070: if (autoregister) {
071: this .identityToken = C3P0ImplUtils
072: .allocateIdentityToken(this );
073: C3P0Registry.reregister(this );
074: }
075: }
076:
077: public boolean isJndiLookupCaching() {
078: return jrfds.isCaching();
079: }
080:
081: public void setJndiLookupCaching(boolean caching) {
082: jrfds.setCaching(caching);
083: }
084:
085: public Hashtable getJndiEnv() {
086: return jrfds.getJndiEnv();
087: }
088:
089: public void setJndiEnv(Hashtable jndiEnv) {
090: jrfds.setJndiEnv(jndiEnv);
091: }
092:
093: public Object getJndiName() {
094: return jrfds.getJndiName();
095: }
096:
097: public void setJndiName(Object jndiName)
098: throws PropertyVetoException {
099: jrfds.setJndiName(jndiName);
100: }
101:
102: public int getAcquireIncrement() {
103: return wcpds.getAcquireIncrement();
104: }
105:
106: public void setAcquireIncrement(int acquireIncrement) {
107: wcpds.setAcquireIncrement(acquireIncrement);
108: }
109:
110: public int getAcquireRetryAttempts() {
111: return wcpds.getAcquireRetryAttempts();
112: }
113:
114: public void setAcquireRetryAttempts(int ara) {
115: wcpds.setAcquireRetryAttempts(ara);
116: }
117:
118: public int getAcquireRetryDelay() {
119: return wcpds.getAcquireRetryDelay();
120: }
121:
122: public void setAcquireRetryDelay(int ard) {
123: wcpds.setAcquireRetryDelay(ard);
124: }
125:
126: public boolean isAutoCommitOnClose() {
127: return wcpds.isAutoCommitOnClose();
128: }
129:
130: public void setAutoCommitOnClose(boolean autoCommitOnClose) {
131: wcpds.setAutoCommitOnClose(autoCommitOnClose);
132: }
133:
134: public void setAutomaticTestTable(String att) {
135: wcpds.setAutomaticTestTable(att);
136: }
137:
138: public String getAutomaticTestTable() {
139: return wcpds.getAutomaticTestTable();
140: }
141:
142: public void setBreakAfterAcquireFailure(boolean baaf) {
143: wcpds.setBreakAfterAcquireFailure(baaf);
144: }
145:
146: public boolean isBreakAfterAcquireFailure() {
147: return wcpds.isBreakAfterAcquireFailure();
148: }
149:
150: public void setCheckoutTimeout(int ct) {
151: wcpds.setCheckoutTimeout(ct);
152: }
153:
154: public int getCheckoutTimeout() {
155: return wcpds.getCheckoutTimeout();
156: }
157:
158: public String getConnectionTesterClassName() {
159: return wcpds.getConnectionTesterClassName();
160: }
161:
162: public void setConnectionTesterClassName(
163: String connectionTesterClassName)
164: throws PropertyVetoException {
165: wcpds.setConnectionTesterClassName(connectionTesterClassName);
166: }
167:
168: public boolean isForceIgnoreUnresolvedTransactions() {
169: return wcpds.isForceIgnoreUnresolvedTransactions();
170: }
171:
172: public void setForceIgnoreUnresolvedTransactions(
173: boolean forceIgnoreUnresolvedTransactions) {
174: wcpds
175: .setForceIgnoreUnresolvedTransactions(forceIgnoreUnresolvedTransactions);
176: }
177:
178: public String getIdentityToken() {
179: return identityToken;
180: }
181:
182: public void setIdentityToken(String identityToken) {
183: this .identityToken = identityToken;
184: }
185:
186: public void setIdleConnectionTestPeriod(int idleConnectionTestPeriod) {
187: wcpds.setIdleConnectionTestPeriod(idleConnectionTestPeriod);
188: }
189:
190: public int getIdleConnectionTestPeriod() {
191: return wcpds.getIdleConnectionTestPeriod();
192: }
193:
194: public int getInitialPoolSize() {
195: return wcpds.getInitialPoolSize();
196: }
197:
198: public void setInitialPoolSize(int initialPoolSize) {
199: wcpds.setInitialPoolSize(initialPoolSize);
200: }
201:
202: public int getMaxIdleTime() {
203: return wcpds.getMaxIdleTime();
204: }
205:
206: public void setMaxIdleTime(int maxIdleTime) {
207: wcpds.setMaxIdleTime(maxIdleTime);
208: }
209:
210: public int getMaxPoolSize() {
211: return wcpds.getMaxPoolSize();
212: }
213:
214: public void setMaxPoolSize(int maxPoolSize) {
215: wcpds.setMaxPoolSize(maxPoolSize);
216: }
217:
218: public int getMaxStatements() {
219: return wcpds.getMaxStatements();
220: }
221:
222: public void setMaxStatements(int maxStatements) {
223: wcpds.setMaxStatements(maxStatements);
224: }
225:
226: public int getMaxStatementsPerConnection() {
227: return wcpds.getMaxStatementsPerConnection();
228: }
229:
230: public void setMaxStatementsPerConnection(int mspc) {
231: wcpds.setMaxStatementsPerConnection(mspc);
232: }
233:
234: public int getMinPoolSize() {
235: return wcpds.getMinPoolSize();
236: }
237:
238: public void setMinPoolSize(int minPoolSize) {
239: wcpds.setMinPoolSize(minPoolSize);
240: }
241:
242: public String getPreferredTestQuery() {
243: return wcpds.getPreferredTestQuery();
244: }
245:
246: public void setPreferredTestQuery(String ptq) {
247: wcpds.setPreferredTestQuery(ptq);
248: }
249:
250: public int getPropertyCycle() {
251: return wcpds.getPropertyCycle();
252: }
253:
254: public void setPropertyCycle(int propertyCycle) {
255: wcpds.setPropertyCycle(propertyCycle);
256: }
257:
258: public boolean isTestConnectionOnCheckin() {
259: return wcpds.isTestConnectionOnCheckin();
260: }
261:
262: public void setTestConnectionOnCheckin(
263: boolean testConnectionOnCheckin) {
264: wcpds.setTestConnectionOnCheckin(testConnectionOnCheckin);
265: }
266:
267: public boolean isTestConnectionOnCheckout() {
268: return wcpds.isTestConnectionOnCheckout();
269: }
270:
271: public void setTestConnectionOnCheckout(
272: boolean testConnectionOnCheckout) {
273: wcpds.setTestConnectionOnCheckout(testConnectionOnCheckout);
274: }
275:
276: public boolean isUsesTraditionalReflectiveProxies() {
277: return wcpds.isUsesTraditionalReflectiveProxies();
278: }
279:
280: public void setUsesTraditionalReflectiveProxies(boolean utrp) {
281: wcpds.setUsesTraditionalReflectiveProxies(utrp);
282: }
283:
284: public String getFactoryClassLocation() {
285: return jrfds.getFactoryClassLocation();
286: }
287:
288: public void setFactoryClassLocation(String factoryClassLocation) {
289: jrfds.setFactoryClassLocation(factoryClassLocation);
290: wcpds.setFactoryClassLocation(factoryClassLocation);
291: }
292:
293: final static JavaBeanReferenceMaker referenceMaker = new JavaBeanReferenceMaker();
294:
295: static {
296: referenceMaker
297: .setFactoryClassName(C3P0JavaBeanObjectFactory.class
298: .getName());
299: referenceMaker.addReferenceProperty("acquireIncrement");
300: referenceMaker.addReferenceProperty("acquireRetryAttempts");
301: referenceMaker.addReferenceProperty("acquireRetryDelay");
302: referenceMaker.addReferenceProperty("autoCommitOnClose");
303: referenceMaker.addReferenceProperty("automaticTestTable");
304: referenceMaker.addReferenceProperty("checkoutTimeout");
305: referenceMaker
306: .addReferenceProperty("connectionTesterClassName");
307: referenceMaker.addReferenceProperty("factoryClassLocation");
308: referenceMaker
309: .addReferenceProperty("forceIgnoreUnresolvedTransactions");
310: referenceMaker.addReferenceProperty("idleConnectionTestPeriod");
311: referenceMaker.addReferenceProperty("identityToken");
312: referenceMaker.addReferenceProperty("initialPoolSize");
313: referenceMaker.addReferenceProperty("jndiEnv");
314: referenceMaker.addReferenceProperty("jndiLookupCaching");
315: referenceMaker.addReferenceProperty("jndiName");
316: referenceMaker.addReferenceProperty("maxIdleTime");
317: referenceMaker.addReferenceProperty("maxPoolSize");
318: referenceMaker.addReferenceProperty("maxStatements");
319: referenceMaker
320: .addReferenceProperty("maxStatementsPerConnection");
321: referenceMaker.addReferenceProperty("minPoolSize");
322: referenceMaker.addReferenceProperty("preferredTestQuery");
323: referenceMaker.addReferenceProperty("propertyCycle");
324: referenceMaker.addReferenceProperty("testConnectionOnCheckin");
325: referenceMaker.addReferenceProperty("testConnectionOnCheckout");
326: referenceMaker
327: .addReferenceProperty("usesTraditionalReflectiveProxies");
328: }
329:
330: public Reference getReference() throws NamingException {
331: return referenceMaker.createReference(this );
332: }
333:
334: //implementation of javax.sql.ConnectionPoolDataSource
335: public PooledConnection getPooledConnection() throws SQLException {
336: return wcpds.getPooledConnection();
337: }
338:
339: public PooledConnection getPooledConnection(String user,
340: String password) throws SQLException {
341: return wcpds.getPooledConnection(user, password);
342: }
343:
344: public PrintWriter getLogWriter() throws SQLException {
345: return wcpds.getLogWriter();
346: }
347:
348: public void setLogWriter(PrintWriter out) throws SQLException {
349: wcpds.setLogWriter(out);
350: }
351:
352: public void setLoginTimeout(int seconds) throws SQLException {
353: wcpds.setLoginTimeout(seconds);
354: }
355:
356: public int getLoginTimeout() throws SQLException {
357: return wcpds.getLoginTimeout();
358: }
359:
360: public String toString() {
361: StringBuffer sb = new StringBuffer(512);
362: sb.append(super .toString());
363: sb.append(" [");
364: try {
365: BeansUtils.appendPropNamesAndValues(sb, this , IGNORE_PROPS);
366: } catch (Exception e) {
367: //e.printStackTrace();
368: if (Debug.DEBUG && logger.isLoggable(MLevel.FINE))
369: logger
370: .log(
371: MLevel.FINE,
372: "An exception occurred while extracting property names and values for toString()",
373: e);
374: sb.append(e.toString());
375: }
376: sb.append("]");
377: return sb.toString();
378: }
379: }
|