WalnutSchemaImpl.mesa
Copyright © 1984 by Xerox Corporation. All rights reserved.
Willie-Sue, June 11, 1985 2:14:03 pm PDT
Types and entities in the Walnut message database
Last Edited by: Willie-Sue, January 4, 1985 9:05:15 am PST
Last Edited by: Wert, August 31, 1984 7:38:03 pm PDT
Last Edited by: Donahue, February 2, 1985 9:37:11 am PST
(Added NewMail and Archive log position info for restart)
(Changed to be consistent with new WalnutSchema)
DIRECTORY
BasicTime USING [GMT, nullGMT, OutOfRange],
Convert USING [TimeFromRope],
DB USING [Error, Attribute, BoolType, DeclareAttribute, DeclareDomain, DeclareIndex, DeclareRelation, DeclareRelship, Domain, GetF, GMT, IntType, NextRelship, Null, Relation, RelationSubset, ReleaseRelshipSet, Relship, RelshipSet, RopeType, SetF, T2V, TimeType, V2T, Version],
IO,
Rope USING [ROPE, Cat],
WalnutDefs USING [SchemaMismatch, Segment],
WalnutRoot USING [CommitAndContinue],
WalnutSchema USING [],
WalnutSchemaInternal USING [InitializeGlobals];
WalnutSchemaImpl: CEDAR PROGRAM
IMPORTS
Convert, DB, IO, Rope, WalnutDefs, WalnutRoot, WalnutSchemaInternal
EXPORTS
WalnutSchema
= BEGIN
OPEN DB, WalnutSchema;
Types
GMT: TYPE = BasicTime.GMT;
ROPE: TYPE = Rope.ROPE;
Variables
schemaVersionDate: GMT = Convert.TimeFromRope["April 30, 1985 10:25:43 am PDT"];
(The rest of the) Schema Variables - relations and Global Domains
Global Domains
MsgDomain: PUBLIC Domain;
MsgSetDomain: PUBLIC Domain;
ServerDomain: PUBLIC Domain;
Global Relations - one each per database
gSchemaDateInfo: PUBLIC Relation;
gSVDate: PUBLIC Attribute;   -- time (of schema definition)
Server entity Relation
sBasicInfo: PUBLIC Relation;    -- One per Server
sBIOf: PUBLIC Attribute;     -- Server
sBINum: PUBLIC Attribute;     -- int (number of messages, -1 if error)
MsgSet entity Relation
msBasicInfo: PUBLIC Relation;    -- One per MsgSet
msBIOf: PUBLIC Attribute;      -- MsgSet
msBICount: PUBLIC Attribute;     -- int (number of messages in set)
msBIVersion: PUBLIC Attribute;    -- int
Msg displaying Relation
mTextInfo: PUBLIC Relation;   -- One per Msg
mTIOf: PUBLIC Attribute;      -- Msg
mTIHerald: PUBLIC Attribute;    -- rope
mTIShortNameLen: PUBLIC Attribute;  -- int (for icon label, other uses)
mTIEntryStart: PUBLIC Attribute;   -- int (start of entry in log)
mTITextOffset: PUBLIC Attribute;   -- int (offset for text)
mTITextLen: PUBLIC Attribute;   -- int (length of text)
mTIFormatLen: PUBLIC Attribute;   -- int (length of formatting)
Msg in MsgSet displayer relation
mDisplayInfo: PUBLIC Relation;   -- One per Msg
mDIOf: PUBLIC Attribute;      -- Msg
mDITOCEntry: PUBLIC Attribute;   -- rope
mDIStartOfSubject: PUBLIC Attribute;  -- int
mDIHasBeenRead: PUBLIC Attribute;  -- bool
Msg Date/Show relation
mInfo: PUBLIC Relation;    -- One per Msg
mInfoOf: PUBLIC Attribute;    -- Msg
mDateIs: PUBLIC Attribute;    -- time
mShowIs: PUBLIC Attribute;   -- bool
Msg accepted relation
mAcceptedInfo: PUBLIC Relation;   -- One per Msg
mAcceptedOf: PUBLIC Attribute;   -- Msg
mAcceptedIs: PUBLIC Attribute;  -- want bool, must use int
Category/Date Relation
cdRelation: PUBLIC Relation;    -- One per Msg / MsgSet pair
cdMsg: PUBLIC Attribute;      -- Msg
cdMsgSet: PUBLIC Attribute;     -- MsgSet
cdDate: PUBLIC Attribute;      -- time
Procedures
Initialize: PUBLIC PROC [segment: WalnutDefs.Segment, version: Version ← NewOrOld] = {
This procedure initializes the database schema, and commits it to the database.
Errors from Cypress (?).
DO
BEGIN ENABLE DB.Error => GOTO badSchema;
date: BasicTime.GMT;
gSchemaDateInfo: Relation;
gSVDate: Attribute;
schemaRelship: Relship;
-- Define the Schema Info relation
gSchemaDateInfo ← DeclareRelation["gSchemaDateInfo", segment, OldOnly];
IF DB.Null[gSchemaDateInfo] THEN
ERROR WalnutDefs.SchemaMismatch["SchemaDateInfo doesn't exist"];
-- Schema Version
gSVDate ← DeclareAttribute[gSchemaDateInfo, "SVDate", TimeType, , , , version];
schemaRelship ← DeclareGlobalRelship[gSchemaDateInfo, version];
-- Check the Schema Version attribute
date ← V2T[GetF[schemaRelship, gSVDate]];
IF date = BasicTime.nullGMT THEN
{ date ← schemaVersionDate;
IF version # OldOnly THEN SetF[schemaRelship, gSVDate, T2V[[date]]];
EXIT
};
IF date = schemaVersionDate THEN EXIT;
ERROR WalnutDefs.SchemaMismatch[TimesToRope[date, schemaVersionDate]];
EXITS
badSchema =>
ERROR WalnutDefs.SchemaMismatch[
TimesToRope[BasicTime.nullGMT, schemaVersionDate]];
END;
ENDLOOP;
WalnutSchemaInternal.InitializeGlobals[segment, version];
-- Define the Global Domains
MsgDomain ← DeclareDomain["Msg", segment, version, 2];
MsgSetDomain ← DeclareDomain["MsgSet", segment, version, 2];
ServerDomain ← DeclareDomain["Server", segment, version, 1];
-- Define the Server Info Relation
sBasicInfo ← DeclareRelation["sBasicInfo", segment, version];
sBIOf ← DeclareAttribute[sBasicInfo, "of", ServerDomain, Key, , , version];
sBINum ← DeclareAttribute[sBasicInfo, "Num", IntType, , , , version];
-- Define the Walnut MsgSet Info Relation
msBasicInfo ← DeclareRelation["msBasicInfo", segment, version];
msBIOf ← DeclareAttribute[msBasicInfo, "of", MsgSetDomain, Key, , , version];
msBICount ← DeclareAttribute[msBasicInfo, "count", IntType, None, , , version];
msBIVersion ← DeclareAttribute[msBasicInfo, "version", IntType, None, , , version];
-- Define the Walnut Msg DisplayInfo Relation
mTextInfo ← DeclareRelation["mTextInfo", segment, version];
mTIOf ← DeclareAttribute[mTextInfo, "of", MsgDomain, Key, , , version];
mTIHerald ← DeclareAttribute[mTextInfo, "herald", RopeType, None, 60, , version];
mTIShortNameLen ←
DeclareAttribute[mTextInfo, "shortNameLen", IntType, None, , , version];
mTIEntryStart ← DeclareAttribute[mTextInfo, "entryStart", IntType, None, , , version];
mTITextOffset ← DeclareAttribute[mTextInfo, "textOffset", IntType, None, , , version];
mTITextLen ← DeclareAttribute[mTextInfo, "textLen", IntType, None, , , version];
mTIFormatLen ←
DeclareAttribute[mTextInfo, "formatLen", IntType, None, , , version];
-- Define the Walnut Msg in MsgSet displayer Relation
mDisplayInfo ← DeclareRelation["mDisplayInfo", segment, version];
mDIOf ← DeclareAttribute[mDisplayInfo, "of", MsgDomain, Key, , , version];
mDITOCEntry ←
DeclareAttribute[mDisplayInfo, "tocEntry", RopeType, None, 70, , version];
mDIStartOfSubject ←
DeclareAttribute[mDisplayInfo, "startOfSubject", IntType, None, , , version];
mDIHasBeenRead ←
DeclareAttribute[mDisplayInfo, "hasBeenRead", BoolType, None, , , version];
-- Define the Walnut Msg Date/Accepted Relation
mInfo ← DeclareRelation["mInfo", segment, version];
mInfoOf ← DeclareAttribute[mInfo, "of", MsgDomain, Key, , , version];
mDateIs ← DeclareAttribute[mInfo, "date", TimeType, None, , , version];
mShowIs ← DeclareAttribute[mInfo, "Show", BoolType, None, , , version];
-- Define the Walnut Category/Date Relation
cdRelation ← DeclareRelation["cdRelation", segment, version];
cdMsg ← DeclareAttribute[cdRelation, "msg", MsgDomain, None, , , version];
cdMsgSet ←
DeclareAttribute[cdRelation, "msgSet", MsgSetDomain, None, , , version];
cdDate ← DeclareAttribute[cdRelation, "date", TimeType, None, , , version];
-- Define the indicies
[] ← DeclareIndex[sBasicInfo, LIST[sBIOf], version];
[] ← DeclareIndex[cdRelation, LIST[cdMsgSet, cdDate], version];
-- Commit what we've done
WalnutRoot.CommitAndContinue[];
};
SetSchemaVersion: PUBLIC PROC[segment: WalnutDefs.Segment] = {
gSchemaDateInfo: Relation;
gSVDate: Attribute;
schemaRelship: Relship;
gSchemaDateInfo ← DB.DeclareRelation["gSchemaDateInfo", segment, NewOnly];
gSVDate ← DB.DeclareAttribute[gSchemaDateInfo, "SVDate", TimeType, , , , NewOnly];
schemaRelship ← DeclareGlobalRelship[gSchemaDateInfo];
DB.SetF[schemaRelship, gSVDate, T2V[[schemaVersionDate]]];
WalnutRoot.CommitAndContinue[];
};
DeclareGlobalRelship: PROC [r: Relation, version: Version ← NewOrOld]
RETURNS [rel: Relship] = {
rs: RelshipSet ← RelationSubset[r];
rel ← DB.NextRelship[rs];
IF DB.NextRelship[rs] # NIL THEN ERROR;
ReleaseRelshipSet[rs];
IF rel = NIL THEN rel ← DeclareRelship[r, NIL, version];
};
TimesToRope: PROC[is, shouldBe: BasicTime.GMT] RETURNS[ROPE] = {
isR, shouldR: ROPE;
isR ← IO.PutFR[NIL, IO.time[is ! BasicTime.OutOfRange => isR ← "OutOfRange"]];
shouldR ← IO.PutFR[NIL, IO.time[shouldBe ! BasicTime.OutOfRange =>
shouldR ← "OutOfRange"]];
RETURN[Rope.Cat["\nSchema is of: ", isR, " but should be of: ", shouldR]];
};
END.