Search in sources :

Example 96 with FormatableBitSet

use of org.apache.derby.iapi.services.io.FormatableBitSet in project derby by apache.

the class T_QualifierTest method t_scanFetchNextPartial.

/**
 * Test scan which does FetchNext with subset of fields.
 * <p>
 * FetchNext() may be optimized by the underlying scan code to try and
 * not do multiple fetches of the same row for the user, but if the user
 * asks for one column, but the stop position depends on the whole row
 * this optimization is not possible.
 * <p>
 *
 * @return Whether the test succeeded or not.
 *
 * @exception  StandardException  Standard exception policy.
 */
public static boolean t_scanFetchNextPartial(TransactionController tc, long conglomid, DataValueDescriptor[] fetch_template, DataValueDescriptor[] start_key, int start_op, Qualifier[][] qualifier, DataValueDescriptor[] stop_key, int stop_op, int expect_numrows, int input_expect_key, int order) throws StandardException, T_Fail {
    HashSet set = null;
    boolean ordered = (order == ORDER_FORWARD || order == ORDER_DESC);
    /**
     ********************************************************************
     * setup shared by both.
     **********************************************************************
     */
    // In the fetchNext call only ask the minimum set of columns
    // necessary, which is the union of the "key" (col[2]) and other
    // columns referenced in the qualifier list.
    FormatableBitSet fetch_row_validColumns = RowUtil.getQualifierBitSet(qualifier);
    // now add in column 2, as we always need the key field.
    // grow to length of 3
    fetch_row_validColumns.grow(3);
    fetch_row_validColumns.set(2);
    // add in any fields in start and stop positions
    if (start_key != null) {
        for (int i = 0; i < start_key.length; i++) {
            fetch_row_validColumns.set(i);
        }
    }
    if (stop_key != null) {
        for (int i = 0; i < stop_key.length; i++) {
            fetch_row_validColumns.set(i);
        }
    }
    // point key at the right column in the fetch_template
    SQLLongint key_column = (SQLLongint) fetch_template[2];
    if (!ordered) {
        set = create_hash_set(input_expect_key, expect_numrows, order);
    }
    ScanController scan = tc.openScan(conglomid, false, 0, TransactionController.MODE_RECORD, TransactionController.ISOLATION_SERIALIZABLE, (FormatableBitSet) fetch_row_validColumns, start_key, start_op, qualifier, stop_key, stop_op);
    int expect_key = input_expect_key;
    long key = -42;
    long key2 = -42;
    long numrows = 0;
    while (scan.fetchNext(fetch_template)) {
        // see if we are getting the right keys.
        key = key_column.getLong();
        // make sure a subsequent fetch also works.
        key_column.setValue(-42);
        scan.fetch(fetch_template);
        key2 = key_column.getLong();
        if (ordered) {
            if ((key != expect_key) || (key2 != expect_key)) {
                return (fail("(t_scanFetchNext) wrong key, expected (" + expect_key + ")" + "but got (" + key + ")."));
            } else {
                if (order == ORDER_DESC)
                    expect_key--;
                else
                    expect_key++;
            }
        } else {
            if (!set.remove(key)) {
                return (fail("(t_scanFetchNext) wrong key, expected (" + expect_key + ")" + "but got (" + key + ")."));
            }
        }
        numrows++;
    }
    scan.close();
    if (numrows != expect_numrows) {
        return (fail("(t_scanFetchNext) wrong number of rows. Expected " + expect_numrows + " rows, but got " + numrows + "rows."));
    }
    return (true);
}
Also used : ScanController(org.apache.derby.iapi.store.access.ScanController) GroupFetchScanController(org.apache.derby.iapi.store.access.GroupFetchScanController) SQLLongint(org.apache.derby.iapi.types.SQLLongint) FormatableBitSet(org.apache.derby.iapi.services.io.FormatableBitSet) SQLLongint(org.apache.derby.iapi.types.SQLLongint) HashSet(java.util.HashSet)

Example 97 with FormatableBitSet

use of org.apache.derby.iapi.services.io.FormatableBitSet in project derby by apache.

the class T_StreamFile method SF002.

