KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > mchange > v2 > c3p0 > JndiRefConnectionPoolDataSource


1 /*
2  * Distributed as part of c3p0 v.0.9.1
3  *
4  * Copyright (C) 2005 Machinery For Change, Inc.
5  *
6  * Author: Steve Waldman <swaldman@mchange.com>
7  *
8  * This library is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU Lesser General Public License version 2.1, as
10  * published by the Free Software Foundation.
11  *
12  * This software is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public License
18  * along with this software; see the file LICENSE. If not, write to the
19  * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
20  * Boston, MA 02111-1307, USA.
21  */

22
23
24 package com.mchange.v2.c3p0;
25
26 import com.mchange.v2.c3p0.impl.*;
27
28 import java.beans.PropertyVetoException JavaDoc;
29 import java.io.PrintWriter JavaDoc;
30 import java.io.Serializable JavaDoc;
31 import java.sql.SQLException JavaDoc;
32 import java.util.Arrays JavaDoc;
33 import java.util.Collection JavaDoc;
34 import java.util.Hashtable JavaDoc;
35 import javax.naming.NamingException JavaDoc;
36 import javax.naming.Reference JavaDoc;
37 import javax.naming.Referenceable JavaDoc;
38 import javax.sql.ConnectionPoolDataSource JavaDoc;
39 import javax.sql.PooledConnection JavaDoc;
40 import com.mchange.v2.beans.BeansUtils;
41 import com.mchange.v2.log.MLevel;
42 import com.mchange.v2.log.MLog;
43 import com.mchange.v2.log.MLogger;
44 import com.mchange.v2.naming.JavaBeanReferenceMaker;
45 import com.mchange.v2.naming.JavaBeanObjectFactory;
46 import com.mchange.v2.naming.ReferenceMaker;
47
48 public final class JndiRefConnectionPoolDataSource extends IdentityTokenResolvable implements ConnectionPoolDataSource JavaDoc, Serializable JavaDoc, Referenceable JavaDoc
49 {
50     final static MLogger logger = MLog.getLogger( JndiRefConnectionPoolDataSource.class );
51
52     final static Collection JavaDoc IGNORE_PROPS = Arrays.asList( new String JavaDoc[] {"reference", "pooledConnection"} );
53
54     JndiRefForwardingDataSource jrfds;
55     WrapperConnectionPoolDataSource wcpds;
56
57     String JavaDoc identityToken;
58
59     public JndiRefConnectionPoolDataSource()
60     { this( true ); }
61
62     public JndiRefConnectionPoolDataSource( boolean autoregister )
63     {
64     jrfds = new JndiRefForwardingDataSource();
65     wcpds = new WrapperConnectionPoolDataSource();
66     wcpds.setNestedDataSource( jrfds );
67
68     if (autoregister)
69         {
70         this.identityToken = C3P0ImplUtils.allocateIdentityToken( this );
71         C3P0Registry.reregister( this );
72         }
73     }
74
75     public boolean isJndiLookupCaching()
76     { return jrfds.isCaching(); }
77     
78     public void setJndiLookupCaching( boolean caching )
79     { jrfds.setCaching( caching ); }
80     
81     public Hashtable JavaDoc getJndiEnv()
82     { return jrfds.getJndiEnv(); }
83     
84     public void setJndiEnv( Hashtable JavaDoc jndiEnv )
85     { jrfds.setJndiEnv( jndiEnv ); }
86     
87     public Object JavaDoc getJndiName()
88     { return jrfds.getJndiName(); }
89     
90     public void setJndiName( Object JavaDoc jndiName ) throws PropertyVetoException JavaDoc
91     { jrfds.setJndiName( jndiName ); }
92
93     public int getAcquireIncrement()
94     { return wcpds.getAcquireIncrement(); }
95     
96     public void setAcquireIncrement( int acquireIncrement )
97     { wcpds.setAcquireIncrement( acquireIncrement ); }
98     
99     public int getAcquireRetryAttempts()
100     { return wcpds.getAcquireRetryAttempts(); }
101     
102     public void setAcquireRetryAttempts( int ara )
103     { wcpds.setAcquireRetryAttempts( ara ); }
104     
105     public int getAcquireRetryDelay()
106     { return wcpds.getAcquireRetryDelay(); }
107     
108     public void setAcquireRetryDelay( int ard )
109     { wcpds.setAcquireRetryDelay( ard ); }
110     
111     public boolean isAutoCommitOnClose()
112     { return wcpds.isAutoCommitOnClose(); }
113
114     public void setAutoCommitOnClose( boolean autoCommitOnClose )
115     { wcpds.setAutoCommitOnClose( autoCommitOnClose ); }
116     
117     public void setAutomaticTestTable( String JavaDoc att )
118     { wcpds.setAutomaticTestTable( att ); }
119     
120     public String JavaDoc getAutomaticTestTable()
121     { return wcpds.getAutomaticTestTable(); }
122     
123     public void setBreakAfterAcquireFailure( boolean baaf )
124     { wcpds.setBreakAfterAcquireFailure( baaf ); }
125     
126     public boolean isBreakAfterAcquireFailure()
127     { return wcpds.isBreakAfterAcquireFailure(); }
128
129     public void setCheckoutTimeout( int ct )
130     { wcpds.setCheckoutTimeout( ct ); }
131
132     public int getCheckoutTimeout()
133     { return wcpds.getCheckoutTimeout(); }
134     
135     public String JavaDoc getConnectionTesterClassName()
136     { return wcpds.getConnectionTesterClassName(); }
137     
138     public void setConnectionTesterClassName( String JavaDoc connectionTesterClassName ) throws PropertyVetoException JavaDoc
139     { wcpds.setConnectionTesterClassName( connectionTesterClassName ); }
140     
141     public boolean isForceIgnoreUnresolvedTransactions()
142     { return wcpds.isForceIgnoreUnresolvedTransactions(); }
143     
144     public void setForceIgnoreUnresolvedTransactions( boolean forceIgnoreUnresolvedTransactions )
145     { wcpds.setForceIgnoreUnresolvedTransactions( forceIgnoreUnresolvedTransactions ); }
146     
147     public String JavaDoc getIdentityToken()
148     { return identityToken; }
149     
150     public void setIdentityToken(String JavaDoc identityToken)
151     { this.identityToken = identityToken; }
152     
153     public void setIdleConnectionTestPeriod( int idleConnectionTestPeriod )
154     { wcpds.setIdleConnectionTestPeriod( idleConnectionTestPeriod ); }
155     
156     public int getIdleConnectionTestPeriod()
157     { return wcpds.getIdleConnectionTestPeriod(); }
158     
159     public int getInitialPoolSize()
160     { return wcpds.getInitialPoolSize(); }
161     
162     public void setInitialPoolSize( int initialPoolSize )
163     { wcpds.setInitialPoolSize( initialPoolSize ); }
164
165     public int getMaxIdleTime()
166     { return wcpds.getMaxIdleTime(); }
167     
168     public void setMaxIdleTime( int maxIdleTime )
169     { wcpds.setMaxIdleTime( maxIdleTime ); }
170     
171     public int getMaxPoolSize()
172     { return wcpds.getMaxPoolSize(); }
173     
174     public void setMaxPoolSize( int maxPoolSize )
175     { wcpds.setMaxPoolSize( maxPoolSize ); }
176     
177     public int getMaxStatements()
178     { return wcpds.getMaxStatements(); }
179     
180     public void setMaxStatements( int maxStatements )
181     { wcpds.setMaxStatements( maxStatements ); }
182     
183     public int getMaxStatementsPerConnection()
184     { return wcpds.getMaxStatementsPerConnection(); }
185     
186     public void setMaxStatementsPerConnection( int mspc )
187     { wcpds.setMaxStatementsPerConnection( mspc ); }
188     
189     public int getMinPoolSize()
190     { return wcpds.getMinPoolSize(); }
191     
192     public void setMinPoolSize( int minPoolSize )
193     { wcpds.setMinPoolSize( minPoolSize ); }
194     
195     public String JavaDoc getPreferredTestQuery()
196     { return wcpds.getPreferredTestQuery(); }
197     
198     public void setPreferredTestQuery( String JavaDoc ptq )
199     { wcpds.setPreferredTestQuery( ptq ); }
200     
201     public int getPropertyCycle()
202     { return wcpds.getPropertyCycle(); }
203     
204     public void setPropertyCycle( int propertyCycle )
205     { wcpds.setPropertyCycle( propertyCycle ); }
206     
207     public boolean isTestConnectionOnCheckin()
208     { return wcpds.isTestConnectionOnCheckin(); }
209     
210     public void setTestConnectionOnCheckin( boolean testConnectionOnCheckin )
211     { wcpds.setTestConnectionOnCheckin( testConnectionOnCheckin ); }
212     
213     public boolean isTestConnectionOnCheckout()
214     { return wcpds.isTestConnectionOnCheckout(); }
215     
216     public void setTestConnectionOnCheckout( boolean testConnectionOnCheckout )
217     { wcpds.setTestConnectionOnCheckout( testConnectionOnCheckout ); }
218     
219     public boolean isUsesTraditionalReflectiveProxies()
220     { return wcpds.isUsesTraditionalReflectiveProxies(); }
221     
222     public void setUsesTraditionalReflectiveProxies( boolean utrp )
223     { wcpds.setUsesTraditionalReflectiveProxies( utrp ); }
224     
225     public String JavaDoc getFactoryClassLocation()
226     { return jrfds.getFactoryClassLocation(); }
227
228     public void setFactoryClassLocation( String JavaDoc factoryClassLocation )
229     {
230     jrfds.setFactoryClassLocation( factoryClassLocation );
231     wcpds.setFactoryClassLocation( factoryClassLocation );
232     }
233
234     final static JavaBeanReferenceMaker referenceMaker = new JavaBeanReferenceMaker();
235     
236     static
237     {
238     referenceMaker.setFactoryClassName( C3P0JavaBeanObjectFactory.class.getName() );
239     referenceMaker.addReferenceProperty("acquireIncrement");
240     referenceMaker.addReferenceProperty("acquireRetryAttempts");
241     referenceMaker.addReferenceProperty("acquireRetryDelay");
242     referenceMaker.addReferenceProperty("autoCommitOnClose");
243     referenceMaker.addReferenceProperty("automaticTestTable");
244     referenceMaker.addReferenceProperty("checkoutTimeout");
245     referenceMaker.addReferenceProperty("connectionTesterClassName");
246     referenceMaker.addReferenceProperty("factoryClassLocation");
247     referenceMaker.addReferenceProperty("forceIgnoreUnresolvedTransactions");
248     referenceMaker.addReferenceProperty("idleConnectionTestPeriod");
249     referenceMaker.addReferenceProperty("identityToken");
250     referenceMaker.addReferenceProperty("initialPoolSize");
251     referenceMaker.addReferenceProperty("jndiEnv");
252     referenceMaker.addReferenceProperty("jndiLookupCaching");
253     referenceMaker.addReferenceProperty("jndiName");
254     referenceMaker.addReferenceProperty("maxIdleTime");
255     referenceMaker.addReferenceProperty("maxPoolSize");
256     referenceMaker.addReferenceProperty("maxStatements");
257     referenceMaker.addReferenceProperty("maxStatementsPerConnection");
258     referenceMaker.addReferenceProperty("minPoolSize");
259     referenceMaker.addReferenceProperty("preferredTestQuery");
260     referenceMaker.addReferenceProperty("propertyCycle");
261     referenceMaker.addReferenceProperty("testConnectionOnCheckin");
262     referenceMaker.addReferenceProperty("testConnectionOnCheckout");
263     referenceMaker.addReferenceProperty("usesTraditionalReflectiveProxies");
264     }
265     
266     public Reference JavaDoc getReference() throws NamingException JavaDoc
267     { return referenceMaker.createReference( this ); }
268
269     //implementation of javax.sql.ConnectionPoolDataSource
270
public PooledConnection JavaDoc getPooledConnection()
271     throws SQLException JavaDoc
272     { return wcpds.getPooledConnection(); }
273  
274     public PooledConnection JavaDoc getPooledConnection(String JavaDoc user, String JavaDoc password)
275     throws SQLException JavaDoc
276     { return wcpds.getPooledConnection( user, password ); }
277  
278     public PrintWriter JavaDoc getLogWriter()
279     throws SQLException JavaDoc
280     { return wcpds.getLogWriter(); }
281
282     public void setLogWriter(PrintWriter JavaDoc out)
283     throws SQLException JavaDoc
284     { wcpds.setLogWriter( out ); }
285
286     public void setLoginTimeout(int seconds)
287     throws SQLException JavaDoc
288     { wcpds.setLoginTimeout( seconds ); }
289
290     public int getLoginTimeout()
291     throws SQLException JavaDoc
292     { return wcpds.getLoginTimeout(); }
293
294     public String JavaDoc toString()
295     {
296     StringBuffer JavaDoc sb = new StringBuffer JavaDoc(512);
297     sb.append( super.toString() );
298     sb.append(" [");
299     try { BeansUtils.appendPropNamesAndValues( sb, this, IGNORE_PROPS ); }
300     catch (Exception JavaDoc e)
301         {
302         //e.printStackTrace();
303
if ( Debug.DEBUG && logger.isLoggable( MLevel.FINE ) )
304             logger.log( MLevel.FINE, "An exception occurred while extracting property names and values for toString()", e);
305         sb.append( e.toString() );
306         }
307     sb.append("]");
308     return sb.toString();
309     }
310 }
311
312
Popular Tags