Top Description Fields Constructors Methods
com.mchange.v2.c3p0

public final Class DataSources

extends Object
Class Inheritance
Imports
com.mchange.v2.log.*, java.beans.PropertyChangeEvent, .PropertyVetoException, java.util.Arrays, .Collections, .Enumeration, .HashMap, .HashSet, .Iterator, .Map, .Properties, .Set, java.sql.SQLException, javax.sql.DataSource, .ConnectionPoolDataSource, com.mchange.v2.sql.SqlUtils, com.mchange.v2.beans.BeansUtils

A simple factory class for creating DataSources. Generally, users will call DataSources.unpooledDataSource() to get a basic DataSource, and then get a pooled version by calling DataSources.pooledDataSource().

Most users will not need to worry about configuration details. If you want to use a PreparedStatement cache, be sure to call the version of DataSources.pooledDataSource() that accepts a statement_cache_size parameter, and set that to be a number (much) greater than zero. (For maximum performance, you would set this to be several times the number kinds of PreparedStatements you expect your application to use.)

For those interested in detailed configuration, note that c3p0 pools can be configured by providing explicit Properties objects (driver properties for unpooledDataSource(), bean properties for pooledDataSource()), by defining a c3p0.properties file in your resource path, or by defining System properties.

Field Summary

Modifier and TypeField and Description
pack-priv static final MLogger

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static void
destroy(DataSource pooledDataSource)

Immediately releases resources (Threads and database Connections) that are held by a C3P0 DataSource.

private static void
destroy(DataSource pooledDataSource, boolean force)

public static void
forceDestroy(DataSource pooledDataSource)
Deprecated forceDestroy() is no longer meaningful, as a set of pools is now directly associated with a DataSource, and not potentially shared.

public static DataSource

Returns:

a DataSource that can be cast to a PooledDataSource if you are interested in pool statistics
pooledDataSource
(DataSource unpooledDataSource)

Creates a pooled version of an unpooled DataSource using default configuration information.

public static DataSource

Returns:

a DataSource that can be cast to a PooledDataSource if you are interested in pool statistics
pooledDataSource
(DataSource unpooledDataSource, int statement_cache_size)

Creates a pooled version of an unpooled DataSource using default configuration information and the specified startement cache size.

public static DataSource
pooledDataSource(DataSource unpooledDataSource, String configName)

public static DataSource
pooledDataSource(DataSource unpooledDataSource, Map<K, V> overrideProps)

public static DataSource
pooledDataSource(DataSource unpooledDataSource, String configName, Map<K, V> overrideProps)

public static DataSource

Returns:

a DataSource that can be cast to a PooledDataSource if you are interested in pool statistics
pooledDataSource
(DataSource unpooledDataSource, Properties props)

Creates a pooled version of an unpooled DataSource using configuration information supplied explicitly by a Java Properties object.

public static DataSource
unpooledDataSource()

Defines an unpooled DataSource all of whose paramateres (especially jdbcUrl) should be set in config files.

public static DataSource
public static DataSource
unpooledDataSource(String jdbcUrl, String user, String password)

Defines an unpooled DataSource on the specified JDBC URL, authenticating with a username and password.

public static DataSource
unpooledDataSource(String jdbcUrl, Properties
the usual DriverManager properties for your JDBC driver (e.g. "user" and "password" for most drivers that support authentication)
driverProps
)

Defines an unpooled DataSource on the specified JDBC URL.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

loggerback to summary
pack-priv static final MLogger logger

Constructor Detail

DataSourcesback to summary
private DataSources()

Method Detail

destroyback to summary
public static void destroy(DataSource pooledDataSource) throws SQLException

Immediately releases resources (Threads and database Connections) that are held by a C3P0 DataSource.

Only DataSources created by the poolingDataSource() method hold any non-memory resources. Calling this method on unpooled DataSources is effectively a no-op.

You can safely presume that destroying a pooled DataSource that is wrapped around another DataSource created by this library destroys both the outer and the wrapped DataSource. There is no reason to hold a reference to a nested DataSource in order to explicitly destroy it.

destroyback to summary
private static void destroy(DataSource pooledDataSource, boolean force) throws SQLException
forceDestroyback to summary
public static void forceDestroy(DataSource pooledDataSource) throws SQLException

Deprecated

forceDestroy() is no longer meaningful, as a set of pools is now directly associated with a DataSource, and not potentially shared. (This simplification was made possible by canonicalization of JNDI-looked-up DataSources within a virtual machine.) Just use DataSources.destroy().

See Also
destroy
pooledDataSourceback to summary
public static DataSource pooledDataSource(DataSource unpooledDataSource) throws SQLException

Creates a pooled version of an unpooled DataSource using default configuration information.

Note

By default, statement pooling is turned off, because for simple databases that do not pre-parse and optimize PreparedStatements, statement caching is a net performance loss. But if your database does optimize PreparedStatements you'll want to turn StatementCaching on via pooledDataSource(javax.sql.DataSource, int).

Returns:DataSource

a DataSource that can be cast to a PooledDataSource if you are interested in pool statistics

pooledDataSourceback to summary
public static DataSource pooledDataSource(DataSource unpooledDataSource, int statement_cache_size) throws SQLException

Creates a pooled version of an unpooled DataSource using default configuration information and the specified startement cache size. Use a value greater than zero to turn statement caching on.

Returns:DataSource

a DataSource that can be cast to a PooledDataSource if you are interested in pool statistics

pooledDataSourceback to summary
public static DataSource pooledDataSource(DataSource unpooledDataSource, String configName) throws SQLException
pooledDataSourceback to summary
public static DataSource pooledDataSource(DataSource unpooledDataSource, Map<K, V> overrideProps) throws SQLException
pooledDataSourceback to summary
public static DataSource pooledDataSource(DataSource unpooledDataSource, String configName, Map<K, V> overrideProps) throws SQLException
pooledDataSourceback to summary
public static DataSource pooledDataSource(DataSource unpooledDataSource, Properties props) throws SQLException

Creates a pooled version of an unpooled DataSource using configuration information supplied explicitly by a Java Properties object.

Returns:DataSource

a DataSource that can be cast to a PooledDataSource if you are interested in pool statistics

unpooledDataSourceback to summary
public static DataSource unpooledDataSource() throws SQLException

Defines an unpooled DataSource all of whose paramateres (especially jdbcUrl) should be set in config files.

unpooledDataSourceback to summary
public static DataSource unpooledDataSource(String jdbcUrl) throws SQLException
unpooledDataSourceback to summary
public static DataSource unpooledDataSource(String jdbcUrl, String user, String password) throws SQLException

Defines an unpooled DataSource on the specified JDBC URL, authenticating with a username and password.

unpooledDataSourceback to summary
public static DataSource unpooledDataSource(String jdbcUrl, Properties driverProps) throws SQLException

Defines an unpooled DataSource on the specified JDBC URL.

Parameters
driverProps:Properties

the usual DriverManager properties for your JDBC driver (e.g. "user" and "password" for most drivers that support authentication)

See Also
java.sql.DriverManager