📄 ndbtransaction.hpp
字号:
/* Copyright (C) 2003 MySQL AB This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; version 2 of the License. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */#ifndef NdbTransaction_H#define NdbTransaction_H#include <ndb_types.h>#include "NdbError.hpp"#include "NdbDictionary.hpp"#include "Ndb.hpp"class NdbTransaction;class NdbOperation;class NdbScanOperation;class NdbIndexScanOperation;class NdbIndexOperation;class NdbApiSignal;class Ndb;class NdbBlob;#ifndef DOXYGEN_SHOULD_SKIP_INTERNAL// to be documented later/** * NdbAsynchCallback functions are used when executing asynchronous * transactions (using NdbTransaction::executeAsynchPrepare, or * NdbTransaction::executeAsynch). * The functions are called when the execute has finished. * See @ref secAsync for more information. */typedef void (* NdbAsynchCallback)(int, NdbTransaction*, void*);#endif#ifndef DOXYGEN_SHOULD_SKIP_INTERNALenum AbortOption { CommitIfFailFree= 0, TryCommit= 0, AbortOnError= 0, CommitAsMuchAsPossible= 2, AO_IgnoreError= 2};enum ExecType { NoExecTypeDef = -1, Prepare, NoCommit, Commit, Rollback};#endif/** * @class NdbTransaction * @brief Represents a transaction. * * 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: * -# NdbTransaction::NoCommit Executes operations without committing them. * -# NdbTransaction::Commit Executes remaining operation and commits the * complete transaction * -# NdbTransaction::Rollback Rollbacks the entire transaction. * * execute() is equipped with an extra error handling parameter. * There are two alternatives: * -# NdbTransaction::AbortOnError (default). * The transaction is aborted if there are any error during the * execution * -# NdbTransaction::AO_IgnoreError * Continue execution of transaction even if operation fails * *//* FUTURE IMPLEMENTATION: * Later a prepare mode will be added when Ndb supports Prepare-To-Commit * The NdbTransaction can deliver the Transaction Id of the transaction. * After committing a transaction it is also possible to retrieve the * global transaction checkpoint which the transaction was put in. * * FUTURE IMPLEMENTATION: * There are three methods for acquiring the NdbOperation. * -# The first method is the normal where a table name is * provided. In this case the primary key must be supplied through * the use of the NdbOperation::equal methods on the NdbOperation object. * -# The second method provides the tuple identity of the tuple to be * read. The tuple identity contains a table identifier and will * thus be possible to use to ensure the attribute names provided * are correct. If an object-oriented layer is put on top of NDB * Cluster it is essential that all tables derived from a base * class has the same attributes with the same type and the same * name. Thus the application can use the tuple identity and need * not known the table of the tuple. As long as the table is * derived from the known base class everything is ok. * It is not possible to provide any primary key since it is * already supplied with the call to NdbTransaction::getNdbOperation. * -# The third method is used when a scanned tuple is to be transferred to * another transaction. In this case it is not possible to define the * primary key since it came along from the scanned tuple. * */class NdbTransaction{#ifndef DOXYGEN_SHOULD_SKIP_INTERNAL friend class Ndb; friend class NdbOperation; friend class NdbScanOperation; friend class NdbIndexOperation; friend class NdbIndexScanOperation; friend class NdbBlob; friend class ha_ndbcluster;#endifpublic: /** * Commit type of transaction */ enum AbortOption { AbortOnError= ///< Abort transaction on failed operation#ifndef DOXYGEN_SHOULD_SKIP_INTERNAL ::AbortOnError#endif ,AO_IgnoreError= ///< Transaction continues on failed operation#ifndef DOXYGEN_SHOULD_SKIP_INTERNAL ::AO_IgnoreError#endif }; /** * Execution type of transaction */ enum ExecType {#ifndef DOXYGEN_SHOULD_SKIP_INTERNAL NoExecTypeDef= ::NoExecTypeDef, ///< Erroneous type (Used for debugging only) Prepare= ::Prepare, ///< <i>Missing explanation</i>#endif NoCommit= ///< Execute the transaction as far as it has ///< been defined, but do not yet commit it#ifndef DOXYGEN_SHOULD_SKIP_INTERNAL ::NoCommit#endif ,Commit= ///< Execute and try to commit the transaction#ifndef DOXYGEN_SHOULD_SKIP_INTERNAL ::Commit#endif ,Rollback ///< Rollback transaction#ifndef DOXYGEN_SHOULD_SKIP_INTERNAL = ::Rollback#endif };#ifndef DOXYGEN_SHOULD_SKIP_DEPRECATED /** * Get an NdbOperation for a table. * Note that the operation has to be defined before it is executed. * * @note All operations within the same transaction need to * be initialized with this method. * * @param aTableName The table name. * @return Pointer to an NdbOperation object if successful, otherwise NULL. */ NdbOperation* getNdbOperation(const char* aTableName);#endif /** * Get an NdbOperation for a table. * Note that the operation has to be defined before it is executed. * * @note All operations within the same transaction need to * be initialized with this method. * * @param aTable * A table object (fetched by NdbDictionary::Dictionary::getTable) * @return Pointer to an NdbOperation object if successful, otherwise NULL. */ NdbOperation* getNdbOperation(const NdbDictionary::Table * aTable);#ifndef DOXYGEN_SHOULD_SKIP_DEPRECATED /** * Get an operation from NdbScanOperation idlelist and * get the NdbTransaction object which * was fetched by startTransaction pointing to this operation. * * @param aTableName The table name. * @return pointer to an NdbOperation object if successful, otherwise NULL */ NdbScanOperation* getNdbScanOperation(const char* aTableName);#endif /** * Get an operation from NdbScanOperation idlelist and * get the NdbTransaction object which * was fetched by startTransaction pointing to this operation. * * @param aTable * A table object (fetched by NdbDictionary::Dictionary::getTable) * @return pointer to an NdbOperation object if successful, otherwise NULL */ NdbScanOperation* getNdbScanOperation(const NdbDictionary::Table * aTable);#ifndef DOXYGEN_SHOULD_SKIP_DEPRECATED /** * Get an operation from NdbIndexScanOperation idlelist and * get the NdbTransaction object which * was fetched by startTransaction pointing to this operation. * * @param anIndexName The index name. * @param aTableName The table name. * @return pointer to an NdbOperation object if successful, otherwise NULL */ NdbIndexScanOperation* getNdbIndexScanOperation(const char* anIndexName, const char* aTableName); NdbIndexScanOperation* getNdbIndexScanOperation (const NdbDictionary::Index *anIndex, const NdbDictionary::Table *aTable);#endif /** * Get an operation from NdbIndexScanOperation idlelist and * get the NdbTransaction object which * was fetched by startTransaction pointing to this operation. * * @param anIndex An index object (fetched by NdbDictionary::Dictionary::getIndex). * @return pointer to an NdbOperation object if successful, otherwise NULL */ NdbIndexScanOperation* getNdbIndexScanOperation (const NdbDictionary::Index *anIndex); #ifndef DOXYGEN_SHOULD_SKIP_DEPRECATED /** * Get an operation from NdbIndexOperation idlelist and * get the NdbTransaction object that * was fetched by startTransaction pointing to this operation. * * @param anIndexName The index name (as created by createIndex). * @param aTableName The table name. * @return Pointer to an NdbIndexOperation object if * successful, otherwise NULL */ NdbIndexOperation* getNdbIndexOperation(const char* anIndexName, const char* aTableName); NdbIndexOperation* getNdbIndexOperation(const NdbDictionary::Index *anIndex, const NdbDictionary::Table *aTable);#endif /** * Get an operation from NdbIndexOperation idlelist and * get the NdbTransaction object that * was fetched by startTransaction pointing to this operation. * * @param anIndex * An index object (fetched by NdbDictionary::Dictionary::getIndex). * @return Pointer to an NdbIndexOperation object if * successful, otherwise NULL */ NdbIndexOperation* getNdbIndexOperation(const NdbDictionary::Index *anIndex); /** * @name Execute Transaction * @{ */ /** * Executes transaction. * * @param execType Execution type:<br> * ExecType::NoCommit executes operations without * committing them.<br> * ExecType::Commit executes remaining operations and * commits the complete transaction.<br> * ExecType::Rollback rollbacks the entire transaction. * @param abortOption Handling of error while excuting * AbortOnError - Abort transaction if an operation fail * IgnoreError - Accept failing operations * @param force When operations should be sent to NDB Kernel. * (See @ref secAdapt.) * - 0: non-force, adaptive algorithm notices it * (default); * - 1: force send, adaptive algorithm notices it; * - 2: non-force, adaptive algorithm do not notice * the send. * @return 0 if successful otherwise -1. */ int execute(ExecType execType, AbortOption abortOption = AbortOnError, int force = 0 );#ifndef DOXYGEN_SHOULD_SKIP_DEPRECATED int execute(::ExecType execType, ::AbortOption abortOption = ::AbortOnError, int force = 0 ) { return execute ((ExecType)execType,(AbortOption)abortOption,force); }#endif#ifndef DOXYGEN_SHOULD_SKIP_INTERNAL // to be documented later /** * Prepare an asynchronous transaction. * * See @ref secAsync for more information on * how to use this method. * * @param execType Execution type:<br> * ExecType::NoCommit executes operations without committing them.<br> * ExecType::Commit executes remaining operations and commits the * complete transaction.<br> * ExecType::Rollback rollbacks the entire transaction. * @param callback A callback method. This method gets * called when the transaction has been * executed. See @ref ndbapi_async1.cpp * for an example on how to specify and use * a callback method. * @param anyObject A void pointer. This pointer is forwarded to the * callback method and can be used to give * the callback method some data to work on. * It is up to the application programmer * to decide on the use of this pointer. * @param abortOption see @ref execute */ void executeAsynchPrepare(ExecType execType, NdbAsynchCallback callback,
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -