158 config.sources()['system']) |
158 config.sources()['system']) |
159 self.sources = [self.system_source] |
159 self.sources = [self.system_source] |
160 self.sources_by_uri = {'system': self.system_source} |
160 self.sources_by_uri = {'system': self.system_source} |
161 # querier helper, need to be created after sources initialization |
161 # querier helper, need to be created after sources initialization |
162 self.querier = querier.QuerierHelper(self, self.schema) |
162 self.querier = querier.QuerierHelper(self, self.schema) |
163 # cache eid -> type / source |
163 # cache eid -> (type, source, extid) |
164 self._type_source_cache = {} |
164 self._type_source_cache = {} |
165 # cache (extid, source uri) -> eid |
165 # cache (extid, source uri) -> eid |
166 self._extid_cache = {} |
166 self._extid_cache = {} |
167 # open some connections set |
167 # open some connections set |
168 if config.init_cnxset_pool: |
168 if config.init_cnxset_pool: |
1030 raise UnknownEid(eid) |
1030 raise UnknownEid(eid) |
1031 return extid |
1031 return extid |
1032 |
1032 |
1033 def extid2eid(self, source, extid, etype, session=None, insert=True, |
1033 def extid2eid(self, source, extid, etype, session=None, insert=True, |
1034 sourceparams=None): |
1034 sourceparams=None): |
1035 """get eid from a local id. An eid is attributed if no record is found""" |
1035 """Return eid from a local id. If the eid is a negative integer, that |
|
1036 means the entity is known but has been copied back to the system source |
|
1037 hence should be ignored. |
|
1038 |
|
1039 If no record is found, ie the entity is not known yet: |
|
1040 |
|
1041 1. an eid is attributed |
|
1042 |
|
1043 2. the source's :meth:`before_entity_insertion` method is called to |
|
1044 build the entity instance |
|
1045 |
|
1046 3. unless source's :attr:`should_call_hooks` tell otherwise, |
|
1047 'before_add_entity' hooks are called |
|
1048 |
|
1049 4. record is added into the system source |
|
1050 |
|
1051 5. the source's :meth:`after_entity_insertion` method is called to |
|
1052 complete building of the entity instance |
|
1053 |
|
1054 6. unless source's :attr:`should_call_hooks` tell otherwise, |
|
1055 'before_add_entity' hooks are called |
|
1056 """ |
1036 uri = 'system' if source.copy_based_source else source.uri |
1057 uri = 'system' if source.copy_based_source else source.uri |
1037 cachekey = (extid, uri) |
1058 cachekey = (extid, uri) |
1038 try: |
1059 try: |
1039 return self._extid_cache[cachekey] |
1060 return self._extid_cache[cachekey] |
1040 except KeyError: |
1061 except KeyError: |