org.glite.data.common.helpers
Class DBManager

java.lang.Object
  extended byorg.glite.data.common.helpers.DBManager

public class DBManager
extends java.lang.Object

Class to manage database connection for the given pool.


Field Summary
protected  javax.sql.DataSource m_dataSource
           
protected  java.lang.String m_db_pool_name
           
 
Constructor Summary
DBManager(java.lang.String pool)
          Create a manager for the given poolname.
 
Method Summary
 void cleanupResources(java.sql.Connection conn)
          Cleanup a connection and return to pool.
 void cleanupResources(java.sql.ResultSet rs)
          Cleanup ResultSet.
 void cleanupResources(java.sql.Statement st)
          Cleanup a Statement.
 void commit(java.sql.Connection conn)
          Commit a connection, throwing an exception if it fails.
 void commitRegardless(java.sql.Connection conn)
          Commit a connection, but do not throw any exceptions if the commit fails.
 boolean commitWithResult(java.sql.Connection conn)
          Commit a connection, returning true if it suceeded and false if it failed.
 java.sql.Statement createStatement(java.sql.Connection conn)
          Create a basic statement object from the connection.
 java.sql.Connection getConnection(boolean autocommit)
          Fetch a cvonnection from the pool.
 java.sql.PreparedStatement prepareStatement(java.sql.Connection conn, java.lang.String sqlQuery)
          Create a basic statement object from the connection.
 void rollback(java.sql.Connection conn)
          Rollback a connectiopn and throw an excpetion if it fails.
 void rollbackRegardless(java.sql.Connection conn)
          Rollback, but do not throw any exceptions if the rollback fails.
 boolean rollbackWithResult(java.sql.Connection conn)
          Rollback a connection, returning true on success, false on failure.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

m_db_pool_name

protected final java.lang.String m_db_pool_name

m_dataSource

protected final javax.sql.DataSource m_dataSource
Constructor Detail

DBManager

public DBManager(java.lang.String pool)
          throws DBException
Create a manager for the given poolname. Multiple managers can be active on any one pool. Just like the real thing.

Parameters:
pool -
Throws:
DBException
Method Detail

getConnection

public java.sql.Connection getConnection(boolean autocommit)
                                  throws DBException
Fetch a cvonnection from the pool.

Parameters:
autocommit - Boolean flag for autocommit
Returns:
the connection.
Throws:
DBException - if a connection cannot be fetched.

createStatement

public java.sql.Statement createStatement(java.sql.Connection conn)
                                   throws DBException
Create a basic statement object from the connection.

Parameters:
conn -
Returns:
Throws:
DBException

prepareStatement

public java.sql.PreparedStatement prepareStatement(java.sql.Connection conn,
                                                   java.lang.String sqlQuery)
                                            throws DBException
Create a basic statement object from the connection.

Parameters:
conn -
Returns:
Throws:
DBException

rollback

public void rollback(java.sql.Connection conn)
              throws DBException
Rollback a connectiopn and throw an excpetion if it fails.

Parameters:
conn -
Throws:
DBException

rollbackWithResult

public boolean rollbackWithResult(java.sql.Connection conn)
Rollback a connection, returning true on success, false on failure.

Parameters:
conn -
Returns:

rollbackRegardless

public void rollbackRegardless(java.sql.Connection conn)
Rollback, but do not throw any exceptions if the rollback fails. This method should be used sparingly in only cases where you don't care or can't actually do anything if the rollback failed...

Parameters:
conn -

commit

public void commit(java.sql.Connection conn)
            throws DBException
Commit a connection, throwing an exception if it fails.

Parameters:
conn -
Throws:
DBException

commitWithResult

public boolean commitWithResult(java.sql.Connection conn)
Commit a connection, returning true if it suceeded and false if it failed.

Parameters:
conn -
Returns:

commitRegardless

public void commitRegardless(java.sql.Connection conn)
Commit a connection, but do not throw any exceptions if the commit fails. This method should be used sparingly in only cases where you don't care or can't actually do anything if the commit failed...

Parameters:
conn -

cleanupResources

public void cleanupResources(java.sql.Connection conn)
Cleanup a connection and return to pool. You should cleanup ResultSets and Statements belonging to the Connection first.

Parameters:
conn -

cleanupResources

public void cleanupResources(java.sql.Statement st)
Cleanup a Statement. You should cleanup ResultSets belonging to the Statement first.

Parameters:
st -

cleanupResources

public void cleanupResources(java.sql.ResultSet rs)
Cleanup ResultSet.

Parameters:
rs -