i-net JDBC drivers for MS SQL Server

com.inet.pool
Class PoolManager

java.lang.Object
  extended by com.inet.pool.PoolManager

public class PoolManager
extends java.lang.Object

This class is the pool manager i-net PLEXA(tm). You can use it with all ConnectionPoolDataSource and standard DataSource realizations from all vendors. If you use it with a standard datasource it will return a real connection. If you use a ConnectionPoolDataSource it will return a connection that was handled from a PooledConnection. You can find an example on how to employ the pool manager in the file sample/WithPoolManager.java.


Constructor Summary
PoolManager()
          Create a new PoolManager.
 
Method Summary
static void addFailoverListener(FailoverListener listener, java.sql.Connection con)
          Use this method to register a FailoverListener for the specified Connection.
 void closeAll()
          Close all real connections to the databases.
 void closeConnection(java.sql.Connection con)
          Close and remove a connection from the pool.
 void dispose()
          Close all Connections and free all resources of the PoolManager.
 void executeFailover(javax.sql.ConnectionPoolDataSource ds, FailoverRunnable run)
          Execute a FailoverRunnable.
 java.sql.Connection getConnection(javax.sql.ConnectionPoolDataSource ds)
          This function returns a JDBC Connection from a pool.
 java.sql.Connection getConnection(javax.sql.DataSource ds)
          This function returns a JDBC Connection.
 java.sql.Connection getConnection(java.lang.String dsn)
          This function returns a JDBC Connection.
 java.sql.Connection getConnection(javax.sql.XADataSource ds)
          This function returns a JDBC Connection that comes from a pool.
 int getConnectionCount()
          Get the total count of Connections for all DataSources.
 int getConnectionCount(java.lang.Object ds)
          Get the total count of Connections for one DataSource.
static PoolManager getDefault()
          Common method of getting the default PoolManager.
 int getFailoverCount()
          Returns the current failover count.
 FailoverListener[] getFailoverListener(java.sql.Connection con)
          Returns the registered FailoverListeners.
 int getFailoverTimeout()
          Returns the current failover timeout.
 int getFreeConnectionCount()
          Get the count of free Connections for all DataSources.
 int getFreeConnectionCount(java.lang.Object ds)
          Get the count of free Connections for one DataSource.
 int getInactiveTimeout()
          Returns the timeout of an unused connection in the pool before the connection was closed.
 int getInitialPoolSize()
          Get the number of physical connections a pool should contain when it is created
 int getLoginTimeout()
          Set the maximum time in seconds that the PoolManager can wait when the maximum number of connections for a DataSource is in use.
 int getMaxConnectionCount()
          Deprecated. replace with getMaxPoolSize
 int getMaxIdleTime()
          Get the number of seconds that a physical connection should remain unused in the pool before the connection is closed. 0 (zero) indicates no limit.
 int getMaxPoolSize()
          Get the maximum number of physical connections that a pool should contain. 0 (zero) indicates no maximum size.
 int getPoolTimeout()
          Deprecated. replace with getMaxIdleTime
 int getUsedConnectionCount()
          Get the count of used Connections for all DataSources.
 int getUsedConnectionCount(java.lang.Object ds)
          Get the count of used Connections for one DataSource.
 void removeAllFailoverListener(java.sql.Connection con)
          Removes all FailoverListener from that Connection.
static void removeFailoverListener(FailoverListener listener, java.sql.Connection con)
          Use this method to remove a registered FailoverListener for the specified Connection.
 void setFailoverCount(int count)
          Sets the count of how many times the driver will to try to run a FailoverRunnable.
 void setFailoverTimeout(int timeout)
          Sets the maximum time in seconds the driver can wait to reconnect to the Server after a connection break.
 void setInactiveTimeout(int inactiveTimeout)
          Sets the timeout that a connection can be inactive before the PoolManager close it.
 void setInitialPoolSize(int initialPoolSize)
          Set the number of physical connections a pool should contain when a new pool is created.
 void setLoginTimeout(int timeout)
          Set the maximum time in seconds that the PoolManager can wait when the maximum number of connections for a DataSource is in use.
 void setMaxConnectionCount(int max)
          Deprecated. replace with setMaxPoolSize
 void setMaxIdleTime(int maxIdleTime)
          Set the number of seconds that a physical connection should remain unused in the pool before the connection is closed. 0 (zero) indicates no limit.
 void setMaxPoolSize(int maxPoolSize)
          Set the maximum number of physical connections that a pool should contain. 0 (zero) indicates no maximum size.
 void setPoolTimeout(int poolTimeout)
          Deprecated. replace with setMaxIdleTime
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PoolManager

public PoolManager()
Create a new PoolManager. This can you use if you want use more as one PoolManager.

