CMS 3D CMS Logo

Public Member Functions | Private Attributes

python::tagInventory::tagInventory Class Reference

List of all members.

Public Member Functions

def __init__
def addEntriesReplaceService
def addEntry
def bulkInsertEntries
def cloneEntry
def createInventoryTable
def deleteAllEntries
def deleteEntryByName
def dropme
def existInventoryTable
def getAllEntries
def getEntryById
def getEntryByName
def getIDsByName
def modifyEntriesReplaceService
def replaceTagLabel

Private Attributes

 __session
 __tagInventoryIDName
 __tagInventoryTableColumns
 __tagInventoryTableHandle
 __tagInventoryTableName
 __tagInventoryTableNotNullColumns
 __tagInventoryTablePK

Detailed Description

Class manages tag inventory 

Definition at line 3 of file tagInventory.py.


Constructor & Destructor Documentation

def python::tagInventory::tagInventory::__init__ (   self,
  session 
)
Input: coral session handle

Definition at line 6 of file tagInventory.py.

00007                                   :
00008         """Input: coral session handle
00009         """
00010         self.__session = session
00011         self.__tagInventoryTableName=CommonUtils.inventoryTableName()
00012         self.__tagInventoryIDName=CommonUtils.inventoryIDTableName()
00013         self.__tagInventoryTableColumns = {'tagid':'unsigned long', 'tagname':'string', 'pfn':'string','recordname':'string', 'objectname':'string', 'labelname':'string'}
00014         self.__tagInventoryTableNotNullColumns = ['tagname','pfn','recordname','objectname']
00015         #self.__tagInventoryTableUniqueColumns = ['tagname']
        self.__tagInventoryTablePK = ('tagid')

Member Function Documentation

def python::tagInventory::tagInventory::addEntriesReplaceService (   self,
  newservicename 
)
clone all existing entries only servicename in pfn are different
return collection of new (oldtagid,newtagid) pair 

Definition at line 122 of file tagInventory.py.

00123                                                         :
00124         """ clone all existing entries only servicename in pfn are different
00125         return collection of new (oldtagid,newtagid) pair 
00126         """
00127         newtaglinks=[]
00128         transaction=self.__session.transaction()
00129         try:
00130             results=[]
00131             transaction.start(True)
00132             query = self.__session.nominalSchema().tableHandle(self.__tagInventoryTableName).newQuery()
00133             for columnName in self.__tagInventoryTableColumns:
00134                 query.addToOutputList(columnName)
00135             cursor=query.execute()
00136             while cursor.next():
00137                 tagid=cursor.currentRow()['tagid'].data()
00138                 tagname=cursor.currentRow()['tagname'].data()
00139                 pfn=cursor.currentRow()['pfn'].data()
00140                 (servicename,schemaname)=pfn.rsplit('/',1)
00141                 newpfn=('/').join([newservicename,schemaname])
00142                 #k=(' ').join([tagname,newpfn])
00143                 objname=cursor.currentRow()['objectname'].data()
00144                 redname=cursor.currentRow()['recordname'].data()
00145                 labname=cursor.currentRow()['labelname'].data()
00146                 #return a tuple
00147                 r=(tagid,tagname,newpfn,objname,redname,labname)
00148                 results.append(r)
00149             transaction.commit()
00150             del query
00151         except Exception, er:
00152             transaction.rollback()
00153             raise Exception, str(er)
00154         
00155         inv=tagInventory(self.__session)
00156         try:
00157             for r in results:
00158                 nd=Node.LeafNode()
00159                 oldtagid=r[0]
00160                 nd.tagname=r[1]
00161                 nd.pfn=r[2]
00162                 nd.objectname=r[3]
00163                 nd.recordname=r[4]
00164                 #if not r.items()[1][2] is None:
00165                 nd.labelname=r[5]
00166                 n=inv.addEntry(nd)
00167                 if n==0:
00168                     raise "addEntry returns 0"
00169                 newtaglinks.append((oldtagid,n))
00170             return newtaglinks
00171         except Exception, e:
00172             print str(e)
00173             raise Exception, str(e)
    
def python::tagInventory::tagInventory::addEntry (   self,
  leafNode 
)
Add entry into the inventory.\n
Input: base tag info. If identical data found already exists, do nothing
Output: tagid. if tagid=0, there's no new entry added, i.e.no new tagid

