Package org.apache.derby.iapi.types

Examples of org.apache.derby.iapi.types.SQLInteger


                    TransactionController.MODE_RECORD,
                    TransactionController.ISOLATION_SERIALIZABLE);

            for (int i = 0; i < numcols; i++)
            {
                r1.setCol(i, new SQLInteger(numcols));
            }

            // time before
            before = System.currentTimeMillis();
View Full Code Here


                TransactionController.MODE_RECORD,
                TransactionController.ISOLATION_SERIALIZABLE);

    // Create a 2 column row.
    T_AccessRow r1 = new T_AccessRow(2);
    SQLInteger c1 = new SQLInteger(1);
    SQLInteger c2 = new SQLInteger(100);
    r1.setCol(0, c1);
    r1.setCol(1, c2);

    // Get a location template
    RowLocation rowloc1 = cc.newRowLocationTemplate();
View Full Code Here

                TransactionController.MODE_RECORD,
                TransactionController.ISOLATION_SERIALIZABLE);

    // Create a 2 column row.
    T_AccessRow r1 = new T_AccessRow(2);
    SQLInteger c1 = new SQLInteger(1);
    SQLInteger c2 = new SQLInteger(100);
    r1.setCol(0, c1);
    r1.setCol(1, c2);

    // Get a location template
    RowLocation rowloc1 = cc.newRowLocationTemplate();
