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_SQL_RTSQLTRANSACTION_IMPL_HH
00025 #define RESOURCEPOOL_SQL_RTSQLTRANSACTION_IMPL_HH
00026
00027 #include "config.h"
00028 #include "util/Clone.hh"
00029
00030 #include "ResourcePool/SQL/Factory.hh"
00031
00032 #ifdef RESOURCEPOOL_HAVE_MYSQL_TRANSACTIONS
00033 #include "ResourcePool/mysql/ResourcePool.hh"
00034 #endif
00035
00036 #ifdef RESOURCEPOOL_HAVE_ORACLE
00037 #include "ResourcePool/oracle/ResourcePool.hh"
00038 #include "ResourcePool/oracle/Resource.hh"
00039 #include "ResourcePool/oracle/oracleType.hh"
00040 #endif
00041
00042
00043 #include <sstream>
00044
00045 namespace fatalmind {
00046 namespace SQL {
00047
00048 template<class TM>
00049 class RTSQLTransaction_Impl: public Clone {
00050 public:
00051 RTSQLTransaction_Impl() {
00052 };
00053 virtual ~RTSQLTransaction_Impl() {
00054 }
00055
00056 virtual void execute(SQLResource<TM>& hand) = 0;
00057
00058 template<class CS>
00059 static typename CS::Impl* newRealCommand(
00060 typename SQLFactory<TM>::databaseType_t a_type
00061 , typename CS::RTC& a_that
00062 , const typename CS::RTC::innercommand_t& a_cmd
00063 ) {
00064 switch(a_type) {
00065 #ifdef RESOURCEPOOL_HAVE_MYSQL
00066 case SQLFactory<TM>::MYSQLTX :
00067 #ifdef RESOURCEPOOL_HAVE_MYSQL_TRANSACTIONS
00068 return new typename CS::template Specialized<fatalmind::ResourceType::mysql>::Impl(a_that, a_cmd);
00069 #else
00070 throw Exception("This version of ResourcePool was not build with mysql transaction support");
00071 #endif
00072 break;
00073 case SQLFactory<TM>::MYSQL :
00074
00075 throw Exception("This version of ResourcePool was not build with mysql transaction support");
00076 break;
00077 #endif
00078 #ifdef RESOURCEPOOL_HAVE_ORACLE
00079 case SQLFactory<TM>::OCI:
00080 return new typename CS::template Specialized<fatalmind::ResourceType::oracle>::Impl(a_that, a_cmd);
00081 break;
00082 #endif
00083 default:
00084 std::ostringstream oss;
00085 oss << "Assertaion failure (type=" << a_type << ")";
00086 throw Exception(oss.str());
00087 break;
00088 }
00089 }
00090 };
00091
00092 template<class TM, template<class TM2>class B, class RT, class CW, class RTC>
00093 class RTSQLTransaction_SpecializedImplCloneHelper
00094 {
00095 public:
00096 static Clone* DoClone(const Clone * const that) {
00097 throw CloneException(that);
00098 }
00099 };
00100
00101
00102 template<class TM, template<class TM2>class B, class RT, class CW, class RTC>
00103 class RTSQLTransaction_SpecializedImpl ;
00104
00105 template<class TM, class RT, class CW, class RTC>
00106 class RTSQLTransaction_SpecializedImplCloneHelper<TM, RTSQLTransaction_Impl, RT, CW, RTC>
00107 {
00108 public:
00109 typedef RTSQLTransaction_SpecializedImpl<TM, RTSQLTransaction_Impl, RT, CW, RTC> target;
00110 static Clone* DoClone(const Clone *const that) {
00111 const target *x = dynamic_cast<const target*>(that);
00112 return new target(*x);
00113 }
00114 };
00115
00116
00117 template<class TM, template<class TM2>class B, class RT, class CW, class RTC>
00118 class RTSQLTransaction_SpecializedImpl
00119 : public B<TM>
00120 {
00121 public:
00122 RTSQLTransaction_SpecializedImpl(RTC& rtc, const typename RTC::innercommand_t& cmd)
00123 : sqlTransaction_(rtc, cmd)
00124 {
00125 }
00126
00127 virtual void execute(SQLResource<TM>& hand) {
00128 sqlTransaction_.execute(
00129 dynamic_cast<
00130 SQLResourceSpecialized<TM, typename RT::resource_t>&
00131 >(hand).getRealResource()
00132 );
00133 }
00134
00135 protected:
00136 virtual Clone* DoClone() const {
00137 return RTSQLTransaction_SpecializedImplCloneHelper<TM, B, RT, CW, RTC>::DoClone(this);
00138 }
00139
00140 CW sqlTransaction_;
00141 };
00142
00143
00144 }
00145 }
00146
00147 #endif