File: DBNamesImpl.mesa
last edited by:
Cattell, July 5, 1983 5:00 pm
Donahue, July 13, 1984 5:41:40 pm PDT
Willie-sue, February 22, 1983 4:08 pm
DIRECTORY
Atom,
DB,
DBEnvironment,
DBNames,
Rope;
DBNamesImpl: CEDAR PROGRAM
IMPORTS Atom, Rope, DB, DBEnvironment
EXPORTS DBNames =
BEGIN OPEN Rope, DB;
Separator: PUBLIC CHAR ← '#;
Sep: ROPE = Rope.FromChar[Separator];
EntityToName: PUBLIC PROC[e: Entity, seg: DB.Segment] RETURNS[ name: ROPE ] = {
name ← Rope.Cat[DB.GetSegmentInfo[seg].filePath, Sep, Atom.GetPName[seg], Sep];
name ← Rope.Cat[ name, NameOf[DomainOf[e]], Sep, NameOf[e] ] };
MakeName: PUBLIC PROC[seg: DB.Segment, domain, eName: ROPE] RETURNS[name: ROPE] =
{ name ← Rope.Cat[GetSegmentInfo[seg].filePath, Sep, Atom.GetPName[seg], Sep];
name ← Rope.Cat[ name, domain, Sep, eName ] };
NameToEntity: PUBLIC PROC[name: ROPE, create: BOOLFALSE] RETURNS[e: Entity] = {
segName, domainName, entityName: ROPE;
domain: Domain;
segment: DB.Segment;
[segName, domainName, entityName] ← DecomposeName[name];
segment ← Atom.MakeAtom[segName];
check to make sure that this is the right segment for the entity
IF NOT Rope.Equal[DB.GetSegmentInfo[segment].filePath, SegmentOf[name].filePath, FALSE]
THEN RETURN[NIL];
domain ← DeclareDomain[ domainName, segment, Version[OldOnly] !
DBEnvironment.Error => CHECKED { domain ← NIL; CONTINUE } ];
e ← IF domain = NIL THEN NIL
ELSE FetchEntity[ domain, entityName, segment ];
IF e = NIL AND domain # NIL AND create THEN
e ← DeclareEntity[ domain, entityName ! DB.Error => CONTINUE ] };
SegmentOf: PUBLIC PROC[name: ROPE] RETURNS[segment: DB.Segment, filePath: ROPE] = {
segmentName: ROPE;
substrLength: INT ← Rope.Find[name, Sep]; -- always has the length to the next separator
filePath ← Rope.Substr[name, 0, substrLength];
name ← Rope.Replace[name, 0, substrLength+1]; -- make sure to throw away the separator
substrLength ← Rope.Find[name, Sep];
segmentName ← Rope.Substr[name, 0, substrLength];
RETURN[ Atom.MakeAtom[segmentName], filePath ] };
DecomposeName: PUBLIC PROC[name: ROPE] RETURNS[segment, domain, entity: ROPE] =
BEGIN
substrLength: INT ← Rope.Find[name, Sep];
throw away the leading file path information
name ← Rope.Replace[name, 0, substrLength+1];
now get the remaining fields
substrLength ← Rope.Find[name, Sep];
segment ← Rope.Substr[name, 0, substrLength];
name ← Rope.Replace[name, 0, substrLength+1];
substrLength ← Rope.Find[name, Sep];
domain ← Rope.Substr[name, 0, substrLength];
entity ← Rope.Replace[name, 0, substrLength+1]
END;
END. . .