Prev Class | Next Class | Frames | No Frames |
Summary: Nested | Field | Method | Constr | Detail: Nested | Field | Method | Constr |
java.lang.Object
ca.odell.glazedlists.AbstractEventList<E>
ca.odell.glazedlists.TransformedList<S,E>
ca.odell.glazedlists.TransactionList<E>
public class TransactionList<E>
extends TransformedList<S,E>
EventList source = ... TransactionList txList = new TransactionList(source); // begin a transaction in which all ListEvents are collected by txList // into a single "super ListEvent", which is fired on commit txList.beginEvent(true); // fill in the details of the transaction // (these operations actually physically change ONLY txList and its source) txList.add("A new element"); txList.set(0, "A changed element"); txList.remove(6); // commit the transaction, which will broadcast a single ListEvent from // txList describing the aggregate of all changes made during the transaction // (this returns the entire list pipeline to a consistent state) txList.commitEvent();In this usage, all ListEventListeners "downstream" of TransactionList remain clueless about changes made during a transaction. As a result, the "list pipeline" is allowed to temporarily fall into an inconsistent state because only a portion of the pipeline (TransactionList and lower) has seen changes made during the transaction. Users must ensure that they do not read or write through any "downstream" EventList that depends on the TransactionList during a transaction. Typically this is done using the built-in
locks
.
If the transaction was rolled back instead of committed, the txList would
not produce a ListEvent, since none of its listeners would be aware of any
changes made during the transaction.
The second popular usage resembles this:
EventList source = ... TransactionList txList = new TransactionList(source); // begin a transaction in which we change the ListEvent txList.beginEvent(); // this is the same as txList.beginEvent(false); // fill in the details of the transaction // (these operations actually physically change the ENTIRE PIPELINE) txList.add("A new element"); txList.set(0, "A changed element"); txList.remove(6); // commit the transaction, which will NOT broadcast a ListEvent from // txList because all of its listeners are already aware of the changes // made during the transaction txList.commitEvent();In this case, the "list pipeline" always remains consistent and reads/writes may occur through any part EventList in the pipeline without error. If the transaction is rolled back instead of committed, the txList produces a ListEvent describing the rollback, since its listeners are fully aware of the changes made during the transaction and must also be given a chance to undo their changes. Transactions may be nested arbitrarily deep using code that resembles:
txList.beginEvent(); txList.add("A"); txList.beginEvent(); txList.set(0, "B"); txList.commitEvent(); txList.beginEvent(); txList.add("C"); txList.commitEvent(); txList.commitEvent();
Field Summary |
Fields inherited from class ca.odell.glazedlists.TransformedList<S,E> | |
source |
Fields inherited from class ca.odell.glazedlists.AbstractEventList<E> | |
publisher , readWriteLock , updates |
Constructor Summary | |
|
Method Summary | |
void |
|
void |
|
void |
|
void |
|
protected boolean | |
void |
|
void |
|
Methods inherited from class ca.odell.glazedlists.TransformedList<S,E> | |
add , addAll , clear , dispose , get , getSourceIndex , isWritable , listChanged , remove , removeAll , retainAll , set , size |
Methods inherited from class ca.odell.glazedlists.AbstractEventList<E> | |
T[] toArray , add , add , addAll , addAll , addListEventListener , clear , contains , containsAll , equals , get , getPublisher , getReadWriteLock , hashCode , indexOf , isEmpty , iterator , lastIndexOf , listIterator , listIterator , remove , remove , removeAll , removeListEventListener , retainAll , set , size , subList , toArray , toString |
public TransactionList(EventListsource)
Constructs aTransactionList
that provides traditional transaction semantics over the givensource
.
- Parameters:
source
- the EventList over which to provide a transactional view
public void beginEvent()
Demarks the beginning of a transaction which accumulates all ListEvents received during the transaction and fires a single aggregate ListEvent oncommitEvent()
.
public void beginEvent(boolean buffered)
Demarks the beginning of a transaction. Ifbuffered
is true then all ListEvents received during the transaction are accumulated and fired as a single aggregate ListEvent oncommitEvent()
. Ifbuffered
is false then all ListEvents received during the transaction are forwarded immediately andcommitEvent()
produces no ListEvent of its own.
- Parameters:
buffered
- true indicates ListEvents should be buffered and sent oncommitEvent()
; false indicates they should be sent on immediately
public void commitEvent()
Demarks the successful completion of a transaction. If changes were buffered during the transaction by callingbeginEvent(true)
then a single ListEvent will be fired from this TransactionList describing the changes accumulated during the transaction.
public void dispose()
- Specified by:
- dispose in interface EventList<E>
- Overrides:
- dispose in interface TransformedList<S,E>
public void listChanged(ListEventlistChanges)
Simply forwards all of thelistChanges
since TransactionList doesn't transform the source data in any way.
- Specified by:
- listChanged in interface ListEventListener<E>
public void rollbackEvent()
Demarks the unsuccessful completion of a transaction. If changes were NOT buffered during the transaction by callingbeginEvent(false)
then a single ListEvent will be fired from this TransactionList describing the rollback of the changes accumulated during the transaction.