Resource.hh

00001 //********************************************************************
00002 //*** ResourcePool/SQL/Resource.hh
00003 //*** Copyright (c) 2003-2009 by Markus Winand <mws@fatalmind.com>
00004 //*** $Id: Resource.hh,v 1.10 2009-03-02 14:16:45 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_RESOURCE_HH
00025 #define RESOURCEPOOL_SQL_RESOURCE_HH
00026 
00027 #include "mm/gc_ptr.hh"
00028 
00029 #include "ResourcePool/Resource.hh"
00030 #include "ResourcePool/Command.hh"
00031 #include "ResourcePool/SQL/ResourcePoolFwd.hh"
00032 
00033 #include <string>
00034 
00035 namespace fatalmind {
00036 namespace SQL {
00037 
00038 /*
00039  * A Resource implementation to access SQL databases.
00040  */
00041 template<class TM>
00042 class SQLResource
00043 : public fatalmind::Resource
00044 {
00045     public:
00046         SQLResource();
00047         virtual ~SQLResource();
00048 
00049         virtual bool precheck() = 0;
00050         virtual bool postcheck() = 0;
00051         virtual void close() = 0;
00052         virtual void fail_close() = 0;
00053 
00054         SQLResource<TM>& get_plain_resource() {
00055             return *this;
00056         };
00057 
00058         /*
00059          * Returns a string describing the identiy of the database session.
00060          * Intended for human usage to perform administrative actions upon the session.
00061          */
00062         virtual const std::string& getSessionID() const = 0;
00063 };
00064 
00065 template<class TM>
00066 class DummySQLResource: public SQLResource<TM> {
00067     public:
00068         DummySQLResource();
00069 };
00070 
00071 template<class TM, class RT>
00072 class SQLResourceSpecialized
00073 : public DummySQLResource<TM>
00074 {
00075         typedef gc_ptr<RT> ptr_t;
00076     public:
00077         SQLResourceSpecialized(RT* a_resource);
00078         SQLResourceSpecialized(RT& a_resource);
00079 
00080         virtual ~SQLResourceSpecialized();
00081 
00082         virtual bool precheck();
00083         virtual bool postcheck();
00084         virtual void close();
00085         virtual void fail_close();
00086         
00087         RT& getRealResource() const {
00088             return resource_ref;
00089         };      
00090             
00091         const std::string& getSessionID() const;
00092         const std::string& getResourceID() const;
00093 
00094     private:
00095         ptr_t resource_;
00096         RT&   resource_ref;
00097 };
00098 
00099 } // namespace SQL
00100 } // namespace fatalmind
00101 
00102 #endif

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