NutOps.mesa
useful database utilities
Implemented by: NutOpsImpl
Created by: Donahue on: January 20, 1983 3:48 pm
last edited by: Donahue, July 16, 1984 2:28:56 pm PDT
Last Edited by: Willie-sue, February 22, 1983 3:44 pm
Last Edited by: Cattell, July 22, 1983 2:59 pm
Last Edited by: Widom, June 15, 1984 8:45:05 am PDT
Last Edited by: Butler, June 26, 1984 4:30:56 pm PDT
DIRECTORY
DB,
Rope USING [ROPE];
NutOps: CEDAR DEFINITIONS =
BEGIN
OPEN DB, Rope;
**********************************************
Handy DB routines, implemented by NutOpsImpl.mesa (no failures or aborts caught in implementations)
**********************************************
IsSystemDomain:PROC[name: Rope.ROPE] RETURNS[BOOLEAN];
IsSystemRelation: PROC[name: Rope.ROPE] RETURNS[BOOLEAN];
IsSystemEntity:PROC[name: Rope.ROPE] RETURNS[BOOLEAN];
AttributesOf:
PROC[r: Relation]
RETURNS[AttributeList];
Returns list of r's attributes
FirstAttributeOf:
PROC[r: Relation]
RETURNS[Attribute];
returns AttributesOf[r].first
EntityValued:
PROC [a: Attribute]
RETURNS[
BOOL];
returns TRUE iff the value stored in attribute a should be an entity
GetUniquenessString:
PROC[a: Attribute]
RETURNS[
ROPE];
returns the uniqueness of a: Key, OptionalKey, etc., as a printable string
RSetSize:
PROC[rs: RelshipSet]
RETURNS[
INT];
returns the length of rs, and does a ReleaseRelshipSet
GetTuples:
PROC[e: Entity, a: Attribute]
RETURNS [tl:
LIST
OF Relship];
returns all the tuples that reference e via attribute a
GetRelation:
PROC[a: Attribute]
RETURNS[r: Relation];
finds a's relation
GetRefAttributes:
PROC[d: Domain]
RETURNS[al:
LIST
OF Attribute];
returns all the attributes that can reference an entity from domain d
RemoveAttribute:
PROC[a: Attribute, al: AttributeList]
RETURNS[AttributeList];
destructively removes a from al
AppendAttributes:
PROC [al1, al2: AttributeList]
RETURNS [al: AttributeList];
destructively appends al1 and al2 and returns the result
***********************************************
Opening segments and transactions for them
***********************************************
SetUpSegment:
PROC[segmentFile:
ROPE, seg:
DB.Segment, number:
NAT← 0, makeReadOnly:
BOOL←
FALSE]
RETURNS [readOnly:
BOOL];
Open a transaction on the given segment, if possible. This procedure may fail by raising DB.Error, DB.Failure or DB.Aborted. It is also idempotent, if a transaction is already open, nothing will be done.
Outcome: TYPE = {success, abort, error, failure};
Do: PROC[proc: PROC[REF ANY], clientData: REF ANY ← NIL] RETURNS [outcome: Outcome];
Evaluates the procedure supplied in an environment where the Aborted, Error and Failed signals that may be raised from DB will be caught and turned into returned values. (This is useful in situations where it is awkward to attempt to recover from a failure.)
TryRestart:
PROC[trans:
DB.Transaction]
RETURNS[success:
BOOL, failureReason:
ATOM];
Attempt to re-open an aborted transaction.
SafeNameOf:
PROC[e: Entity]
RETURNS [s:
ROPE];
Returns DB.NameOf iff e is not NIL, else returns NIL
SafeSegmentOf:
PROC[e: EntityOrRelship]
RETURNS [s: Segment];
Returns DB.SegmentOf iff e is not NIL, else returns NIL
SafeDomainOf:
PROC[e: Entity]
RETURNS [s: Domain];
Returns DB.DomainOf iff e is not NIL, else returns NIL
END.