|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectinfo.fingo.db.pool.PoolingDataSource
public class PoolingDataSource
Connection pooling implementation of javax.sql.DataSource interface.
This implementation is database vendor independent.
There is a set of PROPERTY_XXX constants, with correspondig getters and setters which can be used to
customize the connection pool.
Examplary use:
void poolingDataSourceExample( String driverName, String dbUrl, String dbUser, String dbPassword ) throws SQLException
{
Connection conn = null;
try
{
// create new data source instance
PoolingDataSource pds = new PoolingDataSource( driverName, dbUrl, dbUser, dbPassword );
// customize your pool
pds.setInitialConnectionCount( 7 );
// any other setXXX method call
conn = pds.getConnection();
// use the connection
}
finally
{
if( conn != null )
{
// here, the connection isn't closed in fact
// it is now marked in the pool as 'free' - ready to use
conn.close();
}
}
}
PoolableConnection| Field Summary | |
|---|---|
protected java.util.Properties |
databaseProperties
The data source properties |
static int |
DEFAULT_ALL_CONNECTIONS_LIMIT
The default number of the all connections: 15. |
static int |
DEFAULT_CONNECTION_EXPIRE_TIME
The default connection expire time: 60 minutes. |
static int |
DEFAULT_CONNECTION_IDLE_TIME
The default connection idle time: 10 minutes. |
static int |
DEFAULT_CONNECTION_TIMEOUT
The default connection wait timeout: 10 seconds. |
static int |
DEFAULT_INITIAL_CONNECTION_COUNT
The default initial number of the pooled connections: 1. |
static int |
DEFAULT_MAXIMUM_CONNECTION_COUNT
The default maximum number of the pooled connections: 5. |
static java.lang.String |
PROPERTY_ALL_CONNECTIONS_LIMIT
The all connections limit property name: 'cm.connection.all.limit'. |
static java.lang.String |
PROPERTY_CONNECTION_EXPIRE_TIME
The connection expire time property name: 'cm.connection.expire.time'. |
static java.lang.String |
PROPERTY_CONNECTION_IDLE_TIME
The connection idle time property name: 'cm.connection.idle.time'. |
static java.lang.String |
PROPERTY_CONNECTION_TEST_QUERY
The query to ensure that conection is open: 'cm.connection.test.query'. |
static java.lang.String |
PROPERTY_CONNECTION_WAIT_TIMEOUT
The timeout waiting for connection property name: 'cm.connection.wait.timeout'. |
static java.lang.String |
PROPERTY_DB_PASSWORD
The databse password property name: 'cm.connection.password'. |
static java.lang.String |
PROPERTY_DB_URL
The database url property name: 'cm.connection.url'. |
static java.lang.String |
PROPERTY_DB_USER
The databse user name property name: 'cm.connection.user'. |
static java.lang.String |
PROPERTY_DRIVER_NAME
The driver property name: 'cm.connection.driver'. |
static java.lang.String |
PROPERTY_INITIAL_CONNECTION_COUNT
The initial connection count property name: 'cm.connection.count.initial'. |
static java.lang.String |
PROPERTY_MAX_CONNECTION_COUNT
The maximum connection count property name: 'cm.connection.count.maximum'. |
| Constructor Summary | |
|---|---|
PoolingDataSource()
Default constructor |
|
PoolingDataSource(java.util.Properties properties)
Creates new instance with the given properties as pool configuration. |
|
PoolingDataSource(java.lang.String driverClassName,
java.lang.String dbUrl,
java.lang.String dbUser,
java.lang.String dbPassword)
Creates new instance with all required properties specified. |
|
| Method Summary | |
|---|---|
int |
getAllConnectionsLimit()
Gets the limit for all connections. |
java.sql.Connection |
getConnection()
|
java.sql.Connection |
getConnection(java.lang.String username,
java.lang.String password)
|
int |
getConnectionExpireTime()
Gets the connection expire time. |
int |
getConnectionIdleTime()
Gets the connection idle time. |
java.lang.String |
getDriverClassName()
Gets the database driver class name. |
int |
getInitialConnectionCount()
Gets the initial connection count. |
int |
getLoginTimeout()
|
java.io.PrintWriter |
getLogWriter()
|
int |
getMaximumConnectionCount()
Gets the maximum connection count. |
java.lang.String |
getUrl()
Gets the database url. |
java.lang.String |
getUserName()
Gets the data source user name |
java.lang.String |
getValidationQuery()
Gets the connection validation query |
protected boolean |
isInitialized()
Tests if the data source is already initialized. |
void |
setAllConnectionsLimit(int count)
Sets the limit for all connections. |
void |
setConnectionExpireTime(int minutes)
Sets the connection expired time. |
void |
setConnectionIdleTime(int minutes)
Sets the connection idle time. |
void |
setDriverClassName(java.lang.String driverClassName)
Sets the database driver class name. |
void |
setInitialConnectionCount(int count)
Sets the initial count of the connections. |
void |
setLoginTimeout(int seconds)
|
void |
setLogWriter(java.io.PrintWriter out)
|
void |
setMaximumConnectionCount(int count)
Sets the maximum connection count. |
void |
setPassword(java.lang.String password)
Sets the data source password |
void |
setUrl(java.lang.String url)
Sets the database url |
void |
setUserName(java.lang.String userName)
Sets the data source user name. |
void |
setValidationQuery(java.lang.String validationQuery)
Sets the connection validation query. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public static final java.lang.String PROPERTY_ALL_CONNECTIONS_LIMIT
When the pool has maximum connection open and used, the data source may create connection which will be not
pooled. Such extra connection will be phisically closed just after Connection.close() method call.
The PROPERTY_ALL_CONNECTIONS_LIMIT defines the max count of pooled and non-pooled connections
together.
public static final java.lang.String PROPERTY_MAX_CONNECTION_COUNT
This property defines maximum count of pooled connections. When the value is reached, extra, not pooled
connections may be still created (until connection count < PROPERTY_ALL_CONNECTIONS_LIMIT).
PROPERTY_ALL_CONNECTIONS_LIMIT,
Constant Field Valuespublic static final java.lang.String PROPERTY_INITIAL_CONNECTION_COUNT
Defines count of connections the data source will create on initialization time.
PROPERTY_MAX_CONNECTION_COUNT,
PROPERTY_ALL_CONNECTIONS_LIMIT,
Constant Field Valuespublic static final java.lang.String PROPERTY_DRIVER_NAME
The full name of the database driver class. Required.
public static final java.lang.String PROPERTY_DB_URL
The database url. Required.
public static final java.lang.String PROPERTY_CONNECTION_WAIT_TIMEOUT
After that time, 'connection timeout' exception will be thrown when waiting for connection. Specified in seconds.
DEFAULT_CONNECTION_TIMEOUT,
Constant Field Valuespublic static final java.lang.String PROPERTY_CONNECTION_EXPIRE_TIME
Connection which was taken from the pool and not returned to the pool for expire time value will be closed. Specified in minutes.
DEFAULT_CONNECTION_EXPIRE_TIME,
Constant Field Valuespublic static final java.lang.String PROPERTY_CONNECTION_IDLE_TIME
After idle time, the not-used, pooled connection will be closed and removed from the pool. Specified in minutes.
DEFAULT_CONNECTION_IDLE_TIME,
Constant Field Valuespublic static final java.lang.String PROPERTY_DB_USER
The database user name.
public static final java.lang.String PROPERTY_DB_PASSWORD
The database user password.
public static final java.lang.String PROPERTY_CONNECTION_TEST_QUERY
The test query is used before returning requested connection, to ensure if it's really open. The query shouldn't be resource consuming, but must connect database.
public static final int DEFAULT_CONNECTION_TIMEOUT
public static final int DEFAULT_CONNECTION_EXPIRE_TIME
public static final int DEFAULT_CONNECTION_IDLE_TIME
public static final int DEFAULT_MAXIMUM_CONNECTION_COUNT
public static final int DEFAULT_INITIAL_CONNECTION_COUNT
public static final int DEFAULT_ALL_CONNECTIONS_LIMIT
protected java.util.Properties databaseProperties
| Constructor Detail |
|---|
public PoolingDataSource()
public PoolingDataSource(java.lang.String driverClassName,
java.lang.String dbUrl,
java.lang.String dbUser,
java.lang.String dbPassword)
driverClassName - -
the full name of database driver classdbUrl - -
the database urldbUser - -
the database user namedbPassword - -
the database user passwordpublic PoolingDataSource(java.util.Properties properties)
PROPERTY_XXX constants.
properties - -
the connection pool configuration| Method Detail |
|---|
public int getLoginTimeout()
throws java.sql.SQLException
getLoginTimeout in interface javax.sql.DataSourcejava.sql.SQLException
public void setLoginTimeout(int seconds)
throws java.sql.SQLException
setLoginTimeout in interface javax.sql.DataSourcejava.sql.SQLExceptionpublic int getConnectionExpireTime()
PROPERTY_CONNECTION_EXPIRE_TIMEpublic void setConnectionExpireTime(int minutes)
minutes - -
the connection expired time in minutesPROPERTY_CONNECTION_EXPIRE_TIMEpublic int getConnectionIdleTime()
PROPERTY_CONNECTION_IDLE_TIMEpublic void setConnectionIdleTime(int minutes)
minutes - -
the connection idle time in minutesPROPERTY_CONNECTION_IDLE_TIMEpublic int getMaximumConnectionCount()
PROPERTY_MAX_CONNECTION_COUNTpublic void setMaximumConnectionCount(int count)
count - -
the maximum connection count to setPROPERTY_MAX_CONNECTION_COUNTpublic int getInitialConnectionCount()
PROPERTY_INITIAL_CONNECTION_COUNTpublic void setInitialConnectionCount(int count)
count - -
the initial count of the connections to setPROPERTY_INITIAL_CONNECTION_COUNTpublic int getAllConnectionsLimit()
PROPERTY_ALL_CONNECTIONS_LIMITpublic void setAllConnectionsLimit(int count)
count - -
the limit for all connectionsPROPERTY_ALL_CONNECTIONS_LIMITpublic java.lang.String getValidationQuery()
PROPERTY_CONNECTION_TEST_QUERYpublic void setValidationQuery(java.lang.String validationQuery)
validationQuery - -
the connection validation query to setPROPERTY_CONNECTION_TEST_QUERYpublic java.lang.String getDriverClassName()
PROPERTY_DRIVER_NAMEpublic void setDriverClassName(java.lang.String driverClassName)
driverClassName - -
the database driver class namePROPERTY_DRIVER_NAMEpublic java.lang.String getUrl()
PROPERTY_DB_URLpublic void setUrl(java.lang.String url)
url - -
the database urlPROPERTY_DB_URLpublic java.lang.String getUserName()
public void setUserName(java.lang.String userName)
userName - the data source user name to set.PROPERTY_DB_USERpublic void setPassword(java.lang.String password)
password - -
the data source pasword to setPROPERTY_DB_PASSWORD
public java.io.PrintWriter getLogWriter()
throws java.sql.SQLException
getLogWriter in interface javax.sql.DataSourcejava.sql.SQLException
public void setLogWriter(java.io.PrintWriter out)
throws java.sql.SQLException
setLogWriter in interface javax.sql.DataSourcejava.sql.SQLException
public java.sql.Connection getConnection()
throws java.sql.SQLException
getConnection in interface javax.sql.DataSourcejava.sql.SQLException
public java.sql.Connection getConnection(java.lang.String username,
java.lang.String password)
throws java.sql.SQLException
getConnection in interface javax.sql.DataSourcejava.sql.SQLExceptionprotected boolean isInitialized()
true, if this data source is already initialized.
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||