00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #ifndef RESOURCEPOOL_MYSQL_RESOURCE_HH
00026 #define RESOURCEPOOL_MYSQL_RESOURCE_HH
00027
00028 #ifndef RESOURCEPOOL_MYSQL_MYSQLFWD_HH
00029 #include "mysqlFwd.hh"
00030 #endif
00031
00032 #include <string>
00033
00034 namespace fatalmind {
00035 namespace mysql {
00036 class FinallyTxDepth;
00037 };
00038
00039 class mysqlResource {
00040 public:
00041 mysqlResource(const std::string& host
00042 , const std::string& user
00043 , const std::string& pass
00044 , const std::string& db
00045 , unsigned int port = 3306
00046 , const std::string& sock = ""
00047 );
00048 ~mysqlResource();
00049 bool precheck();
00050 bool postcheck();
00051 void close();
00052 void fail_close();
00053 MYSQL& get_plain_resource();
00054
00055 int getTxDepth() {
00056 return _txDepth;
00057 }
00058
00059 std::string getSessionID() const;
00060 private:
00061 MYSQL* _dbh;
00062
00063 int _txDepth;
00064 int incTxDepth() {
00065 return _txDepth++;
00066 }
00067 void decTxDepth() {
00068 --_txDepth;
00069 }
00070
00071 friend class mysql::FinallyTxDepth;
00072 };
00073
00074 namespace mysql {
00075
00076 class FinallyTxDepth {
00077 public:
00078 FinallyTxDepth(mysqlResource& a_hand)
00079 : hand(a_hand)
00080 {
00081 hand.incTxDepth();
00082 }
00083
00084 ~FinallyTxDepth() {
00085 hand.decTxDepth();
00086 }
00087 private:
00088 mysqlResource& hand;
00089 };
00090 };
00091
00092 }
00093 #endif