View Full Code Here

    int                   isolation_level)
    throws StandardException, T_Fail
  {
    // Create a 2 column row.
    T_AccessRow r1 = new T_AccessRow(2);
    SQLInteger c1 = new SQLInteger(1);
    SQLInteger c2 = new SQLInteger(100);
    r1.setCol(0, c1);
    r1.setCol(1, c2);

    // Create a heap conglomerate.
    long orig_conglomid =
            tc.createConglomerate(
                "heap",       // create a heap conglomerate
                r1.getRowArray(),
        null,   // column sort order not required for heap
                null,   // default collation
                null,         // default properties
                TransactionController.IS_DEFAULT);       // not temporary

        // add rows 1 and 2
        ConglomerateController cc =
            tc.openConglomerate(
                orig_conglomid,
                false,
                TransactionController.OPENMODE_FORUPDATE,
                TransactionController.MODE_RECORD,
                TransactionController.ISOLATION_SERIALIZABLE);

        // insert (1, 100)
    r1.setCol(0, new SQLInteger(1));
    r1.setCol(1, new SQLInteger(100));
        cc.insert(r1.getRowArray());

        // insert (2, 200)
    r1.setCol(0, new SQLInteger(2));
    r1.setCol(1, new SQLInteger(200));
        cc.insert(r1.getRowArray());

        // insert (3, 300)
    r1.setCol(0, new SQLInteger(3));
    r1.setCol(1, new SQLInteger(300));
        cc.insert(r1.getRowArray());

        cc.close();

        tc.commit();
       
    REPORT("(updatelocks ending.)");

    ScanController sc = tc.openScan(
      orig_conglomid,
      false, // don't hold
      (TransactionController.OPENMODE_FORUPDATE |
       TransactionController.OPENMODE_USE_UPDATE_LOCKS),
            TransactionController.MODE_RECORD,
            TransactionController.ISOLATION_SERIALIZABLE,
      (FormatableBitSet) null, // all columns, all as objects
      null, // start position - first row in conglomerate
            0,    // unused if start position is null.
      null, // qualifier - accept all rows
      null, // stop position - last row in conglomerate
            0);   // unused if stop position is null.

        int key_value;

        boolean found_row_2 = false;

        while (sc.next())
        {
            sc.fetch(r1.getRowArray());

            key_value = ((SQLInteger) r1.getCol(0)).getInt();

            switch(key_value)
            {
                case 1:
                {
                    // delete first row
                    sc.delete();
                    break;
                }
                   
                   
                case 2:
                {
                    // leave second alone - no update, lock will get coverted
                    // down.
                    found_row_2 = true;
                    break;
                }

                case 3:
                {
                    // update the third row.
                    T_AccessRow update_row = new T_AccessRow(2);
                    r1.setCol(0, new SQLInteger(30));
                    r1.setCol(1, new SQLInteger(3000));
                    sc.replace(r1.getRowArray(), null);
                    break;
                }

                default:
                {
                    throw T_Fail.testFailMsg(
                        "(updatelock) bad row value found in table.");
                }
            }
           
        }

        if (!found_row_2)
            throw T_Fail.testFailMsg(
                "(updatelock) did not find row in first scan.");

        // reposition the scan
    sc.reopenScan(
      null, // start position - first row in conglomerate
            0,    // unused if start position is null.
      null, // qualifier - accept all rows
      null, // stop position - last row in conglomerate
            0);   // unused if stop position is null.


        found_row_2 = false;

        while (sc.next())
        {
            sc.fetch(r1.getRowArray());

            key_value = ((SQLInteger) r1.getCol(0)).getInt();

            switch(key_value)
            {
                case 2:
                {
                    // leave second alone - no update, lock will get coverted
                    // down.
                    found_row_2 = true;

                    break;
                }

                case 30:
                {
                    // update the third row.
                    T_AccessRow update_row = new T_AccessRow(2);
                    r1.setCol(0, new SQLInteger(40));
                    r1.setCol(1, new SQLInteger(4000));
                    sc.replace(r1.getRowArray(), null);
                    break;
                }

                default:
                {
                    throw T_Fail.testFailMsg(
                        "(updatelock) bad row value found in table.");
                }
            }
           
        }

        if (!found_row_2)
            throw T_Fail.testFailMsg(
                "(updatelock) did not find row in second scan.");

        sc.close();

        tc.commit();

        // try the scan after the first xact has completed.

    sc = tc.openScan(
      orig_conglomid,
      false, // don't hold
      (TransactionController.OPENMODE_FORUPDATE |
       TransactionController.OPENMODE_USE_UPDATE_LOCKS),
            TransactionController.MODE_RECORD,
            TransactionController.ISOLATION_SERIALIZABLE,
      (FormatableBitSet) null, // all columns, all as objects
      null, // start position - first row in conglomerate
            0,    // unused if start position is null.
      null, // qualifier - accept all rows
      null, // stop position - last row in conglomerate
            0);   // unused if stop position is null.

        found_row_2 = false;

        while (sc.next())
        {
            sc.fetch(r1.getRowArray());

            key_value = ((SQLInteger) r1.getCol(0)).getInt();

            switch(key_value)
            {
                case 2:
                {
                    // leave second alone - no update, lock will get coverted
                    // down.
                    found_row_2 = true;
                    break;
                }

                case 40:
                {
                    // update the third row.
                    T_AccessRow update_row = new T_AccessRow(2);
                    r1.setCol(0, new SQLInteger(30));
                    r1.setCol(1, new SQLInteger(3000));
                    sc.replace(r1.getRowArray(), null);
                    break;
                }

                default:
View Full Code Here

                TransactionController.ISOLATION_SERIALIZABLE);

        try
        {
            // should not be able to do an update in a read only transaction.
            big_row.setCol(0, new SQLInteger(1042));
      child_cc.insert(big_row.getRowArray());

      throw T_Fail.testFailMsg(
                "(nestedUserTransaction) read only xact does not allow upd.");

        }
        catch (StandardException se)
        {
            // expected exception, fall through.
            child_tc.commit();
            child_tc.destroy();
        }

        tc.commit();

        // start an update nested user transaction.
        child_tc = tc.startNestedUserTransaction(false);

        child_cc =
            child_tc.openConglomerate(
                orig_conglomid,
                false,
                TransactionController.OPENMODE_FORUPDATE,
                TransactionController.MODE_RECORD,
                TransactionController.ISOLATION_SERIALIZABLE);

        try
        {
            // should be able to do an update in a read only transaction.
            big_row.setCol(0, new SQLInteger(1043));
      child_cc.insert(big_row.getRowArray());


        }
        catch (StandardException se)
View Full Code Here

                TransactionController.MODE_RECORD,
                TransactionController.ISOLATION_SERIALIZABLE);

    // Create a row.
    T_AccessRow r1 = new T_AccessRow(1);
    SQLInteger c1 = new SQLInteger(0);
    r1.setCol(0, c1);

    // Get a location template
    RowLocation rowloc = cc.newRowLocationTemplate();
View Full Code Here

        // add 5 pages worth of data.

        for (int i = 0; i < 10; i++)
        {
            big_row.setCol(0, new SQLInteger(i));
      cc.insert(big_row.getRowArray());
        }
        cc.close();

    // Open another scan on the conglomerate.
    ScanController base_scan = tc.openScan(
      orig_conglomid,
      true, // hold cursor open across commit
      TransactionController.OPENMODE_FORUPDATE, // for update
            TransactionController.MODE_RECORD,
            TransactionController.ISOLATION_SERIALIZABLE,
      (FormatableBitSet) null, // all columns, all as objects
      null, // start position - first row in conglomerate
            0,    // unused if start position is null.
      null, // qualifier - accept all rows
      null, // stop position - last row in conglomerate
            0);   // unused if stop position is null.

        // now delete all the rows and remember the row location of the
        // last row.

        RowLocation deleted_page_rowloc = base_scan.newRowLocationTemplate();


        for (int i = 0; i < 10; i++)
        {
            base_scan.next();
            base_scan.fetchLocation(deleted_page_rowloc);
            base_scan.delete();

            tc.commit();
        }
        base_scan.close();
        tc.commit();

        // at this point the post commit thread should have reclaimed all the 5
        // pages.  Open it, at read uncommitted level.
    cc = tc.openConglomerate(
                orig_conglomid,
                false,
                0,
                TransactionController.MODE_RECORD,
                TransactionController.ISOLATION_READ_UNCOMMITTED);

        // Test heap fetch of row on page which does not exist.
        if (cc.fetch(deleted_page_rowloc, big_row.getRowArray(), null))
        {
            throw T_Fail.testFailMsg(
                "(readUncommitted) fetch should ret false for reclaimed page.");
        }
            
        // Test heap replace of row on page which does not exist.
        FormatableBitSet   update_desc = new FormatableBitSet(1);
        if (cc.replace(deleted_page_rowloc, big_row.getRowArray(), update_desc))
        {
            throw T_Fail.testFailMsg(
                "(readUncommitted) delete should ret false for reclaimed page.");
        }
      
        // Test heap fetch (overloaded call) of row on page which does not exist.
        if (cc.fetch(deleted_page_rowloc, big_row.getRowArray(), null, true))
        {
            throw T_Fail.testFailMsg(
                "(readUncommitted) fetch should ret false for reclaimed page.");
        }
       
        // Test heap delete of row on page which does not exist.
        if (cc.delete(deleted_page_rowloc))
        {
            throw T_Fail.testFailMsg(
                "(readUncommitted) delete should ret false for reclaimed page.");
        }
               
        cc.close();

        /*
         * TEST 2 - test heap fetch of row on page where row does not exist.
         * <p>
         * Do this by inserting enough rows to put 1 row on the 2nd page.
         * Then delete this one row, which will queue a post commit to reclaim
         * the row and page.  Then insert one more row on the same page in
         * the same xact.  Now commit the xact, which will cause post commit
         * to run which will reclaim the row but not the page.  Then try and
         * fetch the row which was deleted.
         */

        // string column will be 1500 bytes, allowing 2 rows per page to fit.
        SQLChar stringcol = new SQLChar();
        stringcol.setValue(T_AccessFactory.repeatString("012345678901234", 100));
        big_row.setCol(1, stringcol);

    // Create a heap conglomerate.
    orig_conglomid =
            tc.createConglomerate(
                "heap",       // create a heap conglomerate
                big_row.getRowArray(),
        null,   // column sort order not required for heap
                null,   // default collation
                null,         // default properties
                TransactionController.IS_DEFAULT);       // not temporary

    cc = 
            tc.openConglomerate(
                orig_conglomid,
                false,
                TransactionController.OPENMODE_FORUPDATE,
                TransactionController.MODE_RECORD,
                TransactionController.ISOLATION_READ_UNCOMMITTED);

        // add 3 rows, should result in 1 row on second page.

        for (int i = 0; i < 3; i++)
        {
            big_row.setCol(0, new SQLInteger(i));
      cc.insert(big_row.getRowArray());
        }

    // Open another scan on the conglomerate.
    base_scan = tc.openScan(
      orig_conglomid,
      true, // hold cursor open across commit
      TransactionController.OPENMODE_FORUPDATE, // for update
            TransactionController.MODE_RECORD,
            TransactionController.ISOLATION_SERIALIZABLE,
      (FormatableBitSet) null, // all columns, all as objects
      null, // start position - first row in conglomerate
            0,    // unused if start position is null.
      null, // qualifier - accept all rows
      null, // stop position - last row in conglomerate
            0);   // unused if stop position is null.

        // now delete all the rows and remember the row location of the
        // last row.

        RowLocation deleted_row_rowloc  = base_scan.newRowLocationTemplate();

        for (int i = 0; i < 3; i++)
        {
            base_scan.next();
            base_scan.fetchLocation(deleted_row_rowloc);
            base_scan.delete();
        }

        // insert another row on page 2 to make sure page does not go away.
        cc.insert(big_row.getRowArray());

        cc.close();
        base_scan.close();
        tc.commit();

        // at this point the post commit thread should have reclaimed all the
        // deleted row on page 2, but not the page.
        //
    // Open it, at read uncommitted level.
    cc = tc.openConglomerate(
                orig_conglomid,
                false,
                0,
                TransactionController.MODE_RECORD,
                TransactionController.ISOLATION_READ_UNCOMMITTED);

        // the following will be attempting to fetch a row which has been
        // reclaimed by post commit, on an existing page.

        // test heap fetch of row on page where row does not exist.
        if (cc.fetch(deleted_row_rowloc, big_row.getRowArray(), null))
        {
            throw T_Fail.testFailMsg(
                "(readUncommitted) fetch should ret false for reclaimed row.");
        }
       
        // test heap replace of row on page where row does not exist.
        if (cc.replace(deleted_page_rowloc, big_row.getRowArray(), update_desc))
        {
            throw T_Fail.testFailMsg(
                "(readUncommitted) delete should ret false for reclaimed page.");
        }

        // test heap fetch (overloaded) of row on page where row does not exist.
        if (cc.fetch(deleted_page_rowloc, big_row.getRowArray(), null, true))
        {
            throw T_Fail.testFailMsg(
                "(readUncommitted) fetch should ret false for reclaimed page.");
        }
       
        // test heap delete of row on page where row does not exist.
        if (cc.delete(deleted_page_rowloc))
        {
            throw T_Fail.testFailMsg(
                "(readUncommitted) delete should ret false for reclaimed page.");
        }

        cc.close();

        /*
         * TEST 3 - test heap scan fetch of row on page prevents page from
         *          disappearing, but handles row being deleted.
         * <p>
         * A heap scan will maintain a scan lock on a page even if it is doing
         * a read uncommitted scan.  This will prevent the row/page from being
         * reclaimed by post commit while the scan is positioned on the page.
         * This presents no other concurrency issues for read uncommitted, it
         * should be invisible to the user (deletes can still happen and the
         * read uncommitted scanner will not block anyone).
         *
         * You need to at least get to the 2nd page, because the 1st page is
         * never totally reclaimed and deleted by the system in a heap (it has
         * some internal catalog information stored internally in row "0").
         */

        big_row = new T_AccessRow(2);
       
        big_row.setCol(1, new SQLChar(twok_string));

    // Create a heap conglomerate.
    orig_conglomid =
            tc.createConglomerate(
                "heap",       // create a heap conglomerate
                big_row.getRowArray(),
        null,   // column sort order not required for heap
                null,   // default collation
                null,         // default properties
                TransactionController.IS_DEFAULT);       // not temporary

    cc = 
            tc.openConglomerate(
                orig_conglomid,
                false,
                TransactionController.OPENMODE_FORUPDATE,
                TransactionController.MODE_RECORD,
                TransactionController.ISOLATION_READ_UNCOMMITTED);

        // add 5 pages worth of data.

        for (int i = 0; i < 10; i++)
        {
            big_row.setCol(0, new SQLInteger(i));
      cc.insert(big_row.getRowArray());
        }
        cc.close();

    // Open scan on the conglomerate, and position it on the second page.
View Full Code Here

        "maxRows not expected to be -1");
    }

    constructorTime += getElapsedMillis(beginTime);

    positionInHashTable = new SQLInteger();
    needsRepositioning = false;
    if (isForUpdate()) {
      target = ((CursorActivation)activation).getTargetResultSet();
      extraColumns = LAST_EXTRA_COLUMN + 1;
    } else {
View Full Code Here

    throws StandardException
  {
    DataValueDescriptor[] hashRowArray = new
        DataValueDescriptor[sourceRowWidth + extraColumns];
    // 1st element is the key
    hashRowArray[0] = new SQLInteger(position);
    if (isForUpdate()) {
      hashRowArray[POS_ROWLOCATION] = rowLoc.getClone();
      hashRowArray[POS_ROWDELETED] = new SQLBoolean(false);
      hashRowArray[POS_ROWUPDATED] = new SQLBoolean(rowUpdated);
    }
View Full Code Here

    }
    positionInHashTable.setValue(currentPosition);
    DataValueDescriptor[] hashRowArray = (DataValueDescriptor[])
        ht.get(positionInHashTable);
    RowLocation rowLoc = (RowLocation) hashRowArray[POS_ROWLOCATION];
    ht.remove(new SQLInteger(currentPosition));
    addRowToHashTable(newRow, currentPosition, rowLoc, true);
   
    // Modify row to refer to data in the BackingStoreHashtable.
    // This allows reading of data which goes over multiple pages
    // when doing the actual update (LOBs). Putting columns of
View Full Code Here

TOP

Related Classes of org.apache.derby.iapi.types.SQLInteger

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.