Beispiel #1
0
 def createIDTable(self, idtableName, deleteOld=True):
     """Create ID table 'tableName_ID' for the given table.\n
     Input: name of the table which needs new associated id table
     Output: name of the id table created
     """
     dbop = DBImpl.DBImpl(self.__schema)
     try:
         if dbop.tableExists(idtableName) is True:
             if deleteOld is True:
                 dbop.dropTable(idtableName)
             else:
                 return
         description = coral.TableDescription()
         description.setName(idtableName)
         description.insertColumn(self.__idTableColumnName,
                                  self.__idTableColumnType)
         idtableHandle = self.__schema.createTable(description)
         idtableHandle.privilegeManager().grantToPublic(
             coral.privilege_Select)
         inputData = coral.AttributeList()
         editor = idtableHandle.dataEditor()
         editor.rowBuffer(inputData)
         inputData[self.__idTableColumnName].setData(1)
         editor.insertRow(inputData)
     except Exception, e:
         raise Exception, str(e)
Beispiel #2
0
 def insertNode( self, node, parentLabel='ROOT' ):
     """Append a new node to specified parent. \n
     Silently ignore duplicate entry \n
     Input: new node. \n
     Input: name of the parent node. \n
     Output: result nodeid  
     """
     nodeid=node.nodeid
     nodelabel=node.nodelabel
     parentid=0
     tagid=node.tagid
     lft=1
     rgt=2
     globalsince=node.globalsince
     globaltill=node.globaltill
     duplicate=False
     transaction=self.__session.transaction()
     try:
         if parentLabel != 'ROOT':
                 parentNode=self.getNode(parentLabel)
                 if parentNode.empty():
                     raise ValueError,"non-existing parent node "+parentLabel
                 parentid=parentNode.nodeid
                 lft=parentNode.rgt
                 rgt=parentNode.rgt+1
         ##start readonly transaction
         transaction.start(False)
         condition='nodelabel=:nodelabel'
         conditionbindDict=coral.AttributeList()
         conditionbindDict.extend('nodelabel','string')
         conditionbindDict['nodelabel'].setData(nodelabel)
         dbop=DBImpl.DBImpl(self.__session.nominalSchema())
         duplicate=dbop.existRow(self.__tagTreeTableName,condition,conditionbindDict)
         if duplicate is False:                
             generator=IdGenerator.IdGenerator(self.__session.nominalSchema())
             nodeid=generator.getNewID(self.__tagTreeIDs)
         if duplicate is False:                
             tabrowValueDict={'nodeid':nodeid, 'nodelabel':nodelabel,
                              'lft':lft, 'rgt':rgt, 'parentid':parentid,
                              'tagid':tagid, 'globalsince':globalsince,
                              'globaltill':globaltill
                              }
             if parentLabel != 'ROOT':
                 self.__openGap(self.__session.nominalSchema().tableHandle(self.__tagTreeTableName),parentNode.rgt,1 )
             dbop.insertOneRow(self.__tagTreeTableName,
                               self.__tagTreeTableColumns,
                               tabrowValueDict)
             generator.incrementNextID(self.__tagTreeIDs)
         transaction.commit()
         return nodeid
     except coral.Exception, er:
         transaction.rollback()
         raise Exception, str(er)
