abstract class AbstractReversible extends Reversible
Reversible
. Adds storage of the buffer
associated with the reversible action, and a record identifier which is
used to retrieve the DMO to be acted upon. The identifier is used instead
of the DMO itself in order to save the memory overhead. The DMO is only
retrieved (using the identifier) when it is actually needed.Modifier and Type | Field and Description |
---|---|
private RecordBuffer |
buffer
Buffer which generated this reversible
|
private RecordIdentifier |
ident
Identifier for the database record being acted upon
|
private Persistable |
tempDMO
A DMO stored temporarily during rollback processing
|
LOG
Constructor and Description |
---|
AbstractReversible(RecordBuffer buffer,
Persistable dmo)
Constructor.
|
Modifier and Type | Method and Description |
---|---|
protected RecordBuffer |
getBuffer()
Get the record buffer which generated this reversible.
|
protected Persistable |
getDMO()
Get the underlying DMO.
|
protected java.lang.String |
getDMOName()
Get the unqualified interface name of the DMO being managed by this
reversible.
|
protected java.io.Serializable |
getId()
Get the ID of the underlying DMO.
|
protected RecordIdentifier |
getIdentifier()
Get the record identifier of the underlying DMO.
|
protected boolean |
isNullDMOAllowed()
Indicate whether a DMO passed to
setDMO(Persistable) may be
null . |
protected void |
prepareRollback(Persistable dmo)
Prepare for this reversible to be rolled back.
|
protected void |
rollback(boolean rollForward,
boolean transaction)
Roll back the database change represented by this object.
|
protected abstract void |
rollbackWorker(boolean rollForward,
boolean transaction)
Roll back the database change represented by this object.
|
protected void |
setDMO(Persistable dmo)
Set the underlying DMO for this reversible action.
|
protected boolean |
storesDMO()
Indicate whether this
Reversible implementation stores its
DMO locally, as opposed to storing an identifier and having to retrieve
the DMO from the backing database, or not making a DMO available at all. |
duplicate, getAction, isNewlyCreated, setNewlyCreated, toString
private final RecordBuffer buffer
private RecordIdentifier ident
private Persistable tempDMO
public AbstractReversible(RecordBuffer buffer, Persistable dmo)
buffer
- Record buffer which generated this reversible.dmo
- Object representing record upon which an action may be
reversed. May not be null
.protected abstract void rollbackWorker(boolean rollForward, boolean transaction) throws PersistenceException
Subclasses must implement this method in a manner appropriate to the database actions they represent.
rollForward
- If true
, this method is being invoked in order to
re-roll forward a non-undoable change, after a database-level
rollback. This indicates the modification is made within a
new transaction invoked after the database-level rollback.
If false
, this method is being invoked in order to
roll back an undoable change within the context of an
application-level, full transaction or sub-transaction
rollback.transaction
- true
if this rollback occurs at a full transaction
boundary, else false
.PersistenceException
- if an error occurs at the database or in the persistence
layer when reversing the action.protected final void rollback(boolean rollForward, boolean transaction) throws PersistenceException
This implemetation simply invokes rollbackWorker(boolean,
boolean)
and ensures the temporary DMO stored by prepareRollback(Persistable)
is nulled out afterward to enable it to
be garbage collected.
rollback
in class Reversible
rollForward
- If true
, this method is being invoked in order to
re-roll forward a non-undoable change, after a database-level
rollback. This indicates the modification is made within a
new transaction invoked after the database-level rollback.
If false
, this method is being invoked in order to
roll back an undoable change within the context of an
application-level, full transaction or sub-transaction
rollback.transaction
- true
if this rollback occurs at a full transaction
boundary, else false
.PersistenceException
- if an error occurs at the database or in the persistence
layer when reversing the action.protected boolean storesDMO()
Reversible
implementation stores its
DMO locally, as opposed to storing an identifier and having to retrieve
the DMO from the backing database, or not making a DMO available at all.storesDMO
in class Reversible
true
if the DMO is stored locally, else
false
.protected RecordIdentifier getIdentifier()
null
if none is stored.protected Persistable getDMO()
getDMO
in class Reversible
null
if no DMO is associated with this
reversible.protected void setDMO(Persistable dmo)
setDMO
in class Reversible
dmo
- The underlying DMO; may not be null
if isNullDMOAllowed()
returns false
.java.lang.NullPointerException
- if dmo
is null
and this is
disallowed.protected void prepareRollback(Persistable dmo)
null
, the getDMO()
method will be used
to retrieve the backing DMO from the database.prepareRollback
in class Reversible
dmo
- If non-null
, the caller is providing a DMO which
it thinks is the appropriate object to act upon during rollback
processing.protected java.io.Serializable getId()
getId
in class Reversible
protected java.lang.String getDMOName()
getDMOName
in class Reversible
protected RecordBuffer getBuffer()
protected boolean isNullDMOAllowed()
setDMO(Persistable)
may be
null
. This implementation returns false
; it
should be overridden if a subclass requires different behavior.false
.