Package org.opencms.db
Class CmsDbPoolV11
- java.lang.Object
-
- org.opencms.db.CmsDbPoolV11
-
public final class CmsDbPoolV11 extends java.lang.Object
Database connection pool class using HikariCP.
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.String
KEY_CONNECT_ATTEMTS
Key for number of connection attempts.static java.lang.String
KEY_CONNECT_WAITS
Key for connection waiting.static java.lang.String
KEY_DATABASE
Prefix for database keys.static java.lang.String
KEY_DATABASE_NAME
Key for the database name.static java.lang.String
KEY_DATABASE_POOL
Key for the pool id.static java.lang.String
KEY_ENTITY_MANAGER_POOL_SIZE
Key for the entity manager pool size.static java.lang.String
KEY_JDBC_DRIVER
Key for jdbc driver.static java.lang.String
KEY_JDBC_URL
Key for jdbc url.static java.lang.String
KEY_JDBC_URL_PARAMS
Key for jdbc url params.static java.lang.String
KEY_PASSWORD
Key for database password.static java.lang.String
KEY_POOL_DEFAULT
Key for default.static java.lang.String
KEY_POOL_URL
Key for pool url.static java.lang.String
KEY_POOL_USER
Key for pool user.static java.lang.String
KEY_POOL_VFS
Key for vfs pool.static java.lang.String
KEY_USERNAME
Key for user name.static java.lang.String
OPENCMS_DEFAULT_POOL_NAME
The name of the opencms default pool.static java.lang.String
OPENCMS_DEFAULT_POOL_URL
The default OpenCms JDBC pool URL.static java.lang.String
OPENCMS_URL_PREFIX
The prefix used for opencms JDBC pools.
-
Constructor Summary
Constructors Constructor Description CmsDbPoolV11(CmsParameterConfiguration config, java.lang.String key)
Default constructor.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
close()
Closes the pool.static com.zaxxer.hikari.HikariConfig
createHikariConfig(CmsParameterConfiguration config, java.lang.String key)
Creates the HikariCP configuration based on the configuration of a pool defined in opencms.properties.int
getActiveConnections()
Returns the number of active connections.java.sql.Connection
getConnection()
Gets a database connection from the pool.static java.lang.String
getDefaultDbPoolName()
Returns the name of the default database connection pool.int
getIdleConnections()
Gets the number of idle connections.java.lang.String
getPoolUrl()
Gets the pool url.static java.lang.String
getPropertyRelativeSuffix(java.lang.String prefix, java.lang.String str)
If str starts with prefix + '.', return the remaining part, otherwise return null.
-
-
-
Field Detail
-
KEY_DATABASE
public static final java.lang.String KEY_DATABASE
Prefix for database keys.- See Also:
- Constant Field Values
-
KEY_DATABASE_NAME
public static final java.lang.String KEY_DATABASE_NAME
Key for the database name.- See Also:
- Constant Field Values
-
KEY_DATABASE_POOL
public static final java.lang.String KEY_DATABASE_POOL
Key for the pool id.- See Also:
- Constant Field Values
-
KEY_CONNECT_ATTEMTS
public static final java.lang.String KEY_CONNECT_ATTEMTS
Key for number of connection attempts.- See Also:
- Constant Field Values
-
KEY_CONNECT_WAITS
public static final java.lang.String KEY_CONNECT_WAITS
Key for connection waiting.- See Also:
- Constant Field Values
-
KEY_ENTITY_MANAGER_POOL_SIZE
public static final java.lang.String KEY_ENTITY_MANAGER_POOL_SIZE
Key for the entity manager pool size.- See Also:
- Constant Field Values
-
KEY_JDBC_DRIVER
public static final java.lang.String KEY_JDBC_DRIVER
Key for jdbc driver.- See Also:
- Constant Field Values
-
KEY_JDBC_URL
public static final java.lang.String KEY_JDBC_URL
Key for jdbc url.- See Also:
- Constant Field Values
-
KEY_JDBC_URL_PARAMS
public static final java.lang.String KEY_JDBC_URL_PARAMS
Key for jdbc url params.- See Also:
- Constant Field Values
-
KEY_PASSWORD
public static final java.lang.String KEY_PASSWORD
Key for database password.- See Also:
- Constant Field Values
-
KEY_POOL_DEFAULT
public static final java.lang.String KEY_POOL_DEFAULT
Key for default.- See Also:
- Constant Field Values
-
KEY_POOL_URL
public static final java.lang.String KEY_POOL_URL
Key for pool url.- See Also:
- Constant Field Values
-
KEY_POOL_USER
public static final java.lang.String KEY_POOL_USER
Key for pool user.- See Also:
- Constant Field Values
-
KEY_POOL_VFS
public static final java.lang.String KEY_POOL_VFS
Key for vfs pool.- See Also:
- Constant Field Values
-
KEY_USERNAME
public static final java.lang.String KEY_USERNAME
Key for user name.- See Also:
- Constant Field Values
-
OPENCMS_DEFAULT_POOL_NAME
public static final java.lang.String OPENCMS_DEFAULT_POOL_NAME
The name of the opencms default pool.- See Also:
- Constant Field Values
-
OPENCMS_DEFAULT_POOL_URL
public static final java.lang.String OPENCMS_DEFAULT_POOL_URL
The default OpenCms JDBC pool URL.- See Also:
- Constant Field Values
-
OPENCMS_URL_PREFIX
public static final java.lang.String OPENCMS_URL_PREFIX
The prefix used for opencms JDBC pools.- See Also:
- Constant Field Values
-
-
Constructor Detail
-
CmsDbPoolV11
public CmsDbPoolV11(CmsParameterConfiguration config, java.lang.String key) throws java.lang.Exception
Default constructor.- Parameters:
config
- the OpenCms configuration (opencms.properties)key
- the name of the pool (without the opencms: prefix)- Throws:
java.lang.Exception
- if something goes wrong
-
-
Method Detail
-
createHikariConfig
public static com.zaxxer.hikari.HikariConfig createHikariConfig(CmsParameterConfiguration config, java.lang.String key)
Creates the HikariCP configuration based on the configuration of a pool defined in opencms.properties.- Parameters:
config
- the configuration object with the propertieskey
- the pool name (without the opencms prefix)- Returns:
- the HikariCP configuration for the pool
-
getDefaultDbPoolName
public static java.lang.String getDefaultDbPoolName()
Returns the name of the default database connection pool.- Returns:
- the name of the default database connection pool
-
getPropertyRelativeSuffix
public static java.lang.String getPropertyRelativeSuffix(java.lang.String prefix, java.lang.String str)
If str starts with prefix + '.', return the remaining part, otherwise return null.- Parameters:
prefix
- the prefixstr
- the string to remove the prefix from- Returns:
- str with the prefix removed, or null if it didn't start with prefix + '.'
-
close
public void close() throws java.lang.Exception
Closes the pool.- Throws:
java.lang.Exception
- if something goes wrong
-
getActiveConnections
public int getActiveConnections()
Returns the number of active connections.- Returns:
- the number of active connections
-
getConnection
public java.sql.Connection getConnection() throws java.sql.SQLException
Gets a database connection from the pool.- Returns:
- the database connection
- Throws:
java.sql.SQLException
- if something goes wrong
-
getIdleConnections
public int getIdleConnections()
Gets the number of idle connections.- Returns:
- the number of idle connections
-
getPoolUrl
public java.lang.String getPoolUrl()
Gets the pool url.- Returns:
- the pool url
-
-