See Also:
getDefault()
Method Detail

getConnection

public java.sql.Connection getConnection(java.lang.String dsn)
                                  throws java.sql.SQLException
This function returns a JDBC Connection. If the DataSource is a ConnectionPoolDataSource then the connection comes from a pool. The PoolManager searches in the Local LDAP Directory. If the pool has the max pool size exceeded and there is no free connection available and the login timeout is expired then a login timeout exception occurs.

Parameters:
dsn - The Data Soure Name that describes the connection in the directory.
Returns:
a pooled JDBC Connection
Throws:
java.sql.SQLException

getConnection

public java.sql.Connection getConnection(javax.sql.XADataSource ds)
                                  throws java.sql.SQLException
This function returns a JDBC Connection that comes from a pool. You need to call connection.close() after using the connection to make the connection free. If the pool has the max pool size exceeded and there is no free connection available and the login timeout is expired then a login timeout exception occurs.

Parameters:
ds - The datasoure that describes the connection.
Returns:
a pooled JDBC Connection
Throws:
java.sql.SQLException

getConnection

public java.sql.Connection getConnection(javax.sql.ConnectionPoolDataSource ds)
                                  throws java.sql.SQLException
This function returns a JDBC Connection from a pool.
You need to call connection.close() after using the connection to make the connection free. If the pool has the max pool size exceeded and there is no free connection available and the login timeout is expired then a login timeout exception occurs.

Parameters:
ds - The datasoure that describes the connection.
Returns:
a pooled JDBC Connection
Throws:
java.sql.SQLException

getConnection

public java.sql.Connection getConnection(javax.sql.DataSource ds)
                                  throws java.sql.SQLException
This function returns a JDBC Connection. If the DataSource is a ConnectionPoolDataSource then the connection comes from a pool. You need to call connection.close() after using the connection to make the connection free. If the pool has the max pool size exceeded and there is no free connection available and the login timeout is expired then a login timeout exception occurs.

Parameters:
ds - The datasoure that describes the connection.
Returns:
a pooled JDBC Connection
Throws:
java.sql.SQLException

closeAll

public void closeAll()
Close all real connections to the databases. This method also closes all used connections.

See Also:
getConnectionCount(Object), dispose()

dispose

public void dispose()
Close all Connections and free all resources of the PoolManager. After this call you can't use this pool manager. This call is invalid for the default PoolManager. It can take some time until the timer thread terminate in the background.

See Also:
closeAll()

closeConnection

public void closeConnection(java.sql.Connection con)
                     throws java.sql.SQLException
Close and remove a connection from the pool. This is different to Connection.close(); this method will close the physical connection.

Throws:
java.sql.SQLException

getConnectionCount

public int getConnectionCount()
Get the total count of Connections for all DataSources. This is the count of PooledConnection and equals the count of real database Connections.

Returns:
The Count of PooledConnection.
See Also:
getFreeConnectionCount(), getUsedConnectionCount(), getConnectionCount(Object)

getConnectionCount

public int getConnectionCount(java.lang.Object ds)
Get the total count of Connections for one DataSource. This is the count of PooledConnection and equals the count of real database Connections. If the DataSource is not a ConnectionPoolDataSource the result is always 0.

Parameters:
ds - a equals DataSource that describes the connection.
Returns:
The Count of PooledConnection for this DataSource.
See Also:
getUsedConnectionCount(Object), getFreeConnectionCount(Object), getConnectionCount()

getFreeConnectionCount

public int getFreeConnectionCount()
Get the count of free Connections for all DataSources. This is the count of PooledConnection and equals the count of real database Connections.

Returns:
The Count of free PooledConnection.
See Also:
getConnectionCount(), getUsedConnectionCount(), getFreeConnectionCount(Object)

getFreeConnectionCount

public int getFreeConnectionCount(java.lang.Object ds)
Get the count of free Connections for one DataSource. This is the count of PooledConnection and equals the count of real database Connections. If the DataSource is not a ConnectionPoolDataSource the result is always 0.

Parameters:
ds - a equals DataSource that describes the connection.
Returns:
The Count of unused PooledConnection for this DataSource.
See Also:
getConnectionCount(Object), getUsedConnectionCount(Object), getFreeConnectionCount()

getUsedConnectionCount

public int getUsedConnectionCount()
Get the count of used Connections for all DataSources. This is the count of PooledConnection and equals the count of real database Connections.

Returns:
The Count of used PooledConnection.
See Also:
getConnectionCount(), getFreeConnectionCount(), getUsedConnectionCount(Object)

getUsedConnectionCount

public int getUsedConnectionCount(java.lang.Object ds)
Get the count of used Connections for one DataSource. This is the count of PooledConnection and equals the count of real database Connections. If the DataSource is not a ConnectionPoolDataSource the result is always 0.

