Package org.apache.derby.iapi.types

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


        // create the index on the "hash" base table.  The key of the index
        // is the hash code of the row key.  The second column is the
        // RowLocation of the row in the "base" table of the hash overflow.
        btreeRow =
            new DataValueDescriptor[]
                { new SQLInteger(), rowConglomerate.newRowLocationTemplate()};

        Properties btreeProps = new Properties();

        btreeProps.put("baseConglomerateId",
                String.valueOf(rowConglomerateId));
View Full Code Here


    /* 6th column is STATE (char(1)) */
        row.setColumn(SYSCONSTRAINTS_STATE,
            new SQLChar(encodeCharacteristics(deferrable, initiallyDeferred, enforced)));

    /* 7th column is REFERENCED */
    row.setColumn(SYSCONSTRAINTS_REFERENCECOUNT, new SQLInteger(referenceCount));

    return row;
  }
View Full Code Here

  {

    // We know, because this is a test program and it's only
    // used this way, that we can safely cast the arguments
    // to SQLInteger.
    SQLInteger increment = (SQLInteger) insertRow[columnId];
    SQLInteger sum = (SQLInteger) existingRow[columnId];

    // Perform the aggregation.
    sum.plus(sum, increment, sum);

    return null;
  }
View Full Code Here

                static_info,
                dynamic_info);

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

    // Get a location template
    RowLocation rowloc = cc.newRowLocationTemplate();



    // Insert the row and remember its location.
    cc.insertAndFetchLocation(r1.getRowArray(), rowloc);

        // quick test to make sure we can hash insert and find row location.
        Hashtable<RowLocation, RowLocation> test_rowloc_hash =
                new Hashtable<RowLocation, RowLocation>();
        test_rowloc_hash.put(rowloc, rowloc);

        RowLocation hash_find = test_rowloc_hash.get(rowloc);

        if (!hash_find.equals(rowloc))
            throw T_Fail.testFailMsg("(insertAndFetch) bad hash lookup 1");

        hash_find = test_rowloc_hash.remove(rowloc);

        if (!hash_find.equals(rowloc))
            throw T_Fail.testFailMsg("(insertAndFetch) bad hash lookup 2");

        hash_find = test_rowloc_hash.remove(rowloc);

        if (hash_find != null)
            throw T_Fail.testFailMsg("(insertAndFetch) bad hash lookup 3");


    // Create a new row of the same type (since the interface expects
    // the callers to be keeping the row types straight), but with
    // a different column value.
    T_AccessRow r2 = new T_AccessRow(1);
    SQLInteger c2 = new SQLInteger(0);
    r2.setCol(0, c2);

    // Fetch the stored value.
    if (!cc.fetch(rowloc, r2.getRowArray(), (FormatableBitSet) null))
        {
      throw T_Fail.testFailMsg("(insertAndFetch) fetch found no row.");
        }

        // Fetch using the fetch partial column interface
        SQLInteger c3 = new SQLInteger(0);
    FormatableBitSet singleColumn = new FormatableBitSet(1);
    singleColumn.set(0);
    DataValueDescriptor[] c3row = new DataValueDescriptor[1];
    c3row[0] = c3;

        if (!cc.fetch(rowloc, c3row, singleColumn))
        {
      throw T_Fail.testFailMsg("(insertAndFetch) fetch found no row.");
        }

    // Close the conglomerate.
    cc.close();

    // Make sure we read back the value we wrote.
    if (c2.getInt() != value)
      throw T_Fail.testFailMsg("(insertAndFetch) Fetched value != inserted value.");

        if (c3.getInt() != value)
      throw T_Fail.testFailMsg("(insertAndFetch) Fetched value != inserted value.");
   
        return true;
  }
View Full Code Here

                TransactionController.MODE_RECORD,
                TransactionController.ISOLATION_SERIALIZABLE);

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

    // Get a location template
    RowLocation rowloc = cc.newRowLocationTemplate();

    // Insert the row and remember its location.
