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

📄 t_util.java

📁 derby database source code.good for you.
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
	 * The slot refers to a row in the page which has a T_RawStoreRow of 1 column, the	 * column has the value of data input.	 *	 * @param page the page in question	 * @param slot the slot number (see above)	 * @param data the column value	 * @param deleted if the row is deleted, set to true	 * @param forUpdate If you want to lock the row for update, set forUpdate to true.	 *	 */	public static void t_checkFetchBySlot(Page page, int slot, 									String data, boolean deleted, 									boolean forUpdate)		throws T_Fail, StandardException 	{		T_RawStoreRow readRow = new T_RawStoreRow((String) null);		RecordHandle rh =             page.fetchFromSlot(                (RecordHandle) null, slot,                 readRow.getRow(),                (FetchDescriptor) null,                true);		if (rh == null)			throw T_Fail.testFailMsg("Failed to read record");		if (!readRow.toString().equals(data))			throw T_Fail.testFailMsg("Record's value incorrect, expected :" + data + ": - got :" + readRow.toString());		if (page.isDeletedAtSlot(slot) != deleted)			throw T_Fail.testFailMsg("Record at slot " + slot + " deleted=" +									 page.isDeletedAtSlot(slot) + ", expect " + deleted);		// RESOLVE: check locking	}	/*	 * check a column value from a slot on the page	 *	 * The slot number is NOT a stable reference once the page is unlatched,	 * this check is only valid if you know the page has not been unlatched	 * since you put the row in, or you know nobody has touched the page since	 * you determined the slot number	 *	 * The storable in the specified column put into the input column and it	 * is check for the same value as the input data 	 *	 * @param page the page in question	 * @param slot the slot number (see above)	 * @param fieldId the field Id on the row	 * @param column the storable to put the column in	 * @param forUpdate true if you want to lock the row for update	 * @param data the expected value in the column	 */	public static void t_checkFetchColFromSlot(Page page,										 int slot,										 int fieldId,										 DataValueDescriptor column,										 boolean forUpdate,										 String data,										 int stringLen)		 throws StandardException, T_Fail	{		t_checkFetchColFromSlot(page, slot, fieldId, column, forUpdate, T_Util.getStringFromData(data, stringLen));	}		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);		// RESOLVE - how to check rh lock mode?		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);		}	}	/**		Take an empty page and check it does actually seem to be empty.		@exception T_Fail Unexpected behaviour from the API		@exception StandardException Unexpected exception from the implementation	*/	public static void t_checkEmptyPage(Page page) throws T_Fail, StandardException {		// check the counts		t_checkRecordCount(page, 0, 0);        try        {            page.fetchFromSlot(                (RecordHandle) null, 0, null,                 (FetchDescriptor) null,                false);            throw T_Fail.testFailMsg(                "fetchFromSlot() must throw exception on fetch from slot 0 on an empty page");        }        catch (StandardException se)        {            // expected exception.        }		// check we can't get a record handle. NB here we are guessing that 0		// and RecordHandle.FIRST_RECORD_ID might be valid record identifiers,		// nothing in the API states that they will be.  Eother way we		// shouldn't get a valid RecordHandle back.		if (page.getRecordHandle(0) != null)			throw T_Fail.testFailMsg("obtained a RecordHandle for an empty page");		if (page.getRecordHandle(RecordHandle.FIRST_RECORD_ID) != null)			throw T_Fail.testFailMsg("obtained a RecordHandle for an empty page");				// should be no aux object		if (page.getAuxObject() != null)			throw T_Fail.testFailMsg("empty page has an aux object");		t_readOnlySlotOutOfRange(page, Page.FIRST_SLOT_NUMBER);		if (!page.spaceForInsert())			throw T_Fail.testFailMsg("spaceForInsert() returned false on an empty page");	}	/*		Check to see the correct behaviour for read only operations		that take a slot when the slot is out of range.	*/	public static void t_readOnlySlotOutOfRange(Page page, int slot) throws T_Fail, StandardException {		try {			page.fetchFromSlot(                (RecordHandle) null, slot,                 new DataValueDescriptor[0],                 (FetchDescriptor) null,                true);			throw T_Fail.testFailMsg("fetchFromSlot succeeded on out of range slot " + slot);		} catch (StandardException se0) {			// Statement exception expected, throw if not a statement exception.            if (se0.getSeverity() > ExceptionSeverity.STATEMENT_SEVERITY)                throw se0;		}		try {			page.isDeletedAtSlot(slot);			throw T_Fail.testFailMsg("isDeletedAtSlot succeeded on out of range slot " + slot);		} catch (StandardException se2) {			// Statement exception expected, throw if not a statement exception.            if (se2.getSeverity() > ExceptionSeverity.STATEMENT_SEVERITY)                throw se2;		}	}	/*		Check to see the correct behaviour for update operations		that take a slot when the slot is out of range.	*/	public static void t_updateSlotOutOfRange(Page page, int slot) throws T_Fail, StandardException {		try {			page.deleteAtSlot(slot, false, (LogicalUndo)null);			throw T_Fail.testFailMsg("deleteAtSlot succeeded on out of range slot " + slot);		} catch (StandardException se0) {			// Statement exception expected, throw if not a statement exception.            if (se0.getSeverity() > ExceptionSeverity.STATEMENT_SEVERITY)                throw se0;		}		try {			page.deleteAtSlot(slot, true, (LogicalUndo)null);			throw T_Fail.testFailMsg("deleteAtSlot succeeded on out of range slot " + slot);		} catch (StandardException se0) {			// Statement exception expected, throw if not a statement exception.            if (se0.getSeverity() > ExceptionSeverity.STATEMENT_SEVERITY)                throw se0;		}		T_RawStoreRow row = new T_RawStoreRow((String) null);		// insert at the last slot will succeed, so don't do it.		if (page.recordCount() != slot) {			try {								page.insertAtSlot(slot, row.getRow(), (FormatableBitSet) null, (LogicalUndo)null,						Page.INSERT_DEFAULT, 100);					throw T_Fail.testFailMsg("insertAtSlot succeeded, on out of range slot " + slot);            } catch (StandardException se0) {                // Statement exception expected, throw if not a statement exception.                if (se0.getSeverity() > ExceptionSeverity.STATEMENT_SEVERITY)                    throw se0;            }		}		try {						page.updateAtSlot(slot, row.getRow(), (FormatableBitSet) null);			throw T_Fail.testFailMsg("updateAtSlot succeeded on out of range slot " + slot);        } catch (StandardException se0) {            // Statement exception expected, throw if not a statement exception.            if (se0.getSeverity() > ExceptionSeverity.STATEMENT_SEVERITY)                throw se0;        }	}	/*	 * Save point checks	 */	/**		Negative test - check that an invalid savepoint is detected.	    		@exception T_Fail Unexpected behaviour from the API		@exception StandardException Unexpected exception from the implementation	*/	public static void t_checkInvalidSavePoint(Transaction t, String name)		throws T_Fail, StandardException {		// check a non-existent save point is trapped		try {			t.rollbackToSavePoint(name, null);			throw T_Fail.testFailMsg("non existent save point did not cause exception on rollbackToSavePoint");		} catch (StandardException se) {			// we expected this ...		}		try {			t.releaseSavePoint(name, null);			throw T_Fail.testFailMsg("non existent save point did not cause exception on releaseSavePoint");		} catch (StandardException se) {			// we expected this ...		}	}	/* 	 * same as above, check an invalid savepoint in the given transaction	 * context	 */	public void t_checkInvalidSavePoint(T_TWC ctx, String name)		throws T_Fail, StandardException {		csFactory.setCurrentContextManager(ctx.cm);		try {		t_checkInvalidSavePoint(ctx.tran, name);		} finally {			csFactory.resetCurrentContextManager(ctx.cm);		}	}	/*	 * function that actually do something, start, commit, abort a trasaction,	 * get a page, insert a row, etc.	 */	/*		Start a user transaction, ensures that the startTransaction method		does not return null (which it shouldn't).	*/	public Transaction t_startTransaction() 		throws StandardException, T_Fail {						Transaction t1 =                 rsFactory.startTransaction(                    csFactory.getCurrentContextManager(),					AccessFactoryGlobals.USER_TRANS_NAME);			if (t1 == null)				throw T_Fail.testFailMsg("Start a transaction");			t_checkNullLockCount(t1);			return t1;	}	/*		Start a user transaction, ensures that the startTransaction method		does not return null (which it shouldn't).	*/	public Transaction t_startGlobalTransaction(    int     format_id,    byte[]  global_id,    byte[]  branch_id) 		throws StandardException, T_Fail {			Transaction t1 =                 rsFactory.startGlobalTransaction(                    csFactory.getCurrentContextManager(),                    format_id, global_id, branch_id);			if (t1 == null)				throw T_Fail.testFailMsg("Start a transaction");			t_checkNullLockCount(t1);			return t1;	}	/*	 * start a user transaction with its own context (T_TWC)	 */	public T_TWC t_startTransactionWithContext()		throws StandardException, T_Fail	{		T_TWC ctx = new T_TWC(csFactory, lFactory, rsFactory);		ctx.startUserTransaction();		return ctx;	}	/*	 * start an internal transaction	 */	public Transaction t_startInternalTransaction() 		throws StandardException, T_Fail {			Transaction t1 = rsFactory.startInternalTransaction(csFactory.getCurrentContextManager());			if (t1 == null)				throw T_Fail.testFailMsg("Failed to start an internal transaction");			t_checkNullLockCount(t1);			return t1;	}	/*	 * commit a transaction	 */	public void t_commit(Transaction t) 		throws StandardException, T_Fail {		t.commit();		t_checkNullLockCount(t);	}	/*	 * commit a transaction with context	 */	public void t_commit(T_TWC ctx) 		throws StandardException, T_Fail 	{		csFactory.setCurrentContextManager(ctx.cm);		try {		t_commit(ctx.tran);		} finally {			csFactory.resetCurrentContextManager(ctx.cm);		}	}	/*	 * close a transaction with context	 */	public void t_close(T_TWC ctx)		throws StandardException, T_Fail 	{		ctx.tran.close();		ctx.tran = null;		ctx.cm = null;		// no need to close a context ???	}	/*	 * abort a transaction	 */	public void t_abort(Transaction t) 		throws StandardException, T_Fail {		t.abort();		t_checkNullLockCount(t);	}	/*	 * abort a transaction with context	 */	public void t_abort(T_TWC ctx) 		throws StandardException, T_Fail 	{		csFactory.setCurrentContextManager(ctx.cm);		try {		t_abort(ctx.tran);		} finally {			csFactory.resetCurrentContextManager(ctx.cm);		}	}	/**		Add a new container in the transaction		@exception T_Fail Unexpected behaviour from the API		@exception StandardException Unexpected exception from the implementation	*/	public long t_addContainer(Transaction t, long segmentId)		throws StandardException, T_Fail {				long cid =             t.addContainer(                segmentId, ContainerHandle.DEFAULT_ASSIGN_ID,                 ContainerHandle.MODE_DEFAULT, (Properties) null, 0);		if (cid < 0)			throw T_Fail.testFailMsg("add container");		return cid;			}	public long t_addContainer(T_TWC ctx, long segmentId)		throws StandardException, T_Fail 	{		csFactory.setCurrentContextManager(ctx.cm);		try {		return t_addContainer(ctx.tran, segmentId);		} finally {			csFactory.resetCurrentContextManager(ctx.cm);		}	}	/**		Add a new container in the transaction with a specified page size		@exception T_Fail Unexpected behaviour from the API		@exception StandardException Unexpected exception from the implementation	*/	public long t_addContainer(Transaction t, long segmentId, int pageSize)		throws StandardException, T_Fail {		Properties tableProperties = new Properties();		tableProperties.put(Property.PAGE_SIZE_PARAMETER, Integer.toString(pageSize));				long cid =             t.addContainer(                segmentId, ContainerHandle.DEFAULT_ASSIGN_ID,                 ContainerHandle.MODE_DEFAULT, tableProperties, 0);		if (cid < 0)			throw T_Fail.testFailMsg("add container");		return cid;			}	public long t_addContainer(T_TWC ctx, long segmentId, int pageSize)		throws StandardException, T_Fail {		csFactory.setCurrentContextManager(ctx.cm);		try {		return t_addContainer(ctx.tran, segmentId, pageSize);		} finally {			csFactory.resetCurrentContextManager(ctx.cm);		}	}	public long t_addContainer(Transaction t, long segmentId, Properties tableProperties)		throws StandardException, T_Fail {		long cid =             t.addContainer(                segmentId, ContainerHandle.DEFAULT_ASSIGN_ID,                 ContainerHandle.MODE_DEFAULT, tableProperties, 0);		if (cid < 0)			throw T_Fail.testFailMsg("add container");

⌨️ 快捷键说明

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