com.sage.orion.sdata.servlet.swtservice
Class ConnectionPool

java.lang.Object
  extended by com.sage.orion.sdata.servlet.swtservice.ConnectionPool
All Implemented Interfaces:
IConnectionPool, java.lang.Runnable

public class ConnectionPool
extends java.lang.Object
implements IConnectionPool

This class handles a pool of connections to a JDBC database.

Author:
cliwa01

Constructor Summary
ConnectionPool(ApplicationContext applicationContext)
          Constructs an instance of the ConnectionPool class for those tables that do not depend on the tenant id.
ConnectionPool(ApplicationContext applicationContext, java.lang.String tenant)
          Constructs an instance of the ConnectionPool class for those tables that do depend on the tenant id.
 
Method Summary
 void closeAllConnections()
          Close all the connections.
 void free(java.sql.Connection connection)
          free the connection provided by IConnectionPool.getConnection().
 java.sql.Connection getConnection()
          Gets a connection from the connection pool.
 JDBCDatabaseType getDatabaseType()
          Gets the Database type which is connected to the application
 void run()
          
 java.lang.String toString()
          
 int totalConnections()
          the total number of connections in the pool currently
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ConnectionPool

public ConnectionPool(ApplicationContext applicationContext)
               throws java.sql.SQLException
Constructs an instance of the ConnectionPool class for those tables that do not depend on the tenant id.

Parameters:
applicationContext - the application context.
Throws:
java.sql.SQLException - if it is thrown by the underlying system

ConnectionPool

public ConnectionPool(ApplicationContext applicationContext,
                      java.lang.String tenant)
               throws java.sql.SQLException
Constructs an instance of the ConnectionPool class for those tables that do depend on the tenant id.

Parameters:
applicationContext - the application context.
tenant - the non-null tenant id (when running in hosted) or null
Throws:
java.sql.SQLException - if it is thrown by the underlying system
Method Detail

getConnection

public java.sql.Connection getConnection()
                                  throws java.sql.SQLException
Gets a connection from the connection pool. Note: When finished using this connection, the caller MUST call free on the connection. Otherwise the connection will not be freed from the connection and there will be a resource leak.

Specified by:
getConnection in interface IConnectionPool
Returns:
a non-null Connection.
Throws:
java.sql.SQLException - if it is thrown by the underlying system

run

public void run()

Specified by:
run in interface java.lang.Runnable

free

public void free(java.sql.Connection connection)
free the connection provided by IConnectionPool.getConnection().

Specified by:
free in interface IConnectionPool
Parameters:
connection - the connection to free, as returned by getConnection

totalConnections

public int totalConnections()
the total number of connections in the pool currently

Specified by:
totalConnections in interface IConnectionPool
Returns:
the total number of connections in the pool currently

closeAllConnections

public void closeAllConnections()
Close all the connections. Use with caution: be sure no connections are in use before calling. Note that you are not required to call this when done with a ConnectionPool, since connections are guaranteed to be closed when garbage collected. But this method gives more control regarding when the connections are closed.

Specified by:
closeAllConnections in interface IConnectionPool

toString

public java.lang.String toString()

This version displays information about the Connection Pool.

Overrides:
toString in class java.lang.Object

getDatabaseType

public JDBCDatabaseType getDatabaseType()
Gets the Database type which is connected to the application

Specified by:
getDatabaseType in interface IConnectionPool
Returns:
databaseType


Copyright © 2011 Sage Software, Inc. All rights reserved.