Class ConnectionPool
- java.lang.Object
-
- fr.paris.lutece.util.pool.service.ConnectionPool
-
- All Implemented Interfaces:
java.sql.Wrapper,javax.sql.CommonDataSource,javax.sql.DataSource
public class ConnectionPool extends java.lang.Object implements javax.sql.DataSourceThis class manages a database connection pool.
Connections are wrapped by aLuteceConnectionto avoid explicit calls toConnection.close(). Connections are released to this pool whenConnection.close()is called, and are not actually closed untilrelease()call.- See Also:
LuteceConnection
-
-
Constructor Summary
Constructors Constructor Description ConnectionPool(java.lang.String strName, java.lang.String strUrl, java.lang.String strUser, java.lang.String strPassword, int nMaxConns, int nInitConns, int nTimeOut, org.apache.logging.log4j.Logger logger, java.lang.String strCheckValidConnectionSql)Constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidfreeConnection(java.sql.Connection conn)Returns a connection to pool.intgetBusyConnectionCount()Returns the number of busy connections of the pool (available or busy)java.sql.ConnectiongetConnection()Returns a connection from the pool.java.sql.ConnectiongetConnection(java.lang.String username, java.lang.String password)Returns the connection of the pool.intgetConnectionCount()Returns the number of connections opened by the pool (available or busy)intgetFreeConnectionCount()Returns the number of free connections of the pool (available or busy)intgetLoginTimeout()Get loging timeout.java.io.PrintWritergetLogWriter()Get the log.intgetMaxConnectionCount()Returns the maximum number of connections of the pooljava.util.logging.LoggergetParentLogger()Implementation of JDBC 4.1's getParentLogger method (Java 7)booleanisWrapperFor(java.lang.Class<?> iface)Get the wrapper.voidrelease()Releases the pool by closing all its connections.voidsetLoginTimeout(int seconds)Set Login Timeout.voidsetLogWriter(java.io.PrintWriter out)Set the log.<T> Tunwrap(java.lang.Class<T> iface)Get the unwrap.
-
-
-
Constructor Detail
-
ConnectionPool
public ConnectionPool(java.lang.String strName, java.lang.String strUrl, java.lang.String strUser, java.lang.String strPassword, int nMaxConns, int nInitConns, int nTimeOut, org.apache.logging.log4j.Logger logger, java.lang.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 Detail
-
getConnection
public java.sql.Connection getConnection() throws java.sql.SQLExceptionReturns a connection from the pool.- Specified by:
getConnectionin interfacejavax.sql.DataSource- Returns:
- An open connection
- Throws:
java.sql.SQLException- The SQL exception
-
freeConnection
public void freeConnection(java.sql.Connection conn)
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
public java.sql.Connection getConnection(java.lang.String username, java.lang.String password) throws java.sql.SQLExceptionReturns the connection of the pool.- Specified by:
getConnectionin interfacejavax.sql.DataSource- Parameters:
username- the usernamepassword- the password- Returns:
- A connection
- Throws:
java.sql.SQLException- the sQL exception
-
getLogWriter
public java.io.PrintWriter getLogWriter() throws java.sql.SQLExceptionGet the log.- Specified by:
getLogWriterin interfacejavax.sql.CommonDataSource- Specified by:
getLogWriterin interfacejavax.sql.DataSource- Returns:
- A log writer
- Throws:
java.sql.SQLException- the sQL exception
-
setLogWriter
public void setLogWriter(java.io.PrintWriter out) throws java.sql.SQLExceptionSet the log.- Specified by:
setLogWriterin interfacejavax.sql.CommonDataSource- Specified by:
setLogWriterin interfacejavax.sql.DataSource- Parameters:
out- the new log writer- Throws:
java.sql.SQLException- the sQL exception
-
setLoginTimeout
public void setLoginTimeout(int seconds) throws java.sql.SQLExceptionSet Login Timeout.- Specified by:
setLoginTimeoutin interfacejavax.sql.CommonDataSource- Specified by:
setLoginTimeoutin interfacejavax.sql.DataSource- Parameters:
seconds- the new login timeout- Throws:
java.sql.SQLException- the sQL exception
-
getLoginTimeout
public int getLoginTimeout() throws java.sql.SQLExceptionGet loging timeout.- Specified by:
getLoginTimeoutin interfacejavax.sql.CommonDataSource- Specified by:
getLoginTimeoutin interfacejavax.sql.DataSource- Returns:
- A time out
- Throws:
java.sql.SQLException- the sQL exception
-
unwrap
public <T> T unwrap(java.lang.Class<T> iface) throws java.sql.SQLExceptionGet the unwrap.- Specified by:
unwrapin interfacejava.sql.Wrapper- Type Parameters:
T- the generic type- Parameters:
iface- the iface- Returns:
- null
- Throws:
java.sql.SQLException- the sQL exception
-
isWrapperFor
public boolean isWrapperFor(java.lang.Class<?> iface) throws java.sql.SQLExceptionGet the wrapper.- Specified by:
isWrapperForin interfacejava.sql.Wrapper- Parameters:
iface- the iface- Returns:
- false
- Throws:
java.sql.SQLException- the sQL exception
-
getParentLogger
public java.util.logging.Logger getParentLogger()
Implementation of JDBC 4.1's getParentLogger method (Java 7)- Specified by:
getParentLoggerin interfacejavax.sql.CommonDataSource- Returns:
- the parent logger
-
-