org.jaffa.persistence.engines.jdbcengine.datasource
Class PersistentTransaction

java.lang.Object
  extended byorg.jaffa.persistence.engines.jdbcengine.datasource.PersistentTransaction

public class PersistentTransaction
extends Object

This class is used to hold a connection to the database. It holds collections of objects to be added, updated, deleted or queried. The UOW will add objects to these collections. The JdbcBridge will utilise the collections to perform the relevant operations. It is important to invoke the close() method, which will free up the pooled connection.


Constructor Summary
PersistentTransaction(Database database)
          Creates a PersitentTransaction.
 
Method Summary
 void addObject(IPersistent object)
          Adds an object to the transaction to be written.
 void close()
          This will free up the underlying pooled connection.
 void commit()
          Commits all changes executed against the persistent store.
 void deleteObject(IPersistent object)
          Adds an object to the transaction to be deleted.
 Collection getAdds()
          Returns a Collection of Persistent objects to be added to the persistent store.
 DataSource getDataSource()
          Returns the DataSource holding the Connection.
 Collection getDeletes()
          Returns a Collection of Persistent objects to be deleted from the persistent store.
 Collection getQueries()
          Returns a Collection of Criteria objects to be used for querying the persistent store.
 Collection getUpdates()
          Returns a Collection of Persistent objects to be updated in the persistent store.
 void queryObject(Criteria object)
          Adds a Criteria object to the transaction for performing a query.
 void rollback()
          Rollback the changes executed against the persistent store.
 void updateObject(IPersistent object)
          Adds an object to the transaction to be updated.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PersistentTransaction

public PersistentTransaction(Database database)
                      throws DataSourceCreationException
Creates a PersitentTransaction. It uses the input Database configuration to acquire a Connection to the database.

Parameters:
database - The object with the requisite information for acquiring a Connection to the database.
Throws:
DataSourceCreationException - if the connection could not be acquired.
Method Detail

addObject

public void addObject(IPersistent object)
               throws AddFailedException,
                      IllegalPersistentStateRuntimeException
Adds an object to the transaction to be written. The PreAdd trigger for will be invoked and the domain object will be validated before the addition to the transaction.

Parameters:
object - the object to be created.
Throws:
AddFailedException - if any error occurs during the validation of the persistent object.
IllegalPersistentStateRuntimeException - this RuntimeException will be thrown if the domain object has been submitted to the UOW for an Add/Update/Delete and commit hasnt yet been performed.

updateObject

public void updateObject(IPersistent object)
                  throws UpdateFailedException,
                         IllegalPersistentStateRuntimeException
Adds an object to the transaction to be updated. The PreUpdate trigger will be invoked and the domain object will be validated before the updation to the transaction.

Parameters:
object - the object to be updated.
Throws:
UpdateFailedException - if any error occurs during the validation of the persistent object.
IllegalPersistentStateRuntimeException - this RuntimeException will be thrown if the domain object has been submitted to the UOW for an Add/Update/Delete and commit hasnt yet been performed.

deleteObject

public void deleteObject(IPersistent object)
                  throws DeleteFailedException,
                         IllegalPersistentStateRuntimeException
Adds an object to the transaction to be deleted. The PreDelete trigger will be invoked before the deletion from the transaction.

Parameters:
object - the object to be deleted.
Throws:
DeleteFailedException - if any error occurs during the process.
IllegalPersistentStateRuntimeException - this RuntimeException will be thrown if the domain object has been submitted to the UOW for an Add/Update/Delete and commit hasnt yet been performed.

queryObject

public void queryObject(Criteria object)
Adds a Criteria object to the transaction for performing a query.

Parameters:
object - the Criteria based on which a query is to be performed.

commit

public void commit()
            throws SQLException
Commits all changes executed against the persistent store.

Throws:
SQLException - if any database error occurs.

rollback

public void rollback()
              throws SQLException
Rollback the changes executed against the persistent store.

Throws:
SQLException - if any database error occurs.

close

public void close()
           throws SQLException
This will free up the underlying pooled connection. It will first do an implicit rollback().

Throws:
SQLException - if any database error occurs.

getDataSource

public DataSource getDataSource()
Returns the DataSource holding the Connection.

Returns:
the DataSource.

getAdds

public Collection getAdds()
Returns a Collection of Persistent objects to be added to the persistent store.

Returns:
a Collection of objects to be added.

getUpdates

public Collection getUpdates()
Returns a Collection of Persistent objects to be updated in the persistent store.

Returns:
a Collection of objects to be updated.

getDeletes

public Collection getDeletes()
Returns a Collection of Persistent objects to be deleted from the persistent store.

Returns:
a Collection of objects to be deleted.

getQueries

public Collection getQueries()
Returns a Collection of Criteria objects to be used for querying the persistent store.

Returns:
a Collection of Criteria objects to be used for queries.


Copyright © 2002-2004 JAFFA Project.