Package org.jivesoftware.database
Class DefaultConnectionProvider
java.lang.Object
org.jivesoftware.database.DefaultConnectionProvider
- All Implemented Interfaces:
ConnectionProvider
Default Jive connection provider, which uses an internal connection pool.
- Author:
- Jive Software
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoiddestroy()Tells the connection provider to destroy itself.intReturns a database connection.longReturns the amount of time between connection recycles in days.Returns the JDBC driver classname used to make database connections.intintReturns the maximum number of connections that the pool will use.intReturns the minimum number of connections that the pool will use.Returns the password used to connect to the database.longReturns the JDBC connection URL used to make database connections.Returns whether returned connections will be tested after being returned to the pool.Returns whether returned connections will be tested before being handed over to be used.Returns the SQL statement used to test if a connection is valid.Returns the username used to connect to the database.booleanbooleanisPooled()Returns true if this connection provider provides connections out of a connection pool.voidrestart()This method should be called whenever properties have been changed so that the changes will take effect.voidsetConnectionTimeout(Duration connectionTimeout) Sets the amount of time between connection recycles.voidSets the JDBC driver classname used to make database connections.voidsetMaxConnections(int maxConnections) Sets the maximum number of connections that the pool will use.voidsetMinConnections(int minConnections) Sets the minimum number of connections that the pool will use.voidsetPassword(String password) Sets the password used to connect to the database.voidsetServerURL(String serverURL) Sets the JDBC connection URL used to make database connections.voidsetTestAfterUse(Boolean testAfterUse) Sets whether connections will be tested after being returned to the pool.voidsetTestBeforeUse(Boolean testBeforeUse) Sets whether connections will be tested before being handed over to be used.voidsetTestSQL(String testSQL) Sets the SQL statement used to test if a connection is valid.voidsetUsername(String username) Sets the username used to connect to the database.voidstart()Starts the connection provider.
-
Constructor Details
-
DefaultConnectionProvider
public DefaultConnectionProvider()Creates a new DefaultConnectionProvider.
-
-
Method Details
-
isPooled
public boolean isPooled()Description copied from interface:ConnectionProviderReturns true if this connection provider provides connections out of a connection pool. Implementing and using connection providers that are pooled is strongly recommended, as they greatly increase the speed of Jive.- Specified by:
isPooledin interfaceConnectionProvider- Returns:
- true if the Connection objects returned by this provider are pooled.
-
getConnection
Description copied from interface:ConnectionProviderReturns a database connection. When a Jive component is done with a connection, it will call the close method of that connection. Therefore, connection pools with special release methods are not directly supported by the connection provider infrastructure. Instead, connections from those pools should be wrapped such that calling the close method on the wrapper class will release the connection from the pool.- Specified by:
getConnectionin interfaceConnectionProvider- Returns:
- a Connection object.
- Throws:
SQLException- is an SQL error occurred while retrieving the connection.
-
start
public void start()Description copied from interface:ConnectionProviderStarts the connection provider. For some connection providers, this will be a no-op. However, connection provider users should always call this method to make sure the connection provider is started.- Specified by:
startin interfaceConnectionProvider
-
restart
public void restart()Description copied from interface:ConnectionProviderThis method should be called whenever properties have been changed so that the changes will take effect.- Specified by:
restartin interfaceConnectionProvider
-
destroy
public void destroy()Description copied from interface:ConnectionProviderTells the connection provider to destroy itself. For many connection providers, this will essentially result in a no-op. However, connection provider users should always call this method when changing from one connection provider to another to ensure that there are no dangling database connections.- Specified by:
destroyin interfaceConnectionProvider
-
getDriver
Returns the JDBC driver classname used to make database connections. For example: com.mysql.jdbc.Driver- Returns:
- the JDBC driver classname.
-
setDriver
Sets the JDBC driver classname used to make database connections. For example: com.mysql.jdbc.Driver- Parameters:
driver- the fully qualified JDBC driver name.
-
getServerURL
Returns the JDBC connection URL used to make database connections.- Returns:
- the JDBC connection URL.
-
setServerURL
Sets the JDBC connection URL used to make database connections.- Parameters:
serverURL- the JDBC connection URL.
-
getUsername
Returns the username used to connect to the database. In some cases, a username is not needed so this method will return null.- Returns:
- the username used to connect to the database.
-
setUsername
Sets the username used to connect to the database. In some cases, a username is not needed so null should be passed in.- Parameters:
username- the username used to connect to the database.
-
getPassword
Returns the password used to connect to the database. In some cases, a password is not needed so this method will return null.- Returns:
- the password used to connect to the database.
-
setPassword
Sets the password used to connect to the database. In some cases, a password is not needed so null should be passed in.- Parameters:
password- the password used to connect to the database.
-
getMinConnections
public int getMinConnections()Returns the minimum number of connections that the pool will use. This should probably be at least three.- Returns:
- the minimum number of connections in the pool.
-
setMinConnections
public void setMinConnections(int minConnections) Sets the minimum number of connections that the pool will use. This should probably be at least three.- Parameters:
minConnections- the minimum number of connections in the pool.
-
getMaxConnections
public int getMaxConnections()Returns the maximum number of connections that the pool will use. The actual number of connections in the pool will vary between this value and the minimum based on the current load.- Returns:
- the max possible number of connections in the pool.
-
setMaxConnections
public void setMaxConnections(int maxConnections) Sets the maximum number of connections that the pool will use. The actual number of connections in the pool will vary between this value and the minimum based on the current load.- Parameters:
maxConnections- the max possible number of connections in the pool.
-
getConnectionTimeout
Returns the amount of time between connection recycles in days. For example, a value of .5 would correspond to recycling the connections in the pool once every half day.- Returns:
- the amount of time in days between connection recycles.
-
setConnectionTimeout
Sets the amount of time between connection recycles.- Parameters:
connectionTimeout- the amount of time between connection recycles.
-
getTestSQL
Returns the SQL statement used to test if a connection is valid.- Returns:
- the SQL statement that will be run to test a connection.
-
getTestTimeout
-
getTimeBetweenEvictionRunsMillis
-
getMinIdleTime
-
getActiveConnections
public int getActiveConnections() -
getIdleConnections
public int getIdleConnections() -
getConnectionsServed
public long getConnectionsServed() -
getRefusedCount
public long getRefusedCount() -
getMaxWaitTime
-
getMeanBorrowWaitTime
-
getMaxBorrowWaitTime
-
setTestSQL
Sets the SQL statement used to test if a connection is valid. House keeping and before/after connection tests make use of this. This should be something that causes the minimal amount of work by the database server and is as quick as possible.- Parameters:
testSQL- the SQL statement that will be run to test a connection.
-
getTestBeforeUse
Returns whether returned connections will be tested before being handed over to be used.- Returns:
- True if connections are tested before use.
-
setTestBeforeUse
Sets whether connections will be tested before being handed over to be used.- Parameters:
testBeforeUse- True or false if connections are to be tested before use.
-
getTestAfterUse
Returns whether returned connections will be tested after being returned to the pool.- Returns:
- True if connections are tested after use.
-
setTestAfterUse
Sets whether connections will be tested after being returned to the pool.- Parameters:
testAfterUse- True or false if connections are to be tested after use.
-
isMysqlUseUnicode
public boolean isMysqlUseUnicode()
-