00001 //******************************************************************** 00002 //*** ResourcePool/SQL/ConcreteWrapper.hh 00003 //*** Copyright (c) 2003-2009 by Markus Winand <mws@fatalmind.com> 00004 //*** $Id: ConcreteWrapper.hh,v 1.6 2009-03-02 14:16:44 mws Exp $ 00005 //******************************************************************** 00006 /* 00007 This file is part of ResourcePool. 00008 00009 ResourcePool is free software; you can redistribute it 00010 and/or modify it under the terms of the GNU General Public License 00011 as published by the Free Software Foundation; either version 2 of 00012 the License, or (at your option) any later version. 00013 00014 ResourcePool is distributed in the hope that it will be 00015 useful, but WITHOUT ANY WARRANTY; without even the implied warranty 00016 of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00017 GNU General Public License for more details. 00018 00019 You should have received a copy of the GNU General Public License 00020 along with ResourcePool; if not, write to the Free Software 00021 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 00022 02111-1307 USA */ 00023 00024 #ifndef RESOURCEPOOL_SQL_CONCRETEWRAPPER_HH 00025 #define RESOURCEPOOL_SQL_CONCRETEWRAPPER_HH 00026 00027 #include "mm/gc_ptr.hh" 00028 #include "ResourcePool/SQL/Resource.hh" 00029 #include "ResourcePool/SQL/RTSQLCommand.hh" 00030 00031 namespace fatalmind { 00032 namespace SQL { 00033 00034 /* 00035 * This wrapper can be used to encapsulate a RTSQL Command 00036 * so that it can be executed by a ResourcePool for a concrete 00037 * database. 00038 * This is useful where commands itself expect child commands as 00039 * parameter (e.g. Transactions) so that i can put a RTSQL command 00040 * wrapped with this class into the transaction. 00041 */ 00042 // CPT - Concrete Pool Type (e.g. oracle, mysql, ...) 00043 // RTPT - Runtime Selectable Pool Type 00044 template<class CPT, class RTPT> 00045 class ConcreteWrapper: public Command<CPT> 00046 { 00047 public: 00048 ConcreteWrapper(const ConcreteWrapper<CPT, RTPT>& rho) 00049 : cmd_(rho.cmd_) 00050 { 00051 } 00052 ConcreteWrapper(const Command<RTPT>& cmd) 00053 : cmd_(cmd.template clone<Command<RTPT> >()) 00054 { 00055 } 00056 00057 virtual void execute(typename CPT::resource_t& r) { 00058 SQLResourceSpecialized<typename RTPT::ThreadingModell, typename CPT::resource_t> rtresource(r); 00059 cmd_->execute(rtresource); 00060 } 00061 00062 virtual gc_ptr<Command<RTPT> > unwrap(int level=1) { 00063 // TODO, level handling 00064 return cmd_; 00065 }; 00066 00067 private: 00068 virtual Clone* DoClone() const { 00069 return new ConcreteWrapper<CPT, RTPT>(*this); 00070 } 00071 00072 private: 00073 gc_ptr<Command<RTPT> > cmd_; 00074 }; 00075 00076 }; // namespace SQL 00077 }; // namespace fatalmind 00078 00079 #endif