00001 // OSB library ********************************************* -*- C++ -*- 00009 /* 00010 AUTHOR(S): Darryl Kang (dk) 00011 00012 RCS information 00013 $Name: OSB_060808 $ 00014 $Revision: 1.18 $ 00015 00016 License 00017 OSB rating and billing library for communication networks 00018 Copyright (C) 2004, 2005, 2006 OSB systems 00019 00020 This file may be distributed and/or modify under the terms of the 00021 GNU General Public License (GPL) as published by the Free Software 00022 Foundation which is provided in the file LICENSE.GPL included in the 00023 packaging of this file. 00024 00025 The file is distributed in the hope that it will be useful, but WITHOUT 00026 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 00027 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 00028 for more details. 00029 00030 Holders of a OSB Commercial License may use this file under the terms 00031 and conditions of this commercial license. 00032 */ 00033 00034 #ifndef _CONTRACTADMIN_SERVER_H_ 00035 #define _CONTRACTADMIN_SERVER_H_ 00036 00037 // ********************************************************************* 00038 // included header files 00039 // + standard includes 00040 // + libraries and external header files 00041 // + local headers 00042 00043 namespace OSB_DB { 00044 class Session; 00045 } 00046 00047 namespace OSB_LIB { 00048 class Mutex; 00049 } 00050 00051 // ***************************************************************** 00052 // Database session guards. 00053 class SessionGuardBase { 00054 static OSB_LIB::Mutex mutex_; 00055 public: 00056 SessionGuardBase(bool noWait); 00057 virtual ~SessionGuardBase() = 0; 00058 00059 protected: 00060 OSB_DB::Session& get(); 00061 00062 private: 00063 // copy and assignment not implemented 00064 SessionGuardBase(const SessionGuardBase&); 00065 SessionGuardBase& operator=(const SessionGuardBase&); 00066 00067 OSB_DB::Session* pSession_; 00068 }; 00069 00070 struct ReadSession : private SessionGuardBase { 00071 ReadSession(bool noWait) 00072 : SessionGuardBase(noWait) 00073 { 00074 } 00075 const OSB_DB::Session& get() 00076 { 00077 return SessionGuardBase::get(); 00078 } 00079 }; 00080 00081 struct WriteSession : private SessionGuardBase { 00082 WriteSession(bool noWait) 00083 : SessionGuardBase(noWait), 00084 dirty_(false) 00085 { 00086 } 00087 ~WriteSession(); 00088 const OSB_DB::Session& getConst() 00089 { 00090 return SessionGuardBase::get(); 00091 } 00092 OSB_DB::Session& get() 00093 { 00094 dirty_ = true; 00095 return SessionGuardBase::get(); 00096 } 00097 void commit(); 00098 void rollback(); 00099 private: 00100 bool dirty_; 00101 }; 00102 #endif // #ifndef _CONTRACTADMIN_SERVER_H_