diff options
Diffstat (limited to 'ndb/include')
-rw-r--r-- | ndb/include/ndbapi/NdbApi.hpp | 1 | ||||
-rw-r--r-- | ndb/include/ndbapi/NdbIndexScanOperation.hpp | 18 | ||||
-rw-r--r-- | ndb/include/ndbapi/NdbResultSet.hpp | 162 | ||||
-rw-r--r-- | ndb/include/ndbapi/NdbScanOperation.hpp | 158 |
4 files changed, 137 insertions, 202 deletions
diff --git a/ndb/include/ndbapi/NdbApi.hpp b/ndb/include/ndbapi/NdbApi.hpp index add733cccd7..c6c6bfdd546 100644 --- a/ndb/include/ndbapi/NdbApi.hpp +++ b/ndb/include/ndbapi/NdbApi.hpp @@ -26,7 +26,6 @@ #include "NdbIndexScanOperation.hpp" #include "NdbScanFilter.hpp" #include "NdbRecAttr.hpp" -#include "NdbResultSet.hpp" #include "NdbDictionary.hpp" #include "NdbEventOperation.hpp" #include "NdbPool.hpp" diff --git a/ndb/include/ndbapi/NdbIndexScanOperation.hpp b/ndb/include/ndbapi/NdbIndexScanOperation.hpp index cc5b468c1fb..84e91b42c98 100644 --- a/ndb/include/ndbapi/NdbIndexScanOperation.hpp +++ b/ndb/include/ndbapi/NdbIndexScanOperation.hpp @@ -42,20 +42,20 @@ public: * @returns NdbResultSet. * @see NdbScanOperation::readTuples */ - NdbResultSet* readTuples(LockMode = LM_Read, - Uint32 batch = 0, - Uint32 parallel = 0, - bool order_by = false, - bool read_range_no = false); + int readTuples(LockMode = LM_Read, + Uint32 batch = 0, + Uint32 parallel = 0, + bool order_by = false, + bool read_range_no = false); - inline NdbResultSet* readTuples(int parallell){ + inline int readTuples(int parallell){ return readTuples(LM_Read, 0, parallell, false); } - inline NdbResultSet* readTuplesExclusive(int parallell = 0){ + inline int readTuplesExclusive(int parallell = 0){ return readTuples(LM_Exclusive, 0, parallell, false); } - + /** * Type of ordered index key bound. The values (0-4) will not change * and can be used explicitly (e.g. they could be computed). @@ -125,7 +125,7 @@ public: /** * Return range no for current row */ - Uint32 get_range_no(); + int get_range_no(); bool getSorted() const { return m_ordered; } private: diff --git a/ndb/include/ndbapi/NdbResultSet.hpp b/ndb/include/ndbapi/NdbResultSet.hpp deleted file mode 100644 index dc0288a380c..00000000000 --- a/ndb/include/ndbapi/NdbResultSet.hpp +++ /dev/null @@ -1,162 +0,0 @@ -/* 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; either version 2 of the License, or - (at your option) any later version. - - 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 */ - -/***************************************************************************** - * Name: NdbResultSet.hpp - * Include: - * Link: - * Author: Martin Sköld - * Date: 2002-04-01 - * Version: 0.1 - * Description: Cursor class - * Documentation: - * Adjust: 2002-04-01 Martin Sköld First version. - ****************************************************************************/ - -#ifndef NdbResultSet_H -#define NdbResultSet_H - - -#include <NdbScanOperation.hpp> - -/** - * @class NdbResultSet - * @brief NdbResultSet contains a NdbScanOperation. - */ -class NdbResultSet -{ - friend class NdbScanOperation; - -public: - - /** - * Get the next tuple in a scan transaction. - * - * After each call to NdbResult::nextResult - * the buffers and NdbRecAttr objects defined in - * NdbOperation::getValue are updated with values - * from the scanned tuple. - * - * @param fetchAllowed If set to false, then fetching is disabled - * - * The NDB API will contact the NDB Kernel for more tuples - * when necessary to do so unless you set the fetchAllowed - * to false. - * This will force NDB to process any records it - * already has in it's caches. When there are no more cached - * records it will return 2. You must then call nextResult - * with fetchAllowed = true in order to contact NDB for more - * records. - * - * fetchAllowed = false is useful when you want to update or - * delete all the records fetched in one transaction(This will save a - * lot of round trip time and make updates or deletes of scanned - * records a lot faster). - * While nextResult(false) - * returns 0 take over the record to another transaction. When - * nextResult(false) returns 2 you must execute and commit the other - * transaction. This will cause the locks to be transferred to the - * other transaction, updates or deletes will be made and then the - * locks will be released. - * After that, call nextResult(true) which will fetch new records and - * cache them in the NdbApi. - * - * @note If you don't take over the records to another transaction the - * locks on those records will be released the next time NDB Kernel - * is contacted for more records. - * - * @note Please contact for examples of efficient scan - * updates and deletes. - * - * @note See ndb/examples/ndbapi_scan_example for usage. - * - * @return - * - -1: if unsuccessful,<br> - * - 0: if another tuple was received, and<br> - * - 1: if there are no more tuples to scan. - * - 2: if there are no more cached records in NdbApi - */ - int nextResult(bool fetchAllowed = true, bool forceSend = false); - - /** - * Close result set (scan) - */ - void close(bool forceSend = false); - - /** - * Restart - */ - int restart(bool forceSend = false); - - /** - * Transfer scan operation to an updating transaction. Use this function - * when a scan has found a record that you want to update. - * 1. Start a new transaction. - * 2. Call the function takeOverForUpdate using your new transaction - * as parameter, all the properties of the found record will be copied - * to the new transaction. - * 3. When you execute the new transaction, the lock held by the scan will - * be transferred to the new transaction(it's taken over). - * - * @note You must have started the scan with openScanExclusive - * to be able to update the found tuple. - * - * @param updateTrans the update transaction connection. - * @return an NdbOperation or NULL. - */ - NdbOperation* updateTuple(); - NdbOperation* updateTuple(NdbConnection* updateTrans); - - /** - * Transfer scan operation to a deleting transaction. Use this function - * when a scan has found a record that you want to delete. - * 1. Start a new transaction. - * 2. Call the function takeOverForDelete using your new transaction - * as parameter, all the properties of the found record will be copied - * to the new transaction. - * 3. When you execute the new transaction, the lock held by the scan will - * be transferred to the new transaction(its taken over). - * - * @note You must have started the scan with openScanExclusive - * to be able to delete the found tuple. - * - * @param deleteTrans the delete transaction connection. - * @return an NdbOperation or NULL. - */ - int deleteTuple(); - int deleteTuple(NdbConnection* takeOverTransaction); - - /** - * Get underlying operation - */ - NdbOperation* getOperation(); -private: - NdbResultSet(NdbScanOperation*); - - ~NdbResultSet(); - - void init(); - - NdbScanOperation* m_operation; -}; - -inline -NdbOperation* -NdbResultSet::getOperation(){ - return m_operation; -} - -#endif diff --git a/ndb/include/ndbapi/NdbScanOperation.hpp b/ndb/include/ndbapi/NdbScanOperation.hpp index 861cda9b09e..06f7c7f9565 100644 --- a/ndb/include/ndbapi/NdbScanOperation.hpp +++ b/ndb/include/ndbapi/NdbScanOperation.hpp @@ -46,20 +46,6 @@ class NdbScanOperation : public NdbOperation { friend class NdbBlob; public: /** - * Type of cursor - */ - enum CursorType { - NoCursor = 0, - ScanCursor = 1, - IndexCursor = 2 - }; - - /** - * Type of cursor - */ - CursorType get_cursor_type() const; - - /** * readTuples returns a NdbResultSet where tuples are stored. * Tuples are not stored in NdbResultSet until execute(NoCommit) * has been executed and nextResult has been called. @@ -67,33 +53,126 @@ public: * @param parallel Scan parallelism * @param batch No of rows to fetch from each fragment at a time * @param LockMode Scan lock handling - * @returns NdbResultSet. * @note specifying 0 for batch and parallall means max performance */ - NdbResultSet* readTuples(LockMode = LM_Read, - Uint32 batch = 0, Uint32 parallel = 0); + int readTuples(LockMode = LM_Read, + Uint32 batch = 0, Uint32 parallel = 0); - inline NdbResultSet* readTuples(int parallell){ + inline int readTuples(int parallell){ return readTuples(LM_Read, 0, parallell); } - inline NdbResultSet* readTuplesExclusive(int parallell = 0){ + inline int readTuplesExclusive(int parallell = 0){ return readTuples(LM_Exclusive, 0, parallell); } NdbBlob* getBlobHandle(const char* anAttrName); NdbBlob* getBlobHandle(Uint32 anAttrId); -protected: - CursorType m_cursor_type; + /** + * Get the next tuple in a scan transaction. + * + * After each call to NdbResult::nextResult + * the buffers and NdbRecAttr objects defined in + * NdbOperation::getValue are updated with values + * from the scanned tuple. + * + * @param fetchAllowed If set to false, then fetching is disabled + * + * The NDB API will contact the NDB Kernel for more tuples + * when necessary to do so unless you set the fetchAllowed + * to false. + * This will force NDB to process any records it + * already has in it's caches. When there are no more cached + * records it will return 2. You must then call nextResult + * with fetchAllowed = true in order to contact NDB for more + * records. + * + * fetchAllowed = false is useful when you want to update or + * delete all the records fetched in one transaction(This will save a + * lot of round trip time and make updates or deletes of scanned + * records a lot faster). + * While nextResult(false) + * returns 0 take over the record to another transaction. When + * nextResult(false) returns 2 you must execute and commit the other + * transaction. This will cause the locks to be transferred to the + * other transaction, updates or deletes will be made and then the + * locks will be released. + * After that, call nextResult(true) which will fetch new records and + * cache them in the NdbApi. + * + * @note If you don't take over the records to another transaction the + * locks on those records will be released the next time NDB Kernel + * is contacted for more records. + * + * @note Please contact for examples of efficient scan + * updates and deletes. + * + * @note See ndb/examples/ndbapi_scan_example for usage. + * + * @return + * - -1: if unsuccessful,<br> + * - 0: if another tuple was received, and<br> + * - 1: if there are no more tuples to scan. + * - 2: if there are no more cached records in NdbApi + */ + int nextResult(bool fetchAllowed = true, bool forceSend = false); + + /** + * Close result set (scan) + */ + void close(bool forceSend = false); + /** + * Restart + */ + int restart(bool forceSend = false); + + /** + * Transfer scan operation to an updating transaction. Use this function + * when a scan has found a record that you want to update. + * 1. Start a new transaction. + * 2. Call the function takeOverForUpdate using your new transaction + * as parameter, all the properties of the found record will be copied + * to the new transaction. + * 3. When you execute the new transaction, the lock held by the scan will + * be transferred to the new transaction(it's taken over). + * + * @note You must have started the scan with openScanExclusive + * to be able to update the found tuple. + * + * @param updateTrans the update transaction connection. + * @return an NdbOperation or NULL. + */ + NdbOperation* updateCurrentTuple(); + NdbOperation* updateCurrentTuple(NdbConnection* updateTrans); + + /** + * Transfer scan operation to a deleting transaction. Use this function + * when a scan has found a record that you want to delete. + * 1. Start a new transaction. + * 2. Call the function takeOverForDelete using your new transaction + * as parameter, all the properties of the found record will be copied + * to the new transaction. + * 3. When you execute the new transaction, the lock held by the scan will + * be transferred to the new transaction(its taken over). + * + * @note You must have started the scan with openScanExclusive + * to be able to delete the found tuple. + * + * @param deleteTrans the delete transaction connection. + * @return an NdbOperation or NULL. + */ + int deleteCurrentTuple(); + int deleteCurrentTuple(NdbConnection* takeOverTransaction); + +protected: NdbScanOperation(Ndb* aNdb); virtual ~NdbScanOperation(); - int nextResult(bool fetchAllowed = true, bool forceSend = false); + int nextResultImpl(bool fetchAllowed = true, bool forceSend = false); virtual void release(); - void closeScan(bool forceSend = false); int close_impl(class TransporterFacade*, bool forceSend = false); // Overloaded methods from NdbCursorOperation @@ -108,8 +187,6 @@ protected: virtual void setErrorCode(int aErrorCode); virtual void setErrorCodeAbort(int aErrorCode); - NdbResultSet * m_resultSet; - NdbResultSet* getResultSet(); NdbConnection *m_transConnection; // Scan related variables @@ -157,14 +234,35 @@ protected: Uint32 m_ordered; Uint32 m_read_range_no; - - int restart(bool forceSend = false); }; inline -NdbScanOperation::CursorType -NdbScanOperation::get_cursor_type() const { - return m_cursor_type; +NdbOperation* +NdbScanOperation::updateCurrentTuple(){ + return updateCurrentTuple(m_transConnection); +} + +inline +NdbOperation* +NdbScanOperation::updateCurrentTuple(NdbConnection* takeOverTrans){ + return takeOverScanOp(NdbOperation::UpdateRequest, + takeOverTrans); +} + +inline +int +NdbScanOperation::deleteCurrentTuple(){ + return deleteCurrentTuple(m_transConnection); +} + +inline +int +NdbScanOperation::deleteCurrentTuple(NdbConnection * takeOverTrans){ + void * res = takeOverScanOp(NdbOperation::DeleteRequest, + takeOverTrans); + if(res == 0) + return -1; + return 0; } #endif |