Definition at line 75 of file tagInventory.py.

00076                                   :
00077         """Add entry into the inventory.\n
00078         Input: base tag info. If identical data found already exists, do nothing
00079         Output: tagid. if tagid=0, there's no new entry added, i.e.no new tagid
00080         
00081         """
00082         tagid=0
00083         transaction=self.__session.transaction()
00084         duplicate=False
00085         try:
00086             transaction.start(True)
00087             schema = self.__session.nominalSchema()
00088             query = schema.tableHandle(self.__tagInventoryTableName).newQuery()
00089             condition='tagname=:tagname'
00090             conditionbindDict=coral.AttributeList()
00091             conditionbindDict.extend('tagname','string')
00092             conditionbindDict['tagname'].setData(leafNode.tagname)
00093             if len(leafNode.pfn)!=0:
00094                 condition+=' AND pfn=:pfn'
00095                 conditionbindDict.extend('pfn','string')
00096                 conditionbindDict['pfn'].setData(leafNode.pfn)
00097             query.setCondition(condition,conditionbindDict)
00098             #duplicate=dbop.existRow(self.__tagInventoryTableName,condition,conditionbindDict)
00099             cursor=query.execute()
00100             while( cursor.next() ):
00101                 duplicate=True
00102                 tagid=cursor.currentRow()['tagid'].data()
00103                 cursor.close()
00104             transaction.commit()
00105             del query
00106             #transaction.commit()
00107             if duplicate is False:
00108                 transaction.start(False)                
00109                 generator=IdGenerator.IdGenerator(schema)
00110                 tagid=generator.getNewID(self.__tagInventoryIDName)
00111                 tabrowValueDict={'tagid':tagid,'tagname':leafNode.tagname,'objectname':leafNode.objectname,'pfn':leafNode.pfn,'labelname':leafNode.labelname,'recordname':leafNode.recordname}
00112                 dbop=DBImpl.DBImpl(schema)
00113                 dbop.insertOneRow(self.__tagInventoryTableName,
00114                                   self.__tagInventoryTableColumns,
00115                                   tabrowValueDict)
00116                 generator.incrementNextID(self.__tagInventoryIDName)           
00117                 transaction.commit()
00118             return tagid
00119         except Exception, er:
00120             transaction.rollback()
00121             raise Exception, str(er)
        
def python::tagInventory::tagInventory::bulkInsertEntries (   self,
  entries 
)
insert a chunk of entries.
Input: entries [{tagid:unsigned long, tagname:string , pfn:string , recordname:string , objectname:string, labelname:string }]
Output: {oldtagid:newtagid} of the inserted entries. If tag already exists, old tagid is returned

Definition at line 420 of file tagInventory.py.

