1 |
afaq |
1.1 |
#include "TableTemplate.hpp"
|
2 |
|
|
#include "TableFactory.hpp"
|
3 |
|
|
#include "ObjectLayerTables.hpp"
|
4 |
|
|
#include "ObjectLayerException.hpp"
|
5 |
|
|
#include "DBException.hpp"
|
6 |
|
|
#include "NameMaper.hpp"
|
7 |
|
|
#include "Util.hpp"
|
8 |
|
|
#include "Log.hpp"
|
9 |
|
|
#include <log4cxx/logger.h>
|
10 |
|
|
#include <exception>
|
11 |
|
|
|
12 |
|
|
|
13 |
|
|
///Default constructor
|
14 |
|
|
template <class R>
|
15 |
|
|
TableTemplate<R>::TableTemplate(){
|
16 |
|
|
this->init();
|
17 |
|
|
};
|
18 |
|
|
|
19 |
|
|
|
20 |
|
|
template <class R>
|
21 |
|
|
TableTemplate<R>::~TableTemplate(){
|
22 |
|
|
for(rowIterator = rows.begin();
|
23 |
|
|
rowIterator != rows.end();
|
24 |
|
|
++rowIterator ) {
|
25 |
|
|
delete *rowIterator;
|
26 |
|
|
}
|
27 |
|
|
delete sql;
|
28 |
|
|
/*for(tivIterator = tiv.begin();
|
29 |
|
|
tivIterator != tiv.end();
|
30 |
|
|
++tivIterator ) {
|
31 |
|
|
delete *tivIterator;
|
32 |
|
|
}*/
|
33 |
|
|
|
34 |
|
|
};
|
35 |
|
|
|
36 |
|
|
template <class R>
|
37 |
|
|
TableTemplate<R>::TableTemplate(DBManagement* dbmanager){
|
38 |
|
|
this->dbmanager = dbmanager;
|
39 |
|
|
this->init();
|
40 |
|
|
};
|
41 |
|
|
|
42 |
|
|
template <class R>
|
43 |
|
|
void TableTemplate<R>::setDBManager(DBManagement* dbmanager){
|
44 |
|
|
this->dbmanager = dbmanager;
|
45 |
|
|
}
|
46 |
|
|
|
47 |
|
|
template <class R>
|
48 |
|
|
void TableTemplate<R>::addRow(RowInterface* aRow) {
|
49 |
|
|
this->rows.push_back((R*)aRow);
|
50 |
|
|
}
|
51 |
|
|
|
52 |
|
|
|
53 |
|
|
template <class R>
|
54 |
|
|
void TableTemplate<R>::addRow(R* aRow) {
|
55 |
|
|
this->rows.push_back(aRow);
|
56 |
|
|
}
|
57 |
|
|
|
58 |
|
|
template <class R>
|
59 |
|
|
string* TableTemplate<R>::getTableName(void) {
|
60 |
|
|
return this->tableName;
|
61 |
|
|
}
|
62 |
|
|
|
63 |
|
|
template <class R>
|
64 |
|
|
Dictionary* TableTemplate<R>::getSchema() {
|
65 |
|
|
cout<<"RETURNNING SCHEMA..."<<endl;
|
66 |
|
|
return this->schema;
|
67 |
|
|
}
|
68 |
|
|
|
69 |
|
|
|
70 |
|
|
|
71 |
|
|
template <class R>
|
72 |
|
|
void TableTemplate<R>::init() {
|
73 |
|
|
cout<<"initilizing......"<<endl;
|
74 |
|
|
static Log l("TableTemplate");
|
75 |
|
|
TableTemplate::logger = l.getLogger();
|
76 |
|
|
schema = this->schemaNconstraints.schemaNconstraints.getSchema();
|
77 |
|
|
constraints = this->schemaNconstraints.schemaNconstraints.getConstraints();
|
78 |
|
|
primaryKeys = this->schemaNconstraints.schemaNconstraints.getPrimaryKeys();
|
79 |
|
|
uniqueKeys = this->schemaNconstraints.schemaNconstraints.getUniqueKeys();
|
80 |
|
|
notNullKeys = this->schemaNconstraints.schemaNconstraints.getNotNullKeys();
|
81 |
|
|
refrences = this->schemaNconstraints.schemaNconstraints.getReferences();
|
82 |
|
|
multiRefrences = this->schemaNconstraints.schemaNconstraints.getMultiReferences();
|
83 |
|
|
tableName = this->schemaNconstraints.schemaNconstraints.getTableName();
|
84 |
|
|
//cout<<"table name is set now "<<*tableName<<endl;
|
85 |
|
|
//LOG4CXX_DEBUG(TableTemplate::logger, "table name is set now");
|
86 |
|
|
schemaOrder = this->schemaNconstraints.schemaNconstraints.getSchemaOrder();
|
87 |
|
|
util.setSchema(schema);
|
88 |
|
|
sql = new SQL(&util);
|
89 |
|
|
cout<<"primary keys "<<endl;
|
90 |
|
|
primaryKeysReal = util.getPrimaryKeys(schemaOrder->begin(), schemaOrder->end(), multiRefrences->begin(), multiRefrences->end());
|
91 |
|
|
cout<<"DONE initilizing......"<<endl;
|
92 |
|
|
};
|
93 |
|
|
|
94 |
|
|
|
95 |
|
|
template <class R>
|
96 |
|
|
Dictionary TableTemplate<R>::getSatisfiedRefrences(ResultSet* rs, int rowIndex) {
|
97 |
|
|
Dictionary satisfiedRefrences;
|
98 |
|
|
for(Dictionary_iter i = multiRefrences->begin(); i != multiRefrences->end(); ++i) {
|
99 |
|
|
if( (string) rs->getElement(rowIndex, rs->getColIndex(i->first)) ==
|
100 |
|
|
(string) rs->getElement(rowIndex, rs->getColIndex(i->second + "." + i->first)) ) {
|
101 |
|
|
//cout<<"Satisfied relation "<<util.getTokenAt(i->second,0)<<" is equal to "<<i->first<<" value is "<<(string) rs->getElement(rowIndex, rs->getColIndex(i->first))<<endl;
|
102 |
|
|
LOG4CXX_DEBUG(TableTemplate::logger, "Satisfied relation "+util.getTokenAt(i->second,0) + " is equal to " + i->first + " value is " + (string) rs->getElement(rowIndex, rs->getColIndex(i->first)) );
|
103 |
|
|
satisfiedRefrences.insert(Entry(util.getTokenAt(i->second,0),i->first));
|
104 |
|
|
}
|
105 |
|
|
|
106 |
|
|
}
|
107 |
|
|
return(satisfiedRefrences);
|
108 |
|
|
}
|
109 |
|
|
|
110 |
|
|
template <class R>
|
111 |
|
|
void TableTemplate<R>::convertIntoRow(ResultSet* rs, int rowIndex, R* tmpRow) {
|
112 |
|
|
Dictionary satisfiedRefrences = this->getSatisfiedRefrences(rs,rowIndex);
|
113 |
|
|
for(int colIndex = 0; colIndex < rs->getNoOfCols(); colIndex++) {
|
114 |
|
|
string name = rs->getColName(colIndex);
|
115 |
|
|
if( name.length() == 63 ) {
|
116 |
|
|
for(Dictionary_iter schemaIterator = schema->begin();
|
117 |
|
|
schemaIterator != schema->end(); schemaIterator++) {
|
118 |
|
|
string nameFromSchema = schemaIterator->first;
|
119 |
|
|
if(nameFromSchema.substr(0,63) == name) {
|
120 |
|
|
name = nameFromSchema;
|
121 |
|
|
break;
|
122 |
|
|
}
|
123 |
|
|
}
|
124 |
|
|
}
|
125 |
|
|
//if(!toSetCol(name,satisfiedRefrences)) {
|
126 |
|
|
//cout<<"toSetCol "<<endl;
|
127 |
|
|
if(!util.toSetCol(name, satisfiedRefrences.begin(), satisfiedRefrences.end())) {
|
128 |
|
|
//cout<<"toSetCol returned false for "<<name<<endl;
|
129 |
|
|
continue;
|
130 |
|
|
}
|
131 |
|
|
cout<<"trying to fetch value from ResultSet"<<endl;
|
132 |
|
|
string value = rs->getElement(rowIndex,colIndex);
|
133 |
|
|
if(value.length() == 0) {
|
134 |
|
|
continue;
|
135 |
|
|
}
|
136 |
|
|
cout<<"value is "<<value<<endl;
|
137 |
|
|
string dataType = util.getDataType(name);
|
138 |
|
|
cout<<"dataType "<<dataType;
|
139 |
|
|
util.setValue(tmpRow, name, dataType, value);
|
140 |
|
|
cout<<"after setvalue"<<endl;
|
141 |
|
|
}
|
142 |
|
|
//cout<<"returnning tmpRow"<<endl;
|
143 |
|
|
}
|
144 |
|
|
|
145 |
|
|
template <class R>
|
146 |
|
|
string TableTemplate<R>::makeSelectQuery(string userGivenWhereClause="") {
|
147 |
|
|
//cout<<"inside ::makeSelectQuery"<<endl;
|
148 |
|
|
string sqlQuery = sql->makeSelectClause(schema->begin(), schema->end()) +
|
149 |
|
|
" FROM " +
|
150 |
|
|
sql->makeTableClause(schemaOrder->begin(), schemaOrder->end());
|
151 |
|
|
string whereClause = this->makeWhereClause(userGivenWhereClause);
|
152 |
|
|
if( whereClause.length() > 0 ) {
|
153 |
|
|
sqlQuery = sqlQuery + "\nWHERE\n" + whereClause;
|
154 |
|
|
}
|
155 |
|
|
//cout<<"Query is "<<endl<<sqlQuery<<endl;
|
156 |
|
|
LOG4CXX_INFO(logger,"Query is " + sqlQuery);
|
157 |
|
|
return (sqlQuery);
|
158 |
|
|
}
|
159 |
|
|
|
160 |
|
|
|
161 |
|
|
template <class R>
|
162 |
|
|
string TableTemplate<R>::makeWhereClause(string userGivenWhereClause="") {
|
163 |
|
|
//cout<<"inside ::makeWhereClause"<<endl;
|
164 |
|
|
string whereClause = sql->makeRefClause(refrences->begin(), refrences->end()) ;
|
165 |
|
|
string whereMultiRefClause = sql->makeMultiRefClause(multiRefrences->begin(), multiRefrences->end()) ;
|
166 |
|
|
int whereClauseLen = whereClause.length();
|
167 |
|
|
if(whereClauseLen > 0) {
|
168 |
|
|
if(whereMultiRefClause.length() > 0) {
|
169 |
|
|
whereClause += " AND " + whereMultiRefClause;
|
170 |
|
|
}
|
171 |
|
|
}else if(whereMultiRefClause.length() > 0) {
|
172 |
|
|
whereClause = whereMultiRefClause;
|
173 |
|
|
}
|
174 |
|
|
if( whereClauseLen == 0 ) {
|
175 |
|
|
return(userGivenWhereClause);
|
176 |
|
|
}
|
177 |
|
|
if( userGivenWhereClause.length() > 0 ) {
|
178 |
|
|
whereClause += " AND " + userGivenWhereClause ;
|
179 |
|
|
}
|
180 |
|
|
return(whereClause);
|
181 |
|
|
}
|
182 |
|
|
|
183 |
|
|
template <class R>
|
184 |
|
|
ResultSet * TableTemplate<R>::doSelect(string query="", string whereClause="") {
|
185 |
|
|
//return query.length() == 0 ?
|
186 |
|
|
// dbmanager->executeQueryWithResults(this->makeSelectQuery(whereClause)) :
|
187 |
|
|
// dbmanager->executeQueryWithResults(query) ;
|
188 |
|
|
string tempQuery = "";
|
189 |
|
|
if( query.length() == 0 ) {
|
190 |
|
|
tempQuery = this->makeSelectQuery(whereClause);
|
191 |
|
|
} else {
|
192 |
|
|
tempQuery = query;
|
193 |
|
|
}
|
194 |
|
|
//LOG4CXX_INFO(TableTemplate::logger,"Query is " + tempQuery);
|
195 |
|
|
//cout<<"calling dbmanager->executeQueryWithResults(tempQuery)"<<endl;
|
196 |
|
|
return dbmanager->executeQueryWithResults(tempQuery) ;
|
197 |
|
|
|
198 |
|
|
}
|
199 |
|
|
|
200 |
|
|
template <class R>
|
201 |
|
|
void TableTemplate<R>::reSetColNamesInRS(ResultSet * rs) {
|
202 |
|
|
NameMaper nm;
|
203 |
|
|
for(int i = 0; i < rs->getNoOfCols(); ++i) {
|
204 |
|
|
string colName = rs->getColName(i);
|
205 |
|
|
bool found = false;
|
206 |
|
|
//for(NmIterator ni = nm.NameMap.begin(); ni != nm.NameMap.end(); ++ni) {
|
207 |
|
|
for(Dictionary_iter ni = nm.NameMap.begin(); ni != nm.NameMap.end(); ++ni) {
|
208 |
|
|
if(ni->second == colName) {
|
209 |
|
|
rs->setColName(i, ni->first);
|
210 |
|
|
found = true;
|
211 |
|
|
break;
|
212 |
|
|
}
|
213 |
|
|
}
|
214 |
|
|
if(!found) {
|
215 |
|
|
throw ObjectLayerException("Name Mater could not found key "+colName);
|
216 |
|
|
}
|
217 |
|
|
}
|
218 |
|
|
}
|
219 |
|
|
|
220 |
|
|
template <class R>
|
221 |
|
|
//vector<R*>::iterator& TableTemplate<R>::select(string whereClause=""){
|
222 |
|
|
vector<R*>& TableTemplate<R>::select(string whereClause=""){
|
223 |
|
|
//vector<RowInterface*>& TableTemplate<R>::select(string whereClause=""){
|
224 |
|
|
//TableInterface TableTemplate<R>::select(string whereClause=""){
|
225 |
|
|
bool exceptionOccured = false;
|
226 |
|
|
string exceptionMessage = "\n";
|
227 |
|
|
|
228 |
|
|
//ResultSet * rs = this->doSelect("",whereClause);
|
229 |
|
|
ResultSet * rs;
|
230 |
|
|
try {
|
231 |
|
|
rs = this->doSelect("",whereClause);
|
232 |
|
|
this->reSetColNamesInRS(rs);
|
233 |
|
|
|
234 |
|
|
cout<<"NOOFROWS iS "<<rs->getNoOfRows()<<endl<<endl;
|
235 |
|
|
LOG4CXX_DEBUG(TableTemplate::logger,"noOfRows is " + rs->getNoOfRows());
|
236 |
|
|
for(int rowIndex = 0; rowIndex < rs->getNoOfRows(); rowIndex++) {
|
237 |
|
|
//cout << "\n\nChecking PK" << endl;
|
238 |
|
|
bool pKEqual = false;
|
239 |
|
|
for(rowIterator = rows.begin(); rowIterator != rows.end(); ++rowIterator ) {
|
240 |
|
|
//cout << "\n\nChecking Next Row..." << endl;
|
241 |
|
|
R* aRow = (R*)*rowIterator;
|
242 |
|
|
pKEqual = false;
|
243 |
|
|
for(Keys_iter i = primaryKeys->begin(); i!= primaryKeys->end(); ++i) {
|
244 |
|
|
|
245 |
|
|
string dataType = util.getDataType(*i) ;
|
246 |
|
|
if (util.isSet(aRow, *i ,dataType) ) {
|
247 |
|
|
if( (string) rs->getElement(rowIndex, rs->getColIndex(*i)) !=
|
248 |
|
|
util.getStrValue(aRow, *i , dataType) ) {
|
249 |
|
|
pKEqual = false;
|
250 |
|
|
break;
|
251 |
|
|
|
252 |
|
|
} else {
|
253 |
|
|
pKEqual = true;
|
254 |
|
|
}
|
255 |
|
|
}
|
256 |
|
|
}
|
257 |
|
|
if(pKEqual) {
|
258 |
|
|
//cout<<"ITSEQUAL "<<endl;
|
259 |
|
|
LOG4CXX_DEBUG(TableTemplate::logger,"ITSEQUAL");
|
260 |
|
|
this->convertIntoRow(rs,rowIndex,aRow);
|
261 |
|
|
break;
|
262 |
|
|
}
|
263 |
|
|
}
|
264 |
|
|
if(!pKEqual) {
|
265 |
|
|
//cout<<"INSERT BEACUSE it is UNEQUAL"<<endl;
|
266 |
|
|
LOG4CXX_DEBUG(TableTemplate::logger,"INSERT BEACUSE it is UNEQUAL");
|
267 |
|
|
R* tempRow = new R();
|
268 |
|
|
cout<<"calling convert into rows"<<endl;
|
269 |
|
|
this->convertIntoRow(rs, rowIndex,tempRow);
|
270 |
|
|
rows.push_back(tempRow);
|
271 |
|
|
cout<<"line11"<<endl;
|
272 |
|
|
}
|
273 |
|
|
}
|
274 |
|
|
//rowIterator = rows.begin();
|
275 |
|
|
} catch (ObjectLayerException &e) {
|
276 |
|
|
exceptionOccured = true;
|
277 |
|
|
exceptionMessage = e.report();
|
278 |
|
|
delete rs;
|
279 |
|
|
} catch (DBException &e) {
|
280 |
|
|
exceptionOccured = true;
|
281 |
|
|
exceptionMessage = e.report();
|
282 |
|
|
} catch (exception &e) {
|
283 |
|
|
exceptionOccured = true;
|
284 |
|
|
exceptionMessage = e.what();
|
285 |
|
|
delete rs;
|
286 |
|
|
}
|
287 |
|
|
|
288 |
|
|
//return this->rowIterator;
|
289 |
|
|
if(exceptionOccured) {
|
290 |
|
|
LOG4CXX_ERROR(TableTemplate::logger,exceptionMessage);
|
291 |
|
|
throw ObjectLayerException(exceptionMessage);
|
292 |
|
|
}
|
293 |
|
|
|
294 |
|
|
return rows;
|
295 |
|
|
//return *this;
|
296 |
|
|
}
|
297 |
|
|
|
298 |
|
|
template <class R>
|
299 |
|
|
vector<string> TableTemplate<R>::makeInsertQuery(R* aRow) {
|
300 |
|
|
vector<string> toReturn;
|
301 |
|
|
for(Keys_iter i = schemaOrder->begin();
|
302 |
|
|
i != schemaOrder->end(); i++) {
|
303 |
|
|
if( util.isInMultiRef(*i, multiRefrences->begin(), multiRefrences->end()) ) {
|
304 |
|
|
for(Dictionary_iter m = multiRefrences->begin();
|
305 |
|
|
m != multiRefrences->end();
|
306 |
|
|
m++) {
|
307 |
|
|
if(*i == util.getTokenAt(m->second,0) ) {
|
308 |
|
|
cout<<"Multi FOUND" <<endl;
|
309 |
|
|
toReturn.push_back( sql->makeInsertQuery(aRow,*i,m->first, schema->begin(), schema->end()) );
|
310 |
|
|
}
|
311 |
|
|
}
|
312 |
|
|
} else {
|
313 |
|
|
toReturn.push_back( sql->makeInsertQuery(aRow, *i, "", schema->begin(), schema->end()) );
|
314 |
|
|
}
|
315 |
|
|
}
|
316 |
|
|
return(toReturn);
|
317 |
|
|
}
|
318 |
|
|
|
319 |
|
|
|
320 |
|
|
|
321 |
|
|
/*
|
322 |
|
|
template <class R>
|
323 |
|
|
void TableTemplate<R>::insert() {
|
324 |
|
|
for(rowIterator = rows.begin(); rowIterator != rows.end(); rowIterator++ ) {
|
325 |
|
|
R* aRow = (R*)*rowIterator;
|
326 |
|
|
makeInsertQuery(aRow);
|
327 |
|
|
}
|
328 |
|
|
}
|
329 |
|
|
*/
|
330 |
|
|
|
331 |
|
|
template <class R>
|
332 |
|
|
void TableTemplate<R>::insert() {
|
333 |
|
|
bool exceptionOccured = false;
|
334 |
|
|
string exceptionMessage = "\n";
|
335 |
|
|
int i = -1;
|
336 |
|
|
for(rowIterator = rows.begin(); rowIterator != rows.end(); ++rowIterator ) {
|
337 |
|
|
++i;
|
338 |
|
|
R* aRow = (R*)*rowIterator;
|
339 |
|
|
try{
|
340 |
|
|
//cout<<endl<<"inserting ROW no "<<i<<endl;
|
341 |
|
|
LOG4CXX_DEBUG(TableTemplate::logger,"inserting ROW no ");
|
342 |
|
|
LOG4CXX_DEBUG(TableTemplate::logger,i);
|
343 |
|
|
this->doSmartInsert(aRow);
|
344 |
|
|
//cout<<"out of smart insert"<<endl;
|
345 |
|
|
//doSimpleInsert(aRow);
|
346 |
|
|
} catch (ObjectLayerException &e) {
|
347 |
|
|
exceptionOccured = true;
|
348 |
|
|
exceptionMessage += "At row "+util.itoa(i)+": "+ e.report() + " \n";
|
349 |
|
|
} catch (DBException &e) {
|
350 |
|
|
exceptionOccured = true;
|
351 |
|
|
exceptionMessage += "At row "+util.itoa(i)+": "+ e.report() + " \n";
|
352 |
|
|
} catch (exception &e) {
|
353 |
|
|
exceptionOccured = true;
|
354 |
|
|
exceptionMessage += "At row "+util.itoa(i)+": "+ e.what() + " \n";
|
355 |
|
|
}
|
356 |
|
|
|
357 |
|
|
}
|
358 |
|
|
//cout<<"OUT of FOR Loop"<<endl;
|
359 |
|
|
if(exceptionOccured) {
|
360 |
|
|
LOG4CXX_ERROR(TableTemplate::logger,exceptionMessage);
|
361 |
|
|
throw ObjectLayerException(exceptionMessage);
|
362 |
|
|
}
|
363 |
|
|
}
|
364 |
|
|
|
365 |
|
|
|
366 |
|
|
template <class R>
|
367 |
|
|
void TableTemplate<R>::doSimpleInsert(R* aRow) {
|
368 |
|
|
//cout<<"inside doSimpleInsert"<<endl;
|
369 |
|
|
LOG4CXX_DEBUG(TableTemplate::logger,"inside doSimpleInsert");
|
370 |
|
|
|
371 |
|
|
//if(!isNotNullKeySet(aRow)) {
|
372 |
|
|
this->fixPKWithSeq(aRow);
|
373 |
|
|
//this->setTimeInRow(aRow);
|
374 |
|
|
//this->setPersonInRow(aRow);
|
375 |
|
|
if(!util.isKeySet(aRow, notNullKeys->begin(), notNullKeys->end()) ) {
|
376 |
|
|
string message = "Coloumn name "+*util.getNullKey(aRow, notNullKeys->begin(), notNullKeys->end())+" is NULL";
|
377 |
|
|
LOG4CXX_ERROR(TableTemplate::logger,message);
|
378 |
|
|
throw ObjectLayerException(message);
|
379 |
|
|
|
380 |
|
|
}
|
381 |
|
|
//this->fixPKWithSeq(aRow);
|
382 |
|
|
//if(isPrimaryKeySet(aRow)) {
|
383 |
|
|
//if( util.isKeySet(aRow, primaryKeys->begin(), primaryKeys->end()) ) {
|
384 |
|
|
if( util.isKeySet(aRow, primaryKeysReal.begin(), primaryKeysReal.end()) ) {
|
385 |
|
|
vector<string> strQuery = this->makeInsertQuery(aRow);
|
386 |
|
|
typedef vector<string>::iterator QueryIter;
|
387 |
|
|
for(QueryIter qi = strQuery.begin(); qi != strQuery.end(); ++qi ) {
|
388 |
|
|
//cout<<"Query to execute is "<<endl<<*qi<<endl;
|
389 |
|
|
|
390 |
|
|
LOG4CXX_INFO(TableTemplate::logger,"Query is "+*qi);
|
391 |
|
|
int returnCode = dbmanager->executeQuery(*qi);
|
392 |
|
|
if(returnCode != 0) {
|
393 |
|
|
throw ObjectLayerException("Query: "+*qi+" could not be executed");
|
394 |
|
|
}
|
395 |
|
|
}
|
396 |
|
|
} else {
|
397 |
|
|
throw ObjectLayerException("Sequencers falied to set Primary key ");
|
398 |
|
|
}
|
399 |
|
|
}
|
400 |
|
|
|
401 |
|
|
|
402 |
|
|
template <class R>
|
403 |
|
|
void TableTemplate<R>::delRows() {
|
404 |
|
|
cout<<"ERASING rows"<<endl;
|
405 |
|
|
rows.clear();
|
406 |
|
|
}
|
407 |
|
|
|
408 |
|
|
|
409 |
|
|
template <class R>
|
410 |
|
|
void TableTemplate<R>::insertSingle(R* aRow, string name, string fkey) {
|
411 |
|
|
name += "row";
|
412 |
|
|
cout<<"name is "<<name<<" fkey is "<<fkey<<endl;
|
413 |
|
|
RowInterface* subRow = (RowInterface*)aRow->getConstituentRow(name,fkey);
|
414 |
|
|
cout<<"RowInterface* subRow = (RowInterface*)aRow->getConstituentRow(name,fkey) "<<endl;
|
415 |
|
|
TableFactory tf;
|
416 |
|
|
//cout<<"calling tf.getTableObject"<<endl;
|
417 |
|
|
TableInterface* ti = tf.getTableObject(name);
|
418 |
|
|
ti->setDBManager(dbmanager);
|
419 |
|
|
//cout<<"Done calling tf.getTableObject"<<endl;
|
420 |
|
|
ti->addRow(subRow);
|
421 |
|
|
ti->insert();
|
422 |
|
|
ti->delRows();
|
423 |
|
|
delete ti;
|
424 |
|
|
|
425 |
|
|
util.equatePKWithRef(aRow, refrences->begin(), refrences->end() );
|
426 |
|
|
util.equatePKWithMultiRef(aRow, multiRefrences->begin(), multiRefrences->end() );
|
427 |
|
|
|
428 |
|
|
}
|
429 |
|
|
|
430 |
|
|
|
431 |
|
|
|
432 |
|
|
|
433 |
|
|
template <class R>
|
434 |
|
|
void TableTemplate<R>::insertMulti(R* aRow, string name) {
|
435 |
|
|
bool exceptionOccured = false;
|
436 |
|
|
string exceptionMessage = "\n";
|
437 |
|
|
|
438 |
|
|
for(Dictionary_iter m = multiRefrences->begin(); m != multiRefrences->end(); ++m) {
|
439 |
|
|
try {
|
440 |
|
|
//cout<<"checking name "<<name<<" with util.getTokenAt(m->second,0) "<<util.getTokenAt(m->second,0)<<endl;
|
441 |
|
|
if(name == util.getTokenAt(m->second,0) ) {
|
442 |
|
|
this->insertSingle(aRow, name, m->first);
|
443 |
|
|
}
|
444 |
|
|
} catch (ObjectLayerException &e) {
|
445 |
|
|
exceptionOccured = true;
|
446 |
|
|
exceptionMessage += "At row "+name+": "+ e.report() + " \n";
|
447 |
|
|
} catch (DBException &e) {
|
448 |
|
|
exceptionOccured = true;
|
449 |
|
|
exceptionMessage += "At row "+name+": "+ e.report() + " \n";
|
450 |
|
|
} catch (exception &e) {
|
451 |
|
|
exceptionOccured = true;
|
452 |
|
|
exceptionMessage += "At row "+name+": "+ e.what() + " \n";
|
453 |
|
|
}
|
454 |
|
|
|
455 |
|
|
}
|
456 |
|
|
if(exceptionOccured) {
|
457 |
|
|
throw ObjectLayerException(exceptionMessage);
|
458 |
|
|
}
|
459 |
|
|
}
|
460 |
|
|
|
461 |
|
|
/*
|
462 |
|
|
template <class R>
|
463 |
|
|
void TableTemplate<R>::doSmartInsert(R* aRow) {
|
464 |
|
|
//cout<<"inside doSmartInsert for TableTemplate"<<endl;
|
465 |
|
|
LOG4CXX_DEBUG(TableTemplate::logger,"inside doSmartInsert for TableTemplate");
|
466 |
|
|
bool exceptionOccured = false;
|
467 |
|
|
string exceptionMessage = "\n";
|
468 |
|
|
|
469 |
|
|
for(Keys_iter i = schemaOrder->begin(); i != schemaOrder->end(); ++i) {
|
470 |
|
|
try{
|
471 |
|
|
if( util.isInMultiRef(*i, multiRefrences->begin(), multiRefrences->end()) ) {
|
472 |
|
|
this->insertMulti(aRow,*i);
|
473 |
|
|
} else {
|
474 |
|
|
this->insertSingle(aRow, *i,"");
|
475 |
|
|
}
|
476 |
|
|
} catch (ObjectLayerException &e) {
|
477 |
|
|
exceptionOccured = true;
|
478 |
|
|
exceptionMessage += "At row "+*i+": "+ e.report() + " \n";
|
479 |
|
|
} catch (DBException &e) {
|
480 |
|
|
exceptionOccured = true;
|
481 |
|
|
exceptionMessage += "At row "+*i+": "+ e.report() + " \n";
|
482 |
|
|
} catch (exception &e) {
|
483 |
|
|
exceptionOccured = true;
|
484 |
|
|
exceptionMessage += "At row "+*i+": "+ e.what() + " \n";
|
485 |
|
|
}
|
486 |
|
|
|
487 |
|
|
|
488 |
|
|
}
|
489 |
|
|
if(exceptionOccured) {
|
490 |
|
|
throw ObjectLayerException(exceptionMessage);
|
491 |
|
|
}
|
492 |
|
|
}
|
493 |
|
|
*/
|
494 |
|
|
|
495 |
|
|
template <class R>
|
496 |
|
|
void TableTemplate<R>::update(){
|
497 |
|
|
cout << "Hello I am in Update" << endl;
|
498 |
|
|
}
|
499 |
|
|
|
500 |
|
|
template <class R>
|
501 |
|
|
int TableTemplate<R>::getSeqValue(string tableName, string colName) {
|
502 |
|
|
ResultSet* rs = this->doSelect(sql->makeSeqQuery(tableName,colName),"");
|
503 |
|
|
if(rs->getNoOfRows() == 0) {
|
504 |
|
|
delete rs;
|
505 |
|
|
return 0;
|
506 |
|
|
}
|
507 |
|
|
int intValue = atoi(rs->getElement(0,0).c_str());
|
508 |
|
|
delete rs;
|
509 |
|
|
return ++intValue;
|
510 |
|
|
|
511 |
|
|
}
|
512 |
|
|
|
513 |
|
|
template <class R>
|
514 |
|
|
void TableTemplate<R>::fixPKWithSeq(R* aRow) {
|
515 |
|
|
for(Keys_iter i = primaryKeysReal.begin(); i != primaryKeysReal.end(); ++i) {
|
516 |
|
|
string dataType = util.getDataType(*i);
|
517 |
|
|
if( util.isSet(aRow, *i, dataType) ) {
|
518 |
|
|
continue;
|
519 |
|
|
}
|
520 |
|
|
if(dataType != "INTEGER") {
|
521 |
|
|
//cout<<"Sequencer for non int type is invalid"<<endl;
|
522 |
|
|
LOG4CXX_ERROR(TableTemplate::logger,"Sequencer for non int type is invalid");
|
523 |
|
|
continue;
|
524 |
|
|
}
|
525 |
|
|
int value = this->getSeqValue(util.getTokenAt(*i, 0), util.getTokenAt(*i, 1));
|
526 |
|
|
cout<<"Setting sequencer value of "<<*i<<" "<<value<<endl;
|
527 |
|
|
//LOG4CXX_DEBUG(TableTemplate::logger,"Setting sequencer value of " + *i + " " + value);
|
528 |
|
|
aRow->setValue(*i,&value);
|
529 |
|
|
}
|
530 |
|
|
}
|
531 |
|
|
|
532 |
|
|
template <class R>
|
533 |
|
|
void TableTemplate<R>::setTimeInRow(R* aRow) {
|
534 |
|
|
string tableName = this->util.getTokenAt(schema->begin()->first,0);
|
535 |
|
|
long value = this->util.getTime();
|
536 |
|
|
//float value = this->util.getTime();
|
537 |
|
|
//cout<<"setting "<<tableName<<".created_at to "<<value<<endl;
|
538 |
|
|
aRow->setValue(tableName+".created_at",&value);
|
539 |
|
|
aRow->setValue(tableName+".modified_at",&value);
|
540 |
|
|
}
|
541 |
|
|
|
542 |
|
|
template <class R>
|
543 |
|
|
void TableTemplate<R>::setPersonInRow(R* aRow) {
|
544 |
|
|
string tableName = this->util.getTokenAt(schema->begin()->first,0);
|
545 |
|
|
int value = 1;
|
546 |
|
|
aRow->setValue(tableName+".created_by",&value);
|
547 |
|
|
aRow->setValue(tableName+".modified_by",&value);
|
548 |
|
|
}
|
549 |
|
|
|
550 |
|
|
template TableTemplate<T_Schema_Revisionrow>;
|
551 |
|
|
template TableTemplate<T_Personrow>;
|
552 |
|
|
template TableTemplate<T_Physics_Grouprow>;
|
553 |
|
|
template TableTemplate<T_Collection_Typerow>;
|
554 |
|
|
template TableTemplate<T_App_Familyrow>;
|
555 |
|
|
template TableTemplate<T_Applicationrow>;
|
556 |
|
|
template TableTemplate<T_App_Configrow>;
|
557 |
|
|
template TableTemplate<T_Desc_Triggerrow>;
|
558 |
|
|
template TableTemplate<T_Desc_Mcrow>;
|
559 |
|
|
template TableTemplate<T_Desc_Primaryrow>;
|
560 |
|
|
template TableTemplate<T_Data_Tierrow>;
|
561 |
|
|
template TableTemplate<T_Primary_Datasetrow>;
|
562 |
|
|
template TableTemplate<T_Processing_Pathrow>;
|
563 |
|
|
template TableTemplate<T_Processed_Datasetrow>;
|
564 |
|
|
template TableTemplate<T_Event_Collectionrow>;
|
565 |
|
|
template TableTemplate<T_Analysis_Datasetrow>;
|
566 |
|
|
template TableTemplate<T_Anads_Datarow>;
|
567 |
|
|
template TableTemplate<T_Parentage_Typerow>;
|
568 |
|
|
template TableTemplate<T_Evcoll_Parentagerow>;
|
569 |
|
|
template TableTemplate<T_Block_Statusrow>;
|
570 |
|
|
template TableTemplate<T_Blockrow>;
|
571 |
|
|
template TableTemplate<T_File_Statusrow>;
|
572 |
|
|
template TableTemplate<T_File_Typerow>;
|
573 |
|
|
template TableTemplate<T_Filerow>;
|
574 |
|
|
template TableTemplate<T_Evcoll_Filerow>;
|
575 |
|
|
template TableTemplate<T_Validation_Statusrow>;
|
576 |
|
|
template TableTemplate<T_Dataset_Statusrow>;
|
577 |
|
|
template TableTemplate<T_Evcoll_Statusrow>;
|
578 |
|
|
template TableTemplate<T_Run_Qualityrow>;
|
579 |
|
|
template TableTemplate<T_Info_Anadsrow>;
|
580 |
|
|
template TableTemplate<T_Info_Evcollrow>;
|
581 |
|
|
template TableTemplate<T_Runrow>;
|
582 |
|
|
template TableTemplate<T_Evcoll_Runrow>;
|
583 |
|
|
template TableTemplate<Insertappsmultirow>;
|
584 |
|
|
template TableTemplate<Personmultirow>;
|
585 |
|
|
template TableTemplate<Physicsgroupmultirow>;
|
586 |
|
|
template TableTemplate<Evcollviewmultirow>;
|
587 |
|
|
template TableTemplate<Fileviewmultirow>;
|
588 |
|
|
template TableTemplate<Primarydatasetmultirow>;
|
589 |
|
|
template TableTemplate<Processingpathmultirow>;
|
590 |
|
|
template TableTemplate<Analysisdatasetmultirow>;
|
591 |
|
|
template TableTemplate<Datasetprovenenceevchildmultirow>;
|
592 |
|
|
template TableTemplate<Datasetprovenenceevparentmultirow>;
|
593 |
|
|
template TableTemplate<Crabevcollviewmultirow>;
|
594 |
|
|
|
595 |
|
|
|