Class ConnectionPoolManager
java.lang.Object
net.simplace.core.database.ConnectionPoolManager
Simple implementation of a JDBC connection pool manager (singleton). Pools are registered by name; each pool
belongs to a system id (e.g.
memorytable for in-memory databases) and is released with it.-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic voidcreateH2TempPool(String aPoolName, int aPoolSize) Creates a pool for an in-memory H2 database in HSQLDB mode (systemmemorytable).static voidcreateHSQLTempPool(String aPoolName, int aPoolSize) Creates a pool for an in-memory HSQL database (systemmemorytable).static voidcreatePermanentPool(String aPoolName) Creates a pool for a file based HSQL database in the cache directory (systemrealtable) with 5 connections.voidcreatePool(String aPoolName, String aJDBCDriver, String aJDBCURL, String aSystemID, String aUser, String aPassword, int aMaxConnections) Creates a pool, unless a pool with this name exists; the JDBC driver is loaded and registered once.static voidcreateTempPool(String aPoolName) Creates an in-memory HSQL pool with 5 connections, seecreateHSQLTempPool(String, int).voidfreeConnection(String aName, Connection aConnection) Returns a connection to its pool (a warning is logged for unknown pools).voidfreeConnection(Connection aConnection) Returns a connection to the pool it belongs to.getConnection(String aName) Takes a free connection from a pool or opens a new one if the maximum is not reached.getConnection(String aName, long aTime) Takes a connection from a pool, waiting up to the given time if none is available.static ConnectionPoolManagerbooleanvoidCloses all connections of a pool and removes it.voidCloses all connections of all pools (the pools stay registered) and deregisters the JDBC drivers.voidreleaseAll(String aSystemID) Releases and removes all pools of a system.voidrenewPool(String aPoolName, String aJDBCDriver, String aJDBCURL, String aSystemID, String aUser, String aPassword, int aMaxConnections) Replaces a pool by a new one with the given settings; the free connections of the replaced pool are closed (without shutting down the database).
-
Constructor Details
-
ConnectionPoolManager
public ConnectionPoolManager()
-
-
Method Details
-
getInstance
- Returns:
- the singleton connection pool manager (created on first call)
-
freeConnection
Returns a connection to its pool (a warning is logged for unknown pools).- Parameters:
aName- name of the poolaConnection- the connection
-
freeConnection
Returns a connection to the pool it belongs to.- Parameters:
aConnection- the connection, may benull
-
getConnection
Takes a free connection from a pool or opens a new one if the maximum is not reached.- Parameters:
aName- name of the pool- Returns:
- the connection, or
nullif the pool is unknown or exhausted - Throws:
SQLException- if a new connection cannot be opened
-
getConnection
Takes a connection from a pool, waiting up to the given time if none is available.- Parameters:
aName- name of the poolaTime- maximum waiting time in milliseconds- Returns:
- the connection, or
nullif the pool is unknown or no connection became available - Throws:
SQLException- if a new connection cannot be opened
-
releaseAll
public void releaseAll()Closes all connections of all pools (the pools stay registered) and deregisters the JDBC drivers. -
release
Closes all connections of a pool and removes it.- Parameters:
aPoolKey- name of the pool
-
releaseAll
Releases and removes all pools of a system.- Parameters:
aSystemID- the system id
-
createPool
public void createPool(String aPoolName, String aJDBCDriver, String aJDBCURL, String aSystemID, String aUser, String aPassword, int aMaxConnections) Creates a pool, unless a pool with this name exists; the JDBC driver is loaded and registered once. Errors are logged.- Parameters:
aPoolName- name of the poolaJDBCDriver- class name of the JDBC driveraJDBCURL- JDBC URL of the databaseaSystemID- system the pool belongs toaUser- user name, ornullto connect without credentialsaPassword- passwordaMaxConnections- maximum number of connections in use; 0 for unlimited
-
renewPool
public void renewPool(String aPoolName, String aJDBCDriver, String aJDBCURL, String aSystemID, String aUser, String aPassword, int aMaxConnections) Replaces a pool by a new one with the given settings; the free connections of the replaced pool are closed (without shutting down the database). If no pool with this name exists, pools namedaPoolName_simsession...are released and replaced. Errors are logged.- Parameters:
aPoolName- name of the poolaJDBCDriver- class name of the JDBC driveraJDBCURL- JDBC URL of the databaseaSystemID- system the pool belongs toaUser- user name, ornullto connect without credentialsaPassword- passwordaMaxConnections- maximum number of connections in use; 0 for unlimited
-
createTempPool
Creates an in-memory HSQL pool with 5 connections, seecreateHSQLTempPool(String, int).- Parameters:
aPoolName- name of the pool and the database
-
createH2TempPool
Creates a pool for an in-memory H2 database in HSQLDB mode (systemmemorytable).- Parameters:
aPoolName- name of the pool and the databaseaPoolSize- maximum number of connections
-
createHSQLTempPool
Creates a pool for an in-memory HSQL database (systemmemorytable).- Parameters:
aPoolName- name of the pool and the databaseaPoolSize- maximum number of connections
-
createPermanentPool
Creates a pool for a file based HSQL database in the cache directory (systemrealtable) with 5 connections.- Parameters:
aPoolName- name of the pool and the database file
-
hasPool
- Parameters:
aName- name of the pool- Returns:
trueif a pool with this name or a poolaName_simsession...exists
-