# HG changeset patch
# User Sylvain Thénault <sylvain.thenault@logilab.fr>
# Date 1280139311 -7200
# Mon Jul 26 12:15:11 2010 +0200
# Node ID 8ca424bc393b5517b83c0e9808780ec1dabbef6c
# Parent d56fd78006cd1888c26182a28b11c943622ad1c2
[dbapi] cleanup shared data api: let access to transaction from dbapi, we can write it after all... Also, querydata is better named txdata
# User Sylvain Thénault <sylvain.thenault@logilab.fr>
# Date 1280139311 -7200
# Mon Jul 26 12:15:11 2010 +0200
# Node ID 8ca424bc393b5517b83c0e9808780ec1dabbef6c
# Parent d56fd78006cd1888c26182a28b11c943622ad1c2
[dbapi] cleanup shared data api: let access to transaction from dbapi, we can write it after all... Also, querydata is better named txdata
@@ -311,23 +311,21 @@
1 else: 2 del self._eid_cache[eid] 3 4 # low level session data management ####################################### 5 6 - def get_shared_data(self, key, default=None, pop=False): 7 - """return value associated to `key` in shared data""" 8 - return self.cnx.get_shared_data(key, default, pop) 9 - 10 - def set_shared_data(self, key, value, querydata=False): 11 - """set value associated to `key` in shared data 12 + def get_shared_data(self, key, default=None, pop=False, txdata=False): 13 + """see :meth:`Connection.get_shared_data`""" 14 + return self.cnx.get_shared_data(key, default, pop, txdata) 15 16 - if `querydata` is true, the value will be added to the repository 17 - session's query data which are cleared on commit/rollback of the current 18 - transaction, and won't be available through the connexion, only on the 19 - repository side. 20 - """ 21 - return self.cnx.set_shared_data(key, value, querydata) 22 + def set_shared_data(self, key, value, txdata=False, querydata=None): 23 + """see :meth:`Connection.set_shared_data`""" 24 + if querydata is not None: 25 + txdata = querydata 26 + warn('[3.10] querydata argument has been renamed to txdata', 27 + DeprecationWarning, stacklevel=2) 28 + return self.cnx.set_shared_data(key, value, txdata) 29 30 # server session compat layer ############################################# 31 32 def describe(self, eid): 33 """return a tuple (type, sourceuri, extid) for the entity with id <eid>"""
@@ -518,27 +516,33 @@
34 """raise `BadConnectionId` if the connection is no more valid""" 35 if self._closed is not None: 36 raise ProgrammingError('Closed connection') 37 self._repo.set_session_props(self.sessionid, props) 38 39 - def get_shared_data(self, key, default=None, pop=False): 40 - """return value associated to `key` in shared data""" 41 - if self._closed is not None: 42 - raise ProgrammingError('Closed connection') 43 - return self._repo.get_shared_data(self.sessionid, key, default, pop) 44 + def get_shared_data(self, key, default=None, pop=False, txdata=False): 45 + """return value associated to key in the session's data dictionary or 46 + session's transaction's data if `txdata` is true. 47 48 - def set_shared_data(self, key, value, querydata=False): 49 - """set value associated to `key` in shared data 50 + If pop is True, value will be removed from the dictionnary. 51 52 - if `querydata` is true, the value will be added to the repository 53 - session's query data which are cleared on commit/rollback of the current 54 - transaction, and won't be available through the connexion, only on the 55 - repository side. 56 + If key isn't defined in the dictionnary, value specified by the 57 + `default` argument will be returned. 58 """ 59 if self._closed is not None: 60 raise ProgrammingError('Closed connection') 61 - return self._repo.set_shared_data(self.sessionid, key, value, querydata) 62 + return self._repo.get_shared_data(self.sessionid, key, default, pop, txdata) 63 + 64 + def set_shared_data(self, key, value, txdata=False): 65 + """set value associated to `key` in shared data 66 + 67 + if `txdata` is true, the value will be added to the repository session's 68 + transaction's data which are cleared on commit/rollback of the current 69 + transaction. 70 + """ 71 + if self._closed is not None: 72 + raise ProgrammingError('Closed connection') 73 + return self._repo.set_shared_data(self.sessionid, key, value, txdata) 74 75 def get_schema(self): 76 """Return the schema currently used by the repository. 77 78 This is NOT part of the DB-API.
@@ -628,25 +628,31 @@
79 """raise `BadConnectionId` if the connection is no more valid, else 80 return its latest activity timestamp. 81 """ 82 return self._get_session(sessionid, setpool=False).timestamp 83 84 - def get_shared_data(self, sessionid, key, default=None, pop=False): 85 - """return the session's data dictionary""" 86 + def get_shared_data(self, sessionid, key, default=None, pop=False, txdata=False): 87 + """return value associated to key in the session's data dictionary or 88 + session's transaction's data if `txdata` is true. 89 + 90 + If pop is True, value will be removed from the dictionnary. 91 + 92 + If key isn't defined in the dictionnary, value specified by the 93 + `default` argument will be returned. 94 + """ 95 session = self._get_session(sessionid, setpool=False) 96 - return session.get_shared_data(key, default, pop) 97 + return session.get_shared_data(key, default, pop, txdata) 98 99 - def set_shared_data(self, sessionid, key, value, querydata=False): 100 + def set_shared_data(self, sessionid, key, value, txdata=False): 101 """set value associated to `key` in shared data 102 103 - if `querydata` is true, the value will be added to the repository 104 - session's query data which are cleared on commit/rollback of the current 105 - transaction, and won't be available through the connexion, only on the 106 - repository side. 107 + if `txdata` is true, the value will be added to the repository session's 108 + transaction's data which are cleared on commit/rollback of the current 109 + transaction. 110 """ 111 session = self._get_session(sessionid, setpool=False) 112 - session.set_shared_data(key, value, querydata) 113 + session.set_shared_data(key, value, txdata) 114 115 def commit(self, sessionid, txid=None): 116 """commit transaction for the session with the given id""" 117 self.debug('begin commit for session %s', sessionid) 118 try:
@@ -616,20 +616,24 @@
119 self.timestamp = time() 120 self.local_perm_cache.clear() # XXX simply move in transaction_data, no? 121 122 # shared data handling ################################################### 123 124 - def get_shared_data(self, key, default=None, pop=False): 125 + def get_shared_data(self, key, default=None, pop=False, txdata=False): 126 """return value associated to `key` in session data""" 127 - if pop: 128 - return self.data.pop(key, default) 129 + if txdata: 130 + data = self.transaction_data 131 else: 132 - return self.data.get(key, default) 133 + data = self.data 134 + if pop: 135 + return data.pop(key, default) 136 + else: 137 + return data.get(key, default) 138 139 - def set_shared_data(self, key, value, querydata=False): 140 + def set_shared_data(self, key, value, txdata=False): 141 """set value associated to `key` in session data""" 142 - if querydata: 143 + if txdata: 144 self.transaction_data[key] = value 145 else: 146 self.data[key] = value 147 148 # request interface #######################################################