Search in sources :

Example 11 with SQLInteger

use of org.apache.derby.iapi.types.SQLInteger in project derby by apache.

the class T_AccessFactory method scanExample.

protected boolean scanExample(TransactionController tc) throws StandardException, T_Fail {
    tc.commit();
    if (!tc.isPristine() || !tc.isIdle() || tc.isGlobal())
        throw T_Fail.testFailMsg("(scanExample) bad xact state after commit.");
    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 0:\n" + tc.debugOpened());
        return (FAIL("unexpected open count."));
    }
    // Create a heap conglomerate.
    long conglomid = tc.createConglomerate(// create a heap conglomerate
    "heap", // 1 SQLInteger() column template.
    new T_AccessRow(1).getRowArray(), // column sort order not required for heap
    null, // default collation
    null, // default properties
    null, // not temporary
    TransactionController.IS_DEFAULT);
    REPORT("(scanExample) starting");
    // Open it.
    ConglomerateController cc = tc.openConglomerate(conglomid, false, TransactionController.OPENMODE_FORUPDATE, TransactionController.MODE_RECORD, TransactionController.ISOLATION_SERIALIZABLE);
    // 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(// don't hold
    false, // not for update
    0, TransactionController.MODE_RECORD, TransactionController.ISOLATION_SERIALIZABLE, // all columns, all as objects
    (FormatableBitSet) null, // start position - first row in conglomerate
    null, // unused if start position is null.
    0, // qualifier - accept all rows
    null, // stop position - last row in conglomerate
    null, // unused if stop position is null.
    0, static_info, tc.getDynamicCompiledConglomInfo(conglomid));
    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(// start position - first row in conglomerate
    null, // unused if start position is null.
    0, // qualifier - accept all rows
    null, // stop position - last row in conglomerate
    null, // unused if stop position is null.
    0);
    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, // don't hold
    false, // for update
    TransactionController.OPENMODE_FORUPDATE, TransactionController.MODE_RECORD, TransactionController.ISOLATION_SERIALIZABLE, // all columns, all as objects
    (FormatableBitSet) null, // start position - first row in conglomerate
    null, // unused if start position is null.
    0, // qualifier - accept all rows
    null, // stop position - last row in conglomerate
    null, // unused if stop position is null.
    0);
    // 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, // don't hold
    false, // not for update
    0, TransactionController.MODE_RECORD, TransactionController.ISOLATION_SERIALIZABLE, // all columns, all as objects
    (FormatableBitSet) null, // start position - first row in conglomerate
    null, // unused if start position is null.
    0, // qualifier - accept all rows
    null, // stop position - last row in conglomerate
    null, // unused if stop position is null.
    0);
    // 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, // don't hold
    false, // not for update
    0, TransactionController.MODE_RECORD, TransactionController.ISOLATION_READ_UNCOMMITTED, // all columns, all as objects
    (FormatableBitSet) null, // start position - first row in conglomerate
    null, // unused if start position is null.
    0, // qualifier - accept all rows
    null, // stop position - last row in conglomerate
    null, // unused if stop position is null.
    0);
    // 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();
    // Check we saw the right number of rows.
    if (scanindex != newvalues.length)
        throw T_Fail.testFailMsg("(scanExample after changes) Expected " + newvalues.length + "rows, got " + scanindex);
    REPORT("(scanExample) fiddled rows present and accounted for");
    REPORT("(scanExample) testing expected delete errors");
    // Open 4th scan on conglomerate and test "expected" error returns
    // from replace, partial column replace, delete.
    ScanController scan4 = tc.openScan(conglomid, // don't hold
    false, // for update
    TransactionController.OPENMODE_FORUPDATE, TransactionController.MODE_RECORD, TransactionController.ISOLATION_SERIALIZABLE, // all columns, all as objects
    (FormatableBitSet) null, // start position - first row in conglomerate
    null, // unused if start position is null.
    0, // qualifier - accept all rows
    null, // stop position - last row in conglomerate
    null, // unused if stop position is null.
    0);
    // then test that operations on that deleted entry FAIL as expected.
    while (scan4.next()) {
        scan4.fetch(row.getRowArray());
        if (!scan4.doesCurrentPositionQualify()) {
            throw T_Fail.testFailMsg("(scanExample doesCurrentPositionQualify() errors) Expected requalify of current row to succeed");
        }
        if (((SQLInteger) row.getCol(0)).getInt() == 22) {
            if (!scan4.delete()) {
                throw T_Fail.testFailMsg("(scanExample delete errors) Delete failed.");
            }
            break;
        }
    }
    if (scan4.doesCurrentPositionQualify()) {
        throw T_Fail.testFailMsg("(scanExample doesCurrentPositionQualify() errors) Expected qualify of deleted row to FAIL");
    }
    DataValueDescriptor[] update_row = new DataValueDescriptor[1];
    FormatableBitSet update_desc = new FormatableBitSet(1);
    update_desc.set(0);
    if (scan4.replace(update_row, update_desc)) {
        throw T_Fail.testFailMsg("(scanExample delete errors) Expected partial column replace to FAIL");
    }
    if (scan4.replace(row.getRowArray(), (FormatableBitSet) null)) {
        throw T_Fail.testFailMsg("(scanExample after changes) Expected replace to FAIL");
    }
    if (scan4.delete()) {
        throw T_Fail.testFailMsg("(scanExample after changes) Expected delete to FAIL");
    }
    scan4.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:\n" + tc.debugOpened());
        return (FAIL("unexpected open count."));
    }
    REPORT("(scanExample) completed");
    return true;
}
Also used : FormatableBitSet(org.apache.derby.iapi.services.io.FormatableBitSet) DataValueDescriptor(org.apache.derby.iapi.types.DataValueDescriptor) RowLocation(org.apache.derby.iapi.types.RowLocation) SQLLongint(org.apache.derby.iapi.types.SQLLongint) SQLInteger(org.apache.derby.iapi.types.SQLInteger)

