OCIHandle.hh

00001 //********************************************************************
00002 //*** ResourcePool/oracle/OCIHandle.hh
00003 //*** Copyright (c) 2003-2009 by Markus Winand <mws@fatalmind.com>
00004 //*** $Id: OCIHandle.hh,v 1.24 2009-03-18 07:35:10 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_OCIHANDLE_HH
00025 #define RESOURCEPOOL_ORACLE_OCIHANDLE_HH
00026 
00027 #ifndef RESOURCEPOOL_ORACLE_OCIENVHANDLE_HH
00028 #include "OCIEnvHandle.hh"
00029 #endif
00030 
00031 #ifndef RESOURCEPOOL_ORACLE_RESOURCEFWD_HH
00032 #include "ResourceFwd.hh"
00033 #endif
00034 
00035 #ifndef RESOURCEPOOL_ORACLE_ORACLESTATEMENT_HH
00036 #include "oracleStatement.hh"
00037 #endif
00038 
00039 #ifndef OCI_ORACLE
00040 #include <oci.h>
00041 #endif
00042 
00043 #include <string>
00044 #include <memory>
00045 
00046 namespace fatalmind {
00047 namespace oracle {
00048 
00049 template<typename HTYPE, int HCONST>
00050 class OCIHandle {
00051     public:
00052         OCIHandle(const OCIEnv* env);
00053         OCIHandle(const OCIEnvHandle& env);
00054         ~OCIHandle();
00055         inline HTYPE* get() const {
00056             return  _h;
00057         };
00058     private:
00059         HTYPE* _h;
00060 };
00061 
00062 typedef oracle::OCIHandle<OCIError,   OCI_HTYPE_ERROR>   OCIErrorHandle;
00063 typedef oracle::OCIHandle<OCIServer,  OCI_HTYPE_SERVER>  OCIServerHandle;
00064 typedef oracle::OCIHandle<OCISvcCtx,  OCI_HTYPE_SVCCTX>  OCISvcCtxHandle;
00065 typedef oracle::OCIHandle<OCISession, OCI_HTYPE_SESSION> OCISessionHandle;
00066 
00067 class OCIStatementHandle {
00068     public:
00069         OCIStatementHandle(const oracleStatement&);
00070         ~OCIStatementHandle() {
00071         }
00072         bool prepare(oracleHandles&);
00073         OCIStmt* get() const {
00074             return _sth->get();
00075         }
00076         unsigned int getEfficienty() const;
00077 
00078         std::string getOraSQL() const;
00079     private:
00080         void force_prepare(oracleHandles&);
00081 
00082         oracleStatement _SQL;
00083         typedef OCIHandle<OCIStmt, OCI_HTYPE_STMT> Stmt_t;
00084         std::auto_ptr<Stmt_t> _sth;
00085 
00086         unsigned int _prepare;
00087         unsigned int _force_prepare;
00088 
00095         bool isCacheable(oracleHandles&) const;
00096 
00097     friend
00098         std::ostream& operator<<(std::ostream& s, const OCIStatementHandle&);
00099 };
00100 
00101 std::ostream& operator<<(std::ostream& s, const OCIStatementHandle&);
00102 
00103 } // namespace oracle
00104 } // namespace fatalmind
00105 #endif

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