//////////////////////////////////////////////////////////////////////////////// /// @brief transaction collection /// /// @file /// /// DISCLAIMER /// /// Copyright 2004-2013 triAGENS GmbH, Cologne, Germany /// /// Licensed under the Apache License, Version 2.0 (the "License"); /// you may not use this file except in compliance with the License. /// You may obtain a copy of the License at /// /// http://www.apache.org/licenses/LICENSE-2.0 /// /// Unless required by applicable law or agreed to in writing, software /// distributed under the License is distributed on an "AS IS" BASIS, /// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. /// See the License for the specific language governing permissions and /// limitations under the License. /// /// Copyright holder is triAGENS GmbH, Cologne, Germany /// /// @author Jan Steemann /// @author Copyright 2011-2013, triAGENS GmbH, Cologne, Germany //////////////////////////////////////////////////////////////////////////////// #ifndef TRIAGENS_TRANSACTION_COLLECTION_H #define TRIAGENS_TRANSACTION_COLLECTION_H 1 #include "Basics/Common.h" #include "VocBase/primary-collection.h" #include "VocBase/vocbase.h" namespace triagens { namespace transaction { // ----------------------------------------------------------------------------- // --SECTION-- class Collection // ----------------------------------------------------------------------------- class Collection { // ----------------------------------------------------------------------------- // --SECTION-- typedefs // ----------------------------------------------------------------------------- public: //////////////////////////////////////////////////////////////////////////////// /// @brief access type //////////////////////////////////////////////////////////////////////////////// enum class AccessType { READ = 0, WRITE = 1 // includes read }; //////////////////////////////////////////////////////////////////////////////// /// @brief Operations //////////////////////////////////////////////////////////////////////////////// private: Collection (Collection const&); Collection& operator= (Collection const&); // ----------------------------------------------------------------------------- // --SECTION-- constructors and destructors // ----------------------------------------------------------------------------- public: //////////////////////////////////////////////////////////////////////////////// /// @brief create the transaction collection //////////////////////////////////////////////////////////////////////////////// Collection (TRI_vocbase_col_t*, Collection::AccessType, bool, bool); //////////////////////////////////////////////////////////////////////////////// /// @brief destroy the transaction collection //////////////////////////////////////////////////////////////////////////////// ~Collection (); // ----------------------------------------------------------------------------- // --SECTION-- public methods // ----------------------------------------------------------------------------- public: //////////////////////////////////////////////////////////////////////////////// /// @brief collection id //////////////////////////////////////////////////////////////////////////////// inline TRI_voc_cid_t id () const { return _collection->_cid; } //////////////////////////////////////////////////////////////////////////////// /// @brief database id //////////////////////////////////////////////////////////////////////////////// inline TRI_voc_tick_t databaseId () const { return _collection->_vocbase->_id; } //////////////////////////////////////////////////////////////////////////////// /// @brief whether or not write access is allowed //////////////////////////////////////////////////////////////////////////////// inline bool allowWriteAccess () const { return _accessType == AccessType::WRITE; } //////////////////////////////////////////////////////////////////////////////// /// @brief whether or not the collection is currently locked //////////////////////////////////////////////////////////////////////////////// inline bool isLocked () const { return _locked; } //////////////////////////////////////////////////////////////////////////////// /// @brief whether or not we are responsible for locking and using //////////////////////////////////////////////////////////////////////////////// inline bool hasResponsibility () const { return _responsibility; } //////////////////////////////////////////////////////////////////////////////// /// @brief return the pointer to the primary collection //////////////////////////////////////////////////////////////////////////////// inline TRI_primary_collection_t* primary () const { return _collection->_collection; } //////////////////////////////////////////////////////////////////////////////// /// @brief generate a new revision //////////////////////////////////////////////////////////////////////////////// TRI_voc_tick_t generateRevision (); //////////////////////////////////////////////////////////////////////////////// /// @brief create a new key //////////////////////////////////////////////////////////////////////////////// std::string generateKey (TRI_voc_tick_t); //////////////////////////////////////////////////////////////////////////////// /// @brief validate a key //////////////////////////////////////////////////////////////////////////////// void validateKey (std::string const&); //////////////////////////////////////////////////////////////////////////////// /// @brief finalise usage of the collection //////////////////////////////////////////////////////////////////////////////// int done (); //////////////////////////////////////////////////////////////////////////////// /// @brief use the collection //////////////////////////////////////////////////////////////////////////////// int use (); //////////////////////////////////////////////////////////////////////////////// /// @brief unuse the collection //////////////////////////////////////////////////////////////////////////////// int unuse (); //////////////////////////////////////////////////////////////////////////////// /// @brief lock the collection //////////////////////////////////////////////////////////////////////////////// int lock (); //////////////////////////////////////////////////////////////////////////////// /// @brief unlock the collection //////////////////////////////////////////////////////////////////////////////// int unlock (); // ----------------------------------------------------------------------------- // --SECTION-- private methods // ----------------------------------------------------------------------------- private: // ----------------------------------------------------------------------------- // --SECTION-- private variables // ----------------------------------------------------------------------------- private: //////////////////////////////////////////////////////////////////////////////// /// @brief the pointer to the vocbase collection //////////////////////////////////////////////////////////////////////////////// TRI_vocbase_col_t* _collection; //////////////////////////////////////////////////////////////////////////////// /// @brief initial revision of the collection //////////////////////////////////////////////////////////////////////////////// TRI_voc_rid_t _initialRevision; //////////////////////////////////////////////////////////////////////////////// /// @brief access type for the collection //////////////////////////////////////////////////////////////////////////////// Collection::AccessType const _accessType; //////////////////////////////////////////////////////////////////////////////// /// @brief are we responsible for using / locking ourselves? //////////////////////////////////////////////////////////////////////////////// bool const _responsibility; //////////////////////////////////////////////////////////////////////////////// /// @brief whether or not the collection is currently locked //////////////////////////////////////////////////////////////////////////////// bool _locked; //////////////////////////////////////////////////////////////////////////////// /// @brief whether or not we have used the collection //////////////////////////////////////////////////////////////////////////////// bool _used; }; } } #endif // Local Variables: // mode: outline-minor // outline-regexp: "/// @brief\\|/// {@inheritDoc}\\|/// @addtogroup\\|/// @page\\|// --SECTION--\\|/// @\\}" // End: