Class BTreeController
- java.lang.Object
-
- org.apache.derby.impl.store.access.btree.OpenBTree
-
- org.apache.derby.impl.store.access.btree.BTreeController
-
- All Implemented Interfaces:
- ConglomerateController, ConglomPropertyQueryable
- Direct Known Subclasses:
- B2IController
public class BTreeController extends OpenBTree implements ConglomerateController
A b-tree controller corresponds to an instance of an open b-tree conglomerate.Concurrency Notes
The concurrency rules are derived from OpenBTree.
- See Also:
OpenBTree
-
-
Field Summary
-
Fields inherited from interface org.apache.derby.iapi.store.access.ConglomerateController
LOCK_INS, LOCK_INS_PREVKEY, LOCK_READ, LOCK_UPD, LOCK_UPDATE_LOCKS, ROWISDUPLICATE
-
-
Constructor Summary
Constructors Constructor and Description BTreeController()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method and Description voidclose()Close the conglomerate controller.booleancloseForEndTransaction(boolean closeHeldScan)Close conglomerate controller as part of terminating a transaction.booleandelete(RowLocation loc)Delete a row from the conglomerate.booleanfetch(RowLocation loc, DataValueDescriptor[] row, FormatableBitSet validColumns)Fetch the row at the given location.booleanfetch(RowLocation loc, DataValueDescriptor[] row, FormatableBitSet validColumns, boolean waitForLock)Fetch the row at the given location.java.util.PropertiesgetInternalTablePropertySet(java.util.Properties prop)Request set of properties associated with a table.voidgetTableProperties(java.util.Properties prop)Request the system properties associated with a table.voidinit(TransactionManager xact_manager, boolean hold, ContainerHandle container, Transaction rawtran, int open_mode, int lock_level, BTreeLockingPolicy btree_locking_policy, BTree conglomerate, LogicalUndo undo, StaticCompiledOpenConglomInfo static_info, DynamicCompiledOpenConglomInfo dynamic_info)Initialize the controller for use.intinsert(DataValueDescriptor[] row)Insert a row into the conglomerate.voidinsertAndFetchLocation(DataValueDescriptor[] row, RowLocation templateRowLocation)Insert a row into the conglomerate, and store its location in the provided template row location.booleanisKeyed()Return whether this is a keyed conglomerate.longload(TransactionManager xact_manager, boolean createConglom, RowLocationRetRowSource rowSource)Load rows from rowSource into the opened btree.booleanlockRow(long page_num, int record_id, int lock_operation, boolean wait, int lock_duration)Lock the given record id/page num pair.booleanlockRow(RowLocation loc, int lock_operation, boolean wait, int lock_duration)Lock the given row location.RowLocationnewRowLocationTemplate()Return a row location object of the correct type to be used in calls to insertAndFetchLocation.booleanreplace(RowLocation loc, DataValueDescriptor[] row, FormatableBitSet validColumns)Replace the entire row at the given location.voidunlockRowAfterRead(RowLocation loc, boolean forUpdate, boolean row_qualifies)UnLock the given row location.-
Methods inherited from class org.apache.derby.impl.store.access.btree.OpenBTree
checkConsistency, debugConglomerate, getColumnSortOrderInfo, getConglomerate, getContainer, getContainerHandle, getEstimatedRowCount, getHeight, getHold, getLockingPolicy, getLockLevel, getOpenMode, getRawTran, getRuntimeMem, getSpaceInfo, getXactMgr, init, isClosed, isTableLocked, reopen, setEstimatedRowCount, setLockingPolicy, test_errors
-
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.apache.derby.iapi.store.access.ConglomerateController
checkConsistency, debugConglomerate, getSpaceInfo
-
-
-
-
Method Detail
-
init
public void init(TransactionManager xact_manager, boolean hold, ContainerHandle container, Transaction rawtran, int open_mode, int lock_level, BTreeLockingPolicy btree_locking_policy, BTree conglomerate, LogicalUndo undo, StaticCompiledOpenConglomInfo static_info, DynamicCompiledOpenConglomInfo dynamic_info) throws StandardException
Initialize the controller for use.Any changes to this method will probably have to be reflected in close as well.
Currently delegates to OpenBTree. If the btree controller ends up not having any state of its own, we can remove this method (the VM will dispatch to OpenBTree), gaining some small efficiency. For now, this method remains for clarity.
- Throws:
StandardException- Standard exception policy.
-
close
public void close() throws StandardExceptionClose the conglomerate controller.Any changes to this method will probably have to be reflected in close as well.
Currently delegates to OpenBTree. If the btree controller ends up not having any state of its own, we can remove this method (the VM will dispatch to OpenBTree), gaining some small efficiency. For now, this method remains for clarity.
- Specified by:
closein interfaceConglomerateController- Overrides:
closein classOpenBTree- Throws:
StandardException- Standard exception policy.- See Also:
ConglomerateController.close()
-
closeForEndTransaction
public boolean closeForEndTransaction(boolean closeHeldScan) throws StandardExceptionClose conglomerate controller as part of terminating a transaction.Use this call to close the conglomerate controller resources as part of committing or aborting a transaction. The normal close() routine may do some cleanup that is either unnecessary, or not correct due to the unknown condition of the controller following a transaction ending error. Use this call when closing all controllers as part of an abort of a transaction.
RESOLVE (mikem) - move this call to ConglomerateManager so it is obvious that non-access clients should not call this.
- Specified by:
closeForEndTransactionin interfaceConglomerateController- Parameters:
closeHeldScan- If true, means to close controller even if it has been opened to be kept opened across commit. This is used to close these controllers on abort.- Returns:
- boolean indicating that the close has resulted in a real close of the controller. A held scan will return false if called by closeForEndTransaction(false), otherwise it will return true. A non-held scan will always return true.
- Throws:
StandardException- Standard exception policy.
-
insert
public int insert(DataValueDescriptor[] row) throws StandardException
Insert a row into the conglomerate.- Specified by:
insertin interfaceConglomerateController- Parameters:
row- The row to insert into the conglomerate. The stored representations of the row's columns are copied into a new row somewhere in the conglomerate.- Returns:
- Returns 0 if insert succeeded. Returns ConglomerateController.ROWISDUPLICATE if conglomerate supports uniqueness checks and has been created to disallow duplicates, and the row inserted had key columns which were duplicate of a row already in the table. Other insert failures will raise StandardException's.
- Throws:
StandardException- Standard exception policy.- See Also:
ConglomerateController.insert(org.apache.derby.iapi.types.DataValueDescriptor[])
-
isKeyed
public boolean isKeyed()
Return whether this is a keyed conglomerate.All b-trees are keyed.
- Specified by:
isKeyedin interfaceConglomerateController- See Also:
ConglomerateController.isKeyed()
-
getTableProperties
public void getTableProperties(java.util.Properties prop) throws StandardExceptionRequest the system properties associated with a table.Request the value of properties that are associated with a table. The following properties can be requested: derby.storage.pageSize derby.storage.pageReservedSpace derby.storage.minimumRecordSize derby.storage.initialPages
To get the value of a particular property add it to the property list, and on return the value of the property will be set to it's current value. For example: get_prop(ConglomerateController cc) { Properties prop = new Properties(); prop.put("derby.storage.pageSize", ""); cc.getTableProperties(prop); System.out.println( "table's page size = " + prop.getProperty("derby.storage.pageSize"); }
- Specified by:
getTablePropertiesin interfaceConglomPropertyQueryable- Parameters:
prop- Property list to fill in.- Throws:
StandardException- Standard exception policy.
-
getInternalTablePropertySet
public java.util.Properties getInternalTablePropertySet(java.util.Properties prop) throws StandardExceptionRequest set of properties associated with a table.Returns a property object containing all properties that the store knows about, which are stored persistently by the store. This set of properties may vary from implementation to implementation of the store.
This call is meant to be used only for internal query of the properties by jbms, for instance by language during bulk insert so that it can create a new conglomerate which exactly matches the properties that the original container was created with. This call should not be used by the user interface to present properties to users as it may contain properties that are meant to be internal to jbms. Some properties are meant only to be specified by jbms code and not by users on the command line.
Note that not all properties passed into createConglomerate() are stored persistently, and that set may vary by store implementation.
- Specified by:
getInternalTablePropertySetin interfaceConglomPropertyQueryable- Parameters:
prop- Property list to add properties to. If null, routine will create a new Properties object, fill it in and return it.- Throws:
StandardException- Standard exception policy.
-
load
public long load(TransactionManager xact_manager, boolean createConglom, RowLocationRetRowSource rowSource) throws StandardException
Load rows from rowSource into the opened btree.Efficiently load rows into the already opened btree. The btree must be table locked, as no row locks will be requested by this routine. On exit from this routine the conglomerate will be closed (on both error or success).
This routine does an almost bottom up build of a btree. It assumes all rows arrive in sorted order, and inserts them directly into the next (to the right) spot in the current leaf until there is no space. Then it calls the generic split code to add the next leaf (RESOLVE - in the future we could optimize this to split bottom up rather than top down for create index).
- Throws:
StandardException- Standard exception policy. If conglomerate supports uniqueness checks and has been created to disallow duplicates, and one of the rows being loaded had key columns which were duplicate of a row already in the conglomerate, then raise SQLState.STORE_CONGLOMERATE_DUPLICATE_KEY_EXCEPTION.- See Also:
Conglomerate.load(org.apache.derby.iapi.store.access.conglomerate.TransactionManager, boolean, org.apache.derby.iapi.store.access.RowLocationRetRowSource)
-
delete
public boolean delete(RowLocation loc) throws StandardException
Delete a row from the conglomerate.- Specified by:
deletein interfaceConglomerateController- Returns:
- Returns true if delete was successful, false if the record pointed at no longer represents a valid record.
- Throws:
StandardException- Standard exception policy.- See Also:
ConglomerateController.delete(org.apache.derby.iapi.types.RowLocation)
-
fetch
public boolean fetch(RowLocation loc, DataValueDescriptor[] row, FormatableBitSet validColumns) throws StandardException
Fetch the row at the given location.- Specified by:
fetchin interfaceConglomerateController- Parameters:
loc- The "RowLocation" which describes the exact row to fetch from the table.row- The row to read the data into.validColumns- A description of which columns to return from row on the page into "destRow." destRow and validColumns work together to describe the row to be returned by the fetch - see RowUtil for description of how these three parameters work together to describe a fetched "row".- Returns:
- Returns true if fetch was successful, false if the record pointed at no longer represents a valid record.
- Throws:
StandardException- Standard exception policy.- See Also:
ConglomerateController.fetch(org.apache.derby.iapi.types.RowLocation, org.apache.derby.iapi.types.DataValueDescriptor[], org.apache.derby.iapi.services.io.FormatableBitSet)
-
fetch
public boolean fetch(RowLocation loc, DataValueDescriptor[] row, FormatableBitSet validColumns, boolean waitForLock) throws StandardException
Fetch the row at the given location.- Specified by:
fetchin interfaceConglomerateController- Parameters:
loc- The "RowLocation" which describes the exact row to fetch from the table.row- The row to read the data into.validColumns- A description of which columns to return from row on the page into "destRow." destRow and validColumns work together to describe the row to be returned by the fetch - see RowUtil for description of how these three parameters work together to describe a fetched "row".waitForLock- If false, then the call will throw a lock timeout exception immediately, if the lock can not be granted without waiting. If true call will act exactly as fetch() interface with no waitForLock parameter.- Returns:
- Returns true if fetch was successful, false if the record pointed at no longer represents a valid record.
- Throws:
StandardException- Standard exception policy.- See Also:
ConglomerateController.fetch(org.apache.derby.iapi.types.RowLocation, org.apache.derby.iapi.types.DataValueDescriptor[], org.apache.derby.iapi.services.io.FormatableBitSet)
-
insertAndFetchLocation
public void insertAndFetchLocation(DataValueDescriptor[] row, RowLocation templateRowLocation) throws StandardException
Insert a row into the conglomerate, and store its location in the provided template row location. Unimplemented by btree.- Specified by:
insertAndFetchLocationin interfaceConglomerateController- Parameters:
row- The row to insert into the conglomerate. The stored representations of the row's columns are copied into a new row somewhere in the conglomerate.templateRowLocation- The rowlocation to read the inserted row location into.- Throws:
StandardException- Standard exception policy.- See Also:
ConglomerateController.insertAndFetchLocation(org.apache.derby.iapi.types.DataValueDescriptor[], org.apache.derby.iapi.types.RowLocation)
-
newRowLocationTemplate
public RowLocation newRowLocationTemplate() throws StandardException
Return a row location object of the correct type to be used in calls to insertAndFetchLocation.- Specified by:
newRowLocationTemplatein interfaceConglomerateController- Throws:
StandardException- Standard exception policy.- See Also:
ConglomerateController.newRowLocationTemplate()
-
lockRow
public boolean lockRow(RowLocation loc, int lock_operation, boolean wait, int lock_duration) throws StandardException
Lock the given row location.Should only be called by access.
This call can be made on a ConglomerateController that was opened for locking only.
RESOLVE (mikem) - move this call to ConglomerateManager so it is obvious that non-access clients should not call this.
- Specified by:
lockRowin interfaceConglomerateController- Parameters:
loc- The "RowLocation" which describes the exact row to lock.wait- Should the lock call wait to be granted?lock_operation- For what operation are we requesting the lock, this should be one of the following 4 options: LOCK_READ [read lock], (LOCK_INS | LOCK_UPD) [ lock for insert], (LOCK_INSERT_PREVKEY | LOCK_UPD) [lock for previous key to insert], (LOCK_UPD) [lock for delete or replace] (LOCK_UPD | LOCK_UPDATE_LOCKS) [lock scan for update, will upgrade lock later if actual update is take place]lock_duration- If set to TransactionManager.LOCK_INSTANT_DURATION, then lock will be released immediately after being granted.- Returns:
- true if lock was granted, only can be false if wait was false.
- Throws:
StandardException- Standard exception policy.
-
lockRow
public boolean lockRow(long page_num, int record_id, int lock_operation, boolean wait, int lock_duration) throws StandardExceptionDescription copied from interface:ConglomerateControllerLock the given record id/page num pair.Should only be called by access, to lock "special" locks formed from the Recordhandle.* reserved constants for page specific locks.
This call can be made on a ConglomerateController that was opened for locking only.
RESOLVE (mikem) - move this call to ConglomerateManager so it is obvious that non-access clients should not call this.
- Specified by:
lockRowin interfaceConglomerateController- Parameters:
page_num- page number of record to lock.record_id- record id of record to lock.lock_operation- For what operation are we requesting the lock, this should be one of the following 4 options: LOCK_READ [read lock], (LOCK_INS | LOCK_UPD) [ lock for insert], (LOCK_INSERT_PREVKEY | LOCK_UPD) [lock for previous key to insert], (LOCK_UPD) [lock for delete or replace] (LOCK_UPD | LOCK_UPDATE_LOCKS) [lock scan for update, will upgrade lock later if actual update is take place]wait- Should the lock call wait to be granted?lock_duration- If set to TransactionManager.LOCK_INSTANT_DURATION, then lock will be released immediately after being granted.- Returns:
- true if lock was granted, only can be false if wait was false.
- Throws:
StandardException- Standard exception policy.
-
unlockRowAfterRead
public void unlockRowAfterRead(RowLocation loc, boolean forUpdate, boolean row_qualifies) throws StandardException
Description copied from interface:ConglomerateControllerUnLock the given row location.Should only be called by access.
This call can be made on a ConglomerateController that was opened for locking only.
RESOLVE (mikem) - move this call to ConglomerateManager so it is obvious that non-access clients should not call this.
- Specified by:
unlockRowAfterReadin interfaceConglomerateController- Parameters:
loc- The "RowLocation" which describes the row to unlock.forUpdate- Row was locked for read or update.row_qualifies- Row was qualified and returned to the user.- Throws:
StandardException- Standard exception policy.
-
replace
public boolean replace(RowLocation loc, DataValueDescriptor[] row, FormatableBitSet validColumns) throws StandardException
Replace the entire row at the given location.- Specified by:
replacein interfaceConglomerateController- Returns:
- true if update was successful, returns false if the update fails because the record pointed at no longer represents a valid record.
- Throws:
StandardException- Standard exception policy.- See Also:
ConglomerateController.replace(org.apache.derby.iapi.types.RowLocation, org.apache.derby.iapi.types.DataValueDescriptor[], org.apache.derby.iapi.services.io.FormatableBitSet)
-
-
DataMelt 3.0 © DataMelt by jWork.ORG