604 return len(self.relations) |
604 return len(self.relations) |
605 |
605 |
606 class RQLObjectStore(ObjectStore): |
606 class RQLObjectStore(ObjectStore): |
607 """ObjectStore that works with an actual RQL repository (production mode)""" |
607 """ObjectStore that works with an actual RQL repository (production mode)""" |
608 |
608 |
609 def __init__(self, session, commit=None): |
609 def __init__(self, cnx, commit=None): |
610 ObjectStore.__init__(self) |
610 if commit is not None: |
611 if not hasattr(session, 'set_cnxset'): |
611 warnings.warn('[3.19] commit argument should not be specified ' |
612 if hasattr(session, 'request'): |
612 'as the cnx object already provides it.', |
613 # connection object |
613 DeprecationWarning, stacklevel=2) |
614 cnx = session |
614 super(RQLObjectStore, self).__init__() |
615 session = session.request() |
615 self._cnx = cnx |
616 else: # object is already a request |
616 self._commit = commit or cnx.commit |
617 cnx = session.cnx |
|
618 session.set_cnxset = lambda : None |
|
619 commit = commit or cnx.commit |
|
620 else: |
|
621 session.set_cnxset() |
|
622 self.session = session |
|
623 self._commit = commit or session.commit |
|
624 |
617 |
625 def commit(self): |
618 def commit(self): |
626 txuuid = self._commit() |
619 return self._commit() |
627 self.session.set_cnxset() |
|
628 return txuuid |
|
629 |
620 |
630 def rql(self, *args): |
621 def rql(self, *args): |
631 return self.session.execute(*args) |
622 return self._cnx.execute(*args) |
|
623 |
|
624 @property |
|
625 def session(self): |
|
626 warnings.warn('[3.19] deprecated property.', DeprecationWarning, |
|
627 stacklevel=2) |
|
628 return self._cnx.repo._get_session(self._cnx.sessionid) |
632 |
629 |
633 def create_entity(self, *args, **kwargs): |
630 def create_entity(self, *args, **kwargs): |
634 entity = self.session.create_entity(*args, **kwargs) |
631 entity = self._cnx.create_entity(*args, **kwargs) |
635 self.eids[entity.eid] = entity |
632 self.eids[entity.eid] = entity |
636 self.types.setdefault(args[0], []).append(entity.eid) |
633 self.types.setdefault(args[0], []).append(entity.eid) |
637 return entity |
634 return entity |
638 |
635 |
639 def relate(self, eid_from, rtype, eid_to, **kwargs): |
636 def relate(self, eid_from, rtype, eid_to, **kwargs): |
640 eid_from, rtype, eid_to = super(RQLObjectStore, self).relate( |
637 eid_from, rtype, eid_to = super(RQLObjectStore, self).relate( |
641 eid_from, rtype, eid_to, **kwargs) |
638 eid_from, rtype, eid_to, **kwargs) |
642 self.rql('SET X %s Y WHERE X eid %%(x)s, Y eid %%(y)s' % rtype, |
639 self.rql('SET X %s Y WHERE X eid %%(x)s, Y eid %%(y)s' % rtype, |
643 {'x': int(eid_from), 'y': int(eid_to)}) |
640 {'x': int(eid_from), 'y': int(eid_to)}) |
644 |
641 |
645 @deprecated("[3.19] use session.find(*args, **kwargs).entities() instead") |
642 @deprecated("[3.19] use cnx.find(*args, **kwargs).entities() instead") |
646 def find_entities(self, *args, **kwargs): |
643 def find_entities(self, *args, **kwargs): |
647 return self.session.find(*args, **kwargs).entities() |
644 return self._cnx.find(*args, **kwargs).entities() |
648 |
645 |
649 @deprecated("[3.19] use session.find(*args, **kwargs).one() instead") |
646 @deprecated("[3.19] use cnx.find(*args, **kwargs).one() instead") |
650 def find_one_entity(self, *args, **kwargs): |
647 def find_one_entity(self, *args, **kwargs): |
651 return self.session.find(*args, **kwargs).one() |
648 return self._cnx.find(*args, **kwargs).one() |
652 |
649 |
653 # the import controller ######################################################## |
650 # the import controller ######################################################## |
654 |
651 |
655 class CWImportController(object): |
652 class CWImportController(object): |
656 """Controller of the data import process. |
653 """Controller of the data import process. |