mirror of
https://github.com/NationalSecurityAgency/ghidra.git
synced 2025-10-06 12:00:04 +02:00
GP-3122 Added AutoCloseable Transaction API to DBHandle and
UndoableDomainObject. Performed renaming of some internal classes.
This commit is contained in:
parent
b4de95f4f5
commit
1795c35dfc
209 changed files with 1892 additions and 2054 deletions
|
@ -21,6 +21,7 @@ import java.util.Hashtable;
|
|||
import java.util.Iterator;
|
||||
|
||||
import db.buffers.*;
|
||||
import db.util.ErrorHandler;
|
||||
import ghidra.util.Msg;
|
||||
import ghidra.util.UniversalIdGenerator;
|
||||
import ghidra.util.datastruct.WeakDataStructureFactory;
|
||||
|
@ -423,6 +424,40 @@ public class DBHandle {
|
|||
return txStarted;
|
||||
}
|
||||
|
||||
/**
|
||||
* Open new transaction. This should generally be done with a try-with-resources block:
|
||||
* <pre>
|
||||
* try (Transaction tx = dbHandle.openTransaction(dbErrorHandler)) {
|
||||
* // ... Do something
|
||||
* }
|
||||
* </pre>
|
||||
*
|
||||
* @param errorHandler handler resposible for handling an IOException which may result during
|
||||
* transaction processing. In general, a {@link RuntimeException} should be thrown by the
|
||||
* handler to ensure continued processing is properly signaled/interupted.
|
||||
* @return transaction object
|
||||
* @throws IllegalStateException if transaction is already active or this {@link DBHandle} has
|
||||
* already been closed.
|
||||
*/
|
||||
public Transaction openTransaction(ErrorHandler errorHandler)
|
||||
throws IllegalStateException {
|
||||
return new Transaction() {
|
||||
|
||||
long txId = startTransaction();
|
||||
|
||||
@Override
|
||||
protected boolean endTransaction(boolean commit) {
|
||||
try {
|
||||
return DBHandle.this.endTransaction(txId, commit);
|
||||
}
|
||||
catch (IOException e) {
|
||||
errorHandler.dbError(e);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Start a new transaction
|
||||
* @return transaction ID
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue