server/pool.py
changeset 8696 0bb18407c053
parent 8544 3d049071957e
child 9456 a79e88aad555
equal deleted inserted replaced
8695:358d8bed9626 8696:0bb18407c053
    61     def commit(self):
    61     def commit(self):
    62         """commit the current transaction for this user"""
    62         """commit the current transaction for this user"""
    63         # FIXME: what happends if a commit fail
    63         # FIXME: what happends if a commit fail
    64         # would need a two phases commit or like, but I don't know how to do
    64         # would need a two phases commit or like, but I don't know how to do
    65         # this using the db-api...
    65         # this using the db-api...
    66         for source, cnx in self.source_cnxs.values():
    66         for source, cnx in self.source_cnxs.itervalues():
    67             # let exception propagates
    67             # let exception propagates
    68             cnx.commit()
    68             cnx.commit()
    69 
    69 
    70     def rollback(self):
    70     def rollback(self):
    71         """rollback the current transaction for this user"""
    71         """rollback the current transaction for this user"""
    72         for source, cnx in self.source_cnxs.values():
    72         for source, cnx in self.source_cnxs.itervalues():
    73             # catch exceptions, rollback other sources anyway
    73             # catch exceptions, rollback other sources anyway
    74             try:
    74             try:
    75                 cnx.rollback()
    75                 cnx.rollback()
    76             except Exception:
    76             except Exception:
    77                 source.critical('rollback error', exc_info=sys.exc_info())
    77                 source.critical('rollback error', exc_info=sys.exc_info())
    81 
    81 
    82     def close(self, i_know_what_i_do=False):
    82     def close(self, i_know_what_i_do=False):
    83         """close all connections in the set"""
    83         """close all connections in the set"""
    84         if i_know_what_i_do is not True: # unexpected closing safety belt
    84         if i_know_what_i_do is not True: # unexpected closing safety belt
    85             raise RuntimeError('connections set shouldn\'t be closed')
    85             raise RuntimeError('connections set shouldn\'t be closed')
    86         for cu in self._cursors.values():
    86         for cu in self._cursors.itervalues():
    87             try:
    87             try:
    88                 cu.close()
    88                 cu.close()
    89             except Exception:
    89             except Exception:
    90                 continue
    90                 continue
    91         for _, cnx in self.source_cnxs.values():
    91         for _, cnx in self.source_cnxs.itervalues():
    92             try:
    92             try:
    93                 cnx.close()
    93                 cnx.close()
    94             except Exception:
    94             except Exception:
    95                 continue
    95                 continue
    96 
    96 
   100         """connections set is being set on a session"""
   100         """connections set is being set on a session"""
   101         self.check_connections()
   101         self.check_connections()
   102 
   102 
   103     def cnxset_freed(self):
   103     def cnxset_freed(self):
   104         """connections set is being freed from a session"""
   104         """connections set is being freed from a session"""
   105         for source, cnx in self.source_cnxs.values():
   105         for source, cnx in self.source_cnxs.itervalues():
   106             source.cnxset_freed(cnx)
   106             source.cnxset_freed(cnx)
   107 
   107 
   108     def sources(self):
   108     def sources(self):
   109         """return the source objects handled by this connections set"""
   109         """return the source objects handled by this connections set"""
   110         # implementation details of flying insert requires the system source
   110         # implementation details of flying insert requires the system source
   112         yield self.source_cnxs['system'][0]
   112         yield self.source_cnxs['system'][0]
   113         for uri, (source, cnx) in self.source_cnxs.items():
   113         for uri, (source, cnx) in self.source_cnxs.items():
   114             if uri == 'system':
   114             if uri == 'system':
   115                 continue
   115                 continue
   116             yield source
   116             yield source
   117         #return [source_cnx[0] for source_cnx in self.source_cnxs.values()]
   117         #return [source_cnx[0] for source_cnx in self.source_cnxs.itervalues()]
   118 
   118 
   119     def source(self, uid):
   119     def source(self, uid):
   120         """return the source object with the given uri"""
   120         """return the source object with the given uri"""
   121         return self.source_cnxs[uid][0]
   121         return self.source_cnxs[uid][0]
   122 
   122