test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
sessionManager.py
Go to the documentation of this file.
1 import coral,os,os.path
2 from RecoLuminosity.LumiDB import cacheconfigParser,connectstrParser
3 
6  return '''<frontier-connect><proxy url = "http://cmst0frontier.cern.ch:3128"/><proxy url = "http://cmst0frontier.cern.ch:3128"/><proxy url = "http://cmst0frontier1.cern.ch:3128"/><proxy url = "http://cmst0frontier2.cern.ch:3128"/><server url = "http://cmsfrontier.cern.ch:8000/FrontierInt"/><server url = "http://cmsfrontier.cern.ch:8000/FrontierInt"/><server url = "http://cmsfrontier1.cern.ch:8000/FrontierInt"/><server url = "http://cmsfrontier2.cern.ch:8000/FrontierInt"/><server url = "http://cmsfrontier3.cern.ch:8000/FrontierInt"/><server url = "http://cmsfrontier4.cern.ch:8000/FrontierInt"/></frontier-connect>'''
7 
8  def __init__(self,connectString,authpath=None,siteconfpath=None,debugON = False):
9  self.__connectString=connectString
10  self.__svc=None
12  usedefaultfrontierconfig = False
13  cacheconfigpath = ''
14  try:
15  self.__connectparser.parse()
16  if self.__connectparser.needsitelocalinfo():
17  if not siteconfpath:
18  cacheconfigpath = os.environ['CMS_PATH']
19  if cacheconfigpath:
20  cacheconfigpath = os.path.join (cacheconfigpath, 'SITECONF', 'local', 'JobConfig', 'site-local-config.xml')
21  else:
22  usedefaultfrontierconfig = True
23  else:
24  cacheconfigpath = siteconfpath
25  cacheconfigpath = os.path.join (cacheconfigpath, 'site-local-config.xml')
27  if usedefaultfrontierconfig:
28  ccp.parseString ( self.defaultfrontierConfigString() )
29  else:
30  ccp.parse (cacheconfigpath)
31  self.__connectString = self.__connectparser.fullfrontierStr(self.__connectparser.schemaname(), ccp.parameterdict())
32  if self.__connectparser.protocol()=='oracle':
33  if authpath:
34  os.environ['CORAL_AUTH_PATH']=authpath
35  else:
36  os.environ['CORAL_AUTH_PATH']='.'
37  if debugON :
38  msg = coral.MessageStream ('')
39  msg.setMsgVerbosity (coral.message_Level_Debug)
40  self.__svc = coral.ConnectionService()
41  except:
42  if self.__svc: del self.__svc
43  raise
44  def openSession(self,isReadOnly=True,cpp2sqltype=[],sql2cpptype=[] ):
45  try:
46  session=None
47  if self.__connectparser.protocol()=='frontier' or isReadOnly:
48  session = self.__svc.connect(self.__connectString, accessMode = coral.access_ReadOnly)
49  else:
50  session = self.__svc.connect(self.__connectString, accessMode = coral.access_Update)
51  for (cpptype,sqltype) in cpp2sqltype:
52  session.typeConverter().setCppTypeForSqlType(cpptype,sqltype)
53  for (sqltype,cpptype) in sql2cpptype:
54  session.typeConverter().setSqlTypeForCppType(sqltype,cpptype)
55  return session
56  except:
57  if session: del session
58  raise
59  def realConnectString(self):
60  return self.__connectString
61  def __del__(self):
62  del self.__svc
63  def svcHandle(self):
64  return self.__svc
65 
66 if __name__ == "__main__":
67  svc=sessionManager('oracle://cms_orcoff_prep/cms_lumi_dev_offline',authpath='/afs/cern.ch/user/x/xiezhen',debugON=False)
68  print svc.realConnectString()
69  session=svc.openSession(isReadOnly=True,cpp2sqltype=[('unsigned int','NUMBER(10)'),('unsigned long long','NUMBER(20)')])
70  session.transaction().start(True)
71  session.transaction().commit()
72  del session
73  svc=sessionManager('frontier://LumiPrep/CMS_LUMI_DEV_OFFLINE',debugON=False)
74  print svc.realConnectString()
75  session=svc.openSession(isReadOnly=True,cpp2sqltype=[('unsigned int','NUMBER(10)'),('unsigned long long','NUMBER(20)')])
76  del session
Definition: start.py:1
list object
Definition: dbtoconf.py:77