|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objecthudson.BulkChange
public class BulkChange
Transaction-like object that can be used to make a bunch of changes to an object, and defer the
Saveable.save()
until the end.
The usage of BulkChange
needs to follow a specific closure-like pattern, namely:
BulkChange bc = new BulkChange(someObject); try { ... make changes to 'someObject' } finally { bc.commit(); }
... or if you'd like to avoid saving when something bad happens:
BulkChange bc = new BulkChange(someObject); try { ... make changes to 'someObject' bc.commit(); } finally { bc.abort(); }
Use of this method is optional. If BulkChange
is not used, individual mutator
will perform the save operation, and things will just run somewhat slower.
Saveable
For this class to work as intended, Saveable
implementations need to co-operate.
Namely,
this.save()
so that if the method is called outside
a BulkChange
, the result will be saved immediately.
save()
method implementation, use contains(Saveable)
and
only perform the actual I/O operation when this method returns false.
See Jenkins.save()
as an example if you are not sure how to implement Saveable
.
Field Summary | |
---|---|
static Saveable |
ALL
Magic Saveable instance that can make BulkChange veto
all the save operations by making the contains(Saveable) method return
true for everything. |
Exception |
allocator
|
Constructor Summary | |
---|---|
BulkChange(Saveable saveable)
|
Method Summary | |
---|---|
void |
abort()
Exits the scope of BulkChange without saving the changes. |
void |
commit()
Saves the accumulated changes. |
static boolean |
contains(Saveable s)
Checks if the given Saveable is currently in the bulk change. |
static BulkChange |
current()
Gets the BulkChange instance currently in scope for the current thread. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public final Exception allocator
public static final Saveable ALL
Saveable
instance that can make BulkChange
veto
all the save operations by making the contains(Saveable)
method return
true for everything.
Constructor Detail |
---|
public BulkChange(Saveable saveable)
Method Detail |
---|
public void commit() throws IOException
IOException
public void abort()
BulkChange
without saving the changes.
This can be used when a bulk change fails in the middle. Note that unlike a real transaction, this will not roll back the state of the object.
The abort method can be called after the commit method, in which case this method does nothing.
This is so that BulkChange
can be used naturally in the try/finally block.
public static BulkChange current()
BulkChange
instance currently in scope for the current thread.
public static boolean contains(Saveable s)
Saveable
is currently in the bulk change.
The expected usage is from the Saveable.save()
implementation to check
if the actual persistence should happen now or not.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |