300 self.cnxsets.close() |
300 self.cnxsets.close() |
301 self.cnxsets = _CnxSetPool(self.system_source, pool_size) |
301 self.cnxsets = _CnxSetPool(self.system_source, pool_size) |
302 # 5. call instance level initialisation hooks |
302 # 5. call instance level initialisation hooks |
303 self.hm.call_hooks('server_startup', repo=self) |
303 self.hm.call_hooks('server_startup', repo=self) |
304 |
304 |
|
305 def source_by_uri(self, uri): |
|
306 with self.internal_cnx() as cnx: |
|
307 rset = cnx.find('CWSource', name=uri) |
|
308 if not rset: |
|
309 raise ValueError('no source with uri %s found' % uri) |
|
310 return self._source_from_cwsource(rset.one()) |
|
311 |
|
312 def source_by_eid(self, eid): |
|
313 with self.internal_cnx() as cnx: |
|
314 rset = cnx.find('CWSource', eid=eid) |
|
315 if not rset: |
|
316 raise ValueError('no source with eid %d found' % eid) |
|
317 return self._source_from_cwsource(rset.one()) |
|
318 |
305 @property |
319 @property |
306 def sources_by_uri(self): |
320 def sources_by_uri(self): |
307 mapping = {'system': self.system_source} |
321 mapping = {'system': self.system_source} |
308 mapping.update((sourceent.name, source) |
322 mapping.update((sourceent.name, source) |
309 for sourceent, source in self._sources()) |
323 for sourceent, source in self._sources()) |
321 return |
335 return |
322 with self.internal_cnx() as cnx: |
336 with self.internal_cnx() as cnx: |
323 for sourceent in cnx.execute( |
337 for sourceent in cnx.execute( |
324 'Any S, SN, SA, SC WHERE S is_instance_of CWSource, ' |
338 'Any S, SN, SA, SC WHERE S is_instance_of CWSource, ' |
325 'S name SN, S type SA, S config SC, S name != "system"').entities(): |
339 'S name SN, S type SA, S config SC, S name != "system"').entities(): |
326 source = self.get_source(sourceent.type, sourceent.name, |
340 source = self._source_from_cwsource(sourceent) |
327 sourceent.host_config, sourceent.eid) |
|
328 if self.config.source_enabled(source): |
|
329 # call source's init method to complete their initialisation if |
|
330 # needed (for instance looking for persistent configuration using an |
|
331 # internal session, which is not possible until connections sets have been |
|
332 # initialized) |
|
333 source.init(True, sourceent) |
|
334 else: |
|
335 source.init(False, sourceent) |
|
336 source.set_schema(self.schema) |
|
337 yield sourceent, source |
341 yield sourceent, source |
338 self._clear_source_defs_caches() |
342 self._clear_source_defs_caches() |
|
343 |
|
344 def _source_from_cwsource(self, sourceent): |
|
345 source = self.get_source(sourceent.type, sourceent.name, |
|
346 sourceent.host_config, sourceent.eid) |
|
347 if self.config.source_enabled(source): |
|
348 # call source's init method to complete their initialisation if |
|
349 # needed (for instance looking for persistent configuration using an |
|
350 # internal session, which is not possible until connections sets have been |
|
351 # initialized) |
|
352 source.init(True, sourceent) |
|
353 else: |
|
354 source.init(False, sourceent) |
|
355 source.set_schema(self.schema) |
|
356 return source |
339 |
357 |
340 # internals ############################################################### |
358 # internals ############################################################### |
341 |
359 |
342 def _init_system_source(self): |
360 def _init_system_source(self): |
343 if self.config.quick_start: |
361 if self.config.quick_start: |