net.sf.spif
Class StoreAccumulator

java.lang.Object
  |
  +--net.sf.spif.StoreChain
        |
        +--net.sf.spif.StoreAccumulator

public class StoreAccumulator
extends StoreChain

A store accumulator can accumulate several puts and removes, and forget them, or send them further down the chain at some later time. Use this too create long transactions without having to make the business code using the store transaction-aware.

This class is not thread safe.

Version:
$Id: StoreAccumulator.java,v 1.2 2003/02/05 22:15:44 bratseth Exp $
Author:
Jon S Bratseth

Field Summary
 
Fields inherited from class net.sf.spif.StoreChain
chained
 
Constructor Summary
StoreAccumulator()
           
 
Method Summary
 void begin()
          Starts a transaction.
 void clear()
          Clears all puts and gets and sets this to be not in a transaction
 void commit()
          Commits all accumulated changes (puts and removes) to the downstream store chain.
 java.lang.Object get(Id id, boolean writable)
          Returns an object.
 boolean inTransaction()
          Returns whether we are in a transaction
 Id put(Id id, java.lang.Object object)
          Accumulates the put in this class until commit if a transaction has started.
 boolean remove(Id id)
          Accumulates the remove in this class until commit if a transaction has started.
 void rollback()
          Rolls back all changes if we are in a transaction.
 
Methods inherited from class net.sf.spif.StoreChain
equals, getChained, getChained, getChained, hashCode, setChained
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

StoreAccumulator

public StoreAccumulator()
Method Detail

get

public java.lang.Object get(Id id,
                            boolean writable)
Returns an object. Changes which are not yet committed are reflected in what it returned, writable or not.

Overrides:
get in class StoreChain
Parameters:
id - the id of the object to return
Returns:
the object, or null if the object could not be retrieved or if the input id was null

put

public Id put(Id id,
              java.lang.Object object)
Accumulates the put in this class until commit if a transaction has started. Passes it on if not.

Overrides:
put in class StoreChain
Parameters:
id - the id of the object to put. May be null
object - the object to put. May be null
Returns:
the id if we are not in a transaction, null if we are

remove

public boolean remove(Id id)
Accumulates the remove in this class until commit if a transaction has started. Passes it on if not.

Overrides:
remove in class StoreChain
Parameters:
id - the id of the object to remove
Returns:
true if the object did not exists

clear

public void clear()
Clears all puts and gets and sets this to be not in a transaction

Overrides:
clear in class StoreChain

rollback

public void rollback()
Rolls back all changes if we are in a transaction. Does nothing if we are not


begin

public void begin()
Starts a transaction. Does nothing if we are allready in one.


commit

public void commit()
Commits all accumulated changes (puts and removes) to the downstream store chain. Does nothing if we are not in a transaction.


inTransaction

public boolean inTransaction()
Returns whether we are in a transaction



Spif 1.01 (2003-04-03). http://spif.sf.net