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

📄 btree.java

📁 derby database source code.good for you.
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
    The following properties are generic to a b-tree conglomerate.  :    <UL>    <LI>"allowDuplicates" (boolean).  If set to true the table will allow     rows which are duplicate in key column's 0 through (nUniqueColumns - 1).    Currently only supports "false".    This property is optional, defaults to false.    <LI>"nKeyFields"  (integer) Columns 0 through (nKeyFields - 1) will be     included in key of the conglomerate.    This implementation requires that "nKeyFields" must be the same as the    number of fields in the conglomerate, including the rowLocationColumn.    Other implementations may relax this restriction to allow non-key fields    in the index.    This property is required.    <LI>"nUniqueColumns" (integer) Columns 0 through "nUniqueColumns" will be     used to check for uniqueness.  So for a standard SQL non-unique index     implementation set "nUniqueColumns" to the same value as "nKeyFields"; and    for a unique index set "nUniqueColumns" to "nKeyFields" - 1 (ie. don't     include the rowLocationColumn in the uniqueness check).    This property is required.    <LI>"maintainParentLinks" (boolean)    Whether the b-tree pages maintain the page number of their parent.  Only    used for consistency checking.  It takes a certain amount more effort to    maintain these links, but they're really handy for ensuring that the index    is consistent.    This property is optional, defaults to true.    </UL>    @exception StandardException Thrown by underlying raw store, or thrown by    this routine on an invalid containerid.    	**/	public void create(    Transaction             rawtran,    int                     segmentId,    long                    input_containerid,    DataValueDescriptor[]   template,    Properties              properties,    int                     conglom_format_id,	int                     tmpFlag    )        throws StandardException	{        String result_string;        if (properties == null)        {            throw(                StandardException.newException(                    SQLState.BTREE_PROPERTY_NOT_FOUND, PROPERTY_NKEYFIELDS));        }        // Check input arguments        allowDuplicates = (Boolean.valueOf(            properties.getProperty(PROPERTY_ALLOWDUPLICATES, "false"))).booleanValue();        result_string = properties.getProperty(PROPERTY_NKEYFIELDS);        if (result_string == null)        {            throw(                StandardException.newException(                    SQLState.BTREE_PROPERTY_NOT_FOUND, PROPERTY_NKEYFIELDS));        }        else        {            nKeyFields = Integer.parseInt(result_string);        }        result_string = properties.getProperty(PROPERTY_NUNIQUECOLUMNS);        if (result_string == null)        {            throw(StandardException.newException(                SQLState.BTREE_PROPERTY_NOT_FOUND, PROPERTY_NUNIQUECOLUMNS));        }        else        {            nUniqueColumns = Integer.parseInt(result_string);        }        if (SanityManager.DEBUG)        {            result_string =                 properties.getProperty(PROPERTY_MAX_ROWS_PER_PAGE_PARAMETER);            if (result_string != null)            {                maxRowsPerPage = Integer.parseInt(result_string);            }        }        maintainParentLinks = (Boolean.valueOf(            properties.getProperty(PROPERTY_PARENTLINKS, "true"))).booleanValue();        // RESOLVE (mikem) - true for now, if we want to support non-key         // fields eventually this assert may be wrong.        if (SanityManager.DEBUG)        {			if (template.length != nKeyFields)			{				SanityManager.THROWASSERT(					"template.length (" + template.length +					") expected to equal nKeyFields (" + 					nKeyFields + ")");			}            SanityManager.ASSERT((nUniqueColumns == nKeyFields) ||                                  (nUniqueColumns == (nKeyFields - 1)));        }        // get format id's from each column in template and store it in the        // conglomerate state.        format_ids = ConglomerateUtil.createFormatIds(template);        // copy the format id of the conglomerate.        this.conglom_format_id = conglom_format_id;		// Create a container for the b-tree with default page size and         // fill up pages.		properties.put(RawStoreFactory.PAGE_RESERVED_SPACE_PARAMETER, "0");		properties.put(RawStoreFactory.MINIMUM_RECORD_SIZE_PARAMETER, "1");		properties.put(RawStoreFactory.PAGE_REUSABLE_RECORD_ID, "true");		long containerid =             rawtran.addContainer(                segmentId, input_containerid,                 ContainerHandle.MODE_DEFAULT, properties, tmpFlag);		// Make sure the container was actually created.		// Open segment will get cleaned up when transaction is.		if (containerid <= 0)        {            throw(StandardException.newException(                    SQLState.BTREE_CANT_CREATE_CONTAINER));         }        if (SanityManager.DEBUG)        {            if (input_containerid != ContainerHandle.DEFAULT_ASSIGN_ID)                SanityManager.ASSERT(containerid == input_containerid);        }		id = new ContainerKey(segmentId, containerid);	}	/**	Drop this btree.	This must be done by a concrete implementation.	@see Conglomerate#drop    @exception StandardException Standard exception policy.	**/	public abstract void drop(TransactionManager xact_manager)		throws StandardException;	/**	Load a b-tree.  This must be done by a concrete implementation.	@see Conglomerate#load    @exception StandardException Standard exception policy.	**/	public abstract long load(	TransactionManager      xact_manager,	boolean                 createConglom,	RowLocationRetRowSource rowSource)		throws StandardException;    public long getContainerid()    {        return(this.id.getContainerId());    }    /**     * Return dynamic information about the conglomerate to be dynamically      * reused in repeated execution of a statement.     * <p>     * The dynamic info is a set of variables to be used in a given      * ScanController or ConglomerateController.  It can only be used in one      * controller at a time.  It is up to the caller to insure the correct      * thread access to this info.  The type of info in this is a scratch      * template for btree traversal, other scratch variables for qualifier      * evaluation, ...     * <p>     *	 * @return The dynamic information.     *     * @param conglomId The identifier of the conglomerate to open.     *	 * @exception  StandardException  Standard exception policy.     **/    public DynamicCompiledOpenConglomInfo getDynamicCompiledConglomInfo(    long        conglomId)		throws StandardException    {        return(new OpenConglomerateScratchSpace(format_ids));    }    /**     * Is this conglomerate temporary?     * <p>     *	 * @return whether conglomerate is temporary or not.     **/    public boolean isTemporary()    {        return (id.getSegmentId() == ContainerHandle.TEMPORARY_SEGMENT);    }	/**	Open a b-tree controller.	This must be done by a concrete implementation.	@see Conglomerate#open    @exception StandardException Standard exception policy.	**/	public abstract ConglomerateController open(    TransactionManager              xact_manager,    Transaction                     rawtran,    boolean                         hold,    int                             open_mode,    int                             lock_level,    LockingPolicy                   locking_policy,    StaticCompiledOpenConglomInfo   static_info,    DynamicCompiledOpenConglomInfo  dynamic_info)		throws StandardException;    /**************************************************************************     * Public Methods of Storable Interface (via Conglomerate):     *     This class is responsible for re/storing its own state.     **************************************************************************     */	/**	Return whether the value is null or not.	The containerid being zero is what determines nullness;  subclasses	are not expected to override this method.	@see org.apache.derby.iapi.services.io.Storable#isNull	**/	public boolean isNull()	{		return id == null;	}	/**	Restore the in-memory representation to the null value.	The containerid being zero is what determines nullness;  subclasses	are not expected to override this method.	@see org.apache.derby.iapi.services.io.Storable#restoreToNull	**/	public void restoreToNull()	{		id = null;	}	/**	Restore the in-memory representation from the stream.	@exception ClassNotFoundException Thrown if the stored representation is	serialized and a class named in the stream could not be found.    @exception IOException thrown by readObject()		@see java.io.Externalizable#readExternal	*/	public void readExternal(ObjectInput in)         throws IOException, ClassNotFoundException	{        // read in the conglomerate format id.        conglom_format_id = FormatIdUtil.readFormatIdInteger(in);		// XXX (nat) need to improve error handling		long containerid         = in.readLong();		int segmentid			= in.readInt();		nKeyFields          = in.readInt();		nUniqueColumns      = in.readInt();		allowDuplicates     = in.readBoolean();		maintainParentLinks = in.readBoolean();        // read in the array of format id's        format_ids = ConglomerateUtil.readFormatIdArray(this.nKeyFields, in);		id = new ContainerKey(segmentid, containerid);	}	public void readExternalFromArray(ArrayInputStream in)         throws IOException, ClassNotFoundException	{        // read in the conglomerate format id.        conglom_format_id = FormatIdUtil.readFormatIdInteger(in);		// XXX (nat) need to improve error handling		long containerid         = in.readLong();		int segmentid			= in.readInt();		nKeyFields          = in.readInt();		nUniqueColumns      = in.readInt();		allowDuplicates     = in.readBoolean();		maintainParentLinks = in.readBoolean();        // read in the array of format id's        format_ids = ConglomerateUtil.readFormatIdArray(this.nKeyFields, in);		id = new ContainerKey(segmentid, containerid);	}		/**	Store the stored representation of the column value in the stream.	It might be easier to simply store the properties - which would certainly	make upgrading easier.    @exception IOException thrown by writeObject()	*/	public void writeExternal(ObjectOutput out)         throws IOException    {        FormatIdUtil.writeFormatIdInteger(out, conglom_format_id);		out.writeLong(id.getContainerId());		out.writeInt((int) id.getSegmentId());		out.writeInt((nKeyFields));		out.writeInt((nUniqueColumns));		out.writeBoolean((allowDuplicates));		out.writeBoolean((maintainParentLinks));        ConglomerateUtil.writeFormatIdArray(format_ids, out);	}    /**************************************************************************     * Public toString() Method:     **************************************************************************     */    public String toString()    {        if (SanityManager.DEBUG)        {            return  ("BTREE: containerid = " +                      (this.id == null ? "null" : this.id.toString()) +                     ";nKeyFields = " + nKeyFields +                     ";nUniqueColumns = " + nUniqueColumns +                     ";allowDuplicates = " + allowDuplicates);        }        else        {            return(super.toString());        }    }}

⌨️ 快捷键说明

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