Search in sources :

Example 96 with StandardException

use of org.apache.derby.shared.common.error.StandardException 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 97 with StandardException

use of org.apache.derby.shared.common.error.StandardException in project derby by apache.

the class T_FileSystemData method runTestSet.

/**
 *	  run the test
 *
 *	  @exception T_Fail Unexpected behaviour from the API
 */
protected void runTestSet() throws T_Fail {
    // get a utility helper
    ContextManager cm1 = contextService.newContextManager();
    contextService.setCurrentContextManager(cm1);
    try {
        runCostEstimationTests();
        runAllocationTests();
    } catch (StandardException se) {
        // Assume database is not active. DERBY-4856 thread dump
        cm1.cleanupOnError(se, false);
        throw T_Fail.exceptionFail(se);
    } finally {
        contextService.resetCurrentContextManager(cm1);
    }
}
Also used : StandardException(org.apache.derby.shared.common.error.StandardException) ContextManager(org.apache.derby.iapi.services.context.ContextManager)

Example 98 with StandardException

use of org.apache.derby.shared.common.error.StandardException in project derby by apache.

the class T_FileSystemData method setupTest.

/**
 *		Run the tests
 *
 *		@exception T_Fail Unexpected behaviour from the API
 */
protected void setupTest() throws T_Fail {
    String rollbackOff = PropertyUtil.getSystemProperty(TEST_ROLLBACK_OFF);
    testRollback = !Boolean.valueOf(rollbackOff).booleanValue();
    // don't automatic boot this service if it gets left around
    if (startParams == null) {
        startParams = new Properties();
    }
    // see if we are testing encryption
    startParams = T_Util.setEncryptionParam(startParams);
    startParams.put(Property.NO_AUTO_BOOT, Boolean.TRUE.toString());
    // remove the service directory to ensure a clean run
    startParams.put(Property.DELETE_ON_CREATE, Boolean.TRUE.toString());
    try {
        factory = (RawStoreFactory) createPersistentService(getModuleToTestProtocolName(), testService, startParams);
        if (factory == null) {
            throw T_Fail.testFailMsg(getModuleToTestProtocolName() + " service not started.");
        }
        lf = factory.getLockFactory();
        if (lf == null) {
            throw T_Fail.testFailMsg("LockFactory.MODULE not found");
        }
    } catch (StandardException mse) {
        throw T_Fail.exceptionFail(mse);
    }
    t_util = new T_Util(factory, lf, contextService);
    commonContainer = commonContainer();
    return;
}
Also used : StandardException(org.apache.derby.shared.common.error.StandardException) Properties(java.util.Properties)

Example 99 with StandardException

use of org.apache.derby.shared.common.error.StandardException in project derby by apache.

the class T_RawStoreFactory method P002.

/**
 *		Insert rows on the first page until the page is full, then add a page
 *		and repeat the test (for a total of three pages with full rows).
 *		Fetch the rows back by handle and slot methods.
 *
 *		@exception T_Fail Unexpected behaviour from the API
 *		@exception StandardException Unexpected exception from the implementation
 */
