ResourcePool.hh

00001 //********************************************************************
00002 //*** ResourcePool/SQL/ResourcePool.hh
00003 //*** Copyright (c) 2003-2009 by Markus Winand <mws@fatalmind.com>
00004 //*** $Id: ResourcePool.hh,v 1.18 2009-03-23 09: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_SQL_RESOURCEPOOL_HH
00025 #define RESOURCEPOOL_SQL_RESOURCEPOOL_HH
00026 
00027 #include "ResourcePool/ResourcePoolType.hh"
00028 #include "ResourcePool/IgnoreExceptionCommand.hh"
00029 #include "ResourcePool/SQL/Factory.hh"
00030 #include "ResourcePool/SQL/Resource.hh"
00031 
00032 #include "ResourcePool/SQL/RTSQLExecute.hh"
00033 #include "ResourcePool/SQL/RTSQLSelectRow.hh"
00034 #include "ResourcePool/SQL/RTSQLSelect.hh"
00035 #include "ResourcePool/SQL/RTSQLTransaction.hh"
00036 #include "ResourcePool/SQL/RTSQLBatch.hh"
00037 
00038 namespace fatalmind {
00039 /*
00040  * the fatalmind::SQL namespace serves two requirements:
00041  * - it includes the runtime selectable SQL resource type
00042  * - it includes code common to all SQL resource types
00043  */
00044 namespace SQL {
00045 
00046 template<class TM>
00047 struct Commands;
00048 
00052 template<class TM>
00053 class ResourceType
00054 : public fatalmind::PoolType<SQLFactory<TM> 
00055     , DummySQLResource<TM>
00056     , SQLResource<TM> // plain resource
00057     , Commands<TM>
00058     , TM>
00059 {
00060 };
00061 
00062 template<class TM>
00063 struct Commands {
00064     Commands(const SQLFactory<TM>& f) 
00065     : type_(f.getDatabaseType())
00066     {
00067     };
00068 
00069     CommandParameters<TM> SQL(const std::string& sql) {
00070         CommandParameters<TM> cp(type_, sql);
00071         return cp;
00072     }
00073     
00074     typedef Command<ResourceType<TM> >   Base;
00075     typedef RTSQLExecute<TM>   SQLExecute;
00076     typedef RTSQLSelect<TM>    SQLSelect;
00077     typedef RTSQLSelectRow<TM> SQLSelectRow;
00078     typedef RTSQLBatch<TM>     SQLBatch;
00079     typedef RTSQLTransaction<TM>  Transaction;
00080     typedef fatalmind::IgnoreExceptionCommand<RTSQLExecute<TM> >  IgnoreException;
00081     private:
00082         const typename SQLFactory<TM>::databaseType_t type_;
00083 };
00084 
00085 } // namespace SQL
00086 
00087 namespace ResourceType {
00088 
00089 typedef SQL::ResourceType<DefaultThreadedModel > SQL;
00090 typedef SQL::ResourceType<SingleThreadedModel<> > SQLST;
00091 typedef SQL::ResourceType<MultiThreadedModel<> > SQLMT;
00092 
00093 } // namespace ResourceType
00094 } // namespace fatalmind
00095 
00096 #endif

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