Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## org.ensembl.util
Class ConnectionPoolDataSource

    java.lang.Object
      org.ensembl.util.ConnectionPoolDataSource

All Implemented Interfaces:
  javax.sql.DataSource

public class ConnectionPoolDataSource
extends java.lang.Object
implements javax.sql.DataSource

Connection pooling implementation of a datasource. Checks every 5 minutes for unused connections and closes them. If you want to connect to several databases on the same server then it is possible to reduce the number of connections used by pooling connections this usually reduces the load on both the client and server. See createDataSourceProxy(String defaultCatalog) and getConnection(String defaultCatalog).

Author:
  Craig Melsopp
See Also:
  `createDataSourceProxy(String)`, `getConnection(String)`

Constructor Summary
`ConnectionPoolDataSource()` Creates an unconfigured connection pool.
`ConnectionPoolDataSource(java.lang.String jdbcDriverName, java.lang.String fullConnectionString, java.lang.String user, java.lang.String password, int maxPoolSize)` Creates new instance of the connection pool.

Method Summary
`int` | `activeSize()`
`void` | `closeAllConnections()` Close the underlying database connections.
`static void` | `closeAllConnections(javax.sql.DataSource datasource)` Convenience method for closing connections on instances of this class, handles the fact that the datasource is null and prints a warning if it is not a ConnectionPoolDataSource.
`javax.sql.DataSource` | `createDataSourceProxy(java.lang.String defaultCatalog)` Creates a proxy for this pool which returns a Datasource whose getConnection() method returns a connection pointing at _defaultConnection_.
`java.sql.Connection` | `getConnection()` Gets a connection, either from the pool or a new one is created.
`java.sql.Connection` | `getConnection(java.lang.String catalog)` Returns a connection to the specified catalog from the pool or by creating a new one.
`java.sql.Connection` | `getConnection(java.lang.String arg0, java.lang.String arg1)`
`int` | `getLoginTimeout()`
`java.io.PrintWriter` | `getLogWriter()`
`int` | `getMaxPoolSize()`
`int` | `poolSize()`
`void` | `release(java.sql.Connection conn)` Returns the connection to the pool.
`void` | `setLoginTimeout(int arg0)`
`void` | `setLogWriter(java.io.PrintWriter arg0)`
`java.lang.String` | `toString()`

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

Constructor Detail

### ConnectionPoolDataSource

    public ConnectionPoolDataSource(java.lang.String jdbcDriverName,
                                    java.lang.String fullConnectionString,
                                    java.lang.String user,
                                    java.lang.String password,
                                    int maxPoolSize)
                             throws java.lang.ClassNotFoundException,
                                    java.sql.SQLException

  Creates new instance of the connection pool.

Parameters:
  `jdbcDriverName` - name of the jdbc driver
  `fullConnectionString` - connection string
  `user` - user name
  `password` - password, can be null
  `maxPoolSize` - maximum connection pool size, must be >0
Throws:
  `java.lang.ClassNotFoundException` - if the jdbc driver can be found
  `java.sql.SQLException` - if a problem occurs connecting to the database
  `java.lang.IllegalArgumentException` - if the parameters are illegal

### ConnectionPoolDataSource

    public ConnectionPoolDataSource()

  Creates an unconfigured connection pool.

Method Detail

### createDataSourceProxy

    public javax.sql.DataSource createDataSourceProxy(java.lang.String defaultCatalog)

  Creates a proxy for this pool which returns a Datasource whose getConnection() method returns a connection pointing at _defaultConnection_. Optimisation: This method is used to create multiple DataSources backed by a single pool which enables different users to access multiple databases on the same server using the same connections. Doing this usually reduces the number of database connections required for a server. Also, `createDataSource("my_db").getConnection().getCatalog().equals("my_db").`

  Parameters:
    `defaultCatalog` -
  Returns:
    catalog specific datasource backed by this pool.
  See Also:
    `getConnection()`, `getConnection(String)`

### getConnection

    public java.sql.Connection getConnection()
                                      throws java.sql.SQLException

  Gets a connection, either from the pool or a new one is created. If creating a new connection would exceed the pool size then an SQLException is thrown.

  Specified by:
    `getConnection` in interface `javax.sql.DataSource`
  Returns:
    connection from pool if one is available, otherwise a new one if the creation of the connection does not exceed the maxPoolSize.
  Throws:
    `java.sql.SQLException` - if a problem occurs connecting to db. This includes if the number of connections will be exceeded if another is created.
  See Also:
    `DataSource.getConnection()`

### getConnection

    public java.sql.Connection getConnection(java.lang.String catalog)
                                      throws java.sql.SQLException

  Returns a connection to the specified catalog from the pool or by creating a new one. If creating a new connection would exceed the pool size then an SQLException is thrown.

  Returns:
    connection to specified catalog from pool if one is available, otherwise a new one if the creation of the connection does not exceed the maxPoolSize.
  Throws:
    `java.sql.SQLException` - if a problem occurs connecting to db. This includes if the number of connections will be exceeded if another is created.
  See Also:
    `DataSource.getConnection()`, `An alternative to calling this method is to create a datasource backed by this pool.`

### release

    public void release(java.sql.Connection conn)

  Returns the connection to the pool. Does nothing if this connection was not created by this instance.

  Parameters:
    `conn` - connection to be returned to pool.

### getConnection

    public java.sql.Connection getConnection(java.lang.String arg0,
                                             java.lang.String arg1)
                                      throws java.sql.SQLException

  Specified by:
    `getConnection` in interface `javax.sql.DataSource`
  Throws:
    `NotImplementedYetException`
    `java.sql.SQLException`

### getLogWriter

    public java.io.PrintWriter getLogWriter()
                                     throws java.sql.SQLException

  Specified by:
    `getLogWriter` in interface `javax.sql.DataSource`
  Throws:
    `NotImplementedYetException`
    `java.sql.SQLException`

### getLoginTimeout

    public int getLoginTimeout()
                        throws java.sql.SQLException

  Specified by:
    `getLoginTimeout` in interface `javax.sql.DataSource`
  Throws:
    `NotImplementedYetException`
    `java.sql.SQLException`

### setLogWriter

    public void setLogWriter(java.io.PrintWriter arg0)
                      throws java.sql.SQLException

  Specified by:
    `setLogWriter` in interface `javax.sql.DataSource`
  Throws:
    `NotImplementedYetException`
    `java.sql.SQLException`

### setLoginTimeout

    public void setLoginTimeout(int arg0)
                         throws java.sql.SQLException

  Specified by:
    `setLoginTimeout` in interface `javax.sql.DataSource`
  Throws:
    `NotImplementedYetException`
    `java.sql.SQLException`

### getMaxPoolSize

    public int getMaxPoolSize()

  Returns:
    maximum pool size

### poolSize

    public int poolSize()

  Returns:
    current number of connections in the pool.

### activeSize

    public int activeSize()

  Returns:
    current number of connections that have been given out through getConnection().

### closeAllConnections

    public void closeAllConnections()
                             throws java.sql.SQLException

  Close the underlying database connections.

  Throws:
    `java.sql.SQLException`

### closeAllConnections

    public static void closeAllConnections(javax.sql.DataSource datasource)
                                    throws AdaptorException

  Convenience method for closing connections on instances of this class, handles the fact that the datasource is null and prints a warning if it is not a ConnectionPoolDataSource.

  Parameters:
    `datasource` -
  Throws:
    `java.sql.SQLException`
    `AdaptorException`

### toString

    public java.lang.String toString()

  Returns:
    string representation of this pool.

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD