server/repository.py
branchstable
changeset 1954 9b20f3504af8
parent 1939 67e7379edd96
child 1977 606923dff11b
equal deleted inserted replaced
1953:8834399f076e 1954:9b20f3504af8
   792         if source.uri != uri:
   792         if source.uri != uri:
   793             # eid not from the given source
   793             # eid not from the given source
   794             raise UnknownEid(eid)
   794             raise UnknownEid(eid)
   795         return extid
   795         return extid
   796 
   796 
   797     def extid2eid(self, source, lid, etype, session=None, insert=True,
   797     def extid2eid(self, source, extid, etype, session=None, insert=True,
   798                   recreate=False):
   798                   recreate=False):
   799         """get eid from a local id. An eid is attributed if no record is found"""
   799         """get eid from a local id. An eid is attributed if no record is found"""
   800         cachekey = (str(lid), source.uri)
   800         cachekey = (extid, source.uri)
   801         try:
   801         try:
   802             return self._extid_cache[cachekey]
   802             return self._extid_cache[cachekey]
   803         except KeyError:
   803         except KeyError:
   804             pass
   804             pass
   805         reset_pool = False
   805         reset_pool = False
   806         if session is None:
   806         if session is None:
   807             session = self.internal_session()
   807             session = self.internal_session()
   808             reset_pool = True
   808             reset_pool = True
   809         eid = self.system_source.extid2eid(session, source, lid)
   809         eid = self.system_source.extid2eid(session, source, extid)
   810         if eid is not None:
   810         if eid is not None:
   811             self._extid_cache[cachekey] = eid
   811             self._extid_cache[cachekey] = eid
   812             self._type_source_cache[eid] = (etype, source.uri, lid)
   812             self._type_source_cache[eid] = (etype, source.uri, extid)
   813             if recreate:
   813             if recreate:
   814                 entity = source.before_entity_insertion(session, lid, etype, eid)
   814                 entity = source.before_entity_insertion(session, extid, etype, eid)
   815                 entity._cw_recreating = True
   815                 entity._cw_recreating = True
   816                 if source.should_call_hooks:
   816                 if source.should_call_hooks:
   817                     self.hm.call_hooks('before_add_entity', etype, session, entity)
   817                     self.hm.call_hooks('before_add_entity', etype, session, entity)
   818                 # XXX add fti op ?
   818                 # XXX add fti op ?
   819                 source.after_entity_insertion(session, lid, entity)
   819                 source.after_entity_insertion(session, extid, entity)
   820                 if source.should_call_hooks:
   820                 if source.should_call_hooks:
   821                     self.hm.call_hooks('after_add_entity', etype, session, entity)
   821                     self.hm.call_hooks('after_add_entity', etype, session, entity)
   822             if reset_pool:
   822             if reset_pool:
   823                 session.reset_pool()
   823                 session.reset_pool()
   824             return eid
   824             return eid
   825         if not insert:
   825         if not insert:
   826             return
   826             return
   827         # no link between lid and eid, create one using an internal session
   827         # no link between extid and eid, create one using an internal session
   828         # since the current session user may not have required permissions to
   828         # since the current session user may not have required permissions to
   829         # do necessary stuff and we don't want to commit user session.
   829         # do necessary stuff and we don't want to commit user session.
   830         #
   830         #
   831         # Moreover, even if session is already an internal session but is
   831         # Moreover, even if session is already an internal session but is
   832         # processing a commit, we have to use another one
   832         # processing a commit, we have to use another one
   834             session = self.internal_session()
   834             session = self.internal_session()
   835             reset_pool = True
   835             reset_pool = True
   836         try:
   836         try:
   837             eid = self.system_source.create_eid(session)
   837             eid = self.system_source.create_eid(session)
   838             self._extid_cache[cachekey] = eid
   838             self._extid_cache[cachekey] = eid
   839             self._type_source_cache[eid] = (etype, source.uri, lid)
   839             self._type_source_cache[eid] = (etype, source.uri, extid)
   840             entity = source.before_entity_insertion(session, lid, etype, eid)
   840             entity = source.before_entity_insertion(session, extid, etype, eid)
   841             if source.should_call_hooks:
   841             if source.should_call_hooks:
   842                 self.hm.call_hooks('before_add_entity', etype, session, entity)
   842                 self.hm.call_hooks('before_add_entity', etype, session, entity)
   843             # XXX call add_info with complete=False ?
   843             # XXX call add_info with complete=False ?
   844             self.add_info(session, entity, source, lid)
   844             self.add_info(session, entity, source, extid)
   845             source.after_entity_insertion(session, lid, entity)
   845             source.after_entity_insertion(session, extid, entity)
   846             if source.should_call_hooks:
   846             if source.should_call_hooks:
   847                 self.hm.call_hooks('after_add_entity', etype, session, entity)
   847                 self.hm.call_hooks('after_add_entity', etype, session, entity)
   848             else:
   848             else:
   849                 # minimal meta-data
   849                 # minimal meta-data
   850                 session.execute('SET X is E WHERE X eid %(x)s, E name %(name)s',
   850                 session.execute('SET X is E WHERE X eid %(x)s, E name %(name)s',