Package org.apache.derby.impl.store.raw.data

Examples of org.apache.derby.impl.store.raw.data.StoredRecordHeader$OverflowInfo


    boolean rowHasReservedSpace = false;

    StoredPage curPage = this;
    for (;;)
        {
      StoredRecordHeader rh = curPage.getHeaderAtSlot(slot);

      int startField          = rh.getFirstField();
      int endFieldExclusive   = startField + rh.getNumberFields();

      // curPage contains column[startField] to column[endFieldExclusive-1]

      // Need to cope with an update that is increasing the number of
            // columns.  If this occurs we want to make sure that we perform a
            // single update to the last portion of a record, and not an update
            // of the current columns and then an update to append a column.

      long nextPage        = -1;
      int  realStartColumn = -1;
      int  realSpaceOnPage = -1;

      if (!rh.hasOverflow() ||
                ((startColumn >= startField) &&
                 (startColumn <  endFieldExclusive)))
      {
        boolean                 hitLongColumn;
        int                     nextColumn      = -1;
        Object[]   savedFields     = null;
        DynamicByteArrayOutputStream  logBuffer       = null;

        do
                {
          try
                    {
            // Update this portion of the record.
            // Pass in headRowHandle in case we are to update any
            // long column and they need to be cleaned up by post
            // commit processing.  We don't want to purge the
            // columns right now because in order to reclaim the
            // page, we need to remove them.  But it would be bad
            // to remove them now because the transaction may not
            // commit for a long time.  We can do both purging of
            // the long column and page removal together in the
            // post commit.
            nextColumn =
                            owner.getActionSet().actionUpdate(
                                t, curPage, slot, id, row, validColumns,
                  realStartColumn, logBuffer,
                                realSpaceOnPage, headRowHandle);

            hitLongColumn = false;

          }
                    catch (LongColumnException lce)
                    {
 
            if (lce.getRealSpaceOnPage() == -1)
                        {
              // an update that has caused the row to increase
                            // in size *and* push some fields off the page
                            // that need to be inserted in an overflow page

              // no need to make a copy as we are going to use
                            // this buffer right away
              logBuffer = lce.getLogBuffer();

              savedFields     =
                                (Object[]) lce.getColumn();
                           
              realStartColumn = lce.getNextColumn();
              realSpaceOnPage = -1;

              hitLongColumn   = true;

              continue;
            }

           
            // we caught a real long column exception
            // three things should happen here:
            // 1. insert the long column into overflow pages.
            // 2. append the overflow field header in the main chain.
            // 3. continue the update in the main data chain.
            logBuffer =
                            new DynamicByteArrayOutputStream(lce.getLogBuffer());

            // step 1: insert the long column ... if this update
                        // operation rolls back, purge the after image column
                        // chain and reclaim the overflow page because the
                        // whole chain will be orphaned anyway.
            RecordHandle longColumnHandle =
              insertLongColumn(
                                curPage, lce, Page.INSERT_UNDO_WITH_PURGE);

            // step 2: append overflow field header to log buffer
            int overflowFieldLen = 0;
            try
                        {
              overflowFieldLen +=
                appendOverflowFieldHeader(
                                    logBuffer, longColumnHandle);

            }
                        catch (IOException ioe)
                        {
              throw StandardException.newException(
                                SQLState.DATA_UNEXPECTED_EXCEPTION, ioe);
            }

            // step 3: continue the insert in the main data chain
            // need to pass the log buffer, and start column to the
                        // next insert.
            realStartColumn = lce.getNextColumn() + 1;
            realSpaceOnPage = lce.getRealSpaceOnPage() - overflowFieldLen;
            hitLongColumn = true;

          }

        } while (hitLongColumn);


        // See if we completed all the columns that are on this page.
        int validColumnsSize =
                    (validColumns == null) ? 0 : validColumns.getLength();

        if (nextColumn != -1)
                {

          if (SanityManager.DEBUG)
                    {
            // note nextColumn might be less than the the first
                        // column we started updating. This is because the
                        // update might force the record header to grow and
                        // push fields before the one we are updating off the
                        // page and into this insert.

            if ((nextColumn < startField) ||
                            (rh.hasOverflow() && (nextColumn >= endFieldExclusive)))
                        {
              SanityManager.THROWASSERT(
                                "nextColumn out of range = " + nextColumn +
                " expected between " +
                                startField + " and " + endFieldExclusive);
                        }
          }

          // Need to insert rows from nextColumn to endFieldExclusive
                    // onto a new overflow page.
          // If the column is not being updated we
          // pick it up from the current page. If it is being updated
          // we take it from the new value.
          int possibleLastFieldExclusive = endFieldExclusive;
                   
          if (!rh.hasOverflow())
                    {
            // we might be adding a field here
            if (validColumns == null)
                        {
              if (row.length > possibleLastFieldExclusive)
                possibleLastFieldExclusive = row.length;
            }
                        else
                        {
              if (validColumnsSize > possibleLastFieldExclusive)
                possibleLastFieldExclusive = validColumnsSize;
            }
          }


                    // use a sparse row
          Object[] newRow =
                        new Object[possibleLastFieldExclusive];

          FormatableBitSet  newColumnList =
                        new FormatableBitSet(possibleLastFieldExclusive);

          ByteArrayOutputStream fieldStream = null;

          for (int i = nextColumn; i < possibleLastFieldExclusive; i++)
                    {
            if ((validColumns == null) ||
                            (validColumnsSize > i && validColumns.isSet(i)))
                        {
              newColumnList.set(i);
              // use the new value
              newRow[i] = RowUtil.getColumn(row, validColumns, i);

            }
                        else if (i < endFieldExclusive)
                        {
              newColumnList.set(i);

              // use the old value
              newRow[i] = savedFields[i - nextColumn];
            }
          }

          RecordHandle handle = curPage.getRecordHandleAtSlot(slot);

          // If the portion we just updated is the last portion then
                    // there cannot be any updates to do.
          if (rh.hasOverflow())
                    {
            // We have to carry across the overflow information
            // from the current record, if any.
            nextPage = rh.getOverflowPage();
            id = rh.getOverflowId();

            // find the next starting column before unlatching page
            startColumn =
                            RowUtil.nextColumn(
                                row, validColumns, endFieldExclusive);
          }
                    else
                    {
            startColumn = -1;
            nextPage = 0;
          }


          // After the update is done, see if this row piece has
          // shrunk in curPage if no other row pieces have shrunk so
          // far.  In head page, need to respect minimumRecordSize.
          // In overflow page, only need to respect
          // RawStoreFactory.MINIMUM_RECORD_SIZE_DEFAULT
          // Don't bother with temp container.
          if (!rowHasReservedSpace && headRowHandle != null &&
            curPage != null && !owner.isTemporaryContainer())
          {
            rowHasReservedSpace =
                            curPage.checkRowReservedSpace(slot);
          }


          // insert the record portion on a new overflow page at slot
                    // 0 this will automatically handle any overflows in
          // this new portion

          // BasePage op = getNewOverflowPage();

                    BasePage op =
                        curPage.getOverflowPageForInsert(
                            slot,
                            newRow,
                            newColumnList,
                            nextColumn);

          // We have all the information from this page so unlatch it
          if (curPage != this)
                    {
            curPage.unlatch();
            curPage = null;
          }

          byte mode = Page.INSERT_OVERFLOW;
          if (nextPage != 0)
            mode |= Page.INSERT_FOR_SPLIT;

          RecordHandle nextPortionHandle =
            nextPage == 0 ? null :
            owner.makeRecordHandle(nextPage, id);

          // RESOLVED (sku):  even though we would like to roll back
                    // these inserts with PURGE rather than with delete,
                    // we have to delete because if we purge the last row
          // from an overflow page, the purge will queue a post
                    // commit to remove the page.
          // While this is OK with long columns, we cannot do this
                    // for long rows because long row overflow pages can be
                    // shared by more than one long rows, and thus it is unsafe
          // to remove the page without first latching the head page.
                    // However, the insert log record do not have the head
                    // row's page number so the rollback cannot put that
          // information into the post commit work.
          RecordHandle portionHandle =
            op.insertAllowOverflow(
                            0, newRow, newColumnList, nextColumn, mode, 100,
                            nextPortionHandle);

          // Update the previous record header to point to new portion
          if (curPage == this)
            updateOverflowDetails(this, handle, portionHandle);
          else
            updateOverflowDetails(handle, portionHandle);
          op.unlatch();
        }
                else
                {

          // See earlier comments on checking row reserved space.
          if (!rowHasReservedSpace    &&
                        headRowHandle != null   &&
            curPage != null         &&
                        !owner.isTemporaryContainer())
                    {
            rowHasReservedSpace =
                            curPage.checkRowReservedSpace(slot);
          }


          // find the next starting column before we unlatch the page
          startColumn =
                        rh.hasOverflow() ?
                            RowUtil.nextColumn(
                                row, validColumns, endFieldExclusive) : -1;
        }

        // have we completed this update?
        if (startColumn == -1) {

          if ((curPage != this) && (curPage != null))
            curPage.unlatch();
          break;    // break out of the for loop
        }
      }

      if (nextPage == -1)
            {
        if (SanityManager.DEBUG)
                {
          SanityManager.ASSERT(
                        curPage != null,
                        "Current page is null be no overflow information has been obtained");
        }

        // Get the next page info while we still have the page
        // latched.
        nextPage = rh.getOverflowPage();
        id = rh.getOverflowId();
      }
     
      if ((curPage != this) && (curPage != null))
        curPage.unlatch();

View Full Code Here


  {
    // If this is a head row piece, first take care of the entire overflow
    // row chain.  Don't need to worry about long column because they are
    // not in place updatable.
    if (isOverflowPage() == false) {
      StoredRecordHeader recordHeader = getHeaderAtSlot(slot);

      while (recordHeader.hasOverflow()) {
        StoredPage nextPageInRowChain =
          getOverflowPage(recordHeader.getOverflowPage());

        if (SanityManager.DEBUG)
          SanityManager.ASSERT(nextPageInRowChain != null);

        try {
          int nextId = recordHeader.getOverflowId();
          int nextSlot = getOverflowSlot(nextPageInRowChain, recordHeader);

          nextPageInRowChain.compactRecord(t, nextSlot, nextId);

          // Follow the next long row pointer.
View Full Code Here

            }
    }

    try
        {
      StoredRecordHeader recordHeader = getHeaderAtSlot(slot);
      int numberFields =
                recordHeader.getNumberFields();

      if (SanityManager.DEBUG)
            {
        if ((numberFields > 2) || (numberFields < 1))
                {
          SanityManager.THROWASSERT(
            "longColumn record header must have 1 or 2 fields." +
                        " numberFields = " + numberFields);
                }
      }

      if (numberFields != 2) // End of column chain.
        return null;

      // these reads are always against the page array
      ArrayInputStream lrdi = rawDataIn;

      // The 2nd field is the pointer to the next page in column chain.

      int offset = getRecordOffset(slot) + recordHeader.size();
      lrdi.setPosition(offset);

      // skip the first field
      skipField(lrdi);
View Full Code Here

        return(logOverflowRecord(slot, spaceAvailable, out));
      }   

            int                numberFields = 0;
            StoredRecordHeader recordHeader;

      if (forInsert)
            {
        recordHeader = new StoredRecordHeader();
      }
            else
            {
        // Get a full copy of the record header since we might change
                // it,  and we can't modify the one on the page
        recordHeader =
                    new StoredRecordHeader(getHeaderAtSlot(slot));

        // an update always starts at the first column on this page
        startColumn = recordHeader.getFirstField();
      }

      if (validColumns == null)
            {
                // all columns in row[] are valid, we will be logging them all.

        numberFields = row.length - startColumn;
            }
      else
            {
                // RESOLVE (mikem) - counting on validColumns.length may be bad
                // for performance.

        for (int i = validColumns.getLength() - 1;
                     i >= startColumn;
                     i--)
                {
          if (validColumns.isSet(i))
                    {
            numberFields = i + 1 - startColumn;
            break;
          }
        }
      }

      int onPageNumberFields = -1; // only valid for update

      if (forInsert)
            {
        recordHeader.setId(recordId);
        recordHeader.setNumberFields(numberFields);
      }
            else
            {
        // an update

        onPageNumberFields = recordHeader.getNumberFields();

        if (numberFields > onPageNumberFields)
                {
          // number of fields *might* be increasing
          if (recordHeader.hasOverflow())
                    {
            // other fields will be handled in next portion update
                       
            numberFields = onPageNumberFields;
          }
                    else
                    {
            // number of fields is increasing

            recordHeader.setNumberFields(numberFields);
          }
        }
                else if (numberFields < onPageNumberFields)
                {
          if (validColumns == null)
                    {
            // number of fields is decreasing,
            // but only allowed when the complete
            // row is being updated.
            recordHeader.setNumberFields(numberFields);

            // RESOLVE -
                        // need some post commit work if row has overflow

            // if (recordHeader.hasOverflow()) {
            // remove overflow portion after commit.
            // }

          }
                    else
                    {
            // we process all the fields, the unchanged ones
            // at the end will have a single byte written out
            // indicating they are unchanged (nonexistent)
            numberFields = onPageNumberFields;
          }
        }
      }

      int endFieldExclusive = startColumn + numberFields;

      if (realStartColumn >= endFieldExclusive)
            {
        // The realStartColumn is greater than the last column we need
                // to log, so we are done.
        return (-1);
      }

      if ((insertFlag & Page.INSERT_DEFAULT) != Page.INSERT_DEFAULT)
            {
                // if this is not logging the part of the row being inserted
                // on the main page, then use startColumn as first field.
        recordHeader.setFirstField(startColumn);
      }

            // what column to start with?

      int firstColumn = realStartColumn;
      if (realStartColumn == (-1))
            {
                // logging on the head page.

        int recordHeaderLength = recordHeader.write(logicalDataOut);

        spaceAvailable -= recordHeaderLength;
        if (spaceAvailable < 0)
                {
                    // ran out of space just writing the record header.
                    throw new NoSpaceOnPage(isOverflowPage());
                }

        firstColumn = startColumn;
      }


      boolean monitoringOldFields = false;
            int validColumnsSize =
                (validColumns == null) ? 0 : validColumns.getLength();
           
      if (validColumns != null)
            {
        if (!forInsert)
                {
          // we monitor the length of the old fields by skipping them
          // but only on a partial update.
          if ((validColumns != null) &&
                        (firstColumn < (startColumn + onPageNumberFields)))
                    {
            rawDataIn.setPosition(
                            getFieldOffset(slot, firstColumn));

            monitoringOldFields = true;
          }
        }
      }

      int lastSpaceAvailable              = spaceAvailable;
      int recordSize                      = 0;
      int lastColumnPositionAllowOverflow = out.getPosition();
      int lastColumnAllowOverflow         = startColumn;

      if (spaceAvailable > OVERFLOW_POINTER_SIZE)
        lastColumnPositionAllowOverflow = -1;
      int columnFlag = COLUMN_FIRST;

      for (int i = firstColumn; i < endFieldExclusive; i++)
            {
                Object              ref          = null;
        boolean             ignoreColumn = false;


                // should we log this column or not?
        if ((validColumns == null) ||
                    (validColumnsSize > i && validColumns.isSet(i)))
                {
          if (i < row.length)
            ref = row[i];
        }
                else if (!forInsert)
                {
          // field is not supplied, log as non-existent
          ignoreColumn = true;
        }

        if (spaceAvailable > OVERFLOW_POINTER_SIZE)
                {
          lastColumnPositionAllowOverflow = out.getPosition();
          lastColumnAllowOverflow         = i;
        }

        lastSpaceAvailable = spaceAvailable;

        if (ignoreColumn)
                {
          if (SanityManager.DEBUG)
                    {
            SanityManager.ASSERT(
                            ref == null,
                            "ref should be null for an ignored column");

            SanityManager.ASSERT(
                            validColumns != null,
                            "validColumns should be non-null for ignored col");
          }

          if (i < (startColumn + onPageNumberFields))
                    {
            if (SanityManager.DEBUG)
                        {
              SanityManager.ASSERT(
                                monitoringOldFields,
                                "monitoringOldFields must be true");
            }

            // need to keep track of the old field lengths
            // as they are remaining in the row.
            int oldOffset = rawDataIn.getPosition();
            skipField(rawDataIn);
            int oldFieldLength =
                            rawDataIn.getPosition() - oldOffset;

            if (oldFieldLength <= spaceAvailable)
                        {
                            //  if field doesn't fit,
                            //      spaceAvailable must be left unchanged.

              logColumn(
                                null, 0, out, Integer.MAX_VALUE,
                                COLUMN_NONE, overflowThreshold);

              spaceAvailable -= oldFieldLength;
            }

          }
                    else
                    {
            // this is an update that is increasing the number of
                        // columns but not providing any value, strange ...

            spaceAvailable =
                            logColumn(
                                null, 0, out, spaceAvailable,
                                columnFlag, overflowThreshold);
          }

        }
                else
                {
                    // ignoreColumn is false, we are logging this column.

          if (monitoringOldFields &&
                        (i < (startColumn + onPageNumberFields)))
                    {
            // skip the old version of the field so that
            // rawDataIn is correctly positioned.
            skipField(rawDataIn);
          }


          try
                    {
            if (ref == null)
                        {
                            // no new value to provide, use the on page value.
              spaceAvailable =
                                logColumn(
                                    null, 0, out, spaceAvailable,
                                    columnFlag, overflowThreshold);
                        }
            else
                        {
                            // log the value provided in the row[i]
              spaceAvailable =
                                logColumn(
                                    row, i, out, spaceAvailable,
                                    columnFlag, overflowThreshold);
                        }

          }
                    catch (LongColumnException lce)
                    {
                        // logColumn determined that the column would not fit
                        // and that the column length exceeded the long column
                        // threshold so turn this column into a long column.
                       

            if ((insertFlag & Page.INSERT_DEFAULT) ==
                                Page.INSERT_DEFAULT)
                        {
                            // if default insert, just throw no space exception.

              // if the lce has throw the column as an InputStream,
              // in the following 2 situations
              //    1. If column came in 'row[i]' as InputStream
              //    2. If the object stream of 'row[i]' is not
                            //       null, which means that the object state of
                            //       the column is null.
                            //
              // we need to set the original InputStream column to
                            // the column that has been thrown by lce.  It is a
                            // store formated InputStream which remembers all
                            // the bytes that has been read, but not yet stored.
                            // Therefore, we will not lose any bytes.
              //
              // In any other situation, we should not change the
                            // state of the column,
              // i.e. if 'row[i]' has an object state, it should
                            // not be turned into an InputStream.

              if ((lce.getColumn() instanceof InputStream)
                  && (row[i] instanceof StreamStorable) )
                            {
                if ((row[i] instanceof InputStream) ||
                                    (((StreamStorable) row[i]).returnStream()
                                         != null) )
                                {
                                    // change state of stream so that it uses
                                    // the stream just created by the lce -
                                    // which is remembering the bytes it has
                                    // already read from the stream but couldn't
                                    // log as there was not enough room on
                                    // current page.

                  ((StreamStorable) row[i]).setStream(
                                                (InputStream) lce.getColumn());
                }
              }

              throw new NoSpaceOnPage(isOverflowPage());
            }

            // When one of the following two conditions is true,
            // we will allow the insert of the long column:
                        //
            // 1.  if this is the last field,
                        //      and overflow field header fits on page.
            // 2.  if it is not the last field,
                        //      and overflow field header fits on page (for col)
                        //      and another overflow ptr fits (for row).
                        //     
                        //

            if (((spaceAvailable >= OVERFLOW_PTR_FIELD_SIZE) &&
                             (i == (endFieldExclusive - 1))) ||
                            ((spaceAvailable >= (OVERFLOW_PTR_FIELD_SIZE * 2))&&
                             (i < (endFieldExclusive - 1))))
                        {
              // If the column is a long column, it must be a
                            // InputStream.  We have made the input stream into
                            // a RememberBytesInputStream, have to set the
                            // column to that, in order to preserve the bytes
              // we already read off the stream.

              // caught a long column exception,
                            // set the variables, and rethrow the error
              out.setBeginPosition(beginPosition);
              lce.setExceptionInfo(out, i, spaceAvailable);
              throw (lce);
            }
          }
        }

        int nextColumn;

        recordSize += (lastSpaceAvailable - spaceAvailable);
        boolean recordIsLong =
                    (overflowThreshold == 100) ?
                        false : isLong(recordSize, overflowThreshold);

        // get the no overflow case out of the way asap
        if ((lastSpaceAvailable == spaceAvailable) || recordIsLong)
                {
          if ((insertFlag & Page.INSERT_DEFAULT) ==
                            Page.INSERT_DEFAULT)
                    {
            throw new NoSpaceOnPage(isOverflowPage());
          }

          if (recordIsLong)
                    {
                        // if the record is long because of threshold,
                        // then, we need to reset the logicalOut.
                        // set position to the end of the previous field

            out.setPosition(out.getPosition() - recordSize);
          }

          // did not write this column
          nextColumn = i;
        }
                else
                {
          // assume that all fields will be written to this page.
          nextColumn = endFieldExclusive;
        }

        // See if we have enough room to write an overflow field if the
                // row needs to overflow.  We need overflow if we need to
                // write another portion or another portion already exists and
                // we will need to point to it.

        if ((lastSpaceAvailable == spaceAvailable) ||
          ((insertFlag & Page.INSERT_FOR_SPLIT) ==
                         Page.INSERT_FOR_SPLIT))
                {
          // The current row has filled the page.

          if (spaceAvailable <= OVERFLOW_POINTER_SIZE)
                    {
            if ((i == startColumn) ||
                            (lastColumnPositionAllowOverflow < 0)) 
                        {
              // not enough room for the overflow recordheader,
                            // and this is the first column on this page so
                            // need to try another page.
              throw new NoSpaceOnPage(isOverflowPage());
            }
                        else
                        {
              // we need to go back to the last column
              // that left enough room for an overflow pointer.

              out.setPosition(lastColumnPositionAllowOverflow);
              nextColumn = lastColumnAllowOverflow;
            }
          }
        }

        if (nextColumn < endFieldExclusive)
                {
                    // If the number of cols has been reduced.

          int actualNumberFields = nextColumn - startColumn;

          // go back and update that numberFields in recordHeader.
          // no need to update spaceAvailable here, because if we are
                    // here, we will be returning any way, and spaceAvailable
                    // will be thrown away.

          int oldSize = recordHeader.size();
          recordHeader.setNumberFields(actualNumberFields);

          int newSize = recordHeader.size();
         
          // now we are ready to write the new record header.
          int endPosition = out.getPosition();

          if (oldSize > newSize)
                    {
            // if the old size is bigger than the new size, then
                        // leave extra bytes at the beginning of byte stream.

            int delta = oldSize - newSize;
            out.setBeginPosition(beginPosition + delta);
            out.setPosition(beginPosition + delta);
          }
                    else if (newSize > oldSize)
                    {
            out.setPosition(beginPosition);

          }
                    else
                    {
            out.setBeginPosition(beginPosition);
            out.setPosition(beginPosition);
          }

          int realLen = recordHeader.write(logicalDataOut);
          if (SanityManager.DEBUG)
                    {
            if ((realLen + (oldSize - newSize)) != oldSize)
                        {
              SanityManager.THROWASSERT(
View Full Code Here

    throws StandardException
    {
    if (SanityManager.DEBUG)
      SanityManager.ASSERT(columnList != null);

    StoredRecordHeader rh = getHeaderAtSlot(slot);

    int endFieldExclusive = rh.getFirstField() + rh.getNumberFields();

    // first see if any fields are not being modified
    boolean needSave = false;
    int columnListSize = columnList.size();
    for (int i = startColumn; i < endFieldExclusive; i++)
View Full Code Here

    LimitObjectInput    in,
    Object[]            row)
    throws StandardException, IOException
  {

    StoredRecordHeader recordHeader = new StoredRecordHeader();
    recordHeader.read(in);
    readRecordFromStream(
            row,
            row.length - 1,
            (int[]) null,
            (int[]) null,
View Full Code Here

    throws StandardException, IOException
  {
    int                 slot       =
            findRecordById(fetchStream.getOverflowId(), FIRST_SLOT_NUMBER);

    StoredRecordHeader recordHeader = getHeaderAtSlot(slot);

    int offset       = getRecordOffset(slot);
    int numberFields = recordHeader.getNumberFields();

    if (SanityManager.DEBUG)
        {
      if ((numberFields > 2) || (numberFields < 1))
            {
        SanityManager.THROWASSERT(
          "longColumn record header must have 1 or 2 fields." +
                    "numberFields = " + numberFields);
            }
    }

    rawDataIn.setPosition(offset + recordHeader.size());

    int fieldStatus     =
            StoredFieldHeader.readStatus(rawDataIn);
    int fieldDataLength =
            StoredFieldHeader.readFieldDataLength(
View Full Code Here

      // in the long column portion on the new page there will be 1 field
            // if the portion fits on the page (2 if it needs another pointer
            // to continue to yet another page).
      int numberFields = 1;

      StoredRecordHeader recordHeader =
                new StoredRecordHeader(recordId, numberFields);

      int recordHeaderLength = recordHeader.write(logicalDataOut);

      spaceAvailable -= recordHeaderLength;

      if (spaceAvailable < 0)
            {
View Full Code Here

    DynamicByteArrayOutputStream  out)
    throws StandardException, IOException
  {
    setOutputStream(out);
   
    StoredRecordHeader pageRecordHeader = getHeaderAtSlot(slot);
       
        StoredRecordHeader  overflow_rh = getOverFlowRecordHeader();
        overflow_rh.setOverflowFields(pageRecordHeader);

    if (SanityManager.DEBUG)
        {
      SanityManager.ASSERT(overflow_rh.getOverflowPage() != 0);
    }

    /*
    // #1 situation,
    // we want to update the header to just an overflow pointer with no data
    // so, update the recordHeader, and we are done...
    if (!overflow_rh.isPartialOverflow()) {
      // this recordHeader becomes just a overflow pointer,
      // we need to make sure that the number of fields is set to 0.
      overflow_rh.setNumberFields(0);
     
      spaceAvailable -= overflow_rh.write(logicalDataOut);

      if (spaceAvailable < 0) {
        throw new NoSpaceOnPage(isOverflowPage());
      }

      resetOutputStream();

      return (-1);
    }
    */

    // #2 situation,
    // we want to only update the recordheader of the page, while leaving
        // the data of the record on the page.  Just update the header part and
        // then arrange for the data part to move to after the new header.

    int oldSize = pageRecordHeader.size();
    int newSize = overflow_rh.size();

    if (oldSize < newSize)
        {
      // need extra room...
      int delta = newSize - oldSize;
      if (spaceAvailable < delta)
            {
        throw new NoSpaceOnPage(isOverflowPage());
      }
    }

    // write the new overflow_rh for the record.
    overflow_rh.write(logicalDataOut);

    // now, log the data
    logRecordDataPortion(
            slot, LOG_RECORD_DEFAULT, pageRecordHeader,
            (FormatableBitSet) null, logicalDataOut, (RecordHandle)null);
View Full Code Here

    FormatableBitSet         validColumns,
    OutputStream    out,
    RecordHandle    headRowHandle)
    throws StandardException, IOException
  {
    StoredRecordHeader recordHeader = getHeaderAtSlot(slot);

    if (recordId != recordHeader.getId())
        {
      // the record is being logged under a different identifier,
      // write it out with the correct identifier
      StoredRecordHeader newRecordHeader =
                new StoredRecordHeader(recordHeader);

      newRecordHeader.setId(recordId);

      newRecordHeader.write(out);
      newRecordHeader = null;
    }
        else
        {
      // write the original record header
View Full Code Here

TOP

Related Classes of org.apache.derby.impl.store.raw.data.StoredRecordHeader$OverflowInfo

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.