PoolDbTupleCallback.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 #include <algorithm>
00012
00013 #include "GaudiPoolDb/PoolDbTupleCallback.h"
00014 #include "GaudiKernel/INTuple.h"
00015 #include "GaudiKernel/ISelectStatement.h"
00016
00017 #include "StorageSvc/DbType.h"
00018 #include "StorageSvc/DbSelect.h"
00019 #include "StorageSvc/DbColumn.h"
00020 #include "StorageSvc/DbTypeInfo.h"
00021 #include "StorageSvc/DbDatabase.h"
00022 #include "StorageSvc/DbInstanceCount.h"
00023
00024 static pool::DbInstanceCount::Counter* s_count =
00025 pool::DbInstanceCount::getCounter(typeid(PoolDbTupleCallback));
00026
00028 PoolDbTupleCallback::PoolDbTupleCallback(DataObject* pObj)
00029 : pool::DbDefaultDataHandler(),
00030 pool::DbObjectCallBack(0),
00031 m_iter(0), m_cntH(pool::POOL_StorageType)
00032 {
00033 m_refCount = 1;
00034 setObject(pObj);
00035 s_count->increment();
00036 }
00037
00039 PoolDbTupleCallback::~PoolDbTupleCallback()
00040 {
00041 pool::deletePtr(m_iter);
00042 s_count->decrement();
00043 const pool::DbTypeInfo* typ = (const pool::DbTypeInfo*)shape();
00044 if ( typ ) typ->deleteRef();
00045 }
00046
00048 pool::DataCallBack* PoolDbTupleCallback::clone() const
00049 {
00050 PoolDbTupleCallback* cb = const_cast<PoolDbTupleCallback*>(this);
00051 cb->m_refCount++;
00052 return cb;
00053 }
00054
00056 void PoolDbTupleCallback::release()
00057 {
00058 if ( --m_refCount <= 0 ) {
00059 delete this;
00060 }
00061 }
00062
00064 void PoolDbTupleCallback::configure(const INTuple* pTuple,
00065 const pool::DbTypeInfo* typ,
00066 const pool::DbContainer& cntH)
00067 {
00068 pool::DbTypeInfo::Columns::const_iterator ic;
00069 const INTuple::ItemContainer& items = pTuple->items();
00070 const pool::DbTypeInfo::Columns& cols = typ->columns();
00071 size_t colsize = cols.size();
00072 m_map.resize(items.size()+1,-1);
00073 for(size_t item_no = 0; item_no < items.size(); ++item_no ) {
00074 int icc = 0;
00075 m_map[item_no] = -1;
00076 const std::string& itm_nam = items[item_no]->name();
00077 for (ic=cols.begin(); ic != cols.end(); ++ic, ++icc ) {
00078 if ( (*ic)->name() == itm_nam ) {
00079 m_map[item_no] = icc;
00080 break;
00081 }
00082 }
00083 }
00084 m_addr.resize(colsize);
00085 m_addr[colsize-1] = &m_stream;
00086 m_links.resize(m_map.size());
00087 m_plinks.resize(m_map.size());
00088 for(size_t i = 0; i < m_map.size(); ++i ) {
00089 m_plinks[i] = &m_links[i];
00090 }
00091 m_cntH = cntH;
00092 typ->addRef();
00093 setShape(typ);
00094 }
00095
00096 pool::DbSelect*
00097 PoolDbTupleCallback::select(ISelectStatement* sel) {
00098 pool::deletePtr(m_iter);
00099 if ( m_cntH.isValid() ) {
00100 std::string criteria = (sel && (sel->type() & ISelectStatement::STRING))
00101 ? sel->criteria() : std::string("");
00102 m_iter = new pool::DbSelect( criteria );
00103 pool::DbDatabase dbH = m_cntH.containedIn();
00104 m_iter->start(dbH, m_cntH.name());
00105 }
00106 return m_iter;
00107 }
00108
00110 pool::DbStatus
00111 PoolDbTupleCallback::start (CallType ,
00112 void* ,
00113 void** )
00114 {
00115 return pool::Success;
00116 }
00117
00119 pool::DbStatus PoolDbTupleCallback::end(CallType ,
00120 void* )
00121 {
00122 return pool::Success;
00123 }
00124
00126 pool::DbStatus
00127 PoolDbTupleCallback::bind(CallType action_type,
00128 const pool::DbColumn* ,
00129 int col_number,
00130 void* ,
00131 void** data_pointer)
00132 {
00133 switch(action_type) {
00134 case GET:
00135 *data_pointer = m_addr[col_number];
00136 break;
00137 case PUT:
00138 *data_pointer = m_addr[col_number];
00139 break;
00140 }
00141 return pool::Success;
00142 }
00143