Package org.jivesoftware.database
Class DefaultConnectionProvider
- java.lang.Object
-
- org.jivesoftware.database.DefaultConnectionProvider
-
- All Implemented Interfaces:
ConnectionProvider
public class DefaultConnectionProvider extends Object implements ConnectionProvider
Default Jive connection provider, which uses an internal connection pool.- Author:
- Jive Software
-
-
Constructor Summary
Constructors Constructor Description DefaultConnectionProvider()Creates a new DefaultConnectionProvider.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voiddestroy()Tells the connection provider to destroy itself.intgetActiveConnections()ConnectiongetConnection()Returns a database connection.longgetConnectionsServed()doublegetConnectionTimeout()Returns the amount of time between connection recycles in days.StringgetDriver()Returns the JDBC driver classname used to make database connections.intgetIdleConnections()longgetMaxBorrowWaitTime()intgetMaxConnections()Returns the maximum number of connections that the pool will use.longgetMaxWaitTime()longgetMeanBorrowWaitTime()intgetMinConnections()Returns the minimum number of connections that the pool will use.longgetMinIdleTime()StringgetPassword()Returns the password used to connect to the database.longgetRefusedCount()StringgetServerURL()Returns the JDBC connection URL used to make database connections.BooleangetTestAfterUse()Returns whether returned connections will be tested after being returned to the pool.BooleangetTestBeforeUse()Returns whether returned connections will be tested before being handed over to be used.StringgetTestSQL()Returns the SQL statement used to test if a connection is valid.intgetTestTimeout()longgetTimeBetweenEvictionRunsMillis()StringgetUsername()Returns the username used to connect to the database.booleanisMysqlUseUnicode()booleanisPooled()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(double connectionTimeout)Sets the amount of time between connection recycles in days.voidsetDriver(String driver)Sets 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.
-
-
-
Method Detail
-
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
public Connection getConnection() throws SQLException
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 occured 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
public String getDriver()
Returns the JDBC driver classname used to make database connections. For example: com.mysql.jdbc.Driver- Returns:
- the JDBC driver classname.
-
setDriver
public void setDriver(String driver)
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
public String getServerURL()
Returns the JDBC connection URL used to make database connections.- Returns:
- the JDBC connection URL.
-
setServerURL
public void setServerURL(String serverURL)
Sets the JDBC connection URL used to make database connections.- Parameters:
serverURL- the JDBC connection URL.
-
getUsername
public String 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 datbase.
-
setUsername
public void setUsername(String username)
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
public String 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
public void setPassword(String password)
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
public double 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
public void setConnectionTimeout(double connectionTimeout)
Sets 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.- Parameters:
connectionTimeout- the amount of time in days between connection recycles.
-
getTestSQL
public String 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
public int getTestTimeout()
-
getTimeBetweenEvictionRunsMillis
public long getTimeBetweenEvictionRunsMillis()
-
getMinIdleTime
public long getMinIdleTime()
-
getActiveConnections
public int getActiveConnections()
-
getIdleConnections
public int getIdleConnections()
-
getConnectionsServed
public long getConnectionsServed()
-
getRefusedCount
public long getRefusedCount()
-
getMaxWaitTime
public long getMaxWaitTime()
-
getMeanBorrowWaitTime
public long getMeanBorrowWaitTime()
-
getMaxBorrowWaitTime
public long getMaxBorrowWaitTime()
-
setTestSQL
public void setTestSQL(String testSQL)
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
public Boolean getTestBeforeUse()
Returns whether returned connections will be tested before being handed over to be used.- Returns:
- True if connections are tested before use.
-
setTestBeforeUse
public void setTestBeforeUse(Boolean testBeforeUse)
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
public Boolean getTestAfterUse()
Returns whether returned connections will be tested after being returned to the pool.- Returns:
- True if connections are tested after use.
-
setTestAfterUse
public void setTestAfterUse(Boolean testAfterUse)
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()
-
-