00420                                           : 
00421         """insert a chunk of entries.
00422         Input: entries [{tagid:unsigned long, tagname:string , pfn:string , recordname:string , objectname:string, labelname:string }]
00423         Output: {oldtagid:newtagid} of the inserted entries. If tag already exists, old tagid is returned
00424         """
00425         transaction=self.__session.transaction()
00426         results={}
00427         ihad=[]
00428         try:
00429             if self.existInventoryTable():
00430                 ihad=self.getAllEntries()
00431             else:    
00432                 self.createInventoryTable()
00433             #clean input list removing duplicates
00434             for e in entries:
00435                 for n in ihad:
00436                     if n.tagname==e['tagname'] and n.pfn==e['pfn']:
00437                         results[n.tagid]=n.tagid
00438                         entries.remove(e)
00439             transaction.start(False)
00440             query=self.__session.nominalSchema().tableHandle(self.__tagInventoryIDName).newQuery()
00441             query.addToOutputList('nextID')
00442             query.setForUpdate()
00443             cursor = query.execute()
00444             nextid=0
00445             while cursor.next():
00446                 nextid=cursor.currentRow()[0].data()
00447             idEditor = self.__session.nominalSchema().tableHandle(self.__tagInventoryIDName).dataEditor()
00448             inputData = coral.AttributeList()
00449             inputData.extend( 'delta', 'unsigned long' )
00450 
00451             delta=len(entries)
00452             if nextid==0:
00453                 nextid=1
00454                 delta=1
00455 
00456             inputData['delta'].setData(delta)
00457             idEditor.updateRows('nextID = nextID + :delta','',inputData)
00458 
00459             dataEditor=self.__session.nominalSchema().tableHandle(self.__tagInventoryTableName).dataEditor()
00460             insertdata=coral.AttributeList()
00461             insertdata.extend('tagid','unsigned long')
00462             insertdata.extend('tagname','string')
00463             insertdata.extend('pfn','string')
00464             insertdata.extend('recordname','string')
00465             insertdata.extend('objectname','string')
00466             insertdata.extend('labelname','string')
00467             bulkOperation=dataEditor.bulkInsert(insertdata,delta)
00468             for entry in entries:
00469                 insertdata['tagid'].setData(nextid)
00470                 insertdata['tagname'].setData(entry['tagname'])
00471                 insertdata['pfn'].setData(entry['pfn'])
00472                 insertdata['recordname'].setData(entry['recordname'])
00473                 insertdata['objectname'].setData(entry['objectname'])
00474                 insertdata['labelname'].setData(entry['labelname'])
00475                 bulkOperation.processNextIteration()
00476                 results[entry['tagid']]=nextid
00477                 nextid=nextid+1
00478             bulkOperation.flush()
00479             transaction.commit()
00480             del bulkOperation
00481             del query
00482             return results
00483         except Exception, e:
00484             transaction.rollback()
00485             raise Exception, str(e)
00486         
def python::tagInventory::tagInventory::cloneEntry (   self,
  sourcetagid,
  pfn 
)
clone an existing entry with different pfn parameter
Input: sourcetagid, pfn.
Output: tagid of the new entry. Return 0 in case no new entry created or required entry already exists. 

Definition at line 211 of file tagInventory.py.

00212                                             :
00213         """ clone an existing entry with different pfn parameter
00214         Input: sourcetagid, pfn.
00215         Output: tagid of the new entry. Return 0 in case no new entry created or required entry already exists. 
00216         """
00217         newtagid=sourcetagid
00218         if len(pfn)==0:
00219             return newtagid
00220         try:
00221             nd=self.getEntryById(sourcetagid)
00222             if nd.tagid==0:
00223                 return newtagid
00224             oldpfn=nd.pfn
00225             if oldpfn==pfn:
00226                 return nd.tagid
00227             transaction=self.__session.transaction()
00228             transaction.start(False)
00229             schema = self.__session.nominalSchema()
00230             generator=IdGenerator.IdGenerator(schema)
00231             newtagid=generator.getNewID(self.__tagInventoryIDName)
00232             tabrowValueDict={'tagid':newtagid,'tagname':nd.tagname,'objectname':nd.objectname,'pfn':pfn,'labelname':nd.labelname,'recordname':nd.recordname}
00233             dbop=DBImpl.DBImpl(schema)
00234             dbop.insertOneRow(self.__tagInventoryTableName,
00235                               self.__tagInventoryTableColumns,
00236                               tabrowValueDict)
00237             generator.incrementNextID(self.__tagInventoryIDName)
00238             transaction.commit()
00239             return newtagid
00240         except Exception, er:
00241             transaction.rollback()
00242             raise Exception, str(er)
        
def python::tagInventory::tagInventory::createInventoryTable (   self)
Create tag inventory table. Existing table will be deleted. 

Definition at line 45 of file tagInventory.py.

00046                                     :
00047         """Create tag inventory table. Existing table will be deleted. 
00048         """
00049         try:
00050             transaction=self.__session.transaction()
00051             transaction.start()
00052             schema = self.__session.nominalSchema()
00053             schema.dropIfExistsTable( self.__tagInventoryTableName )
00054             description = coral.TableDescription();
00055             description.setName( self.__tagInventoryTableName )
00056             for columnName, columnType in self.__tagInventoryTableColumns.items():
00057                 description.insertColumn(columnName, columnType)
00058             for columnName in self.__tagInventoryTableNotNullColumns :
00059                 description.setNotNullConstraint(columnName,True)
00060             #for columnName in self.__tagInventoryTableUniqueColumns :
00061                 #description.setUniqueConstraint(columnName)
00062             #combinedunique1=('pfn','recordname','objectname','labelname')
00063             #description.setUniqueConstraint(combinedunique1)
00064             #combinedunique2=('tagname','pfn')
00065             #description.setUniqueConstraint(combinedunique2)
00066             description.setPrimaryKey(  self.__tagInventoryTablePK )
00067             self.__tagInventoryTableHandle = schema.createTable( description )
00068             self.__tagInventoryTableHandle.privilegeManager().grantToPublic( coral.privilege_Select )
00069             #create also the associated id table
00070             generator=IdGenerator.IdGenerator(schema)
00071             generator.createIDTable(self.__tagInventoryIDName,True)
00072             transaction.commit()
00073         except Exception, er:
00074             transaction.rollback()
            raise Exception, str(er)
