Package ghidra.framework.data
Class DomainObjectAdapterDB
java.lang.Object
ghidra.framework.data.DomainObjectAdapter
ghidra.framework.data.DomainObjectAdapterDB
- All Implemented Interfaces:
ErrorHandler
,DomainObject
- Direct Known Subclasses:
DataTypeArchiveDB
,ProgramDB
,URLLinkObject
Database version of the DomainObjectAdapter. Adds the
concept of starting a transaction before a change is made to the
domain object and ending the transaction. The transaction allows for
undo/redo changes.
-
Field Summary
Modifier and TypeFieldDescriptionprotected DomainObjectDBChangeSet
protected DBHandle
protected static final int
protected ghidra.framework.data.OptionsDB
Fields inherited from class ghidra.framework.data.DomainObjectAdapter
changed, changeSupportMap, DEFAULT_NAME, lock, metadata, name, temporary
Fields inherited from interface ghidra.framework.model.DomainObject
DO_DOMAIN_FILE_CHANGED, DO_OBJECT_CLOSED, DO_OBJECT_ERROR, DO_OBJECT_RENAMED, DO_OBJECT_RESTORED, DO_OBJECT_SAVED, DO_PROPERTY_CHANGED, undoLock
-
Constructor Summary
ModifierConstructorDescriptionprotected
DomainObjectAdapterDB
(DBHandle dbh, String name, int timeInterval, Object consumer) Construct a new DomainObjectAdapterDB object. -
Method Summary
Modifier and TypeMethodDescriptionvoid
addSynchronizedDomainObject
(DomainObject domainObj) Synchronize the specified domain object with this domain object using a shared transaction manager.void
addTransactionListener
(TransactionListener listener) Adds the given transaction listener to this domain objectboolean
canLock()
Returns true if a modification lock can be obtained on this domain object.boolean
canRedo()
Returns true if there is a later state to "redo" to.boolean
canSave()
Returns true if this object can be saved; a read-only file cannot be saved.boolean
canUndo()
Returns true if there is a previous state to "undo" to.protected void
clearCache
(boolean all) void
Clear all undoable/redoable transactionsprotected void
clearUndo
(boolean notifyListeners) protected void
close()
void
Notification that an IO exception occurred.protected void
Indicates that this domain object has been restored to a completely different state due to a transaction undo/redo/rollback or a database merge operation.void
endTransaction
(int transactionID, boolean commit) Terminate the specified transaction for this domain object.void
Flush any pending database changes.void
Force transaction lock and terminate current transaction.Returns a list of the names of all current redo transactionsReturns a list of the names of all current undo transactionsReturns the change set corresponding to all unsaved changes in this domain object.Returns the current transaction infoReturns the open handle to the underlying database.getOptions
(String propertyListName) Get the property list for the given name.Returns all properties lists contained by this domain object.Returns a description of the change that would be "redone".Return array of all domain objects synchronized with a shared transaction manager.Returns a description of the change that would be "undone".int
Returns the undo stack depth.protected DomainObjectAdapterDB
Returns the user data object or null if not supported by this domain object.boolean
Returns true if the last transaction was terminated from the action that started it.void
Invalidates any caching in a program and generate aDomainObjectEvent.RESTORED
event.void
Invalidate (i.e., clear) any pending database changes not yet written.boolean
Returns whether the object has changed.boolean
isClosed()
Returns true if this domain object has been closed as a result of the last releaseboolean
isLocked()
Returns true if the domain object currently has a modification lock enabled.protected void
boolean
Attempt to obtain a modification lock on the domain object.openTransaction
(String description) Open new transaction.protected void
performPropertyListAlterations
(Map<String, String> propertyAlterations, TaskMonitor monitor) This method can be used to perform property list alterations resulting from renamed or obsolete property paths.protected boolean
propertyChanged
(String propertyName, Object oldValue, Object newValue) Notification of property changevoid
redo()
Returns to a latter state that exists because of an undo.void
Release this domain object from a shared transaction manager.void
removeTransactionListener
(TransactionListener listener) Removes the given transaction listener from this domain object.void
save
(String comment, TaskMonitor monitor) Saves changes to the DomainFile.protected void
void
saveToPackedFile
(File outputFile, TaskMonitor monitor) Saves (i.e., serializes) the current content to a packed file.protected void
setChanged
(boolean b) protected void
Set instance as immutable by disabling use of transactions.int
startTransaction
(String description) Start a new transaction in order to make changes to this domain object.int
startTransaction
(String description, AbortedTransactionListener listener) Start a new transaction in order to make changes to this domain object.void
undo()
Returns to the previous state.void
unlock()
Release a modification lock previously granted with the lock method.protected void
This method is called before a save, saveAs, or saveToPackedFile to update common meta dataMethods inherited from class ghidra.framework.data.DomainObjectAdapter
addCloseListener, addConsumer, addDomainFileListener, addListener, checkExclusiveAccess, createPrivateEventQueue, fatalErrorOccurred, fireEvent, flushEvents, flushPrivateEventQueue, getAssociatedUserFilesystem, getChangeStatus, getConsumerList, getContentHandler, getContentHandler, getContentHandler, getContentHandlers, getDescription, getDomainFile, getLock, getMetadata, getModificationNumber, getName, hasExclusiveAccess, isSendingEvents, isTemporary, isUsedBy, release, removeCloseListener, removeDomainFileListener, removeListener, removePrivateEventQueue, setDomainFile, setEventsEnabled, setName, setTemporary, toString
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface ghidra.framework.model.DomainObject
isChangeable, withTransaction, withTransaction
-
Field Details
-
NUM_UNDOS
protected static final int NUM_UNDOS- See Also:
-
dbh
-
changeSet
-
options
protected ghidra.framework.data.OptionsDB options
-
-
Constructor Details
-
DomainObjectAdapterDB
Construct a new DomainObjectAdapterDB object.- Parameters:
dbh
- database handlename
- name of the domain objecttimeInterval
- the time (in milliseconds) to wait before the event queue is flushed. If a new event comes in before the time expires the timer is reset.consumer
- the object that created this domain object
-
-
Method Details
-
flushWriteCache
public void flushWriteCache()Flush any pending database changes. This method will be invoked by the transaction manager prior to closing a transaction. -
invalidateWriteCache
public void invalidateWriteCache()Invalidate (i.e., clear) any pending database changes not yet written. This method will be invoked by the transaction manager prior to aborting a transaction. -
getSynchronizedDomainObjects
Return array of all domain objects synchronized with a shared transaction manager.- Specified by:
getSynchronizedDomainObjects
in interfaceDomainObject
- Returns:
- returns array of synchronized domain objects or null if this domain object is not synchronized with others.
-
addSynchronizedDomainObject
Synchronize the specified domain object with this domain object using a shared transaction manager. If either or both is already shared, a transition to a single shared transaction manager will be performed.- Specified by:
addSynchronizedDomainObject
in interfaceDomainObject
- Parameters:
domainObj
-- Throws:
LockException
- if lock or open transaction is active on either this or the specified domain object
-
releaseSynchronizedDomainObject
Release this domain object from a shared transaction manager. If this object has not been synchronized with others via a shared transaction manager, this method will have no affect.- Specified by:
releaseSynchronizedDomainObject
in interfaceDomainObject
- Throws:
LockException
- if lock or open transaction is active
-
getDBHandle
Returns the open handle to the underlying database. -
getUserData
Returns the user data object or null if not supported by this domain object. -
getChangeSet
Returns the change set corresponding to all unsaved changes in this domain object.- Returns:
- the change set corresponding to all unsaved changes in this domain object
-
dbError
Description copied from interface:ErrorHandler
Notification that an IO exception occurred.- Specified by:
dbError
in interfaceErrorHandler
- Parameters:
e
-IOException
which was cause of error
-
getOptionsNames
Returns all properties lists contained by this domain object.- Specified by:
getOptionsNames
in interfaceDomainObject
- Returns:
- all property lists contained by this domain object.
-
getOptions
Description copied from interface:DomainObject
Get the property list for the given name.- Specified by:
getOptions
in interfaceDomainObject
- Parameters:
propertyListName
- name of property list- Returns:
- the options
-
performPropertyListAlterations
protected void performPropertyListAlterations(Map<String, String> propertyAlterations, TaskMonitor monitor) throws IOExceptionThis method can be used to perform property list alterations resulting from renamed or obsolete property paths. This should only be invoked during an upgrade. WARNING! Should only be called during construction of domain object- Throws:
IOException
- See Also:
-
canLock
public boolean canLock()Description copied from interface:DomainObject
Returns true if a modification lock can be obtained on this domain object. Care should be taken with using this method since this will not prevent another thread from modifying the domain object.- Specified by:
canLock
in interfaceDomainObject
- Returns:
- true if can lock
-
isLocked
public boolean isLocked()Description copied from interface:DomainObject
Returns true if the domain object currently has a modification lock enabled.- Specified by:
isLocked
in interfaceDomainObject
- Returns:
- true if locked
-
lock
Description copied from interface:DomainObject
Attempt to obtain a modification lock on the domain object. Multiple locks may be granted on this domain object, although all lock owners must release their lock in a timely fashion.- Specified by:
lock
in interfaceDomainObject
- Parameters:
reason
- very short reason for requesting lock- Returns:
- true if lock obtained successfully, else false which indicates that a modification is in process.
-
setImmutable
protected void setImmutable()Set instance as immutable by disabling use of transactions. Attempts to start a transaction will result in aTerminatedTransactionException
. This method should invoked at the end of instance instatiationOpenMode.IMMUTABLE
was used. -
forceLock
Description copied from interface:DomainObject
Force transaction lock and terminate current transaction.- Specified by:
forceLock
in interfaceDomainObject
- Parameters:
rollback
- true if rollback of non-commited changes should occurs, false if commit should be done. NOTE: it can be potentially detrimental to commit an incomplete transaction which should be avoided.reason
- very short reason for requesting lock
-
unlock
public void unlock()Description copied from interface:DomainObject
Release a modification lock previously granted with the lock method.- Specified by:
unlock
in interfaceDomainObject
-
openTransaction
public Transaction openTransaction(String description) throws TerminatedTransactionException, IllegalStateException Description copied from interface:DomainObject
Open new transaction. This should generally be done with a try-with-resources block:try (Transaction tx = dobj.openTransaction(description)) { // ... Do something }
- Specified by:
openTransaction
in interfaceDomainObject
- Parameters:
description
- a short description of the changes to be made.- Returns:
- transaction object
- Throws:
IllegalStateException
- if thisDomainObject
has already been closed.TerminatedTransactionException
-
startTransaction
Description copied from interface:DomainObject
Start a new transaction in order to make changes to this domain object. All changes must be made in the context of a transaction. If a transaction is already in progress, a sub-transaction of the current transaction will be returned.- Specified by:
startTransaction
in interfaceDomainObject
- Parameters:
description
- brief description of transaction- Returns:
- transaction ID
- Throws:
TerminatedTransactionException
- an existing transaction which has not yet ended was terminated early. Sub-transactions are not permitted until the terminated transaction ends.
-
startTransaction
public int startTransaction(String description, AbortedTransactionListener listener) throws TerminatedTransactionException Description copied from interface:DomainObject
Start a new transaction in order to make changes to this domain object. All changes must be made in the context of a transaction. If a transaction is already in progress, a sub-transaction of the current transaction will be returned.- Specified by:
startTransaction
in interfaceDomainObject
- Parameters:
description
- brief description of transactionlistener
- listener to be notified if the transaction is aborted.- Returns:
- transaction ID
- Throws:
TerminatedTransactionException
- an existing transaction which has not yet ended was terminated early. Sub-transactions are not permitted until the terminated transaction ends.
-
endTransaction
Description copied from interface:DomainObject
Terminate the specified transaction for this domain object.- Specified by:
endTransaction
in interfaceDomainObject
- Parameters:
transactionID
- transaction ID obtained from startTransaction methodcommit
- if true the changes made in this transaction will be marked for commit, if false this and any concurrent transaction will be rolled-back.- Throws:
IllegalStateException
-
addTransactionListener
Adds the given transaction listener to this domain object- Specified by:
addTransactionListener
in interfaceDomainObject
- Parameters:
listener
- the new transaction listener to add
-
removeTransactionListener
Removes the given transaction listener from this domain object.- Specified by:
removeTransactionListener
in interfaceDomainObject
- Parameters:
listener
- the transaction listener to remove
-
getUndoStackDepth
public int getUndoStackDepth()Returns the undo stack depth. (The number of items on the undo stack) This method is for JUnits.- Returns:
- the undo stack depth
-
canRedo
public boolean canRedo()Description copied from interface:DomainObject
Returns true if there is a later state to "redo" to.- Specified by:
canRedo
in interfaceDomainObject
-
canUndo
public boolean canUndo()Description copied from interface:DomainObject
Returns true if there is a previous state to "undo" to.- Specified by:
canUndo
in interfaceDomainObject
-
getRedoName
Description copied from interface:DomainObject
Returns a description of the change that would be "redone".- Specified by:
getRedoName
in interfaceDomainObject
- Returns:
- a description of the change that would be "redone".
-
getUndoName
Description copied from interface:DomainObject
Returns a description of the change that would be "undone".- Specified by:
getUndoName
in interfaceDomainObject
- Returns:
- a description of the change that would be "undone".
-
getAllUndoNames
Description copied from interface:DomainObject
Returns a list of the names of all current undo transactions- Specified by:
getAllUndoNames
in interfaceDomainObject
- Returns:
- a list of the names of all current undo transactions
-
getAllRedoNames
Description copied from interface:DomainObject
Returns a list of the names of all current redo transactions- Specified by:
getAllRedoNames
in interfaceDomainObject
- Returns:
- a list of the names of all current redo transactions
-
getCurrentTransactionInfo
Description copied from interface:DomainObject
Returns the current transaction info- Specified by:
getCurrentTransactionInfo
in interfaceDomainObject
- Returns:
- the current transaction info
-
redo
Description copied from interface:DomainObject
Returns to a latter state that exists because of an undo. Normally, this will cause the current state to appear on the "undo" stack. This method will do nothing if there are no latter states to "redo".- Specified by:
redo
in interfaceDomainObject
- Throws:
IOException
- if an IO error occurs
-
undo
Description copied from interface:DomainObject
Returns to the previous state. Normally, this will cause the current state to appear on the "redo" stack. This method will do nothing if there are no previous states to "undo".- Specified by:
undo
in interfaceDomainObject
- Throws:
IOException
- if an IO error occurs
-
isChanged
public boolean isChanged()Description copied from interface:DomainObject
Returns whether the object has changed.- Specified by:
isChanged
in interfaceDomainObject
- Overrides:
isChanged
in classDomainObjectAdapter
- Returns:
- whether the object has changed.
-
setChanged
protected void setChanged(boolean b) - Overrides:
setChanged
in classDomainObjectAdapter
-
propertyChanged
Notification of property change- Parameters:
propertyName
-oldValue
-newValue
-- Returns:
- true if change is OK, false value should be reverted
-
clearUndo
public void clearUndo()Description copied from interface:DomainObject
Clear all undoable/redoable transactions- Specified by:
clearUndo
in interfaceDomainObject
-
clearUndo
protected void clearUndo(boolean notifyListeners) -
invalidate
public void invalidate()Description copied from class:DomainObjectAdapter
Invalidates any caching in a program and generate aDomainObjectEvent.RESTORED
event. NOTE: Over-using this method can adversely affect system performance.- Overrides:
invalidate
in classDomainObjectAdapter
-
clearCache
protected void clearCache(boolean all) -
domainObjectRestored
protected void domainObjectRestored()Indicates that this domain object has been restored to a completely different state due to a transaction undo/redo/rollback or a database merge operation. -
canSave
public boolean canSave()Description copied from interface:DomainObject
Returns true if this object can be saved; a read-only file cannot be saved.- Specified by:
canSave
in interfaceDomainObject
- Returns:
- true if this object can be saved
-
save
Description copied from interface:DomainObject
Saves changes to the DomainFile.- Specified by:
save
in interfaceDomainObject
- Parameters:
comment
- comment used for new versionmonitor
- monitor that shows the progress of the save- Throws:
IOException
- thrown if there was an error accessing this domain objectCancelledException
- thrown if the user canceled the save operation
-
saveToPackedFile
public void saveToPackedFile(File outputFile, TaskMonitor monitor) throws IOException, CancelledException Description copied from interface:DomainObject
Saves (i.e., serializes) the current content to a packed file.- Specified by:
saveToPackedFile
in interfaceDomainObject
- Parameters:
outputFile
- packed output filemonitor
- progress monitor- Throws:
IOException
- if an exception occursCancelledException
- if the user cancels
-
updateMetadata
This method is called before a save, saveAs, or saveToPackedFile to update common meta data- Throws:
IOException
-
close
protected void close()- Overrides:
close
in classDomainObjectAdapter
-
isClosed
public boolean isClosed()Description copied from interface:DomainObject
Returns true if this domain object has been closed as a result of the last release- Specified by:
isClosed
in interfaceDomainObject
- Returns:
- true if closed
-
hasTerminatedTransaction
public boolean hasTerminatedTransaction()Description copied from interface:DomainObject
Returns true if the last transaction was terminated from the action that started it.- Specified by:
hasTerminatedTransaction
in interfaceDomainObject
- Returns:
- true if the last transaction was terminated from the action that started it.
-
loadMetadata
- Throws:
IOException
-
saveMetadata
- Throws:
IOException
-