-- File: DBModelGlobalImpl.mesa
-- Contents: Implementation of global operations (open, close, schema def) ops for Model level
-- Last edited by:
-- Eric Bier on August 6, 1981 17:10:15
-- Rick Cattell on January 4, 1984 10:36 am
-- Willie-Sue on February 3, 1983 11:39 am

DIRECTORY
Atom,
Basics USING [LowHalf],
DBEnvironment,
DBStorage,
DBTuplesConcrete,
DB,
DBModel,
DBModelPrivate,
Rope;

DBModelGlobalImpl: PROGRAM
IMPORTS Atom, DBStorage, DBModel, DB, DBModelPrivate, Basics, Rope
EXPORTS DB, DBModel, DBEnvironment =

BEGIN OPEN DB, DBModelPrivate, DBModel;


-- variables private to this module

initialized: BOOL← FALSE;

surrogatesEnabled: BOOL← TRUE;


-- opaque type objects: concrete in DBTuplesConcrete exported to DBModel

TupleObject: PUBLIC TYPE = DBTuplesConcrete.TupleObject;
EntityObject: PUBLIC TYPE = TupleObject;
RelshipObject: PUBLIC TYPE = TupleObject;

EntitySetObject: PUBLIC TYPE = DBTuplesConcrete.EntitySetObject;
RelshipSetObject: PUBLIC TYPE = DBTuplesConcrete.RelshipSetObject;


-- REFS to opaque type objects

Tuple, TupleSet, Index, IndexFactor: TYPE = REF TupleObject;
Domain, Relation, Entity, Attribute, DataType: PUBLIC TYPE = REF EntityObject;
Relship: PUBLIC TYPE = REF RelshipObject;

SystemATuple: TYPE = REF attribute TupleObject;
SystemTSTuple: TYPE = REF tupleSet TupleObject;

EntitySet: PUBLIC TYPE = REF EntitySetObject;
RelshipSet: PUBLIC TYPE = REF RelshipSetObject;

T2SAT: PUBLIC PROCEDURE[t: Tuple] RETURNS [SystemATuple] =
BEGIN RETURN [NARROW[t]] END;

T2ST: PUBLIC PROCEDURE[t: Tuple] RETURNS [SystemTSTuple] =
-- INLINE -- BEGIN RETURN [NARROW[t]] END;

T2STT: PUBLIC PROCEDURE[t: Tuple] RETURNS [SystemTSTuple] =
-- INLINE -- BEGIN RETURN [NARROW[t]] END;


-- Initialization of database system

QInitialize: PUBLIC PROC[
nCachePages: NAT, nFreeTuples: NAT, cacheFileName: ROPE, augments: BOOL] =
-- Initializes database system
BEGIN
-- DBModelPrivate.enableAugments← augments;
IF initialized THEN RETURN;
initialized← TRUE;
IF cacheFileName=NIL THEN cacheFileName← "DBSegment.VM";
DBStorage.Initialize[nCachePages, nFreeTuples, cacheFileName];
InitializeSystemTuples[];
END;


--Transaction operations

QOpenTransaction: PUBLIC PROC[
segment: Segment, useTrans: Transaction← NIL, noLog: BOOL← FALSE] = {
IF NOT initialized THEN ERROR Error[DatabaseNotInitialized];
DBStorage.OpenTransaction[segment, useTrans, noLog];
};