def python::tagInventory::tagInventory::deleteAllEntries (   self)
Delete all entries in the inventory

Definition at line 365 of file tagInventory.py.

00366                                 :
00367         """Delete all entries in the inventory
00368         """
00369         transaction=self.__session.transaction()
00370         try:
00371             transaction.start(False)
00372             schema = self.__session.nominalSchema()
00373             dbop=DBImpl.DBImpl(schema)
00374             inputData = coral.AttributeList()
00375             dbop.deleteRows(self.__tagInventoryTableName,
00376                             '',
00377                             inputData)
00378             transaction.commit()
00379         except Exception, e:
00380             transaction.rollback()
00381             raise Exception, str(e)
        
def python::tagInventory::tagInventory::deleteEntryByName (   self,
  tagname 
)
Delete entry with given tag name

Definition at line 382 of file tagInventory.py.

00383                                           :
00384         """Delete entry with given tag name
00385         """
00386         try:
00387             transaction=self.__session.transaction()
00388             transaction.start(False)
00389             schema = self.__session.nominalSchema()
00390             dbop=DBImpl.DBImpl(schema)
00391             inputData = coral.AttributeList()
00392             inputData.extend( "tagname","string" )
00393             inputData[0].setData(tagname)
00394             dbop.deleteRows(self.__tagInventoryTableName,
00395                             'tagname=:tagname',
00396                             inputData)
00397             transaction.commit()
00398         except Exception, e:
00399             transaction.rollback()
00400             raise Exception, str(e)
        
def python::tagInventory::tagInventory::dropme (   self)
Drop inventory related tables

Definition at line 16 of file tagInventory.py.

00017                       :
00018         """Drop inventory related tables
00019         """
00020         try:
00021             transaction=self.__session.transaction()
00022             transaction.start(False)
00023             schema = self.__session.nominalSchema()
00024             schema.dropIfExistsTable( self.__tagInventoryIDName )
00025             schema.dropIfExistsTable( self.__tagInventoryTableName )
00026             transaction.commit()
00027         except Exception, er:
00028             transaction.rollback()
00029             raise Exception, str(er)
00030         return
    
def python::tagInventory::tagInventory::existInventoryTable (   self)
Check if inventory table exists

Definition at line 31 of file tagInventory.py.

00032                                    :
00033         """Check if inventory table exists
00034         """
00035         try:
00036             transaction=self.__session.transaction()
00037             transaction.start(True)
00038             schema = self.__session.nominalSchema()
00039             result=schema.existsTable(self.__tagInventoryTableName)
00040             transaction.commit()
00041             #print result
00042         except Exception, er:
00043             transaction.rollback()
00044             raise Exception, str(er)
        return result
def python::tagInventory::tagInventory::getAllEntries (   self)
Get all entries in the inventory
Output: list of leafNode objects

Definition at line 315 of file tagInventory.py.

00316                              :
00317         """Get all entries in the inventory
00318         Output: list of leafNode objects
00319         """
00320         result=[]
00321         transaction=self.__session.transaction()
00322         try:
00323             transaction.start(True)
00324             query = self.__session.nominalSchema().tableHandle(self.__tagInventoryTableName).newQuery()
00325             for columnName in self.__tagInventoryTableColumns:
00326                 query.addToOutputList(columnName)    
00327             cursor = query.execute()
00328             while ( cursor.next() ):
00329                 leafnode = Node.LeafNode()
00330                 leafnode.tagid=cursor.currentRow()['tagid'].data()
00331                 leafnode.tagname=cursor.currentRow()['tagname'].data()
00332                 leafnode.objectname=cursor.currentRow()['objectname'].data()
00333                 leafnode.pfn=cursor.currentRow()['pfn'].data()
00334                 leafnode.recordname=cursor.currentRow()['recordname'].data()
00335                 leafnode.labelname=cursor.currentRow()['labelname'].data()
00336                 result.append(leafnode)
00337             transaction.commit()
00338             del query
00339             return result
00340         except Exception, e:
00341             transaction.rollback()
            raise Exception, str(e)
