Package com.kheops.jmap.db
Class DatabaseConnectionPool
java.lang.Object
com.kheops.util.KObjectPool
com.kheops.jmap.db.DatabaseConnectionPool
- All Implemented Interfaces:
KSchedulerClient
- Direct Known Subclasses:
DatabaseNamedConnectionPool
This class manages a pool of JDBC connections. A pool has an initial size but
can automatically grow if necessary. Users of a connection pool use the
method
borrowConnection
to get exclusive use of a database
connection and returnConnection
to return the connection in the
pool and thus make it available for others. Optionally, the connections can
be recycled if they are inactive for a certain period of time. This is used
with databases that automatically close connections when they are inactive.-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected String
protected DatabaseConfig
protected Vector
<DatabaseConnectionPoolListener> protected DatabaseConnectionPoolInfo
Fields inherited from class com.kheops.util.KObjectPool
cleanupPeriod, recyclePeriod, shrinkTime, TIMEOUT_UNDEFINED, TIMEOUT_UNLIMITED
-
Constructor Summary
ConstructorsConstructorDescriptionCreates a new DatabaseConnectionPool instance.Deprecated.DatabaseConnectionPool
(DatabaseConnectionPoolInfo poolInfo, DatabaseConfig databaseConfig) Deprecated.use the default constructor andinit(DatabaseConnectionPoolInfo, DatabaseConfig)
-
Method Summary
Modifier and TypeMethodDescriptionvoid
activate()
void
addListener
(DatabaseConnectionPoolListener listener) Borrows a connection from the pool for exclusive use until it is returned by calling the methodreturnConnection
.borrowConnection
(int sessionId) borrowConnection
(long timeout, TimeUnit unit) Borrows a connection from the pool for exclusive use until it is returned by calling the methodreturnConnection
.create()
Should not be called.void
void
Should not be called.Returns the database configuration associated with this connection pool.protected int
getId()
This method returns the last exception thrown.int
long
boolean
init
(DatabaseConnectionPoolInfo poolInfo, DatabaseConfig databaseConfig) Initializes the connection pool with the specified pool info.protected void
boolean
void
removeListener
(DatabaseConnectionPoolListener listener) void
reset()
This will close and reinitialize the pool.void
returnConnection
(int id, Connection c) void
Returns a connection to the poll that was obtained using the methodborrowConnection
.void
setDatabaseConfig
(DatabaseConfig databaseConfig) Sets the database configuration to be associated with this connection pool.protected void
setStatus
(int status) Sets the status of this database connection pool.boolean
Should not be called.Methods inherited from class com.kheops.util.KObjectPool
apply, checkIn, checkOut, checkOut, close, createUnlockedInstance, getDefaultTimeout, getMonitoringInfo, getPoolMaximumSize, getPoolSize, getPoolUsageCount, getPoolUsagePeak, initialize, initialize, initialize, resourceAdded, schCallback, setDefaultTimeout, setPoolMaximumSize, setPoolMinimumSize
-
Field Details
-
poolInfo
-
listeners
-
databaseConfig
-
currentSchema
-
-
Constructor Details
-
DatabaseConnectionPool
public DatabaseConnectionPool()Creates a new DatabaseConnectionPool instance.- Since:
- 6.5
- See Also:
-
DatabaseConnectionPool
Deprecated.use the default constructor andinit(DatabaseConnectionPoolInfo, DatabaseConfig)
Creates a new connection pool instance.- Parameters:
poolInfo
- the DatabaseConnectionPoolInfo instance associated with this DatabaseconnectionPool- See Also:
-
DatabaseConnectionPool
@Deprecated public DatabaseConnectionPool(DatabaseConnectionPoolInfo poolInfo, DatabaseConfig databaseConfig) Deprecated.use the default constructor andinit(DatabaseConnectionPoolInfo, DatabaseConfig)
Creates a new connection pool instance.- Parameters:
poolInfo
- the DatabaseConnectionPoolInfo instance associated with this DatabaseconnectionPooldatabaseConfig
- the database configuration to use with borrowed connections.
-
-
Method Details
-
init
Initializes the connection pool with the specified pool info.- Parameters:
poolInfo
- the DatabaseConnectionPoolInfo instance associated with this DatabaseconnectionPooldatabaseConfig
- the database configuration to use with borrowed connections.- Returns:
- true if no error occurred during the initialization.
- Since:
- 6.5
-
create
Should not be called.- Specified by:
create
in classKObjectPool
- Returns:
- a new object (Connection)
- Throws:
SQLException
-
reset
Description copied from class:KObjectPool
This will close and reinitialize the pool.- Overrides:
reset
in classKObjectPool
- Throws:
Exception
-
validate
Should not be called. Important note : The createStatement test works only with Oracle and mySQL.- Specified by:
validate
in classKObjectPool
- Parameters:
o
- object (Connection) to validate- Returns:
- true if valid
-
expire
Should not be called.- Specified by:
expire
in classKObjectPool
- Parameters:
o
- object (Connection) to close
-
borrowConnection
- Throws:
SQLException
-
borrowConnection
Borrows a connection from the pool for exclusive use until it is returned by calling the methodreturnConnection
.- Returns:
- a database connection
- Throws:
SQLException
-
borrowConnection
Borrows a connection from the pool for exclusive use until it is returned by calling the methodreturnConnection
.- Parameters:
timeout
- the maximum time to waitunit
- the time unit of the timeout argument- Returns:
- a database connection
- Throws:
SQLException
-
returnConnection
Returns a connection to the poll that was obtained using the methodborrowConnection
. This method MUST ABSOLUTELY be called when the connection not needed anymore otherwise it will stay unavailable for ever for other users.- Parameters:
c
- the corresponding connection
-
returnConnection
-
getStatus
public int getStatus()- Returns:
- the status of this database connection pool
-
setStatus
protected void setStatus(int status) Sets the status of this database connection pool. -
getId
protected int getId()- Overrides:
getId
in classKObjectPool
-
internalErrorOccurred
- Overrides:
internalErrorOccurred
in classKObjectPool
-
getLastException
This method returns the last exception thrown.- Returns:
- the last exception thrown
-
addListener
-
removeListener
-
getDatabaseConnectionPoolInfo
-
getCurrentSchema
- Throws:
SQLException
-
setDatabaseConfig
Sets the database configuration to be associated with this connection pool.- Parameters:
databaseConfig
- the database configuration to set.
-
getDatabaseConfig
Returns the database configuration associated with this connection pool. Note that the returned instance may be null.- Returns:
- the database configuration associated with this connection pool.
-
getSystemDefaultTimeout
public long getSystemDefaultTimeout()- Overrides:
getSystemDefaultTimeout
in classKObjectPool
-
isInactive
public boolean isInactive() -
activate
public void activate() -
deactivate
public void deactivate()
-
init(DatabaseConnectionPoolInfo, DatabaseConfig)