server/session.py
changeset 2234 1fbcf202882d
parent 2200 25bb65dc4559
child 2306 95da5d9f0870
equal deleted inserted replaced
2209:2b91abd9f5a4 2234:1fbcf202882d
    82 
    82 
    83     def etype_class(self, etype):
    83     def etype_class(self, etype):
    84         """return an entity class for the given entity type"""
    84         """return an entity class for the given entity type"""
    85         return self.vreg.etype_class(etype)
    85         return self.vreg.etype_class(etype)
    86 
    86 
    87     def entity(self, eid):
       
    88         """return a result set for the given eid"""
       
    89         return self.eid_rset(eid).get_entity(0, 0)
       
    90 
       
    91     def system_sql(self, sql, args=None):
    87     def system_sql(self, sql, args=None):
    92         """return a sql cursor on the system database"""
    88         """return a sql cursor on the system database"""
    93         if not sql.split(None, 1)[0].upper() == 'SELECT':
    89         if not sql.split(None, 1)[0].upper() == 'SELECT':
    94             self.mode = 'write'
    90             self.mode = 'write'
    95         cursor = self.pool['system']
    91         cursor = self.pool['system']
   268         """commit the current session's transaction"""
   264         """commit the current session's transaction"""
   269         if self.pool is None:
   265         if self.pool is None:
   270             assert not self.pending_operations
   266             assert not self.pending_operations
   271             self.transaction_data.clear()
   267             self.transaction_data.clear()
   272             self._touch()
   268             self._touch()
       
   269             self.debug('commit session %s done (no db activity)', self.id)
   273             return
   270             return
   274         if self.commit_state:
   271         if self.commit_state:
   275             return
   272             return
   276         # on rollback, an operation should have the following state
   273         # on rollback, an operation should have the following state
   277         # information:
   274         # information:
   309         """rollback the current session's transaction"""
   306         """rollback the current session's transaction"""
   310         if self.pool is None:
   307         if self.pool is None:
   311             assert not self.pending_operations
   308             assert not self.pending_operations
   312             self.transaction_data.clear()
   309             self.transaction_data.clear()
   313             self._touch()
   310             self._touch()
       
   311             self.debug('rollback session %s done (no db activity)', self.id)
   314             return
   312             return
   315         try:
   313         try:
   316             while self.pending_operations:
   314             while self.pending_operations:
   317                 try:
   315                 try:
   318                     operation = self.pending_operations.pop(0)
   316                     operation = self.pending_operations.pop(0)
   319                     operation.handle_event('rollback_event')
   317                     operation.handle_event('rollback_event')
   320                 except:
   318                 except:
   321                     self.critical('rollback error', exc_info=sys.exc_info())
   319                     self.critical('rollback error', exc_info=sys.exc_info())
   322                     continue
   320                     continue
   323             self.pool.rollback()
   321             self.pool.rollback()
       
   322             self.debug('rollback for session %s done', self.id)
   324         finally:
   323         finally:
   325             self._touch()
   324             self._touch()
   326             self.pending_operations[:] = []
   325             self.pending_operations[:] = []
   327             self.transaction_data.clear()
   326             self.transaction_data.clear()
   328             if reset_pool:
   327             if reset_pool:
   356         try:
   355         try:
   357             return self._threaddata.transaction_data
   356             return self._threaddata.transaction_data
   358         except AttributeError:
   357         except AttributeError:
   359             self._threaddata.transaction_data = {}
   358             self._threaddata.transaction_data = {}
   360             return self._threaddata.transaction_data
   359             return self._threaddata.transaction_data
   361 
       
   362     @obsolete('use direct access to session.transaction_data')
       
   363     def query_data(self, key, default=None, setdefault=False, pop=False):
       
   364         if setdefault:
       
   365             assert not pop
       
   366             return self.transaction_data.setdefault(key, default)
       
   367         if pop:
       
   368             return self.transaction_data.pop(key, default)
       
   369         else:
       
   370             return self.transaction_data.get(key, default)
       
   371 
   360 
   372     @property
   361     @property
   373     def pending_operations(self):
   362     def pending_operations(self):
   374         try:
   363         try:
   375             return self._threaddata.pending_operations
   364             return self._threaddata.pending_operations
   455                         self.critical('wrong eid %s in repository, should check database' % value)
   444                         self.critical('wrong eid %s in repository, should check database' % value)
   456                         row_descr[index] = row[index] = None
   445                         row_descr[index] = row[index] = None
   457             description.append(tuple(row_descr))
   446             description.append(tuple(row_descr))
   458         return description
   447         return description
   459 
   448 
       
   449     @obsolete('use direct access to session.transaction_data')
       
   450     def query_data(self, key, default=None, setdefault=False, pop=False):
       
   451         if setdefault:
       
   452             assert not pop
       
   453             return self.transaction_data.setdefault(key, default)
       
   454         if pop:
       
   455             return self.transaction_data.pop(key, default)
       
   456         else:
       
   457             return self.transaction_data.get(key, default)
       
   458 
       
   459     @obsolete('use entity_from_eid(eid, etype=None)')
       
   460     def entity(self, eid):
       
   461         """return a result set for the given eid"""
       
   462         return self.eid_rset(eid).get_entity(0, 0)
       
   463 
   460 
   464 
   461 class ChildSession(Session):
   465 class ChildSession(Session):
   462     """child (or internal) session are used to hijack the security system
   466     """child (or internal) session are used to hijack the security system
   463     """
   467     """
   464     cnxtype = 'inmemory'
   468     cnxtype = 'inmemory'