ATLAS Offline Software
Loading...
Searching...
No Matches
CoraCoolSequence Class Reference

#include <CoraCoolSequence.h>

Collaboration diagram for CoraCoolSequence:

Public Member Functions

 CoraCoolSequence (const std::string &dbname, const std::string &seqname, coral::ISessionProxy *proxy, bool create=false)
int fetch (const int inc=1)
bool querySeq (int &keyval, bool update=false, bool gettable=false)
bool dropSeq ()

Private Member Functions

 CoraCoolSequence ()

Private Attributes

std::string m_dbname
std::string m_seqname
coral::ISessionProxy * m_proxy
coral::ITable * m_table

Detailed Description

Definition at line 15 of file CoraCoolSequence.h.

Constructor & Destructor Documentation

◆ CoraCoolSequence() [1/2]

CoraCoolSequence::CoraCoolSequence ( const std::string & dbname,
const std::string & seqname,
coral::ISessionProxy * proxy,
bool create = false )

Definition at line 26 of file CoraCoolSequence.cxx.

29 :
30 m_dbname(dbname), m_seqname(seqname), m_proxy(proxy), m_table(0) {
31
32 // derive key table name from CoraCool database name
33 const std::string keytblname=m_dbname+"_CORACOOLKEYS";
34 // check for existance of key table
35 try {
36 m_table=&(m_proxy->nominalSchema().tableHandle(keytblname));
37 }
38 catch (coral::SchemaException& e) {
39 // try to create the table if requested
40 if (create) {
41 coral::TableDescription tdesc(keytblname);
42 tdesc.setName(keytblname);
43 tdesc.insertColumn("SEQNAME","string",63,false);
44 tdesc.insertColumn("SEQVAL","int");
45 tdesc.setPrimaryKey("SEQNAME");
46 m_table=&(m_proxy->nominalSchema().createTable(tdesc));
47 // pause for thought
48 m_proxy->transaction().commit();
49 sleep(1);
50 m_proxy->transaction().start(false);
51 m_table=&(m_proxy->nominalSchema().tableHandle(keytblname));
52 }
53 }
54 // throw exception here? FIXME
55 if (m_table==0) throw CoraCoolException("Cannot create "+keytblname+" table",
56 "CoraCoolSequence::CoraCoolSequence");
57 // if not creating, finish here in any case - have pointer to table
58 if (!create) return;
59
60 int ifk;
61 if (!querySeq(ifk,false)) {
62 // update table with sequence starting at 0
63 coral::AttributeList data;
64 data.extend<std::string>("SEQNAME");
65 data.extend<int>("SEQVAL");
66 data[0].data<std::string>()=m_seqname;
67 data[1].data<int>()=0;
68 coral::ITableDataEditor& editor=m_table->dataEditor();
69 editor.insertRow(data);
70 }
71}
char data[hepevt_bytes_allocation_ATLAS]
Definition HepEvt.cxx:11
coral::ITable * m_table
bool querySeq(int &keyval, bool update=false, bool gettable=false)
coral::ISessionProxy * m_proxy
std::string m_seqname

◆ CoraCoolSequence() [2/2]

CoraCoolSequence::CoraCoolSequence ( )
private

Member Function Documentation

◆ dropSeq()

bool CoraCoolSequence::dropSeq ( )

Definition at line 124 of file CoraCoolSequence.cxx.

124 {
125 coral::AttributeList bindvar;
126 bindvar.extend<std::string>("SKEY");
127 bindvar[0].data<std::string>()=m_seqname;
128 coral::ITableDataEditor& editor=m_table->dataEditor();
129 long rows=editor.deleteRows("SEQNAME=:SKEY",bindvar);
130 return (rows==1);
131}

◆ fetch()

int CoraCoolSequence::fetch ( const int inc = 1)

Definition at line 73 of file CoraCoolSequence.cxx.

73 {
74 int key=0;
75 // query sequence setting lock on row
76 if (querySeq(key,true)) {
77 // got result, now update rows
78 coral::AttributeList bindvar;
79 bindvar.extend<std::string>("SKEY");
80 bindvar[0].data<std::string>()=m_seqname;
81 bindvar.extend<int>("SINC");
82 bindvar[1].data<int>()=inc;
83 coral::ITableDataEditor& editor=m_table->dataEditor();
84 int rowsupdated=editor.updateRows("SEQVAL=SEQVAL+:SINC",
85 "SEQNAME=:SKEY",bindvar);
86 if (rowsupdated!=1) throw CoraCoolException(
87 "Unexpected number of rows locked in keytable",
88 "CoraCoolSequence::CoraCoolSequence");
89 } else {
90 throw CoraCoolException ("Problem generating next key value for "+m_seqname,
91 "CoraCoolSequence::fetch");
92 }
93 return key;
94}

◆ querySeq()

bool CoraCoolSequence::querySeq ( int & keyval,
bool update = false,
bool gettable = false )

Definition at line 96 of file CoraCoolSequence.cxx.

96 {
97 if (gettable) {
98 const std::string keytblname=m_dbname+"_CORACOOLKEYS";
99 m_table=&(m_proxy->nominalSchema().tableHandle(keytblname));
100 }
101 coral::IQuery* query=m_table->newQuery();
102 coral::AttributeList bindvar;
103 bindvar.extend<std::string>("SKEY");
104 bindvar[0].data<std::string>()=m_seqname;
105 query->setCondition("SEQNAME=:SKEY",bindvar);
106 query->setRowCacheSize(2);
107 query->defineOutputType("SEQVAL","int");
108 if (update) query->setForUpdate();
109 coral::ICursor& cursor=query->execute();
110 bool res=true;
111 if (!cursor.next()) {
112 res=false;
113 } else {
114 const coral::AttributeList& res=cursor.currentRow();
115 keyval=res["SEQVAL"].data<int>();
116 }
117 if (cursor.next()) {
118 res=false;
119 }
120 delete query;
121 return res;
122}
std::pair< std::vector< unsigned int >, bool > res
query
Definition index.py:72

Member Data Documentation

◆ m_dbname

std::string CoraCoolSequence::m_dbname
private

Definition at line 40 of file CoraCoolSequence.h.

◆ m_proxy

coral::ISessionProxy* CoraCoolSequence::m_proxy
private

Definition at line 42 of file CoraCoolSequence.h.

◆ m_seqname

std::string CoraCoolSequence::m_seqname
private

Definition at line 41 of file CoraCoolSequence.h.

◆ m_table

coral::ITable* CoraCoolSequence::m_table
private

Definition at line 43 of file CoraCoolSequence.h.


The documentation for this class was generated from the following files: