File: DBModelPrivate.mesa
Copyright © 1985 by Xerox Corporation. All rights reserved.
File created by Rick Cattell, September 1980
Last edited by:
Cattell on: November 8, 1983 11:10 am
Willie-Sue on February 20, 1985 10:32:27 am PST
Donahue, August 20, 1986 8:22:33 am PDT
Widom, September 9, 1985 10:20:32 am PDT
DIRECTORY
BasicTime,
DB,
DBStorage,
DBModel,
DBCommon,
DBDefs,
RefTab,
Rope;
DBModelPrivate:
CEDAR
DEFINITIONS
= BEGIN OPEN DBCommon, DBDefs;
Types
ROPE: TYPE = Rope.ROPE;
Global variables and constants
DefaultNameLength: CARDINAL = 12;
OneWordDescriptor: DBStorage.FieldDescriptor = DBStorage.FieldDescriptor[OneWord[]];
TypeDescriptor: DBStorage.FieldDescriptor = DBStorage.FieldDescriptor[TwoWord[]];
NameDescriptor: DBStorage.FieldDescriptor = DBStorage.FieldDescriptor[VarByte[lengthHint: DefaultNameLength]];
The default descriptor for a tuple field used to hold the name of a domain, relation, etc.
TupleSetDescriptor: DBStorage.FieldDescriptor = DBStorage.FieldDescriptor[NWord[length: DBStorage.TuplesetObjectSize]];
A field descriptor for setting the tuple set handle (first) fields of tuples that are used as tuplesets
IndexDescriptor: DBStorage.FieldDescriptor = DBStorage.FieldDescriptor[NWord[length: DBStorage.IndexObjectSize]];
A field descriptor for setting the tuple set handle (first) fields of tuples that are used as indices
HandleDescriptor: DBStorage.FieldDescriptor = DBStorage.FieldDescriptor[NWord[length: DBStorage.FieldObjectSize]];
A field descriptor for setting the tuple set handle (first) fields of tuples that are used as indices
NoTID: LONG CARDINAL = 0; -- used in tuple handles nullified by storage level
DomainTSID:
LONG
CARDINAL = 1;
The tuple set ID of the DomainDomain
RelationTSID:
LONG
CARDINAL = 2;
The tuple set ID of the RelationDomain
IndexTSID:
LONG
CARDINAL = 3;
The tuple set ID of the IndexDomain
IndexFactorTSID:
LONG
CARDINAL = 4;
The tuple set ID of the IndexFactorDomain
AttributeTSID:
LONG
CARDINAL = 5;
The tuple set ID of the AttributeDomain
SetSystemTable: PROC[tid: TID] RETURNS[tupleSet: DBStorage.SystemTuplesetHandle, tuple: TupleHandle];
IndexDomain: DBCommon.TupleHandle;
IndexTupleSet: DBStorage.SystemTuplesetHandle;
IndexCountField: DBStorage.FieldHandle;
IndexRelationField: DBStorage.FieldHandle;
IndexKeyField: DBStorage.FieldHandle;
DomainDomain: DBCommon.TupleHandle;
RelationDomain: DBCommon.TupleHandle;
RelationTupleSet: DBStorage.SystemTuplesetHandle;
DomainTupleSet: DBStorage.SystemTuplesetHandle;
Private Operations on Segments
SegmentToHandle:
PROC [segment: Segment]
RETURNS [SegmentHandle];
Maps the atom (client) representation of a segment to the internal descriptor
Private Operations on Domains
These operations define the interface between DBModelDomainImpl and the other pieces of DBModel — the InitializeSystemDomains operation is used by DBModelSegmentImpl and the other operations (both on domains and on entities) are used by DBModelRelationImpl
InitializeDomainSchema:
PROC[];
Initialize the component of the Cypress database schema that is needed to interpret the operations on domains (this includes the DomainDomain and the IndexDomain). This procedure must be called before InitializeRelationSchema, since it also sets up the system tables necessary for InitializeRelationSchema!
TupleToDomain:
PROC[t: TupleHandle, segment: Segment, name: Rope.
ROPE ←
NIL]
RETURNS[d: Domain];
Return the domain object corresponding to the named tuple. If the name is not already known, then it will be read from the tuple
CompatibleTypes:
PROC[d: Domain, type: TypeCode]
RETURNS[yes:
BOOL];
Is d equivalent to or a subtype of type? I.e., can a value of the subType domain be stored in a field that has the typecode type? This is how the effects of the public operations DeclareSubType and DestroySubType can be observed
NoSubtypes:
PROC[d: Domain]
RETURNS[yes:
BOOL];
TRUE iff the domain d has no subtypes
CheckDomainKey:
PROC[d: Domain];
Fails if the key is inconsistent with that of the segment table
ReadDomain:
PROC[d: Domain];
Ensure that all of the details of the domain are known
Private Operations on Relations
These operations define the interface between DBModelRelationImpl and the other pieces of DBModel — the operations on relations and relationships are the ones needed by DBModelDomainImpl and DBModelIndexImpl
InitializeRelationSchema:
PROC[];
Return the relation object corresponding to the named tuple
CheckRelationKey: PROC[r: Relation];
TupleToRelation:
PROC[t: TupleHandle, segment: Segment, name: Rope.
ROPE ←
NIL]
RETURNS[r: Relation];
Return the relation object corresponding to the given tuple; if the name is not provided, then it will be read from the database
DestroyStoredRelations:
PROC[d: Domain];
Destroy all of the stored relations that contain fields of the domain type. This removes both the information in the database and also the cache entries corresponding to relations that are destroyed
DestroySurrogates:
PROC[d: Domain];
Destroy all of the information in the schema about surrogates for the domain
Unlink:
PROC[t: TupleHandle, d: Domain];
For each stored relationship that contains a reference to the tuple t, destroy the relationship. For each surrogate relationship stored in t, remove t from the group for the relation (and set each of the entity- and rope-valued fields to NIL).
CacheAttributes:
PROC[r: Relation];
Ensure that all of the information about the attributes of r is correct.
IsLegalIndex:
PROC[r: Relation, index: Index, checkKeysOnly:
BOOL ←
FALSE]
RETURNS[legal:
BOOL];
Ensure that all of the information about the attributes of r is correct.
Private Operations on Relationships
DestroyRelshipTuple:
PROC[t: TupleHandle, r: Relation];
Destroy the relationship pointed at by the tuple handle t from the relation r
Index Maintenance Operations
InitializeIndexSchema: PROC[];
DestroyIndexTuple:
PROC[handle: DBStorage.TupleHandle];
It is assumed that the tuple handle point to an index tuple; this also destroys all of the related index factor tuples
DeleteTupleFromIndex:
PROC[t: TupleHandle, r: Relation, iHandle: IndexHandle];
Remove the tuple from the given index (the index handle gives the order in which the attribute values are used to compose the key for the tuple)
AddTupleToIndex:
PROC[t: TupleHandle, r: Relation, iHandle: IndexHandle];
Add the tuple to the given index (the index handle gives the order in which the attribute values are used to compose the key for the tuple)
CheckKeyInIndex: PROC[i: IndexHandle, key: Rope.ROPE] RETURNS [yes: BOOL];
NCode:
PROC [v: Value]
RETURNS [code: Rope.
ROPE];
This procedure is composed from the more primitive procedures below
NCodeTuple: PROC[t: TupleHandle] RETURNS [code: Rope.ROPE];
NCodeRope: PROC[rope: Rope.ROPE] RETURNS [code: Rope.ROPE];
NCodeBool: PROC[bool: BOOL] RETURNS [code: Rope.ROPE];
NCodeInt: PROC[int: INT] RETURNS [code: Rope.ROPE];
NCodeTime: PROC[time: BasicTime.GMT] RETURNS [code: Rope.ROPE];
DCode:
PROC[key: DBCommon.IndexKey, ropes: RopeSequence];
This procedure assumes that the sequence passed in is precisely long enough to take the decoded version of the key
NameFromIndexKey:
PUBLIC
PROC[key: DBCommon.IndexKey]
RETURNS[name: Rope.
ROPE];
Reads the key fields of index entries and returns them as ropes
CacheIndices:
PROC[r: Relation];
Read the database information on the indices for the given relation
Operations that manipulate tuples directly
CheckForNull:
PROC[t: TupleHandle];
Raises DBError.Nullified if the tuple has been nullified
CopyTupleHandle:
PROC[t: TupleHandle]
RETURNS[new: TupleHandle];
This copies the tid and cacheHint fields of a tuple into a new System Tuple (which is not touched when transactions are closed or aborted)
EmptyTupleSet:
PROC[ts: TupleHandle]
RETURNS[yes:
BOOL];
This predicate is true iff the tuple set named by the given tid is empty
GetNamedTuple:
PROC[index: DBStorage.IndexHandle, name: Rope.
ROPE]
RETURNS[TupleHandle];
Produce the tuple that in the specified index that has the given name
SetTupleField:
PROC[t: TupleHandle, f: DBStorage.FieldHandle, val: TupleHandle];
Set the f field of t to point to the tuple val (f must refer to a DBStorage.FieldObjectSize field). val must point to a non-NIL tuple; to set a field to NIL use NullifyTupleField
NullifyTupleField: PROC[t: TupleHandle, f: DBStorage.FieldHandle];
GetTupleField: PROC[t: TupleHandle, f: DBStorage.FieldHandle] RETURNS[val: TupleHandle];
SetRopeField: PROC[t: TupleHandle, f: DBStorage.FieldHandle, val: Rope.ROPE];
GetRopeField: PROC[t: TupleHandle, f: DBStorage.FieldHandle] RETURNS[val: Rope.ROPE];
SetCardField: PROC[t: TupleHandle, f: DBStorage.FieldHandle, val: CARDINAL];
GetCardField: PROC[t: TupleHandle, f: DBStorage.FieldHandle] RETURNS[val: CARDINAL];
SetBoolField: PROC[t: TupleHandle, f: DBStorage.FieldHandle, val: BOOL];
GetBoolField: PROC[t: TupleHandle, f: DBStorage.FieldHandle] RETURNS[val: BOOL];
SetIntField: PROC[t: TupleHandle, f: DBStorage.FieldHandle, val: INT];
GetIntField: PROC[t: TupleHandle, f: DBStorage.FieldHandle] RETURNS[val: INT];
SetTimeField: PROC[t: TupleHandle, f: DBStorage.FieldHandle, val: BasicTime.GMT];
GetTimeField: PROC[t: TupleHandle, f: DBStorage.FieldHandle] RETURNS[val: BasicTime.GMT];
SetTypeField: PROC[t: TupleHandle, f: DBStorage.FieldHandle, val: DBDefs.TypeCode];
GetTypeField: PROC[t: TupleHandle, f: DBStorage.FieldHandle] RETURNS[val: DBDefs.TypeCode];
SetFieldField: PROC[t: TupleHandle, f: DBStorage.FieldHandle, val: DBStorage.FieldHandle];
GetFieldField: PROC[t: TupleHandle, f: DBStorage.FieldHandle] RETURNS[val: DBStorage.FieldHandle];
END.