Package ghidra.framework.store.db

# Class PackedDatabase

java.lang.Object
db.Database
ghidra.framework.store.db.PackedDatabase

public class PackedDatabase extends Database
`PackedDatabase` provides a packed form of Database which compresses a single version into a file.

When opening a packed database, a PackedDBHandle is returned after first expanding the file into a temporary Database.

- ## Nested Class Summary

  ## Nested classes/interfaces inherited from class db.Database

  `Database.DBBufferFileManager`

- ## Field Summary

  Fields
  Modifier and Type
  Field
  Description
  `static final String`
  `READ_ONLY_DIRECTORY_LOCK_FILE`
  Presence of the directory lock file will prevent the creation or modification of any packed database files contained within that directory or any sub-directory.

  ### Fields inherited from class db.Database

  `bfMgr, CHANGE_FILE_PREFIX, CUMULATIVE_CHANGE_FILENAME, CUMULATIVE_MODMAP_FILENAME, currentVersion, DATABASE_FILE_PREFIX, dbDir, dbDirCreated, dbFileListener, isCheckOutCopy, isVersioned, lastModified, minVersion, syncObject, updateAllowed, VERSION_FILE_PREFIX`

- ## Method Summary

  Modifier and Type
  Method
  Description
  `static void`
  `cleanupOldTempDatabases()`
  Attempt to remove all old temporary databases.
  `void`
  `delete()`
  Deletes the storage file associated with this packed database.
  `static void`
  `delete(File packedDbFile)`
  Deletes the storage file associated with this packed database.
  `void`
  `dispose()`
  Free resources consumed by this object.
  `protected void`
  `finalize()`
  `String`
  `getContentType()`
  Returns the user defined content type associated with this database.
  `static PackedDatabase`
  `getPackedDatabase(ResourceFile packedDbFile, boolean neverCache, TaskMonitor monitor)`
  Get a packed database whose unpacking may be cached if possible provided doNotCache is false.
  `static PackedDatabase`
  `getPackedDatabase(File packedDbFile, boolean neverCache, TaskMonitor monitor)`
  Get a packed database whose unpacking may be cached if possible provided doNotCache is false.
  `static PackedDatabase`
  `getPackedDatabase(File packedDbFile, TaskMonitor monitor)`
  Get a packed database which whose unpacking will be cached if possible.
  `ResourceFile`
  `getPackedFile()`
  Returns the storage file associated with this packed database.
  `boolean`
  `isReadOnly()`
  `static boolean`
  `isReadOnlyPDBDirectory(ResourceFile directory)`
  Check for the presence of directory read-only lock
  `DBHandle`
  `open(TaskMonitor monitor)`
  Open the stored database for non-update use.
  `DBHandle`
  `openForUpdate(TaskMonitor monitor)`
  Open the stored database for update use.
  `static void`
  `packDatabase(DBHandle dbh, String itemName, String contentType, File outputFile, TaskMonitor monitor)`
  Serialize (i.e., pack) an open database into the specified outputFile.
  `static void`
  `unpackDatabase(BufferFileManager bfMgr, long checkinId, File packedFile, TaskMonitor monitor)`
  Create a new Database with data provided by an ItemDeserializer.

  ### Methods inherited from class db.Database

  `deleteDir, getCurrentVersion, lastModified, length, refresh, scanFiles, setSynchronizationObject`

  ### Methods inherited from class java.lang.Object

  `clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Field Details

  - ### READ_ONLY_DIRECTORY_LOCK_FILE

    public static final String READ_ONLY_DIRECTORY_LOCK_FILE
    Presence of the directory lock file will prevent the creation or modification of any packed database files contained within that directory or any sub-directory.
    See Also:
      - Constant Field Values

- ## Method Details

  - ### isReadOnly

    public boolean isReadOnly()

  - ### getPackedDatabase

    public static PackedDatabase getPackedDatabase(File packedDbFile, TaskMonitor monitor) throws IOException, CancelledException
    Get a packed database which whose unpacking will be cached if possible.
    Parameters:
      `packedDbFile` - packed database file to be opened
      `monitor` - unpack/open monitor
    Returns:
      packed database which corresponds to the specified packedDbFile
    Throws:
      `IOException` - if IO error occurs
      `CancelledException` - if unpack/open is cancelled

  - ### getPackedDatabase

    public static PackedDatabase getPackedDatabase(File packedDbFile, boolean neverCache, TaskMonitor monitor) throws IOException, CancelledException
    Get a packed database whose unpacking may be cached if possible provided doNotCache is false.
    Parameters:
      `packedDbFile` - packed database file to be opened
      `neverCache` - if true unpacking will never be cache.
      `monitor` - unpack/open monitor
    Returns:
      packed database which corresponds to the specified packedDbFile
    Throws:
      `IOException` - if IO error occurs
      `CancelledException` - if unpack/open is cancelled

  - ### getPackedDatabase

    public static PackedDatabase getPackedDatabase(ResourceFile packedDbFile, boolean neverCache, TaskMonitor monitor) throws IOException, CancelledException
    Get a packed database whose unpacking may be cached if possible provided doNotCache is false.
    Parameters:
      `packedDbFile` - packed database resource file to be opened
      `neverCache` - if true unpacking will never be cache.
      `monitor` - unpack/open monitor
    Returns:
      packed database which corresponds to the specified packedDbFile
    Throws:
      `IOException` - if IO error occurs
      `CancelledException` - if unpack/open is cancelled

  - ### isReadOnlyPDBDirectory

    public static boolean isReadOnlyPDBDirectory(ResourceFile directory)
    Check for the presence of directory read-only lock
    Parameters:
      `directory` - directory to check for read-only lock
    Returns:
      true if read-only lock exists

  - ### finalize

    protected void finalize() throws Throwable
    Overrides:
      `finalize` in class `Object`
    Throws:
      `Throwable`

  - ### dispose

    public void dispose()
    Free resources consumed by this object. If there is an associated database handle it will be closed.

  - ### getContentType

    public String getContentType()
    Returns the user defined content type associated with this database.
    Returns:
      packed DB content type

  - ### getPackedFile

    public ResourceFile getPackedFile()
    Returns the storage file associated with this packed database.
    Returns:
      associated packed DB file

  - ### delete

    public void delete() throws IOException
    Deletes the storage file associated with this packed database. This method should not be called while the database is open, if it is an attempt will be made to close the handle.
    Throws:
      `IOException` - if IO error occurs (e.g., file in-use or write-protected)

  - ### delete

    public static void delete(File packedDbFile) throws IOException
    Deletes the storage file associated with this packed database.
    Parameters:
      `packedDbFile` - packed DB file to be removed
    Throws:
      `FileInUseException` - if packed DB is currently locked and in use
      `IOException` - if an IO error occurs (e.g., file in-use or write-protected)

  - ### unpackDatabase

    public static void unpackDatabase(BufferFileManager bfMgr, long checkinId, File packedFile, TaskMonitor monitor) throws IOException, CancelledException
    Create a new Database with data provided by an ItemDeserializer.
    Parameters:
      `bfMgr` - the buffer manager for the database
      `checkinId` - the check-in id
      `packedFile` - the file to unpack
      `monitor` - the task monitor
    Throws:
      `IOException` - if IO error occurs
      `CancelledException` - if unpack is cancelled

  - ### packDatabase

    public static void packDatabase(DBHandle dbh, String itemName, String contentType, File outputFile, TaskMonitor monitor) throws CancelledException, IOException
    Serialize (i.e., pack) an open database into the specified outputFile.
    Parameters:
      `dbh` - open database handle
      `itemName` - name to associate with packed content
      `contentType` - supported DB content type
      `outputFile` - packed output file to be created
      `monitor` - save/pack monitor
    Throws:
      `ReadOnlyException` - if `outputFile` location is write-protected
      `DuplicateFileException` - if `outputFile` already exists
      `IOException` - if IO error occurs
      `CancelledException` - if monitor cancels operation

  - ### open

    public DBHandle open(TaskMonitor monitor) throws CancelledException, IOException
    Description copied from class: `Database`
    Open the stored database for non-update use. The returned handle does not support the Save operation.
    Overrides:
      `open` in class `Database`
    Parameters:
      `monitor` - task monitor (may be null)
    Returns:
      database handle
    Throws:
      `CancelledException` - if cancelled by monitor
      `IOException` - thrown if IO error occurs.

  - ### openForUpdate

    public DBHandle openForUpdate(TaskMonitor monitor) throws CancelledException, IOException
    Description copied from class: `Database`
    Open the stored database for update use.
    Overrides:
      `openForUpdate` in class `Database`
    Parameters:
      `monitor` - task monitor (may be null)
    Returns:
      buffer file
    Throws:
      `CancelledException` - if cancelled by monitor
      `IOException` - thrown if IO error occurs.

  - ### cleanupOldTempDatabases

    public static void cleanupOldTempDatabases()
    Attempt to remove all old temporary databases. This method is not intended for general use and should only be invoked once during module initialization (see `FileSystemInitializer`).