def python::tagInventory::tagInventory::getEntryById (   self,
  tagId 
)
Get basic tag from inventory by id.\n
Input: tagid
Output: leafNode

Definition at line 283 of file tagInventory.py.

00284                                    :
00285         """Get basic tag from inventory by id.\n
00286         Input: tagid
00287         Output: leafNode
00288         """
00289         leafnode = Node.LeafNode()
00290         transaction=self.__session.transaction()
00291         try:
00292             transaction.start(True)
00293             query = self.__session.nominalSchema().tableHandle(self.__tagInventoryTableName).newQuery()
00294             for columnName in self.__tagInventoryTableColumns:
00295                 query.addToOutputList(columnName)
00296             condition = "tagid=:tagid"
00297             conditionData = coral.AttributeList()
00298             conditionData.extend( 'tagid','unsigned long' )
00299             conditionData['tagid'].setData(tagId)
00300             query.setCondition( condition, conditionData)
00301             cursor = query.execute()
00302             while ( cursor.next() ):
00303                 #print 'got it'
00304                 leafnode.tagid=cursor.currentRow()['tagid'].data()
00305                 leafnode.tagname=cursor.currentRow()['tagname'].data()
00306                 leafnode.objectname=cursor.currentRow()['objectname'].data()
00307                 leafnode.pfn=cursor.currentRow()['pfn'].data()
00308                 leafnode.labelname=cursor.currentRow()['labelname'].data()
00309                 leafnode.recordname=cursor.currentRow()['recordname'].data()
00310             transaction.commit()
00311             del query
00312             return leafnode
00313         except Exception, e:
00314             transaction.rollback()
            raise Exception, str(e)
def python::tagInventory::tagInventory::getEntryByName (   self,
  tagName,
  pfn 
)
Get basic tag from inventory by tagName+pfn. pfn can be empty\n
Input: tagname,pfn
Output: leafNode
throw if more than one entry is found.

Definition at line 243 of file tagInventory.py.

00244                                             :
00245         """Get basic tag from inventory by tagName+pfn. pfn can be empty\n
00246         Input: tagname,pfn
00247         Output: leafNode
00248         throw if more than one entry is found.
00249         """
00250         leafnode = Node.LeafNode()
00251         transaction=self.__session.transaction()
00252         try:
00253             transaction.start(True)
00254             query = self.__session.nominalSchema().tableHandle(self.__tagInventoryTableName).newQuery()
00255             for columnName in self.__tagInventoryTableColumns:
00256                 query.addToOutputList(columnName)
00257             conditionData = coral.AttributeList()
00258             condition = "tagname=:tagname"
00259             conditionData.extend( 'tagname','string' )
00260             conditionData['tagname'].setData(tagName)
00261             if len(pfn)!=0 :
00262                 condition += " AND pfn=:pfn"
00263                 conditionData.extend( 'pfn','string' )
00264                 conditionData['pfn'].setData(pfn)
00265             query.setCondition(condition,conditionData)
00266             cursor = query.execute()
00267             counter=0
00268             while ( cursor.next() ):
00269                 if counter > 0 :
00270                     raise ValueError, "tagName "+tagName+" is not unique, please further specify parameter pfn"
00271                 counter+=1
00272                 leafnode.tagid=cursor.currentRow()['tagid'].data()
00273                 leafnode.tagname=cursor.currentRow()['tagname'].data()
00274                 leafnode.objectname=cursor.currentRow()['objectname'].data()
00275                 leafnode.pfn=cursor.currentRow()['pfn'].data()
00276                 leafnode.labelname=cursor.currentRow()['labelname'].data()
00277                 leafnode.recordname=cursor.currentRow()['recordname'].data()
00278             transaction.commit()
00279             del query
00280             return leafnode
00281         except Exception, e:
00282             transaction.rollback()
            raise Exception, str(e)