Beispiel #3
0
 def 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
     
     """
     tagid = 0
     transaction = self.__session.transaction()
     duplicate = False
     try:
         transaction.start(True)
         schema = self.__session.nominalSchema()
         query = schema.tableHandle(self.__tagInventoryTableName).newQuery()
         condition = 'tagname=:tagname'
         conditionbindDict = coral.AttributeList()
         conditionbindDict.extend('tagname', 'string')
         conditionbindDict['tagname'].setData(leafNode.tagname)
         if len(leafNode.pfn) != 0:
             condition += ' AND pfn=:pfn'
             conditionbindDict.extend('pfn', 'string')
             conditionbindDict['pfn'].setData(leafNode.pfn)
         query.setCondition(condition, conditionbindDict)
         #duplicate=dbop.existRow(self.__tagInventoryTableName,condition,conditionbindDict)
         cursor = query.execute()
         while (next(cursor)):
             duplicate = True
             tagid = cursor.currentRow()['tagid'].data()
             cursor.close()
         transaction.commit()
         del query
         #transaction.commit()
         if duplicate is False:
             transaction.start(False)
             generator = IdGenerator.IdGenerator(schema)
             tagid = generator.getNewID(self.__tagInventoryIDName)
             tabrowValueDict = {
                 'tagid': tagid,
                 'tagname': leafNode.tagname,
                 'objectname': leafNode.objectname,
                 'pfn': leafNode.pfn,
                 'labelname': leafNode.labelname,
                 'recordname': leafNode.recordname
             }
             dbop = DBImpl.DBImpl(schema)
             dbop.insertOneRow(self.__tagInventoryTableName,
                               self.__tagInventoryTableColumns,
                               tabrowValueDict)
             generator.incrementNextID(self.__tagInventoryIDName)
             transaction.commit()
         return tagid
     except Exception, er:
         transaction.rollback()
         raise Exception, str(er)
Beispiel #4
0
 def deleteAllEntries(self):
     """Delete all entries in the inventory
     """
     transaction = self.__session.transaction()
     try:
         transaction.start(False)
         schema = self.__session.nominalSchema()
         dbop = DBImpl.DBImpl(schema)
         inputData = coral.AttributeList()
         dbop.deleteRows(self.__tagInventoryTableName, '', inputData)
         transaction.commit()
     except Exception, e:
         transaction.rollback()
         raise Exception, str(e)
Beispiel #5
0
 def bulkinsertComments( self, tableName,bulkinput):
     """bulk insert comments for a given table
     bulkinput [{'entryid':unsigned long, 'tablename':string,'comment':string}]
     """
     transaction=self.__session.transaction()
     try:
         transaction.start(False)
         schema = self.__session.nominalSchema()
         dbop=DBImpl.DBImpl(schema)
         dbop.bulkInsert(CommonUtils.commentTableName(),self.__entryCommentTableColumns,bulkinput)
         transaction.commit()  
     except Exception, e:
         transaction.rollback()
         raise Exception, str(e)    
Beispiel #6
0
 def insertComment( self, tablename, entryid,comment ):
     """insert comment on the given entry of given table
     """
     transaction=self.__session.transaction()
     try:
         transaction.start(False)
         tabrowValueDict={'entryid':entryid,'tablename':tablename,'comment':comment}
         schema = self.__session.nominalSchema()
         dbop=DBImpl.DBImpl(schema)
         dbop.insertOneRow(CommonUtils.commentTableName(),self.__entryCommentTableColumns,tabrowValueDict)
         transaction.commit()
     except Exception, e:
         transaction.rollback()
         raise Exception, str(e)
Beispiel #7
0
 def clearAllEntriesForTable( self, tablename ):
     """delete all entries related with given table
     """
     transaction=self.__session.transaction()
     try:
         transaction.start(False)
         dbop=DBImpl.DBImpl(self.__session.nominalSchema())
         condition='tablename = :tablename'
         conditionbindDict=coral.AttributeList()
         conditionbindDict.extend('tablename','string')
         conditionbindDict['tablename'].setData(tablename)
         dbop.deleteRows(CommonUtils.commentTableName(),condition,conditionbindDict)
         transaction.commit()
     except Exception, e:
         transaction.rollback()
         raise Exception, str(e)
Beispiel #8
0
 def deleteEntryByName(self, tagname):
     """Delete entry with given tag name
     """
     try:
         transaction = self.__session.transaction()
         transaction.start(False)
         schema = self.__session.nominalSchema()
         dbop = DBImpl.DBImpl(schema)
         inputData = coral.AttributeList()
         inputData.extend("tagname", "string")
         inputData[0].setData(tagname)
         dbop.deleteRows(self.__tagInventoryTableName, 'tagname=:tagname',
                         inputData)
         transaction.commit()
     except Exception, e:
         transaction.rollback()
         raise Exception, str(e)
Beispiel #9
0
 def deleteCommentForId( self, tablename, entryid):
     """delete selected comment entry 
     """
     transaction=self.__session.transaction()
     try:
         transaction.start(False)
         dbop=DBImpl.DBImpl(self.__session.nominalSchema())
         condition='tablename = :tablename AND entryid = :entryid'
         conditionbindDict=coral.AttributeList()
         conditionbindDict.extend('tablename','string')
         conditionbindDict.extend('entryid','unsigned long')
         conditionbindDict['tablename'].setData(tablename)
         conditionbindDict['entryid'].setData(entryid)
         dbop.deleteRows(CommonUtils.commentTableName(),condition,conditionbindDict)
         transaction.commit()
     except Exception, e:
         transaction.rollback()
         raise Exception, str(e)
Beispiel #10
0
 def 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. 
     """
     newtagid = sourcetagid
     if len(pfn) == 0:
         return newtagid
     try:
         nd = self.getEntryById(sourcetagid)
         if nd.tagid == 0:
             return newtagid
         oldpfn = nd.pfn
         if oldpfn == pfn:
             return nd.tagid
         transaction = self.__session.transaction()
         transaction.start(False)
         schema = self.__session.nominalSchema()
         generator = IdGenerator.IdGenerator(schema)
         newtagid = generator.getNewID(self.__tagInventoryIDName)
         tabrowValueDict = {
             'tagid': newtagid,
             'tagname': nd.tagname,
             'objectname': nd.objectname,
             'pfn': pfn,
             'labelname': nd.labelname,
             'recordname': nd.recordname
         }
         dbop = DBImpl.DBImpl(schema)
         dbop.insertOneRow(self.__tagInventoryTableName,
                           self.__tagInventoryTableColumns, tabrowValueDict)
         generator.incrementNextID(self.__tagInventoryIDName)
         transaction.commit()
         return newtagid
     except Exception, er:
         transaction.rollback()
         raise Exception, str(er)