A
gdbm::ResourceDB
class is a protected subclass of the
gdbm
class.
gdbm::ResourceDB
hides the raw record-based GDBM interface, and
replaces it with a slightly higher-level version.
Although the keys are still arbitrary strings,
instead of storing an arbitrary chunk of bytes,
gdbm::ResourceDB
stores a set of
Dependency
objects.
The
gdbm::ResourceDB
object
stores zero or more Dependency
objects in the
underlying GDBM record, associated with a particular key,
and retrieves them upon demand.
Well, not exactly.
The gdbm::ResourceDB
object does not actually store
new records in the underlying GDBM file.
The gdbm::ResourceDB
object saves new records
in an internal buffer.
Subsequent requests for a record with the same key returns the saved
Dependency
objects.
An attempt to store an empty list of Dependency
objects for a given key gets interpreted as a request to delete the underlying
GDBM record.
It follows that
a request to retrieve the Dependency
list of a
nonexistent key returns an empty list.
The gdbm::ResourceDB
object's
commit
method receives a
FileInstall
object,
that actually records the updated records.
Later, when the
FileInstall
gets commited, the
GDBM file gets actually updated with the new content.
After storing the accumulated list of changed records in the
FileInstall
object, the internal buffer gets cleared
and the underlying GDBM file gets closed.
This is because the file is presently opened in read-only mode (the updated
records are not written to a file, they get saved in a buffer), and the
same GDBM file is going to be opened in read-write
mode very soon.
This means that the read-only file descriptor must be closed (together with
its corresponding lock file), so that the file can be reopened in
read-write mode
(after everything gets commited, if the same
gdbm::ResourceDB
object is accessed, it will automatically reopen the updated file).