Package org.apache.derby.iapi.services.io

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


  }

  public DynamicByteArrayOutputStream getLogBuffer() {

    if (logBuffer == null) {
      logBuffer = new DynamicByteArrayOutputStream(1024);
    } else {
      logBuffer.reset();
    }

    return logBuffer;
View Full Code Here

      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

    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

        byte[] buffer = null;
        int length = 0;

        try {
            DynamicByteArrayOutputStream dbaos = new DynamicByteArrayOutputStream();
            ObjectOutputStream oos = new ObjectOutputStream( dbaos );

            oos.writeObject( val );

            buffer = dbaos.getByteArray();
            length = dbaos.getUsed();
           
        } catch(IOException e)
        {
            agent.markCommunicationsFailure
                ( e,"DDMWriter.writeUDT()", "", e.getMessage(), "" );
View Full Code Here

     **/
  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

  // when param set to 1, also gets the overhead for writeExternal for Storables
  protected void SF002(int param) throws StandardException, T_Fail {

    T_RowSource rowSource = new T_RowSource(500000, 13, 2, false, null);

    DynamicByteArrayOutputStream out = new DynamicByteArrayOutputStream(16384);
    FormatIdOutputStream logicalDataOut = new FormatIdOutputStream(out);

    long startms = System.currentTimeMillis();
    System.out.println("starting rowSource test, time: " + startms);
    try {

      FormatableBitSet validColumns = rowSource.getValidColumns();

      int numberFields = 0;
      if (validColumns != null) {
        for (int i = validColumns.size() - 1; i >= 0; i--) {
          if (validColumns.get(i)) {
            numberFields = i + 1;
            break;
          }
        }
      }

      DataValueDescriptor[] row = rowSource.getNextRowFromRowSource();
      while (row != null) {
        if (SanityManager.DEBUG) {
          SanityManager.ASSERT(row != null,
                     "RowSource returned null");
        }

        int arrayPosition = -1;
        for (int i = 0; i < numberFields; i++) {
          // write each column out
          if (validColumns.get(i)) {
            arrayPosition++;
            DataValueDescriptor column = row[arrayPosition];

            if (param == 1) {
              try {
                Storable sColumn = (Storable) column;
                if (!sColumn.isNull()) {
                  sColumn.writeExternal(logicalDataOut);
                  out.reset();
                }
              } catch (IOException ioe) {
                throw T_Fail.exceptionFail(ioe);
              }
            }
View Full Code Here

    throws StandardException, IOException
  {

    if (logBuffer == null) {
      // YYZ: need to revisit this.  Do we really want to allocate this much for a buffer every time?
      logBuffer = new DynamicByteArrayOutputStream(1024); // init size 1K
    } else {
      logBuffer.reset();
    }

    int optionalDataStart = logBuffer.getPosition();
View Full Code Here

        // does the estimate think it won't fit, if not return false to avoid
        // cost of calling logRow() just to figure out if the row will fit.
        if (!allowInsert())
            return false;

        DynamicByteArrayOutputStream out = new DynamicByteArrayOutputStream();

        try
        {
            // This is a public call, start column is rawstore only. 
            // set the starting Column for the row to be 0.
View Full Code Here

        throws StandardException
    {
        if (!(spaceForInsert() && (freeSpace >= spaceNeeded)))
            return false;

        DynamicByteArrayOutputStream out = new DynamicByteArrayOutputStream();

        try
        {
            logRow(
                0, true, nextId, row, validColumns, out, startColumn,
View Full Code Here

TOP

Related Classes of org.apache.derby.iapi.services.io.DynamicByteArrayOutputStream

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.