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

📄 basepage.java

📁 derby database source code.good for you.
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
			int slot = curPage.recordCount;			int recordId = curPage.newRecordId();			handle = new RecordId(curPage.getPageId(), recordId, slot);			if (isFirstPage)				firstHandle = handle;			// step 2: insert column portion			startColumn = owner.getActionSet().actionInsert(t, curPage, slot, recordId,				row, (FormatableBitSet)null, (LogicalUndo) null, insertFlag,				startColumn, true, -1, (DynamicByteArrayOutputStream) null, -1, 100);			// step 3: if it is not the first page, update previous page,			// then release latch on prevPage			if (!isFirstPage) {				// for the previous page, add an overflow field header,				// and update the record header to show 2 fields				prevPage.updateFieldOverflowDetails(prevHandle, handle);				prevPage.unlatch();				prevPage = null;			} else				isFirstPage = false;		} while (startColumn != (-1)) ;		if (curPage != null) {			curPage.unlatch();			curPage = null;		}		return (firstHandle);	}	/**		The page or its header is about to be modified.		Loggable actions use this to make sure the page gets cleaned if a		checkpoint is taken after any log record is sent to the log stream but		before the page is actually dirtied.	*/	public abstract void preDirty();	/**		Update the overflow pointer for a long row		<BR> MT - latched - page latch must be held		@param handle			handle of the record for long row		@param overflowHandle	the overflow (continuation) pointer for the long row		@exception StandardException	Standard Cloudscape error policy	*/	public abstract void updateOverflowDetails(RecordHandle handle, RecordHandle overflowHandle)		throws StandardException;	/**		Update the overflow pointer for a long column		<BR> MT - latched - page latch must be held		@param handle			handle of the record for long row		@param overflowHandle	the overflow (continuation) pointer for the long row		@exception StandardException	Standard Cloudscape error policy	*/	public abstract void updateFieldOverflowDetails(RecordHandle handle, RecordHandle overflowHandle)		throws StandardException;	/**		Append an overflow pointer to a partly logged row,		to point to a long column that just been logged.		<BR> MT - latched - page latch must be held		@param logBuffer		The buffer that contains the partially logged row.		@param overflowHandle	the overflow (continuation) pointer								to the beginning of the long column		@exception StandardException	Standard Cloudscape error policy	*/	public abstract int appendOverflowFieldHeader(DynamicByteArrayOutputStream logBuffer, RecordHandle overflowHandle)		throws StandardException, IOException;	public abstract BasePage getOverflowPageForInsert(    int        slot,     Object[]   row,     FormatableBitSet    validColumns,     int        startColumn)		throws StandardException;	protected abstract BasePage getNewOverflowPage()		throws StandardException;	public final boolean update(    RecordHandle            handle,     Object[]   row,     FormatableBitSet                 validColumns)		throws StandardException	{		if (SanityManager.DEBUG) {			SanityManager.ASSERT(isLatched());		}		if (!owner.updateOK())        {			throw StandardException.newException(                    SQLState.DATA_CONTAINER_READ_ONLY);        }		RawTransaction t = owner.getTransaction();		owner.getLockingPolicy().lockRecordForWrite(myLatch, handle);		int slot = getSlotNumber(handle);		if (isDeletedAtSlot(slot))			return false;		doUpdateAtSlot(t, slot, handle.getId(), row, validColumns);				return true;	}	/** @see Page#delete	    @see BasePage#deleteAtSlot		@exception StandardException Standard exception policy. 	*/	public boolean delete(RecordHandle handle, LogicalUndo undo)		throws StandardException	{		if (SanityManager.DEBUG) {			SanityManager.ASSERT(isLatched());		}		owner.getLockingPolicy().lockRecordForWrite(myLatch, handle);		int slot = getSlotNumber(handle);		if (isDeletedAtSlot(slot))			return false;		deleteAtSlot(slot, true, undo);		return true;	}	/** @see Page#updateAtSlot		@exception StandardException	Standard Cloudscape error policy		@exception StandardException	StandardException.newException(SQLState.UPDATE_DELETED_RECORD		if the record is already deleted		@exception StandardException	StandardException.newException(SQLState.CONTAINER_READ_ONLY		if the container is read only	 */	public final RecordHandle updateAtSlot(    int                     slot,     Object[]   row,     FormatableBitSet                 validColumns)		 throws	StandardException	{		if (SanityManager.DEBUG) {			SanityManager.ASSERT(isLatched());		}		if (!owner.updateOK())        {			throw StandardException.newException(                    SQLState.DATA_CONTAINER_READ_ONLY);        }		if (isDeletedAtSlot(slot))        {			throw StandardException.newException(                    SQLState.DATA_UPDATE_DELETED_RECORD);        }		RecordHandle handle = getRecordHandleAtSlot(slot);		RawTransaction t = owner.getTransaction();		doUpdateAtSlot(t, slot, handle.getId(), row, validColumns);				return handle;	}	public abstract void doUpdateAtSlot(    RawTransaction          t,     int                     slot,     int                     id,     Object[]   row,     FormatableBitSet                 validColumns)		throws	StandardException;	/** @see Page#updateFieldAtSlot		@exception StandardException	Standard Cloudscape error policy		@exception StandardException	StandardException.newException(SQLState.UPDATE_DELETED_RECORD		if the record is already deleted		@exception StandardException	StandardException.newException(SQLState.CONTAINER_READ_ONLY		if the container is read only	*/	public RecordHandle updateFieldAtSlot(    int                 slot,     int                 fieldId,     Object newValue,     LogicalUndo         undo)		throws StandardException	{		if (SanityManager.DEBUG) {			SanityManager.ASSERT(isLatched());			SanityManager.ASSERT(newValue != null);		}		if (!owner.updateOK())        {			throw StandardException.newException(                    SQLState.DATA_CONTAINER_READ_ONLY);        }		if (isDeletedAtSlot(slot))        {			throw StandardException.newException(                    SQLState.DATA_UPDATE_DELETED_RECORD);        }		RawTransaction t = owner.getTransaction();		RecordHandle handle = getRecordHandleAtSlot(slot);		owner.getActionSet().actionUpdateField(t, this, slot,				handle.getId(), fieldId, newValue, undo);		return handle;	}	/** @see Page#fetchNumFields		@exception StandardException Standard exception policy. 	*/	public final int fetchNumFields(RecordHandle handle)		 throws StandardException	{		if (SanityManager.DEBUG) {			SanityManager.ASSERT(isLatched());		}		return fetchNumFieldsAtSlot(getSlotNumber(handle));	}	/** @see Page#fetchNumFieldsAtSlot		@exception StandardException Standard exception policy. 	*/	public int fetchNumFieldsAtSlot(int slot)		 throws StandardException	{		if (SanityManager.DEBUG) {			SanityManager.ASSERT(isLatched());		}		return getHeaderAtSlot(slot).getNumberFields();	}	/** 		@see Page#deleteAtSlot		@param slot		the slot number		@param delete	true if this record is to be deleted, false if this						deleted record is to be marked undeleted		@param undo		logical undo logic if necessary		@exception StandardException Standard exception policy. 		@exception StandardException	StandardException.newException(SQLState.UPDATE_DELETED_RECORD		if an attempt to delete a record that is already deleted		@exception StandardException	StandardException.newException(SQLState.UNDELETE_RECORD		if an attempt to undelete a record that is not deleted	 */	public RecordHandle deleteAtSlot(int slot, boolean delete, LogicalUndo undo)		throws StandardException	{		if (SanityManager.DEBUG) {			SanityManager.ASSERT(isLatched());		}		if (!owner.updateOK())        {			throw StandardException.newException(                    SQLState.DATA_CONTAINER_READ_ONLY);        }		if (delete)		{			if (isDeletedAtSlot(slot))            {				throw StandardException.newException(                        SQLState.DATA_UPDATE_DELETED_RECORD);            }		}		else					// undelete a deleted record		{			if (!isDeletedAtSlot(slot))            {				throw StandardException.newException(                        SQLState.DATA_UNDELETE_RECORD);            }		}		RawTransaction t = owner.getTransaction();		// logical operations not allowed in internal transactions.		if (undo != null) {			t.checkLogicalOperationOk();		}		RecordHandle handle = getRecordHandleAtSlot(slot);		owner.getActionSet().actionDelete(t, this, slot, handle.getId(), delete, undo);				// delete/undelete the record in the stored version		// and in the in memory version performed by the PageActions item 		return handle;	}	/** 		Purge one or more rows on a non-overflow page.		@see Page#purgeAtSlot		@exception StandardException Standard exception policy. 	 */	public void purgeAtSlot(int slot, int numpurges, boolean needDataLogged)		throws StandardException	{		if (SanityManager.DEBUG)         {			SanityManager.ASSERT(isLatched());            if (isOverflowPage())                SanityManager.THROWASSERT(                    "purge committed deletes on an overflow page.  Page = " +                     this);		}		if (numpurges <= 0)			return;		if (!owner.updateOK())        {			throw StandardException.newException(                    SQLState.DATA_CONTAINER_READ_ONLY);        }		if ((slot < 0) || ((slot+numpurges) > recordCount))        {			throw StandardException.newException(                    SQLState.DATA_SLOT_NOT_ON_PAGE);        }		RawTransaction t = owner.getTransaction();		// lock the records to be purged		int[] recordIds = new int[numpurges];		PageKey pageId = getPageId(); // RESOLVE: MT problem ?		for (int i = 0; i < numpurges; i++)		{			recordIds[i] = getHeaderAtSlot(slot + i).getId();			// get row lock on head row piece			RecordHandle handle = getRecordHandleAtSlot(slot);			owner.getLockingPolicy().lockRecordForWrite(t, handle, false, true);			// Before we purge these rows, we need to make sure they don't have			// overflow rows and columns.  Only clean up long rows and long			// columns if this is not a temporary container, otherwise, just			// loose the space.			if (owner.isTemporaryContainer() ||	entireRecordOnPage(slot+i))				continue;			// row[slot+i] has overflow rows and/or long columns, reclaim			// them in a loop.			RecordHandle headRowHandle = 				getHeaderAtSlot(slot+i).getHandle(pageId, slot+i);			purgeRowPieces(t, slot+i, headRowHandle, needDataLogged);		}		owner.getActionSet().actionPurge(t, this, slot, numpurges, recordIds, needDataLogged);	}	/**		Purge all the overflow columns and overflow rows of the record at slot.		@exception StandardException Standard exception policy. 	 */	protected abstract void purgeRowPieces(RawTransaction t, int slot, 										   RecordHandle headRowHandle, 										   boolean needDataLogged)		 throws StandardException; 	/** @see Page#copyAndPurge		@exception StandardException Standard exception policy. 	*/	public void copyAndPurge(Page destPage, int src_slot, int num_rows, int dest_slot)		 throws StandardException	{		if (SanityManager.DEBUG) {			SanityManager.ASSERT(isLatched());		}		if (num_rows <= 0)        {            throw StandardException.newException(SQLState.DATA_NO_ROW_COPIED);        }		if (!owner.updateOK())        {			throw StandardException.newException(                    SQLState.DATA_CONTAINER_READ_ONLY);        }		if ((src_slot < 0) || ((src_slot + num_rows) > recordCount))        {			throw StandardException.newException(                    SQLState.DATA_SLOT_NOT_ON_PAGE);        }		if (SanityManager.DEBUG) {			// first copy into the destination page, let it do the work			// if no problem, then purge from this page			SanityManager.ASSERT((destPage instanceof BasePage), "must copy from BasePage to BasePage");		}		BasePage dpage = (BasePage)destPage;		// make sure they are from the same container - this means they are of		// the same size and have the same page and record format.		PageKey pageId = getPageId(); // RESOLVE: MT problem ?		if (!pageId.getContainerId().equals(dpage.getPageId().getContainerId()))        {			throw StandardException.newException(                    SQLState.DATA_DIFFERENT_CONTAINER,                     pageId.getContainerId(),                     dpage.getPageId().getContainerId());        }		int[] recordIds = new int[num_rows];		RawTransaction t = owner.getTransaction();		// lock the records to be purged and calculate total space needed		for (int i = 0; i < num_rows; i++)		{			RecordHandle handle = getRecordHandleAtSlot(src_slot+i);			owner.getLockingPolicy().lockRecordForWrite(t, handle, false, true);			recordIds[i] = getHeaderAtSlot(src_slot + i).getId();		}

⌨️ 快捷键说明

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