Example 12 with SQLInteger

use of org.apache.derby.iapi.types.SQLInteger in project derby by apache.

the class T_AccessFactory method alterTable.

/**
 * Test the access level alter table interface for adding columns.
 * <p>
 *
 * @return true if the test succeeded.
 *
 * @param tc The transaction controller to use in the test.
 * @param temporary flag which tells whether or not the conglomerate
 * used in the test should be temporary
 *
 * @exception  StandardException  Standard exception policy.
 * @exception  T_Fail Unexpected behaviour from the API
 */
private boolean alterTable(TransactionController tc, boolean temporary) throws StandardException, T_Fail {
    int key_value;
    REPORT("(alterTable) starting");
    // Create a heap conglomerate.
    T_AccessRow template_row = new T_AccessRow(1);
    int temporaryFlag = temporary ? TransactionController.IS_TEMPORARY : TransactionController.IS_DEFAULT;
    long conglomid = tc.createConglomerate(// create a heap conglomerate
    "heap", // 1 column template.
    template_row.getRowArray(), // column sort order not required for heap
    null, // default collation
    null, // default properties
    null, temporaryFlag);
    // Open the conglomerate.
    ConglomerateController cc = tc.openConglomerate(conglomid, false, TransactionController.OPENMODE_FORUPDATE, 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);
    // 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.
        }
    }
    // 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.
        }
    }
    // 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.
        }
    }
    // 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, // don't hold
    false, // for update
    TransactionController.OPENMODE_FORUPDATE, TransactionController.MODE_RECORD, TransactionController.ISOLATION_SERIALIZABLE, // all columns, all as objects
    (FormatableBitSet) null, // start position - first row in conglomerate
    null, // unused if start position is null.
    0, // qualifier - accept all rows
    null, // stop position - last row in conglomerate
    null, // unused if stop position is null.
    0);
    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;
                }
            case 3:
                {
                    break;
                }
            default:
                {
                    throw T_Fail.testFailMsg("(alterTable) bad row value found in table.");
                }
        }
    }
    // reposition the scan
    scan.reopenScan(// start position - first row in conglomerate
    null, // unused if start position is null.
    0, // qualifier - accept all rows
    null, // stop position - last row in conglomerate
    null, // unused if stop position is null.
    0);
    while (scan.next()) {
        scan.fetch(two_column_row.getRowArray());
        key_value = ((SQLInteger) two_column_row.getCol(0)).getInt();
        switch(key_value) {
            case 1:
            case 2:
            case 3:
                {
                    int second_col_val = ((SQLInteger) two_column_row.getCol(1)).getInt();
                    if (second_col_val != (key_value * 100)) {
                        throw T_Fail.testFailMsg("(alterTable) Bad column value after alter." + "expected: (" + key_value + ", " + key_value * 100 + ")\n" + "got     : (" + key_value + ", " + second_col_val + ")\n");
                    }
                    break;
                }
            default:
                {
                    throw T_Fail.testFailMsg("(alterTable) bad row value found in table.");
                }
        }
    }
    scan.close();
    tc.commit();
    REPORT("(alterTable) completed");
    return true;
}
Also used : StandardException(org.apache.derby.shared.common.error.StandardException) FormatableBitSet(org.apache.derby.iapi.services.io.FormatableBitSet) DataValueDescriptor(org.apache.derby.iapi.types.DataValueDescriptor) RowLocation(org.apache.derby.iapi.types.RowLocation) SQLLongint(org.apache.derby.iapi.types.SQLLongint) SQLInteger(org.apache.derby.iapi.types.SQLInteger)

