KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > mchange > v2 > c3p0 > mbean > C3P0PooledDataSource


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.mbean;
25
26 import com.mchange.v2.c3p0.*;
27 import com.mchange.v2.log.*;
28 import java.beans.PropertyVetoException JavaDoc;
29 import java.sql.Connection JavaDoc;
30 import java.sql.SQLException JavaDoc;
31 import java.io.PrintWriter JavaDoc;
32 import java.util.Properties JavaDoc;
33 import javax.sql.DataSource JavaDoc;
34 import javax.naming.InitialContext JavaDoc;
35 import javax.naming.Name JavaDoc;
36 import javax.naming.Context JavaDoc;
37 import javax.naming.NameAlreadyBoundException JavaDoc;
38 import javax.naming.NamingException JavaDoc;
39
40 /**
41  * @deprecated Please use com.mchange.v2.c3p0.jboss.C3P0PooledDataSource
42  */

43 public class C3P0PooledDataSource implements C3P0PooledDataSourceMBean
44 {
45     private final static MLogger logger = MLog.getLogger( C3P0PooledDataSource.class );
46
47     String JavaDoc jndiName;
48
49     ComboPooledDataSource combods = new ComboPooledDataSource();
50
51     private void rebind() throws NamingException JavaDoc
52     { rebind(null); }
53
54     private void rebind(String JavaDoc unbindName) throws NamingException JavaDoc
55     {
56     InitialContext JavaDoc ictx = new InitialContext JavaDoc();
57     if (unbindName != null)
58         ictx.unbind( unbindName );
59     
60     if (jndiName != null)
61     {
62         // Thanks to David D. Kilzer for this code to auto-create
63
// subcontext paths!
64
Name JavaDoc name = ictx.getNameParser( jndiName ).parse( jndiName );
65         Context JavaDoc ctx = ictx;
66         for (int i = 0, max = name.size() - 1; i < max; i++)
67         {
68         try
69         { ctx = ctx.createSubcontext( name.get( i ) ); }
70         catch (NameAlreadyBoundException JavaDoc ignore)
71         { ctx = (Context JavaDoc) ctx.lookup( name.get( i ) ); }
72         }
73
74         ictx.rebind( jndiName, combods );
75     }
76
77
78     }
79
80     // Jndi Setup Names
81
public void setJndiName(String JavaDoc jndiName) throws NamingException JavaDoc
82     {
83     String JavaDoc unbindName = this.jndiName;
84     this.jndiName = jndiName;
85     rebind( unbindName );
86     }
87
88     public String JavaDoc getJndiName()
89     { return jndiName; }
90
91     // DriverManagerDataSourceProperties (count: 4)
92
public String JavaDoc getDescription()
93     { return combods.getDescription(); }
94     
95     public void setDescription( String JavaDoc description ) throws NamingException JavaDoc
96     {
97     combods.setDescription( description );
98     rebind();
99     }
100     
101     public String JavaDoc getDriverClass()
102     { return combods.getDriverClass(); }
103     
104     public void setDriverClass( String JavaDoc driverClass ) throws PropertyVetoException JavaDoc, NamingException JavaDoc
105     {
106     combods.setDriverClass( driverClass );
107     rebind();
108     }
109     
110     public String JavaDoc getJdbcUrl()
111     { return combods.getJdbcUrl(); }
112     
113     public void setJdbcUrl( String JavaDoc jdbcUrl ) throws NamingException JavaDoc
114     {
115     combods.setJdbcUrl( jdbcUrl );
116     rebind();
117     }
118     
119     // DriverManagerDataSource "virtual properties" based on properties
120
public String JavaDoc getUser()
121     { return combods.getUser(); }
122     
123     public void setUser( String JavaDoc user ) throws NamingException JavaDoc
124     {
125     combods.setUser( user );
126     rebind();
127     }
128     
129     public String JavaDoc getPassword()
130     { return combods.getPassword(); }
131     
132     public void setPassword( String JavaDoc password ) throws NamingException JavaDoc
133     {
134     combods.setPassword( password );
135     rebind();
136     }
137
138     // WrapperConnectionPoolDataSource properties (count: 21)
139
public int getCheckoutTimeout()
140     { return combods.getCheckoutTimeout(); }
141     
142     public void setCheckoutTimeout( int checkoutTimeout ) throws NamingException JavaDoc
143     {
144     combods.setCheckoutTimeout( checkoutTimeout );
145     rebind();
146     }
147
148     public int getAcquireIncrement()
149     { return combods.getAcquireIncrement(); }
150     
151     public void setAcquireIncrement( int acquireIncrement ) throws NamingException JavaDoc
152     {
153     combods.setAcquireIncrement( acquireIncrement );
154     rebind();
155     }
156     
157     public int getAcquireRetryAttempts()
158     { return combods.getAcquireRetryAttempts(); }
159     
160     public void setAcquireRetryAttempts( int acquireRetryAttempts ) throws NamingException JavaDoc
161     {
162     combods.setAcquireRetryAttempts( acquireRetryAttempts );
163     rebind();
164     }
165     
166     public int getAcquireRetryDelay()
167     { return combods.getAcquireRetryDelay(); }
168     
169     public void setAcquireRetryDelay( int acquireRetryDelay ) throws NamingException JavaDoc
170     {
171     combods.setAcquireRetryDelay( acquireRetryDelay );
172     rebind();
173     }
174     
175     public boolean isAutoCommitOnClose()
176     { return combods.isAutoCommitOnClose(); }
177
178     public void setAutoCommitOnClose( boolean autoCommitOnClose ) throws NamingException JavaDoc
179     {
180     combods.setAutoCommitOnClose( autoCommitOnClose );
181     rebind();
182     }
183     
184     public String JavaDoc getConnectionTesterClassName()
185     { return combods.getConnectionTesterClassName(); }
186     
187     public void setConnectionTesterClassName( String JavaDoc connectionTesterClassName ) throws PropertyVetoException JavaDoc, NamingException JavaDoc
188     {
189     combods.setConnectionTesterClassName( connectionTesterClassName );
190     rebind();
191     }
192     
193     public String JavaDoc getAutomaticTestTable()
194     { return combods.getAutomaticTestTable(); }
195     
196     public void setAutomaticTestTable( String JavaDoc automaticTestTable ) throws NamingException JavaDoc
197     {
198     combods.setAutomaticTestTable( automaticTestTable );
199     rebind();
200     }
201     
202     public boolean isForceIgnoreUnresolvedTransactions()
203     { return combods.isForceIgnoreUnresolvedTransactions(); }
204     
205     public void setForceIgnoreUnresolvedTransactions( boolean forceIgnoreUnresolvedTransactions ) throws NamingException JavaDoc
206     {
207     combods.setForceIgnoreUnresolvedTransactions( forceIgnoreUnresolvedTransactions );
208     rebind();
209     }
210     
211     public int getIdleConnectionTestPeriod()
212     { return combods.getIdleConnectionTestPeriod(); }
213     
214     public void setIdleConnectionTestPeriod( int idleConnectionTestPeriod ) throws NamingException JavaDoc
215     {
216     combods.setIdleConnectionTestPeriod( idleConnectionTestPeriod );
217     rebind();
218     }
219     
220     public int getInitialPoolSize()
221     { return combods.getInitialPoolSize(); }
222     
223     public void setInitialPoolSize( int initialPoolSize ) throws NamingException JavaDoc
224     {
225     combods.setInitialPoolSize( initialPoolSize );
226     rebind();
227     }
228
229     public int getMaxIdleTime()
230     { return combods.getMaxIdleTime(); }
231     
232     public void setMaxIdleTime( int maxIdleTime ) throws NamingException JavaDoc
233     {
234     combods.setMaxIdleTime( maxIdleTime );
235     rebind();
236     }
237     
238     public int getMaxPoolSize()
239     { return combods.getMaxPoolSize(); }
240     
241     public void setMaxPoolSize( int maxPoolSize ) throws NamingException JavaDoc
242     {
243     combods.setMaxPoolSize( maxPoolSize );
244     rebind();
245     }
246     
247     public int getMaxStatements()
248     { return combods.getMaxStatements(); }
249     
250     public void setMaxStatements( int maxStatements ) throws NamingException JavaDoc
251     {
252     combods.setMaxStatements( maxStatements );
253     rebind();
254     }
255     
256     public int getMaxStatementsPerConnection()
257     { return combods.getMaxStatementsPerConnection(); }
258     
259     public void setMaxStatementsPerConnection( int maxStatementsPerConnection ) throws NamingException JavaDoc
260     {
261     combods.setMaxStatementsPerConnection( maxStatementsPerConnection );
262     rebind();
263     }
264     
265     public int getMinPoolSize()
266     { return combods.getMinPoolSize(); }
267     
268     public void setMinPoolSize( int minPoolSize ) throws NamingException JavaDoc
269     {
270     combods.setMinPoolSize( minPoolSize );
271     rebind();
272     }
273     
274     public int getPropertyCycle()
275     { return combods.getPropertyCycle(); }
276     
277     public void setPropertyCycle( int propertyCycle ) throws NamingException JavaDoc
278     {
279     combods.setPropertyCycle( propertyCycle );
280     rebind();
281     }
282     
283     public boolean isBreakAfterAcquireFailure()
284     { return combods.isBreakAfterAcquireFailure(); }
285     
286     public void setBreakAfterAcquireFailure( boolean breakAfterAcquireFailure ) throws NamingException JavaDoc
287     {
288     combods.setBreakAfterAcquireFailure( breakAfterAcquireFailure );
289     rebind();
290     }
291     
292     public boolean isTestConnectionOnCheckout()
293     { return combods.isTestConnectionOnCheckout(); }
294     
295     public void setTestConnectionOnCheckout( boolean testConnectionOnCheckout ) throws NamingException JavaDoc
296     {
297     combods.setTestConnectionOnCheckout( testConnectionOnCheckout );
298     rebind();
299     }
300     
301     public boolean isTestConnectionOnCheckin()
302     { return combods.isTestConnectionOnCheckin(); }
303     
304     public void setTestConnectionOnCheckin( boolean testConnectionOnCheckin ) throws NamingException JavaDoc
305     {
306     combods.setTestConnectionOnCheckin( testConnectionOnCheckin );
307     rebind();
308     }
309     
310     public boolean isUsesTraditionalReflectiveProxies()
311     { return combods.isUsesTraditionalReflectiveProxies(); }
312     
313     public void setUsesTraditionalReflectiveProxies( boolean usesTraditionalReflectiveProxies ) throws NamingException JavaDoc
314     {
315     combods.setUsesTraditionalReflectiveProxies( usesTraditionalReflectiveProxies );
316     rebind();
317     }
318
319     public String JavaDoc getPreferredTestQuery()
320     { return combods.getPreferredTestQuery(); }
321     
322     public void setPreferredTestQuery( String JavaDoc preferredTestQuery ) throws NamingException JavaDoc
323     {
324     combods.setPreferredTestQuery( preferredTestQuery );
325     rebind();
326     }
327
328     // PoolBackedDataSource properties (count: 2)
329
public String JavaDoc getDataSourceName()
330     { return combods.getDataSourceName(); }
331     
332     public void setDataSourceName( String JavaDoc name ) throws NamingException JavaDoc
333     {
334     combods.setDataSourceName( name );
335     rebind();
336     }
337
338     public int getNumHelperThreads()
339     { return combods.getNumHelperThreads(); }
340     
341     public void setNumHelperThreads( int numHelperThreads ) throws NamingException JavaDoc
342     {
343     combods.setNumHelperThreads( numHelperThreads );
344     rebind();
345     }
346
347     // shared properties (count: 1)
348
public String JavaDoc getFactoryClassLocation()
349     { return combods.getFactoryClassLocation(); }
350     
351     public void setFactoryClassLocation( String JavaDoc factoryClassLocation ) throws NamingException JavaDoc
352     {
353     combods.setFactoryClassLocation( factoryClassLocation );
354     rebind();
355     }
356
357     // PooledDataSource statistics
358

359     public int getNumUserPools() throws SQLException JavaDoc
360     { return combods.getNumUserPools(); }
361
362     public int getNumConnectionsDefaultUser() throws SQLException JavaDoc
363     { return combods.getNumConnectionsDefaultUser(); }
364
365     public int getNumIdleConnectionsDefaultUser() throws SQLException JavaDoc
366     { return combods.getNumIdleConnectionsDefaultUser(); }
367
368     public int getNumBusyConnectionsDefaultUser() throws SQLException JavaDoc
369     { return combods.getNumBusyConnectionsDefaultUser(); }
370
371     public int getNumUnclosedOrphanedConnectionsDefaultUser() throws SQLException JavaDoc
372     { return combods.getNumUnclosedOrphanedConnectionsDefaultUser(); }
373
374     public int getNumConnections(String JavaDoc username, String JavaDoc password) throws SQLException JavaDoc
375     { return combods.getNumConnections(username, password); }
376
377     public int getNumIdleConnections(String JavaDoc username, String JavaDoc password) throws SQLException JavaDoc
378     { return combods.getNumIdleConnections(username, password); }
379
380     public int getNumBusyConnections(String JavaDoc username, String JavaDoc password) throws SQLException JavaDoc
381     { return combods.getNumBusyConnections(username, password); }
382
383     public int getNumUnclosedOrphanedConnections(String JavaDoc username, String JavaDoc password) throws SQLException JavaDoc
384     { return combods.getNumUnclosedOrphanedConnections(username, password); }
385
386     public int getNumConnectionsAllUsers() throws SQLException JavaDoc
387     { return combods.getNumConnectionsAllUsers(); }
388
389     public int getNumIdleConnectionsAllUsers() throws SQLException JavaDoc
390     { return combods.getNumIdleConnectionsAllUsers(); }
391
392     public int getNumBusyConnectionsAllUsers() throws SQLException JavaDoc
393     { return combods.getNumBusyConnectionsAllUsers(); }
394
395     public int getNumUnclosedOrphanedConnectionsAllUsers() throws SQLException JavaDoc
396     { return combods.getNumUnclosedOrphanedConnectionsAllUsers(); }
397
398     // PooledDataSource operations
399
public void softResetDefaultUser() throws SQLException JavaDoc
400     { combods.softResetDefaultUser(); }
401
402     public void softReset(String JavaDoc username, String JavaDoc password) throws SQLException JavaDoc
403     { combods.softReset(username, password); }
404
405     public void softResetAllUsers() throws SQLException JavaDoc
406     { combods.softResetAllUsers(); }
407
408     public void hardReset() throws SQLException JavaDoc
409     { combods.hardReset(); }
410
411     public void close() throws SQLException JavaDoc
412     { combods.close(); }
413
414     //JBoss only... (but these methods need not be called for the mbean to work)
415
public void create() throws Exception JavaDoc
416     { }
417
418     // the mbean works without this, but if called we start populating the pool early
419
public void start() throws Exception JavaDoc
420     {
421     //System.err.println("Bound C3P0 PooledDataSource to name '" + jndiName + "'. Starting...");
422
logger.log(MLevel.INFO, "Bound C3P0 PooledDataSource to name ''{0}''. Starting...", jndiName);
423     combods.getNumBusyConnectionsDefaultUser(); //just touch the datasource to start it up.
424
}
425
426
427     public void stop()
428     { }
429
430     public void destroy()
431     { }
432 }
433
434
Popular Tags