LoganBerryToolsDoc.tioga
Doug Terry, November 24, 1986 7:44:58 pm PST
LOGANBERRY TOOLS
CEDAR 6.1 — FOR INTERNAL XEROX USE ONLY
LoganBerry Tools
Doug Terry
© Copyright 1985 Xerox Corporation. All rights reserved.
Abstract: LoganBerry is a simple facility for managing databases. LoganBerry tools include LoganBerryStub, a package that handles interactions with local and/or remote LoganBerry servers, LoganQuery, which allows complex queries to be formulated such as those involving filters and mergers, LoganBerryCommands for invoking operations from a CommandTool, and the LoganBerry Browser, which permits one to browse (and update) a LoganBerry database interactively.
Created by: Doug Terry
Maintained by: Doug Terry <Terry.pa>
Keywords: database, servers, RPC, queries, browsing
XEROX  Xerox Corporation
   Palo Alto Research Center
   3333 Coyote Hill Road
   Palo Alto, California 94304

For Internal Xerox Use Only
Introduction
LoganBerry tools include LoganBerryStub, a package that handles interactions with local and/or remote LoganBerry database servers, LoganQuery, which allows complex queries to be formulated such as those involving filters and mergers, LoganBerryCommands for invoking operations from a CommandTool, and the LoganBerry Browser, which permits one to browse (and update) a LoganBerry database interactively. Each of these is described in more detail in the following sections.
To use any of these facilities, bringover [Cedar]<CedarChest®>Top>LoganBerryTools.df. For more information on the LoganBerry data management system, see LoganBerryDoc.Tioga.
LoganBerryStub
Functionality
LoganBerryStub provides easy access to local or remote LoganBerry database servers. It attempts to hide any RPC details. That is, it (1) catches RPC failures and attempts to either recover or turn them into LoganBerry errors, (2) imports RPC interfaces from multiple servers on demand, (3) uses secure RPC conversations, and (4) tries to keep LoganBerry databases open.
The interface is identical to LoganBerry.mesa. Any LoganBerry application should be able to change its imports statement to:
IMPORTS LoganBerry: LoganBerryStub;
and everything should continue to work. The major difference is that the application can now access remote databases as well as local ones.
Convention for naming remote databases
The server portion of the database name is taken to be the instance under which the remote LoganBerry server has exported its LoganBerry interface. For example,
LoganBerryStub.Open["/Strowger.lark//Database.schema"];
attempts to set up an RPC connection with Strowger.lark and open a database named "///Database.schema" on that server.
LoganQuery
Summary
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 (see LoganBerryBrowser.FilteredQuery). The predefined $Simple class permits operations identical to those provided by LoganBerry. Clients are free to create their own class of queries.
Operations
Two operations are generic to all query classes. These operations are syntactically identical and semantically similar to those provided by LoganBerry, except that they operate on "complex cursors" instead of LoganBerry's simple cursors:
NextEntry: 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.
EndGenerate: 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
The creation of complex cursors is a class-specific operation. Clients are free to introduce new query classes and operations for generating cursors of those classes. LoganQuery.mesa defines the following operations to generate cursors of class $Simple, $Filter, or $Merger:
GenerateEntries: Identical to the GenerateEntries operation provided by LoganBerry but returns a ComplexCursor with class=$Simple and data=LoganBerry.Cursor.
FilterEntries: 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.
MergeEntries: 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
The $Filter class uses pattern-matching filters that compare the value of some LoganBerry attribute against a pattern. For convenience, LoganQuery.mesa defines the following types of filters:
Equal: Compares the value and pattern for equality.
Prefix: Checks if the pattern is a prefix of the value. Prefix[v, "p"] is the same as Wildcard[v, "p*"], though faster.
Wildcard: The pattern may contain zero or more wildcards (the character "*") that match anything.
RE: The pattern is taken to be a regular expression as defined in RegularExpressionDoc.tioga.
Soundex: 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.
LoganBerry Browser
Basics
A tool exists for interactively browsing and updating LoganBerry databases. Think of the browser as a convenient way of performing LoganBerry commands. To run the browser, type:
Bringover -p /Cedar/CedarChest®/Top/LoganBerryTools.df
LoganBerryBrowser some-database-schema-name
The convention for naming databases is the same as that used by LoganBerryStub (see above); both local and remote databases may be browsed concurrently. The browser reads the database schema to discover what indices exist for the database. It then builds an input form in which values for the various attribute keys can be entered. These values are treated as patterns against which database entries are compared.
For example, LoganBerryTools.df contains SampleDB.df, the schema for a sample database storing names and phone numbers. Typing "LoganBerryBrowser SampleDB.df" produces a viewer that looks something like the following:
[Artwork node; type 'ArtworkInterpress on' to command tool]
User interface
The browser has several areas or subviewers. At the very top is the caption indicating the name of the database being browsed. Right below this is a menu with one or two lines (the display of the second line is controlled by the "AdminOps" button). The function of each menu button is explained in the next section.
Below the menu is the input form. Each line of the input form allows the user to type in a pattern for a given attribute. For instance, the browser tool shown above has an input form with two attributes: "Name" and "Phone". There may be some painting problems remaining in the browser. If what you type is not being displayed, make the browser iconic and then reopen it and the problem should go away (hopefully).
Preceding each attribute name on the input form is a choice button that allows the user to select what pattern matching is too be applied to the attribute value. Clicking on this choice button cycles through the various options (see the section on pattern-matching options below).
The last line of the input form is a text viewer with the label "other attributes:". This is used to type in values for attributes that are not keys of the database. The input syntax is identical to the attribute-pattern specifications that may be typed into a CommandTool (see below).
Below the input form is another choice button that allows users to select on which attribute the output should be ordered. (To speed up queries it is best to order the output on some attribute that has a well-specified pattern.) The pattern-selection and order-by choice buttons comprise the details subviewer.
The history window optionally resides below the input form and details subviewer (it is not shown in the browser above). Whether or not it is currently displayed is governed by the "History" menu button. This area contains a list of the operations that have been executed in the past; these operations are given in a format that could be typed into a CommandTool to get identical results (except the database name is omitted). Clicking on one of these "history commands" fills in the input form with the values that previously existed and also sets the previous details. Thus, a query can be re-executed by selecting a line in the history window and clicking "Browse" again. The user is also free to change any of the values once they are refreshed.
At the bottom of the browser tool is the output area where the results of queries are displayed. This area is scrollable.
Menu buttons
The LoganBerry Browser Tool displays the following menu buttons:
STOP!: terminates a currently executing database query.
Browse: initiates a database query to retrieve all entries matching the input form. That is all database entries whose attribute values match the corresponding pattern in the input form (according to the selected pattern matching style) are displayed in the output area of the browser. (Same as LBQuery.)
Update: writes a database entry consisting of all the non-null values in the input form. (Same as LBWrite.)
Delete: initiates a database query to retrieve all entries matching the input form; then deletes all of these entries. (Same as LBDelete.)
UnDelete: rewrites all of the entries deleted by the last "Delete" operation.
History: toggles whether or not the history of past queries is displayed.
Details: toggles whether or not the details that govern how a query is performed are displayed.
AdminOps: displays (or hides) a second menu line that contains buttons for performing administrative operations on the database.
The second menu line offers the following buttons (intended mostly for advanced users):
Open: opens the database. (This is automatically done when the browser is created and on every browse operation; thus a user should never have to use this button).
Close: closes the database and its associated files. (Same as LBClose.)
BuildIndices: rebuilds the database indices. (Same as LBBuildIndices.)
CompactLogs: compacts the database logs. (Same as LBCompactLogs.)
Pattern-matching options
The following assortment of pattern matching may be selected on the browser's input form:
exact: values must match exactly;
prefix: the pattern must be a prefix of the database entry's attribute value;
wildcard: the pattern may contain zero or more wildcards (the character "*") that match anything;
regular expression: the pattern is taken to be a regular expression as defined in RegularExpressionDoc.tioga;
soundex: the form value's Soundex code is compared with that of a database entry's attribute value, i.e. values match if they "sound" alike; for instance, Johnson, Jansen, and Johansen have identical Soundex codes.
subrange: the pattern is taken to be two strings (or rope literals) separated by a dash, e.g. "beginning-end"; a match occurs on a database entry's attribute value if beginningdvaluedend in lexicographic ordering or prefix(value)=end.
numrange: the pattern should consist of two positive integers separated by a dash. e.g. "18-21"; a match occurs if the value is in the numerical range specified by the pattern.
daterange: the pattern should consist of two date and times (as can be parsed by Tempus) separated by a dash, e.g. "today at noon-doomsday"; a match occurs if the value is in the chronological range specified by the pattern.
date: the pattern, as well as the value, should be a date and time (as can be parsed by Tempus); the value and pattern match if they represent the same time within the precision of the pattern. Note: A match can not occur unless the pattern is no more precise than the value. For example, a pattern of "Wednesday" will match a value of "Wednesday at 2 pm", but not vice versa.
DWIM: the browser attempts to deduce an appropriate filter type from the given pattern. The logic is as follows:
pattern-matching ←
IF pattern contains a dash THEN
IF start and end are integers THEN "numrange"
ELSE IF start and end are dates THEN "daterange"
ELSE "subrange"
ELSE
IF pattern contains a * THEN "wildcard"
ELSE IF pattern is a date then "date"
ELSE "prefix"
Warning: The "numrange", "daterange", and "date" pattern-matching filters are problematic since they assert that the attributes in the database are of a certain type other then simply ropes. The LoganBerry data management system treats all attribute values as ropes and does not enforce any constraints on the these values. If the browser encounters an attribute value that can not be converted to the type desired by the filter, then the entry is deemed to not match. Also, the "DWIM" option has the obvious problem that its semantics are not easy to predict or determine. For these reasons. "numrange", "daterange", "date", and "DWIM" are provided on an experimental basis only and should be used with caution.
Programmers' interface
LoganBerryBrowser.mesa provides a programmer's interface to some of the useful utilities used by the Browser, such as FilteredQuery; see the interface for details. It also allows one to create a LoganBerry Browser that will call a client-given procedure for handling entries retrieved by the browser.
LoganBerry Commands
Overview
Several commands are available for invoking operations on a LoganBerry database from a CommandTool. These commands are registered by the LoganBerryTools.load file.
All of the LoganBerry CommandTool commands have a similar syntax, "<cmdname> <dbname> <attributes>", a command name followed by a database name followed by zero or more attribute-pattern specifications. The database name may be for a remote database, see "Convention for naming remote databases", or may be the special name "#", which is a shorthand notation for the last database name given.
An attribute-pattern specification is of the form: "<attribute-type>(<pattern>): <attribute-value>". The attribute value may be either a token or a rope literal. The currently supported types of patterns include "exact", "prefix", "wildcard", "re", and "soundex" (see above for a description of these patterns). The pattern, along with its surrounding parenthesis, is optional. A missing pattern defaults to "exact".
name LBQuery:
syntax
LBQuery dbname attributes
description
Retrieves entries in the LoganBerry database that match the attribute patterns.
examples
retrieve all database entries for "John"s whose phone number ends in "4427":
% LBQuery testdb.schema Integer(prefix): 1 Rope(wildcard): *ten*
Integer: 10
Rope: ten

