diff -r 1d25e928c299 -r 69c0ba095536 server/repository.py --- a/server/repository.py Tue Sep 15 15:01:41 2009 +0200 +++ b/server/repository.py Thu Sep 17 15:16:53 2009 +0200 @@ -101,6 +101,9 @@ # hooks responsability to ensure they do not violate relation's cardinality if session.is_super_session: return + ensure_card_respected(session.unsafe_execute, session, eidfrom, rtype, eidto) + +def ensure_card_respected(execute, session, eidfrom, rtype, eidto): card = session.schema_rproperty(rtype, eidfrom, eidto, 'cardinality') # one may be tented to check for neweids but this may cause more than one # relation even with '1?' cardinality if thoses relations are added in the @@ -111,14 +114,11 @@ if card[0] in '1?': rschema = session.repo.schema.rschema(rtype) if not rschema.inlined: - session.unsafe_execute( - 'DELETE X %s Y WHERE X eid %%(x)s, NOT Y eid %%(y)s' % rtype, - {'x': eidfrom, 'y': eidto}, 'x') + execute('DELETE X %s Y WHERE X eid %%(x)s,NOT Y eid %%(y)s' % rtype, + {'x': eidfrom, 'y': eidto}, 'x') if card[1] in '1?': - session.unsafe_execute( - 'DELETE X %s Y WHERE NOT X eid %%(x)s, Y eid %%(y)s' % rtype, - {'x': eidfrom, 'y': eidto}, 'y') - + execute('DELETE X %s Y WHERE NOT X eid %%(x)s, Y eid %%(y)s' % rtype, + {'x': eidfrom, 'y': eidto}, 'y') class Repository(object): """a repository provides access to a set of persistent storages for @@ -142,6 +142,7 @@ self._running_threads = [] # initial schema, should be build or replaced latter self.schema = schema.CubicWebSchema(config.appid) + self.vreg.schema = self.schema # until actual schema is loaded... # querier helper, need to be created after sources initialization self.querier = querier.QuerierHelper(self, self.schema) # should we reindex in changes? @@ -183,7 +184,6 @@ config.bootstrap_cubes() self.set_schema(config.load_schema(), resetvreg=False) # need to load the Any and CWUser entity types - self.vreg.schema = self.schema etdirectory = join(CW_SOFTWARE_ROOT, 'entities') self.vreg.init_registration([etdirectory]) self.vreg.load_file(join(etdirectory, '__init__.py'), @@ -237,17 +237,18 @@ if rebuildinfered: schema.rebuild_infered_relations() self.info('set schema %s %#x', schema.name, id(schema)) - self.debug(', '.join(sorted(str(e) for e in schema.entities()))) - self.querier.set_schema(schema) - for source in self.sources: - source.set_schema(schema) - self.schema = schema if resetvreg: if self.config._cubes is None: self.config.init_cubes(self.get_cubes()) # full reload of all appobjects self.vreg.reset() self.vreg.set_schema(schema) + else: + self.vreg._set_schema(schema) + self.querier.set_schema(schema) + for source in self.sources: + source.set_schema(schema) + self.schema = schema def fill_schema(self): """lod schema from the repository"""