test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
idDealer.cc
Go to the documentation of this file.
2 #include "RelationalAccess/ISchema.h"
3 #include "RelationalAccess/ITable.h"
4 #include "RelationalAccess/IQuery.h"
5 #include "RelationalAccess/ICursor.h"
6 #include "RelationalAccess/ITableDataEditor.h"
7 #include "CoralBase/AttributeList.h"
8 #include "CoralBase/AttributeSpecification.h"
9 #include "CoralBase/AttributeList.h"
10 #include "CoralBase/Attribute.h"
12 #include <sstream>
13 //#include <iostream>
14 lumi::idDealer::idDealer( coral::ISchema& schema):m_schema(schema),m_idtablecolumnName(lumi::LumiNames::idTableColumnName()),m_idtablecolumnType(lumi::LumiNames::idTableColumnType()){
15 }
16 unsigned long long lumi::idDealer::getIDforTable( const std::string& tableName ){
18  coral::IQuery* q=m_schema.tableHandle(idtableName).newQuery();
19  q->addToOutputList(m_idtablecolumnName);
20  q->setForUpdate(); //lock it
21  coral::ICursor& cursor=q->execute();
22  unsigned long long result=0;
23  while ( cursor.next() ){
24  const coral::AttributeList& row = cursor.currentRow();
25  result = row[m_idtablecolumnName].data<unsigned long long>();
26  }
27  cursor.close();
28  delete q;
29  return result;
30 }
31 unsigned long long lumi::idDealer::generateNextIDForTable( const std::string& tableName,unsigned int interval ){
33  coral::IQuery* q=m_schema.tableHandle(idtableName).newQuery();
34  q->addToOutputList(m_idtablecolumnName);
35  unsigned long long r=0;
36  coral::AttributeList myresult;
37  myresult.extend(m_idtablecolumnName,typeid(unsigned long long));
38  q->defineOutput(myresult);
39  q->setForUpdate(); //lock it
40  coral::ICursor& cursor=q->execute();
41  while ( cursor.next() ){
42  const coral::AttributeList& row = cursor.currentRow();
43  r = row[m_idtablecolumnName].data<unsigned long long>();
44  }
45  coral::ITableDataEditor& dataEditor=m_schema.tableHandle(idtableName).dataEditor();
46  coral::AttributeList inputData;
47  //inputData.extend("interval",typeid(unsigned int));
48  //inputData["interval"].data<unsigned int>()=interval;
49  //dataEditor.updateRows(m_idtablecolumnName+"="+m_idtablecolumnName+"+1","",inputData);
50  std::stringstream ss;
51  ss<<interval;
52  dataEditor.updateRows(m_idtablecolumnName+"="+m_idtablecolumnName+"+"+ss.str(),"",inputData);
53  delete q;
54  return r+interval;
55 }
tuple interval
Definition: MergeJob_cfg.py:20
tuple lumi
Definition: fjr2json.py:35
unsigned long long getIDforTable(const std::string &tableName)
Definition: idDealer.cc:16
tuple result
Definition: query.py:137
idDealer(coral::ISchema &schema)
Definition: idDealer.cc:14
unsigned long long generateNextIDForTable(const std::string &tableName, unsigned int interval=1)
Definition: idDealer.cc:31
static const std::string idTableName(const std::string &dataTableName)
Definition: LumiNames.cc:68
tuple inputData
Definition: idDealer.py:72