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

📄 storedrecordheader.java

📁 derby database source code.good for you.
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/*   Derby - Class org.apache.derby.impl.store.raw.data.StoredRecordHeader   Copyright 2002, 2004 The Apache Software Foundation or its licensors, as applicable.   Licensed under the Apache License, Version 2.0 (the "License");   you may not use this file except in compliance with the License.   You may obtain a copy of the License at      http://www.apache.org/licenses/LICENSE-2.0   Unless required by applicable law or agreed to in writing, software   distributed under the License is distributed on an "AS IS" BASIS,   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.   See the License for the specific language governing permissions and   limitations under the License. */package org.apache.derby.impl.store.raw.data;import org.apache.derby.iapi.services.sanity.SanityManager;import org.apache.derby.iapi.store.raw.PageKey;import org.apache.derby.iapi.store.raw.RecordHandle;import java.io.IOException;import java.io.EOFException;import java.io.InputStream;import java.io.OutputStream;import org.apache.derby.iapi.services.io.CompressedNumber;/**	A class StoredPage uses to cache record headers by passing instances	to BasePage, and to write stored versions of record headers.	Format	<PRE>	1 byte          - status	compressed int  - record identifier	compressed long - overflow page } only if hasOverflow() is true	compressed int  - overflow id   }     "        "           "	compressed int  - first field   } only if hasFirstField set - otherwise 0	compressed int  - number of fields in this portion - only if hasOverflow()								is false OR hasFirstField is true - otherwise 0	</PRE>*/public final class StoredRecordHeader{    /**************************************************************************     * Constants of the class     **************************************************************************     */    /**     * Status bits for the record header:     *     * RECORD_INITIAL			- used when record header is first initialized     * RECORD_DELETED			- used to indicate the record has been deleted     * RECORD_OVERFLOW			- used to indicate the record has been      *                            overflowed, it will point to the overflow      *                            page and ID     * RECORD_HAS_FIRST_FIELD	- used to indicate that firstField is stored      *                            will be stored.  When RECORD_OVERFLOW and      *                            RECORD_HAS_FIRST_FIELD both are set, part of      *                            record is on the page, the record header      *                            also stores the overflow point to the next      *                            part of the record.     * RECORD_VALID_MASK        - A mask of valid bits that can be set      *                            currently, such that the following assert can     *                            be made:      *                              ASSERT((status & ~RECORD_VALID_MASK) == 0))     **/	public static final int RECORD_INITIAL =			0x00;	public static final int RECORD_DELETED =			0x01;	public static final int RECORD_OVERFLOW =			0x02;	public static final int RECORD_HAS_FIRST_FIELD =	0x04;     public static final int RECORD_VALID_MASK  =        0x0f;    /**************************************************************************     * Fields of the class     **************************************************************************     */    /**     * Actual identifier of the record     *     * <BR> MT - Mutable     **/	protected int   id;    /**     * Status of the record.     *     * See above for description of fields:     *     RECORD_INITIAL     *     RECORD_DELETED     *     RECORD_OVERFLOW     *     RECORD_HAS_FIRST_FIELD     *     RECORD_VALID_MASK     *     * <BR> MT - Mutable - single thread required.     **/	protected int status;    /**     * number of fields in the row.     **/	protected int numberFields;    /**     * A record handle that can represent the record, may be null.     **/	protected RecordHandle	handle;    /**     * If (hasOverflow()) then this is the id of the row on page overflowPage     * where the next portion of the row can be found.  In this case there     * are no "real" fields on this page.  This situation comes about if a     * row has been updated such that the real first field no longer fits on     * the head page.     **/	protected int	overflowId;    /**     * If (hasOverflow()) then this is the page where where the next portion of     * the row can be found.  In this case there are no "real" fields on this      * page.     **/	protected long  overflowPage;    /**     * if (hasFirstField()) then this field is the number of the column in     * the orginal row which is now stored as the first field in this row.  This     * row is 2nd through N'th portion of a long row.      *     * For example if a row has its first 3 fields on page 0 and its next 3     * fields on page 1, then the record header of the row portion on page 1     * will have hasFirstField() set to true, and the value would be 4,      * indicating that the 4th field of the row is stored as the 1st field of     * the partial row portion stored on page 1.     **/	protected int	firstField;    /**************************************************************************     * Constructors for This class:     **************************************************************************     */	public StoredRecordHeader()     {	}	public StoredRecordHeader(int id, int numberFields)     {		setId(id);		setNumberFields(numberFields);	}	public StoredRecordHeader(    byte    data[],    int     offset)    {        read(data, offset);	}	public StoredRecordHeader(StoredRecordHeader loadTargetFrom)     {		this.status         = loadTargetFrom.status;		this.id             = loadTargetFrom.id;		this.numberFields   = loadTargetFrom.numberFields;		handle              = null;		overflowId          = loadTargetFrom.overflowId;		overflowPage        = loadTargetFrom.overflowPage;		firstField          = loadTargetFrom.firstField;	}    /**************************************************************************     * Public Accessor "Get" Methods of This class:     **************************************************************************     */    /**     * Get a record handle for the record.     * <p>     *     * <BR> MT - single thread required     **/	protected RecordHandle getHandle(    PageKey pageId,     int current_slot)     {		if (handle == null)			handle = new RecordId(pageId, id, current_slot);		return handle;	}    /**     * Get the record identifier     *     * <BR> MT - thread safe     **/	public final int getId()     {		return id;	}	public int getNumberFields()     {		return numberFields;	}	public long getOverflowPage()     {		return overflowPage;	}	public int getOverflowId()     {		return overflowId;	}	public int getFirstField()     {		return firstField;	}	public final boolean hasOverflow()     {		return ((status & RECORD_OVERFLOW) == RECORD_OVERFLOW);	}	protected final boolean hasFirstField()     {		return ((status & RECORD_HAS_FIRST_FIELD) == RECORD_HAS_FIRST_FIELD);	}    /**     * Get the deleted state of the record.     * <p>     *     * <BR> MT - single thread required     **/	public final boolean isDeleted()     {		return ((status & RECORD_DELETED) == RECORD_DELETED);	}    /**     * return the size of the record header.     * <p>     * Calculates the size of the record header, mostly used to allow a     * reader to skip over the record header and position on the 1st field     * of the record.     * <p>     * This low level routine is performance critical to processing lots of     * rows, so calls to CompressNumber have been hand inlined.     *	 * @return The length of the record header.     *	 * @exception  StandardException  Standard exception policy.     **/	public int size()     {        // account for length of fieldDataLength field stored as a compressed        // int plus one byte for status.          //        //    int len = CompressedNumber.sizeInt(id) + 1;        int len =           (id <= CompressedNumber.MAX_COMPRESSED_INT_ONE_BYTE) ?              2 :           (id <= CompressedNumber.MAX_COMPRESSED_INT_TWO_BYTES) ?              3 : 5;        if ((status & (RECORD_OVERFLOW | RECORD_HAS_FIRST_FIELD)) == 0)        {            // usual case, not a record overflow and does not have first field            len +=               (numberFields <= CompressedNumber.MAX_COMPRESSED_INT_ONE_BYTE) ?                  1 :               (numberFields <= CompressedNumber.MAX_COMPRESSED_INT_TWO_BYTES) ?                  2 : 4;        }        else if ((status & RECORD_OVERFLOW) == 0)        {            // not overflow, and has first field set.            // account for size of the numberFields field + size fo the             // firstField field.            //            //     len += (CompressedNumber.sizeInt(numberFields) +            //             CompressedNumber.sizeInt(firstField);            //            len +=               ((numberFields <= CompressedNumber.MAX_COMPRESSED_INT_ONE_BYTE) ?                  1 :                (numberFields <= CompressedNumber.MAX_COMPRESSED_INT_TWO_BYTES) ?                  2 : 4) +              ((firstField <= CompressedNumber.MAX_COMPRESSED_INT_ONE_BYTE) ?                  1 :                (firstField <= CompressedNumber.MAX_COMPRESSED_INT_TWO_BYTES) ?                  2 : 4);        }        else        {            // is an overflow field			len += CompressedNumber.sizeLong(overflowPage);			len += CompressedNumber.sizeInt(overflowId);            if (hasFirstField())            {                len += CompressedNumber.sizeInt(firstField);                len += CompressedNumber.sizeInt(numberFields);            }		}		return len;	}    /**************************************************************************     * Public Accessor "Set" Methods of This class:     **************************************************************************     */    /**     * Set the deleted state of the record.     * <p>     * return	1, if delete status from not deleted to deleted     * return  -1, if delete status from deleted to not deleted     * return   0, if status unchanged.     *     * <BR> MT - single thread required     **/	public int setDeleted(boolean deleteTrue)     {		int retCode = 0;		if (deleteTrue)         {			if (!isDeleted())             {				// setting the bit from not deleted to deleted				retCode = 1;				status |= RECORD_DELETED;			}		}         else         {			if (isDeleted())             {				// setting the bit from deleted to not deleted				retCode = -1;				status &= ~RECORD_DELETED;			}		}		return(retCode);	}	public void setFirstField(int firstField)     {		this.firstField = firstField;        status |= RECORD_HAS_FIRST_FIELD;	}	public final void setId(int id)     {		this.id = id;	}	public void setOverflowDetails(RecordHandle overflowHandle)     {		this.overflowPage   = overflowHandle.getPageNumber();

⌨️ 快捷键说明

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