Examples of DynamicByteArrayOutputStream


Examples of org.apache.derby.iapi.services.io.DynamicByteArrayOutputStream

                 (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.
View Full Code Here

Examples of org.apache.derby.iapi.services.io.DynamicByteArrayOutputStream

                 (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.
View Full Code Here

Examples of org.apache.derby.iapi.services.io.DynamicByteArrayOutputStream

    if (SanityManager.DEBUG) {
      SanityManager.ASSERT(this.page != null);
    }

    DynamicByteArrayOutputStream logBuffer = t.getLogBuffer();
    int optionalDataStart = logBuffer.getPosition();

    if (SanityManager.DEBUG) {
      SanityManager.ASSERT(optionalDataStart == 0,
        "Buffer for writing the optional data should start at position 0");
    }

    if (undo != null)
      this.page.logRecord(doMeSlot, BasePage.LOG_RECORD_DEFAULT,
                recordId,  (FormatableBitSet) null, logBuffer,
                (RecordHandle)null);
   
    int optionalDataLength = logBuffer.getPosition() - optionalDataStart;

    if (SanityManager.DEBUG) {
      if (optionalDataLength != logBuffer.getUsed())
        SanityManager.THROWASSERT("wrong optional data length, optionalDataLength = "
          + optionalDataLength + ", logBuffer.getUsed() = " + logBuffer.getUsed());
    }

    // set the position to the beginning of the buffer
    logBuffer.setPosition(optionalDataStart);

    this.preparedLog = new ByteArray(logBuffer.getByteArray(), optionalDataStart,
      optionalDataLength);

  }
View Full Code Here

Examples of org.apache.derby.iapi.services.io.DynamicByteArrayOutputStream

    MT - not needed for constructor
  */
  public FileLogger(LogToFile logFactory) {

    this.logFactory = logFactory;
    logOutputBuffer = new DynamicByteArrayOutputStream(1024); // init size 1K
    logicalOut = new FormatIdOutputStream(logOutputBuffer);

    // logIn and logOutputBuffer must share the same buffer because they
    // combined to form an IO stream to access the same log record.
    //
View Full Code Here

Examples of org.apache.derby.iapi.services.io.DynamicByteArrayOutputStream

    if (SanityManager.DEBUG) {
      SanityManager.ASSERT(this.page != null);
    }

    DynamicByteArrayOutputStream localLogBuffer = null;
    if (logBuffer != null) {
      localLogBuffer = (DynamicByteArrayOutputStream) logBuffer;
    } else {
      realStartColumn = -1;
      realSpaceOnPage = -1;
      localLogBuffer = t.getLogBuffer();
    }
   
    if (isLongColumn) {
      this.startColumn = this.page.logLongColumn(doMeSlot, recordId,
        row[0], localLogBuffer);
    } else {
      this.startColumn = this.page.logRow(doMeSlot, true, recordId,
        row, validColumns, localLogBuffer, this.startColumn, insertFlag,
        realStartColumn, realSpaceOnPage, overflowThreshold);
    }

    int optionalDataStart = localLogBuffer.getBeginPosition();
    int optionalDataLength = localLogBuffer.getPosition() - optionalDataStart;

    this.preparedLog = new ByteArray (localLogBuffer.getByteArray(), optionalDataStart,
      optionalDataLength);
  }
View Full Code Here

Examples of org.apache.derby.iapi.services.io.DynamicByteArrayOutputStream

    if (SanityManager.DEBUG) {
      SanityManager.ASSERT(this.page != null);
    }

    DynamicByteArrayOutputStream localLogBuffer = null;
    if (logBuffer != null) {
      localLogBuffer = (DynamicByteArrayOutputStream) logBuffer;
    } else {
      realStartColumn = -1;
      realSpaceOnPage = -1;
      localLogBuffer = t.getLogBuffer();
    }
   
    if (isLongColumn) {
      this.startColumn = this.page.logLongColumn(doMeSlot, recordId,
        row[0], localLogBuffer);
    } else {
      this.startColumn = this.page.logRow(doMeSlot, true, recordId,
        row, validColumns, localLogBuffer, this.startColumn, insertFlag,
        realStartColumn, realSpaceOnPage, overflowThreshold);
    }

    int optionalDataStart = localLogBuffer.getBeginPosition();
    int optionalDataLength = localLogBuffer.getPosition() - optionalDataStart;

    this.preparedLog = new ByteArray (localLogBuffer.getByteArray(), optionalDataStart,
      optionalDataLength);
  }
