server/repository.py
changeset 9448 3e7cad3967c5
parent 9404 3e3e9b37e177
child 9449 287a05ec7ab1
equal deleted inserted replaced
9447:0636c4960259 9448:3e7cad3967c5
   281                 if sourceent.name == 'system':
   281                 if sourceent.name == 'system':
   282                     self.system_source.eid = sourceent.eid
   282                     self.system_source.eid = sourceent.eid
   283                     self.sources_by_eid[sourceent.eid] = self.system_source
   283                     self.sources_by_eid[sourceent.eid] = self.system_source
   284                     self.system_source.init(True, sourceent)
   284                     self.system_source.init(True, sourceent)
   285                     continue
   285                     continue
   286                 self.add_source(sourceent, add_to_cnxsets=False)
   286                 self.add_source(sourceent)
   287 
   287 
   288     def _clear_planning_caches(self):
   288     def _clear_planning_caches(self):
   289         for cache in ('source_defs', 'is_multi_sources_relation',
   289         for cache in ('source_defs', 'is_multi_sources_relation',
   290                       'can_cross_relation', 'rel_type_sources'):
   290                       'can_cross_relation', 'rel_type_sources'):
   291             clear_cache(self, cache)
   291             clear_cache(self, cache)
   292 
   292 
   293     def add_source(self, sourceent, add_to_cnxsets=True):
   293     def add_source(self, sourceent):
   294         source = self.get_source(sourceent.type, sourceent.name,
   294         source = self.get_source(sourceent.type, sourceent.name,
   295                                  sourceent.host_config, sourceent.eid)
   295                                  sourceent.host_config, sourceent.eid)
   296         self.sources_by_eid[sourceent.eid] = source
   296         self.sources_by_eid[sourceent.eid] = source
   297         self.sources_by_uri[sourceent.name] = source
   297         self.sources_by_uri[sourceent.name] = source
   298         if self.config.source_enabled(source):
   298         if self.config.source_enabled(source):
   299             # call source's init method to complete their initialisation if
   299             # call source's init method to complete their initialisation if
   300             # needed (for instance looking for persistent configuration using an
   300             # needed (for instance looking for persistent configuration using an
   301             # internal session, which is not possible until connections sets have been
   301             # internal session, which is not possible until connections sets have been
   302             # initialized)
   302             # initialized)
   303             source.init(True, sourceent)
   303             source.init(True, sourceent)
   304             if not source.copy_based_source:
       
   305                 warn('[3.18] old multi-source system will go away in the next version',
       
   306                      DeprecationWarning)
       
   307                 self.sources.append(source)
       
   308                 self.querier.set_planner()
       
   309                 if add_to_cnxsets:
       
   310                     for cnxset in self.cnxsets:
       
   311                        cnxset.add_source(source)
       
   312         else:
   304         else:
   313             source.init(False, sourceent)
   305             source.init(False, sourceent)
   314         self._clear_planning_caches()
   306         self._clear_planning_caches()
   315 
   307 
   316     def remove_source(self, uri):
   308     def remove_source(self, uri):
   317         source = self.sources_by_uri.pop(uri)
   309         source = self.sources_by_uri.pop(uri)
   318         del self.sources_by_eid[source.eid]
   310         del self.sources_by_eid[source.eid]
   319         if self.config.source_enabled(source) and not source.copy_based_source:
       
   320             self.sources.remove(source)
       
   321             self.querier.set_planner()
       
   322             for cnxset in self.cnxsets:
       
   323                 cnxset.remove_source(source)
       
   324         self._clear_planning_caches()
   311         self._clear_planning_caches()
   325 
   312 
   326     def get_source(self, type, uri, source_config, eid=None):
   313     def get_source(self, type, uri, source_config, eid=None):
   327         # set uri and type in source config so it's available through
   314         # set uri and type in source config so it's available through
   328         # source_defs()
   315         # source_defs()
  1085            complete building of the entity instance
  1072            complete building of the entity instance
  1086 
  1073 
  1087         6. unless source's :attr:`should_call_hooks` tell otherwise,
  1074         6. unless source's :attr:`should_call_hooks` tell otherwise,
  1088           'before_add_entity' hooks are called
  1075           'before_add_entity' hooks are called
  1089         """
  1076         """
  1090         uri = 'system' if source.copy_based_source else source.uri
  1077         uri = 'system'
  1091         cachekey = (extid, uri)
  1078         cachekey = (extid, uri)
  1092         try:
  1079         try:
  1093             return self._extid_cache[cachekey]
  1080             return self._extid_cache[cachekey]
  1094         except KeyError:
  1081         except KeyError:
  1095             pass
  1082             pass
  1298         session.set_entity_cache(entity)
  1285         session.set_entity_cache(entity)
  1299         suri = source.uri
  1286         suri = source.uri
  1300         if suri == 'system':
  1287         if suri == 'system':
  1301             extid = None
  1288             extid = None
  1302         else:
  1289         else:
  1303             if source.copy_based_source:
  1290             suri = 'system'
  1304                 suri = 'system'
       
  1305             extid = source.get_extid(entity)
  1291             extid = source.get_extid(entity)
  1306             self._extid_cache[(str(extid), suri)] = entity.eid
  1292             self._extid_cache[(str(extid), suri)] = entity.eid
  1307         self._type_source_cache[entity.eid] = (entity.cw_etype, suri, extid,
  1293         self._type_source_cache[entity.eid] = (entity.cw_etype, suri, extid,
  1308                                                source.uri)
  1294                                                source.uri)
  1309         return extid
  1295         return extid