00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #ifndef RESOURCEPOOL_ORACLE_RESOURCE_HH
00025 #define RESOURCEPOOL_ORACLE_RESOURCE_HH
00026
00027
00028 void TEST_oracle_resource_two();
00029
00030 #ifndef RESOURCEPOOL_CREATEEXCEPTION_HH
00031 #include "ResourcePool/CreateException.hh"
00032 #endif
00033
00034 #include "ResourceFwd.hh"
00035
00036 #ifndef RESOURCEPOOL_ORACLE_ORACLEEXCEPTION_HH
00037 #include "OracleException.hh"
00038 #endif
00039
00040 #ifndef RESOURCEPOOL_ORACLE_OCIHANDLE_HH
00041 #include "OCIHandle.hh"
00042 #endif
00043
00044 #ifndef RESOURCEPOOL_ORACLE_OCIENVHANDLEFWD_HH
00045 #include "OCIEnvHandleFwd.hh"
00046 #endif
00047
00048 #ifndef RESOURCEPOOL_ORACLE_STATEMENTCACHE_HH
00049 #include "StatementCache.hh"
00050 #endif
00051
00052 #ifndef RESOURCEPOOL_ORACLE_SELECTLISTMETADATA_HH
00053 #include "SelectListMetaData.hh"
00054 #endif
00055
00056
00057 #include "Transaction.hh"
00058
00059 #ifndef OCI_ORACLE
00060 #include <oci.h>
00061 #endif
00062
00063 #include <string>
00064
00065 namespace fatalmind {
00066
00067 namespace oracle {
00068
00069 template<class TM>
00070 class FinallyTxDepth {
00071 public:
00072 FinallyTxDepth(oracleHandlesWithCache<TM>& a_hand)
00073 : hand(a_hand)
00074 {
00075 hand.incTxDepth();
00076 }
00077
00078 ~FinallyTxDepth() {
00079 hand.decTxDepth();
00080 }
00081 private:
00082 oracleHandlesWithCache<TM>& hand;
00083 };
00084
00085 };
00086
00087 class oracleHandles {
00088 public:
00089 oracleHandles(const oracle::OCIEnvHandle& env
00090 ):_env(env)
00091 , _err(_env)
00092 , _srv(_env)
00093 , _svc(_env)
00094 , _ses(_env)
00095 , _txDepth(0)
00096 {
00097 }
00098
00099 virtual ~oracleHandles() {
00100 }
00101
00102 OCIEnv* getEnv() const {
00103 return _env.get();
00104 }
00105
00106 inline OCIError* getError() const {
00107 return _err.get();
00108 }
00109
00110 OCIServer* getServer() const {
00111 return _srv.get();
00112 }
00113
00114 OCISvcCtx* getSvcCtx() const {
00115 return _svc.get();
00116 }
00117
00118 OCISession* getSession() const {
00119 return _ses.get();
00120 }
00121
00122 int getTxDepth() {
00123 return _txDepth;
00124 }
00125
00126 protected:
00127 const oracle::OCIEnvHandle& _env;
00128 const oracle::OCIErrorHandle _err;
00129 const oracle::OCIServerHandle _srv;
00130 const oracle::OCISvcCtxHandle _svc;
00131 const oracle::OCISessionHandle _ses;
00132 private:
00133
00134 oracleHandles(const oracleHandles&);
00135 oracleHandles& operator=(const oracleHandles&);
00136
00137
00138 int _txDepth;
00139
00140 int incTxDepth() {
00141 return _txDepth++;
00142 }
00143 void decTxDepth() {
00144 --_txDepth;
00145 }
00146
00147 friend class oracle::FinallyTxDepth<DefaultThreadedModel>;
00148 friend void ::TEST_oracle_resource_two();
00149 };
00150
00151 template<class TM = DefaultThreadedModel >
00152 class oracleHandlesWithCache: public oracleHandles {
00153 public:
00154 oracleHandlesWithCache(const oracle::OCIEnvHandle& env
00155 , gc_ptr<typename oracle::SelectListMetaDataCacheInterface<TM>::type > slmdc
00156 ):oracleHandles(env)
00157 , _slmdc(slmdc)
00158 {
00159 }
00160 virtual ~oracleHandlesWithCache()
00161 {
00162 }
00163
00164 virtual typename oracle::SelectListMetaDataCacheInterface<TM>::type& getSelectListMetaDataCache() {
00165 return *_slmdc;
00166 }
00167
00168
00169 protected:
00170 gc_ptr<typename oracle::SelectListMetaDataCacheInterface<TM>::type, TM> _slmdc;
00171 private:
00172
00173 oracleHandlesWithCache(const oracleHandlesWithCache<TM>&);
00174 oracleHandlesWithCache& operator=(const oracleHandlesWithCache<TM>&);
00175 };
00176
00177
00178 template<class TM>
00179 class oracleResource: public oracleHandlesWithCache<TM> {
00180 public:
00181 typedef oracleHandlesWithCache<TM> super;
00182 using super::_srv;
00183 using super::_svc;
00184 using super::_ses;
00185 using super::_err;
00186 typedef typename oracle::SelectListMetaDataCacheInterface<TM>::type _slmdci_t;
00187
00188 oracleResource<TM>(const std::string& service_name
00189 , const std::string& user
00190 , const std::string& pass
00191 , const oracle::OCIEnvHandle& env
00192 , gc_ptr<_slmdci_t, TM> slmdc
00193 );
00194 ~oracleResource();
00195 bool precheck();
00196 bool postcheck();
00197 void close();
00198 void fail_close();
00199 oracleHandlesWithCache<TM>& get_plain_resource();
00200
00206 std::string getSID() const {
00207 return sid_;
00208 };
00209
00215 std::string getSerialNo() const {
00216 return serial_;
00217 };
00226 std::string getAudSID() const {
00227 return audsid_;
00228 };
00229
00230
00231
00232
00233
00234
00235
00236
00237 std::string getSessionID() const {
00238 return sessionid_;
00239 }
00240 private:
00241 std::string sid_;
00242 std::string serial_;
00243 std::string audsid_;
00244 std::string sessionid_;
00245 };
00246
00247 }
00248 #endif
00249