ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/COMP/RegSvc/src/python/ServiceDAO.py
Revision: 1.1
Committed: Mon May 18 20:17:43 2009 UTC (15 years, 11 months ago) by sekhri
Content type: text/x-python
Branch: MAIN
CVS Tags: HEAD
Log Message:
implementing reg service in WMCORE

File Contents

# Content
1 from DataStructures import *
2 from ServiceTypeDAO import *
3 from StatusDAO import *
4 from SqlGenerator import *
5
6 class ServiceDAO:
7 """
8 All the APIs for Service entity
9 """
10 def __init__(self, config):
11 self.config= config
12 self.objType = 'service'
13 self.sqlGenerator = SqlGenerator()
14 self.srvTypeDao = ServiceTypeDAO(self.config)
15 self.statusDao = StatusDAO(self.config)
16 def addService(self, object):
17 """
18 Add a service to the database
19 """
20 validate(self.objType, object)
21 sql = self.sqlGenerator.getInsertSql(self.objType, object)
22 self.config.debug(sql)
23 binds = object.copy()
24 listOfSrvTypes = self.srvTypeDao.listServiceTypes(object['servicetype'])
25 listOfStatus = self.statusDao.listStatus(object['status'])
26 if len(listOfSrvTypes) < 1: raise 'Service Type ' + str(object['servicetype']) + ' could not be found'
27 if len(listOfStatus) < 1: raise 'Status ' + str(object['status']) + ' could not be found'
28 if len(listOfSrvTypes) > 1: raise 'Mutiple Service types ' + str(listOfSrvTypes) + ' found. Only one should be found'
29 if len(listOfStatus) > 1: raise 'Multiple status ' + str(listOfStatus) + ' found. Only one should be found'
30
31
32 binds['servicetype'] = listOfSrvTypes[0]['id']
33 binds['status'] = listOfStatus[0]['id']
34 self.config.dbi.processData(sql, binds)
35
36 return self.listServices(object)
37
38
39 def listServices(self, object):
40 """
41 List services known to RegSvc according to the specific conditions
42 """
43
44 validate(self.objType, object, True)
45 sql = self.sqlGenerator.getSelectSql(self.objType, object)
46 self.config.debug(sql)
47 binds = object.copy()
48 listOfSrvTypes = self.srvTypeDao.listServiceTypes(object['servicetype'])
49 listOfStatus = self.statusDao.listStatus(object['status'])
50 if len(listOfSrvTypes) < 1: return []
51 if len(listOfStatus) < 1: return []
52 if len(listOfSrvTypes) > 1: raise 'Mutiple Service types ' + str(listOfSrvTypes) + ' found. Only one should be found'
53 if len(listOfStatus) > 1: raise 'Multiple status ' + str(listOfStatus) + ' found. Only one should be found'
54
55 binds['servicetype'] = listOfSrvTypes[0]['id']
56 binds['status'] = listOfStatus[0]['id']
57
58 result = self.config.dbi.processData(sql, binds)
59 result = self.config.formatDict(result)
60 for i in range(len(result)):
61 result[i]['servicetype'] = listOfSrvTypes[0]
62 result[i]['status'] = listOfStatus[0]
63 format(self.objType, result[i])
64 return result
65
66 def updateService(self, object):
67 """
68 Update the given service
69 """
70 validate(self.objType, object)
71 sql = self.sqlGenerator.getUpdateSql(self.objType, object)
72 self.config.debug(sql)
73 binds = object.copy()
74 listOfSrvTypes = self.srvTypeDao.listServiceTypes(object['servicetype'])
75 listOfStatus = self.statusDao.listStatus(object['status'])
76 if len(listOfSrvTypes) < 1: raise 'Service type ' + str(object['servicetype']) + ' could not be found'
77 if len(listOfStatus) < 1: raise 'Status ' + str(object['status']) + ' could not be found'
78 if len(listOfSrvTypes) > 1: raise 'Mutiple Service types ' + str(listOfSrvTypes) + ' found. Only one should be found'
79 if len(listOfStatus) > 1: raise 'Multiple status ' + str(listOfStatus) + ' found. Only one should be found'
80
81 binds['servicetype'] = listOfSrvTypes[0]['id']
82 binds['status'] = listOfStatus[0]['id']
83
84 self.config.dbi.processData(sql, binds)
85 return self.listServices(object)
86
87
88
89
90