public final class DataSourceFactory extends Object
Modifier and Type | Method and Description |
---|---|
static DataSource |
getDataSource(ConnectionProperties poolSpec)
Return a DataSource instance from a pool that manages JDBC driver based connections.
|
static DataSource |
getDataSource(String jndiName)
Return a DataSource instance for a JNDI managed JDBC data source.
|
static void |
reset()
Resets the internal state of the factory.
|
public static DataSource getDataSource(String jndiName) throws FactoryException
jndiName
- The JNDI connection nameFactoryException
- When no date source can be retrieved from JNDINullPointerException
- When jndiName
is nullIllegalArgumentException
- When jndiName
is emptypublic static DataSource getDataSource(ConnectionProperties poolSpec) throws FactoryException
The driver-based data sources are managed in a data source pool. The pool is created using the provided properties for both the connection / data source and the pool spec. Once the pool has been created, it is cached (based on the connection parameters, i.e. the URL and username), and can no longer be changed. Subsequent calls to this method will return a data source from the cached pool, and changes in the pool spec (e.g. changes to the size of the pool) will be ignored.
poolSpec
- A connection pool spec that has the driver and url configured as non-empty stringsFactoryException
- When the data source cannot be retrieved from the pool, or the pool cannot be
createdNullPointerException
- When the poolSpec
, poolSpec.getDriver()
, or
poolSpec.getUrl()
are null
IllegalArgumentException
- When poolSpec.getDriver()
or poolSpec.getUrl()
are emptypublic static void reset()
This method does not release any resources that have been borrowed from the connection pools managed by this factory. To avoid resource leaks, you must close / return all connections to their pools before calling this method.
Copyright © 2014–2016 Michael Beiter