QMarkTransaction: PUBLIC PROC[trans: Transaction] = {
IF trans#NIL THEN DBStorage.FinishTransaction[trans, FALSE, TRUE]};

QAbortTransaction: PUBLIC PROC[trans: Transaction] = {
FlushCaches[];
IF trans#NIL THEN DBStorage.FinishTransaction[trans, TRUE, FALSE]
};

QCloseTransaction: PUBLIC PROC[trans: Transaction] = {
-- Note: DBImpl does DBStats.Print after calling this.
FlushCaches[];
IF trans#NIL THEN DBStorage.FinishTransaction[trans, FALSE, FALSE];
};


-- Segment operations

QDeclareSegment: PUBLIC PROC[
filePath: ROPE, segment: Segment, number: NAT← 0, readonly: BOOL← FALSE,
createIfNotFound: BOOL← TRUE, nBytesInitial, nBytesPerExtent: INT ] =
-- Open a segment. Simply registers it, doesn't open the file till transaction opened.
-- Note that we have a slightly different semantics for the version than DBStorage.
-- We NEVER clobber an existing segment, that must be done with EraseSegment.
BEGIN
fileVersion: DBStorage.VersionOptions← IF createIfNotFound THEN None ELSE OldFileOnly;
IF readonly AND createIfNotFound THEN {SIGNAL Error[WriteNotAllowed]; RETURN};
IF NOT initialized THEN {SIGNAL Error[DatabaseNotInitialized]; RETURN};
IF segment=NIL THEN segment← Atom.MakeAtom[ParseSegmentName[filePath].name];
IF number=0 THEN number← MapSegmentToNumber[segment];
DBStorage.AttachSegment[
filePath, segment, number, readonly, fileVersion, FALSE, nBytesInitial, nBytesPerExtent];
END;

MapSegmentToNumber: PROC [segment: Segment] RETURNS [NAT] = {
SELECT segment FROM
$Squirrel => RETURN[100B];
$Foo => RETURN[101B];
$Icons => RETURN[140B];
$Walnut => RETURN[200B];
$Hickory => RETURN[210B];
$Grapenut => RETURN[220B];
$Coconut => RETURN[230B];
$Help => RETURN[240B];
$Nuthatch => RETURN[250B];
$Test => RETURN[300B];
$Chestnut => RETURN[400B];
ENDCASE => ERROR Error[CannotDefaultSegment]; -- seg number not given & can't guess
};

QEraseSegment: PUBLIC PROC[segment: Segment] =
-- Erases a segment. Closes transaction if it was open.
BEGIN
filePath: ROPE; number: NAT; readOnly: BOOL; trans: Transaction;
nBytesInitial, nBytesPerExtent: INT;
[filePath, number, trans, readOnly, nBytesInitial, nBytesPerExtent]←
DBStorage.GetSegmentInfo[segment];
QCloseTransaction[trans]; -- does nothing if no transaction open
DBStorage.AttachSegment[
filePath, segment, number, readOnly, None, TRUE, nBytesInitial, nBytesPerExtent];
QOpenTransaction[segment];
QCloseTransaction[QGetSegmentInfo[segment].trans];
END;

QGetSegmentInfo: PUBLIC PROC[segment: Segment] RETURNS [
filePath: ROPE, number: NAT, trans: Transaction,
readOnly: BOOL, nBytesInitial, nBytesPerExtent: INT] = {
CheckNIL[segment];
[filePath, number, trans, readOnly, nBytesInitial, nBytesPerExtent]←
DBStorage.GetSegmentInfo[segment];
RETURN[filePath, number, trans, readOnly, nBytesInitial, nBytesPerExtent] };

QGetSegments: PUBLIC PROC RETURNS [sl: LIST OF Segment] =
BEGIN
addToList: PROC [s: Segment, segmentIndex: DBStorage.SegmentIndex]RETURNS [stop: BOOL] =
{sl← CONS[s, sl]; RETURN[FALSE]};
sl← NIL;
DBStorage.EnumerateSegments[addToList];
RETURN[sl];
END;


-- Schema definition operations

QDeclareDomain: PUBLIC PROC [
name: ROPE, segment: Segment,
version: Version← NewOrOld, estRelships: INT← 5] RETURNS [d: Domain] =
-- Creates a domain of this name or fetches it if it already exists.
BEGIN
IF NOT initialized THEN ERROR Error[DatabaseNotInitialized];
IF name=NIL THEN name← "";
IF name.Length[]#0 THEN
BEGIN
d← QFetchEntity[DomainDomain, name, segment];
IF d#NIL THEN IF version=NewOnly THEN ERROR Error[AlreadyExists] ELSE RETURN[d];
IF version=OldOnly THEN RETURN[NIL];
END;
-- Create a new domain. Must set name and index entry manually 'since SetP assumes exists.
d← DBStorage.CreateSystemPageTuple[T2ST[DomainDomain].vTuple, NIL, segment];
DBStorage.CreateTupleset[d, Basics.LowHalf[estRelships]];
SetValFromHandle[d, tupleSetNameHandle, RopeType, Unlinked, name];
DBStorage.InsertIntoIndex[GetDomainIndex[segment], ConvertToUpper[name], d];
-- create the name field and index for the entities of this domain
[]← DBStorage.AddField[d, MakeFD[RopeType, DefaultNameLength]];
[]← SafeSetP[d, dIndexProp, CreateTupleSetIndex[d]];
DBModelPrivate.FlushCaches[];
END;

QDeclareRelation: PUBLIC PROC[
name: ROPE, segment: Segment, version: Version← NewOrOld]
RETURNS [r: Relation] =
-- Creates a relation of this name or fetches it if it already exists.
BEGIN
IF NOT initialized THEN ERROR Error[DatabaseNotInitialized];
IF name=NIL THEN name← "";
IF name.Length[]#0 THEN
BEGIN
r← QFetchEntity[RelationDomain, name, segment];
IF r#NIL THEN IF version=NewOnly THEN ERROR Error[AlreadyExists] ELSE RETURN[r];
IF version=OldOnly THEN RETURN[NIL];
END;
-- Create a new relation. Must set name and index entry manually 'since SetP assumes exists.
r← DBStorage.CreateSystemPageTuple[T2ST[RelationDomain].vTuple, NIL, segment];
DBStorage.CreateTupleset[r, 0 -- NO refs to Relships --];
[]← SafeSetP[r, r1to1Prop, B2V[FALSE]];
SetValFromHandle[r, tupleSetNameHandle, RopeType, Unlinked, name];
DBStorage.InsertIntoIndex[GetRelationIndex[segment], ConvertToUpper[name], r];
DBModelPrivate.FlushCaches[];
END;

QDeclareAttribute: PUBLIC PROC [
r: Relation, name: ROPE, type: DataType← NIL, uniqueness: Uniqueness ← None,
length: INT← 0, link: LinkType← Linked, version: Version← NewOrOld]
RETURNS[a: Attribute] =
-- Create a new attribute dictionary entity, and define a new fieldhandle for
-- the appropriate tupleset.
BEGIN
NameEqual: PROC [e: Entity] RETURNS[BOOL] =
{RETURN[name.Equal[QNameOf[e], FALSE]]};
fh: DBStorage.FieldHandle;
attCount: CARDINAL;
IF r=NIL THEN RETURN[NIL];
CheckRelation[r];
IF link=Colocated THEN SIGNAL Error[NotImplemented];
a← SearchEntityList[VL2EL[QGetPList[r, aRelationOf]], NameEqual];
IF a#NIL THEN IF version=NewOnly THEN ERROR Error[AlreadyExists] ELSE
BEGIN -- Check that existing attribute of proper type.
IF type#NIL AND NOT Eq[V2E[QGetP[a, aTypeIs]], type] THEN
SIGNAL Error[MismatchedExistingAttribute];
RETURN[a]
END;
-- No existing attribute, so create it.
IF version = OldOnly THEN RETURN[NIL];
IF type=NIL THEN SIGNAL Error[NILArgument]; -- Must not default type, if new!
a← DBStorage.CreateSystemPageTuple[T2ST[AttributeDomain].vTuple, r];
QChangeName[a, name];
DBModelPrivate.SetTypeAndLink[a, type, link];
[]← SafeSetP[a, aRelationIs, r];
[]← SafeSetP[a, aLengthIs, I2V[length]];
[]← SafeSetP[a, aUniquenessIs, U2V[uniqueness] ];
-- Create the fields for values of this attribute in a's Relation or ref'd Domain:
attCount← NumberOfAttributes[r];
-- The surrogate relation optimization follows. If:
-- (1) this is the first attribute of r
-- (2) it is a single-attribute primary key
-- (3) it is an entity-valued attribute but not of type AnyDomainType
-- (4) the domain it references is empty (has not entities yet)
-- (5) the domain it refs has no subdomains (else they'd need the attr too)
-- then we set r1to1Prop to TRUE for this relation, and store the 2nd-Nth
-- attributes with the domain instead; the relation's relships will be
-- surrogates not actually stored as tuples
IF attCount=1 AND uniqueness=Key AND surrogatesEnabled THEN
SELECT type FROM
AnyDomainType, RopeType, BoolType, IntType =>
NULL;
ENDCASE =>
IF NOT Eq[QDomainOf[type], DomainDomain] THEN ERROR Error[IllegalValueType]
  -- user specified type that was not domain or built-in type
ELSE IF EmptyDomain[type] AND GetCachedDomainInfo[type].subDomains=NIL THEN
  BEGIN -- this is it! we can do the surrogate relation optimization!
  []← SafeSetP[r, r1to1Prop, B2V[TRUE]];
[]← SafeSetP[a, aDomainIs, type];
  RETURN
  END;
IF V2B[SafeGetP[r, r1to1Prop]] THEN
-- we are defining Nth attribute of a 1 to 1 (surrogate) relation where N>1:
BEGIN
storageDomain: Domain← V2E[SafeGetP[GetFirstAttribute[r], aTypeIs]];
fh← DBStorage.AddField[storageDomain, MakeFD[type, length, link=Linked, a]];
[]← SafeSetP[a, aHandleProp, fh];
END
ELSE -- we are defining an attribute of a normal relation:
BEGIN
fh← DBStorage.AddField[r, MakeFD[type, length, link=Linked, a]];
[]← SafeSetP[a, aHandleProp, fh];
END;
DBModelPrivate.FlushCaches[];
END;

QDeclareSubType: PUBLIC PROC [of, is: Domain] =
-- Check that super (of) is not already sub (is) of sub, that super has no entities in it,
-- and that super is not already supertype of sub (just return in this case).
BEGIN
st: Relship;
rs: RelshipSet← QRelationSubset[dSubType, LIST[ [dSubTypeIs, is], [dSubTypeOf, of] ] ];
theseBetterNotIncludeSuper: LIST OF Domain← GetCachedDomainInfo[is].subDomains;
segment: Segment← QSegmentOf[of];
FOR dlT: LIST OF Domain← theseBetterNotIncludeSuper, dlT.rest UNTIL dlT=NIL DO
IF Eq[dlT.first, of] THEN
ERROR Error[IllegalSuperType] -- super is already of a subdomain!
ENDLOOP;
IF QNextRelship[rs]#NIL THEN
-- It's already a subType, just return and leave it that way
{QReleaseRelshipSet[rs]; RETURN};
QReleaseRelshipSet[rs];
IF NOT EmptyDomain[of] THEN
-- Currently can't define subdomain if super already has entries
SIGNAL Error[NotImplemented]; -- But client can resume if knows no surrogates
-- The following line sends the compiler into an address fault if don't use T2CT!
st← DBStorage.CreateSystemPageTuple[T2ST[T2CT[dSubType]].vTuple, NIL, segment];
SafeSetF[st, dSubTypeIs, is];
SafeSetF[st, dSubTypeOf, of];
END;
   
QDeclareIndex: PUBLIC PROC[
r: Relation, order: AttributeList, version: Version] RETURNS[i: Index] =
-- Creates an index on relation r, keyed on the attributes in order; r may not have tuples.
-- We enter the index factors such that a group scan on the index will return them in order
-- of increasing lexicographic significance. We check to see if there's another identical
-- index on r. We allow an index on all kinds of attributes, including entity-valued ones.
-- On entity-valued attributes, the string values used will actually be the entity names.
BEGIN
count: INT;
if: IndexFactor;
ifs: LIST OF IndexFactor;
-- See if the index (ie an index with the same attribute order) already exists.
-- Try all the indexes that include the first attribute in order:
ifs← VL2EL[QGetPList[order.first, ifAttributeOf]];
FOR ifsT: LIST OF IndexFactor← ifs, ifsT.rest UNTIL ifsT=NIL DO
i← V2E[QGetP[ifsT.first, ifIndexIs]];
IF SameIndex[i, order] THEN
IF version=NewOnly THEN ERROR Error[AlreadyExists] ELSE RETURN[i];
REPEAT
FINISHED => IF version=OldOnly THEN RETURN[NIL];
ENDLOOP;
-- Check that relation empty, then create index and index factors.
IF NOT EmptyRelation[r] THEN SIGNAL Error[NotImplemented];
i← CreateTupleSetIndex[r]; count← 0;
FOR orderL: AttributeList← order, orderL.rest UNTIL orderL=NIL DO
if← DBStorage.CreateSystemPageTuple[T2STT[IndexFactorDomain].vTuple, r];
[]← SafeSetP[if, ifIndexIs, i]; -- Each factor points to its index...
[]← SafeSetP[if, ifOrdinalPositionIs, NEW[INT← count]]; -- ... gives its pos'n in the order
[]← SafeSetP[if, ifAttributeIs, orderL.first]; -- .. and the attribute it refers to
count← count+1;
ENDLOOP;
DBModelPrivate.FlushCaches[];
END;

CreateTupleSetIndex: PUBLIC PROC[ts: TupleSet] RETURNS [i: Index] =
-- Creates the storage level index on a domain or relation, and the Index entity
BEGIN
i← DBStorage.CreateSystemPageTuple[T2STT[IndexDomain].vTuple, ts];
DBStorage.CreateIndex[i]; -- storage level sets iHandleProp
END;

QDeclareProperty: PUBLIC PROC [
relationName: ROPE, of: Domain, is: DataType, segment: Segment,
uniqueness: Uniqueness← None, version: Version← NewOrOld] RETURNS [aIs: Attribute] =
BEGIN
r: Relation← QDeclareRelation[relationName, segment, version];
rOf: Attribute← QDeclareAttribute[r, "of", of, Key, 0, Linked, version];
rIs: Attribute← QDeclareAttribute[r, "is", is, uniqueness, 0, Linked, version];
RETURN[rIs];
END;

QDestroyDomain: PUBLIC PROC [d: Domain] =
-- Destroys a domain, any connections it has to super-domains, all
-- the domain's entities, all relations which references this domain (only),
-- and all indexes involving the domain.
BEGIN
e: Entity; r: Relship;
es: EntitySet← QDomainSubset[d]; -- all entities
al: LIST OF Attribute← VL2EL[QGetPList[d, aTypeOf] ]; -- reffing attr's
supers: RelshipSet← QRelationSubset[dSubType, LIST[[dSubTypeIs, d]] ]; -- supers
dIndex: Index; subDomains: LIST OF Domain;
[nameIndex: dIndex, subDomains: subDomains]← GetCachedDomainInfo[d];
IF subDomains#NIL THEN
SIGNAL Error[NotImplemented]; -- must destroy the domain's subdomains first!
DBStorage.DeleteFromIndex[
GetDomainIndex[QSegmentOf[d]], ConvertToUpper[QNameOf[d]], d];
WHILE (r← QNextRelship[supers])#NIL DO
-- destroy any links to super domains
SafeSetF[r, dSubTypeOf, NIL];
SafeSetF[r, dSubTypeIs, NIL];
DBStorage.DestroyTuple[r];
ENDLOOP;
QReleaseRelshipSet[supers];
WHILE (e← QNextEntity[es])#NIL DO QDestroyEntity[e] ENDLOOP;
QReleaseEntitySet[es];
FOR alT: LIST OF Attribute← al, alT.rest UNTIL alT=NIL DO
IF NOT Null[alT.first] THEN -- this check needed 'cause two attrs of reln may ref d
{reln: Relation← V2E[SafeGetP[alT.first, aRelationIs]]; QDestroyRelation[reln]};
ENDLOOP;
[]← SafeSetP[d, dIndexProp, NIL];
QDestroyIndex[dIndex];
DestroyDictionaryEntity[d]; -- destroys any user links to d, all ours should be gone
END;

QDestroyRelation: PUBLIC PROC [r: Relation] =
-- Destroys a relation, its attributes, and all of its relships.
BEGIN
rel: Relship;
rs: RelshipSet← QRelationSubset[r, NIL];
al: LIST OF Attribute← VL2EL[QGetPList[r, aRelationOf] ]; -- R's attributes
WHILE (rel← QNextRelship[rs])#NIL DO QDestroyRelship[rel] ENDLOOP; -- destroy relships
QReleaseRelshipSet[rs];
FOR alT: LIST OF Attribute← al, alT.rest UNTIL alT=NIL DO
-- Destroy attributes: must nil out any refs to domains & relations (to kill back refs)
[]← SafeSetP[alT.first, aRelationIs, NIL];
[]← SafeSetP[alT.first, aTypeEntityProp, NIL];
[]← SafeSetP[alT.first, aDomainIs, NIL];
DBStorage.DestroyTuple[alT.first];
ENDLOOP;
DBStorage.DeleteFromIndex[
GetRelationIndex[QSegmentOf[r]], ConvertToUpper[QNameOf[r]], r];
DBModelPrivate.FlushCaches[];
DestroyDictionaryEntity[r];
END;

QDestroyAttribute: PUBLIC PROC[a: Attribute] =
BEGIN ERROR Error[NotImplemented];
END;

QDestroySubType: PUBLIC PROC [of, is: Domain] =
-- Need only delete the subtype tuple, st. There should be no refs to it, and we
-- leave it to the user to insure that no existing relships now become illegal.
-- However, we must explicitly set sub and super to NIL to destroy SL's back-refs.
BEGIN
st: Relship;
rs: RelshipSet← QRelationSubset[dSubType, LIST[ [dSubTypeIs, is], [dSubTypeOf, of] ] ];
IF (st← QNextRelship[rs])=NIL THEN
-- It's not a subType, just return and leave it that way
{QReleaseRelshipSet[rs]; RETURN};
QReleaseRelshipSet[rs];
SafeSetF[st, dSubTypeOf, NIL];
SafeSetF[st, dSubTypeIs, NIL];
DBStorage.DestroyTuple[st];
END;

QDestroyIndex: PUBLIC PROC[i: Index] =
-- Used to destroy index on domain or on relation.
-- Warning: must not destroy index on domain w/o destroying domain, since still refs index.
BEGIN
ifs: LIST OF IndexFactor← VL2EL[QGetPList[i, ifIndexOf]];
DBStorage.DestroyIndex[i];
FOR ifsT: LIST OF IndexFactor← ifs, ifsT.rest UNTIL ifsT=NIL DO
[]← SafeSetP[ifsT.first, ifIndexIs, NIL]; DBStorage.DestroyTuple[ifsT.first] ENDLOOP;
DBModelPrivate.FlushCaches[];
DestroyDictionaryEntity[i];
END;

DestroyDictionaryEntity: PROC[e: Entity] =
-- Destroy a domain, relation, attribute, index, or index factor entity.
-- Also destroys any group links to the entity: we don't know all the possible links to
-- the entity, now that we allow client-defined relations to reference dictionary entities.
-- We assume caller has destroyed any dependent entities and index entries, however.
BEGIN
DestroyLinksTo[e];
DBStorage.DestroyTuple[e];
END;

SameIndex: PROC[ i: Index, nl: AttributeList] RETURNS[BOOLEAN] =
-- Determines whether the index factors of the given index, when compared in order to the
-- Attributes in nl, are the same.
BEGIN
a: Attribute;
if: IndexFactor;
count: INT← 0;
ifs: LIST OF Attribute← VL2EL[QGetPList[i, ifIndexOf]];
FOR nlT: AttributeList ← nl, nlT.rest UNTIL nlT=NIL DO
IF ifs=NIL THEN -- there more attributes in nl than index factors in ifs
RETURN[FALSE];
a← nlT.first;
if← ifs.first; ifs← ifs.rest;
IF count#V2I[SafeGetP[if, ifOrdinalPositionIs]] THEN ERROR InternalError;
IF NOT Eq[a, V2E[SafeGetP[if, ifAttributeIs]]] THEN RETURN[FALSE];
count← count+1;
ENDLOOP;
IF ifs#NIL THEN RETURN[FALSE]; -- there were more index factors than attributes in nl
RETURN[TRUE]
END;


END.

Changed by Rick on 9-Sep-81 12:03:07: Changed openState to databaseOpen BOOLEAN; patched ExtraCedar to start Pine exactly once, it seems to be the best solution till Pine is incorporated in Cedar.

Changed by Rick on 26-Nov-81 13:38:45: Must check that no subdomains for surrogate relation optimization.

Changed by Rick on 26-Nov-81 16:20:04: Open/Create Database now get server from dbName instead of separate argument.

Changed by Rick on 6-Jan-82 12:25:15: EmptyDomain should not search subdomains. Don't need Nto1fromRole in normal PropertyObject (QDeclarePropertyFromAttrs).

Changed by Rick on 22-Jan-82 9:20:21: Implemented QDestroyDomain which also destroys SubType connections.

Changed by Rick on April 15, 1982 7:01 pm: CreatePropertyFromAttrs checks args.

Changed by Rick on April 24, 1982 12:16 am: QDeclareProperty uses version. QDestroyDomain also destroys any relations that directly reference the domain. QDestroyRelation needs to remove from index.

Changed by Rick on April 24, 1982 5:50 pm: QDestroyRelation must nil out any domain refs when destroying attributes else leave dangling ref in group. It must also FlushAttributeCache.

Changed by Rick on April 28, 1982 10:47 am: upper-case domain/relation index entries.

Changed by Rick on May 4, 1982 1:01 pm: DBStorage.CloseCommunication no longer does CloseDatabase, so call this explicitly now. OpenDatabase now calls CloseCommunication when the VersionProblem error is raised, to leave things in a consistent (unopened) state. Generate RelationOrDomainSubsetsStillOpen at end of CloseDatabase so works properly if client proceeds OR resumes.

Changed by Rick on May 6, 1982 6:39 pm: Forgot to call ConvertToUpper when removing domains and relations from indexes. Moved DestroyIndex here from DBViewSystemImpl.

Changed by Rick on July 30, 1982 1:56 pm: Changed DeclareSubType to do more thorough checking of given sub and super. Changed DestroyDomain to run faster, by destroying the whole B-Tree index at once. This necessitated changing DestroyEntity in DBViewBasicImpl to ignore the B-Tree entry removal if it can't find a B-Tree for the domain.

Changed by Rick on August 1, 1982 11:15 am: Check for databaseOpen on DeclareRelation, DeclareDomain, CloseDatabase, AbortTransaction.

Changed by Rick on November 12, 1982 2:26 pm: New properties, indices, etc. Added DeclareIndex. Added assignment of aDomainProp in DeclareAttribute.

Changed by Rick on December 13, 1982 8:45 pm: Changes for segments and various other cleanups. Indices not yet tested, however. Modified/added the global database, transaction, and segment procedures. Modified DeclareRelation and DeclareDomain to take and use segment argument. Changed BOOL databaseOpen=>initialized.

Changed by Rick on January 16, 1983 3:27 pm: bug in DeclareIndex if index existed.

Changed by Rick on February 1, 1983 8:50 am: Made all Declare procedures flush caches, just for safety; DeclareIndex was invalidating the relation info cache without flushing it! Declaring and Destroying Subtypes should be ok, for now, since they're not cached.

Changed by Willie-Sue on February 3, 1983: add noLog arg to QOpenTransaction

Changed by Rick on February 18, 1983 4:57 pm: Forgot to nil out ref to relation when destroying attributes in DestroyRelation.

Changed by Rick Cattell on March 15, 1983 10:04 am: Domain caching.

Changed by Rick Cattell on April 12, 1983 4:55 pm: A hard-to-find bug. Failed to NIL out the aDomainIs field of an attribute when destroying a relation, causing a dangling back reference in the domain it used to reference. This was being tickled by Maxwell's domain editor, which routinely creates and destroys relations just to see if Cypress has any complaints about the form of the attributes. Hmm. Wish there was an easier way to track down these "dangling groups" problems, which have happened several times before and are always difficult since the damage was done at an ealier time. We could do a GetAllRefAttributes before destroying system entities; we do this in DestroyDictionaryEntity for relations and domains already, in fact. Not sure if this would work for attributes.