666 |
666 |
667 def check_session(self, sessionid): |
667 def check_session(self, sessionid): |
668 """raise `BadConnectionId` if the connection is no more valid, else |
668 """raise `BadConnectionId` if the connection is no more valid, else |
669 return its latest activity timestamp. |
669 return its latest activity timestamp. |
670 """ |
670 """ |
671 return self._get_session(sessionid, setcnxset=False).timestamp |
671 return self._get_session(sessionid).timestamp |
672 |
672 |
673 def close(self, sessionid, txid=None, checkshuttingdown=True): |
673 def close(self, sessionid, txid=None, checkshuttingdown=True): |
674 """close the session with the given id""" |
674 """close the session with the given id""" |
675 session = self._get_session(sessionid, txid=txid, |
675 session = self._get_session(sessionid, txid=txid, |
676 checkshuttingdown=checkshuttingdown) |
676 checkshuttingdown=checkshuttingdown) |
677 # operation uncommited before close are rolled back before hook is called |
677 # operation uncommited before close are rolled back before hook is called |
678 if session._cnx._session_handled: |
|
679 session._cnx.rollback(free_cnxset=False) |
|
680 with session.new_cnx() as cnx: |
678 with session.new_cnx() as cnx: |
681 self.hm.call_hooks('session_close', cnx) |
679 self.hm.call_hooks('session_close', cnx) |
682 # commit connection at this point in case write operation has been |
680 # commit connection at this point in case write operation has been |
683 # done during `session_close` hooks |
681 # done during `session_close` hooks |
684 cnx.commit() |
682 cnx.commit() |
722 with session.new_cnx() as cnx: |
720 with session.new_cnx() as cnx: |
723 with cnx.security_enabled(read=False, write=False): |
721 with cnx.security_enabled(read=False, write=False): |
724 with cnx.ensure_cnx_set: |
722 with cnx.ensure_cnx_set: |
725 yield cnx |
723 yield cnx |
726 |
724 |
727 def _get_session(self, sessionid, setcnxset=False, txid=None, |
725 def _get_session(self, sessionid, txid=None, checkshuttingdown=True): |
728 checkshuttingdown=True): |
|
729 """return the session associated with the given session identifier""" |
726 """return the session associated with the given session identifier""" |
730 if checkshuttingdown and self.shutting_down: |
727 if checkshuttingdown and self.shutting_down: |
731 raise ShuttingDown('Repository is shutting down') |
728 raise ShuttingDown('Repository is shutting down') |
732 try: |
729 try: |
733 session = self._sessions[sessionid] |
730 session = self._sessions[sessionid] |
734 except KeyError: |
731 except KeyError: |
735 raise BadConnectionId('No such session %s' % sessionid) |
732 raise BadConnectionId('No such session %s' % sessionid) |
736 if setcnxset: |
|
737 session.set_cnx(txid) # must be done before set_cnxset |
|
738 session.set_cnxset() |
|
739 return session |
733 return session |
740 |
734 |
741 # data sources handling ################################################### |
735 # data sources handling ################################################### |
742 # * correspondance between eid and (type, source) |
736 # * correspondance between eid and (type, source) |
743 # * correspondance between eid and local id (i.e. specific to a given source) |
737 # * correspondance between eid and local id (i.e. specific to a given source) |