174 # cache (extid, source uri) -> eid |
174 # cache (extid, source uri) -> eid |
175 self._extid_cache = {} |
175 self._extid_cache = {} |
176 # create the hooks manager |
176 # create the hooks manager |
177 self.hm = HooksManager(self.schema) |
177 self.hm = HooksManager(self.schema) |
178 # open some connections pools |
178 # open some connections pools |
|
179 if config.open_connections_pools: |
|
180 self.open_connections_pools() |
|
181 |
|
182 def open_connections_pools(self): |
|
183 config = self.config |
179 self._available_pools = Queue.Queue() |
184 self._available_pools = Queue.Queue() |
180 self._available_pools.put_nowait(ConnectionsPool(self.sources)) |
185 self._available_pools.put_nowait(ConnectionsPool(self.sources)) |
181 if config.read_instance_schema: |
186 if config.read_instance_schema: |
182 # normal start: load the instance schema from the database |
187 # normal start: load the instance schema from the database |
183 self.fill_schema() |
188 self.fill_schema() |
184 elif config.bootstrap_schema: |
189 elif config.bootstrap_schema: |
185 # usually during repository creation |
190 # usually during repository creation |
186 self.warning("set fs instance'schema as bootstrap schema") |
191 self.warning("set fs instance'schema as bootstrap schema") |
187 config.bootstrap_cubes() |
192 config.bootstrap_cubes() |
188 self.set_bootstrap_schema(self.config.load_schema()) |
193 self.set_bootstrap_schema(config.load_schema()) |
189 # need to load the Any and CWUser entity types |
194 # need to load the Any and CWUser entity types |
190 self.vreg.schema = self.schema |
195 self.vreg.schema = self.schema |
191 etdirectory = join(CW_SOFTWARE_ROOT, 'entities') |
196 etdirectory = join(CW_SOFTWARE_ROOT, 'entities') |
192 self.vreg.init_registration([etdirectory]) |
197 self.vreg.init_registration([etdirectory]) |
193 self.vreg.load_file(join(etdirectory, '__init__.py'), |
198 self.vreg.load_file(join(etdirectory, '__init__.py'), |
198 'cubicweb.entities.wfobjs') |
203 'cubicweb.entities.wfobjs') |
199 else: |
204 else: |
200 # test start: use the file system schema (quicker) |
205 # test start: use the file system schema (quicker) |
201 self.warning("set fs instance'schema") |
206 self.warning("set fs instance'schema") |
202 config.bootstrap_cubes() |
207 config.bootstrap_cubes() |
203 self.set_schema(self.config.load_schema()) |
208 self.set_schema(config.load_schema()) |
204 if not config.creating: |
209 if not config.creating: |
205 if 'CWProperty' in self.schema: |
210 if 'CWProperty' in self.schema: |
206 self.vreg.init_properties(self.properties()) |
211 self.vreg.init_properties(self.properties()) |
207 # call source's init method to complete their initialisation if |
212 # call source's init method to complete their initialisation if |
208 # needed (for instance looking for persistent configuration using an |
213 # needed (for instance looking for persistent configuration using an |
226 self._shutting_down = False |
231 self._shutting_down = False |
227 if not (config.creating or config.repairing): |
232 if not (config.creating or config.repairing): |
228 # call instance level initialisation hooks |
233 # call instance level initialisation hooks |
229 self.hm.call_hooks('server_startup', repo=self) |
234 self.hm.call_hooks('server_startup', repo=self) |
230 # register a task to cleanup expired session |
235 # register a task to cleanup expired session |
231 self.looping_task(self.config['session-time']/3., |
236 self.looping_task(config['session-time']/3., self.clean_sessions) |
232 self.clean_sessions) |
|
233 CW_EVENT_MANAGER.bind('after-registry-reload', self.reset_hooks) |
237 CW_EVENT_MANAGER.bind('after-registry-reload', self.reset_hooks) |
234 |
238 |
235 # internals ############################################################### |
239 # internals ############################################################### |
236 |
240 |
237 def get_source(self, uri, source_config): |
241 def get_source(self, uri, source_config): |
238 source_config['uri'] = uri |
242 source_config['uri'] = uri |
239 return get_source(source_config, self.schema, self) |
243 return get_source(source_config, self.schema, self) |
240 |
244 |
241 def set_schema(self, schema, resetvreg=True): |
245 def set_schema(self, schema, resetvreg=True, rebuildinfered=True): |
242 schema.rebuild_infered_relations() |
246 if rebuildinfered: |
|
247 schema.rebuild_infered_relations() |
243 self.info('set schema %s %#x', schema.name, id(schema)) |
248 self.info('set schema %s %#x', schema.name, id(schema)) |
244 self.debug(', '.join(sorted(str(e) for e in schema.entities()))) |
249 self.debug(', '.join(sorted(str(e) for e in schema.entities()))) |
245 self.querier.set_schema(schema) |
250 self.querier.set_schema(schema) |
246 for source in self.sources: |
251 for source in self.sources: |
247 source.set_schema(schema) |
252 source.set_schema(schema) |