// this test test the rowSource over head.
// when param set to 1, also gets the overhead for writeExternal for Storables
protected void SF002(int param) throws StandardException, T_Fail {
    T_RowSource rowSource = new T_RowSource(500000, 13, 2, false, null);
    DynamicByteArrayOutputStream out = new DynamicByteArrayOutputStream(16384);
    FormatIdOutputStream logicalDataOut = new FormatIdOutputStream(out);
    long startms = System.currentTimeMillis();
    System.out.println("starting rowSource test, time: " + startms);
    try {
        FormatableBitSet validColumns = rowSource.getValidColumns();
        int numberFields = 0;
        if (validColumns != null) {
            for (int i = validColumns.size() - 1; i >= 0; i--) {
                if (validColumns.get(i)) {
                    numberFields = i + 1;
                    break;
                }
            }
        }
        DataValueDescriptor[] row = rowSource.getNextRowFromRowSource();
        while (row != null) {
            if (SanityManager.DEBUG) {
                SanityManager.ASSERT(row != null, "RowSource returned null");
            }
            int arrayPosition = -1;
            for (int i = 0; i < numberFields; i++) {
                // write each column out
                if (validColumns.get(i)) {
                    arrayPosition++;
                    DataValueDescriptor column = row[arrayPosition];
                    if (param == 1) {
                        try {
                            Storable sColumn = (Storable) column;
                            if (!sColumn.isNull()) {
                                sColumn.writeExternal(logicalDataOut);
                                out.reset();
                            }
                        } catch (IOException ioe) {
                            throw T_Fail.exceptionFail(ioe);
                        }
                    }
                }
            }
            row = rowSource.getNextRowFromRowSource();
        }
    } finally {
    }
    long endms = System.currentTimeMillis();
    long time2 = endms - startms;
    if (param != 1)
        System.out.println("ended rowSource test, time: " + endms + ", time spent = " + time2);
    else
        System.out.println("------ writeExternal called....\n ended rowSource test, time: " + endms + ", time spent = " + time2);
    PASS("SF002");
}
Also used : DynamicByteArrayOutputStream(org.apache.derby.iapi.services.io.DynamicByteArrayOutputStream) FormatableBitSet(org.apache.derby.iapi.services.io.FormatableBitSet) DataValueDescriptor(org.apache.derby.iapi.types.DataValueDescriptor) FormatIdOutputStream(org.apache.derby.iapi.services.io.FormatIdOutputStream) Storable(org.apache.derby.iapi.services.io.Storable)

Example 98 with FormatableBitSet

use of org.apache.derby.iapi.services.io.FormatableBitSet in project derby by apache.

the class T_Util method t_checkFetchCol.

/*
	    Using sparse row representation:
		Fetch a column of a record that is expected to exist, using a record 
		handle and a FormatableBitSet object.
		Check that column colNum has value data.
	*/
public static void t_checkFetchCol(Page page, RecordHandle rh, int colNum, int numCols, String data) throws T_Fail, StandardException {
    if (!page.recordExists(rh, false))
        throw T_Fail.testFailMsg("Record does not exist");
    T_RawStoreRow readRow = new T_RawStoreRow(numCols);
    for (int i = 0; i < numCols; i++) readRow.setColumn(i, (String) null);
    FormatableBitSet colList = new FormatableBitSet(numCols);
    colList.set(colNum);
    FetchDescriptor desc = new FetchDescriptor(numCols, colList, null);
    RecordHandle rhf = page.fetchFromSlot(rh, page.getSlotNumber(rh), readRow.getRow(), desc, false);
    if (rhf == null)
        throw T_Fail.testFailMsg("Failed to read record");
    String col = readRow.getStorableColumn(colNum).toString();
    if (!col.equals(data))
        throw T_Fail.testFailMsg("Record's value for column " + colNum + " incorrect, expected :" + data + ": - got :" + readRow.toString());
}
Also used : FormatableBitSet(org.apache.derby.iapi.services.io.FormatableBitSet)

Example 99 with FormatableBitSet

use of org.apache.derby.iapi.services.io.FormatableBitSet in project derby by apache.

the class T_Util method t_checkFetchColFromSlot.

public static void t_checkFetchColFromSlot(Page page, int slot, int fieldId, DataValueDescriptor column, boolean forUpdate, String data) throws StandardException, T_Fail {
    DataValueDescriptor[] fetch_row = new DataValueDescriptor[fieldId + 1];
    fetch_row[fieldId] = column;
    FormatableBitSet validCols = new FormatableBitSet(fieldId + 1);
    validCols.set(fieldId);
    RecordHandle rh = page.fetchFromSlot(null, slot, fetch_row, new FetchDescriptor(fetch_row.length, validCols, (Qualifier[][]) null), true);
    if (rh == null)
        throw T_Fail.testFailMsg("Failed to fetch record: slot " + slot + " field " + fieldId);
    if (data == null) {
        if (!column.isNull())
            throw T_Fail.testFailMsg("Failed to fetch null column: slot " + slot + " field " + fieldId + " column is " + column);
    } else {
        if (column.isNull())
            throw T_Fail.testFailMsg("expect non null column, got null: slot " + slot + " field " + fieldId);
        if (!column.toString().equals(data))
            throw T_Fail.testFailMsg("expect " + data + " got " + column.toString() + ": slot " + slot + " field " + fieldId);
    }
}
Also used : FormatableBitSet(org.apache.derby.iapi.services.io.FormatableBitSet) Qualifier(org.apache.derby.iapi.store.access.Qualifier) DataValueDescriptor(org.apache.derby.iapi.types.DataValueDescriptor)