Integer: 110
Rope: one hundred ten
stop/undo
STOP! halts the query.
name LBRead:
syntax
LBRead dbname attributes
description
Synonym for LBQuery.
name LBWrite:
syntax
LBWrite dbname attributes
description
Writes an entry into the LoganBerry database. Any patterns given with the list of attributes are ignored.
examples
% LBWrite # Integer: -10 Rope: "minus ten"
name LBDelete:
syntax
LBDelete dbname attributes
description
Deletes all entries in the LoganBerry database that match the attribute patterns.
examples
% LBDelete # Integer: -10 Rope: "minus ten"
Deleted Integer: -10
warnings
This operation could delete many database entries so be careful!
stop/undo
STOP! halts the delete operation; there is no undo facility.
name LBDescribe:
syntax
LBDescribe dbname
description
Get schema information about a LoganBerry database. Returns a list of the keys, indices, and logs.
examples
% LBDescribe #
Database: []<>Users>Terry.pa>LoganBerry>testdb.schema!1
keys: Integer Rope
index files: []<>Users>Terry.pa>LoganBerry>Integer.index
[]<>Users>Terry.pa>LoganBerry>Rope.index
log files: []<>Users>Terry.pa>LoganBerry>TestDB.log
name LBClose:
syntax
LBClose dbname
description
Close a LoganBerry database. (You may want to do this to release the write locks on the log files, for instance.)
examples
% LBClose #
name LBBuildIndices:
syntax
LBBuildIndices dbname
description
Rebuild the indices for a LoganBerry database.
examples
% LBBuildIndices #
stop/undo
You can not stop this operation once it starts. It could take awhile for a large database.
name LBCompactLogs:
syntax
LBCompactLogs dbname
description
Compact a LoganBerry database.
examples
% LBCompactLogs #
stop/undo
You can not stop this operation once it starts. It could take awhile for a large database.
name LBBrowser or LoganBerryBrowser:
syntax
LBBrowser dbname
description
Creates a tool to browse the given LoganBerry database.
examples
% LBBrowser SampleDB.df