public static class UniqueTracker.Context extends java.lang.Object implements Finalizable, Commitable
UniqueTracker
functionality should be accessed.Modifier and Type | Field and Description |
---|---|
private ScopedList<UniqueTracker.UniqueIndex.Key> |
changes
Scoped list of uncommitted insert/update changes local to this context
|
private ScopedList<org.apache.commons.lang3.tuple.Pair<java.lang.Long,UniqueTracker.UniqueIndex.Key>> |
deletes
Scoped list of uncommitted deletes local to this context
|
private boolean |
fullTx
Whether the innermost scope represents a full (vs.
|
private boolean |
rollback
Whether to reverse apply changes/deletes for the innermost scope at end of life
|
Constructor and Description |
---|
Context() |
Modifier and Type | Method and Description |
---|---|
private void |
beginTxScope()
Begin a transaction scope (full or sub-).
|
private void |
cleanup(boolean exit)
Clean up as a block is finishing its processing.
|
void |
commit(boolean fullTx)
Callback when a full or sub-transaction block is committed.
|
void |
deleted()
No-op block callback.
|
private void |
endTxScope()
End a transaction scope (full or sub-), resulting in a commit or rollback of any changes
or deletes in the context's current, uncommitted database transaction, with respect to
the
UniqueTracker instances active for this context. |
void |
finished()
Callback when a block is finished.
|
void |
iterate()
Callback when a looping block is iterated, before business logic in the block is
executed.
|
UniqueTracker.Token |
lockAndChange(UniqueTracker tracker,
BaseRecord dmo,
java.lang.String bufferName)
Check the given record's state and update the minimal, necessary unique index(es), based
on any dirty properties in the record, or update all unique indexes in the case that
dmo has been newly created and was not previously persisted. |
UniqueTracker.Token |
lockAndDelete(UniqueTracker tracker,
BaseRecord dmo)
The given DMO has been deleted in the current transaction.
|
void |
register(TransactionManager.TransactionHelper txHelper,
int blockDepth) |
void |
retry()
Callback when a block is retried, before business logic in the block is executed.
|
void |
rollback(boolean fullTx)
Callback when a full or sub-transaction block is rolled back.
|
void |
rollbackChange(UniqueTracker tracker,
UniqueTracker.Token token)
Roll back an update operation on zero or more unique keys in this tracker, presumably
in response to a unique constraint violation either generated by this tracker or which
occurred during a database insert or update.
|
void |
unlock(UniqueTracker tracker,
UniqueTracker.Token token)
Complete the operation begun by
lockAndChange(UniqueTracker, BaseRecord, String)
or by lockAndDelete(UniqueTracker, BaseRecord) , using the token returned by the
respective method. |
void |
validate(boolean transaction,
boolean aggressiveFlush)
No-op callback.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
entry, initFailure, weight
private ScopedList<UniqueTracker.UniqueIndex.Key> changes
private ScopedList<org.apache.commons.lang3.tuple.Pair<java.lang.Long,UniqueTracker.UniqueIndex.Key>> deletes
private boolean rollback
private boolean fullTx
public void register(TransactionManager.TransactionHelper txHelper, int blockDepth)
public UniqueTracker.Token lockAndChange(UniqueTracker tracker, BaseRecord dmo, java.lang.String bufferName) throws ValidationException
dmo
has been newly created and was not previously persisted.
If the data within dmo
violates an existing unique constraint, an error is
raised. Any changes made up to that point are rolled back automatically.
tracker
- The unique tracker associated with the affected table.dmo
- Record whose state is driving an update to this tracker.bufferName
- The name of the buffer. It is used when printing the error message, if any.UniqueTracker.unlock(Token)
or to UniqueTracker.rollbackChange(Token)
in order to commit or roll back the update, respectively, and to ensure any
locks acquired by the update are released.ValidationException
- if the data in dmo
represent a unique constraint violation within any
session's uncommitted transactions.public UniqueTracker.Token lockAndDelete(UniqueTracker tracker, BaseRecord dmo)
null
for the key in the deletes
we are tracking. Rollback code must
tolerate this null
.
This operation performs no validation, as no unique constraint can be violated by a delete.
tracker
- The unique tracker associated with the affected table.dmo
- DMO which was deleted.UniqueTracker.unlock(Token)
or to UniqueTracker.rollbackChange(Token)
in order to commit or roll back the update, respectively, and to ensure any
locks acquired by the update are released.public void rollbackChange(UniqueTracker tracker, UniqueTracker.Token token)
This method should be invoked when a unique constraint violation has occurred during a record validation event.
tracker
- The unique tracker associated with the affected table.token
- A token returned by lockAndChange(UniqueTracker, BaseRecord, String)
, used
to roll back any partial or full updates made and to unlock any UniqueIndex
instances locked by the update.public void unlock(UniqueTracker tracker, UniqueTracker.Token token)
lockAndChange(UniqueTracker, BaseRecord, String)
or by lockAndDelete(UniqueTracker, BaseRecord)
, using the token returned by the
respective method. A commit is no more than the absence of a rollback and an unlocking
of any UniqueIndex
instances locked by the update or delete.
This method should be invoked when no unique constraint violation has occurred during a record validation event.
token
- A token returned by lockAndChange(UniqueTracker, BaseRecord, String)
or by
lockAndDelete(UniqueTracker, BaseRecord)
, used to unlock any UniqueIndex
instances locked by those methods.public void iterate()
iterate
in interface Finalizable
public void retry()
retry
in interface Finalizable
public void finished()
finished
in interface Finalizable
public void deleted()
deleted
in interface Finalizable
public void commit(boolean fullTx)
commit
in interface Commitable
fullTx
- true
if the block is a full transaction block; false
if it is
a sub-transaction block.public void rollback(boolean fullTx)
rollback
in interface Commitable
fullTx
- true
if the block is a full transaction block; false
if it is
a sub-transaction block.public void validate(boolean transaction, boolean aggressiveFlush)
validate
in interface Commitable
transaction
- true
if this is a full transaction and
false
if this is only a sub-transaction (a
nested scope with transaction support).aggressiveFlush
- true
if transaction manager is in aggressive subtransaction
flush mode, indicating that any transient buffers should be validated and
flushed, regardless of other state.private void beginTxScope()
private void endTxScope()
UniqueTracker
instances active for this context.
A commit simply rolls up any changes/deletes for the current sub-transaction scope to the enclosing scope, if any. A rollback reverse applies the changes/deletes for the current current (sub-)transaction scope. Either way, the current scope is popped.
private void cleanup(boolean exit)
exit
- true
if the context is exiting, not just the current block. This
represents an emergency cleanup.