Example 13 with SQLInteger

use of org.apache.derby.iapi.types.SQLInteger in project derby by apache.

the class T_SumForIntCol method insertDuplicateKey.

public DataValueDescriptor[] insertDuplicateKey(DataValueDescriptor[] insertRow, DataValueDescriptor[] existingRow) throws StandardException {
    // 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;
}
Also used : SQLInteger(org.apache.derby.iapi.types.SQLInteger)

Example 14 with SQLInteger

use of org.apache.derby.iapi.types.SQLInteger in project derby by apache.

the class DeleteVTIResultSet method openCore.

/**
 *		@exception StandardException Standard Derby error policy
 */
protected void openCore() throws StandardException {
    ExecRow row = getNextRowCore(sourceResultSet);
    if (row != null) {
        rs = activation.getTargetVTI();
        if (SanityManager.DEBUG) {
            SanityManager.ASSERT(rs != null, "rs expected to be non-null");
        }
    }
    /* The source does not know whether or not we are doing a
		 * deferred mode delete.  If we are, then we must clear the
		 * index scan info from the activation so that the row changer
		 * does not re-use that information (which won't be valid for
		 * a deferred mode delete).
		 */
    if (constants.deferred) {
        activation.clearIndexScanInfo();
        if (null == rowHolder)
            rowHolder = new TemporaryRowHolderImpl(activation, new Properties(), (ResultDescription) null);
    }
    try {
        while (row != null) {
            if (!constants.deferred)
                rs.deleteRow();
            else {
                ExecRow rowId = new ValueRow(1);
                rowId.setColumn(1, new SQLInteger(rs.getRow()));
                rowHolder.insert(rowId);
            }
            rowCount++;
            // No need to do a next on a single row source
            if (constants.singleRowSource) {
                row = null;
            } else {
                row = getNextRowCore(sourceResultSet);
            }
        }
    } catch (StandardException se) {
        throw se;
    } catch (Throwable t) {
        throw StandardException.unexpectedUserException(t);
    }
    if (constants.deferred) {
        CursorResultSet tempRS = rowHolder.getResultSet();
        try {
            ExecRow deferredRowBuffer = null;
            tempRS.open();
            while ((deferredRowBuffer = tempRS.getNextRow()) != null) {
                int rowNumber = deferredRowBuffer.getColumn(1).getInt();
                rs.absolute(rowNumber);
                rs.deleteRow();
            }
        } catch (Throwable t) {
            throw StandardException.unexpectedUserException(t);
        } finally {
            sourceResultSet.clearCurrentRow();
            tempRS.close();
        }
    }
    if (rowHolder != null) {
        rowHolder.close();
    // rowHolder kept across opens
    }
}
Also used : StandardException(org.apache.derby.shared.common.error.StandardException) CursorResultSet(org.apache.derby.iapi.sql.execute.CursorResultSet) ExecRow(org.apache.derby.iapi.sql.execute.ExecRow) Properties(java.util.Properties) SQLInteger(org.apache.derby.iapi.types.SQLInteger)

