CMS 3D CMS Logo

DBImpl.py

Go to the documentation of this file.
00001 import coral
00002 import IdGenerator
00003         
00004 class DBImpl(object):
00005     """Class wrap up all the database operations.\n
00006     """
00007     def __init__( self , schema):
00008         """Input: coral schema handle.
00009         """
00010         self.__schema = schema
00011     def existRow( self, tableName, condition, conditionbindDict):
00012         """Return true if one row fulfills the selection criteria
00013         """
00014         try:
00015             tableHandle = self.__schema.tableHandle(tableName)
00016             query = tableHandle.newQuery()
00017             query.setCondition(condition,conditionbindDict)
00018             cursor = query.execute()
00019             result=False
00020             while ( cursor.next() ):
00021                 result=True
00022                 cursor.close()
00023             del query
00024             return result
00025         except Exception, e:
00026             raise Exception, str(e)
00027     def insertOneRow( self, tableName, tabrowDefDict, tabrowValueDict ):
00028         """Insert row 
00029         """
00030         try:
00031             tableHandle = self.__schema.tableHandle(tableName)
00032             editor = tableHandle.dataEditor()
00033             inputData = coral.AttributeList()
00034             for name,type in tabrowDefDict.items():
00035                # print name, type
00036                 inputData.extend( name, type )
00037                 inputData[name].setData(tabrowValueDict[name])
00038             editor.insertRow( inputData )
00039         except Exception, e:
00040             raise Exception, str(e)
00041     def deleteRows( self, tableName, condition, conditionbindDict ):
00042         """Delete row(s)
00043         """
00044         try:
00045             tableHandle = self.__schema.tableHandle(tableName)
00046             editor = tableHandle.dataEditor()
00047             editor.deleteRows( condition, conditionbindDict )
00048         except Exception, e:
00049             raise Exception, str(e)
00050     def dropTable( self, tableName ):
00051         """Drop specified table.
00052         """
00053         self.__schema.dropIfExistsTable( tableName )
00054     def tableExists( self, tableName ):
00055         """Tell whether table exists
00056         """
00057         try:
00058             self.__schema.tableHandle(tableName)
00059             return True
00060         except coral.Exception, e:
00061             return False
00062 
00063 if __name__ == "__main__":
00064     pass

Generated on Tue Jun 9 17:26:14 2009 for CMSSW by  doxygen 1.5.4