LBTest.mesa
Copyright Ó 1985, 1992 by Xerox Corporation. All rights reserved.
Doug Terry, March 18, 1987 11:27:46 am PST
Brian Oki November 15, 1989 4:49:36 pm PST
Willie-s, January 4, 1993 5:49 pm PST
Clients of the LoganBerry data management facilities should use the LoganBerry.mesa interface. This is a non-RPC internal interface to these facilities used as a convenience for testing only.
~
BEGIN
OPEN LoganBerry, LoganBerryStructure;
OpenI:
PROC [dbName:
ROPE]
RETURNS [dbinfo: OpenDBInfo];
Initiates database activity and checks for consistency. This can be called any number of times to get a new OpenDB handle or reopen a database that has been closed.
Errors: CantOpenSchema, BadSchema, CantOpenLog, BadIndex
DescribeI:
PROC [dbinfo: OpenDBInfo]
RETURNS [info: SchemaInfo];
Returns schema information about the database. This routine is not monitored since it can safely be called while other operations are in progress.
ReadEntryI:
PROC [dbinfo: OpenDBInfo, key: AttributeType, value: AttributeValue]
RETURNS [entry: Entry, others:
BOOLEAN];
Returns an entry that contains the given attribute value for the given key. If the key refers to the primary index then the unique entry is returned and `others' is FALSE. If the key is secondary and several entries exist with the same value for the key, then an arbitrary entry is returned and `others' is set to TRUE; use EnumerateEntries to get all of the matching entries.
Errors: BadDBHandle, NoIndex, DBClosed, BadIndex, BadLogEntry
EntryProc: TYPE = PROC [entry: Entry] RETURNS [continue: BOOL];
EnumerateEntriesI:
PROC [dbinfo: OpenDBInfo, key: AttributeType, start: AttributeValue ¬
NIL, end: AttributeValue ¬
NIL, proc: EntryProc]
RETURNS [];
Calls `proc' for each entry in the specified range of key values. The enumeration is halted when either the range of entries is exhausted or `proc' returns FALSE. A NIL value for `start' represents the least attribute value, while a NIL value for `end' represents the largest attribute value. Thus, the complete database can be enumerated by specifying start=NIL and end=NIL with `key' equal to the primary key.
WARNING: THIS ROUTINE CAN NOT BE USED ACROSS AN RPC CONNECTION; USE GenerateEntries INSTEAD.
Errors: BadDBHandle, NoIndex, DBClosed, BadIndex, BadLogEntry
GenerateEntriesI:
PROC [dbinfo: OpenDBInfo, key: AttributeType, start: AttributeValue ¬
NIL, end: AttributeValue ¬
NIL]
RETURNS [cinfo: CursorInfo];
Similar to EnumerateEntries, but creates a cursor so that entries in the specified range of key values can be retrieved using NextEntry (defined below). Initially, the cursor points to the start of the sequence. A NIL value for `start' represents the least attribute value, while a NIL value for `end' represents the largest attribute value. Thus, the complete database can be enumerated by specifying start=NIL and end=NIL with `key' equal to the primary key.
Errors: BadDBHandle, NoIndex
NextEntryI:
PROC [dbinfo: OpenDBInfo, cinfo: CursorInfo, dir: CursorDirection ¬ increasing]
RETURNS [entry: Entry];
Retrieves the next entry relative to the given cursor. The cursor, and thus the sequence of desired entries, must have been previously created by a call to GenerateEntries. The cursor is automatically updated so that NextEntry may be repeatedly called to enumerate entries. NIL is returned if the cursor is at the end of the sequence and dir=increasing or at the start of the sequence and dir=decreasing.
Errors: BadCursor, DBClosed, BadIndex, BadLogEntry
EndGenerateI:
PROC [dbinfo: OpenDBInfo, cinfo: CursorInfo]
RETURNS [];
Releases the cursor; no further operations may be performed using the given cursor. This must be called once for every call to GenerateEntries.
WriteEntryI:
PROC [dbinfo: OpenDBInfo, entry: Entry, log: LogID ¬ activityLog, replace:
BOOLEAN ¬
FALSE]
RETURNS [];
Adds a new entry to the database. The entry is added to the activity log unless another log is explicitly requested. The entry must have an attribute for the primary key. The primary attribute value must be unique throughout the database unless replace=TRUE; in this case, an existing entry with the same primary attribute value is atomically replaced with the new entry.
Errors: BadDBHandle, NoPrimaryKey, ValueNotUnique, LogReadOnly, InvalidReplace, DBClosed, BadIndex
DeleteEntryI:
PROC [dbinfo: OpenDBInfo, key: AttributeType, value: AttributeValue]
RETURNS [deleted: Entry];
Deletes the entry that contains the given attribute value for the given key. If the key is for a secondary index and the value is not unique then an Error[ValueNotUnique] is raised. Deletes are actually performed by logging the delete request (so that the log can be replayed at a later time) and then updating all of the indices.
Errors: BadDBHandle, NoIndex, DBClosed, BadIndex, ValueNotUnique, LogReadOnly, BadLogEntry
CloseI:
PROC [dbinfo: OpenDBInfo]
RETURNS [];
Terminates database activity and closes all log and index files. Databases are always maintained consistently on disk so it doesn't hurt to leave a database open. The main reason for calling Close is to release the FS locks on the log files so they can be manually edited.
WARNING: THIS SHOULD NOT BE CALLED IF THE DATABASE IS BEING SHARED BY MULTIPLE CLIENTS.
Errors: BadDBHandle
BuildIndicesI:
PROC [dbinfo: OpenDBInfo]
RETURNS [];
Rebuilds the indices by scanning the logs and performing WriteEntry or DeleteEntry operations.
CompactLogsI:
PROC [dbinfo: OpenDBInfo]
RETURNS [];
Removes deleted entries from the logs by enumerating the primary index and writing new logs.
SetRemoteAccessI:
PROC [dbinfo: OpenDBInfo, accessible:
BOOLEAN ¬
TRUE, why:
ROPE ¬
NIL]
RETURNS [];
Controls access by remote clients to the database. If accessible=FALSE then the database can not be accessed through the normal LoganBerry interface, only via this interface; setting accessible=TRUE makes the database commonly available (the normal case). This operation is intended for use by administrators that wish to temporarily remove a database from service. The why parameter is returned to clients as an explanation for DBNotAvailable ERRORs.