protected void P002(long segment) throws StandardException, T_Fail {
    Transaction t = t_util.t_startTransaction();
    long cid = t_util.t_addContainer(t, segment);
    ContainerHandle c = t_util.t_openContainer(t, segment, cid, true);
    Page page = t_util.t_getPage(c, ContainerHandle.FIRST_PAGE_NUMBER);
    t_util.t_checkEmptyPage(page);
    RecordHandle rh;
    T_RawStoreRow row;
    int[] recordCount = { 0, 0, 0 };
    for (int i = 0; i < 3; ) {
        row = new T_RawStoreRow(REC_001 + i + "X" + recordCount[i]);
        boolean spaceThere = page.spaceForInsert();
        rh = t_util.t_insert(page, row);
        if (rh != null) {
            recordCount[i]++;
            if (!spaceThere)
                REPORT("record inserted after spaceForInsert() returned false, count is " + recordCount[i]);
        } else {
            if (spaceThere)
                REPORT("record insert failed after spaceForInsert() returned true, count is " + recordCount[i]);
        }
        t_util.t_checkRecordCount(page, recordCount[i], recordCount[i]);
        if (rh != null)
            continue;
        page.unlatch();
        page = null;
        if (++i < 3) {
            page = t_util.t_addPage(c);
            t_util.t_checkEmptyPage(page);
        }
    }
    t_util.t_commit(t);
    for (int i = 0; i < 3; i++) {
        REPORT("RecordCount on page " + i + "=" + recordCount[i]);
    }
    // now check that we read the same number of records back
    // using the handle interface
    c = t_util.t_openContainer(t, segment, cid, false);
    long pageNumber = ContainerHandle.FIRST_PAGE_NUMBER;
    for (int i = 0; i < 3; i++, pageNumber++) {
        page = t_util.t_getPage(c, pageNumber);
        t_util.t_checkRecordCount(page, recordCount[i], recordCount[i]);
        rh = t_util.t_checkFetchFirst(page, REC_001 + i + "X" + 0);
        for (int j = 1; j < recordCount[i]; j++) rh = t_util.t_checkFetchNext(page, rh, REC_001 + i + "X" + j);
        try {
            rh = page.fetchFromSlot(null, page.getSlotNumber(rh) + 1, new DataValueDescriptor[0], (FetchDescriptor) null, false);
            throw T_Fail.testFailMsg("reading more rows on page than were written");
        } catch (StandardException se) {
        // expected error.
        }
        rh = t_util.t_checkFetchLast(page, REC_001 + i + "X" + (recordCount[i] - 1));
        for (int j = recordCount[i] - 2; j >= 0; j--) rh = t_util.t_checkFetchPrevious(page, rh, REC_001 + i + "X" + j);
        page.unlatch();
        page = null;
    }
    t_util.t_commit(t);
    // now check that we read the same number of records back
    // using the slot interface
    c = t_util.t_openContainer(t, segment, cid, false);
    pageNumber = ContainerHandle.FIRST_PAGE_NUMBER;
    for (int i = 0; i < 3; i++, pageNumber++) {
        page = t_util.t_getPage(c, pageNumber);
        for (int j = 0; j < recordCount[i]; j++) t_util.t_checkFetchBySlot(page, j, REC_001 + i + "X" + j, false, false);
        t_util.t_readOnlySlotOutOfRange(page, recordCount[i]);
        page.unlatch();
        page = null;
    }
    // cleanup
    t_util.t_dropContainer(t, segment, cid);
    t_util.t_commit(t);
    t.close();
    PASS("P002");
}
Also used : StandardException(org.apache.derby.shared.common.error.StandardException) RawTransaction(org.apache.derby.iapi.store.raw.xact.RawTransaction) DataValueDescriptor(org.apache.derby.iapi.types.DataValueDescriptor) RawContainerHandle(org.apache.derby.iapi.store.raw.data.RawContainerHandle)

Example 100 with StandardException

use of org.apache.derby.shared.common.error.StandardException in project derby by apache.

the class T_RawStoreFactory method P006.

/*
		P006

		test page time stamp - make sure all operation changes page time stamp
	*/
