19#include "RelationalAccess/ISessionProxy.h"
20#include "RelationalAccess/ITransaction.h"
21#include "RelationalAccess/SchemaException.h"
22#include "RelationalAccess/ConnectionService.h"
23#include "RelationalAccess/ICursor.h"
24#include "RelationalAccess/ITable.h"
25#include "RelationalAccess/ISchema.h"
26#include "RelationalAccess/IQuery.h"
32#include "CoralBase/Exception.h"
37 : base_class(name,svc)
44 const std::string connStr{connName};
47 ATH_MSG_DEBUG(
" Trying to open the connection " << connName <<
" for the first time");
64 coral::ConnectionService conSvcH;
65 coral::ISessionProxy *proxy =
nullptr;
67 proxy = conSvcH.connect(connStr,coral::ReadOnly);
68 proxy->transaction().start(
true);
69 ATH_MSG_DEBUG(
"Proxy for connection " << connName <<
" obtained");
71 catch(std::exception& e) {
91 if(connection->second>0) {
94 ATH_MSG_DEBUG(
"Connection " << connName <<
" Sessions = " << connection->second);
96 if(connection->second==0) {
99 session->second->transaction().commit();
100 delete session->second;
101 session->second =
nullptr;
112 if(connName==
"*Everything*") {
115 ATH_MSG_INFO(
"Close everything: Connection: " << ii.first <<
" with reference count = " << ii.second <<
" will be closed.");
131 ATH_MSG_ERROR(
"Wrong name for the connection: " << connName);
135 connection->second = 0;
139 && session->second) {
140 session->second->transaction().commit();
141 delete session->second;
142 session->second =
nullptr;
151 , std::string_view tag
152 , std::string_view tag2node
153 , std::string_view connName)
155 static const std::string dc{
"::"};
157 key.reserve(
node.size() + tag.size() + tag2node.size() + 4);
161 if(!tag2node.empty()){
163 key.append(tag2node);
165 const std::string connStr{connName};
172 RecordsetPtrMap::const_iterator it = recordsets.find(key);
173 if(it != recordsets.end()) {
179 ATH_MSG_ERROR(
"Unable to open connection " << connName <<
". Returning empty recordset");
185 coral::ISessionProxy* session =
m_sessions[connStr];
189 std::string lookupMapKey;
190 lookupMapKey.reserve(tag.size() + connName.size() + 2);
191 lookupMapKey.append(tag);
192 lookupMapKey.append(dc);
193 lookupMapKey.append(connName);
195 const std::string nodeStr{
node};
196 GlobalTagLookupMap::const_iterator lookupmap =
m_globalTagLookup.find(lookupMapKey);
198 TagNameIdByNode::const_iterator childtagdet = lookupmap->second->find(
node);
199 if(childtagdet!=lookupmap->second->end()) {
200 recConcrete->
getData(session,nodeStr,childtagdet->second.first,childtagdet->second.second);
204 ATH_MSG_DEBUG(
"Unable to find tag for the node " <<
node <<
" in the cache of global tag " << tag <<
". Returning empty recordset");
208 const std::string
str{tag2node.empty()?
node:tag2node};
211 recConcrete->
getData(session,versionAccessor.getNodeName(),versionAccessor.getTagName(),versionAccessor.getTagID());
214 catch(coral::SchemaException& se) {
217 catch(std::exception& e) {
224 recordsets.emplace(key,rec);
230 ,
const std::string& tag
231 ,
const std::string& tag2node
232 ,
const std::string& connName)
234 ATH_MSG_DEBUG(
"getQuery (" <<
node <<
"," << tag <<
"," << tag2node <<
"," << connName <<
")");
238 std::unique_ptr<IRDBQuery>
query;
241 ATH_MSG_ERROR(
"Unable to open connection " << connName <<
". Returning nullptr to IRDBQuery");
245 coral::ISessionProxy* session =
m_sessions[connName];
249 std::string childTagId(
"");
250 std::string lookupMapKey = tag +
"::" + connName;
251 GlobalTagLookupMap::const_iterator lookupmap =
m_globalTagLookup.find(lookupMapKey);
253 TagNameIdByNode::const_iterator childtagdet = lookupmap->second->find(
node);
254 if(childtagdet!=lookupmap->second->end()) {
255 childTagId = childtagdet->second.second;
261 childTagId = versionAccessor.
getTagID();
264 if(childTagId.empty()) {
265 ATH_MSG_WARNING(
"Could not get the tag for " <<
node <<
" node. Returning 0 pointer to IRDBQuery");
268 query = std::unique_ptr<IRDBQuery>(
new RDBQuery(dblock,
this,
node,childTagId,connName));
271 catch(coral::SchemaException& se) {
274 catch(std::exception& e) {
286 ,
const std::string& parentTag
287 ,
const std::string& parentNode
288 ,
const std::string& connName)
298 ,
const std::string& parentTag
299 ,
const std::string& parentNode
300 ,
const std::string& connName
303 ATH_MSG_DEBUG(
"getChildTag for " << childNode <<
" " << parentTag <<
" " << parentNode);
308 std::string lookupMapKey = parentTag +
"::" + connName;
309 GlobalTagLookupMap::const_iterator lookupmap =
m_globalTagLookup.find(lookupMapKey);
311 TagNameIdByNode::const_iterator childtagdet = lookupmap->second->find(childNode);
312 if(childtagdet!=lookupmap->second->end()) {
313 return childtagdet->second.first;
317 return std::string(
"");
323 ATH_MSG_ERROR(
"Unable to open connection " << connName <<
". Returning empty string");
324 return std::string(
"");
327 std::string childTag(
"");
330 coral::ISessionProxy* session =
m_sessions[connName];
336 catch(coral::SchemaException& se) {
339 catch(std::exception& e) {
352 ,
const std::string& tag
353 ,
const std::string& connName)
363 coral::ISessionProxy* session =
m_sessions[connName];
365 coral::ITable& tableTag2Node = session->nominalSchema().tableHandle(
"HVS_TAG2NODE");
366 coral::IQuery *queryTag2Node = tableTag2Node.newQuery();
367 queryTag2Node->addToOutputList(
"LOCKED");
368 queryTag2Node->addToOutputList(
"SUPPORTED");
369 queryTag2Node->setMemoryCacheSize(1);
371 bindsTag2Node.extend<std::string>(
"tagN");
372 queryTag2Node->setCondition(
"TAG_NAME=:tagN", bindsTag2Node);
373 bindsTag2Node[0].data<std::string>() = tag;
375 coral::ICursor& cursorTag2Node = queryTag2Node->execute();
376 if(cursorTag2Node.next()) {
377 tagDetails = cursorTag2Node.currentRow();
380 delete queryTag2Node;
383 std::string lookupMapKey = tag +
"::" + connName;
388 coral::ITable& tableRootTag2Child = session->nominalSchema().tableHandle(
"HVS_TAGCACHE");
389 coral::IQuery* queryRootTag2Child = tableRootTag2Child.newQuery();
390 queryRootTag2Child->addToOutputList(
"CHILDNODE");
391 queryRootTag2Child->addToOutputList(
"CHILDTAG");
392 queryRootTag2Child->addToOutputList(
"CHILDTAGID");
393 queryRootTag2Child->setMemoryCacheSize(1);
395 bindsRootTag2Child.extend<std::string>(
"tagN");
396 queryRootTag2Child->setCondition(
"ROOTTAG=:tagN", bindsRootTag2Child);
397 bindsRootTag2Child[0].data<std::string>() = tag;
398 queryRootTag2Child->addToOrderList(
"CHILDNODE");
400 coral::ICursor& cursorRootTag2Child = queryRootTag2Child->execute();
401 while(cursorRootTag2Child.next()) {
402 const coral::AttributeList& row = cursorRootTag2Child.currentRow();
406 delete queryRootTag2Child;
408 if(lookup->size()>0) {
416 catch(coral::SchemaException& se) {
419 catch(std::exception& e) {
430 ,
const std::string& connName)
438 coral::ISessionProxy* session =
m_sessions[connName];
440 coral::ITable& tableNode = session->nominalSchema().tableHandle(
"HVS_NODE");
441 coral::IQuery *queryNode = tableNode.newQuery();
442 queryNode->addToOutputList(
"NODE_NAME");
443 queryNode->setMemoryCacheSize(1);
445 queryNode->setCondition(
"BRANCH_FLAG=0",
empty);
446 queryNode->addToOrderList(
"NODE_NAME");
448 coral::ICursor& cursorNode = queryNode->execute();
449 while(cursorNode.next()) {
450 list.push_back(cursorNode.currentRow()[
"NODE_NAME"].data<std::string>());
455 catch(coral::SchemaException& se) {
458 catch(std::exception& e) {
469 ,
const std::string& connName)
471 std::vector<std::string> taglist;
477 coral::ISessionProxy* session =
m_sessions[connName];
479 coral::ITable& tableTag2Node = session->nominalSchema().tableHandle(
"HVS_TAG2NODE");
480 coral::IQuery* queryTag2Node = tableTag2Node.newQuery();
481 queryTag2Node->addToOutputList(
"TAG_NAME");
482 queryTag2Node->setMemoryCacheSize(1);
484 std::string condString = std::string(
"NODE_ID=0 AND LOCKED=1 AND SUPPORTED>=")+supportedFlag;
485 queryTag2Node->setCondition(condString,
empty);
486 queryTag2Node->addToOrderList(
"TAG_NAME");
488 coral::ICursor& cursorTagName = queryTag2Node->execute();
489 while(cursorTagName.next()) {
490 const coral::AttributeList& row = cursorTagName.currentRow();
493 delete queryTag2Node;
496 catch(coral::SchemaException& se) {
499 catch(std::exception& e) {
513 return sessionIt ==
m_sessions.end() ? nullptr : sessionIt->second;
518 return StatusCode::SUCCESS;
532 for(
auto& [sessionName,session] :
m_sessions) {
536 return StatusCode::SUCCESS;
#define ATH_MSG_WARNING(x)
char data[hepevt_bytes_allocation_ATLAS]
coral::AttributeList RDBTagDetails
std::shared_ptr< IRDBRecordset > IRDBRecordset_ptr
Definition of RDBAccessSvc class.
std::map< std::string, IRDBRecordset_ptr, std::less<> > RecordsetPtrMap
std::map< std::string, TagNameId, std::less<> > TagNameIdByNode
Definition of RDBRecordset class.
Definition of RDBVersionAccessor class.
static const Attributes_t empty
Define macros for attributes used to control the static checker.
#define ATLAS_THREAD_SAFE
bool disconnect(std::string_view connName) override
If the counnection counter==1 closes the connection.
std::vector< std::string > getLockedSupportedTags(const std::string &supportedFlag, const std::string &connName="ATLASDD")
bool shutdown_connection(std::string_view connName)
std::map< std::string, unsigned int, std::less<> > m_openConnections
bool shutdown(std::string_view connName) override
Closes the connection regardless of the counter value.
std::mutex m_sessionMutex
StatusCode finalize() override
bool connect(std::string_view connName) override
Connect to the relational DB.
RecordsetPtrsByConn m_recordsetptrs
GlobalTagLookupMap m_globalTagLookup
RDBAccessSvc(const std::string &name, ISvcLocator *svc)
Standard Service Constructor.
void getAllLeafNodes(std::vector< std::string > &list, const std::string &connName="ATLASDD")
void getTagDetails(RDBTagDetails &tagDetails, const std::string &tag, const std::string &connName="ATLASDD") override
std::mutex m_recordsetMutex
StatusCode initialize() override
std::string getChildTag(const std::string &childNode, const std::string &parentTag, const std::string &parentNode, const std::string &connName) override
Gets the tag name for the node by giving its parent node tag.
std::unique_ptr< IRDBQuery > getQuery(const std::string &node, const std::string &tag, const std::string &tag2node, const std::string &connName) override
coral::ISessionProxy * getSession(const std::string &connName="ATLASDD")
IRDBRecordset_ptr getRecordsetPtr(std::string_view node, std::string_view tag, std::string_view tag2node="", std::string_view connName="ATLASDD") override
Provides access to the Recordset object containing HVS-tagged data.
RDBQuery is an implementation of IRDBQuery interface.
RDBRecordset is an implementation of IRDBRecordset interface.
void setNodeName(const std::string &nodeName)
void getData(coral::ISessionProxy *session, const std::string &nodeName, const std::string &tagName, const std::string &tagId)
Constructs SQL query and retrieves the data from DB.
RDBVersionAccessor is a helper class navigating HVS tree and getting child node tag by the tag of one...
const std::string & getTagID() const
void getChildTagData()
Constructs SQL query and retrieves child tag ID and Name from DB.
const std::string & getTagName() const