uk.ac.ebi.intenz.webapp.utilities
Class UnitOfWork

java.lang.Object
  extended by uk.ac.ebi.intenz.webapp.utilities.UnitOfWork
All Implemented Interfaces:
EventListener, javax.servlet.http.HttpSessionBindingListener

public class UnitOfWork
extends Object
implements javax.servlet.http.HttpSessionBindingListener

This is a simple UnitOfWork implementation to ease database updates.

Before a requested enzyme is loaded into the session a copy of this instance is made by the register(uk.ac.ebi.intenz.webapp.dtos.EnzymeDTO) method and kept in memory. When the curator finished and pressed the 'submit' button, the enzyme instance modified by the curator will be compared to the copy created in the beginning. Usually only data that changed will then be stored (removed) in (from) the database (links are handled differently).
For data stored in a list the comparison works as follows:

  1. Data that has been removed from the list of the enzyme under development will also be removed from the copy's list.
  2. As long as data is available in the relevant list of the copy, data with the same list index will be compared, and in case of a difference the database will be updated.
  3. Finally the database will be populated with new data if the list of the enzyme under development still contains items.

Version:
$Revision: 1.6 $ $Date: 2008/04/23 14:20:13 $
Author:
Michael Darsow

Field Summary
static int UOW_ID
          This class member is used to give registered objects a unique Unit of Work ID.
 
Constructor Summary
UnitOfWork()
          Deprecated.  
UnitOfWork(EnzymeReactionMapper enzymeReactionMapper)
           
UnitOfWork(EnzymeReactionMapper enzymeReactionMapper, EnzymeEntryMapper enzymeEntryMapper)
           
 
Method Summary
 void commit(EnzymeDTO enzymeUnderDevelopment, Connection con)
          Compares the given enzyme entry to the copy stored in register(uk.ac.ebi.intenz.webapp.dtos.EnzymeDTO).
protected  void finalize()
           
 EnzymeName getEnzymeNameObject(EnzymeNameDTO enzymeNameDTO)
          Creates a EnzymeName object using a EnzymeNameDTO object stored in the enzyme DTO.
 void register(EnzymeDTO enzymeUnderDevelopment)
          Creates and stores a copy of the given EnzymeDTO instance.
 void valueBound(javax.servlet.http.HttpSessionBindingEvent arg0)
           
 void valueUnbound(javax.servlet.http.HttpSessionBindingEvent arg0)
           
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

UOW_ID

public static int UOW_ID
This class member is used to give registered objects a unique Unit of Work ID. Both, the original object and the copy will share this ID. This allows to retreive the correct copy in the commit(uk.ac.ebi.intenz.webapp.dtos.EnzymeDTO, java.sql.Connection) phase.

Constructor Detail

UnitOfWork

public UnitOfWork()
Deprecated. 

Initialises enzymesUnderDevelopment.


UnitOfWork

public UnitOfWork(EnzymeReactionMapper enzymeReactionMapper)

UnitOfWork

public UnitOfWork(EnzymeReactionMapper enzymeReactionMapper,
                  EnzymeEntryMapper enzymeEntryMapper)
Method Detail

finalize

protected void finalize()
                 throws Throwable
Overrides:
finalize in class Object
Throws:
Throwable

register

public void register(EnzymeDTO enzymeUnderDevelopment)
Creates and stores a copy of the given EnzymeDTO instance.

Parameters:
enzymeUnderDevelopment - The current enzyme entry instance.

commit

public void commit(EnzymeDTO enzymeUnderDevelopment,
                   Connection con)
            throws EcException,
                   SQLException,
                   DomainException,
                   NumberFormatException,
                   CommitException
Compares the given enzyme entry to the copy stored in register(uk.ac.ebi.intenz.webapp.dtos.EnzymeDTO).

Changes will be transferred to the database.

Data which is stored in lists will simply be reloaded at the moment.

If a new enzyme has been submitted this method will insert the entry into the database.

Parameters:
enzymeUnderDevelopment - The enzyme the curator has worked on.
con - A database connection used to perform the changes in the database.
Throws:
EcException - if an invalid EC number has been used.
SQLException - if a database error occurs.
DomainException - if a domain error occurs.
CommitException - if there is some data integrity threat
NumberFormatException
DeregisterException - if an object does not exist in enzymesUnderDevelopment (list of registered objects).

getEnzymeNameObject

public EnzymeName getEnzymeNameObject(EnzymeNameDTO enzymeNameDTO)
Creates a EnzymeName object using a EnzymeNameDTO object stored in the enzyme DTO.

Parameters:
enzymeNameDTO - The EnzymeNameDTO used to create a EnzymeName object.
Returns:
an instance of EnzymeName.

valueBound

public void valueBound(javax.servlet.http.HttpSessionBindingEvent arg0)
Specified by:
valueBound in interface javax.servlet.http.HttpSessionBindingListener

valueUnbound

public void valueUnbound(javax.servlet.http.HttpSessionBindingEvent arg0)
Specified by:
valueUnbound in interface javax.servlet.http.HttpSessionBindingListener


Copyright © 2013 EMBL-EBI. All Rights Reserved.