Package ghidra.framework.data
Class DomainObjectAdapterDB
- java.lang.Object
-
- ghidra.framework.data.DomainObjectAdapter
-
- ghidra.framework.data.DomainObjectAdapterDB
-
- All Implemented Interfaces:
DBConstants
,ErrorHandler
,DomainObject
,Undoable
,UndoableDomainObject
- Direct Known Subclasses:
DataTypeArchiveDB
,ProgramDB
public abstract class DomainObjectAdapterDB extends DomainObjectAdapter implements UndoableDomainObject, ErrorHandler, DBConstants
Database version of the DomainObjectAdapter; this version 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. The implementation class must also satisfy the following requirements:1. The following constructor signature must be implemented: ** * Constructs new Domain Object * @param dbh a handle to an open domain object database. * @param openMode one of: * READ_ONLY: the original database will not be modified * UPDATE: the database can be written to. * UPGRADE: the database is upgraded to the latest schema as it is opened. * @param monitor TaskMonitor that allows the open to be cancelled. * @param consumer the object that keeping the program open. * * @throws IOException if an error accessing the database occurs. * @throws VersionException if database version does not match implementation. UPGRADE may be possible. ** public DomainObjectAdapterDB(DBHandle dbh, int openMode, TaskMonitor monitor, Object consumer) throws IOException, VersionException 2. The following static field must be provided: public static final String CONTENT_TYPE
-
-
Field Summary
Fields Modifier and Type Field Description protected DomainObjectDBChangeSet
changeSet
protected DBHandle
dbh
protected static int
NUM_UNDOS
protected ghidra.framework.data.OptionsDB
options
-
Fields inherited from class ghidra.framework.data.DomainObjectAdapter
changed, changeSupportMap, DEFAULT_NAME, lock, metadata, name, temporary
-
Fields inherited from interface db.DBConstants
CREATE, READ_ONLY, UPDATE, UPGRADE
-
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
Constructors Modifier Constructor Description protected
DomainObjectAdapterDB(DBHandle dbh, java.lang.String name, int timeInterval, int bufSize, java.lang.Object consumer)
Construct a new DomainObjectAdapterDB object.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
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
clearUndo()
Clear all undoable/redoable transactionsprotected void
clearUndo(boolean notifyListeners)
protected void
close()
void
dbError(java.io.IOException e)
Notification that an IO exception occurred.void
endTransaction(int transactionID, boolean commit)
Terminate the specified transaction for this domain object.void
flushWriteCache()
Flush any pending database changes.void
forceLock(boolean rollback, java.lang.String reason)
Cancels any previous lock and acquires it.DomainObjectDBChangeSet
getChangeSet()
Returns the change set corresponding to all unsaved changes in this domain object.Transaction
getCurrentTransaction()
Returns the current transactionDBHandle
getDBHandle()
Returns the open handle to the underlying database.Options
getOptions(java.lang.String propertyListName)
Get the property list for the given name.java.util.List<java.lang.String>
getOptionsNames()
Returns all properties lists contained by this domain object.java.lang.String
getRedoName()
Returns a description of the change that would be "redone".DomainObject[]
getSynchronizedDomainObjects()
Return array of all domain objects synchronized with a shared transaction manager.java.lang.String
getUndoName()
Returns a description of the chanage that would be "undone".int
getUndoStackDepth()
Returns the undo stack depth.protected DomainObjectAdapterDB
getUserData()
Returns the user data object or null if not supported by this domain object.boolean
hasTerminatedTransaction()
Returns true if the last transaction was terminated externally from the action that started it.void
invalidateWriteCache()
Invalidate (i.e., clear) any pending database changes not yet written.boolean
isChanged()
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
loadMetadata()
boolean
lock(java.lang.String reason)
Attempt to obtain a modification lock on the domain object.protected void
performPropertyListAlterations(java.util.Map<java.lang.String,java.lang.String> propertyAlterations, TaskMonitor monitor)
This method can be used to perform property list alterations resulting from renamed or obsolete property paths.protected boolean
propertyChanged(java.lang.String propertyName, java.lang.Object oldValue, java.lang.Object newValue)
Notification of property changevoid
redo()
Returns to a latter state that exists because of an undo.void
releaseSynchronizedDomainObject()
Release this domain object from a shared transaction manager.void
removeTransactionListener(TransactionListener listener)
Removes the given transaction listener from this domain object.void
save(java.lang.String comment, TaskMonitor monitor)
Saves changes to the DomainFile.protected void
saveMetadata()
void
saveToPackedFile(java.io.File outputFile, TaskMonitor monitor)
Saves (i.e., serializes) the current content to a packed file.protected void
setChanged(boolean b)
int
startTransaction(java.lang.String description)
Start a new transaction in order to make changes to this domain object.int
startTransaction(java.lang.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
updateMetadata()
This method is called before a save, saveAs, or saveToPackedFile to update common meta data-
Methods inherited from class ghidra.framework.data.DomainObjectAdapter
addCloseListener, addConsumer, addListener, checkExclusiveAccess, createPrivateEventQueue, fatalErrorOccurred, fireEvent, flushEvents, flushPrivateEventQueue, getAssociatedUserFilesystem, getChangeStatus, getConsumerList, getContentHandler, getDescription, getDomainFile, getLock, getMetadata, getModificationNumber, getName, hasExclusiveAccess, isSendingEvents, isTemporary, isUsedBy, release, removeCloseListener, removeListener, removePrivateEventQueue, setDefaultContentClass, 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
addCloseListener, addConsumer, addListener, createPrivateEventQueue, flushEvents, flushPrivateEventQueue, getConsumerList, getDescription, getDomainFile, getMetadata, getModificationNumber, getName, hasExclusiveAccess, isChangeable, isSendingEvents, isTemporary, isUsedBy, release, removeCloseListener, removeListener, removePrivateEventQueue, setEventsEnabled, setName, setTemporary
-
-
-
-
Field Detail
-
NUM_UNDOS
protected static final int NUM_UNDOS
- See Also:
- Constant Field Values
-
dbh
protected DBHandle dbh
-
changeSet
protected DomainObjectDBChangeSet changeSet
-
options
protected ghidra.framework.data.OptionsDB options
-
-
Constructor Detail
-
DomainObjectAdapterDB
protected DomainObjectAdapterDB(DBHandle dbh, java.lang.String name, int timeInterval, int bufSize, java.lang.Object consumer)
Construct a new DomainObjectAdapterDB object. If construction of this object fails, be sure to release with consumer- 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.bufSize
- initial size of event bufferconsumer
- the object that created this domain object
-
-
Method Detail
-
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
public DomainObject[] getSynchronizedDomainObjects()
Return array of all domain objects synchronized with a shared transaction manager.- Specified by:
getSynchronizedDomainObjects
in interfaceUndoableDomainObject
- Returns:
- returns array of synchronized domain objects or null if this domain object is not synchronized with others.
-
addSynchronizedDomainObject
public void addSynchronizedDomainObject(DomainObject domainObj) throws LockException
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 interfaceUndoableDomainObject
- Parameters:
domainObj
-- Throws:
LockException
- if lock or open transaction is active on either this or the specified domain object
-
releaseSynchronizedDomainObject
public void releaseSynchronizedDomainObject() throws LockException
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 interfaceUndoableDomainObject
- Throws:
LockException
- if lock or open transaction is active
-
getDBHandle
public DBHandle getDBHandle()
Returns the open handle to the underlying database.
-
getUserData
protected DomainObjectAdapterDB getUserData()
Returns the user data object or null if not supported by this domain object.
-
getChangeSet
public DomainObjectDBChangeSet 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
public void dbError(java.io.IOException e)
Description copied from interface:ErrorHandler
Notification that an IO exception occurred.- Specified by:
dbError
in interfaceErrorHandler
- See Also:
ErrorHandler.dbError(java.io.IOException)
-
getOptionsNames
public java.util.List<java.lang.String> 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
public Options getOptions(java.lang.String propertyListName)
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
- See Also:
DomainObject.getOptions(java.lang.String)
-
performPropertyListAlterations
protected void performPropertyListAlterations(java.util.Map<java.lang.String,java.lang.String> propertyAlterations, TaskMonitor monitor) throws java.io.IOException
This 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:
java.io.IOException
- See Also:
OptionsDB.performAlterations(Map)
-
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
- See Also:
DomainObject.canLock()
-
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
- See Also:
DomainObject.isLocked()
-
lock
public boolean lock(java.lang.String reason)
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.
- See Also:
DomainObject.lock(String)
-
forceLock
public void forceLock(boolean rollback, java.lang.String reason)
Description copied from interface:DomainObject
Cancels any previous lock and acquires it.- Specified by:
forceLock
in interfaceDomainObject
- Parameters:
rollback
- if true, any changes in made with the previous lock should be discarded.reason
- very short reason for requesting lock- See Also:
DomainObject.forceLock(boolean, String)
-
unlock
public void unlock()
Description copied from interface:DomainObject
Release a modification lock previously granted with the lock method.- Specified by:
unlock
in interfaceDomainObject
- See Also:
DomainObject.unlock()
-
startTransaction
public int startTransaction(java.lang.String description)
Description copied from interface:UndoableDomainObject
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 interfaceUndoableDomainObject
- Parameters:
description
- brief description of transaction- Returns:
- transaction ID
-
startTransaction
public int startTransaction(java.lang.String description, AbortedTransactionListener listener)
Description copied from interface:UndoableDomainObject
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 interfaceUndoableDomainObject
- Parameters:
description
- brief description of transactionlistener
- listener to be notified if the transaction is aborted.- Returns:
- transaction ID
- See Also:
UndoableDomainObject.startTransaction(java.lang.String)
-
endTransaction
public void endTransaction(int transactionID, boolean commit)
Description copied from interface:UndoableDomainObject
Terminate the specified transaction for this domain object.- Specified by:
endTransaction
in interfaceUndoableDomainObject
- 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.- See Also:
UndoableDomainObject.endTransaction(int, boolean)
-
addTransactionListener
public void addTransactionListener(TransactionListener listener)
Adds the given transaction listener to this domain object- Specified by:
addTransactionListener
in interfaceUndoable
- Parameters:
listener
- the new transaction listener to add
-
removeTransactionListener
public void removeTransactionListener(TransactionListener listener)
Removes the given transaction listener from this domain object.- Specified by:
removeTransactionListener
in interfaceUndoable
- 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:Undoable
Returns true if there is a later state to "redo" to.- Specified by:
canRedo
in interfaceUndoable
- See Also:
Undoable.canRedo()
-
canUndo
public boolean canUndo()
Description copied from interface:Undoable
Returns true if there is a previous state to "undo" to.- Specified by:
canUndo
in interfaceUndoable
- See Also:
Undoable.canUndo()
-
getRedoName
public java.lang.String getRedoName()
Description copied from interface:Undoable
Returns a description of the change that would be "redone".- Specified by:
getRedoName
in interfaceUndoable
- See Also:
Undoable.getRedoName()
-
getUndoName
public java.lang.String getUndoName()
Description copied from interface:Undoable
Returns a description of the chanage that would be "undone".- Specified by:
getUndoName
in interfaceUndoable
- See Also:
Undoable.getUndoName()
-
getCurrentTransaction
public Transaction getCurrentTransaction()
Description copied from interface:UndoableDomainObject
Returns the current transaction- Specified by:
getCurrentTransaction
in interfaceUndoableDomainObject
- Returns:
- the current transaction
- See Also:
UndoableDomainObject.getCurrentTransaction()
-
redo
public void redo() throws java.io.IOException
Description copied from interface:Undoable
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 interfaceUndoable
- Throws:
java.io.IOException
- if an IO error occurs- See Also:
Undoable.redo()
-
undo
public void undo() throws java.io.IOException
Description copied from interface:Undoable
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 interfaceUndoable
- Throws:
java.io.IOException
- if an IO error occurs- See Also:
Undoable.undo()
-
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.
- See Also:
DomainObject.isChanged()
-
setChanged
protected void setChanged(boolean b)
- Overrides:
setChanged
in classDomainObjectAdapter
-
propertyChanged
protected boolean propertyChanged(java.lang.String propertyName, java.lang.Object oldValue, java.lang.Object newValue)
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:Undoable
Clear all undoable/redoable transactions- Specified by:
clearUndo
in interfaceUndoable
- See Also:
Undoable.clearUndo()
-
clearUndo
protected void clearUndo(boolean notifyListeners)
-
clearCache
protected void clearCache(boolean all)
-
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
- See Also:
DomainObject.canSave()
-
save
public void save(java.lang.String comment, TaskMonitor monitor) throws java.io.IOException, CancelledException
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:
java.io.IOException
- thrown if there was an error accessing this domain objectReadOnlyException
- thrown if this DomainObject is read only and cannot be savedCancelledException
- thrown if the user canceled the save operation- See Also:
DomainObject.save(java.lang.String, ghidra.util.task.TaskMonitor)
-
saveToPackedFile
public void saveToPackedFile(java.io.File outputFile, TaskMonitor monitor) throws java.io.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:
java.io.IOException
- if an exception occursCancelledException
- if the user cancels- See Also:
DomainObject.saveToPackedFile(java.io.File, ghidra.util.task.TaskMonitor)
-
updateMetadata
protected void updateMetadata() throws java.io.IOException
This method is called before a save, saveAs, or saveToPackedFile to update common meta data- Throws:
java.io.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
- See Also:
DomainObject.isClosed()
-
hasTerminatedTransaction
public boolean hasTerminatedTransaction()
Description copied from interface:UndoableDomainObject
Returns true if the last transaction was terminated externally from the action that started it.- Specified by:
hasTerminatedTransaction
in interfaceUndoableDomainObject
- See Also:
UndoableDomainObject.hasTerminatedTransaction()
-
loadMetadata
protected void loadMetadata() throws java.io.IOException
- Throws:
java.io.IOException
-
saveMetadata
protected void saveMetadata() throws java.io.IOException
- Throws:
java.io.IOException
-
-