public final class JDCConnectionPool
extends java.lang.Object
implements javax.sql.ConnectionPoolDataSource, com.knowgate.storage.DataSource
JDBC Connection Pool
Implementation of a standard JDBC connection pool.
Constructor and Description |
---|
JDCConnectionPool() |
JDCConnectionPool(java.lang.Object bind,
java.lang.String url,
java.lang.String user,
java.lang.String password,
int maxpoolsize,
int maxconnections)
Constructor
This method sets a default login timeout of 20 seconds
|
JDCConnectionPool(java.lang.Object bind,
java.lang.String url,
java.lang.String user,
java.lang.String password,
int maxpoolsize,
int maxconnections,
int logintimeout)
Constructor
This method sets a default login timeout of 20 seconds
|
JDCConnectionPool(java.lang.Object bind,
java.lang.String url,
java.lang.String user,
java.lang.String password,
int maxpoolsize,
int maxconnections,
int logintimeout,
long connectiontimeout)
Constructor
This method sets a default login timeout of 20 seconds
|
JDCConnectionPool(java.lang.String url,
java.lang.String user,
java.lang.String password)
Constructor
By default, maximum pool size is set to 32,
maximum opened connections is 100,
login timeout is 20 seconds,
connection timeout is 5 minutes.
|
JDCConnectionPool(java.lang.String url,
java.lang.String user,
java.lang.String password,
int maxpoolsize,
int maxconnections)
Constructor
This method sets a default login timeout of 20 seconds
|
JDCConnectionPool(java.lang.String url,
java.lang.String user,
java.lang.String password,
int maxpoolsize,
int maxconnections,
int logintimeout)
Constructor
|
Modifier and Type | Method and Description |
---|---|
void |
close()
Close all connections and stop connection reaper
|
void |
closeConnections()
Close all connections from the pool regardless of their current state
|
int |
closeStaledConnections()
Close connections from the pool not used for a longer time
|
java.lang.String |
dumpStatistics()
Human readable usage statistics
|
JDCActivityInfo |
getActivityInfo()
Get information of current activity at database to which this pool is connected
|
JDCConnection[] |
getAllConnections()
Get an array with references to all pooled connections
|
JDCConnection |
getConnection(java.lang.String sCaller)
Get a connection from the pool
|
JDCConnection |
getConnectionForPId(java.lang.String sPId)
Get conenction for a server process identifier
|
javax.sql.DataSource |
getDatabaseBinding()
Get the DBbind object owner of this conenction pool
|
java.util.Map |
getDBTablesMap() |
com.knowgate.storage.Engine |
getEngine() |
int |
getLoginTimeout()
Get login timeout from java.sql.DriverManager
|
java.io.PrintWriter |
getLogWriter()
Get LogWriter from java.sql.DriverManager
|
int |
getMaxPoolSize()
Absolute maximum allowed for concurrent opened connections.
|
com.knowgate.storage.SchemaMetaData |
getMetaData() |
java.util.logging.Logger |
getParentLogger()
This method is added for compatibility with Java 7 and it is not implemented
|
javax.sql.PooledConnection |
getPooledConnection()
Get a connection from the pool
|
javax.sql.PooledConnection |
getPooledConnection(java.lang.String sUser,
java.lang.String sPasswd)
Get a connection bypassing the pool and connection directly to the database with the given user and password
|
int |
getPoolSize()
Get prefered open connections limit
Additional connections beyond PoolSize may be opened but they
will closed inmediately after use and not pooled.
|
long |
getReaperDaemonDelay()
Delay betwwen connection reaper executions
|
long |
getTimeout()
Get staled connection threshold
The default value is 600000ms (10 mins.)
|
boolean |
isClosed() |
boolean |
isReadOnly() |
void |
open(java.lang.String url,
java.lang.String user,
java.lang.String password,
boolean readonly)
Open ConnectionPool
By default, maximum pool size is set to 32,
maximum opened connections is 100,
login timeout is 20 seconds,
connection timeout is 5 minutes.
|
com.knowgate.storage.Table |
openTable(com.knowgate.storage.Record oRec) |
com.knowgate.storage.Table |
openTable(java.lang.String sName) |
com.knowgate.storage.Table |
openTable(java.lang.String sName,
java.lang.String[] sIndexes) |
void |
returnConnection(JDCConnection conn)
Return a connection to the pool
|
void |
returnConnection(JDCConnection conn,
java.lang.String sCaller)
Return a connection to the pool
|
void |
setLoginTimeout(int seconds)
Set login timeout for java.sql.DriverManager
|
void |
setLogWriter(java.io.PrintWriter printwrt)
Set LogWriter for java.sql.DriverManager
|
void |
setMaxPoolSize(int iMaxConnections)
Set maximum concurrent open connections limit
The default value is 100.
|
void |
setPoolSize(int iPoolSize)
Set prefered open connections limit
Additional connections beyond PoolSize may be opened but they
will closed inmediately after use and not pooled.
|
void |
setReaperDaemonDelay(long lDelayMs)
Set delay betwwen connection reaper executions (default value is 5 mins)
|
void |
setTimeout(long miliseconds)
Set staled connection threshold
|
int |
size() |
public JDCConnectionPool()
public JDCConnectionPool(java.lang.String url, java.lang.String user, java.lang.String password) throws com.knowgate.storage.StorageException
url
- JDBC URL stringuser
- Database userpassword
- Password for usercom.knowgate.storage.StorageException
public JDCConnectionPool(java.lang.Object bind, java.lang.String url, java.lang.String user, java.lang.String password, int maxpoolsize, int maxconnections, int logintimeout, long connectiontimeout)
Constructor
This method sets a default login timeout of 20 secondsbind
- DBBind owner of the connection pool (may be null)url
- JDBC URL stringuser
- Database userpassword
- Password for usermaxpoolsize
- Maximum pool sizemaxconnections
- Maximum opened connectionsconnectiontimeout
- Maximum time that alogintimeout
- Maximum time, in seconds, to wait for connectionpublic JDCConnectionPool(java.lang.Object bind, java.lang.String url, java.lang.String user, java.lang.String password, int maxpoolsize, int maxconnections, int logintimeout)
Constructor
This method sets a default login timeout of 20 secondsbind
- DBBind owner of the connection pool (may be null)url
- JDBC URL stringuser
- Database userpassword
- Password for usermaxpoolsize
- Maximum pool sizemaxconnections
- Maximum opened connectionslogintimeout
- Maximum time, in seconds, to wait for connectionpublic JDCConnectionPool(java.lang.Object bind, java.lang.String url, java.lang.String user, java.lang.String password, int maxpoolsize, int maxconnections)
Constructor
This method sets a default login timeout of 20 secondsbind
- DBBind owner of the connection pool (may be null)url
- JDBC URL stringuser
- Database userpassword
- Password for usermaxpoolsize
- Maximum pool size (Default 32)maxconnections
- Maximum opened connections (Default 100)public JDCConnectionPool(java.lang.String url, java.lang.String user, java.lang.String password, int maxpoolsize, int maxconnections, int logintimeout)
Constructor
url
- JDBC URL stringuser
- Database userpassword
- Password for usermaxpoolsize
- Maximum pool size (Default 32)maxconnections
- Maximum opened connections (Default 100)logintimeout
- Maximum time, in seconds, to wait for connectionpublic JDCConnectionPool(java.lang.String url, java.lang.String user, java.lang.String password, int maxpoolsize, int maxconnections)
Constructor
This method sets a default login timeout of 20 secondsurl
- JDBC URL stringuser
- Database userpassword
- Password for usermaxpoolsize
- Maximum pool sizemaxconnections
- Maximum opened connectionspublic com.knowgate.storage.Engine getEngine()
getEngine
in interface com.knowgate.storage.DataSource
public void open(java.lang.String url, java.lang.String user, java.lang.String password, boolean readonly) throws com.knowgate.storage.StorageException
Open ConnectionPool
By default, maximum pool size is set to 32, maximum opened connections is 100, login timeout is 20 seconds, connection timeout is 5 minutes.open
in interface com.knowgate.storage.DataSource
url
- JDBC URL stringuser
- Database userpassword
- Password for usercom.knowgate.storage.StorageException
public void close()
close
in interface com.knowgate.storage.DataSource
public boolean isClosed()
isClosed
in interface com.knowgate.storage.DataSource
public int getPoolSize()
Get prefered open connections limit
Additional connections beyond PoolSize may be opened but they
will closed inmediately after use and not pooled.
The default value is 32.
public void setPoolSize(int iPoolSize)
Set prefered open connections limit
Additional connections beyond PoolSize may be opened but they
will closed inmediately after use and not pooled.
The default value is 32.
Connections not being used can only be in the pool for a maximum of five minutes.
After a connection is not used for over 5 minutes it will be closed so the actual
pool size will eventually go down to zero after a period of inactivity.
iPoolSize
- Maximum pooled connectionspublic void setMaxPoolSize(int iMaxConnections)
Set maximum concurrent open connections limit
The default value is 100.iMaxConnections
- Absolute maximum for opened connectionspublic int getMaxPoolSize()
Absolute maximum allowed for concurrent opened connections.
The default value is 100.public java.io.PrintWriter getLogWriter() throws java.sql.SQLException
getLogWriter
in interface javax.sql.CommonDataSource
java.sql.SQLException
public void setLogWriter(java.io.PrintWriter printwrt) throws java.sql.SQLException
setLogWriter
in interface javax.sql.CommonDataSource
java.sql.SQLException
public int getLoginTimeout() throws java.sql.SQLException
getLoginTimeout
in interface javax.sql.CommonDataSource
java.sql.SQLException
public void setLoginTimeout(int seconds) throws java.sql.SQLException
setLoginTimeout
in interface javax.sql.CommonDataSource
java.sql.SQLException
public long getTimeout()
Get staled connection threshold
The default value is 600000ms (10 mins.)public void setTimeout(long miliseconds) throws java.lang.IllegalArgumentException
Set staled connection threshold
miliseconds
- The maximum amount of time in miliseconds that a JDCConnection
can be opened and not used before considering it staled.java.lang.IllegalArgumentException
- If miliseconds<1000public long getReaperDaemonDelay()
public void setReaperDaemonDelay(long lDelayMs) throws java.lang.IllegalArgumentException
lDelayMs
- long Milisecondsjava.lang.IllegalArgumentException
- if lDelayMs is less than 1000public void closeConnections()
public int closeStaledConnections()
public JDCConnection[] getAllConnections()
public javax.sql.DataSource getDatabaseBinding()
public JDCConnection getConnection(java.lang.String sCaller) throws java.sql.SQLException
sCaller
- This is just an information parameter used for open/closed
mismatch tracking and other benchmarking and statistical purposes.java.sql.SQLException
- If getMaxPoolSize() opened connections is reached an
SQLException with SQLState="08004" will be raised upon calling getConnection().public javax.sql.PooledConnection getPooledConnection() throws java.sql.SQLException
getPooledConnection
in interface javax.sql.ConnectionPoolDataSource
java.sql.SQLException
- If getMaxPoolSize() opened connections is reached an
SQLException with SQLState="08004" will be raised upon calling getConnection().public javax.sql.PooledConnection getPooledConnection(java.lang.String sUser, java.lang.String sPasswd) throws java.sql.SQLException
getPooledConnection
in interface javax.sql.ConnectionPoolDataSource
sUser
- sPasswd
- java.sql.SQLException
public java.util.logging.Logger getParentLogger()
getParentLogger
in interface javax.sql.CommonDataSource
public JDCConnection getConnectionForPId(java.lang.String sPId) throws java.sql.SQLException
sPId
- String Operating system process identifier at server sidejava.sql.SQLException
public void returnConnection(JDCConnection conn)
conn
- JDCConnection returned to the poolpublic void returnConnection(JDCConnection conn, java.lang.String sCaller)
conn
- JDCConnection returned to the poolsCaller
- Must be the same String passed as parameter at getConnection()public int size()
public JDCActivityInfo getActivityInfo() throws java.sql.SQLException
java.sql.SQLException
public java.lang.String dumpStatistics() throws java.util.ConcurrentModificationException
java.util.ConcurrentModificationException
- If pool is modified while iterating
throught connection collectionpublic boolean isReadOnly()
isReadOnly
in interface com.knowgate.storage.DataSource
public com.knowgate.storage.Table openTable(com.knowgate.storage.Record oRec) throws com.knowgate.storage.StorageException
openTable
in interface com.knowgate.storage.DataSource
com.knowgate.storage.StorageException
public com.knowgate.storage.Table openTable(java.lang.String sName) throws com.knowgate.storage.StorageException
openTable
in interface com.knowgate.storage.DataSource
com.knowgate.storage.StorageException
public com.knowgate.storage.Table openTable(java.lang.String sName, java.lang.String[] sIndexes) throws com.knowgate.storage.StorageException
openTable
in interface com.knowgate.storage.DataSource
com.knowgate.storage.StorageException
public com.knowgate.storage.SchemaMetaData getMetaData()
getMetaData
in interface com.knowgate.storage.DataSource
public java.util.Map getDBTablesMap() throws java.lang.IllegalStateException
java.lang.IllegalStateException