info.fingo.db
Class BasePeer

java.lang.Object
  extended by info.fingo.db.BasePeer

public abstract class BasePeer
extends java.lang.Object

The base class for all peers. Encapsulates the connection and transaction management.


Field Summary
protected  javax.sql.DataSource dataSource
          The data source for this peer.
protected  org.apache.log4j.Logger logger
          The logger.
 
Constructor Summary
BasePeer(javax.sql.DataSource dataSource)
          Creates new peer working with given data source.
 
Method Summary
 void commitTransaction()
          Commits current transaction.
protected  java.sql.Connection getConnection()
          Returns the connection.
protected  void releaseConnection()
          If there is no transaction set, releases the connection.
 void rollbackTransaction()
          Rollbacks current transaction (if any).
 void setTransaction()
          Starts transaction.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

logger

protected org.apache.log4j.Logger logger
The logger.


dataSource

protected javax.sql.DataSource dataSource
The data source for this peer.

Constructor Detail

BasePeer

public BasePeer(javax.sql.DataSource dataSource)
Creates new peer working with given data source.

Parameters:
dataSource - the data source for peer to work with
Method Detail

setTransaction

public void setTransaction()
                    throws java.sql.SQLException
Starts transaction. Turns off the connection autocommit mode.

Throws:
java.sql.SQLException

rollbackTransaction

public void rollbackTransaction()
                         throws java.sql.SQLException
Rollbacks current transaction (if any). The rollbackTransaction method always releases the connection!

Throws:
java.sql.SQLException

commitTransaction

public void commitTransaction()
                       throws java.sql.SQLException
Commits current transaction. The commitTransaction method always releases the connection!

Throws:
java.sql.SQLException

getConnection

protected java.sql.Connection getConnection()
                                     throws java.sql.SQLException
Returns the connection. If there is a running transaction it will return the used object, otherwise it will obtain a new one from the ConnectionManager. The autocommit flag depends on current transactional state (negated transaction flag)

Returns:
Connection The open connection.
Throws:
java.sql.SQLException

releaseConnection

protected void releaseConnection()
If there is no transaction set, releases the connection. Eats any possible SQLException that could occur..