SelectListMetaData.hh

00001 //********************************************************************
00002 //*** ResourcePool/oracle/SelectListMetaData.hh
00003 //*** Copyright (c) 2003-2009 by Markus Winand <mws@fatalmind.com>
00004 //*** $Id: SelectListMetaData.hh,v 1.19 2009-03-18 08:21:01 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_SELECTLISTMETADATA_HH
00025 #define RESOURCEPOOL_ORACLE_SELECTLISTMETADATA_HH
00026 
00027 #ifndef OCI_ORACLE
00028 #include <oci.h>
00029 #endif
00030 
00031 #ifndef RESOURCEPOOL_ORACLE_ORACLEREFTYPE_HH
00032 #include "oracleRefType.hh"
00033 #endif
00034 
00035 #ifndef RESOURCEPOOL_ORACLE_SQLSELECTROW_HH
00036 #include "SQLSelectRow.hh"
00037 #endif
00038 
00039 #ifndef RESOURCEPOOL_ORACLE_ORACLESTATEMENT_HH
00040 #include "oracleStatement.hh"
00041 #endif
00042 
00043 #include "mm/RawBuffer.hh"
00044 
00045 #include <vector>
00046 #include <string>
00047 #include <ostream>
00048 
00049 namespace fatalmind {
00050 namespace oracle {
00051 
00052 class ColumnMetaData {
00053     public:
00054         ColumnMetaData(const size_t offst); // for usag in std containers
00055         //ColumnMetaData(const ub2 datatype, const ub2 datasize);
00056         ColumnMetaData(const ColumnMetaData& rho);
00057 
00058         ub2 getType() const throw();
00059         ub2 getSize() const throw();
00060         size_t getOffset() const throw();
00061         bool bufferedDefine() const throw();
00062 
00063         /*
00064          * @returns true if the specified oracle type needs to be fetched via the buffer.
00065          *          false if it can be directly fetched into the users variable
00066          */
00067         static bool needsBuffer(ub2) throw();
00068         bool piecewise() const throw();
00069 
00070     private:
00071         const ub2* getTypePtr() const throw();
00072         const ub2* getSizePtr() const throw();
00073         void alignSize() throw();
00074         void setSize(ub2 s) throw();
00075 
00076         ub2 _datatype;
00077         ub2 _datasize;
00078         size_t _offst;
00079     friend
00080         class SelectListMetaData;
00081     friend
00082         std::ostream& operator<<(std::ostream& s, const ColumnMetaData& rho);   
00083 };
00084 
00085 std::ostream& operator<<(std::ostream& s, const ColumnMetaData& rho);   
00086 
00087 class SelectListMetaData {
00088     public:
00089         SelectListMetaData(const OCIStatementHandle& sth
00090             , const oracleHandles& hand
00091             , const oracleStatement& SQL
00092         );
00093 
00094         size_t getBufferSz() const throw();
00095         int getNumSelectListItems() const;
00096         const ColumnMetaData& getColumnMetaData(const int pos) const;
00097         const oracleStatement& getOraSQL() const;
00098 
00099     private:
00100         typedef std::vector<ColumnMetaData> selectlist_t;
00101         selectlist_t _selectlist;
00102         oracleStatement _oraSQL;
00103         size_t _bufsz;
00104     friend
00105         std::ostream& operator<<(std::ostream& s, const SelectListMetaData& rho);
00106 };
00107 
00108 std::ostream& operator<<(std::ostream& s, const SelectListMetaData& rho);
00109 
00110 /*
00111  * this class will be used to provide OCI with the
00112  * indicator variable and the place to store the actual size
00113  * it's placement constructed into the memory managed by
00114  * SelectListBuffer
00115  * in fact it's just a pattern for the memory
00116  * 
00117  * Note: the actually used indicator variable is in the oracleRefType
00118  *       the indicator Variable managed by this class is used only in
00119  *       case of piecewise fetch (e.g. for LOBS) and just provides 
00120  *       the actual poiner to the indicator variable in the 
00121  *       oracleRefType class
00122  */
00123 class DefineMetaData {
00124     public:
00125         DefineMetaData(const ub2 bufsz, oracleRefType& out) 
00126         : _bufsz(bufsz)
00127         , _out(out)
00128         , _dataPtr(this + 1)
00129         {
00130         }
00131 
00132         ub2* getSizePtr_ub2() throw() {
00133             return &s._size_ub2;
00134         }
00135 
00136         ub4* getSizePtr_ub4() throw() {
00137             return &s._size_ub4;
00138         }
00139 
00140         void* getDataPtr() throw() {
00141             return _dataPtr;
00142         }
00143 
00144         void resetSize() throw() {
00145             s._size_ub4 = _bufsz;
00146         }
00147 
00148         ub2 getSize_ub2() const throw() {
00149             return s._size_ub2;
00150         }   
00151 
00152         ub4 getSize_ub4() const throw() {
00153             return s._size_ub4;
00154         }   
00155 
00156         void done(ub4 len, void* buf) {
00157             _out.done(len, buf);
00158         }
00159 
00160         void setIndPtr(sb2* ind) {
00161             _ind = ind;
00162         }
00163         sb2* getIndPtr() const {
00164             return _ind;
00165         }
00166     private:
00167         //
00168         // Oracle uses two different types to describe the size of the buffer
00169         // and the actually written data:
00170         //   ub2 -> for non piecewise fetch
00171         //   ub4 -> for piecewise fetch
00172         // this class provides both, buth the user (of this class)
00173         // has to make sure to use the right functions.
00174         union size_union {
00175             ub2 _size_ub2;
00176             ub4 _size_ub4;
00177         } s;
00178         ub4 _bufsz;
00179         sb2* _ind;
00180         oracleRefType& _out;
00181         void* _dataPtr;
00182 };
00183 
00184 class SelectListBuffer: private RawBuffer {
00185     public:
00186         SelectListBuffer(const gc_ptr<SelectListMetaData> slmd, oracleBindOut& bindout);
00187         ~SelectListBuffer();
00188 
00189         int getNumSelectListItems() const;
00190         DefineMetaData* getDefineMetaData(const int pos) const;
00191         void* getDataPtr(const int pos) const;
00192         bool bufferedDefine(const int pos) const;
00193         bool piecewiseFetch(const int pos) const;
00194         
00195     private:
00196         const gc_ptr<SelectListMetaData> _slmd;     
00197 };
00198 
00199 
00200 } // namespace oracle
00201 } // namespace fatalmind
00202 #endif

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