public class RAMTransaction extends java.lang.Object implements XATransactionController, TransactionManager
Modifier and Type | Field and Description |
---|---|
protected RAMAccessManager |
accessmanager
The access manager this transaction is under.
|
private boolean |
alterTableCallMade
Set by alter table to indicate that the conglomerate cache needs to
be invalidated if a transaction aborting error is encountered, cleared
after cleanup.
|
private java.util.ArrayList<ConglomerateController> |
conglomerateControllers |
protected RAMTransactionContext |
context
The context this transaction is being managed by.
|
private java.util.ArrayList<java.lang.Integer> |
freeSortIds
List of sort identifiers (represented as
Integer objects)
which can be reused. |
private long |
nextTempConglomId
Next id to use for a temporary conglomerate.
|
protected RAMTransaction |
parent_tran
The parent transaction if this is a nested user transaction.
|
protected Transaction |
rawtran
The corresponding raw store transaction.
|
private java.util.ArrayList<ScanManager> |
scanControllers |
private java.util.ArrayList<SortController> |
sortControllers |
private java.util.ArrayList<Sort> |
sorts |
protected java.util.HashMap<java.lang.Long,Conglomerate> |
tempCongloms
Where to look for temporary conglomerates.
|
private int |
transaction_lock_level
The lock level of the transaction.
|
XA_OK, XA_RDONLY
LOCK_COMMIT_DURATION, LOCK_INSTANT_DURATION, LOCK_MANUAL_DURATION, MODE_NONE
IS_DEFAULT, IS_KEPT, IS_TEMPORARY, ISOLATION_NOLOCK, ISOLATION_READ_COMMITTED, ISOLATION_READ_COMMITTED_NOHOLDLOCK, ISOLATION_READ_UNCOMMITTED, ISOLATION_REPEATABLE_READ, ISOLATION_SERIALIZABLE, KEEP_LOCKS, MODE_RECORD, MODE_TABLE, OPEN_CONGLOMERATE, OPEN_CREATED_SORTS, OPEN_SCAN, OPEN_SORT, OPEN_TOTAL, OPENMODE_BASEROW_INSERT_LOCKED, OPENMODE_FOR_LOCK_ONLY, OPENMODE_FORUPDATE, OPENMODE_LOCK_NOWAIT, OPENMODE_LOCK_ROW_NOWAIT, OPENMODE_SECONDARY_LOCKED, OPENMODE_USE_UPDATE_LOCKS, READONLY_TRANSACTION_INITIALIZATION, RELEASE_LOCKS
Modifier | Constructor and Description |
---|---|
(package private) |
RAMTransaction() |
(package private) |
RAMTransaction(RAMAccessManager myaccessmanager,
RAMTransaction tc,
int format_id,
byte[] global_id,
byte[] branch_id) |
protected |
RAMTransaction(RAMAccessManager myaccessmanager,
Transaction theRawTran,
RAMTransaction parent_transaction) |
Modifier and Type | Method and Description |
---|---|
void |
abort()
Abort all changes made by this transaction since the last commit, abort
or the point the transaction was started, whichever is the most recent.
|
void |
addColumnToConglomerate(long conglomId,
int column_id,
Storable template_column,
int collation_id)
Add a column to a conglomerate.
|
void |
addPostCommitWork(Serviceable work)
Add to the list of post commit work.
|
boolean |
anyoneBlocked()
Return true if any transaction is blocked (even if not by this one).
|
boolean |
checkVersion(int requiredMajorVersion,
int requiredMinorVersion,
java.lang.String feature)
Check to see if a database has been upgraded to the required
level in order to use a store feature.
|
protected void |
closeControllers(boolean closeHeldControllers)
Private/Protected methods of This class:
|
void |
closeMe(ConglomerateController conglom_control)
The ConglomerateController.close() method has been called on
"conglom_control".
|
void |
closeMe(ScanManager scan)
The ScanManager.close() method has been called on "scan".
|
void |
closeMe(SortController sort_control)
The SortController.close() method has been called on "sort_control".
|
void |
commit()
Commit this transaction.
|
DatabaseInstant |
commitNoSync(int commitflag)
"Commit" this transaction without sync'ing the log.
|
void |
compressConglomerate(long conglomId)
Return free space from the conglomerate back to the OS.
|
boolean |
conglomerateExists(long conglomId)
Check whether a conglomerate exists.
|
private int |
countCreatedSorts() |
int |
countOpens(int which_to_count)
Report on the number of open conglomerates in the transaction.
|
long |
createAndLoadConglomerate(java.lang.String implementation,
DataValueDescriptor[] template,
ColumnOrdering[] columnOrder,
int[] collationIds,
java.util.Properties properties,
int temporaryFlag,
RowLocationRetRowSource rowSource,
long[] rowCount)
Create a conglomerate and populate it with rows from rowSource.
|
BackingStoreHashtable |
createBackingStoreHashtableFromScan(long conglomId,
int open_mode,
int lock_level,
int isolation_level,
FormatableBitSet scanColumnList,
DataValueDescriptor[] startKeyValue,
int startSearchOperator,
Qualifier[][] qualifier,
DataValueDescriptor[] stopKeyValue,
int stopSearchOperator,
long max_rowcnt,
int[] key_column_numbers,
boolean remove_duplicates,
long estimated_rowcnt,
long max_inmemory_rowcnt,
int initialCapacity,
float loadFactor,
boolean collect_runtimestats,
boolean skipNullKeyColumns,
boolean keepAfterCommit,
boolean includeRowLocations)
Create a BackingStoreHashtable which contains all rows that qualify for
the described scan.
|
long |
createConglomerate(java.lang.String implementation,
DataValueDescriptor[] template,
ColumnOrdering[] columnOrder,
int[] collationIds,
java.util.Properties properties,
int temporaryFlag)
Create a new conglomerate.
|
long |
createSort(java.util.Properties implParameters,
DataValueDescriptor[] template,
ColumnOrdering[] columnOrdering,
SortObserver sortObserver,
boolean alreadyInOrder,
long estimatedRows,
int estimatedRowSize)
Create a sort.
|
java.lang.Object |
createXATransactionFromLocalTransaction(int format_id,
byte[] global_id,
byte[] branch_id)
Convert a local transaction to a global transaction.
|
java.lang.String |
debugOpened()
Return a string with debug information about opened congloms/scans/sorts.
|
GroupFetchScanController |
defragmentConglomerate(long conglomId,
boolean online,
boolean hold,
int open_mode,
int lock_level,
int isolation_level)
Compress table in place.
|
void |
destroy()
Abort the current transaction and pop the context.
|
private int |
determine_lock_level(int requested_lock_level) |
private LockingPolicy |
determine_locking_policy(int requested_lock_level,
int isolation_level)
Determine correct locking policy for a conglomerate open.
|
void |
dropConglomerate(long conglomId)
Drop a conglomerate.
|
void |
dropSort(long sortid)
Drop a sort.
|
boolean |
fetchMaxOnBtree(long conglomId,
int open_mode,
int lock_level,
int isolation_level,
FormatableBitSet scanColumnList,
DataValueDescriptor[] fetchRow)
Retrieve the maximum value row in an ordered conglomerate.
|
private Conglomerate |
findConglomerate(long conglomId) |
long |
findConglomid(long container_id)
For debugging, find the conglomid given the containerid.
|
long |
findContainerid(long conglom_id)
For debugging, find the containerid given the conglomid.
|
private Conglomerate |
findExistingConglomerate(long conglomId) |
Conglomerate |
findExistingConglomerateFromKey(ContainerKey container_key)
Return existing Conglomerate after doing lookup by ContainerKey
Throws exception if it can't find a matching conglomerate for the
ContainerKey.
|
AccessFactory |
getAccessManager()
Get reference to access factory which started this transaction.
|
java.lang.String |
getActiveStateTxIdString()
Get string id of the transaction that would be when the Transaction
is IN active state.
|
ContextManager |
getContextManager()
Get the context manager that the transaction was created with.
|
DynamicCompiledOpenConglomInfo |
getDynamicCompiledConglomInfo(long conglomId)
Return dynamic information about the conglomerate to be dynamically
reused in repeated execution of a statement.
|
FileResource |
getFileHandler()
Get an object to handle non-transactional files.
|
TransactionManager |
getInternalTransaction()
Get an Internal transaction.
|
CompatibilitySpace |
getLockSpace()
Return an object that when used as the compatibility space,
and the object returned when calling
getOwner() on that object is used as group for a lock
request, guarantees that the lock will be removed on a commit or an
abort. |
java.util.Properties |
getProperties()
Get properties that can be stored in a java.util.Properties object.
|
java.io.Serializable |
getProperty(java.lang.String key)
Gets a value for a stored property.
|
java.io.Serializable |
getPropertyDefault(java.lang.String key)
Gets a default value for a stored property.
|
Transaction |
getRawStoreXact()
Get the Transaction from the Transaction manager.
|
StaticCompiledOpenConglomInfo |
getStaticCompiledConglomInfo(long conglomId)
Return static information about the conglomerate to be included in a
a compiled plan.
|
java.lang.String |
getTransactionIdString()
Get string id of the transaction.
|
java.util.Properties |
getUserCreateConglomPropList()
A superset of properties that "users" can specify.
|
private void |
init(RAMAccessManager myaccessmanager,
Transaction theRawTran,
RAMTransaction parent_tran)
Constructors for This class:
|
protected void |
invalidateConglomerateCache()
Invalidate the conglomerate cache, if necessary.
|
boolean |
isGlobal()
Reveals whether the transaction is a global or local transaction.
|
boolean |
isIdle()
Reveals whether the transaction has ever read or written data.
|
boolean |
isPristine()
Reveals whether the transaction is currently pristine.
|
long |
loadConglomerate(long conglomId,
boolean createConglom,
RowLocationRetRowSource rowSource)
Bulk load into the conglomerate.
|
void |
loadConglomerate(long conglomId,
RowLocationRetRowSource rowSource)
Use this for incremental load in the future.
|
void |
logAndDo(Loggable operation)
Log an operation and then action it in the context of this transaction.
|
ConglomerateController |
openCompiledConglomerate(boolean hold,
int open_mode,
int lock_level,
int isolation_level,
StaticCompiledOpenConglomInfo static_info,
DynamicCompiledOpenConglomInfo dynamic_info)
Open a conglomerate for use, optionally include "compiled" info.
|
ScanController |
openCompiledScan(boolean hold,
int open_mode,
int lock_level,
int isolation_level,
FormatableBitSet scanColumnList,
DataValueDescriptor[] startKeyValue,
int startSearchOperator,
Qualifier[][] qualifier,
DataValueDescriptor[] stopKeyValue,
int stopSearchOperator,
StaticCompiledOpenConglomInfo static_info,
DynamicCompiledOpenConglomInfo dynamic_info)
Open a scan on a conglomerate, optionally providing compiled info.
|
private ConglomerateController |
openConglomerate(Conglomerate conglom,
boolean hold,
int open_mode,
int lock_level,
int isolation_level,
StaticCompiledOpenConglomInfo static_info,
DynamicCompiledOpenConglomInfo dynamic_info) |
ConglomerateController |
openConglomerate(long conglomId,
boolean hold,
int open_mode,
int lock_level,
int isolation_level)
Open a conglomerate for use.
|
GroupFetchScanController |
openGroupFetchScan(long conglomId,
boolean hold,
int open_mode,
int lock_level,
int isolation_level,
FormatableBitSet scanColumnList,
DataValueDescriptor[] startKeyValue,
int startSearchOperator,
Qualifier[][] qualifier,
DataValueDescriptor[] stopKeyValue,
int stopSearchOperator)
Open a scan which gets copies of multiple rows at a time.
|
private ScanController |
openScan(Conglomerate conglom,
boolean hold,
int open_mode,
int lock_level,
int isolation_level,
FormatableBitSet scanColumnList,
DataValueDescriptor[] startKeyValue,
int startSearchOperator,
Qualifier[][] qualifier,
DataValueDescriptor[] stopKeyValue,
int stopSearchOperator,
StaticCompiledOpenConglomInfo static_info,
DynamicCompiledOpenConglomInfo dynamic_info) |
ScanController |
openScan(long conglomId,
boolean hold,
int open_mode,
int lock_level,
int isolation_level,
FormatableBitSet scanColumnList,
DataValueDescriptor[] startKeyValue,
int startSearchOperator,
Qualifier[][] qualifier,
DataValueDescriptor[] stopKeyValue,
int stopSearchOperator)
Open a scan on a conglomerate.
|
SortController |
openSort(long id)
Open a sort controller for a sort previously created in this
transaction.
|
SortCostController |
openSortCostController()
Return an open SortCostController.
|
RowLocationRetRowSource |
openSortRowSource(long id)
Open a scan for retrieving rows from a sort.
|
ScanController |
openSortScan(long id,
boolean hold)
Open a scan for retrieving rows from a sort.
|
StoreCostController |
openStoreCost(long conglomId)
Return an open StoreCostController for the given conglomid.
|
boolean |
propertyDefaultIsVisible(java.lang.String key)
Return true if the default property is visible.
|
void |
purgeConglomerate(long conglomId)
Purge all committed deleted rows from the conglomerate.
|
long |
recreateAndLoadConglomerate(java.lang.String implementation,
boolean recreate_ifempty,
DataValueDescriptor[] template,
ColumnOrdering[] columnOrder,
int[] collationIds,
java.util.Properties properties,
int temporaryFlag,
long orig_conglomId,
RowLocationRetRowSource rowSource,
long[] rowCount)
recreate a conglomerate and populate it with rows from rowSource.
|
int |
releaseSavePoint(java.lang.String name,
java.lang.Object kindOfSavepoint)
Release the save point of the given name.
|
int |
rollbackToSavePoint(java.lang.String name,
boolean close_controllers,
java.lang.Object kindOfSavepoint)
Rollback all changes made since the named savepoint was set.
|
(package private) void |
setContext(RAMTransactionContext rtc) |
void |
setNoLockWait(boolean noWait)
Tell this transaction whether it should time out immediately if a lock
cannot be granted without waiting.
|
void |
setProperty(java.lang.String key,
java.io.Serializable value,
boolean dbOnlyProperty)
Sets the Serializable object associated with a property key.
|
void |
setPropertyDefault(java.lang.String key,
java.io.Serializable value)
Sets the Serializable object default value associated with a property
key.
|
int |
setSavePoint(java.lang.String name,
java.lang.Object kindOfSavepoint)
Set a save point in the current transaction.
|
TransactionController |
startNestedUserTransaction(boolean readOnly,
boolean flush_log_on_xact_end)
Get an nested user transaction.
|
java.lang.String |
toString() |
void |
xa_commit(boolean onePhase)
This method is called to commit the current XA global transaction.
|
int |
xa_prepare()
This method is called to ask the resource manager to prepare for
a transaction commit of the transaction specified in xid.
|
void |
xa_rollback()
rollback the current global transaction.
|
protected Transaction rawtran
protected RAMAccessManager accessmanager
protected RAMTransactionContext context
protected RAMTransaction parent_tran
private java.util.ArrayList<ScanManager> scanControllers
private java.util.ArrayList<ConglomerateController> conglomerateControllers
private java.util.ArrayList<Sort> sorts
private java.util.ArrayList<SortController> sortControllers
private java.util.ArrayList<java.lang.Integer> freeSortIds
Integer
objects)
which can be reused. Since sort identifiers are used as array indexes,
we need to reuse them to avoid leaking memory (DERBY-912).protected java.util.HashMap<java.lang.Long,Conglomerate> tempCongloms
private long nextTempConglomId
private boolean alterTableCallMade
private int transaction_lock_level
Cannot lock a level lower than the getSystemLockLevel(). So if getSystemLockLevel() is table level locking, setting the transaction locking level to record has no effect.
protected RAMTransaction(RAMAccessManager myaccessmanager, Transaction theRawTran, RAMTransaction parent_transaction) throws StandardException
StandardException
RAMTransaction(RAMAccessManager myaccessmanager, RAMTransaction tc, int format_id, byte[] global_id, byte[] branch_id) throws StandardException
StandardException
RAMTransaction()
private final void init(RAMAccessManager myaccessmanager, Transaction theRawTran, RAMTransaction parent_tran)
protected void closeControllers(boolean closeHeldControllers) throws StandardException
StandardException
private LockingPolicy determine_locking_policy(int requested_lock_level, int isolation_level)
Determine from the following table whether to table or record lock the conglomerate we are opening.
System level override ------------------------------- user requests table locking record locking ------------- ------------- -------------- TransactionController.MODE_TABLE TABLE TABLE TransactionController.MODE_RECORD TABLE RECORD
private int determine_lock_level(int requested_lock_level)
private Conglomerate findExistingConglomerate(long conglomId) throws StandardException
StandardException
private Conglomerate findConglomerate(long conglomId) throws StandardException
StandardException
void setContext(RAMTransactionContext rtc)
private ConglomerateController openConglomerate(Conglomerate conglom, boolean hold, int open_mode, int lock_level, int isolation_level, StaticCompiledOpenConglomInfo static_info, DynamicCompiledOpenConglomInfo dynamic_info) throws StandardException
StandardException
private ScanController openScan(Conglomerate conglom, boolean hold, int open_mode, int lock_level, int isolation_level, FormatableBitSet scanColumnList, DataValueDescriptor[] startKeyValue, int startSearchOperator, Qualifier[][] qualifier, DataValueDescriptor[] stopKeyValue, int stopSearchOperator, StaticCompiledOpenConglomInfo static_info, DynamicCompiledOpenConglomInfo dynamic_info) throws StandardException
StandardException
protected void invalidateConglomerateCache() throws StandardException
StandardException
- Standard exception policy.public void addColumnToConglomerate(long conglomId, int column_id, Storable template_column, int collation_id) throws StandardException
addColumnToConglomerate
in interface TransactionController
conglomId
- The identifier of the conglomerate to drop.column_id
- The column number to add this column at.template_column
- An instance of the column to be added to table.collation_id
- collation id of the added column.StandardException
- Only some types of conglomerates can support
adding a column, for instance "heap" conglomerates support adding a
column while "btree" conglomerates do not. If the column can not be
added an exception will be thrown.public StaticCompiledOpenConglomInfo getStaticCompiledConglomInfo(long conglomId) throws StandardException
The static info would be valid until any ddl was executed on the conglomid, and would be up to the caller to throw away when that happened. This ties in with what language already does for other invalidation of static info. The type of info in this would be containerid and array of format id's from which templates can be created. The info in this object is read only and can be shared among as many threads as necessary.
getStaticCompiledConglomInfo
in interface TransactionController
conglomId
- The identifier of the conglomerate to open.StandardException
- Standard exception policy.public DynamicCompiledOpenConglomInfo getDynamicCompiledConglomInfo(long conglomId) throws StandardException
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, ...
getDynamicCompiledConglomInfo
in interface TransactionController
conglomId
- The identifier of the conglomerate to open.StandardException
- Standard exception policy.private final int countCreatedSorts()
public int countOpens(int which_to_count) throws StandardException
There are 4 types of open "conglomerates" that can be tracked, those opened by each of the following: openConglomerate(), openScan(), openSort(), and openSortScan(). This routine can be used to either report on the number of all opens, or may be used to track one particular type of open. This routine is expected to be used for debugging only. An implementation may only track this info under SanityManager.DEBUG mode. If the implementation does not track the info it will return -1 (so code using this call to verify that no congloms are open should check for return <= 0 rather than == 0). The return value depends on the "which_to_count" parameter as follows: OPEN_CONGLOMERATE - return # of openConglomerate() calls not close()'d. OPEN_SCAN - return # of openScan() calls not close()'d. OPEN_CREATED_SORTS - return # of sorts created (createSort()) in current xact. There is currently no way to get rid of these sorts before end of transaction. OPEN_SORT - return # of openSort() calls not close()'d. OPEN_TOTAL - return total # of all above calls not close()'d. - note an implementation may return -1 if it does not track the above information.
countOpens
in interface TransactionController
which_to_count
- Which kind of open to report on.StandardException
- Standard exception policy.public long createConglomerate(java.lang.String implementation, DataValueDescriptor[] template, ColumnOrdering[] columnOrder, int[] collationIds, java.util.Properties properties, int temporaryFlag) throws StandardException
createConglomerate
in interface TransactionController
implementation
- Specifies what kind of conglomerate to create.
THE WAY THAT THE IMPLEMENTATION IS CHOSEN STILL NEEDS SOME WORK.
For now, use "BTREE" or "heap" for a local access manager.template
- A row which describes the prototypical
row that the conglomerate will be holding.
Typically this row gives the conglomerate
information about the number and type of
columns it will be holding. The implementation
may require a specific subclass of row type.
Note that the createConglomerate call reads the template and makes a copy
of any necessary information from the template, no reference to the
template is kept (and thus this template can be re-used in subsequent
calls - such as openScan()). This field is required when creating either
a heap or btree conglomerate.columnOrder
- Specifies the colummns sort order.
Useful only when the conglomerate is of type BTREE, default
value is 'null', which means all columns needs to be sorted in
Ascending order.collationIds
- Specifies the collation id of each of the columns
in the new conglomerate. Collation id along with format id may be used
to create DataValueDescriptor's which may subsequently be used for
comparisons. For instance the correct collation specific order and
searching is maintained by correctly specifying the collation id of
the columns in the index when the index is created.properties
- Implementation-specific properties of the
conglomerate.temporaryFlag
- Where temporaryFlag can have the following values:
IS_DEFAULT - no bit is set.
IS_TEMPORARY - if set, the conglomerate is temporary
IS_KEPT - only looked at if IS_TEMPORARY,
if set, the temporary container is not
removed automatically by store when
transaction terminates.
If IS_TEMPORARY is set, the conglomerate is temporary.
Temporary conglomerates are only visible through the transaction
controller that created them. Otherwise, they are opened,
scanned, and dropped in the same way as permanent conglomerates.
Changes to temporary conglomerates persist across commits, but
temporary conglomerates are truncated on abort (or rollback
to savepoint). Updates to temporary conglomerates are not
locked or logged.
A temporary conglomerate is only visible to the transaction
controller that created it, even if the conglomerate IS_KEPT
when the transaction termination.
All temporary conglomerate is removed by store when the
conglomerate controller is destroyed, or if it is dropped by an explicit
dropConglomerate. If Derby reboots, all temporary
conglomerates are removed.StandardException
- Standard exception policy.TransactionController.createConglomerate(java.lang.String, org.apache.derby.iapi.types.DataValueDescriptor[], org.apache.derby.iapi.store.access.ColumnOrdering[], int[], java.util.Properties, int)
public long createAndLoadConglomerate(java.lang.String implementation, DataValueDescriptor[] template, ColumnOrdering[] columnOrder, int[] collationIds, java.util.Properties properties, int temporaryFlag, RowLocationRetRowSource rowSource, long[] rowCount) throws StandardException
createAndLoadConglomerate
in interface TransactionController
implementation
- Specifies what kind of conglomerate to create.
THE WAY THAT THE IMPLEMENTATION IS CHOSEN STILL NEEDS SOME WORK.
For now, use "BTREE" or "heap" for a local access manager.template
- A row which describes the prototypical
row that the conglomerate will be holding.
Typically this row gives the conglomerate
information about the number and type of
columns it will be holding. The implementation
may require a specific subclass of row type.
Note that the createConglomerate call reads the template and makes a copy
of any necessary information from the template, no reference to the
template is kept (and thus this template can be re-used in subsequent
calls - such as openScan()). This field is required when creating either
a heap or btree conglomerate.columnOrder
- Specifies the colummns sort order.
Useful only when the conglomerate is of type BTREE, default
value is 'null', which means all columns needs to be sorted in
Ascending order.collationIds
- Specifies the collation id of each of the columns
in the new conglomerate. Collation id along with format id may be used
to create DataValueDescriptor's which may subsequently be used for
comparisons. For instance the correct collation specific order and
searching is maintained by correctly specifying the collation id of
the columns in the index when the index is created.properties
- Implementation-specific properties of the
conglomerate.rowSource
- the interface to recieve rows to load into the
conglomerate.rowCount
- - if not null the number of rows loaded into the table
will be returned as the first element of the array.StandardException
- Standard Derby Error PolicyTransactionController.createAndLoadConglomerate(java.lang.String, org.apache.derby.iapi.types.DataValueDescriptor[], org.apache.derby.iapi.store.access.ColumnOrdering[], int[], java.util.Properties, int, org.apache.derby.iapi.store.access.RowLocationRetRowSource, long[])
public long recreateAndLoadConglomerate(java.lang.String implementation, boolean recreate_ifempty, DataValueDescriptor[] template, ColumnOrdering[] columnOrder, int[] collationIds, java.util.Properties properties, int temporaryFlag, long orig_conglomId, RowLocationRetRowSource rowSource, long[] rowCount) throws StandardException
recreateAndLoadConglomerate
in interface TransactionController
implementation
- Specifies what kind of conglomerate to create.
THE WAY THAT THE IMPLEMENTATION IS CHOSEN STILL NEEDS SOME WORK.
For now, use "BTREE" or "heap" for a local access manager.recreate_ifempty
- If false, and the rowsource used to load the new
conglomerate returns no rows, then the original
conglomid will be returned. To the client it will
be as if no call was made. Underlying
implementations may actually create and drop a
container.
If true, then a new empty container will be
created and it's conglomid will be returned.template
- A row which describes the prototypical
row that the conglomerate will be holding.
Typically this row gives the conglomerate
information about the number and type of
columns it will be holding. The implementation
may require a specific subclass of row type.
Note that the createConglomerate call reads the template and makes a copy
of any necessary information from the template, no reference to the
template is kept (and thus this template can be re-used in subsequent
calls - such as openScan()). This field is required when creating either
a heap or btree conglomerate.columnOrder
- Specifies the colummns sort order.
Useful only when the conglomerate is of type BTREE, default
value is 'null', which means all columns needs to be sorted in
Ascending order.collationIds
- Specifies the collation id of each of the columns
in the new conglomerate. Collation id along with format id may be used
to create DataValueDescriptor's which may subsequently be used for
comparisons. For instance the correct collation specific order and
searching is maintained by correctly specifying the collation id of
the columns in the index when the index is created.properties
- Implementation-specific properties of the conglomerate.temporaryFlag
- If true, the conglomerate is temporary.
Temporary conglomerates are only visible through the transaction
controller that created them. Otherwise, they are opened,
scanned, and dropped in the same way as permanent conglomerates.
Changes to temporary conglomerates persist across commits, but
temporary conglomerates are truncated on abort (or rollback
to savepoint). Updates to temporary conglomerates are not
locked or logged.orig_conglomId
- The conglomid of the original conglomerate.rowSource
- interface to receive rows to load into the conglomerate.rowCount
- - if not null the number of rows loaded into the table
will be returned as the first element of the array.StandardException
- Standard Derby Error PolicyTransactionController.createAndLoadConglomerate(java.lang.String, org.apache.derby.iapi.types.DataValueDescriptor[], org.apache.derby.iapi.store.access.ColumnOrdering[], int[], java.util.Properties, int, org.apache.derby.iapi.store.access.RowLocationRetRowSource, long[])
public java.lang.String debugOpened() throws StandardException
Return a string with debugging information about current opened congloms/scans/sorts which have not been close()'d. Calls to this routine are only valid under code which is conditional on SanityManager.DEBUG.
debugOpened
in interface TransactionController
StandardException
- Standard exception policy.public boolean conglomerateExists(long conglomId) throws StandardException
TransactionController
conglomerateExists
in interface TransactionController
conglomId
- The identifier of the conglomerate to check for.StandardException
- only thrown if something goes
wrong in the lower levels.public void dropConglomerate(long conglomId) throws StandardException
TransactionController
dropConglomerate
in interface TransactionController
conglomId
- The identifier of the conglomerate to drop.StandardException
- if the conglomerate could not be
dropped for some reason.public boolean fetchMaxOnBtree(long conglomId, int open_mode, int lock_level, int isolation_level, FormatableBitSet scanColumnList, DataValueDescriptor[] fetchRow) throws StandardException
Returns true and fetches the rightmost row of an ordered conglomerate into "fetchRow" if there is at least one row in the conglomerate. If there are no rows in the conglomerate it returns false.
Non-ordered conglomerates will not implement this interface, calls will generate a StandardException.
RESOLVE - this interface is temporary, long term equivalent (and more) functionality will be provided by the openBackwardScan() interface.
fetchMaxOnBtree
in interface TransactionController
conglomId
- The identifier of the conglomerate
to open the scan for.open_mode
- Specifiy flags to control opening of table.
OPENMODE_FORUPDATE - if set open the table for
update otherwise open table shared.lock_level
- One of (MODE_TABLE, MODE_RECORD, or MODE_NONE).isolation_level
- The isolation level to lock the conglomerate at.
One of (ISOLATION_READ_COMMITTED or
ISOLATION_SERIALIZABLE).scanColumnList
- A description of which columns to return from
every fetch in the scan. template,
and scanColumnList work together
to describe the row to be returned by the scan -
see RowUtil for description of how these three
parameters work together to describe a "row".fetchRow
- The row to retrieve the maximum value into.StandardException
- Standard exception policy.public java.util.Properties getUserCreateConglomPropList()
A superset of properties that "users" (ie. from sql) can specify. Store may implement other properties which should not be specified by users. Layers above access may implement properties which are not known at all to Access.
This list is a superset, as some properties may not be implemented by certain types of conglomerates. For instant an in-memory store may not implement a pageSize property. Or some conglomerates may not support pre-allocation.
This interface is meant to be used by the SQL parser to do validation of properties passsed to the create table statement, and also by the various user interfaces which present table information back to the user.
Currently this routine returns the following list: derby.storage.initialPages derby.storage.minimumRecordSize derby.storage.pageReservedSpace derby.storage.pageSize
getUserCreateConglomPropList
in interface TransactionController
public boolean isIdle()
isIdle
in interface TransactionController
public boolean isGlobal()
isGlobal
in interface TransactionController
AccessFactory.startXATransaction(org.apache.derby.iapi.services.context.ContextManager, int, byte[], byte[])
,
TransactionController.createXATransactionFromLocalTransaction(int, byte[], byte[])
public boolean isPristine()
isPristine
in interface TransactionController
TransactionController.isPristine()
public java.lang.Object createXATransactionFromLocalTransaction(int format_id, byte[] global_id, byte[] branch_id) throws StandardException
Get a transaction controller with which to manipulate data within the access manager. Tbis controller allows one to manipulate a global XA conforming transaction.
Must only be called a previous local transaction was created and exists in the context. Can only be called if the current transaction is in the idle state. Upon return from this call the old tc will be unusable, and all references to it should be dropped (it will have been implicitly destroy()'d by this call.
The (format_id, global_id, branch_id) triplet is meant to come exactly from a javax.transaction.xa.Xid. We don't use Xid so that the system can be delivered on a non-1.2 vm system and not require the javax classes in the path.
createXATransactionFromLocalTransaction
in interface TransactionController
format_id
- the format id part of the Xid - ie. Xid.getFormatId().global_id
- the global transaction identifier part of XID - ie.
Xid.getGlobalTransactionId().branch_id
- The branch qualifier of the Xid - ie.
Xid.getBranchQaulifier()StandardException
- Standard exception policy.TransactionController
public long loadConglomerate(long conglomId, boolean createConglom, RowLocationRetRowSource rowSource) throws StandardException
conglomId
- The conglomerate Id.createConglom
- If true, the conglomerate is being created in the
same operation as the loadConglomerate. The enables further
optimization as recovery does not require page allocation to be
logged.rowSource
- Where the rows come from.StandardException
- Standard Derby Error Policypublic void loadConglomerate(long conglomId, RowLocationRetRowSource rowSource) throws StandardException
conglomId
- the conglomerate IdrowSource
- where the rows to be loaded comes fromStandardException
- Standard Derby Error Policypublic void logAndDo(Loggable operation) throws StandardException
This simply passes the operation to the RawStore which logs and does it.
logAndDo
in interface TransactionController
operation
- the operation that is to be appliedStandardException
- Standard exception policy.Loggable
,
Transaction.logAndDo(org.apache.derby.iapi.store.raw.Loggable)
public ConglomerateController openCompiledConglomerate(boolean hold, int open_mode, int lock_level, int isolation_level, StaticCompiledOpenConglomInfo static_info, DynamicCompiledOpenConglomInfo dynamic_info) throws StandardException
TransactionController
Same as openConglomerate(), except that one can optionally provide "compiled" static_info and/or dynamic_info. This compiled information must have be gotten from getDynamicCompiledConglomInfo() and/or getStaticCompiledConglomInfo() calls on the same conglomid being opened. It is up to caller that "compiled" information is still valid and is appropriately multi-threaded protected.
openCompiledConglomerate
in interface TransactionController
hold
- If true, will be maintained open over commits.open_mode
- Specifiy flags to control opening of table.lock_level
- One of (MODE_TABLE, MODE_RECORD).isolation_level
- The isolation level to lock the conglomerate at.
One of (ISOLATION_READ_COMMITTED,
ISOLATION_REPEATABLE_READ or
ISOLATION_SERIALIZABLE).static_info
- object returned from
getStaticCompiledConglomInfo() call on this id.dynamic_info
- object returned from
getDynamicCompiledConglomInfo() call on this id.StandardException
- Standard exception policy.TransactionController.openConglomerate(long, boolean, int, int, int)
,
TransactionController.getDynamicCompiledConglomInfo(long)
,
TransactionController.getStaticCompiledConglomInfo(long)
,
DynamicCompiledOpenConglomInfo
,
StaticCompiledOpenConglomInfo
public ConglomerateController openConglomerate(long conglomId, boolean hold, int open_mode, int lock_level, int isolation_level) throws StandardException
TransactionController
The lock level indicates the minimum lock level to get locks at, the underlying conglomerate implementation may actually lock at a higher level (ie. caller may request MODE_RECORD, but the table may be locked at MODE_TABLE instead).
The close method is on the ConglomerateController interface.
openConglomerate
in interface TransactionController
conglomId
- The identifier of the conglomerate to open.hold
- If true, will be maintained open over commits.open_mode
- Specifiy flags to control opening of table.
OPENMODE_FORUPDATE - if set open the table for
update otherwise open table shared.lock_level
- One of (MODE_TABLE, MODE_RECORD).isolation_level
- The isolation level to lock the conglomerate at.
One of (ISOLATION_READ_COMMITTED,
ISOLATION_REPEATABLE_READ or
ISOLATION_SERIALIZABLE).StandardException
- if the conglomerate could not be opened
for some reason. Throws
SQLState.STORE_CONGLOMERATE_DOES_NOT_EXIST
if the conglomId being requested does not
exist for some reason (ie. someone has
dropped it).public long findConglomid(long container_id) throws StandardException
TransactionController
findConglomid
in interface TransactionController
StandardException
- Standard exception policy.public long findContainerid(long conglom_id) throws StandardException
TransactionController
Will have to change if we ever have more than one container in a conglomerate.
findContainerid
in interface TransactionController
StandardException
- Standard exception policy.public BackingStoreHashtable createBackingStoreHashtableFromScan(long conglomId, int open_mode, int lock_level, int isolation_level, FormatableBitSet scanColumnList, DataValueDescriptor[] startKeyValue, int startSearchOperator, Qualifier[][] qualifier, DataValueDescriptor[] stopKeyValue, int stopSearchOperator, long max_rowcnt, int[] key_column_numbers, boolean remove_duplicates, long estimated_rowcnt, long max_inmemory_rowcnt, int initialCapacity, float loadFactor, boolean collect_runtimestats, boolean skipNullKeyColumns, boolean keepAfterCommit, boolean includeRowLocations) throws StandardException
createBackingStoreHashtableFromScan
in interface TransactionController
conglomId
- see openScan()open_mode
- see openScan()lock_level
- see openScan()isolation_level
- see openScan()scanColumnList
- see openScan()startKeyValue
- see openScan()startSearchOperator
- see openScan()qualifier
- see openScan()stopKeyValue
- see openScan()stopSearchOperator
- see openScan()max_rowcnt
- The maximum number of rows to insert into
the HashSet. Pass in -1 if there is no
maximum.key_column_numbers
- The column numbers of the columns in the
scan result row to be the key to the
Hashtable. "0" is the first column in the
scan result row (which may be different
than the first row in the table of the
scan).remove_duplicates
- Should the HashSet automatically remove
duplicates, or should it create the Vector
of duplicates?estimated_rowcnt
- The number of rows that the caller
estimates will be inserted into the sort.
-1 indicates that the caller has no idea.
Used by the sort to make good choices about
in-memory vs. external sorting, and to size
merge runs.max_inmemory_rowcnt
- The number of rows at which the underlying
Hashtable implementation should cut over
from an in-memory hash to a disk based
access method.initialCapacity
- If not "-1" used to initialize the java
Hashtable.loadFactor
- If not "-1" used to initialize the java
Hashtable.collect_runtimestats
- If true will collect up runtime stats during
scan processing for retrieval by
BackingStoreHashtable.getRuntimeStats().skipNullKeyColumns
- Whether or not to skip rows with 1 or more null key columnskeepAfterCommit
- If true then keep hash table after commitincludeRowLocations
- If true then rows should include RowLocations.StandardException
- Standard exception policy.BackingStoreHashtable
,
TransactionController.openScan(long, boolean, int, int, int, org.apache.derby.iapi.services.io.FormatableBitSet, org.apache.derby.iapi.types.DataValueDescriptor[], int, org.apache.derby.iapi.store.access.Qualifier[][], org.apache.derby.iapi.types.DataValueDescriptor[], int)
public GroupFetchScanController openGroupFetchScan(long conglomId, boolean hold, int open_mode, int lock_level, int isolation_level, FormatableBitSet scanColumnList, DataValueDescriptor[] startKeyValue, int startSearchOperator, Qualifier[][] qualifier, DataValueDescriptor[] stopKeyValue, int stopSearchOperator) throws StandardException
TransactionController
All inputs work exactly as in openScan(). The return is a GroupFetchScanController, which only allows fetches of groups of rows from the conglomerate.
openGroupFetchScan
in interface TransactionController
conglomId
- see openScan()open_mode
- see openScan()lock_level
- see openScan()isolation_level
- see openScan()scanColumnList
- see openScan()startKeyValue
- see openScan()startSearchOperator
- see openScan()qualifier
- see openScan()stopKeyValue
- see openScan()stopSearchOperator
- see openScan()StandardException
- Standard exception policy.ScanController
,
GroupFetchScanController
public void purgeConglomerate(long conglomId) throws StandardException
This call will purge committed deleted rows from the conglomerate, that space will be available for future inserts into the conglomerate.
purgeConglomerate
in interface TransactionController
conglomId
- Id of the conglomerate to purge.StandardException
- Standard exception policy.public void compressConglomerate(long conglomId) throws StandardException
Returns free space from the conglomerate back to the OS. Currently only the sequential free pages at the "end" of the conglomerate can be returned to the OS.
compressConglomerate
in interface TransactionController
conglomId
- Id of the conglomerate to purge.StandardException
- Standard exception policy.public GroupFetchScanController defragmentConglomerate(long conglomId, boolean online, boolean hold, int open_mode, int lock_level, int isolation_level) throws StandardException
Returns a GroupFetchScanController which can be used to move rows around in a table, creating a block of free pages at the end of the table. The process will move rows from the end of the table toward the beginning. The GroupFetchScanController will return the old row location, the new row location, and the actual data of any row moved. Note that this scan only returns moved rows, not an entire set of rows, the scan is designed specifically to be used by either explicit user call of the SYSCS_ONLINE_COMPRESS_TABLE() procedure, or internal background calls to compress the table. The old and new row locations are returned so that the caller can update any indexes necessary. This scan always returns all collumns of the row. All inputs work exactly as in openScan(). The return is a GroupFetchScanController, which only allows fetches of groups of rows from the conglomerate.
defragmentConglomerate
in interface TransactionController
conglomId
- see openScan()hold
- see openScan()open_mode
- see openScan()lock_level
- see openScan()isolation_level
- see openScan()StandardException
- Standard exception policy.ScanController
,
GroupFetchScanController
public ScanController openScan(long conglomId, boolean hold, int open_mode, int lock_level, int isolation_level, FormatableBitSet scanColumnList, DataValueDescriptor[] startKeyValue, int startSearchOperator, Qualifier[][] qualifier, DataValueDescriptor[] stopKeyValue, int stopSearchOperator) throws StandardException
TransactionController
The way that starting and stopping keys and operators are used may best be described by example. Say there's an ordered conglomerate with two columns, where the 0-th column is named 'x', and the 1st column is named 'y'. The values of the columns are as follows:
x: 1 3 4 4 4 5 5 5 6 7 9 y: 1 1 2 4 6 2 4 6 1 1 1
A {start key, search op} pair of {{5.2}, GE} would position on {x=5, y=2}, whereas the pair {{5}, GT} would position on {x=6, y=1}.
Partial keys are used to implement partial key scans in SQL. For example, the SQL "select * from t where x = 5" would open a scan on the conglomerate (or a useful index) of t using a starting position partial key of {{5}, GE} and a stopping position partial key of {{5}, GT}.
Some more examples:
+-------------------+------------+-----------+--------------+--------------+ | predicate | start key | stop key | rows | rows locked | | | value | op | value |op | returned |serialization | +-------------------+-------+----+-------+---+--------------+--------------+ | x = 5 | {5} | GE | {5} |GT |{5,2} .. {5,6}|{4,6} .. {5,6}| | x > 5 | {5} | GT | null | |{6,1} .. {9,1}|{5,6} .. {9,1}| | x >= 5 | {5} | GE | null | |{5,2} .. {9,1}|{4,6} .. {9,1}| | x <= 5 | null | | {5} |GT |{1,1} .. {5,6}|first .. {5,6}| | x < 5 | null | | {5} |GE |{1,1} .. {4,6}|first .. {4,6}| | x >= 5 and x <= 7 | {5}, | GE | {7} |GT |{5,2} .. {7,1}|{4,6} .. {7,1}| | x = 5 and y > 2 | {5,2} | GT | {5} |GT |{5,4} .. {5,6}|{5,2} .. {5,6}| | x = 5 and y >= 2 | {5,2} | GE | {5} |GT |{5,2} .. {5,6}|{4,6} .. {5,6}| | x = 5 and y < 5 | {5} | GE | {5,5} |GE |{5,2} .. {5,4}|{4,6} .. {5,4}| | x = 2 | {2} | GE | {2} |GT | none |{1,1} .. {1,1}| +-------------------+-------+----+-------+---+--------------+--------------+
As the above table implies, the underlying scan may lock more rows than it returns in order to guarantee serialization.
For each row which meets the start and stop position, as described above the row is "qualified" to see whether it should be returned. The qualification is a 2 dimensional array of @see Qualifiers, which represents the qualification in conjunctive normal form (CNF). Conjunctive normal form is an "and'd" set of "or'd" Qualifiers.
For example x = 5 would be represented is pseudo code as: qualifier_cnf[][] = new Qualifier[1]; qualifier_cnf[0] = new Qualifier[1]; qualifier_cnr[0][0] = new Qualifer(x = 5)
For example (x = 5) or (y = 6) would be represented is pseudo code as: qualifier_cnf[][] = new Qualifier[1]; qualifier_cnf[0] = new Qualifier[2]; qualifier_cnr[0][0] = new Qualifer(x = 5) qualifier_cnr[0][1] = new Qualifer(y = 6)
For example ((x = 5) or (x = 6)) and ((y = 1) or (y = 2)) would be represented is pseudo code as: qualifier_cnf[][] = new Qualifier[2]; qualifier_cnf[0] = new Qualifier[2]; qualifier_cnr[0][0] = new Qualifer(x = 5) qualifier_cnr[0][1] = new Qualifer(x = 6) qualifier_cnr[0][0] = new Qualifer(y = 5) qualifier_cnr[0][1] = new Qualifer(y = 6)
For each row the CNF qualfier is processed and it is determined whether or not the row should be returned to the caller. The following pseudo-code describes how this is done:
}if (qualifier != null) {}for (int and_clause; and_clause < qualifier.length; and_clause++) { boolean or_qualifies = false; for (int or_clause; or_clause < qualifier[and_clause].length; or_clause++) {}DataValueDescriptor key = qualifier[and_clause][or_clause].getOrderable(); DataValueDescriptor row_col = get row column[qualifier[and_clause][or_clause].getColumnId()]; boolean or_qualifies = row_col.compare(qualifier[i].getOperator,if (or_qualifies) { break; } } if (!or_qualifies) {key, qualifier[i].getOrderedNulls, qualifier[i].getUnknownRV);don't return this row to the client - proceed to next row;
openScan
in interface TransactionController
conglomId
- The identifier of the conglomerate
to open the scan for.hold
- If true, this scan will be maintained open over
commits.open_mode
- Specifiy flags to control opening of table.
OPENMODE_FORUPDATE - if set open the table for
update otherwise open table shared.lock_level
- One of (MODE_TABLE, MODE_RECORD).isolation_level
- The isolation level to lock the conglomerate at.
One of (ISOLATION_READ_COMMITTED,
ISOLATION_REPEATABLE_READ or
ISOLATION_SERIALIZABLE).scanColumnList
- A description of which columns to return from
every fetch in the scan. template, and scanColumnList
work together to describe the row to be returned by the scan - see RowUtil
for description of how these three parameters work together to describe
a "row".startKeyValue
- An indexable row which holds a
(partial) key value which, in combination with the
startSearchOperator, defines the starting position of
the scan. If null, the starting position of the scan
is the first row of the conglomerate.
The startKeyValue must only reference columns included
in the scanColumnList.startSearchOperator
- an operator which defines
how the startKeyValue is to be searched for. If
startSearchOperation is ScanController.GE, the scan starts on
the first row which is greater than or equal to the
startKeyValue. If startSearchOperation is ScanController.GT,
the scan starts on the first row whose key is greater than
startKeyValue. The startSearchOperation parameter is
ignored if the startKeyValue parameter is null.qualifier
- A 2 dimensional array encoding a conjunctive normal
form (CNF) datastructure of of qualifiers which, applied
to each key, restrict the rows returned by the scan. Rows
for which the CNF expression returns false are not
returned by the scan. If null, all rows are returned.
Qualifiers can only reference columns which are included in the
scanColumnList. The column id that a qualifier returns is the
column id the table, not the column id in the partial row being
returned.
For detailed description of 2-dimensional array passing @see QualifierstopKeyValue
- An indexable row which holds a
(partial) key value which, in combination with the
stopSearchOperator, defines the ending position of
the scan. If null, the ending position of the scan
is the last row of the conglomerate.
The stopKeyValue must only reference columns included
in the scanColumnList.stopSearchOperator
- an operator which defines
how the stopKeyValue is used to determine the scan stopping
position. If stopSearchOperation is ScanController.GE, the scan
stops just before the first row which is greater than or
equal to the stopKeyValue. If stopSearchOperation is
ScanController.GT, the scan stops just before the first row whose
key is greater than startKeyValue. The stopSearchOperation
parameter is ignored if the stopKeyValue parameter is null.StandardException
- if the scan could not be
opened for some reason. Throws SQLState.STORE_CONGLOMERATE_DOES_NOT_EXIST
if the conglomId being requested does not exist for some reason (ie.
someone has dropped it).RowUtil
,
ScanController
public ScanController openCompiledScan(boolean hold, int open_mode, int lock_level, int isolation_level, FormatableBitSet scanColumnList, DataValueDescriptor[] startKeyValue, int startSearchOperator, Qualifier[][] qualifier, DataValueDescriptor[] stopKeyValue, int stopSearchOperator, StaticCompiledOpenConglomInfo static_info, DynamicCompiledOpenConglomInfo dynamic_info) throws StandardException
TransactionController
Same as openScan(), except that one can optionally provide "compiled" static_info and/or dynamic_info. This compiled information must have be gotten from getDynamicCompiledConglomInfo() and/or getStaticCompiledConglomInfo() calls on the same conglomid being opened. It is up to caller that "compiled" information is still valid and is appropriately multi-threaded protected.
openCompiledScan
in interface TransactionController
open_mode
- see openScan()lock_level
- see openScan()isolation_level
- see openScan()scanColumnList
- see openScan()startKeyValue
- see openScan()startSearchOperator
- see openScan()qualifier
- see openScan()stopKeyValue
- see openScan()stopSearchOperator
- see openScan()static_info
- object returned from
getStaticCompiledConglomInfo() call on this id.dynamic_info
- object returned from
getDynamicCompiledConglomInfo() call on this id.StandardException
- Standard exception policy.TransactionController.openScan(long, boolean, int, int, int, org.apache.derby.iapi.services.io.FormatableBitSet, org.apache.derby.iapi.types.DataValueDescriptor[], int, org.apache.derby.iapi.store.access.Qualifier[][], org.apache.derby.iapi.types.DataValueDescriptor[], int)
,
TransactionController.getDynamicCompiledConglomInfo(long)
,
TransactionController.getStaticCompiledConglomInfo(long)
,
DynamicCompiledOpenConglomInfo
,
StaticCompiledOpenConglomInfo
public StoreCostController openStoreCost(long conglomId) throws StandardException
Return an open StoreCostController which can be used to ask about the estimated row counts and costs of ScanController and ConglomerateController operations, on the given conglomerate.
openStoreCost
in interface TransactionController
conglomId
- The identifier of the conglomerate to open.StandardException
- Standard exception policy.StoreCostController
public long createSort(java.util.Properties implParameters, DataValueDescriptor[] template, ColumnOrdering[] columnOrdering, SortObserver sortObserver, boolean alreadyInOrder, long estimatedRows, int estimatedRowSize) throws StandardException
TransactionController
Sorts also do aggregation. The input (unaggregated) rows have the same format as the aggregated rows, and the aggregate results are part of the both rows. The sorter, when it notices that a row is a duplicate of another, calls a user-supplied aggregation method (see interface Aggregator), passing it both rows. One row is known as the 'addend' and the other the 'accumulator'. The aggregation method is assumed to merge the addend into the accumulator. The sort then discards the addend row.
So, for the query:
The input row to the sorter would have one column for a and another column for sum(b). It is up to the caller to get the format of the row correct, and to initialize the aggregate values correctly (null for most aggregates, 0 for count).select a, sum(b) from t group by a
Nulls are always considered to be ordered in a sort, that is, null compares equal to null, and less than anything else.
createSort
in interface TransactionController
implParameters
- Properties which help in choosing
implementation-specific sort options. If null, a
"generally useful" sort will be used.template
- A row which is prototypical for the sort.
All rows inserted into the sort controller must have
exactly the same number of columns as the template row.
Every column in an inserted row must have the same type
as the corresponding column in the template.columnOrdering
- An array which specifies which columns
participate in ordering - see interface ColumnOrdering for
details. The column referenced in the 0th columnOrdering
object is compared first, then the 1st, etc. To sort on a single
column specify an array with a single entry.sortObserver
- An object that is used to observe
the sort. It is used to provide a callback into the sorter.
If the sortObserver is null, then the sort proceeds as normal.
If the sortObserver is non null, then it is called as
rows are loaded into the sorter. It can be used to implement
a distinct sort, aggregates, etc.alreadyInOrder
- Indicates that the rows inserted into
the sort controller will already be in order. This is used
to perform aggregation only.estimatedRows
- The number of rows that the caller
estimates will be inserted into the sort. -1 indicates that
the caller has no idea. Used by the sort to make good choices
about in-memory vs. external sorting, and to size merge runs.estimatedRowSize
- The estimated average row size of the
rows being sorted. This is the client portion of the rowsize, it should
not attempt to calculate Store's overhead. -1 indicates that the caller
has no idea (and the sorter will use 100 bytes in that case. Used by the
sort to make good choices about in-memory vs. external sorting, and to size
merge runs. The client is not expected to estimate the per column/
per row overhead of raw store, just to make a guess about the storage
associated with each row (ie. reasonable estimates for some implementations
would be 4 for int, 8 for long, 102 for char(100),
202 for varchar(200), a number out of hat for user types, ...).StandardException
- Standard error policy.TransactionController.createSort(java.util.Properties, org.apache.derby.iapi.types.DataValueDescriptor[], org.apache.derby.iapi.store.access.ColumnOrdering[], org.apache.derby.iapi.store.access.SortObserver, boolean, long, int)
public void dropSort(long sortid) throws StandardException
Drop a sort created by a call to createSort() within the current transaction (sorts are automatically "dropped" at the end of a transaction. This call should only be made after all openSortScan()'s and openSort()'s have been closed.
dropSort
in interface TransactionController
sortid
- The identifier of the sort to drop, as returned from
createSort.StandardException
- From a lower-level exception.public java.io.Serializable getProperty(java.lang.String key) throws StandardException
PersistentSet
The Store provides a transaction protected list of database properties. Higher levels of the system can store and retrieve these properties once Recovery has finished. Each property is a serializable object and is stored/retrieved using a String key.
getProperty
in interface PersistentSet
key
- The "key" of the property that is being requested.StandardException
- Standard exception policy.PersistentSet.getProperty(java.lang.String)
public java.io.Serializable getPropertyDefault(java.lang.String key) throws StandardException
PersistentSet
The Store provides a transaction protected list of database properties. Higher levels of the system can store and retrieve these properties once Recovery has finished. Each property is a serializable object and is stored/retrieved using a String key.
getPropertyDefault
in interface PersistentSet
key
- The "key" of the property that is being requested.StandardException
- Standard exception policy.PersistentSet.getPropertyDefault(java.lang.String)
public void setProperty(java.lang.String key, java.io.Serializable value, boolean dbOnlyProperty) throws StandardException
PersistentSet
See the discussion of getProperty().
The value stored may be a Formatable object or a Serializable object whose class name starts with java.*. This stops arbitary objects being stored in the database by class name, which will cause problems in obfuscated/non-obfuscated systems.
setProperty
in interface PersistentSet
key
- The key used to lookup this property.value
- The value to be associated with this key. If null,
delete the property from the properties list.dbOnlyProperty
- True if property is only ever searched for int the database properties.StandardException
- Standard exception policy.PersistentSet.setProperty(java.lang.String, java.io.Serializable, boolean)
public void setPropertyDefault(java.lang.String key, java.io.Serializable value) throws StandardException
PersistentSet
See the discussion of getProperty().
The value stored may be a Formatable object or a Serializable object whose class name starts with java.*. This stops arbitary objects being stored in the database by class name, which will cause problems in obfuscated/non-obfuscated systems.
setPropertyDefault
in interface PersistentSet
key
- The key used to lookup this propertyDefault.value
- The default value to be associated with this key.
If null, delete the property default from the
properties list.StandardException
- Standard exception policy.PersistentSet.setProperty(java.lang.String, java.io.Serializable, boolean)
public boolean propertyDefaultIsVisible(java.lang.String key) throws StandardException
PersistentSet
propertyDefaultIsVisible
in interface PersistentSet
key
- The "key" of the property that is being requested.StandardException
- Standard exception policy.PersistentSet.propertyDefaultIsVisible(java.lang.String)
public java.util.Properties getProperties() throws StandardException
PersistentSet
Get the sub-set of stored properties that can be stored in a java.util.Properties object. That is all the properties that have a value of type java.lang.String. Changes to this properties object are not reflected in any persisent storage.
Code must use the setProperty() method call.
getProperties
in interface PersistentSet
StandardException
- Standard exception policy.PersistentSet.getProperties()
public SortController openSort(long id) throws StandardException
TransactionController
There may (in the future) be multiple sort inserters for a given sort, the idea being that the various threads of a parallel query plan can all insert into the sort. For now, however, only a single sort controller per sort is supported.
openSort
in interface TransactionController
id
- The identifier of the sort to open, as returned from
createSort.StandardException
- Standard error policy.TransactionController.openSort(long)
public SortCostController openSortCostController() throws StandardException
Return an open SortCostController which can be used to ask about the estimated costs of SortController() operations.
openSortCostController
in interface TransactionController
StandardException
- Standard exception policy.StoreCostController
public ScanController openSortScan(long id, boolean hold) throws StandardException
TransactionController
In the future, multiple sort scans on the same sort will be supported (for parallel execution across a uniqueness sort in which the order of the resulting rows is not important). Currently, only a single sort scan is allowed per sort.
In the future, it will be possible to open a sort scan and start retrieving rows before the last row is inserted. The sort controller would block till rows were available to return. Currently, an attempt to retrieve a row before the sort controller is closed will cause an exception.
openSortScan
in interface TransactionController
id
- The identifier of the sort to scan, as returned from createSort.hold
- If true, this scan will be maintained open over commits.StandardException
- Standard error policy.TransactionController.openSortScan(long, boolean)
public RowLocationRetRowSource openSortRowSource(long id) throws StandardException
TransactionController
openSortRowSource
in interface TransactionController
id
- The identifier of the sort to scan, as returned
from createSort.StandardException
- Standard error policy.TransactionController.openSortRowSource(long)
public void commit() throws StandardException
TransactionController
commit
in interface TransactionController
StandardException
- Only exceptions with severities greater than
ExceptionSeverity.TRANSACTION_SEVERITY will be thrown.
If an exception is thrown, the transaction will not (necessarily) have
been aborted. The standard error handling mechanism is expected to do the
appropriate cleanup. In other words, if commit() encounters an error, the
exception is propagated up to the the standard exception handler, which
initiates cleanupOnError() processing, which will eventually abort the
transaction.public DatabaseInstant commitNoSync(int commitflag) throws StandardException
TransactionController
commitNoSync
in interface TransactionController
StandardException
- Only exceptions with severities greater than
ExceptionSeverity.TRANSACTION_SEVERITY will be thrown.
If an exception is thrown, the transaction will not (necessarily) have
been aborted. The standard error handling mechanism is expected to do the
appropriate cleanup. In other words, if commit() encounters an error, the
exception is propagated up to the the standard exception handler, which
initiates cleanupOnError() processing, which will eventually abort the
transaction.TransactionController.commit()
public void abort() throws StandardException
TransactionController
abort
in interface TransactionController
StandardException
- Only exceptions with severities greater than
ExceptionSeverity.TRANSACTION_SEVERITY will be thrown.public ContextManager getContextManager()
getContextManager
in interface TransactionController
public int setSavePoint(java.lang.String name, java.lang.Object kindOfSavepoint) throws StandardException
TransactionController
setSavePoint
in interface TransactionController
name
- The user provided name of the savepoint.kindOfSavepoint
- A NULL value means it is an internal savepoint (ie not a user defined savepoint)
Non NULL value means it is a user defined savepoint which can be a SQL savepoint or a JDBC savepoint
A String value for kindOfSavepoint would mean it is SQL savepoint
A JDBC Savepoint object value for kindOfSavepoint would mean it is JDBC savepointStandardException
- Standard Derby exception policy. A
statement level exception is thrown if
no savepoint exists with the given name.public int releaseSavePoint(java.lang.String name, java.lang.Object kindOfSavepoint) throws StandardException
TransactionController
releaseSavePoint
in interface TransactionController
name
- The user provided name of the savepoint, set by the user
in the setSavePoint() call.kindOfSavepoint
- A NULL value means it is an internal savepoint (ie not a user defined savepoint)
Non NULL value means it is a user defined savepoint which can be a SQL savepoint or a JDBC savepoint
A String value for kindOfSavepoint would mean it is SQL savepoint
A JDBC Savepoint object value for kindOfSavepoint would mean it is JDBC savepointStandardException
- Standard Derby exception policy. A
statement level exception is thrown if
no savepoint exists with the given name.public int rollbackToSavePoint(java.lang.String name, boolean close_controllers, java.lang.Object kindOfSavepoint) throws StandardException
TransactionController
if "close_controllers" is true then all conglomerates and scans are closed (held or non-held).
If "close_controllers" is false then no cleanup is done by the TransactionController. It is then the responsibility of the caller to close all resources that may have been affected by the statements backed out by the call. This option is meant to be used by the Language implementation of statement level backout, where the system "knows" what could be affected by the scope of the statements executed within the statement.
rollbackToSavePoint
in interface TransactionController
name
- The identifier of the SavePoint to roll back to.close_controllers
- boolean indicating whether or not the controller
should close open controllers.kindOfSavepoint
- A NULL value means it is an internal savepoint (ie not a user defined savepoint)
Non NULL value means it is a user defined savepoint which can be a SQL savepoint or a JDBC savepoint
A String value for kindOfSavepoint would mean it is SQL savepoint
A JDBC Savepoint object value for kindOfSavepoint would mean it is JDBC savepointStandardException
- Standard Derby exception policy. A
statement level exception is thrown if
no savepoint exists with the given name.public void destroy()
TransactionController
destroy
in interface TransactionController
public boolean anyoneBlocked()
TransactionController
anyoneBlocked
in interface TransactionController
public void xa_commit(boolean onePhase) throws StandardException
RESOLVE - how do we map to the "right" XAExceptions.
xa_commit
in interface XATransactionController
onePhase
- If true, the resource manager should use a one-phase
commit protocol to commit the work done on behalf of
current xid.StandardException
- Standard exception policy.public int xa_prepare() throws StandardException
xa_prepare
in interface XATransactionController
StandardException
- Standard exception policy.public void xa_rollback() throws StandardException
The given transaction is roll'ed back and it's history is not maintained in the transaction table or long term log.
xa_rollback
in interface XATransactionController
StandardException
- Standard exception policy.public Conglomerate findExistingConglomerateFromKey(ContainerKey container_key) throws StandardException
Throws exception if it can't find a matching conglomerate for the ContainerKey.
findExistingConglomerateFromKey
in interface TransactionManager
container_key
- container key of target conglomerate.StandardException
- Standard exception policy.public void addPostCommitWork(Serviceable work)
Add to the list of post commit work that may be processed after this transaction commits. If this transaction aborts, then the post commit work list will be thrown away. No post commit work will be taken out on a rollback to save point.
This routine simply delegates the work to the Rawstore transaction.
addPostCommitWork
in interface TransactionManager
work
- The post commit work to do.public boolean checkVersion(int requiredMajorVersion, int requiredMinorVersion, java.lang.String feature) throws StandardException
checkVersion
in interface TransactionManager
requiredMajorVersion
- required database Engine major versionrequiredMinorVersion
- required database Engine minor versionfeature
- Non-null to throw an exception, null to
return the state of the version match. true
if the database has been upgraded to
the required level, false
otherwise.StandardException
- if the database is not at the require version
when feature
feature is
not null
.public void closeMe(ConglomerateController conglom_control)
Take whatever cleanup action is appropriate to a closed conglomerateController. It is likely this routine will remove references to the ConglomerateController object that it was maintaining for cleanup purposes.
closeMe
in interface TransactionManager
public void closeMe(SortController sort_control)
Take whatever cleanup action is appropriate to a closed sortController. It is likely this routine will remove references to the SortController object that it was maintaining for cleanup purposes.
closeMe
in interface TransactionManager
public void closeMe(ScanManager scan)
Take whatever cleanup action is appropriate to a closed scan. It is likely this routine will remove references to the scan object that it was maintaining for cleanup purposes.
closeMe
in interface TransactionManager
public AccessFactory getAccessManager()
getAccessManager
in interface TransactionController
public TransactionManager getInternalTransaction() throws StandardException
Start an internal transaction. An internal transaction is a completely separate transaction from the current user transaction. All work done in the internal transaction must be physical (ie. it can be undone physically by the rawstore at the page level, rather than logically undone like btree insert/delete operations). The rawstore guarantee's that in the case of a system failure all open Internal transactions are first undone in reverse order, and then other transactions are undone in reverse order.
Internal transactions are meant to implement operations which, if interupted before completion will cause logical operations like tree searches to fail. This special undo order insures that the state of the tree is restored to a consistent state before any logical undo operation which may need to search the tree is performed.
getInternalTransaction
in interface TransactionManager
StandardException
- Standard exception policy.public TransactionController startNestedUserTransaction(boolean readOnly, boolean flush_log_on_xact_end) throws StandardException
A nested user can be used exactly as any other TransactionController, except as follows. For this discussion let the parent transaction be the transaction used to make the getNestedUserTransaction(), and let the child transaction be the transaction returned by the getNestedUserTransaction() call.
The nesting is limited to one level deep. An exception will be thrown if a subsequent getNestedUserTransaction() is called on the child transaction.
The locks in the child transaction will be compatible with the locks of the parent transaction.
A commit in the child transaction will release locks associated with the child transaction only, work can continue in the parent transaction at this point.
Any abort of the child transaction will result in an abort of both the child transaction and parent transaction.
A TransactionController.destroy() call should be made on the child transaction once all child work is done, and the caller wishes to continue work in the parent transaction.
Nested internal transactions are meant to be used to implement system work necessary to commit as part of implementing a user's request, but where holding the lock for the duration of the user transaction is not acceptable. 2 examples of this are system catalog read locks accumulated while compiling a plan, and auto-increment.
startNestedUserTransaction
in interface TransactionController
readOnly
- Is transaction readonly? Only 1 non-read
only nested transaction is allowed per
transaction.flush_log_on_xact_end
- By default should the transaction commit
and abort be synced to the log. Normal
usage should pick true, unless there is
specific performance need and usage
works correctly if a commit can be lost
on system crash.StandardException
- Standard exception policy.public Transaction getRawStoreXact()
Access methods often need direct access to the "Transaction" - ie. the raw store transaction, so give access to it.
getRawStoreXact
in interface TransactionManager
public FileResource getFileHandler()
TransactionController
getFileHandler
in interface TransactionController
public CompatibilitySpace getLockSpace()
getOwner()
on that object is used as group for a lock
request, guarantees that the lock will be removed on a commit or an
abort.getLockSpace
in interface TransactionController
public void setNoLockWait(boolean noWait)
For now, this only works if the transaction has its own compatibility space. If it has inherited the compatibility space from its parent, the request will be ignored (or cause a failure in debug builds).
setNoLockWait
in interface TransactionController
noWait
- if true
never wait for a lock in this transaction,
but time out immediatelyLockOwner.noWait()
,
Transaction.setNoLockWait(boolean)
public java.lang.String getTransactionIdString()
This transaction "name" will be the same id which is returned in the TransactionInfo information, used by the lock and transaction vti's to identify transactions.
Although implementation specific, the transaction id is usually a number which is bumped every time a commit or abort is issued.
For now return the toString() method, which does what we want. Later if that is not good enough we can add public raw tran interfaces to get exactly what we want.
getTransactionIdString
in interface TransactionController
public java.lang.String getActiveStateTxIdString()
getActiveStateTxIdString
in interface TransactionController
public java.lang.String toString()
toString
in class java.lang.Object
Apache Derby V10.13 Internals - Copyright © 2004,2016 The Apache Software Foundation. All Rights Reserved.