Class ConnectionPool
java.lang.Object
fr.paris.lutece.util.pool.service.ConnectionPool
- All Implemented Interfaces:
Wrapper,CommonDataSource,DataSource
This class manages a database connection pool.
Connections are wrapped by a
Connections are wrapped by a
LuteceConnection to avoid explicit calls to Connection.close(). Connections are released to this pool when
Connection.close() is called, and are not actually closed until release() call.- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidfreeConnection(Connection conn) Returns a connection to pool.intReturns the number of busy connections of the pool (available or busy)Returns a connection from the pool.getConnection(String username, String password) Returns the connection of the pool.intReturns the number of connections opened by the pool (available or busy)intReturns the number of free connections of the pool (available or busy)intGet loging timeout.Get the log.intReturns the maximum number of connections of the poolImplementation of JDBC 4.1's getParentLogger method (Java 7)booleanisWrapperFor(Class<?> iface) Get the wrapper.voidrelease()Releases the pool by closing all its connections.voidsetLoginTimeout(int seconds) Set Login Timeout.voidsetLogWriter(PrintWriter out) Set the log.<T> TGet the unwrap.Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface javax.sql.CommonDataSource
createShardingKeyBuilderMethods inherited from interface javax.sql.DataSource
createConnectionBuilder
-
Constructor Details
-
ConnectionPool
public ConnectionPool(String strName, String strUrl, String strUser, String strPassword, int nMaxConns, int nInitConns, int nTimeOut, org.apache.logging.log4j.Logger logger, String strCheckValidConnectionSql) Constructor.- Parameters:
strName- Nom du poolstrUrl- JDBC Data source URLstrUser- SQL UserstrPassword- SQL PasswordnMaxConns- Max connectionsnInitConns- Initials connectionsnTimeOut- Timeout to get a connectionlogger- the Logger objectstrCheckValidConnectionSql- The SQL syntax used for check connexion validatation
-
-
Method Details
-
getConnection
Returns a connection from the pool.- Specified by:
getConnectionin interfaceDataSource- Returns:
- An open connection
- Throws:
SQLException- The SQL exception
-
freeConnection
Returns a connection to pool.- Parameters:
conn- The released connection to return to pool
-
release
public void release()Releases the pool by closing all its connections. -
getConnectionCount
public int getConnectionCount()Returns the number of connections opened by the pool (available or busy)- Returns:
- A connection count
-
getFreeConnectionCount
public int getFreeConnectionCount()Returns the number of free connections of the pool (available or busy)- Returns:
- A connection count
-
getBusyConnectionCount
public int getBusyConnectionCount()Returns the number of busy connections of the pool (available or busy)- Returns:
- A connection count
-
getMaxConnectionCount
public int getMaxConnectionCount()Returns the maximum number of connections of the pool- Returns:
- A connection count
-
getConnection
Returns the connection of the pool.- Specified by:
getConnectionin interfaceDataSource- Parameters:
username- the usernamepassword- the password- Returns:
- A connection
- Throws:
SQLException- the sQL exception
-
getLogWriter
Get the log.- Specified by:
getLogWriterin interfaceCommonDataSource- Specified by:
getLogWriterin interfaceDataSource- Returns:
- A log writer
- Throws:
SQLException- the sQL exception
-
setLogWriter
Set the log.- Specified by:
setLogWriterin interfaceCommonDataSource- Specified by:
setLogWriterin interfaceDataSource- Parameters:
out- the new log writer- Throws:
SQLException- the sQL exception
-
setLoginTimeout
Set Login Timeout.- Specified by:
setLoginTimeoutin interfaceCommonDataSource- Specified by:
setLoginTimeoutin interfaceDataSource- Parameters:
seconds- the new login timeout- Throws:
SQLException- the sQL exception
-
getLoginTimeout
Get loging timeout.- Specified by:
getLoginTimeoutin interfaceCommonDataSource- Specified by:
getLoginTimeoutin interfaceDataSource- Returns:
- A time out
- Throws:
SQLException- the sQL exception
-
unwrap
Get the unwrap.- Specified by:
unwrapin interfaceWrapper- Type Parameters:
T- the generic type- Parameters:
iface- the iface- Returns:
- null
- Throws:
SQLException- the sQL exception
-
isWrapperFor
Get the wrapper.- Specified by:
isWrapperForin interfaceWrapper- Parameters:
iface- the iface- Returns:
- false
- Throws:
SQLException- the sQL exception
-
getParentLogger
Implementation of JDBC 4.1's getParentLogger method (Java 7)- Specified by:
getParentLoggerin interfaceCommonDataSource- Returns:
- the parent logger
-