LoganQuery.mesa
Copyright © 1985 by Xerox Corporation. All rights reserved.
Doug Terry, November 26, 1985 4:12:52 pm PST
LoganQuery allows more complicated queries to be performed on a LoganBerry database than the simple retrievals provided by the LoganBerry interface. Database queries of various classes can be registered; retrieval operations are class-specific. For instance, the $Filter class returns database entries that match a particular pattern, while the $Merger class merges the entries returned by two independent queries. Filters can be cascaded to perform multiple-attribute queries. The predefined $Simple class permits operations identical to those provided by LoganBerry. Clients are free to create their own class of queries.
DIRECTORY
RefID USING [ID, nullID],
Rope USING [ROPE],
LoganBerry;
LoganQuery: CEDAR DEFINITIONS
~
BEGIN
ROPE: TYPE ~ Rope.ROPE;
Query classes
QueryClass: TYPE = REF QueryClassRec;
QueryClassRec:
TYPE =
RECORD [
flavor: ATOM ← NIL, -- name of cursor's class
retrieve: RetrieveProc ← NIL, -- get next database entry
destroy: DestroyProc ← NIL -- end the query (and destroy the cursor)
];
RetrieveProc:
TYPE =
PROC [cursor: ComplexCursor, dir: CursorDirection ← increasing]
RETURNS [entry: LoganBerry.Entry];
Retrieves the next database entry in a manner particular to the class of query.
DestroyProc:
TYPE =
PROC [cursor: ComplexCursor]
RETURNS [];
Destroys the given cursor and any embedded cursors.
ComplexCursor type
ComplexCursor:
TYPE =
RECORD [
class: QueryClass ← NIL, -- name of cursor's class
data: RefID.ID ← RefID.nullID -- data slot for cursor class implementor
];
CursorDirection: TYPE = LoganBerry.CursorDirection;
Basic operations
ComplexCursor creation is a class-specific operation.
The following operations are syntactically identical and semantically similar to those provided by LoganBerry. Any errors raised by these operations are generated by LoganBerry.
NextEntry:
PROC [cursor: ComplexCursor, dir: CursorDirection ← increasing]
RETURNS [entry: LoganBerry.Entry];
Retrieves the next entry relative to the given cursor. 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: IndexNotOpen, BadIndex, LogNotOpen, BadLogEntry
EndGenerate:
PROC [cursor: ComplexCursor]
RETURNS [];
Releases the cursor; no further operations may be performed using the given cursor. This must be called once for every cursor created.
Predefined query classes
$Simple
GenerateEntries:
PROC [db: LoganBerry.OpenDB, key: LoganBerry.AttributeType, start: LoganBerry.AttributeValue ←
NIL, end: LoganBerry.AttributeValue ←
NIL]
RETURNS [cursor: ComplexCursor];
Identical to the GenerateEntries operation provided by LoganBerry but returns a ComplexCursor with class=$Simple and data=LoganBerry.Cursor.
Errors: LoganBerry.NoIndex
$Filter
FilterEntries:
PROC [input: ComplexCursor, pattern:
ROPE, filter: FilterProc, atype: LoganBerry.AttributeType, stopIfNothingGreater:
BOOLEAN ←
FALSE]
RETURNS [output: ComplexCursor];
Returns a ComplexCursor of class $Filter. Retrievals using this new cursor apply the given pattern-matching filter to the appropriate attribute of entries identified by the input cursor. A retrieval returns NIL if the input is exhausted or stopIfNothingGreater=TRUE and the filter procedure returns nothingGreater=TRUE.
FilterProc:
TYPE =
PROC [value:
ROPE, pattern:
ROPE]
RETURNS [match:
BOOLEAN, nothingGreater:
BOOLEAN ← FALSE];
Compares the presented value to the pattern; match indicates the result of the comparison. If nothingGreater=TRUE then no value greater than or equal to the presented value could possibly match the pattern; nothingGreater=FALSE implies nothing about future comparisons.
$Merger
MergeEntries:
PROC [input1, input2: ComplexCursor
, atype: LoganBerry.AttributeType]
RETURNS [output: ComplexCursor];
Returns a ComplexCursor of class $Merger. Retrievals using this new cursor merge the two input streams. The input streams should be ordered by the given attribute type. A retrieval returns NIL only when both inputs are exhausted.
Predefined filters
Equal: FilterProc
;
Compares the value and pattern for equality.
Prefix: FilterProc;
Checks if the pattern is a prefix of the value. Prefix[v, "p"] is the same as Wildcard[v, "p*"], though faster.
Wildcard: FilterProc
;
The pattern may contain zero or more wildcards (the character "*") that match anything.
RE: FilterProc
;
The pattern is taken to be a regular expression as defined in RegularExpressionDoc.tioga.
Soundex: FilterProc
;
Compares the value and pattern based on their Soundex codes. The Soundex encoding tends to group together variants of the same name; for instance, Johnson, Jansen, and Johansen have identical Soundex codes.
END.
Doug Terry November 6, 1985 9:55:44 am PST
created
Doug Terry, November 6, 1985 5:15:27 pm PST
changes to: DIRECTORY, ILQuery, ~, Cursor, CursorDirection, CursorClass, CursorClassRec, RetrieveProc, DestroyProc, NextEntry, EndGenerate, GenerateEntries, FilterEntries, MatchResult, FilterProc, MergeEntries
Doug Terry, November 7, 1985 2:59:51 pm PST
changes to: ~, QueryClass, QueryClassRec, ComplexCursor, RetrieveProc, DestroyProc, FilterEntries, FilterProc, MergeEntries, Equal, Prefix, Wildcard, RegularExpression, Soundex, DIRECTORY, NextEntry
Doug Terry, November 26, 1985 4:12:52 pm PST
changes to: DIRECTORY, LoganQuery, RetrieveProc, CursorDirection, NextEntry, GenerateEntries, FilterEntries, MergeEntries