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

📄 t_rawstorefactory.java

📁 derby database source code.good for you.
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
		c1.close();		t_util.t_commit(t1);		REPORT("insert a record into the container.");		c1 = t_util.t_openContainer(t1, 0, cid, true);		lastPage = t_util.t_getLastPage(c1);		if (lastPage == null)			throw T_Fail.testFailMsg("Couldn't get container's last page");		if (lastPage.getPageNumber() != ContainerHandle.FIRST_PAGE_NUMBER)			throw T_Fail.testFailMsg("Initial page must be " + ContainerHandle.FIRST_PAGE_NUMBER + ", is " + lastPage.getPageNumber());		row = new T_RawStoreRow(REC_001);		if (!lastPage.spaceForInsert())			throw T_Fail.testFailMsg("No room for record on page");		rh001 = t_util.t_insert(lastPage, row);		if (rh001 == null)			throw T_Fail.testFailMsg("Failed to insert record");		// see if we can fetch that record		t_util.t_checkFetch(lastPage, rh001, REC_001);		lastPage.unlatch();		lastPage = null;		t_util.t_commit(t1);		c1 = null;		REPORT("read record just inserted.");		c1 = t_util.t_openContainer(t1, 0, cid, false);		lastPage = t_util.t_getLastPage(c1);		if (lastPage == null)			throw T_Fail.testFailMsg("Couldn't get container's last page");		t_util.t_checkFetch(lastPage, rh001, REC_001);		t_util.t_checkFetchFirst(lastPage, REC_001);		t_util.t_checkFetchLast(lastPage, REC_001);		t_util.t_commit(t1);		lastPage = null;		c1 = null;		REPORT("insert 2 more records.");		c1 = t_util.t_openContainer(t1, 0, cid, true);		lastPage = t_util.t_getLastPage(c1);		if (lastPage == null)			throw T_Fail.testFailMsg("Could get container's last page");		if (lastPage.getPageNumber() != ContainerHandle.FIRST_PAGE_NUMBER)			throw T_Fail.testFailMsg("Initial page must be " + ContainerHandle.FIRST_PAGE_NUMBER + ", is " + lastPage.getPageNumber());		row = new T_RawStoreRow(REC_002);		if (!lastPage.spaceForInsert())			throw T_Fail.testFailMsg("No room for record on page");		if (!lastPage.recordExists(rh001, false))			throw T_Fail.testFailMsg("Record 001 has vanished");		rh002 = t_util.t_insertAtSlot(lastPage, 0, row);		row = new T_RawStoreRow(REC_003);		rh003 = t_util.t_insert(lastPage, row);		lastPage.unlatch();		lastPage = null;		t_util.t_commit(t1);		c1 = null;			REPORT("checks on all 3 records.");		c1 = t_util.t_openContainer(t1, 0, cid, false);		lastPage = t_util.t_getLastPage(c1);		if (lastPage == null)			throw T_Fail.testFailMsg("Could get container's last page");		// Order is 002, 001, 003		t_util.t_checkFetch(lastPage, rh001, REC_001);		t_util.t_checkFetch(lastPage, rh002, REC_002);		t_util.t_checkFetch(lastPage, rh003, REC_003);		t_util.t_checkFetch(lastPage, lastPage.getRecordHandle(rh001.getId()), REC_001);		t_util.t_checkFetch(lastPage, lastPage.getRecordHandle(rh002.getId()), REC_002);		lastPage.unlatch();		lastPage = null;		t_util.t_commit(t1);		c1 = null;		// clean ip		t_util.t_dropContainer(t1, 0, cid);		t_util.t_commit(t1);		t1.close();		PASS("C201 - " + whatPage);	}	/**		Page tests	 */	 /**	    Create a container, ensure it has one page with no records. Then test		all the things we can do with an empty page opened read-only in the container.		Then add a new page, ensure it has the correct page number and is empty.		@exception T_Fail Unexpected behaviour from the API		@exception StandardException Unexpected exception from the implementation	*/	protected void P001(long segment) throws T_Fail, StandardException {		Transaction t = t_util.t_startTransaction();		long cid = t_util.t_addContainer(t, segment);		t_util.t_commit(t);		// Get the first page & check the record counts are zero		ContainerHandle c = t_util.t_openContainer(t, segment, cid, false);		Page page = t_util.t_getPage(c, ContainerHandle.FIRST_PAGE_NUMBER);		t_util.t_checkEmptyPage(page);		if (Page.FIRST_SLOT_NUMBER != 0)			throw T_Fail.testFailMsg("Page.FIRST_SLOT_NUMBER must be 0, is " + Page.FIRST_SLOT_NUMBER);		page.unlatch();		page = null;		// get the last page and check it is the first page		page = t_util.t_getLastPage(c);		t_util.t_checkPageNumber(page, ContainerHandle.FIRST_PAGE_NUMBER);			t_util.t_checkEmptyPage(page);		t_util.t_commit(t);		// t_util.t_addPage checks that the page is empty.		c = t_util.t_openContainer(t, segment, cid, true);		page = t_util.t_addPage(c);		t_util.t_checkPageNumber(page, ContainerHandle.FIRST_PAGE_NUMBER + 1);		page.unlatch();		page = t_util.t_addPage(c);		t_util.t_checkPageNumber(page, ContainerHandle.FIRST_PAGE_NUMBER + 2);		page.unlatch();		t_util.t_commit(t);		c = t_util.t_openContainer(t, segment, cid, true);		page = t_util.t_getPage(c, ContainerHandle.FIRST_PAGE_NUMBER);		t_util.t_updateSlotOutOfRange(page, 0);		t_util.t_updateSlotOutOfRange(page, -1);		t_util.t_updateSlotOutOfRange(page, 1);		t_util.t_dropContainer(t, segment, cid);	// cleanup		t_util.t_commit(t);		// RESOLVE drop container		t.close();		PASS("P001");	}	/**		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;		}		t_util.t_dropContainer(t, segment, cid);	// cleanup		t_util.t_commit(t);		t.close();		PASS("P002");	}	/**		Test Page.delete		@exception T_Fail Unexpected behaviour from the API		@exception StandardException Unexpected exception from the implementation		@see Page#delete	*/	protected void P003(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);		RecordHandle r1, r2;		T_RawStoreRow row1 = new T_RawStoreRow(REC_001);		T_RawStoreRow row2 = new T_RawStoreRow(REC_002);		r1 = t_util.t_insertAtSlot(page, 0, row1);		r2 = t_util.t_insertAtSlot(page, 1, row2);		t_util.t_checkFetch(page, r1, REC_001);		if (r2 != null)			t_util.t_checkFetch(page, r2, REC_002);		t_util.t_checkRecordCount(page, 2, r2 == null ? 1 : 2);		// delete the first		if (!page.delete(r1, (LogicalUndo)null))			throw T_Fail.testFailMsg("delete() returned false");		t_util.t_checkRecordCount(page, 2, r2 == null ? 0 : 1);		if (page.delete(r1, (LogicalUndo)null))			throw T_Fail.testFailMsg("delete() returned true on already deleted record");		t_util.t_checkRecordCount(page, 2, r2 == null ? 0 : 1);		if (page.recordExists(r1, false))			throw T_Fail.testFailMsg("recordExists() returned true for deleted record");		// check the other record is still there		if (r2 != null)			t_util.t_checkFetch(page, r2, REC_002);		if (!page.isDeletedAtSlot(0))			throw T_Fail.testFailMsg("isDeletedAtSlot() doesn't represent correct state");		t_util.t_dropContainer(t, segment, cid);	// cleanup		t_util.t_commit(t);		t.close();		PASS("P003");	}	/**		Test Page.update		@exception T_Fail Unexpected behaviour from the API		@exception StandardException Unexpected exception from the implementation		@see Page#update	*/	protected void P004(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);		RecordHandle r1, r2;		T_RawStoreRow row1 = new T_RawStoreRow(REC_001);		T_RawStoreRow row2 = new T_RawStoreRow(REC_002);		r1 = t_util.t_insertAtSlot(page, 0, row1);		r2 = t_util.t_insertAtSlot(page, 1, row2);		t_util.t_checkFetch(page, r1, REC_001);		if (r2 != null)			t_util.t_checkFetch(page, r2, REC_002);		row1 = new T_RawStoreRow((String) null);		if (!page.update(r1, row1.getRow(), (FormatableBitSet) null))			throw T_Fail.testFailMsg("update() returned false");		t_util.t_checkFetch(page, r1, (String) null);		if (r2 != null)			t_util.t_checkFetch(page, r2, REC_002);		t_util.t_checkFetch(page, r1, (String) null);		if (r2 != null)			t_util.t_checkFetch(page, r2, REC_002);		row1 = new T_RawStoreRow(REC_003);		if (!page.update(r1, row1.getRow(), (FormatableBitSet) null))			throw T_Fail.testFailMsg("update() returned false");		t_util.t_checkFetch(page, r1, REC_003);		if (r2 != null)			t_util.t_checkFetch(page, r2, REC_002);		// now delete the record we have been updating		if (!page.delete(r1, (LogicalUndo)null))			throw T_Fail.testFailMsg("delete returned false");		row1 = new T_RawStoreRow(REC_004);		if (page.update(r1, row1.getRow(), (FormatableBitSet) null))			throw T_Fail.testFailMsg("update returned true on deleted record");		page.deleteAtSlot(0, false, (LogicalUndo)null);		t_util.t_checkFetch(page, r1, REC_003);		if (!page.update(r1, row1.getRow(), (FormatableBitSet) null))			throw T_Fail.testFailMsg("update returned false");		t_util.t_checkFetch(page, r1, REC_004);		t_util.t_dropContainer(t, segment, cid);	// cleanup		t_util.t_commit(t);		t.close();		PASS("P004");	}	/* test repeated insert */	protected void P005(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 page1 = t_util.t_getLastPage(c);			T_RawStoreRow row0 = new T_RawStoreRow			("long row xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx long row ");		T_RawStoreRow row1 = new T_RawStoreRow			("medium row yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy medium row");		t_util.t_insertAtSlot(page1, 0, row0);		int i = 0;		while (page1.spaceForInsert())		{			if (t_util.t_insertAtSlot(page1, 1, row1) == null)				break;			i++;		}		int count1 = page1.recordCount();		Page page2 = t_util.t_addPage(c);		t_util.t_insertAtSlot(page2, 0, row0);		i = 1;		while (page2.spaceForInsert())		{			if (t_util.t_insertAtSlot(page2, i++, row1) == null)				break;

⌨️ 快捷键说明

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