Package org.opennms.core.db
Class HikariCPConnectionFactory
- java.lang.Object
-
- org.opennms.core.db.BaseConnectionFactory
-
- org.opennms.core.db.HikariCPConnectionFactory
-
- All Implemented Interfaces:
Closeable
,AutoCloseable
,Wrapper
,CommonDataSource
,DataSource
,ClosableDataSource
public class HikariCPConnectionFactory extends BaseConnectionFactory
A factory for creating HikariCPConnection objects.- Author:
- Alejandro Galue
-
-
Field Summary
Fields Modifier and Type Field Description static org.slf4j.Logger
LOG
The Constant LOG.
-
Constructor Summary
Constructors Constructor Description HikariCPConnectionFactory(JdbcDataSource dataSource)
Instantiates a new HikariCP connection factory.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
close()
closeConnection
getConnection()
Connection
getConnection(String username, String password)
DataSource
getDataSource()
getDataSourceint
getLoginTimeout()
getLoginTimeoutPrintWriter
getLogWriter()
Logger
getParentLogger()
String
getUrl()
getUrlString
getUser()
getUserprotected void
initializePool(JdbcDataSource dataSource)
void
setIdleTimeout(int idleTimeout)
How long, in seconds, an idle connection is kept in the pool before it is removed.void
setLoginTimeout(int seconds)
How long, in seconds, to attempt to make a connection to the database.void
setLogWriter(PrintWriter out)
void
setMaxLifetime(int maxLifetimeMs)
Set the maximum lifetime of the connections in the pool (in milliseconds) which forces occasional connection recycling.void
setMaxPool(int maxPool)
The maximum number of pooled connections to retain.void
setMaxSize(int maxSize)
The maximum number of connections that can be created.void
setMinPool(int minPool)
The minimum number of pooled connections to retain.void
setUrl(String url)
setUrlvoid
setUser(String user)
setUser-
Methods inherited from class org.opennms.core.db.BaseConnectionFactory
isWrapperFor, unwrap, validateJdbcUrl
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface javax.sql.CommonDataSource
createShardingKeyBuilder
-
Methods inherited from interface javax.sql.DataSource
createConnectionBuilder
-
-
-
-
Constructor Detail
-
HikariCPConnectionFactory
public HikariCPConnectionFactory(JdbcDataSource dataSource) throws PropertyVetoException, SQLException
Instantiates a new HikariCP connection factory.- Parameters:
dataSource
- the data source- Throws:
PropertyVetoException
- the property veto exceptionSQLException
- the SQL exception
-
-
Method Detail
-
initializePool
protected void initializePool(JdbcDataSource dataSource) throws SQLException
- Specified by:
initializePool
in classBaseConnectionFactory
- Throws:
SQLException
-
getConnection
public Connection getConnection() throws SQLException
- Throws:
SQLException
-
getUrl
public String getUrl()
Description copied from class:BaseConnectionFactory
getUrl
- Specified by:
getUrl
in classBaseConnectionFactory
- Returns:
- a
String
object.
-
setUrl
public void setUrl(String url)
Description copied from class:BaseConnectionFactory
setUrl
- Specified by:
setUrl
in classBaseConnectionFactory
- Parameters:
url
- aString
object.
-
getUser
public String getUser()
Description copied from class:BaseConnectionFactory
getUser
- Specified by:
getUser
in classBaseConnectionFactory
- Returns:
- a
String
object.
-
setUser
public void setUser(String user)
Description copied from class:BaseConnectionFactory
setUser
- Specified by:
setUser
in classBaseConnectionFactory
- Parameters:
user
- aString
object.
-
getDataSource
public DataSource getDataSource()
Description copied from class:BaseConnectionFactory
getDataSource
- Specified by:
getDataSource
in classBaseConnectionFactory
- Returns:
- a
DataSource
object.
-
getConnection
public Connection getConnection(String username, String password) throws SQLException
- Throws:
SQLException
-
getLogWriter
public PrintWriter getLogWriter() throws SQLException
- Throws:
SQLException
-
setLogWriter
public void setLogWriter(PrintWriter out) throws SQLException
- Throws:
SQLException
-
setLoginTimeout
public void setLoginTimeout(int seconds) throws SQLException
Description copied from interface:ClosableDataSource
How long, in seconds, to attempt to make a connection to the database.- Throws:
SQLException
-
getLoginTimeout
public int getLoginTimeout() throws SQLException
Description copied from class:BaseConnectionFactory
getLoginTimeout
- Specified by:
getLoginTimeout
in interfaceCommonDataSource
- Specified by:
getLoginTimeout
in interfaceDataSource
- Specified by:
getLoginTimeout
in classBaseConnectionFactory
- Returns:
- a int.
- Throws:
SQLException
- if any.
-
getParentLogger
public Logger getParentLogger() throws SQLFeatureNotSupportedException
- Throws:
SQLFeatureNotSupportedException
-
close
public void close()
Description copied from class:BaseConnectionFactory
close
- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceClosableDataSource
- Specified by:
close
in interfaceCloseable
- Overrides:
close
in classBaseConnectionFactory
-
setIdleTimeout
public void setIdleTimeout(int idleTimeout)
Description copied from interface:ClosableDataSource
How long, in seconds, an idle connection is kept in the pool before it is removed.
-
setMaxLifetime
public void setMaxLifetime(int maxLifetimeMs)
Set the maximum lifetime of the connections in the pool (in milliseconds) which forces occasional connection recycling. This will probably only be used inside tests although it might be a good idea to do it in production as well to reset server-side query caches and metrics.- Parameters:
maxLifetimeMs
-
-
setMinPool
public void setMinPool(int minPool)
Description copied from interface:ClosableDataSource
The minimum number of pooled connections to retain.
-
setMaxPool
public void setMaxPool(int maxPool)
Description copied from interface:ClosableDataSource
The maximum number of pooled connections to retain.
-
setMaxSize
public void setMaxSize(int maxSize)
Description copied from interface:ClosableDataSource
The maximum number of connections that can be created.
-
-