DIRECTORY DB, IO, Rope, ViewerIO; VLTest1Impl: PROGRAM IMPORTS DB, IO, Rope, ViewerIO = BEGIN OPEN IO, DB; INT: TYPE = LONG INTEGER; tty: IO.STREAM; in: IO.STREAM; mySeg: DB.Segment = $Test; Person, Frog, Thing: Domain; Friend: Relation; friendOf, friendIs: Attribute; Phone: Relation; phoneOf, phoneIs: Attribute; ageProp, heightProp: Attribute; wsh, harry, mark, nori: --Person-- Entity; george: --Frog-- Entity; rock, pebble: --Thing-- Entity; myName: ROPE _ "Rick Cattell"; myExt: REF INT_ NEW[INT _ 4466]; Initialize: PROC = BEGIN tty.Put[rope["Defining data dictionary..."], char[CR]]; Person_ DeclareDomain["Person", mySeg]; Thing_ DeclareDomain["Thing", mySeg]; Frog_ DeclareDomain["Frog", mySeg]; DeclareSubType[of: Thing, is: Person]; DeclareSubType[of: Thing, is: Frog]; ageProp_ DeclareProperty["Age", Thing, IntType, mySeg]; heightProp_ DeclareProperty["Height", Thing, RopeType, mySeg]; Friend_ DeclareRelation["Friend", mySeg]; friendOf_ DeclareAttribute[Friend, "of", Person]; friendIs_ DeclareAttribute[Friend, "is", Person]; Phone_ DeclareRelation["Phone", mySeg]; phoneOf_ DeclareAttribute[Phone, "of", Person]; phoneIs_ DeclareAttribute[Phone, "is", IntType]; []_ DeclareIndex[Phone, LIST[phoneIs], NewOrOld]; END; InsertData: PROC = BEGIN t: Relship; rick: Entity; tty.Put[rope["Creating data..."], char[CR]]; harry_ DeclareEntity[Person, "Harry Q. Bovik"]; mark_ DeclareEntity[Person, "Mark Brown"]; rick_ DeclareEntity[Person, myName]; nori_ DeclareEntity[Person]; ChangeName[nori, "Nori Suzuki"]; []_ SetP[harry, phoneIs, I2V[4999]]; []_ SetP[mark, phoneIs, I2V[4464]]; []_ SetP[nori, phoneIs, I2V[4425]]; []_ SetP[rick, phoneIs, I2V[4466]]; []_ SetP[rick, heightProp, S2V["medium"]]; t_ DeclareRelship[Friend]; SetF[t, friendOf, rick]; SetF[t, friendIs, harry]; []_ DeclareRelship[Friend, LIST[[friendOf, nori], [friendIs, harry]]]; END; InsertMoreData: PROCEDURE = BEGIN t: Relship; rick: Entity; ok: BOOL_ FALSE; tty.Put[rope["\nCreating more data..."], char[CR]]; wsh_ DeclareEntity[Person]; rick_ DeclareEntity[Person, "Rick Cattell", OldOnly]; rock_ DeclareEntity[Thing, "Harry the rock"]; pebble_ DeclareEntity[Thing, "Fred the pebble"]; george_ DeclareEntity[Frog, "George the frog"]; []_ DeclareEntity[Frog, "Larry the frog"]; ChangeName[wsh, "Willie-Sue H"]; []_ SetP[wsh, heightProp, S2V["medium"]]; []_ SetP[mark, heightProp, S2V["taller"]]; []_ SetP[rock, heightProp, S2V["big"]]; []_ SetP[pebble, heightProp, S2V["little"]]; []_ SetP[george, heightProp, S2V["little"]]; t_ DeclareRelship[Friend]; SetF[t, friendOf, rick]; SetF[t, friendIs, george ! DB.Error => TRUSTED {IF code=MismatchedAttributeValueType THEN {ok _ TRUE; CONTINUE}}]; IF NOT ok THEN ERROR; END; DestroySomeData: PROCEDURE = BEGIN flag: BOOL_ FALSE; tty.Put[char[CR], rope["Deleting some data: Rick and all the frogs..."], char[CR]]; DestroyEntity[DeclareEntity[Person, "Rick Cattell", OldOnly]]; DestroyDomain[Frog]; END; PrintPeople: PROC = BEGIN person: -- PersonDomain -- Entity; es: EntitySet; lint: LONG INTEGER; tty.PutF["\nPerson Domain:\n\n"]; tty.Put[rope["Name Phone"], char[CR]]; es_ DomainSubset[Person]; WHILE (person_ NextEntity[es])#NIL DO tty.Put[rope[GetName[person]], char[TAB]]; lint_ V2I[GetP[person, phoneIs]]; tty.Put[int[lint], char[CR]]; ENDLOOP; ReleaseEntitySet[es]; END; PrintEverything: PROCEDURE = BEGIN thing: -- Thing -- Entity; es: EntitySet; r: ROPE; tty.PutF["\nThings:\n\n"]; tty.PutF["Type Name Height\n"]; es_ DomainSubset[Thing]; WHILE (thing_ NextEntity[es])#NIL DO tty.Put[rope[GetName[DomainOf[thing]]], char[TAB]]; tty.Put[rope[GetName[thing]], char[TAB]]; r_ V2S[GetP[thing, heightProp]]; tty.Put[rope[IF r.Length[]=0 THEN "[unknown]" ELSE r], char[CR]]; ENDLOOP; ReleaseEntitySet[es]; END; PrintCSLPhones: PROC = BEGIN rs: RelshipSet; r: Relship; tty.PutF["\nPhone numbers between 4400 and 4499:\n"]; tty.PutF["Name Phone\n"]; rs_ RelationSubset[Phone, LIST[[phoneIs, I2V[4400], I2V[4499]]], Last]; UNTIL (r_ PrevRelship[rs])=NIL DO tty.PutF["%g %g\n", rope[GetFS[r, phoneOf]], rope[GetFS[r, phoneIs]] ]; ENDLOOP; ReleaseRelshipSet[rs]; END; PrintFriends: PROC = BEGIN friendRS: --Friend-- Relship; friendName: --Person-- ROPE; rs: RelshipSet; tty.Put[char[CR], rope["Harry's friends:"], char[CR]]; rs_ RelationSubset[Friend, LIST[[friendIs, harry]]]; WHILE (friendRS_ NextRelship[rs])#NIL DO friendName_ GetFS[friendRS, friendOf]; tty.Put[rope[friendName], rope[" "], char[CR]]; ENDLOOP; ReleaseRelshipSet[rs]; END; DoIt: PROC = { [in, tty]_ ViewerIO.CreateViewerStreams["VLTest1Impl.log"]; tty.PutF["Creating database...\n"]; DB.Initialize[]; DB.DeclareSegment["[Luther.Alpine]Test.segment", mySeg]; DB.EraseSegment[mySeg]; Initialize[]; tty.PutF["Type a character to proceed...\n"]; []_ in.GetChar[]; InsertData[]; PrintPeople[]; PrintCSLPhones[]; PrintFriends[]; InsertMoreData[]; PrintEverything[]; DestroySomeData[]; PrintEverything[]; tty.PutF["\n\nDone.\n"]; CloseTransaction[TransactionOf[mySeg]]; }; DoIt[] END. ØFile: VLTest1Impl.mesa Contents: Simple test program for DBView.mesa Created by: Rick Cattell, 12-Aug-81 Derived from: TLTest1Impl Last Edited by: Cattell, March 25, 1983 3:47 pm Willie-Sue, February 15, 1985 6:27:02 pm PST Declare domains and make Persons and Frogs be subtypes of Things: Declare phone age and height property of Things Declare Friend relation between Persons Declare Phone relation between Persons and integers Data can be assigned with SetP, SetF, or DeclareRelship's initialization list: Create some new entities and fetch old one (rick) Use SetP to assign names and heights Check that Person can't be friend of frog Destroy one person entity and all frog entities Use DomainSubset with no constraints to enumerate all Persons Use DomainSubset to enumerate all Things (includes Frogs and Persons). Print "unknown" if height field is null string. Use RelationSubset to enumerate phones between 4400 and 4500 Use RelationSubset to enumerate friends of Harry ʆ˜Jšœ™Jšœ-™-Jšœ#™#Jšœ™šœ/™/J™,—J˜šÏk ˜ Jšœœ˜J˜—šœ ˜Jšœœœ˜ J˜—Jšœœœœ˜J˜Jšœœœœ˜J˜Jšœœœ˜Jšœœœ˜J˜Jšœœ˜J˜˜J˜—˜J˜—J˜JšœÏc œ˜*Jšœžœ˜Jšœž œ˜Jšœœ˜Jš œœœœœ ˜ J˜šÏn œœ˜Jš˜Jšœ2œ˜7JšœA™AJ˜'J˜%J˜#J˜&J˜$Jšœ/™/J˜7J˜>Jšœ'™'˜)J˜1J˜1—Jšœ3™3˜'J˜/J˜0—Jšœœ˜1Jšœ˜J˜—šŸ œœ˜Jšœ˜Jšœ'œ˜,J˜/J˜*J˜$J˜=JšœN™NJ˜$J˜#J˜#J˜#J˜*J˜MJšœœ'˜FJšœ˜J˜—šŸœ œ˜Jšœœœ˜0Jšœ.œ˜3Jšœ1™1J˜J˜5J˜-J˜0J˜/J˜*Jšœ$™$J˜ J˜)J˜*J˜'J˜,J˜,Jšœ)™)J˜J˜šœœ ˜&Jš œœ#œœœ˜K—Jšœœœœ˜Jšœ˜J˜—šŸœ œ˜Jšœ/™/Jšœœœ˜Jšœ œ?œ˜SJ˜>J˜Jšœ˜J˜—šŸ œœ˜Jšœ=™=Jš˜Jšœžœ˜"J˜Jšœœœ˜˜!Jšœ"œ˜'—J˜šœœ˜%Jšœ$œ˜*J˜!Jšœœ˜Jšœ˜—J˜Jšœ˜J˜—šŸœ œ˜JšœF™FJšœ/™/Jš˜Jšœž œ˜J˜Jšœœ˜J˜J˜ J˜šœœ˜$Jšœ-œ˜3Jšœ#œ˜)J˜ Jš œ œœ œ œ˜AJšœ˜—J˜Jšœ˜J˜—šŸœœ˜Jšœ<™