WalnutDBOpsImpl.mesa
Copyright © 1985 by Xerox Corporation. All rights reserved.
Willie-Sue, June 13, 1985 2:38:10 pm PDT
Donahue, July 17, 1985 3:36:08 pm PDT
Contents: types and procedures dealing with the Walnut message database
Initiated by Willie-Sue, September 24, 1984
Last Edited by: Willie-Sue, January 9, 1985 11:17:16 am PST
Last Edited by: Donahue, December 11, 1984 7:50:08 pm PST
DIRECTORY
BasicTime USING [GMT],
DB USING [Aborted, Error, Failure, InternalError,
Attribute, AttributeValueList, Entity, GMT, Relship, RelshipSet, Value,
DeclareEntity, DeclareRelship, GetF, GetSegmentInfo, Null, SetF,
S2V, V2B, V2I, V2S, V2T],
DBEnvironment USING [ErrorCode],
IO,
RefTab USING [Ref],
Rope,
WalnutDB USING [],
WalnutDefs USING [Error, MsgSet, Segment],
WalnutDBInternal USING [],
WalnutRoot USING [StatsReport],
WalnutSchema;
WalnutDBOpsImpl: CEDAR PROGRAM
IMPORTS
DB, IO,
WalnutDefs, WalnutRoot, WalnutSchema
EXPORTS WalnutDB, WalnutDBInternal =
BEGIN OPEN WalnutSchema;
Types
GMT: TYPE = BasicTime.GMT;
ROPE: TYPE = Rope.ROPE;
MsgSet: TYPE = WalnutDefs.MsgSet;
Entity: TYPE = DB.Entity;
Relship: TYPE = DB.Relship;
RelshipSet: TYPE = DB.RelshipSet;
Public Variables
walnutSegment: PUBLIC ATOM ← $Walnut;
activeMsgSet: PUBLIC MsgSet ← ["Active", -1];
deletedMsgSet: PUBLIC MsgSet ← ["Deleted", -1];
activeMessageSet: PUBLIC DB.Entity;
deletedMessageSet: PUBLIC DB.Entity;
msgSetsTable: PUBLIC RefTab.Ref ← NIL;
Variables
DBBoolValue: REF BOOLNEW[BOOL];
DBIntValue: REF INTNEW[INT];
DBGmtValue: REF DB.GMTNEW[DB.GMT];
Database initialization
DeclareDB: PUBLIC PROC[segment: WalnutDefs.Segment, readOnly: BOOL] = {
walnutSegment ← segment;
msgSetsTable ← NIL;
CheckSchema[segment, readOnly];
};
CheckSchema: PUBLIC PROC[segment: WalnutDefs.Segment, readOnly: BOOL] = {
IF DB.Null[WalnutSchema.MsgDomain] THEN {
IF readOnly THEN WalnutSchema.Initialize[segment, OldOnly]
ELSE WalnutSchema.Initialize[segment];
activeMessageSet ← DB.DeclareEntity[MsgSetDomain, activeMsgSet.name];
deletedMessageSet ← DB.DeclareEntity[MsgSetDomain, deletedMsgSet.name];
};
};
InitSchema: PUBLIC PROC[segment: WalnutDefs.Segment] = {
walnutSegment ← segment;
msgSetsTable ← NIL;
WalnutSchema.SetSchemaVersion[walnutSegment];
CheckSchema[segment, FALSE]
};
Global Values
IsReadOnly: PUBLIC PROC RETURNS[readonly: BOOL] =
{ readonly← DB.GetSegmentInfo[walnutSegment].readOnly };
GetDBName: PUBLIC PROC RETURNS[fileName: ROPE] =
{ fileName← DB.GetSegmentInfo[walnutSegment].filePath };
GetRootInfo: PUBLIC PROC RETURNS[rootFileStamp: GMT, rootFileKey, mailFor: ROPE] = {
Gri: PROC = {
rootFileStamp ← DB.V2T[DB.GetF[rRootInfo, gRootFileStamp]];
rootFileKey ← DB.V2S[DB.GetF[rRootInfo, gRootFileKey]];
mailFor ← DB.V2S[DB.GetF[rRootInfo, gMailFor]];
};
CarefullyApply[Gri];
};
SetRootInfo: PUBLIC PROC[rootFileStamp: GMT, rootFileKey, mailFor: ROPE] = {
Sri: PROC = {
DBGmtValue^ ← [rootFileStamp];
DB.SetF[rRootInfo, gRootFileStamp, DBGmtValue];
DB.SetF[rRootInfo, gRootFileKey, DB.S2V[rootFileKey]];
DB.SetF[rRootInfo, gMailFor, DB.S2V[mailFor]];
};
CarefullyApply[Sri];
};
GetRootFileVersion: PUBLIC PROC RETURNS[rootFileStamp: GMT] = {
Gri: PROC = {
rootFileStamp ← DB.V2T[DB.GetF[rRootInfo, gRootFileStamp]];
};
CarefullyApply[Gri];
};
SetRootFileVersion: PUBLIC PROC[rootFileStamp: GMT] = {
Sri: PROC = {
DBGmtValue^ ← [rootFileStamp];
DB.SetF[rRootInfo, gRootFileStamp, DBGmtValue];
};
CarefullyApply[Sri];
};
GetOpInProgressPos: PUBLIC PROC RETURNS[inProgressPos: INT] = {
Goip: PROC =
{ inProgressPos← DB.V2I[DB.GetF[rLogInfo, gOpInProgressPos]] };
CarefullyApply[Goip];
};
SetOpInProgressPos: PUBLIC PROC[inProgressPos: INT] = {
Siop: PROC = {
DBIntValue^ ← inProgressPos;
DB.SetF[rLogInfo, gOpInProgressPos, DBIntValue];
};
CarefullyApply[Siop];
};
GetParseLogInProgress: PUBLIC PROC RETURNS[inProgress: BOOL] = {
Gplp: PROC =
{ inProgress← DB.V2B[DB.GetF[rParseLogInfo, gParseLogInProgress]] };
CarefullyApply[Gplp];
};
SetParseLogInProgress: PUBLIC PROC[inProgress: BOOL] = {
Splp: PROC = {
DBBoolValue^ ← inProgress;
DB.SetF[rParseLogInfo, gParseLogInProgress, DBBoolValue];
};
CarefullyApply[Splp];
};
GetParseLogPos: PUBLIC PROC RETURNS[pos: INT] = {
Gplp: PROC =
{ pos ← DB.V2I[DB.GetF[rParseLogInfo, gParseLogPos]] };
CarefullyApply[Gplp];
};
SetParseLogPos: PUBLIC PROC[pos: INT] = {
Splp: PROC = {
DBIntValue^ ← pos;
DB.SetF[rParseLogInfo, gParseLogPos, DBIntValue];
};
CarefullyApply[Splp];
};
Exported to WalnutDBInternal
CarefullyApply: PUBLIC PROC [proc: PROC[]] = {
exp: ROPE;
eCode: ATOM;
BEGIN ENABLE BEGIN
DB.Error => { eCode ← $DBError; exp ← RopeForDBError[code]; GOTO Quit};
DB.Failure => { eCode ← $DBFailure; exp ← info; GOTO Quit};
DB.Aborted => { eCode ← $TransactionAbort; GOTO Quit };
DB.InternalError => { eCode ← $DBInternalError; GOTO Quit };
END;
proc[];
EXITS
Quit => {
WalnutRoot.StatsReport[IO.PutFR["\n ***DB error - code: %g, exp: %g ",
IO.atom[eCode], IO.rope[exp]]];
ERROR WalnutDefs.Error[$db, eCode, exp];
};
END;
};
GetMsgDisplayInfo: PUBLIC PROC[m: Entity]
RETURNS[hasBeenRead: BOOL, tocEntry: ROPE, startOfSubject: INT] = {
rel: Relship = DB.DeclareRelship[mDisplayInfo, LIST[[mDIOf, m]]];
hasBeenRead← DB.V2B[DB.GetF[rel, mDIHasBeenRead]];
tocEntry← DB.V2S[DB.GetF[rel, mDITOCEntry]];
startOfSubject← DB.V2I[DB.GetF[rel, mDIStartOfSubject]];
};
ChangeCountInMsgSet: PUBLIC PROC[ms: Entity, inc: INT] = {
rel: Relship ← DB.DeclareRelship[msBasicInfo, LIST[[msBIOf, ms]]];
DBIntValue^ ← DB.V2I[DB.GetF[rel, msBICount]] + inc;
DB.SetF[rel, msBICount, DBIntValue];
DBIntValue^ ← DB.V2I[DB.GetF[rel, msBIVersion]] + 1;
DB.SetF[rel, msBIVersion, DBIntValue];
};
ChangeCountOfMsgs: PUBLIC PROC[delta: INT] = {
numNow: INT DB.V2I[DB.GetF[rVersionInfo, gMsgCount]];
DBIntValue^ ← numNow + delta;
DB.SetF[rVersionInfo, gMsgCount, DBIntValue];
};
Internal procedures
RopeForDBError: PROC[code: DBEnvironment.ErrorCode] RETURNS[ROPE] = {
SELECT code FROM
AlreadyExists => RETURN["AlreadyExists"];
IllegalAttribute => RETURN["IllegalAttribute"];
IllegalDomain => RETURN["IllegalDomain"];
IllegalEntity => RETURN["IllegalEntity"];
IllegalRelship => RETURN["IllegalRelship"];
IllegalRelation => RETURN["IllegalRelation"];
IllegalString => RETURN["IllegalString"];
IllegalValue => RETURN["IllegalValue"];
IllegalValueType => RETURN["IllegalValueType"];
MismatchedProperty => RETURN["MismatchedProperty"];
MismatchedAttributeValueType => RETURN["MismatchedAttributeValueType"];
MismatchedExistingAttribute => RETURN["MismatchedExistingAttribute"];
MismatchedPropertyCardinality => RETURN["MismatchedPropertyCardinality"];
MultipleMatch => RETURN["MultipleMatch"];
NILArgument => RETURN["NILArgument"];
NullifiedArgument => RETURN["NullifiedArgument"];
NotFound => RETURN["NotFound"];
TransactionNotOpen => RETURN["TransactionNotOpen"];
TransactionAlreadyOpen => RETURN["TransactionAlreadyOpen"];
QuotaExceeded => RETURN["QuotaExceeded"];
Unknown => RETURN["Unknown"];
ENDCASE => RETURN["Other Error"];
};
END.