⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 t_accessfactory.java

📁 derby database source code.good for you.
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
		// subsequent replace, update a single column, and delete         // should return false         // update single column        DataValueDescriptor[] update_row  = new DataValueDescriptor[1];        FormatableBitSet   update_desc = new FormatableBitSet(1);        update_desc.set(0);		if (cc.replace(rowloc, update_row, update_desc))		{			throw T_Fail.testFailMsg(            "(deleteTest) partial column row replace returned true on del row");		}        // update whole row.		if (cc.replace(rowloc, r1.getRowArray(), (FormatableBitSet) null))		{			throw T_Fail.testFailMsg("(deleteTest) update returned true on del row");		}		if (cc.delete(rowloc))		{			throw T_Fail.testFailMsg("(deleteTest) delete returned true on del row");		}		// Close the conglomerate.		cc.close();		return true;	}	// Insert a single row with a single column containing	// the first argument integer, update it to the second	// value, and make sure the update happened.	//	protected boolean insertAndUpdate(TransactionController tc, long conglomid,		int value1, int value2)		throws StandardException, T_Fail	{		// Open the conglomerate.		ConglomerateController cc =	            tc.openConglomerate(                conglomid,                 false,                TransactionController.OPENMODE_FORUPDATE,                 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;	}	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(                "heap",       // create a heap conglomerate                new T_AccessRow(1).getRowArray(), // 1 SQLInteger() column template.				null, 	// column sort order not required for heap                null,         // default properties                TransactionController.IS_DEFAULT);       // not temporary		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(			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();		// 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);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -