#include <NdbTransaction.hpp>
A transaction (represented by an NdbTransaction object) belongs to an Ndb object and is created using Ndb::startTransaction(). A transaction consists of a list of operations (represented by NdbOperation, NdbScanOperation, NdbIndexOperation, and NdbIndexScanOperation objects). Each operation access exactly one table.
After getting the NdbTransaction object, the first step is to get (allocate) an operation given the table name using one of the methods getNdbOperation(), getNdbScanOperation(), getNdbIndexOperation(), or getNdbIndexScanOperation(). Then the operation is defined. Several operations can be defined on the same NdbTransaction object, they will in that case be executed in parallell. When all operations are defined, the execute() method sends them to the NDB kernel for execution.
The execute() method returns when the NDB kernel has completed execution of all operations defined before the call to execute(). All allocated operations should be properly defined before calling execute().
A call to execute() uses one out of three types of execution:
execute() is equipped with an extra error handling parameter. There are two alternatives:
NdbOperation* NdbTransaction::getNdbOperation | ( | const NdbDictionary::Table * | aTable | ) |
Get an NdbOperation for a table. Note that the operation has to be defined before it is executed.
aTable | A table object (fetched by NdbDictionary::Dictionary::getTable) |
NdbScanOperation* NdbTransaction::getNdbScanOperation | ( | const NdbDictionary::Table * | aTable | ) |
Get an operation from NdbScanOperation idlelist and get the NdbTransaction object which was fetched by startTransaction pointing to this operation.
aTable | A table object (fetched by NdbDictionary::Dictionary::getTable) |
NdbIndexScanOperation* NdbTransaction::getNdbIndexScanOperation | ( | const NdbDictionary::Index * | anIndex | ) |
Get an operation from NdbIndexScanOperation idlelist and get the NdbTransaction object which was fetched by startTransaction pointing to this operation.
anIndex | An index object (fetched by NdbDictionary::Dictionary::getIndex). |
NdbIndexOperation* NdbTransaction::getNdbIndexOperation | ( | const NdbDictionary::Index * | anIndex | ) |
Get an operation from NdbIndexOperation idlelist and get the NdbTransaction object that was fetched by startTransaction pointing to this operation.
anIndex | An index object (fetched by NdbDictionary::Dictionary::getIndex). |
int NdbTransaction::execute | ( | ExecType | execType, | |
AbortOption | abortOption = AbortOnError , |
|||
int | force = 0 | |||
) |
Executes transaction.
execType | Execution type: ExecType::NoCommit executes operations without committing them. ExecType::Commit executes remaining operations and commits the complete transaction. ExecType::Rollback rollbacks the entire transaction. | |
abortOption | Handling of error while excuting AbortOnError - Abort transaction if an operation fail IgnoreError - Accept failing operations | |
force | When operations should be sent to NDB Kernel. (See Adaptive Send Algorithm.)
|
int NdbTransaction::refresh | ( | ) |
Refresh Update timeout counter of this transaction in the database. If you want to keep the transaction active in the database longer than the transaction abort timeout.
void NdbTransaction::close | ( | ) |
int NdbTransaction::getGCI | ( | ) |
Get global checkpoint identity (GCI) of transaction.
Each committed transaction belong to a GCI. The log for the committed transaction is saved on disk when a global checkpoint occurs.
Whether or not the global checkpoint with this GCI has been saved on disk or not cannot be determined by this method.
By comparing the GCI of a transaction with the value last GCI restored in a restarted NDB Cluster one can determine whether the transaction was restored or not.
Uint64 NdbTransaction::getTransactionId | ( | ) |
Get transaction identity.
CommitStatusType NdbTransaction::commitStatus | ( | ) |
Get the commit status of the transaction.
const NdbError& NdbTransaction::getNdbError | ( | ) | const |
Get error object with information about the latest error.
NdbOperation* NdbTransaction::getNdbErrorOperation | ( | ) |
Get the latest NdbOperation which had an error. This method is used on the NdbTransaction object to find the NdbOperation causing an error. To find more information about the actual error, use method NdbOperation::getNdbError() on the returned NdbOperation object.
int NdbTransaction::getNdbErrorLine | ( | ) |
Get the method number where the latest error occured.
const NdbOperation* NdbTransaction::getNextCompletedOperation | ( | const NdbOperation * | op | ) | const |
Get completed (i.e. executed) operations of a transaction
This method should only be used after a transaction has been executed.
This method is typically used to fetch all NdbOperation:s of a transaction to check for errors (use NdbOperation::getNdbError to fetch the NdbError object of an NdbOperation).
op | Operation, NULL means get first operation |