OracleExceptionFactory.hh

00001 //********************************************************************
00002 //*** ResourcePool/oracle/OracleExceptionFactory.hh
00003 //*** Copyright (c) 2003-2009 by Markus Winand <mws@fatalmind.com>
00004 //*** $Id: OracleExceptionFactory.hh,v 1.17 2009-03-17 18:06:29 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 // TODO - move into fatalmind::oracle namespace
00025 
00026 #ifndef RESOURCEPOOL_ORACLE_ORACLEEXCEPTIONFACTORY_HH
00027 #define RESOURCEPOOL_ORACLE_ORACLEEXCEPTIONFACTORY_HH
00028 
00029 #ifndef RESOURCEPOOL_ORACLE_ORACLEEXCEPTION_HH
00030 #include "OracleException.hh"
00031 #endif
00032 
00033 #ifndef RESOURCEPOOL_ORACLE_OCIHANDLE_HH
00034 #include "OCIHandle.hh"
00035 #endif
00036 
00037 #include "ResourcePool/SQL/SQLStatement.hh"
00038 
00039 #include <sstream>
00040 
00041 namespace fatalmind {
00042 
00043 class OracleExceptionFactory {
00044     public:
00045         // TODO: i think some of them never have a meaningfull
00046         // sqlstm, those should not take the sqlstm argument
00047         // and default it to "N/A"
00048         static void throwit(const std::string& op
00049             , const std::string& fac
00050             , const int errornumber
00051             , const std::string& msg
00052             , const SQL::SQLStatement& sqlstm
00053         );
00054         static void throwit(
00055               const std::string& op
00056             , const oracle::OCIEnvHandle& env
00057             , sword ret
00058             , const SQL::SQLStatement& sqlstm
00059         );
00060         static void throwit(
00061               const std::string& op
00062             , const oracle::OCIErrorHandle& err
00063             , sword ret
00064             , const SQL::SQLStatement& sqlstm
00065         );
00066         static void throwit(
00067               const std::string& op
00068             , const oracleHandles&
00069             , sword ret
00070             , const SQL::SQLStatement& sqlstm
00071         );
00072         
00073     // TODO
00074     //private:
00075         static void throwit(const std::string& oper
00076             , const dvoid* errhp
00077             , sword ret
00078             , ub4 type
00079             , const SQL::SQLStatement& sqlstm
00080         );
00081 
00089         OracleExceptionFactory(
00090               const std::string& oper
00091             , const dvoid* errhp
00092             , sword ret
00093             , ub4 type
00094             , const SQL::SQLStatement& sqlstm
00095         );
00096 
00097         OracleExceptionFactory(
00098               const std::string& op
00099             , const OCIError* errhp
00100             , sword ret
00101             , const SQL::SQLStatement& sqlstm
00102         );
00103 
00104         // returns the string provided by OCI to describe the errro
00105         const std::string getErrorString() const;
00106         
00107         // returns the code (typically ORA-xxxxx) of the error
00108         // returns a ref to a member !
00109         const std::string& getErrorCode() const {
00110             return errorcode;
00111         };
00112 
00113         int getErrorNumber() const {
00114             return errornumber;
00115         }
00116 
00117     
00118         void throwit() const;
00119 
00120     private:
00121         void setFromOCI(const std::string& oper, const dvoid* errhp, ub4 type, sword ret);
00122         static inline std::string setErrorCode(int errorcode);
00123 
00124         std::string state;
00125         std::string msg;
00126         SQL::SQLStatement sqlstm;
00127         int         errornumber;
00128         std::string errorcode; // the ORA-99999 part of it (without details)
00129 };
00130 
00131 } // namespace fatalmind
00132 
00133 #endif

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