com.mchange.v2.c3p0
Interface PooledDataSource

All Superinterfaces:
javax.sql.DataSource
All Known Implementing Classes:
ComboPooledDataSource, PoolBackedDataSource

public interface PooledDataSource
extends javax.sql.DataSource

Most clients need never use or know about this interface -- c3p0 pooled DataSources can be treated like any other DataSource. But, applications that are interested in following the current state of their pools can make use of these c3p0-specific methods.


Method Summary
 void close()
          C3P0 pooled DataSources use no resources before they are actually used in a VM, and they close themselves in their finalize() method.
 void close(boolean force_destory)
          Should be used only with great caution.
 int getNumBusyConnections()
           
 int getNumBusyConnections(java.lang.String username, java.lang.String password)
           
 int getNumConnections()
           
 int getNumConnections(java.lang.String username, java.lang.String password)
           
 int getNumConnectionsAllAuths()
           
 int getNumIdleConnections()
           
 int getNumIdleConnections(java.lang.String username, java.lang.String password)
           
 
Methods inherited from interface javax.sql.DataSource
getConnection, getConnection, getLoginTimeout, getLogWriter, setLoginTimeout, setLogWriter
 

Method Detail

getNumConnections

public int getNumConnections()
                      throws java.sql.SQLException
Throws:
java.sql.SQLException

getNumIdleConnections

public int getNumIdleConnections()
                          throws java.sql.SQLException
Throws:
java.sql.SQLException

getNumBusyConnections

public int getNumBusyConnections()
                          throws java.sql.SQLException
Throws:
java.sql.SQLException

getNumConnections

public int getNumConnections(java.lang.String username,
                             java.lang.String password)
                      throws java.sql.SQLException
Throws:
java.sql.SQLException

getNumIdleConnections

public int getNumIdleConnections(java.lang.String username,
                                 java.lang.String password)
                          throws java.sql.SQLException
Throws:
java.sql.SQLException

getNumBusyConnections

public int getNumBusyConnections(java.lang.String username,
                                 java.lang.String password)
                          throws java.sql.SQLException
Throws:
java.sql.SQLException

getNumConnectionsAllAuths

public int getNumConnectionsAllAuths()
                              throws java.sql.SQLException
Throws:
java.sql.SQLException

close

public void close()
           throws java.sql.SQLException

C3P0 pooled DataSources use no resources before they are actually used in a VM, and they close themselves in their finalize() method. When they are active and pooling, they may have open database connections and their pool may spawn several threads for its maintenance. You can use this method to clean these resource methods up quickly when you will no longer be using this DataSource. The resources will actually be cleaned up only if no other DataSources are sharing the same pool.

You can equivalently use the static method destroy() in the DataSources class to clean-up these resources.

This is equivalent to calling close( false ).

Throws:
java.sql.SQLException
See Also:
DataSources.destroy(javax.sql.DataSource)

close

public void close(boolean force_destory)

Should be used only with great caution. If force_destroy is set to true, this immediately destroys any pool and cleans up all resources this DataSource may be using, even if other DataSources are sharing that pool! In general, it is difficult to know whether a pool is being shared by multiple DataSources. It may depend upon whether or not a JNDI implementation returns a single instance or multiple copies upon lookup (which is undefined by the JNDI spec).

In general, this method should be used only when you wish to wind down all c3p0 pools in a ClassLoader. For example, when shutting down and restarting a web application that uses c3p0, you may wish to kill all threads making use of classes loaded by a web-app specific ClassLoader, so that the ClassLoader can be cleanly garbage collected. In this case, you may wish to use force destroy. Otherwise, it is much safer to use the simple destroy() method, which will not shut down pools that may still be in use.

To close a pool normally, use the no argument close method, or set force_destroy to false.

See Also:
close()