View Full Code Here

                TransactionController.MODE_RECORD,
                TransactionController.ISOLATION_SERIALIZABLE);

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

    // Get a location template
    RowLocation rowloc = cc.newRowLocationTemplate();

    // Insert the row and remember its location.
    cc.insertAndFetchLocation(r1.getRowArray(), rowloc);

    // Update it to the second value
        DataValueDescriptor[] update_row  = new DataValueDescriptor[1];
        update_row[0] = new SQLInteger(value2);

        FormatableBitSet update_desc = new FormatableBitSet(1);
        update_desc.set(0);

    cc.replace(rowloc, update_row, update_desc);

    // Create a new row (of the same type, since the interface expects
    // the callers to be keeping the row types straight.
    T_AccessRow r2 = new T_AccessRow(1);
    SQLInteger c2 = new SQLInteger(0);
    r2.setCol(0, c2);

    // Fetch the stored value.
    if (!cc.fetch(rowloc, r2.getRowArray(), (FormatableBitSet) null))
        {
      throw T_Fail.testFailMsg("(insertAndUpdate) Fetch val not there.");
        }

    // Close the conglomerate.
    cc.close();

    // Make sure we read back the value we wrote.
    if (c2.getInt() != value2)
      throw T_Fail.testFailMsg("(insertAndUpdate) Fetch value != updated value.");
    else
      return true;
  }
