SQLSelectRow.hh

00001 //********************************************************************
00002 //*** ResourcePool/oracle/SQLSelectRow.hh
00003 //*** Copyright (c) 2003-2009 by Markus Winand <mws@fatalmind.com>
00004 //*** $Id: SQLSelectRow.hh,v 1.46 2009-05-10 16:39: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_ORACLE_SQLSELECTROW_HH
00025 #define RESOURCEPOOL_ORACLE_SQLSELECTROW_HH
00026 
00027 #include "mm/gc_ptr.hh"
00028 
00029 #include "CommandCommon.hh"
00030 #include "ResourceFwd.hh"
00031 
00032 #include "ResourcePool/SQL/BindOut.hh"
00033 #include "ResourcePool/SQL/SQLFetcher.hh"
00034 #include "ResourcePool/SQL/SQLSelect.hh"
00035 #include "ResourcePool/SQL/SQLStatement.hh"
00036 
00037 #include "oracleRefTypeFwd.hh"
00038 
00039 #include <string>
00040 
00041 namespace fatalmind {
00042 namespace oracle {
00043 
00044 // TODO: forward decl...
00045 class SelectListMetaData;
00046 class SelectListBuffer;
00047 namespace internal {
00048 
00049 class registerFinish;
00050 }
00051 
00055 class oracleBindOut
00056 : public SQL::BindOut<oracleRefType, oracleRefTypeImpl>
00057 {
00058     protected:
00059         ~oracleBindOut();
00060 
00061         void _done();
00062         void _start();
00063         void real_bindout(oracleHandles&, const OCIStatementHandle&, const SQL::SQLStatement&);
00064 
00065         bool fetch(oracleHandles&, const OCIStatementHandle&, const SQL::SQLStatement&);
00066         bool _fetch(oracleHandles&, const OCIStatementHandle&, const SQL::SQLStatement&);
00067         void finish(oracleHandles&, const OCIStatementHandle&, const SQL::SQLStatement&);
00068 
00069         gc_ptr<SelectListMetaData> _slmd;
00070         gc_ptr<SelectListBuffer> _slb;
00071 
00072         void validateBindOut(const SQL::SQLStatement& SQL) const;
00073 
00074     friend 
00075         class SelectListBuffer; 
00076     friend
00077         class internal::registerFinish;
00078 };
00079 
00083 template<class TM, template<class> class SLMDC>
00084 class SQLSelectRow
00085 : public CommandCommon<TM, SLMDC>
00086 , public oracleBindOut 
00087 , public fatalmind::SQLSelect
00088 {
00089         typedef CommandCommon<TM, SLMDC> super;
00090     protected:
00091         using super::_SQL;
00092         using oracleBindOut::_slb;
00093     public:
00094 
00095         SQLSelectRow(const SQL::SQLStatement& SQL, SQL::SQLFetcher& = SQL::NopFetcher);
00096         SQLSelectRow(const ResourcePool<ResourceType<TM> >& p, const SQL::SQLStatement& SQL, SQL::SQLFetcher& = SQL::NopFetcher);
00097         virtual ~SQLSelectRow();
00098 
00099         using super::execute;
00100 
00101     protected:
00102         virtual Clone* DoClone() const;
00103         void _execute(oracleResource<TM>&, StatementCache&);
00104 
00105         void postSelectBuffer(oracleResource<TM>&, OCIStatementHandle& sth);
00106         inline void preSelectBuffer(oracleResource<TM>&);
00107         inline void preSelectBufferBind(oracleHandles&, OCIStatementHandle& sth);
00108         inline StatementCache::handle_t prepare_buffer(oracleResource<TM>& hand, StatementCache& sthcache);
00109         StatementCache::handle_t prepareForSelect(oracleResource<TM>& hand, StatementCache& sthcache);
00110         
00111 
00112         virtual const std::string& getCommandName() const;
00113         static const std::string _SQLSelectRowName;
00114 };
00115 
00116 namespace internal {
00117 // the best way to make a class really private ;)
00118 class registerFinish {
00119     public:
00120         registerFinish(oracleHandles& hand, oracleBindOut& cmd, const OCIStatementHandle& sth, const SQL::SQLStatement& SQL)
00121         : _hand(hand)
00122         , _sth(sth)
00123         , _SQL(SQL)
00124         , _cmd(cmd)
00125         {
00126         }
00127         ~registerFinish() {
00128             _cmd.finish(_hand, _sth, _SQL);
00129         };
00130     private:
00131         oracleHandles& _hand;
00132         const OCIStatementHandle &_sth;
00133         const SQL::SQLStatement& _SQL;
00134         
00135         oracleBindOut&  _cmd;
00136 };
00137 
00138 } // namespace internal
00139 } // namespace oracle
00140 } // namespace fatalmind
00141 #endif

Generated on Mon Nov 9 16:21:24 2009 for ResourcePool by  doxygen 1.5.3