View Full Code Here

Examples of org.apache.derby.iapi.services.io.DynamicByteArrayOutputStream

     **/
  public void load(RowSource rowSource)
        throws StandardException
    {
    // use this output stream to buffer rows before inserting into file.
    out                 = new DynamicByteArrayOutputStream(bufferSize);
    logicalDataOut      = new FormatIdOutputStream(out);
    boolean encrypted   = dataFactory.databaseEncrypted();

    // reserve the first dataFactory.getEncryptionBlockSize() - 1 bytes, if the database is
        // encrypted These reserved bytes will be used to pad the byte array if
View Full Code Here

Examples of org.apache.derby.iapi.services.io.DynamicByteArrayOutputStream

      boolean isLongColumns   = false;
      int     realStartColumn = -1;
      int     realSpaceOnPage = -1;

      DynamicByteArrayOutputStream logBuffer = null;

            // allocate new record id and handle
            int          recordId = curPage.newRecordIdAndBump();
      RecordHandle handle   =
                new RecordId(curPage.getPageId(), recordId, slot);

      if (curPage == this) {


        // Lock the row, if it is the very first portion of the record.
        if (handleToUpdate == null) {

                    while (!owner.getLockingPolicy().lockRecordForWrite(
                                t, handle,
                                true  /* lock is for insert */,
                                false /* don't wait for grant */)) {

                        // loop until we get a new record id we can get a lock
                        // on.  If we can't get the lock without waiting then
                        // assume the record id is owned by another xact.  The
                        // current heap overflow algorithm makes this likely,
                        // as it first try's to insert a row telling raw store
                        // to fail if it doesn't fit on the page getting a lock
                        // on an id that never makes it to disk.   The
                        // inserting transaction will hold a lock on this
                        // "unused" record id until it commits.  The page can
                        // leave the cache at this point, and the inserting
                        // transaction has not dirtied the page (it failed
                        // after getting the lock but before logging anything),
                        // another inserting transaction will then get the
                        // same id as the previous inserter - thus the loop on
                        // lock waits.
                        //
                        // The lock we request indicates that this is a lock
                        // for insert, which the locking policy may use to
                        // perform locking concurrency optimizations.

                        // allocate new record id and handle
                        recordId = curPage.newRecordIdAndBump();
                        handle   =
                            new RecordId(curPage.getPageId(), recordId, slot);
                    }
        }

        headHandle = handle;
      }

      do {

        // do this loop at least once.  If we caught a long Column,
        // then, we redo the insert with saved logBuffer.
        try {

          startColumn =
                        owner.getActionSet().actionInsert(
                            t, curPage, slot, recordId,
                            row, validColumns, (LogicalUndo) null,
                            insertFlag, startColumn, false,
                            realStartColumn, logBuffer, realSpaceOnPage,
                            overflowThreshold);
          isLongColumns = false;

        } catch (LongColumnException lce) {


          // we caught a 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 insert in the main data chain.
          logBuffer = new DynamicByteArrayOutputStream(lce.getLogBuffer());

          // step 1: insert the long column ... use the same
          // insertFlag as the rest of the row.
          RecordHandle longColumnHandle =
            insertLongColumn(curPage, lce, insertFlag);
View Full Code Here

Examples of org.apache.derby.iapi.services.io.DynamicByteArrayOutputStream

      boolean isLongColumns   = false;
      int     realStartColumn = -1;
      int     realSpaceOnPage = -1;

      DynamicByteArrayOutputStream logBuffer = null;

            // allocate new record id and handle
            int          recordId = curPage.newRecordIdAndBump();
      RecordHandle handle   =
                new RecordId(curPage.getPageId(), recordId, slot);

      if (curPage == this) {


        // Lock the row, if it is the very first portion of the record.
        if (handleToUpdate == null) {

                    while (!owner.getLockingPolicy().lockRecordForWrite(
                                t, handle,
                                true  /* lock is for insert */,
                                false /* don't wait for grant */)) {

                        // loop until we get a new record id we can get a lock
                        // on.  If we can't get the lock without waiting then
                        // assume the record id is owned by another xact.  The
                        // current heap overflow algorithm makes this likely,
                        // as it first try's to insert a row telling raw store
                        // to fail if it doesn't fit on the page getting a lock
                        // on an id that never makes it to disk.   The
                        // inserting transaction will hold a lock on this
                        // "unused" record id until it commits.  The page can
                        // leave the cache at this point, and the inserting
                        // transaction has not dirtied the page (it failed
                        // after getting the lock but before logging anything),
                        // another inserting transaction will then get the
                        // same id as the previous inserter - thus the loop on
                        // lock waits.
                        //
                        // The lock we request indicates that this is a lock
                        // for insert, which the locking policy may use to
                        // perform locking concurrency optimizations.

                        // allocate new record id and handle
                        recordId = curPage.newRecordIdAndBump();
                        handle   =
                            new RecordId(curPage.getPageId(), recordId, slot);
                    }
        }

        headHandle = handle;
      }

      do {

        // do this loop at least once.  If we caught a long Column,
        // then, we redo the insert with saved logBuffer.
        try {

          startColumn =
                        owner.getActionSet().actionInsert(
                            t, curPage, slot, recordId,
                            row, validColumns, (LogicalUndo) null,
                            insertFlag, startColumn, false,
                            realStartColumn, logBuffer, realSpaceOnPage,
                            overflowThreshold);
          isLongColumns = false;

        } catch (LongColumnException lce) {


          // we caught a 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 insert in the main data chain.
          logBuffer = new DynamicByteArrayOutputStream(lce.getLogBuffer());

          // step 1: insert the long column ... use the same
          // insertFlag as the rest of the row.
          RecordHandle longColumnHandle =
            insertLongColumn(curPage, lce, insertFlag);
View Full Code Here

Examples of org.apache.derby.iapi.services.io.DynamicByteArrayOutputStream

    if (SanityManager.DEBUG) {
      SanityManager.ASSERT(this.page != null);
    }

    DynamicByteArrayOutputStream logBuffer = t.getLogBuffer();
    int optionalDataStart = logBuffer.getPosition();

    if (SanityManager.DEBUG) {
      SanityManager.ASSERT(optionalDataStart == 0,
        "Buffer for writing optional data should start at position 0");
    }
       
    this.page.logColumn(doMeSlot, fieldId, column, logBuffer, 100); // the after image of the column
    this.page.logField(doMeSlot, fieldId, logBuffer); // the BI of the column
    if (undo != null)
    {
      // RESOLVE: we want the AFTER image of the row, not the BEFORE
      // image.   This works for now because only btree needs a logical
      // undoable updateField and it always update only the pointer field
      // to point to something else.
      //
      // But in the future, it needs to be changed.

      this.page.logRecord(doMeSlot, BasePage.LOG_RECORD_DEFAULT,
                recordId, (FormatableBitSet) null, logBuffer,
                (RecordHandle)null);
      // log the BI of the entire row

    }

    int optionalDataLength = logBuffer.getPosition() - optionalDataStart;

    if (SanityManager.DEBUG) {
      if (optionalDataLength != logBuffer.getUsed())
        SanityManager.THROWASSERT("wrong optional data length, optionalDataLength = "
          + optionalDataLength + ", logBuffer.getUsed() = " + logBuffer.getUsed());
    }

    // set the position to the beginning of the buffer
    logBuffer.setPosition(optionalDataStart);

    this.preparedLog = new ByteArray(logBuffer.getByteArray(), optionalDataStart,
      optionalDataLength);
  }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.