Go to the documentation of this file.00001
00002 def inventoryTableName():
00003 return 'TAGINVENTORY_TABLE'
00004 def inventoryIDTableName():
00005 return 'TAGINVENTORY_IDS'
00006 def treeTableName(treename):
00007 return 'TAGTREE_TABLE_'+str.upper(treename)
00008 def treeIDTableName(treename):
00009 return 'TAGTREE_'+str.upper(treename)+'_IDS'
00010 def commentTableName():
00011 return 'ENTRYCOMMENT_TABLE'
00012
00013 import coral
00014 def dropAllTreeTables(dbsession):
00015 """drop all tagtree related tables
00016 """
00017 try:
00018 dbsession.transaction().start(False)
00019 tablelist = dbsession.nominalSchema().listTables()
00020 for tname in tablelist:
00021 if tname.find('TAGTREE_') != -1:
00022 dbsession.nominalSchema().dropTable(tname)
00023 dbsession.transaction().commit()
00024 except Exception, e:
00025 raise Exception, str(e)
00026
00027 def tagInTrees(dbsession,tagname,pfn=''):
00028 """returns the tree names which contain the given tag
00029 select tagid from taginventory_table where tagname=tagname
00030 select count(*) from tablename where tablename.tagid=tagid
00031 """
00032 try:
00033 dbsession.transaction().start(True)
00034 invquery = dbsession.nominalSchema().tableHandle(inventoryTableName()).newQuery()
00035 conditionbindDict=coral.AttributeList()
00036 conditionbindDict.extend('tagname','string')
00037 conditionbindDict['tagname'].setData(tagname)
00038 condition='tagname = :tagname'
00039 if len(pfn) !=0 :
00040 condition+=' AND pfn = :pfn'
00041 conditionbindDict.extend('pfn','string')
00042 conditionbindDict['pfn'].setData(pfn)
00043 invquery.setCondition(condition,conditionbindDict)
00044 invquery.addToOutputList('tagid')
00045 invquery.addToOutputList('pfn')
00046 cursor = invquery.execute()
00047 tagidmap={}
00048 while ( cursor.next() ):
00049 tagid=cursor.currentRow()['tagid'].data()
00050 pfn=cursor.currentRow()['pfn'].data()
00051 tagidmap[pfn]=tagid
00052 cursor.close()
00053 dbsession.transaction().commit()
00054 del invquery
00055 if len(tagidmap)==0:
00056 return tagidmap
00057
00058 result={}
00059 treetablelist=[]
00060 dbsession.transaction().start(True)
00061 tablelist = dbsession.nominalSchema().listTables()
00062 for t in tablelist:
00063 if t.find('TAGTREE_TABLE_')!= -1:
00064 treetablelist.append(t)
00065 for (pfn,tagid) in tagidmap.items():
00066 result[pfn]=[]
00067 condition='tagid = :tagid'
00068 for t in treetablelist:
00069 conditionBind=coral.AttributeList()
00070 conditionBind.extend('tagid','unsigned long')
00071 conditionBind['tagid'].setData(tagid)
00072 q=dbsession.nominalSchema().tableHandle(t).newQuery()
00073 q.addToOutputList('count(*)','count')
00074 myresult=coral.AttributeList()
00075 myresult.extend('count','unsigned long')
00076 q.defineOutput(myresult)
00077 q.setCondition(condition,conditionBind)
00078 cr=q.execute()
00079 while (cr.next()):
00080 if cr.currentRow()['count'].data()!=0:
00081 result[pfn].append(t[len('TAGTREE_TABLE_'):])
00082 cr.close()
00083 del q
00084 dbsession.transaction().commit()
00085 return result
00086 except Exception, e:
00087 raise Exception, str(e)
00088
00089 if __name__ == "__main__":
00090
00091
00092 svc = coral.ConnectionService()
00093 session = svc.connect( 'sqlite_file:testInventory.db',
00094 accessMode = coral.access_Update )
00095 try:
00096 print 'TEST 1'
00097 intrees=tagInTrees(session,'Tracker_Geometry_CRUZET3')
00098 print intrees
00099 print 'TEST 2'
00100 hello=tagInTrees(session,'Tracker_Geometry_CRUZ3')
00101 print hello
00102 print 'TEST 3'
00103 kitty=tagInTrees(session,'Tracker_Geometry_CRUZET3','pfnme')
00104 print kitty
00105 print 'TEST 4'
00106 mikey=tagInTrees(session,'Tracker_Geometry_CRUZET3','frontier://(proxyurl=https://localhost:3128)(serverurl=https://frontier1.cms:8000/FrontierOnProd)(serverurl=https://frontier2.cms:8000/FrontierOnProd)(retrieve-ziplevel=0)/CMS_COND_20X_ALIGNMENT')
00107 print mikey
00108 del session
00109 except Exception, e:
00110 print "Failed in unit test"
00111 print str(e)
00112 del session