def python::tagInventory::tagInventory::getIDsByName (   self,
  name 
)
get tagids correspond to a given tag name

Definition at line 342 of file tagInventory.py.

00343                                   :
00344         """get tagids correspond to a given tag name
00345         """
00346         transaction=self.__session.transaction()
00347         ids=[]
00348         try:
00349             transaction.start(True)
00350             query = self.__session.nominalSchema().tableHandle(self.__tagInventoryTableName).newQuery()
00351             condition='tagname = :tagname'
00352             conditionBindData=coral.AttributeList()
00353             conditionBindData.extend('tagname','string')
00354             conditionBindData['tagname'].setData(name)
00355             query.addToOutputList(tagid)
00356             query.setCondition(condition,conditionBindData)
00357             cursor = query.execute()
00358             while ( cursor.next() ):
00359                 tagid=cursor.currentRow()['tagid'].data()
00360                 ids.append(tagid)
00361             transaction.commit()
00362         except Exception, e:
00363             transaction.rollback()
00364             raise Exception, str(e)
        return ids
def python::tagInventory::tagInventory::modifyEntriesReplaceService (   self,
  newservicename 
)
replace all existing entries replace service name in pfn
no change in other parameters

Definition at line 174 of file tagInventory.py.

00175                                                            :
00176         """ replace all existing entries replace service name in pfn
00177         no change in other parameters
00178         """
00179         transaction=self.__session.transaction()
00180         try:
00181             allpfns=[]
00182             transaction.start(True)
00183             query = self.__session.nominalSchema().tableHandle(self.__tagInventoryTableName).newQuery()
00184             query.addToOutputList('pfn')
00185             cursor=query.execute()
00186             while cursor.next():
00187                 pfn=cursor.currentRow()['pfn'].data()
00188                 allpfns.append(pfn)
00189             transaction.commit()
00190             del query
00191         except Exception, er:
00192             transaction.rollback()
00193             del query
00194             raise Exception, str(er)
00195         try:
00196             transaction.start(False)
00197             editor = self.__session.nominalSchema().tableHandle(self.__tagInventoryTableName).dataEditor()
00198             inputData = coral.AttributeList()
00199             inputData.extend('newpfn','string')
00200             inputData.extend('oldpfn','string')
00201             for pfn in allpfns:
00202                 (servicename,schemaname)=pfn.rsplit('/',1)
00203                 newpfn=('/').join([newservicename,schemaname])
00204                 inputData['newpfn'].setData(newpfn)
00205                 inputData['oldpfn'].setData(pfn)
00206                 editor.updateRows( "pfn = :newpfn", "pfn = :oldpfn", inputData )
00207             transaction.commit()
00208         except Exception, e:
00209             transaction.rollback()
00210             raise Exception, str(e)

def python::tagInventory::tagInventory::replaceTagLabel (   self,
  tagname,
  label 
)
Replace the run time label of the given tag

Definition at line 401 of file tagInventory.py.

00402                                                :
00403         """Replace the run time label of the given tag
00404         """
00405         try:
00406             transaction=self.__session.transaction()
00407             transaction.start(False)
00408             schema = self.__session.nominalSchema()
00409             inputData = coral.AttributeList()
00410             inputData.extend( "labelname","string" )
00411             inputData.extend( "tagname", "string" ) 
00412             inputData[0].setData(label)
00413             inputData[1].setData(tagname)
00414             editor = schema.tableHandle(self.__tagInventoryTableName).dataEditor()
00415             editor.updateRows( "labelname=:labelname", "tagname=:tagname", inputData )
00416             transaction.commit()
00417         except Exception, e:
00418             transaction.rollback()
00419             raise Exception, str(e)


Member Data Documentation

Definition at line 7 of file tagInventory.py.

Definition at line 7 of file tagInventory.py.

Definition at line 7 of file tagInventory.py.

Definition at line 46 of file tagInventory.py.

Definition at line 7 of file tagInventory.py.

Definition at line 7 of file tagInventory.py.

Definition at line 7 of file tagInventory.py.