server/session.py
changeset 8764 c4f022a6c7dd
parent 8763 0144b26e958d
child 8765 9e9029ba2d4e
equal deleted inserted replaced
8763:0144b26e958d 8764:c4f022a6c7dd
   157       :attr:`mode`, string telling the connections set handling mode, may be one
   157       :attr:`mode`, string telling the connections set handling mode, may be one
   158       of 'read' (connections set may be freed), 'write' (some write was done in
   158       of 'read' (connections set may be freed), 'write' (some write was done in
   159       the connections set, it can't be freed before end of the transaction),
   159       the connections set, it can't be freed before end of the transaction),
   160       'transaction' (we want to keep the connections set during all the
   160       'transaction' (we want to keep the connections set during all the
   161       transaction, with or without writing)
   161       transaction, with or without writing)
       
   162 
       
   163     Internal transaction data:
       
   164 
       
   165       :attr:`transaction_data`,is a dictionary containing some shared data
       
   166       cleared at the end of the transaction. Hooks and operations may put
       
   167       arbitrary data in there, and this may also be used as a communication
       
   168       channel between the client and the repository.
       
   169 
       
   170       :attr:`pending_operations`, ordered list of operations to be processed on
       
   171       commit/rollback
       
   172 
       
   173       :attr:`commit_state`, describing the transaction commit state, may be one
       
   174       of None (not yet committing), 'precommit' (calling precommit event on
       
   175       operations), 'postcommit' (calling postcommit event on operations),
       
   176       'uncommitable' (some :exc:`ValidationError` or :exc:`Unauthorized` error
       
   177       has been raised during the transaction and so it must be rollbacked).
       
   178 
   162     """
   179     """
   163 
   180 
   164     def __init__(self, txid, mode='read'):
   181     def __init__(self, txid, mode='read'):
   165         #: transaction unique id
   182         #: transaction unique id
   166         self.transactionid = txid
   183         self.transactionid = txid
   169 
   186 
   170         #: connection handling mode
   187         #: connection handling mode
   171         self.mode = mode
   188         self.mode = mode
   172         #: connection set used to execute queries on sources
   189         #: connection set used to execute queries on sources
   173         self.cnxset = None
   190         self.cnxset = None
       
   191 
       
   192         #: dict containing arbitrary data cleared at the end of the transaction
       
   193         self.transaction_data = {}
       
   194         #: ordered list of operations to be processed on commit/rollback
       
   195         self.pending_operations = []
       
   196         #: (None, 'precommit', 'postcommit', 'uncommitable')
       
   197         self.commit_state = None
       
   198 
       
   199     def clear(self):
       
   200         """reset internal data"""
       
   201         self.transaction_data = {}
       
   202         #: ordered list of operations to be processed on commit/rollback
       
   203         self.pending_operations = []
       
   204         #: (None, 'precommit', 'postcommit', 'uncommitable')
       
   205         self.commit_state = None
       
   206 
   174 
   207 
   175 class Session(RequestSessionBase):
   208 class Session(RequestSessionBase):
   176     """Repository user session
   209     """Repository user session
   177 
   210 
   178     This tie all together:
   211     This tie all together:
   791     mode = property(get_mode, set_mode,
   824     mode = property(get_mode, set_mode,
   792                     doc='transaction mode (read/write/transaction), resetted to'
   825                     doc='transaction mode (read/write/transaction), resetted to'
   793                     ' default_mode on commit / rollback')
   826                     ' default_mode on commit / rollback')
   794 
   827 
   795     def get_commit_state(self):
   828     def get_commit_state(self):
   796         return getattr(self._threaddata, 'commit_state', None)
   829         return self._threaddata.commit_state
   797     def set_commit_state(self, value):
   830     def set_commit_state(self, value):
   798         self._threaddata.commit_state = value
   831         self._threaddata.commit_state = value
   799     commit_state = property(get_commit_state, set_commit_state)
   832     commit_state = property(get_commit_state, set_commit_state)
   800 
   833 
   801     @property
   834     @property
   974             del self.__threaddata.txdata
  1007             del self.__threaddata.txdata
   975         except AttributeError:
  1008         except AttributeError:
   976             pass
  1009             pass
   977 
  1010 
   978     def _clear_tx_storage(self, txstore):
  1011     def _clear_tx_storage(self, txstore):
   979         for name in ('commit_state', 'transaction_data',
  1012         txstore.clear()
   980                      'pending_operations', '_rewriter',
  1013         for name in ('_rewriter', 'pruned_hooks_cache'):
   981                      'pruned_hooks_cache'):
       
   982             try:
  1014             try:
   983                 delattr(txstore, name)
  1015                 delattr(txstore, name)
   984             except AttributeError:
  1016             except AttributeError:
   985                 continue
  1017                 continue
   986 
  1018 
  1134 
  1166 
  1135     # transaction data/operations management ##################################
  1167     # transaction data/operations management ##################################
  1136 
  1168 
  1137     @property
  1169     @property
  1138     def transaction_data(self):
  1170     def transaction_data(self):
  1139         try:
  1171         return self._threaddata.transaction_data
  1140             return self._threaddata.transaction_data
       
  1141         except AttributeError:
       
  1142             self._threaddata.transaction_data = {}
       
  1143             return self._threaddata.transaction_data
       
  1144 
  1172 
  1145     @property
  1173     @property
  1146     def pending_operations(self):
  1174     def pending_operations(self):
  1147         try:
  1175         return self._threaddata.pending_operations
  1148             return self._threaddata.pending_operations
       
  1149         except AttributeError:
       
  1150             self._threaddata.pending_operations = []
       
  1151             return self._threaddata.pending_operations
       
  1152 
  1176 
  1153     @property
  1177     @property
  1154     def pruned_hooks_cache(self):
  1178     def pruned_hooks_cache(self):
  1155         try:
  1179         try:
  1156             return self._threaddata.pruned_hooks_cache
  1180             return self._threaddata.pruned_hooks_cache