Example 100 with FormatableBitSet

use of org.apache.derby.iapi.services.io.FormatableBitSet in project derby by apache.

the class commit_method method XATest_6.

/**
 * Very simple testing of changing a local transaction to a global.
 * <p>
 * @exception  StandardException  Standard exception policy.
 */
void XATest_6(commit_method commit_method) throws StandardException, T_Fail {
    REPORT("(XATest_5) starting");
    ContextManager cm = getContextService().getCurrentContextManager();
    TransactionController tc = store.getTransaction(cm);
    // Create a heap conglomerate.
    T_AccessRow template_row = new T_AccessRow(1);
    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);
    tc.commit();
    // COMMIT AN IDLE TRANSACTION.
    // Start a global transaction
    XATransactionController xa_tc = (XATransactionController) tc.createXATransactionFromLocalTransaction(// fake format id
    42, global_id, branch_id);
    if (!xa_tc.isGlobal()) {
        throw T_Fail.testFailMsg("should be a global transaction.");
    }
    // Open a scan on the conglomerate.
    ScanController scan1 = xa_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);
    scan1.next();
    scan1.close();
    // Create a heap conglomerate.
    template_row = new T_AccessRow(1);
    conglomid = xa_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);
    // Should be no prepared transactions, there is one update global xact.
    if (((XAResourceManager) store.getXAResourceManager()).recover(XAResource.TMSTARTRSCAN).length != 0) {
        throw T_Fail.testFailMsg("recover incorrectly returned prepared xacts.");
    }
    // prepare the update xact.
    if (xa_tc.xa_prepare() != XATransactionController.XA_OK) {
        throw T_Fail.testFailMsg("prepare of update xact did not return XA_OK.");
    }
    try {
        // Open a scan on the conglomerate.
        scan1 = xa_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);
        scan1.next();
        scan1.close();
        throw T_Fail.testFailMsg("Should not be able to do anything on xact after prepare.");
    } catch (StandardException se) {
    // expected exception, fall through.
    }
    // commit a prepared transaction - using two phase.
    commit_method.commit(false, 42, global_id, branch_id, xa_tc);
    xa_tc.destroy();
    REPORT("(XATest_6) finishing");
}
Also used : StandardException(org.apache.derby.shared.common.error.StandardException) ContextManager(org.apache.derby.iapi.services.context.ContextManager) FormatableBitSet(org.apache.derby.iapi.services.io.FormatableBitSet)

Aggregations

FormatableBitSet (org.apache.derby.iapi.services.io.FormatableBitSet)146 DataValueDescriptor (org.apache.derby.iapi.types.DataValueDescriptor)36 RowLocation (org.apache.derby.iapi.types.RowLocation)32 SQLLongint (org.apache.derby.iapi.types.SQLLongint)25 ScanController (org.apache.derby.iapi.store.access.ScanController)24 ExecRow (org.apache.derby.iapi.sql.execute.ExecRow)23 ConglomerateController (org.apache.derby.iapi.store.access.ConglomerateController)18 StandardException (org.apache.derby.shared.common.error.StandardException)17 RawTransaction (org.apache.derby.iapi.store.raw.xact.RawTransaction)15 RawContainerHandle (org.apache.derby.iapi.store.raw.data.RawContainerHandle)13 TransactionController (org.apache.derby.iapi.store.access.TransactionController)12 ConglomerateDescriptor (org.apache.derby.iapi.sql.dictionary.ConglomerateDescriptor)11 SQLInteger (org.apache.derby.iapi.types.SQLInteger)11 UUID (org.apache.derby.catalog.UUID)10 ExecIndexRow (org.apache.derby.iapi.sql.execute.ExecIndexRow)10 ConstraintDescriptor (org.apache.derby.iapi.sql.dictionary.ConstraintDescriptor)9 DataDictionary (org.apache.derby.iapi.sql.dictionary.DataDictionary)7 SQLChar (org.apache.derby.iapi.types.SQLChar)7 Properties (java.util.Properties)6 ContextManager (org.apache.derby.iapi.services.context.ContextManager)6