-- File: DBStorageInternalImpl.mesa
-- Last edited by MBrown on 17-Jun-81 10:33:47
-- Last Edited by: Cattell, January 16, 1983 11:45 am


  DIRECTORY
    DBCache USING[CacheHandle],
    DBCommon USING[DBPage],
    DBEnvironment USING[InternalError],
    DBHeapStorage USING[Free],
    DBSegment USING[SegmentIDFromDBPage],
    DBStorage USING[TupleHandle, IndexObjectSize, ReadNWord, WriteNWord],
    DBStorageField USING[TuplesetFieldHandle],
    DBStorageInternal USING[TupleTree, TupleTreeRecord, TID],
    DBStorageTID USING[TID, DecomposeTID],
    DBStorageTuple USING[ConsTupleObject, TIDOfTuple];

DBStorageInternalImpl: PROGRAM
  IMPORTS
    DBEnvironment,
    DBHeapStorage,
    DBSegment,
    DBStorage,
    DBStorageField,
    DBStorageTID,
    DBStorageTuple
  EXPORTS
    DBStorageInternal
  = BEGIN OPEN DBStorageTID;

  --  This module implements DBStorageInternal.

  ReadIndexObject: PUBLIC PROC[t: DBStorage.TupleHandle, result: DBStorageInternal.TupleTree] = {
    -- PARAMETERS: t is an index tuple, i.e. a tuple whose first field is an index object;
    --result points to a TupleTreeRecord that may be overwritten.
    -- EFFECTS: the index object contained in tuple t is written into result.
    tmp: DBStorageInternal.TupleTree;
    IF SIZE[DBStorageInternal.TupleTreeRecord] > DBStorage.IndexObjectSize THEN
      ERROR DBEnvironment.InternalError; -- [Unknown];
    tmp ← DBStorage.ReadNWord[t, DBStorageField.TuplesetFieldHandle[]]; --LOOPHOLE
    result↑ ← tmp↑;
    DBHeapStorage.Free[tmp];
  };--ReadIndexObject

  WriteIndexObject: PUBLIC PROC[t: DBStorage.TupleHandle, val: DBStorageInternal.TupleTree] = {
    -- PARAMETERS: an index tuple, i.e. a tuple whose first field is an index object,
    --and a value for such and object.
    -- EFFECTS: writes the value val into the index object field of tuple t.
    --Does NOT deallocate val.
    tmp: ARRAY [0..DBStorage.IndexObjectSize) OF CARDINAL ← ALL[0];
    IF SIZE[DBStorageInternal.TupleTreeRecord] > DBStorage.IndexObjectSize THEN
      ERROR DBEnvironment.InternalError; -- [Unknown];
    LOOPHOLE[@tmp, DBStorageInternal.TupleTree]↑ ← val↑;
    DBStorage.WriteNWord[t, DBStorageField.TuplesetFieldHandle[], @tmp];
  };--WriteIndexObject

  SegmentIDOfTuple: PUBLIC PROC[t: DBStorage.TupleHandle] RETURNS[--segmentID--DBCommon.DBPage] = {
    -- RESULTS: the "segment ID" of the segment that contains tuple t.
    dbPage: DBCommon.DBPage;
    [dbPage,] ← DecomposeTID[TIDOfTuple[t]];
    RETURN[DBSegment.SegmentIDFromDBPage[dbPage]];
  };--SegmentIDOfTuple

  TIDOfTuple: PUBLIC PROC[t: DBStorage.TupleHandle] RETURNS[DBStorageInternal.TID] = {
    -- RESULTS: the TID of tuple t (suitable for storing in an index).
    RETURN[DBStorageTuple.TIDOfTuple[t]];
  };--TIDOfTuple

  MakeTupleHandle: PUBLIC PROC[tid: DBStorageInternal.TID, cacheHint: DBCache.CacheHandle ← NIL]
   RETURNS[DBStorage.TupleHandle] = {
    -- RESULTS: a tuple handle that contains the given TID and CacheHandle.
    RETURN[DBStorageTuple.ConsTupleObject[tid: tid, cacheHint: cacheHint]];
  };--MakeTupleHandle

END.--StorageInternalImpl


CHANGE LOG

Created by MBrown on  9-May-80 10:54

Changed by MBrown on June 8, 1980  9:35 PM
-- Changed to use DBStorageField.

Changed by MBrown on June 11, 1980  3:53 PM
-- Changed to use DBStorageTuple.

Changed by MBrown on September 26, 1980  4:35 PM
-- Converted to new DBException.

Changed by MBrown on February 27, 1981  5:25 PM
-- Pre-Pilot changes.

Changed by MBrown on 17-Jun-81 10:32:40
-- ReleaseTupleHandle is now a no-op, remove from here and make INLINE in interface.