Class 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 Detail

      • DefaultConnectionProvider

        public DefaultConnectionProvider()
        Creates a new DefaultConnectionProvider.
    • Method Detail

      • isPooled

        public boolean isPooled()
        Description copied from interface: ConnectionProvider
        Returns 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:
        isPooled in interface ConnectionProvider
        Returns:
        true if the Connection objects returned by this provider are pooled.
      • getConnection

        public Connection getConnection()
                                 throws SQLException
        Description copied from interface: ConnectionProvider
        Returns 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:
        getConnection in interface ConnectionProvider
        Returns:
        a Connection object.
        Throws:
        SQLException - is an SQL error occured while retrieving the connection.
      • start

        public void start()
        Description copied from interface: ConnectionProvider
        Starts 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:
        start in interface ConnectionProvider
      • restart

        public void restart()
        Description copied from interface: ConnectionProvider
        This method should be called whenever properties have been changed so that the changes will take effect.
        Specified by:
        restart in interface ConnectionProvider
      • destroy

        public void destroy()
        Description copied from interface: ConnectionProvider
        Tells 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:
        destroy in interface ConnectionProvider
      • 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 Duration 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​(Duration connectionTimeout)
        Sets the amount of time between connection recycles.
        Parameters:
        connectionTimeout - the amount of time 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 Duration getTestTimeout()
      • getTimeBetweenEvictionRunsMillis

        public Duration getTimeBetweenEvictionRunsMillis()
      • getMinIdleTime

        public Duration getMinIdleTime()
      • getActiveConnections

        public int getActiveConnections()
      • getIdleConnections

        public int getIdleConnections()
      • getConnectionsServed

        public long getConnectionsServed()
      • getRefusedCount

        public long getRefusedCount()
      • getMaxWaitTime

        public Duration getMaxWaitTime()
      • getMeanBorrowWaitTime

        public Duration getMeanBorrowWaitTime()
      • getMaxBorrowWaitTime

        public Duration 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()