00001 // $Id: TDbiValRecSet.cxx,v 1.1 2011/01/18 05:49:20 finch Exp $ 00002 00003 #include "TDbiDBProxy.hxx" 00004 #include "TDbiResultSetNonAgg.hxx" 00005 #include "TDbiInRowStream.hxx" 00006 #include "TDbiTableProxy.hxx" 00007 #include "TDbiDatabaseManager.hxx" 00008 #include "TDbiValidityRec.hxx" 00009 #include "TDbiValRecSet.hxx" 00010 #include <TSK_DBI_Log.hxx> 00011 #include <MsgFormat.h> 00012 using std::endl; 00013 00014 ClassImp(TDbiValRecSet) 00015 00016 00017 // Definition of static data members 00018 // ********************************* 00019 00020 00021 // Definition of all member functions (static or otherwise) 00022 // ******************************************************* 00023 // 00024 // - ordered: ctors, dtor, operators then in alphabetical order. 00025 00026 //..................................................................... 00027 00028 TDbiValRecSet::TDbiValRecSet(const string& tableName,UInt_t dbNo,UInt_t seqNo) : 00029 fDbNo(dbNo), 00030 fResult(0) 00031 { 00032 // 00033 // 00034 // Purpose: Constructor 00035 // 00036 // Arguments: 00037 // tableName in Table Name whose TDbiValidityRecs are required. 00038 // dbNo in Database number in the cascade. 00039 // seqNo in Just this SEQNO if >0 or all if 0 [default: 0] 00040 // 00041 // Return: n/a 00042 // 00043 // Contact: N. West 00044 // 00045 // Specification:- 00046 // ============= 00047 // 00048 // o For the required table in the required database, load every 00049 // TDbiValidityRec into TDbiResultSet. 00050 00051 00052 // Program Notes:- 00053 // ============= 00054 00055 // None. 00056 00057 00058 SK_DBI_Trace( "Creating TDbiValRecSet" << " "); 00059 00060 // Get Db proxy for the table. 00061 TDbiValidityRec pet; 00062 const TDbiDBProxy& proxy = TDbiDatabaseManager::Instance() 00063 .GetTableProxy(tableName,&pet) 00064 .GetDBProxy(); 00065 00066 // Collect up all validity records. 00067 TDbiInRowStream* rset = proxy.QueryAllValidities(dbNo,seqNo); 00068 fResult = new TDbiResultSetNonAgg(rset,&pet,0,kFALSE); 00069 delete rset; 00070 00071 00072 } 00073 00074 00075 //..................................................................... 00076 00077 TDbiValRecSet::~TDbiValRecSet() { 00078 // 00079 // 00080 // Purpose: Destructor 00081 // 00082 // Arguments: 00083 // None. 00084 // 00085 // Return: n/a 00086 // 00087 // Contact: N. West 00088 // 00089 // Specification:- 00090 // ============= 00091 // 00092 // o Destroy RowStream. 00093 00094 00095 // Program Notes:- 00096 // ============= 00097 00098 // None. 00099 00100 00101 SK_DBI_Trace( "Destroying TDbiValRecSet" << " "); 00102 delete fResult; 00103 00104 } 00105 00106 //..................................................................... 00107 00108 UInt_t TDbiValRecSet::GetNumRows() const { 00109 // 00110 // 00111 // Purpose: Return the number of rows. 00112 // 00113 // Arguments: None. 00114 // 00115 // Return: 00116 // 00117 // Contact: N. West 00118 // 00119 // Specification:- 00120 // ============= 00121 // 00122 // o Return the number of rows. 00123 00124 // Program Notes:- 00125 // ============= 00126 00127 // None. 00128 00129 return fResult ? fResult->GetNumRows() : 0; 00130 } 00131 00132 //..................................................................... 00133 00134 const string TDbiValRecSet::GetTableName() const { 00135 // 00136 // 00137 // Purpose: Return the table name. 00138 // 00139 // Arguments: None. 00140 // 00141 // Return: 00142 // 00143 // Contact: N. West 00144 // 00145 // Specification:- 00146 // ============= 00147 // 00148 // o Return the table name. 00149 00150 // Program Notes:- 00151 // ============= 00152 00153 // None. 00154 00155 return fResult ? fResult->TableName() : "Unknown"; 00156 } 00157 00158 //..................................................................... 00159 00160 const TDbiValidityRec* TDbiValRecSet::GetTableRow(UInt_t rowNum) const { 00161 // 00162 // 00163 // Purpose: Return TDbiValidityRec at supplied row number. 00164 // 00165 // Arguments: 00166 // rowNum in Row number whose entry is required or 0 if none. 00167 // 00168 // Return: 00169 // 00170 // Contact: N. West 00171 // 00172 // Specification:- 00173 // ============= 00174 // 00175 // o Return TDbiValidityRec at supplied row number. 00176 00177 // Program Notes:- 00178 // ============= 00179 00180 // None. 00181 00182 return fResult ? 00183 dynamic_cast<const TDbiValidityRec*>(fResult->GetTableRow(rowNum)) 00184 : 0; 00185 } 00186 00187 //..................................................................... 00188 00189 const TDbiValidityRec* TDbiValRecSet::GetTableRowBySeqNo(UInt_t seqNo 00190 ) const { 00191 // 00192 // 00193 // Purpose: Return TDbiValidityRec.hxxaving supplied SeqNo. 00194 // 00195 // Arguments: 00196 // seqNo in Sequence number of required entry or 0 if none. 00197 // 00198 // Return: 00199 // 00200 // Contact: N. West 00201 // 00202 // Specification:- 00203 // ============= 00204 // 00205 // o Return TDbiValidityRec at supplied row number. 00206 00207 // Program Notes:- 00208 // ============= 00209 00210 // None. 00211 00212 UInt_t numRows = GetNumRows(); 00213 if ( numRows == 0 ) return 0; 00214 00215 // Create look-up table if not yet built. 00216 00217 if ( fSeqNoToRec.size() == 0 ) { 00218 for ( UInt_t irow = 0; irow < numRows; ++irow) { 00219 const TDbiValidityRec* vrec = GetTableRow(irow); 00220 fSeqNoToRec[vrec->GetSeqNo()] = vrec; 00221 } 00222 } 00223 00224 map<UInt_t,const TDbiValidityRec*>::const_iterator itr = fSeqNoToRec.find(seqNo); 00225 return ( itr == fSeqNoToRec.end() ) ? 0 : itr->second; 00226 00227 } 00228 00229