class ChangeSet extends java.lang.Object implements DmoState
A BaseRecord
instance references zero or one ChangeSet
instances. An instance is only
associated with a BaseRecord
during an active, application-level transaction. During that
transaction, and any sub-transactions it contains, changes to the record are recorded in the change set.
These include both state events, such as the record being created, deleted, validated, and flushed to
the database, as well as the updates of individual DMO properties. Each change is tracked by the
transaction nesting level in which it occurred, where 0 represents the full transaction, 1 represents the
first level of nested sub-transaction, and so on.
Records which have had data or state changes are tracked by the SavepointManager
. When a rollback
event occurs, the savepoint manager rolls back the associated database savepoint, and notifies each
tracked DMO to roll back its changes to the appropriate transaction nesting level.
The implementation of this class is biased toward high performance update tracking, at the cost of some memory. Rollback processing, being the exceptional case rather than the common case, requires more work to be performed, but it should also be quite fast in most cases.
Modifier and Type | Class and Description |
---|---|
(package private) static interface |
ChangeSet.Event
Types of change events which are logged in change set for rollback processing
|
Modifier and Type | Field and Description |
---|---|
private java.lang.Object[] |
baselineData
Baseline snapshot of data before first change is made
|
private int |
baselineState
Baseline state before first change is made
|
private java.lang.Object[][] |
changes
Two dimensional array representing data changes across nested sub-transactions
|
private static int |
INCREMENT
Number of subtransaction levels to increment when growing changes array
|
private static int |
INITIAL_SIZE
Default initial number of subtransaction levels recorded by the change set
|
(package private) int |
inner
Most deeply nested (innermost) sub-transaction level at which a change is made
|
private static java.util.logging.Logger |
log
Logger
|
private java.util.BitSet[] |
marked
Bitsets corresponding with the data changes array, indicating which data elements have changed
|
(package private) int |
outer
Least deeply nested (outermost) sub-transaction level at which a change is made
|
private Session |
session
Session under which this change set was created
|
private int[] |
states
Record states corresponding with the data changes array
|
private int |
txId
Transaction ID associated with this change set
|
Constructor and Description |
---|
ChangeSet(Session session,
int txId,
java.lang.Object[] data,
int state,
int capacity)
Constructor.
|
Modifier and Type | Method and Description |
---|---|
private void |
ensureCapacity(int capacity)
Ensure that this object's internal data structures are sufficiently sized to handle the given
capacity.
|
(package private) void |
logDataChange(int txLevel,
int offset,
java.lang.Object datum)
Log a data change.
|
(package private) void |
logStateChange(int state,
int txLevel)
Log a record state change.
|
private void |
prepare(int txLevel)
Prepare for a log entry into the change set by updating the outermost and innermost transaction
nesting levels at which changes occur, and by ensuring the internal data structures have enough
capacity to record information for the given transaction nesting level.
|
(package private) void |
rollback(int txLevel,
BaseRecord dmo)
Perform a full or sub-transaction level rollback of the given record to its state as it was immediately
before the block of the specified transaction nesting level was entered.
|
(package private) boolean |
verify(Session session,
int txId)
Verify that this change set was created for the given session and transaction.
|
private static final java.util.logging.Logger log
private static final int INITIAL_SIZE
private static final int INCREMENT
private final Session session
private final int txId
private final java.lang.Object[] baselineData
private final int baselineState
private java.lang.Object[][] changes
private java.util.BitSet[] marked
private int[] states
int outer
int inner
ChangeSet(Session session, int txId, java.lang.Object[] data, int state, int capacity)
session
- Session under which this change set was created.txId
- ID for the transaction associated with this change set.data
- DMO's data at the moment of the first state or data change. A baseline snapshot of this
data is made to enable rollback later.state
- Baseline state before first change is made.capacity
- Anticipated maximum number of transaction nesting levels to record. It will be increased
dynamically later, if this capacity is exceeded.boolean verify(Session session, int txId)
session
- Database session.txId
- Transaction ID.true
if the given session and transaction ID match that of this change set, else
false
.void logStateChange(int state, int txLevel)
state
- Bitfield of states to be logged.txLevel
- Transaction nesting level at which event occurred.void logDataChange(int txLevel, int offset, java.lang.Object datum)
txLevel
- The transaction nesting level at which the change occurred.offset
- Index of the changed data element in the record's data array.datum
- The new value of the data element. The original revision of the datum will be recorded in
the baseline snapshot, and intermediate revisions may be recorded in earlier transaction
nesting levels in the change set.void rollback(int txLevel, BaseRecord dmo) throws PersistenceException
txLevel
- The nesting level of sub-transactions of the block being rolled back, where 0 represents
the full transaction block, and a positive number represents that number of nested
sub-transactions. The record will be rolled back to its state as it was immediately before
this block was entered.dmo
- Record to be rolled back.PersistenceException
private void prepare(int txLevel)
txLevel
- Current transaction nesting level.private void ensureCapacity(int capacity)
capacity
- Required maximum number of nested transaction levels to be tracked.