Parameters:
ds - a equals DataSource that describes the connection.
Returns:
The Count of used PooledConnection for this DataSource.
See Also:
getConnectionCount(Object), getFreeConnectionCount(Object), getUsedConnectionCount()

setPoolTimeout

public void setPoolTimeout(int poolTimeout)
Deprecated. replace with setMaxIdleTime

This property sets the minimum time in seconds the PoolManager is waiting before an unused real connection to a database is closed and removed from the pool. A value of zero means that the connection has never been closed. The default value is 10 minutes.

Parameters:
poolTimeout - timeout of the unused connection in seconds
See Also:
getPoolTimeout()

getPoolTimeout

public int getPoolTimeout()
Deprecated. replace with getMaxIdleTime

Get timeout of an unused connection in the pool before the connection was closed.

Returns:
The pool timeout in seconds.
See Also:
setPoolTimeout(int), setInactiveTimeout(int)

setMaxIdleTime

public void setMaxIdleTime(int maxIdleTime)
Set the number of seconds that a physical connection should remain unused in the pool before the connection is closed. 0 (zero) indicates no limit. This value can be overridden by the DataSource. The DataSource needs the method getProperty(String) or getMaxIdleTime.

See Also:
getMaxIdleTime()

getMaxIdleTime

public int getMaxIdleTime()
Get the number of seconds that a physical connection should remain unused in the pool before the connection is closed. 0 (zero) indicates no limit.

See Also:
setMaxIdleTime(int)

setInactiveTimeout

public void setInactiveTimeout(int inactiveTimeout)
Sets the timeout that a connection can be inactive before the PoolManager close it. The default are 10 minutes. A value of 0 means unlimited time. This timeout is used to prevent the pool from connection leaks. A connection is inactive if there are no methods call on the connection or depending objects.

Parameters:
inactiveTimeout - The inactive timeout in seconds
See Also:
getInactiveTimeout(), setPoolTimeout(int), getPoolTimeout()

getInactiveTimeout

public int getInactiveTimeout()
Returns the timeout of an unused connection in the pool before the connection was closed.

Returns:
The inactive timeout in seconds.
See Also:
setPoolTimeout(int)

setMaxConnectionCount

public void setMaxConnectionCount(int max)
Deprecated. replace with setMaxPoolSize

Set the maximum number of connections. The default value is 0. This is the pool size for one ConnectionPoolDataSource. A value of zero means unlimited connections. If PoolManager has the limit of connections and there are no free Connections for a DataSource the PoolManager is waiting. The connections are not closing if you set a value smaller than the current count of connections.

Parameters:
max - the maximum nuber of connetions
See Also:
setLoginTimeout(int), getLoginTimeout(), getMaxConnectionCount()

getMaxConnectionCount

public int getMaxConnectionCount()
Deprecated. replace with getMaxPoolSize

Get the maximum number of connections. The default value is 0.

See Also:
setLoginTimeout(int), getLoginTimeout(), setMaxConnectionCount(int)

setMaxPoolSize

public void setMaxPoolSize(int maxPoolSize)
Set the maximum number of physical connections that a pool should contain. 0 (zero) indicates no maximum size. This value can be overiden by the DataSource. The DataSource needs the method getProperty(String) or getMaxPoolSize.

See Also:
getMaxPoolSize()

getMaxPoolSize

public int getMaxPoolSize()
Get the maximum number of physical connections that a pool should contain. 0 (zero) indicates no maximum size.

See Also:
setMaxPoolSize(int)

setLoginTimeout

public void setLoginTimeout(int timeout)
Set the maximum time in seconds that the PoolManager can wait when the maximum number of connections for a DataSource is in use.

See Also:
getLoginTimeout(), setMaxConnectionCount(int), getMaxConnectionCount()

getLoginTimeout

public int getLoginTimeout()
Set the maximum time in seconds that the PoolManager can wait when the maximum number of connections for a DataSource is in use.

See Also:
setLoginTimeout(int), setMaxConnectionCount(int), getMaxConnectionCount()

getDefault

public static PoolManager getDefault()
Common method of getting the default PoolManager. This PoolManager is being used from the pooled driver. This method can be used to change the options for the pooled driver or as global PoolManager.

Returns:
The default PoolManager.

setInitialPoolSize

public void setInitialPoolSize(int initialPoolSize)
Set the number of physical connections a pool should contain when a new pool is created. This are override from DataSource.getInitialPoolSize() if the DataSource include this method.


getInitialPoolSize

public int getInitialPoolSize()
Get the number of physical connections a pool should contain when it is created


executeFailover

public void executeFailover(javax.sql.ConnectionPoolDataSource ds,
                            FailoverRunnable run)
                     throws java.sql.SQLException
