Class ProgramTransaction
- java.lang.Object
-
- ghidra.program.database.util.ProgramTransaction
-
- All Implemented Interfaces:
java.lang.AutoCloseable
public class ProgramTransaction extends java.lang.Object implements java.lang.AutoCloseable
A convenience context for transaction IDs on a Ghidra program databaseThis is meant to be used as an idiom in a try-with-resources block:
try (ProgramTransaction t = ProgramTransaction.open(program, "Demo")) { program.getMemory()..... t.commit(); }
This idiom is very useful if there is complex logic in your transaction, it's very easy to forget to close the transaction, especially if an error occurs, leaving the database in an open transaction indefinitely. The try-with-resources block will ensure that the transaction is closed in all circumstances. Note, however, that in order for the transaction to be committed, you must call
commit()
.Any exceptions within the block will cause
t.commit()
to be skipped, thus aborting the transaction.
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
close()
Finish the transactionvoid
commit()
Finish the transaction, and commitstatic ProgramTransaction
open(Program program, java.lang.String description)
Start a transaction on the given program with the given description
-
-
-
Field Detail
-
program
protected Program program
-
tid
protected int tid
-
commit
protected boolean commit
-
-
Method Detail
-
open
public static ProgramTransaction open(Program program, java.lang.String description)
Start a transaction on the given program with the given description- Parameters:
program
- the program to modifydescription
- a description of the transaction
-
close
public void close()
Finish the transactionIf this is called before
commit()
, then the transaction is aborted. This is called automatically at the close of a try-with-resources block.- Specified by:
close
in interfacejava.lang.AutoCloseable
-
commit
public void commit()
Finish the transaction, and commitThis MUST be called in order to commit the transaction. The transaction is not committed until the close of the try-with-resources block.
-
-