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 DomainObjectDBChangeSetchangeSetprotected DBHandledbhprotected static intNUM_UNDOSprotected ghidra.framework.data.OptionsDBoptions-
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 protectedDomainObjectAdapterDB(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 voidaddSynchronizedDomainObject(DomainObject domainObj)Synchronize the specified domain object with this domain object using a shared transaction manager.voidaddTransactionListener(TransactionListener listener)Adds the given transaction listener to this domain objectbooleancanLock()Returns true if a modification lock can be obtained on this domain object.booleancanRedo()Returns true if there is a later state to "redo" to.booleancanSave()Returns true if this object can be saved; a read-only file cannot be saved.booleancanUndo()Returns true if there is a previous state to "undo" to.protected voidclearCache(boolean all)voidclearUndo()Clear all undoable/redoable transactionsprotected voidclearUndo(boolean notifyListeners)protected voidclose()voiddbError(java.io.IOException e)Notification that an IO exception occurred.voidendTransaction(int transactionID, boolean commit)Terminate the specified transaction for this domain object.voidflushWriteCache()Flush any pending database changes.voidforceLock(boolean rollback, java.lang.String reason)Cancels any previous lock and acquires it.DomainObjectDBChangeSetgetChangeSet()Returns the change set corresponding to all unsaved changes in this domain object.TransactiongetCurrentTransaction()Returns the current transactionDBHandlegetDBHandle()Returns the open handle to the underlying database.OptionsgetOptions(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.StringgetRedoName()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.StringgetUndoName()Returns a description of the chanage that would be "undone".intgetUndoStackDepth()Returns the undo stack depth.protected DomainObjectAdapterDBgetUserData()Returns the user data object or null if not supported by this domain object.booleanhasTerminatedTransaction()Returns true if the last transaction was terminated externally from the action that started it.voidinvalidateWriteCache()Invalidate (i.e., clear) any pending database changes not yet written.booleanisChanged()Returns whether the object has changed.booleanisClosed()Returns true if this domain object has been closed as a result of the last releasebooleanisLocked()Returns true if the domain object currently has a modification lock enabled.protected voidloadMetadata()booleanlock(java.lang.String reason)Attempt to obtain a modification lock on the domain object.protected voidperformPropertyListAlterations(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 booleanpropertyChanged(java.lang.String propertyName, java.lang.Object oldValue, java.lang.Object newValue)Notification of property changevoidredo()Returns to a latter state that exists because of an undo.voidreleaseSynchronizedDomainObject()Release this domain object from a shared transaction manager.voidremoveTransactionListener(TransactionListener listener)Removes the given transaction listener from this domain object.voidsave(java.lang.String comment, TaskMonitor monitor)Saves changes to the DomainFile.protected voidsaveMetadata()voidsaveToPackedFile(java.io.File outputFile, TaskMonitor monitor)Saves (i.e., serializes) the current content to a packed file.protected voidsetChanged(boolean b)intstartTransaction(java.lang.String description)Start a new transaction in order to make changes to this domain object.intstartTransaction(java.lang.String description, AbortedTransactionListener listener)Start a new transaction in order to make changes to this domain object.voidundo()Returns to the previous state.voidunlock()Release a modification lock previously granted with the lock method.protected voidupdateMetadata()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:
getSynchronizedDomainObjectsin 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:
addSynchronizedDomainObjectin 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 LockExceptionRelease 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:
releaseSynchronizedDomainObjectin 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:ErrorHandlerNotification that an IO exception occurred.- Specified by:
dbErrorin 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:
getOptionsNamesin interfaceDomainObject- Returns:
- all property lists contained by this domain object.
-
getOptions
public Options getOptions(java.lang.String propertyListName)
Description copied from interface:DomainObjectGet the property list for the given name.- Specified by:
getOptionsin 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.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:
java.io.IOException- See Also:
OptionsDB.performAlterations(Map)
-
canLock
public boolean canLock()
Description copied from interface:DomainObjectReturns 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:
canLockin interfaceDomainObject- Returns:
- true if can lock
- See Also:
DomainObject.canLock()
-
isLocked
public boolean isLocked()
Description copied from interface:DomainObjectReturns true if the domain object currently has a modification lock enabled.- Specified by:
isLockedin interfaceDomainObject- Returns:
- true if locked
- See Also:
DomainObject.isLocked()
-
lock
public boolean lock(java.lang.String reason)
Description copied from interface:DomainObjectAttempt 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:
lockin 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:DomainObjectCancels any previous lock and acquires it.- Specified by:
forceLockin 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:DomainObjectRelease a modification lock previously granted with the lock method.- Specified by:
unlockin interfaceDomainObject- See Also:
DomainObject.unlock()
-
startTransaction
public int startTransaction(java.lang.String description)
Description copied from interface:UndoableDomainObjectStart 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:
startTransactionin interfaceUndoableDomainObject- Parameters:
description- brief description of transaction- Returns:
- transaction ID
-
startTransaction
public int startTransaction(java.lang.String description, AbortedTransactionListener listener)Description copied from interface:UndoableDomainObjectStart 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:
startTransactionin 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:UndoableDomainObjectTerminate the specified transaction for this domain object.- Specified by:
endTransactionin 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:
addTransactionListenerin 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:
removeTransactionListenerin 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:UndoableReturns true if there is a later state to "redo" to.- Specified by:
canRedoin interfaceUndoable- See Also:
Undoable.canRedo()
-
canUndo
public boolean canUndo()
Description copied from interface:UndoableReturns true if there is a previous state to "undo" to.- Specified by:
canUndoin interfaceUndoable- See Also:
Undoable.canUndo()
-
getRedoName
public java.lang.String getRedoName()
Description copied from interface:UndoableReturns a description of the change that would be "redone".- Specified by:
getRedoNamein interfaceUndoable- See Also:
Undoable.getRedoName()
-
getUndoName
public java.lang.String getUndoName()
Description copied from interface:UndoableReturns a description of the chanage that would be "undone".- Specified by:
getUndoNamein interfaceUndoable- See Also:
Undoable.getUndoName()
-
getCurrentTransaction
public Transaction getCurrentTransaction()
Description copied from interface:UndoableDomainObjectReturns the current transaction- Specified by:
getCurrentTransactionin interfaceUndoableDomainObject- Returns:
- the current transaction
- See Also:
UndoableDomainObject.getCurrentTransaction()
-
redo
public void redo() throws java.io.IOExceptionDescription copied from interface:UndoableReturns 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:
redoin interfaceUndoable- Throws:
java.io.IOException- if an IO error occurs- See Also:
Undoable.redo()
-
undo
public void undo() throws java.io.IOExceptionDescription copied from interface:UndoableReturns 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:
undoin interfaceUndoable- Throws:
java.io.IOException- if an IO error occurs- See Also:
Undoable.undo()
-
isChanged
public boolean isChanged()
Description copied from interface:DomainObjectReturns whether the object has changed.- Specified by:
isChangedin interfaceDomainObject- Overrides:
isChangedin classDomainObjectAdapter- Returns:
- whether the object has changed.
- See Also:
DomainObject.isChanged()
-
setChanged
protected void setChanged(boolean b)
- Overrides:
setChangedin 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:UndoableClear all undoable/redoable transactions- Specified by:
clearUndoin 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:DomainObjectReturns true if this object can be saved; a read-only file cannot be saved.- Specified by:
canSavein 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, CancelledExceptionDescription copied from interface:DomainObjectSaves changes to the DomainFile.- Specified by:
savein 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, CancelledExceptionDescription copied from interface:DomainObjectSaves (i.e., serializes) the current content to a packed file.- Specified by:
saveToPackedFilein 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.IOExceptionThis method is called before a save, saveAs, or saveToPackedFile to update common meta data- Throws:
java.io.IOException
-
close
protected void close()
- Overrides:
closein classDomainObjectAdapter
-
isClosed
public boolean isClosed()
Description copied from interface:DomainObjectReturns true if this domain object has been closed as a result of the last release- Specified by:
isClosedin interfaceDomainObject- Returns:
- true if closed
- See Also:
DomainObject.isClosed()
-
hasTerminatedTransaction
public boolean hasTerminatedTransaction()
Description copied from interface:UndoableDomainObjectReturns true if the last transaction was terminated externally from the action that started it.- Specified by:
hasTerminatedTransactionin 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
-
-