Execute a FailoverRunnable. If the Connection is broken during an execution then the driver will try to reconnect to the server. This is useful with a failover cluster.

The driver tries to create/request a new Connection with the DataSource from the pool. This connection will be passed to your FailoverRunnable.

If an exception occurs that does not close the connection then this exception will be thrown to the calling process.

If an exception occurs that closes the connection then the driver will try to reconnect to the Server. The driver will try to get a new connection until the FailoverTimeout has expired. The driver will execute your FailoverRunnable for FailoverCount times. This can help in case the driver can reconnect but the db object is not available currently.

If you do not use a cluster then you can use the feature of the failover server. With the property "failover=true" and additional failover properties to describe the second server you can reconnect to a third server in a crash situation. If both servers are being replicated then this equals to a cluster.

Parameters:
ds - a DataSource to create a connection
run - include your buisniss logic
Throws:
java.sql.SQLException
See Also:
setFailoverCount(int), setFailoverTimeout(int), FailoverRunnable

setFailoverCount

public void setFailoverCount(int count)
Sets the count of how many times the driver will to try to run a FailoverRunnable. The default value is 5.

See Also:
executeFailover(javax.sql.ConnectionPoolDataSource, com.inet.pool.FailoverRunnable), FailoverRunnable, getFailoverCount()

getFailoverCount

public int getFailoverCount()
Returns the current failover count.

See Also:
executeFailover(javax.sql.ConnectionPoolDataSource, com.inet.pool.FailoverRunnable), FailoverRunnable, setFailoverCount(int)

setFailoverTimeout

public void setFailoverTimeout(int timeout)
Sets the maximum time in seconds the driver can wait to reconnect to the Server after a connection break. The total time isn't (failoverTimeout * failoverCount). The driver only checks the failoverTimeout for a valid connection once in case the server is down. The default value is 60 seconds.

Parameters:
timeout -
See Also:
getFailoverTimeout(), setFailoverCount(int)

getFailoverTimeout

public int getFailoverTimeout()
Returns the current failover timeout.

See Also:
executeFailover(javax.sql.ConnectionPoolDataSource, com.inet.pool.FailoverRunnable), FailoverRunnable, setFailoverTimeout(int)

addFailoverListener

public static void addFailoverListener(FailoverListener listener,
                                       java.sql.Connection con)
                                throws java.sql.SQLException
Use this method to register a FailoverListener for the specified Connection. By adding a FailoverListener it is possible to detect a broken Connection in background of a running application and to initiate the reconnection mechanism. The FailoverListener can get three different Events which indicates if a broken Connection was detected or if reconnecting was successfull or if reconnection failed. In depend of the return value from FailoverListener, reconnection will be initiated or reinitiated or aborted. If reconnection was successfull, all Statements, PreparedStatements and CallableStatements are also restored in that way that you can reexecute them. Set parameter for PreparesStatements and CallableStatements will be set again. The Connection must be a Connection received from inet PoolDriver. The FailoverListener decides whether the Connection tries to reconnect or not.

Parameters:
con - the Connection for that the FailoverListener have to registered.
listener - an object from class that implements the FailoverListener to handle the FailoverEvents.
Throws:
java.sql.SQLException
See Also:
removeFailoverListener(FailoverListener, Connection), FailoverListener, FailoverEvent

removeFailoverListener

public static void removeFailoverListener(FailoverListener listener,
                                          java.sql.Connection con)
                                   throws java.sql.SQLException
Use this method to remove a registered FailoverListener for the specified Connection. The Connection must be a Connection received from:
com.inet.pool.PoolDriver, com.inet.ora.PDataSource, com.inet.tds.PDataSource, com.inet.syb.PDataSource, com.inet.drda.PDataSource.
All these Connections implements the interface com.inet.pool.TAFConnection.

Parameters:
con - the Connection for that the FailoverListener
listener - an from class that implements the FailoverListener to handle the FailoverEvents.
Throws:
java.sql.SQLException
See Also:
TAFConnection.removeFailoverListener(FailoverListener), addFailoverListener(FailoverListener, Connection), FailoverListener, FailoverEvent

getFailoverListener

public FailoverListener[] getFailoverListener(java.sql.Connection con)
                                       throws java.sql.SQLException
Returns the registered FailoverListeners. If no FailoverListener is registered, the return value is null

Returns:
the registered FailoverListeners.
Throws:
java.sql.SQLException

removeAllFailoverListener

public void removeAllFailoverListener(java.sql.Connection con)
                               throws java.sql.SQLException
Removes all FailoverListener from that Connection.

Throws:
java.sql.SQLException

i-net JDBC drivers for MS SQL Server


copyright by i-net software