Go to the documentation of this file.00001 import coral,os,os.path
00002 from RecoLuminosity.LumiDB import cacheconfigParser,connectstrParser
00003
00004 class sessionManager(object):
00005 def defaultfrontierConfigString ():
00006 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>'''
00007
00008 def __init__(self,connectString,authpath=None,siteconfpath=None,debugON = False):
00009 self.__connectString=connectString
00010 self.__svc=None
00011 self.__connectparser=connectstrParser.connectstrParser(self.__connectString)
00012 usedefaultfrontierconfig = False
00013 cacheconfigpath = ''
00014 try:
00015 self.__connectparser.parse()
00016 if self.__connectparser.needsitelocalinfo():
00017 if not siteconfpath:
00018 cacheconfigpath = os.environ['CMS_PATH']
00019 if cacheconfigpath:
00020 cacheconfigpath = os.path.join (cacheconfigpath, 'SITECONF', 'local', 'JobConfig', 'site-local-config.xml')
00021 else:
00022 usedefaultfrontierconfig = True
00023 else:
00024 cacheconfigpath = siteconfpath
00025 cacheconfigpath = os.path.join (cacheconfigpath, 'site-local-config.xml')
00026 ccp = cacheconfigParser.cacheconfigParser()
00027 if usedefaultfrontierconfig:
00028 ccp.parseString ( self.defaultfrontierConfigString() )
00029 else:
00030 ccp.parse (cacheconfigpath)
00031 self.__connectString = self.__connectparser.fullfrontierStr(self.__connectparser.schemaname(), ccp.parameterdict())
00032 if self.__connectparser.protocol()=='oracle':
00033 if authpath:
00034 os.environ['CORAL_AUTH_PATH']=authpath
00035 else:
00036 os.environ['CORAL_AUTH_PATH']='.'
00037 if debugON :
00038 msg = coral.MessageStream ('')
00039 msg.setMsgVerbosity (coral.message_Level_Debug)
00040 self.__svc = coral.ConnectionService()
00041 except:
00042 if self.__svc: del self.__svc
00043 raise
00044 def openSession(self,isReadOnly=True,cpp2sqltype=[],sql2cpptype=[] ):
00045 try:
00046 session=None
00047 if self.__connectparser.protocol()=='frontier' or isReadOnly:
00048 session = self.__svc.connect(self.__connectString, accessMode = coral.access_ReadOnly)
00049 else:
00050 session = self.__svc.connect(self.__connectString, accessMode = coral.access_Update)
00051 for (cpptype,sqltype) in cpp2sqltype:
00052 session.typeConverter().setCppTypeForSqlType(cpptype,sqltype)
00053 for (sqltype,cpptype) in sql2cpptype:
00054 session.typeConverter().setSqlTypeForCppType(sqltype,cpptype)
00055 return session
00056 except:
00057 if session: del session
00058 raise
00059 def realConnectString(self):
00060 return self.__connectString
00061 def __del__(self):
00062 del self.__svc
00063 def svcHandle(self):
00064 return self.__svc
00065
00066 if __name__ == "__main__":
00067 svc=sessionManager('oracle://cms_orcoff_prep/cms_lumi_dev_offline',authpath='/afs/cern.ch/user/x/xiezhen',debugON=False)
00068 print svc.realConnectString()
00069 session=svc.openSession(isReadOnly=True,cpp2sqltype=[('unsigned int','NUMBER(10)'),('unsigned long long','NUMBER(20)')])
00070 session.transaction().start(True)
00071 session.transaction().commit()
00072 del session
00073 svc=sessionManager('frontier://LumiPrep/CMS_LUMI_DEV_OFFLINE',debugON=False)
00074 print svc.realConnectString()
00075 session=svc.openSession(isReadOnly=True,cpp2sqltype=[('unsigned int','NUMBER(10)'),('unsigned long long','NUMBER(20)')])
00076 del session