# HG changeset patch # User Julien Cristau # Date 1404914374 -7200 # Node ID 696b81eba21866909c79bd4053daab7121e49589 # Parent b2919eca751458d9c9954b38abd309b5162f9e3f [dataimport] Update RQLObjectStore to Connection API Take a connection instead of a session. Don't play games with set_cnxset. diff -r b2919eca7514 -r 696b81eba218 dataimport.py --- a/dataimport.py Wed Jul 09 15:51:58 2014 +0200 +++ b/dataimport.py Wed Jul 09 15:59:34 2014 +0200 @@ -606,32 +606,29 @@ class RQLObjectStore(ObjectStore): """ObjectStore that works with an actual RQL repository (production mode)""" - def __init__(self, session, commit=None): - ObjectStore.__init__(self) - if not hasattr(session, 'set_cnxset'): - if hasattr(session, 'request'): - # connection object - cnx = session - session = session.request() - else: # object is already a request - cnx = session.cnx - session.set_cnxset = lambda : None - commit = commit or cnx.commit - else: - session.set_cnxset() - self.session = session - self._commit = commit or session.commit + def __init__(self, cnx, commit=None): + if commit is not None: + warnings.warn('[3.19] commit argument should not be specified ' + 'as the cnx object already provides it.', + DeprecationWarning, stacklevel=2) + super(RQLObjectStore, self).__init__() + self._cnx = cnx + self._commit = commit or cnx.commit def commit(self): - txuuid = self._commit() - self.session.set_cnxset() - return txuuid + return self._commit() def rql(self, *args): - return self.session.execute(*args) + return self._cnx.execute(*args) + + @property + def session(self): + warnings.warn('[3.19] deprecated property.', DeprecationWarning, + stacklevel=2) + return self._cnx.repo._get_session(self._cnx.sessionid) def create_entity(self, *args, **kwargs): - entity = self.session.create_entity(*args, **kwargs) + entity = self._cnx.create_entity(*args, **kwargs) self.eids[entity.eid] = entity self.types.setdefault(args[0], []).append(entity.eid) return entity @@ -642,13 +639,13 @@ self.rql('SET X %s Y WHERE X eid %%(x)s, Y eid %%(y)s' % rtype, {'x': int(eid_from), 'y': int(eid_to)}) - @deprecated("[3.19] use session.find(*args, **kwargs).entities() instead") + @deprecated("[3.19] use cnx.find(*args, **kwargs).entities() instead") def find_entities(self, *args, **kwargs): - return self.session.find(*args, **kwargs).entities() + return self._cnx.find(*args, **kwargs).entities() - @deprecated("[3.19] use session.find(*args, **kwargs).one() instead") + @deprecated("[3.19] use cnx.find(*args, **kwargs).one() instead") def find_one_entity(self, *args, **kwargs): - return self.session.find(*args, **kwargs).one() + return self._cnx.find(*args, **kwargs).one() # the import controller ########################################################