Example 15 with SQLInteger

use of org.apache.derby.iapi.types.SQLInteger in project derby by apache.

the class T_AccessFactory method partialScan.

/**
 * Test partial scans.
 * <p>
 *
 * @return true if the test succeeded.
 *
 * @param tc The transaction controller to use in the test.
 *
 * @exception  StandardException  Standard exception policy.
 * @exception  T_Fail Unexpected behaviour from the API
 */
protected boolean partialScan(TransactionController tc) throws StandardException, T_Fail {
    int key_value;
    REPORT("(partialScan) starting");
    // Create a heap conglomerate.
    T_AccessRow template_row = new T_AccessRow(2);
    long conglomid = tc.createConglomerate(// create a heap conglomerate
    "heap", // 1 column template.
    template_row.getRowArray(), // column sort order not required for heap
    null, // default collation
    null, // default properties
    null, // not temporary
    TransactionController.IS_DEFAULT);
    // Open the conglomerate.
    ConglomerateController cc = tc.openConglomerate(conglomid, false, TransactionController.OPENMODE_FORUPDATE, 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);
    cc.delete(rowloc2);
    tc.commit();
    // Try a partial Row scan with no columns.
    // only get the 2nd column.
    FormatableBitSet validColumns = new FormatableBitSet();
    ScanController scan = tc.openScan(conglomid, // don't hold
    false, // for update
    TransactionController.OPENMODE_FORUPDATE, TransactionController.MODE_RECORD, TransactionController.ISOLATION_SERIALIZABLE, // only get the second column
    validColumns, // start position - first row in conglomerate
    null, // unused if start position is null.
    0, // qualifier - accept all rows
    null, // stop position - last row in conglomerate
    null, // unused if stop position is null.
    0);
    if (!scan.next()) {
        throw T_Fail.testFailMsg("(partialScan) did not see first row.");
    }
    if (scan.next()) {
        throw T_Fail.testFailMsg("(partialScan) saw more than one row.");
    }
    // RESOLVE - should test the btree one also.
    REPORT("(partialScan) finishing");
    return true;
}
Also used : FormatableBitSet(org.apache.derby.iapi.services.io.FormatableBitSet) RowLocation(org.apache.derby.iapi.types.RowLocation) SQLLongint(org.apache.derby.iapi.types.SQLLongint) SQLInteger(org.apache.derby.iapi.types.SQLInteger)

Aggregations

SQLInteger (org.apache.derby.iapi.types.SQLInteger)20 RowLocation (org.apache.derby.iapi.types.RowLocation)13 FormatableBitSet (org.apache.derby.iapi.services.io.FormatableBitSet)11 SQLLongint (org.apache.derby.iapi.types.SQLLongint)10 DataValueDescriptor (org.apache.derby.iapi.types.DataValueDescriptor)9 StandardException (org.apache.derby.shared.common.error.StandardException)5 ExecRow (org.apache.derby.iapi.sql.execute.ExecRow)3 SQLChar (org.apache.derby.iapi.types.SQLChar)3 Properties (java.util.Properties)2 SQLBoolean (org.apache.derby.iapi.types.SQLBoolean)2 Hashtable (java.util.Hashtable)1 UUID (org.apache.derby.catalog.UUID)1 ContextManager (org.apache.derby.iapi.services.context.ContextManager)1 ConstraintDescriptor (org.apache.derby.iapi.sql.dictionary.ConstraintDescriptor)1 SubCheckConstraintDescriptor (org.apache.derby.iapi.sql.dictionary.SubCheckConstraintDescriptor)1 SubConstraintDescriptor (org.apache.derby.iapi.sql.dictionary.SubConstraintDescriptor)1 SubKeyConstraintDescriptor (org.apache.derby.iapi.sql.dictionary.SubKeyConstraintDescriptor)1 CursorResultSet (org.apache.derby.iapi.sql.execute.CursorResultSet)1 SQLVarchar (org.apache.derby.iapi.types.SQLVarchar)1