View Full Code Here

    // Insert some values.
    int values[] = { 11, 22, 33, 44, 55, 66 };
    T_AccessRow row = new T_AccessRow(1);
    for (int i = 0; i < values.length; i++)
    {
      row.setCol(0, new SQLInteger(values[i]));
      if (cc.insert(row.getRowArray()) != 0)
        throw T_Fail.testFailMsg("(scanExample after insert) insert failed ");
    }

        // For test coverage call the debugging output routine - can't diff it.
        REPORT("(scanExample) debug output testing: " + tc.debugOpened());

    // Close the conglomerate.
    cc.close();

        if ((tc.countOpens(TransactionController.OPEN_TOTAL) > 0)        ||
            (tc.countOpens(TransactionController.OPEN_CONGLOMERATE) > 0) ||
            (tc.countOpens(TransactionController.OPEN_SCAN) > 0)         ||
            (tc.countOpens(TransactionController.OPEN_CREATED_SORTS) > 0)    ||
            (tc.countOpens(TransactionController.OPEN_SORT) > 0))
        {
            System.out.println("OPENED 1:\n" + tc.debugOpened());
            return(FAIL("unexpected open count."));
        }

    REPORT("(scanExample) rows inserted");

    // Correlates our position in the upcoming scan to the values array.
    int scanindex = 0;

    // Put a specific column in the row so we can look at it.
    SQLInteger col = new SQLInteger(0);
    row.setCol(0, col);

        flush_cache();

        StaticCompiledOpenConglomInfo static_info =
            tc.getStaticCompiledConglomInfo(conglomid);

    // Open a scan on the conglomerate.
    ScanController scan1 = tc.openCompiledScan(
      false, // don't hold
      0,     // not 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.
            static_info,
            tc.getDynamicCompiledConglomInfo(conglomid));

        // check out the RowCountable interface's.
       
        if (scan1.getEstimatedRowCount() != 6)
        {
            throw T_Fail.testFailMsg(
                "(scanExample) estimated row count not 6:" +
                scan1.getEstimatedRowCount());
        }

        // Test 2 - ASSERT(should be able to set arbitrary row count)

        scan1.setEstimatedRowCount(5);

        if (scan1.getEstimatedRowCount() != 5)
        {
            throw T_Fail.testFailMsg("(scanExample) estimated row count not 5");
        }


    // Iterate through and check that the rows are still there.
    while (scan1.next())
    {
      scan1.fetch(row.getRowArray());

      // Check we got the value we put in.
      if (col.getInt() != values[scanindex])
        throw T_Fail.testFailMsg("(scanExample after insert) Row "
          + scanindex
          + " should have been "
          + values[scanindex]
          + ", was "
          + col.getInt());

      scanindex++;
    }

        // make sure another next() call continues to return false.
        if (scan1.next())
            throw T_Fail.testFailMsg("(scanExample after insert) should continue to return false after reaching end of scan");

        // see if reopen scan interfaces work
    scan1.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.

        scan1.next();
        scan1.next();
        scan1.next();
        RowLocation third_row_rowloc = scan1.newRowLocationTemplate();
        scan1.fetchLocation(third_row_rowloc);

        // see if reopen scan interfaces work
    scan1.reopenScanByRowLocation(
            third_row_rowloc,
      null);

        scanindex = 2;
    while (scan1.next())
    {
      scan1.fetch(row.getRowArray());

      // Check we got the value we put in.
      if (col.getInt() != values[scanindex])
        throw T_Fail.testFailMsg("(scanExample after insert) Row "
          + scanindex
          + " should have been "
          + values[scanindex]
          + ", was "
          + col.getInt());

      scanindex++;
    }

    scan1.close();

    // Check we saw the right number of rows.
    if (scanindex != values.length)
      throw T_Fail.testFailMsg("(scanExample after insert) Expected "
        + values.length
        + "rows, got "
        + scanindex);

    REPORT("(scanExample) rows present and accounted for");

    // Open another scan on the conglomerate.
    ScanController scan2 = tc.openScan(
      conglomid,
      false, // don't hold
      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.

    // Iterate with the second scan and fiddle with the values so they
    // look like the new value array.
    int newvalues[] = { 22, 33, 444, 55, 6666 };
     while (scan2.next())
    {
      scan2.fetch(row.getRowArray());

      switch(((SQLInteger) row.getCol(0)).getInt())
      {
      case 11:
        if (!scan2.delete())
          throw T_Fail.testFailMsg("(scanExample) delete failed.");
        break;
      case 22:
      case 33:
      case 55:
        // leave these alone
        break;
      case 44:
                DataValueDescriptor[] update_row  = new DataValueDescriptor[1];
                update_row[0] = new SQLInteger(444);

                FormatableBitSet update_desc = new FormatableBitSet(1);
                update_desc.set(0);

        if (!scan2.replace(update_row, update_desc))
                {
          throw T_Fail.testFailMsg(
                        "(scanExample) partial column row replace failed.");
                }
        break;
      case 66:
        row.setCol(0, new SQLInteger(6666));
        if (!scan2.replace(row.getRowArray(), (FormatableBitSet) null))
          throw T_Fail.testFailMsg("(scanExample) replace failed.");
        break;
      default:
        throw T_Fail.testFailMsg("(scanExample) Read unexpected value.");
      }
    }
    scan2.close();

    REPORT("(scanExample) rows fiddled with");

    // Open a third scan on the conglomerate.
    ScanController scan3 = tc.openScan(
      conglomid,
      false, // don't hold
      0, // not 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.

    // Iterate through and inspect the changes.
    scanindex = 0;
    row.setCol(0, col);
    while (scan3.next())
    {
      scan3.fetch(row.getRowArray());

      REPORT("(scanExample) scan3 fetched " + col.getInt());

      // Check we got the value we put in.
      if (col.getInt() != newvalues[scanindex])
        throw T_Fail.testFailMsg("(scanExample after changes) Row "
          + scanindex
          + " should have been "
          + newvalues[scanindex]
          + ", was "
          + col.getInt());

      scanindex++;
    }
    scan3.close();

    // Open a third scan on the conglomerate.
    scan3 = tc.openScan(
      conglomid,
      false, // don't hold
      0, // not for update
            TransactionController.MODE_RECORD,
            TransactionController.ISOLATION_READ_UNCOMMITTED,
      (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.

    // Iterate through and inspect the changes.
    scanindex = 0;
    row.setCol(0, col);
    while (scan3.next())
    {
      scan3.fetch(row.getRowArray());

      REPORT("(scanExample) scan3 fetched " + col.getInt());

      // Check we got the value we put in.
      if (col.getInt() != newvalues[scanindex])
        throw T_Fail.testFailMsg("(scanExample after changes) Row "
          + scanindex
          + " should have been "
          + newvalues[scanindex]
          + ", was "
          + col.getInt());

      scanindex++;
    }
    scan3.close();
View Full Code Here

                TransactionController.MODE_RECORD,
                TransactionController.ISOLATION_SERIALIZABLE);

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

    // Get a location template
    RowLocation rowloc1 = cc.newRowLocationTemplate();

    // Insert the row and remember its location.
    cc.insertAndFetchLocation(r1.getRowArray(), rowloc1);

        // create another 1 column row. int column = 2.
    // Get a location template
        r1.setCol(0, new SQLInteger(2));
    RowLocation rowloc2 = cc.newRowLocationTemplate();

    // Insert the row and remember its location.
    cc.insertAndFetchLocation(r1.getRowArray(), rowloc2);

        // At this point the table looks like:
        // col1
        // ----
        // 1
        // 2

        // RESOLVE - currently the store can't catch the following error:
        /*
        // Test that we can't alter while it is open.
        try
        {
            tc.addColumnToConglomerate(conglomid, 1, c1);
      throw T_Fail.testFailMsg(
                "(alterTable) Allowed alter table while table was open.");
        }
        catch (StandardException t)
        {
            // expected error continue the test.
        }
        */

        // Test that we can't add data to columns that don't exist

        // Currently we only error check in debug code. 
        // RESOLVE - should this be a runtime error?
        if (SanityManager.DEBUG)
        {
            try
            {
                T_AccessRow two_column_row = new T_AccessRow(2);
                SQLInteger col1        = new SQLInteger(3);
                SQLInteger col2        = new SQLInteger(3);
                cc.insert(two_column_row.getRowArray());
                throw T_Fail.testFailMsg(
                    "(alterTable) Allowed insert of bad row.");
            }
            catch (StandardException t)
            {
                // expected error continue the test.
            }
        }

        // Test that we can't fetch data columns that don't exist

        // Currently we only error check for this in sanity code.
        // RESOLVE - (mikem) should we check for this in released runtime?
        if (SanityManager.DEBUG)
        {
            try
            {
                T_AccessRow two_column_row = new T_AccessRow(2);
                if (!cc.fetch(
                        rowloc1, two_column_row.getRowArray(), (FormatableBitSet) null))
                {
                    throw T_Fail.testFailMsg(
                        "(alterTable) Allowed fetch of bad row, bad ret val.");
                }

                throw T_Fail.testFailMsg(
                    "(alterTable) Allowed fetch of bad row.");
            }
            catch (StandardException t)
            {
                // expected error continue the test.
            }
        }

        // Test that we can't fetch data columns that don't exist
        // Currently we only error check for this in sanity code.
        // RESOLVE - (mikem) should we check for this in released runtime?
        if (SanityManager.DEBUG)
        {
            try
            {
                DataValueDescriptor[] third_column_row =
                    new DataValueDescriptor[3];

                third_column_row[2]         = new SQLInteger(3);

                FormatableBitSet   fetch_desc        = new FormatableBitSet(3);
                fetch_desc.set(2);

                if (!cc.fetch(
                        rowloc1, third_column_row, fetch_desc))
                {
                    throw T_Fail.testFailMsg(
                        "(alterTable) Allowed fetch of bad row, bad ret val.");
                }

                throw T_Fail.testFailMsg(
                    "(alterTable) Allowed fetch of bad row.");
            }
            catch (StandardException t)
            {
                // expected error continue the test.
            }
        }

        // Test that we can't replace data columns that don't exist

        // Currently we only error check for this in sanity code.
        // RESOLVE - (mikem) should we check for this in released runtime?
        if (SanityManager.DEBUG)
        {
            try
            {
                T_AccessRow two_column_row = new T_AccessRow(2);
                SQLInteger col1        = new SQLInteger(3);
                SQLInteger col2        = new SQLInteger(3);
                cc.replace(rowloc1, two_column_row.getRowArray(), null);
                throw T_Fail.testFailMsg(
                    "(alterTable) Allowed replace of bad row.");
            }
            catch (StandardException t)
            {
                // expected error continue the test.
            }
        }

        // Test that we can't replace data columns that don't exist
        if (SanityManager.DEBUG)
        {
            try
            {
                DataValueDescriptor[] second_column_row  =
                    new DataValueDescriptor[2];
                second_column_row[1]        = new SQLInteger(3);

                FormatableBitSet   update_desc        = new FormatableBitSet(2);
                update_desc.set(1);

                cc.replace(rowloc1, second_column_row, update_desc);
                throw T_Fail.testFailMsg(
                    "(alterTable) Allowed partial row update of bad column.");
            }
            catch (StandardException t)
            {
                // expected error continue the test.
            }
        }

    // Make sure commitNoSync gets executed sometimes.
        tc.commitNoSync(TransactionController.RELEASE_LOCKS);


        // now alter the conglomerate, add another int column
        tc.addColumnToConglomerate(
            conglomid, 1, c1, StringDataValue.COLLATION_TYPE_UCS_BASIC);

        // Open the table after the close done by commit.
    cc = tc.openConglomerate(
                conglomid,
                false,
                TransactionController.OPENMODE_FORUPDATE,
                TransactionController.MODE_RECORD,
                TransactionController.ISOLATION_SERIALIZABLE);

        T_AccessRow two_column_row = new T_AccessRow(2);
        SQLInteger col1        = new SQLInteger(3);
        SQLInteger col2        = new SQLInteger(3);

        // fetch the rows and make sure you get null's in new fields.
        if (!cc.fetch(
                rowloc1, two_column_row.getRowArray(), (FormatableBitSet) null))
        {
      throw T_Fail.testFailMsg(
                "(alterTable) Row not there.");
        }

        if ((((SQLInteger)two_column_row.getCol(0)).getInt() != 1) ||
            (!two_column_row.getCol(1).isNull()))
        {
      throw T_Fail.testFailMsg(
                "(alterTable) Bad column value after alter.");
        }
        if (!cc.fetch(
                rowloc2, two_column_row.getRowArray(), (FormatableBitSet) null))
        {
      throw T_Fail.testFailMsg(
                "(alterTable) Row not there.");
        }

        if ((((SQLInteger)two_column_row.getCol(0)).getInt() != 2) ||
            (!two_column_row.getCol(1).isNull()))
        {
      throw T_Fail.testFailMsg(
                "(alterTable) Bad column value after alter.");
        }

        // make sure insert of 2 column row works.
        two_column_row = new T_AccessRow(2);
        two_column_row.setCol(0, new SQLInteger(3));
        two_column_row.setCol(1, new SQLInteger(300));
        cc.insert(two_column_row.getRowArray());


        // At this point the table looks like:
        // col1 col2
        // ---- ----
        // 1    NA
        // 2    NA
        // 3    300

       
    ScanController scan = tc.openScan(
      conglomid,
      false,  // don't hold
      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.

        while (scan.next())
        {
            scan.fetch(two_column_row.getRowArray());

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

            switch(key_value)
            {
                case 1:
                {
                    // Set non-existent column value to 100
                    if (!two_column_row.getCol(1).isNull())
                    {
                        throw T_Fail.testFailMsg(
                            "(alterTable) Bad column value after alter.");
                    }

                    // test that replace field works on alter added column
                    // make result row be: (1, 100)

                    two_column_row.setCol(1, new SQLInteger(100));

                    scan.replace(two_column_row.getRowArray(), (FormatableBitSet) null);
                    break;
                }
                case 2:
                {
                    if (!two_column_row.getCol(1).isNull())
                    {
                        throw T_Fail.testFailMsg(
                            "(alterTable) Bad column value after alter.");
                    }

                    // test that replace row works on alter added column row.
                    // make result row be: (2, 200)
                    two_column_row.setCol(1, new SQLInteger(200));

                    scan.replace(two_column_row.getRowArray(), (FormatableBitSet) null);

                    break;
                }
View Full Code Here

                TransactionController.MODE_RECORD,
                TransactionController.ISOLATION_SERIALIZABLE);

    // Create a 1 column row. int column = 1.
    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();

    // Insert the row and remember its location.
    cc.insertAndFetchLocation(r1.getRowArray(), rowloc1);

        // create another 2 column row. int column = 2.
    // Get a location template
        r1.setCol(0, new SQLInteger(2));
        r1.setCol(1, new SQLInteger(200));
    RowLocation rowloc2 = cc.newRowLocationTemplate();

    // Insert the row and remember its location.
    cc.insertAndFetchLocation(r1.getRowArray(), rowloc2);
View Full Code Here

                TransactionController.MODE_RECORD,
                TransactionController.ISOLATION_SERIALIZABLE);

    // Create a 1 column row. int column = 1.
    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();

    // Insert the row and remember its location.
    cc.insertAndFetchLocation(r1.getRowArray(), rowloc1);

        // create another 2 column row. int column = 2.
    // Get a location template
        r1.setCol(0, new SQLInteger(2));
        r1.setCol(1, new SQLInteger(200));
    RowLocation rowloc2 = cc.newRowLocationTemplate();

    // Insert the row and remember its location.
    cc.insertAndFetchLocation(r1.getRowArray(), rowloc2);
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.