protected void P006() throws StandardException, T_Fail {
    Transaction t = t_util.t_startTransaction();
    PageTimeStamp ts;
    long cid = t_util.t_addContainer(t, 0);
    t_util.t_commit(t);
    ContainerHandle c = t_util.t_openContainer(t, 0, cid, true);
    Page page1 = t_util.t_getLastPage(c);
    ts = page1.currentTimeStamp();
    if (ts != null && !page1.equalTimeStamp(ts))
        throw T_Fail.testFailMsg("page returns non-null time stamp which is not equal to its current time stamp");
    T_RawStoreRow row = new T_RawStoreRow(REC_001);
    RecordHandle rh = t_util.t_insert(page1, row);
    if (page1.equalTimeStamp(ts))
        throw T_Fail.testFailMsg("timestamp on page not changed after insert operation");
    page1.setTimeStamp(ts);
    if (ts != null && !page1.equalTimeStamp(ts))
        throw T_Fail.testFailMsg("page returns non-null time stamp which is not equal to its current time stamp");
    // failed update should not change time stamp
    t_util.t_updateSlotOutOfRange(page1, 3);
    if (ts != null && !page1.equalTimeStamp(ts))
        throw T_Fail.testFailMsg("failed pdate should not change time stamp");
    T_RawStoreRow row2 = new T_RawStoreRow(REC_002);
    int slot2 = page1.getSlotNumber(rh);
    page1.updateAtSlot(slot2, row2.getRow(), null);
    if (page1.equalTimeStamp(ts))
        throw T_Fail.testFailMsg("timestamp on page not changed after update operation");
    page1.setTimeStamp(ts);
    T_RawStoreRow upd1 = new T_RawStoreRow(REC_003);
    int slot = page1.getSlotNumber(rh);
    page1.updateAtSlot(slot, upd1.getRow(), BS_COL_0);
    if (page1.equalTimeStamp(ts))
        throw T_Fail.testFailMsg("timestamp on page not changed after update field operation");
    page1.setTimeStamp(ts);
    page1.deleteAtSlot(slot, true, null);
    if (page1.equalTimeStamp(ts))
        throw T_Fail.testFailMsg("timestamp on page not changed after delete operation");
    page1.setTimeStamp(ts);
    page1.purgeAtSlot(0, 1, logDataForPurges);
    if (page1.equalTimeStamp(ts))
        throw T_Fail.testFailMsg("timestamp on page not changed after delete operation");
    page1.setTimeStamp(ts);
    page1.unlatch();
    if (testRollback) {
        t_util.t_abort(t);
        c = t_util.t_openContainer(t, 0, cid, true);
        page1 = t_util.t_getLastPage(c);
        if (page1.equalTimeStamp(ts))
            throw T_Fail.testFailMsg("timestamp on page not changed after rollback");
        page1.setTimeStamp(ts);
    }
    Page page2 = c.addPage();
    Page page3 = c.addPage();
    page2.setTimeStamp(ts);
    if (ts != null) {
        try {
            if (page3.equalTimeStamp(ts))
                throw T_Fail.testFailMsg("timestamp on 2 different pages should not equate");
        } catch (StandardException se) {
        // either throw an exception or return false is OK
        }
    }
    // cleanup
    t_util.t_dropContainer(t, 0, cid);
    t_util.t_commit(t);
    t.close();
    PASS("P006");
}
Also used : StandardException(org.apache.derby.shared.common.error.StandardException) RawTransaction(org.apache.derby.iapi.store.raw.xact.RawTransaction) RawContainerHandle(org.apache.derby.iapi.store.raw.data.RawContainerHandle)

Aggregations

StandardException (org.apache.derby.shared.common.error.StandardException)276 DataValueDescriptor (org.apache.derby.iapi.types.DataValueDescriptor)43 LanguageConnectionContext (org.apache.derby.iapi.sql.conn.LanguageConnectionContext)37 IOException (java.io.IOException)32 Properties (java.util.Properties)29 RawTransaction (org.apache.derby.iapi.store.raw.xact.RawTransaction)27 TransactionController (org.apache.derby.iapi.store.access.TransactionController)26 ContextManager (org.apache.derby.iapi.services.context.ContextManager)22 RawContainerHandle (org.apache.derby.iapi.store.raw.data.RawContainerHandle)20 SQLException (java.sql.SQLException)17 FormatableBitSet (org.apache.derby.iapi.services.io.FormatableBitSet)17 DataDictionary (org.apache.derby.iapi.sql.dictionary.DataDictionary)16 ConglomerateController (org.apache.derby.iapi.store.access.ConglomerateController)12 RowLocation (org.apache.derby.iapi.types.RowLocation)11 SQLLongint (org.apache.derby.iapi.types.SQLLongint)11 StorageFile (org.apache.derby.io.StorageFile)10 TableDescriptor (org.apache.derby.iapi.sql.dictionary.TableDescriptor)9 ScanController (org.apache.derby.iapi.store.access.ScanController)9 File (java.io.File)8 LogInstant (org.apache.derby.iapi.store.raw.log.LogInstant)8