public class ConnectionPool extends Object implements DataSource
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.LuteceConnection
Constructor and Description |
---|
ConnectionPool(String strName,
String strUrl,
String strUser,
String strPassword,
int nMaxConns,
int nInitConns,
int nTimeOut,
org.apache.log4j.Logger logger,
String strCheckValidConnectionSql)
Constructor.
|
Modifier and Type | Method and Description |
---|---|
void |
freeConnection(Connection conn)
Returns a connection to pool.
|
int |
getBusyConnectionCount()
Returns the number of busy connections of the pool (available or busy)
|
Connection |
getConnection()
Returns a connection from the pool.
|
Connection |
getConnection(String username,
String password)
Returns the connection of the pool.
|
int |
getConnectionCount()
Returns the number of connections opened by the pool (available or busy)
|
int |
getFreeConnectionCount()
Returns the number of free connections of the pool (available or busy)
|
int |
getLoginTimeout()
Get loging timeout.
|
PrintWriter |
getLogWriter()
Get the log.
|
int |
getMaxConnectionCount()
Returns the maximum number of connections of the pool
|
Logger |
getParentLogger()
Implementation of JDBC 4.1's getParentLogger method (Java 7)
|
boolean |
isWrapperFor(Class<?> iface)
Get the wrapper.
|
void |
release()
Releases the pool by closing all its connections.
|
void |
setLoginTimeout(int seconds)
Set Login Timeout.
|
void |
setLogWriter(PrintWriter out)
Set the log.
|
<T> T |
unwrap(Class<T> iface)
Get the unwrap.
|
public ConnectionPool(String strName, String strUrl, String strUser, String strPassword, int nMaxConns, int nInitConns, int nTimeOut, org.apache.log4j.Logger logger, String strCheckValidConnectionSql)
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 validatationpublic Connection getConnection() throws SQLException
getConnection
in interface DataSource
SQLException
- The SQL exceptionpublic void freeConnection(Connection conn)
conn
- The released connection to return to poolpublic void release()
public int getConnectionCount()
public int getFreeConnectionCount()
public int getBusyConnectionCount()
public int getMaxConnectionCount()
public Connection getConnection(String username, String password) throws SQLException
getConnection
in interface DataSource
username
- the usernamepassword
- the passwordSQLException
- the sQL exceptionpublic PrintWriter getLogWriter() throws SQLException
getLogWriter
in interface CommonDataSource
SQLException
- the sQL exceptionpublic void setLogWriter(PrintWriter out) throws SQLException
setLogWriter
in interface CommonDataSource
out
- the new log writerSQLException
- the sQL exceptionpublic void setLoginTimeout(int seconds) throws SQLException
setLoginTimeout
in interface CommonDataSource
seconds
- the new login timeoutSQLException
- the sQL exceptionpublic int getLoginTimeout() throws SQLException
getLoginTimeout
in interface CommonDataSource
SQLException
- the sQL exceptionpublic <T> T unwrap(Class<T> iface) throws SQLException
unwrap
in interface Wrapper
T
- the generic typeiface
- the ifaceSQLException
- the sQL exceptionpublic boolean isWrapperFor(Class<?> iface) throws SQLException
isWrapperFor
in interface Wrapper
iface
- the ifaceSQLException
- the sQL exceptionpublic Logger getParentLogger()
getParentLogger
in interface CommonDataSource
Copyright © 2020 City of Paris. All rights reserved.