23 |
23 |
24 * brings these classes all together to provide a single access |
24 * brings these classes all together to provide a single access |
25 point to a cubicweb instance. |
25 point to a cubicweb instance. |
26 * handles session management |
26 * handles session management |
27 """ |
27 """ |
|
28 from __future__ import print_function |
|
29 |
28 __docformat__ = "restructuredtext en" |
30 __docformat__ = "restructuredtext en" |
29 |
31 |
30 import threading |
32 import threading |
31 import Queue |
33 import Queue |
32 from warnings import warn |
34 from warnings import warn |
910 # allocate an eid to the entity before calling hooks |
912 # allocate an eid to the entity before calling hooks |
911 entity.eid = self.system_source.create_eid(cnx) |
913 entity.eid = self.system_source.create_eid(cnx) |
912 # set caches asap |
914 # set caches asap |
913 extid = self.init_entity_caches(cnx, entity, source) |
915 extid = self.init_entity_caches(cnx, entity, source) |
914 if server.DEBUG & server.DBG_REPO: |
916 if server.DEBUG & server.DBG_REPO: |
915 print 'ADD entity', self, entity.cw_etype, entity.eid, edited |
917 print('ADD entity', self, entity.cw_etype, entity.eid, edited) |
916 prefill_entity_caches(entity) |
918 prefill_entity_caches(entity) |
917 self.hm.call_hooks('before_add_entity', cnx, entity=entity) |
919 self.hm.call_hooks('before_add_entity', cnx, entity=entity) |
918 relations = preprocess_inlined_relations(cnx, entity) |
920 relations = preprocess_inlined_relations(cnx, entity) |
919 edited.set_defaults() |
921 edited.set_defaults() |
920 if cnx.is_hook_category_activated('integrity'): |
922 if cnx.is_hook_category_activated('integrity'): |
941 """replace an entity in the repository |
943 """replace an entity in the repository |
942 the type and the eid of an entity must not be changed |
944 the type and the eid of an entity must not be changed |
943 """ |
945 """ |
944 entity = edited.entity |
946 entity = edited.entity |
945 if server.DEBUG & server.DBG_REPO: |
947 if server.DEBUG & server.DBG_REPO: |
946 print 'UPDATE entity', entity.cw_etype, entity.eid, \ |
948 print('UPDATE entity', entity.cw_etype, entity.eid, |
947 entity.cw_attr_cache, edited |
949 entity.cw_attr_cache, edited) |
948 hm = self.hm |
950 hm = self.hm |
949 eschema = entity.e_schema |
951 eschema = entity.e_schema |
950 cnx.set_entity_cache(entity) |
952 cnx.set_entity_cache(entity) |
951 orig_edited = getattr(entity, 'cw_edited', None) |
953 orig_edited = getattr(entity, 'cw_edited', None) |
952 entity.cw_edited = edited |
954 entity.cw_edited = edited |
1036 except KeyError: |
1038 except KeyError: |
1037 data_by_etype[etype] = [entity] |
1039 data_by_etype[etype] = [entity] |
1038 source = self.system_source |
1040 source = self.system_source |
1039 for etype, entities in data_by_etype.iteritems(): |
1041 for etype, entities in data_by_etype.iteritems(): |
1040 if server.DEBUG & server.DBG_REPO: |
1042 if server.DEBUG & server.DBG_REPO: |
1041 print 'DELETE entities', etype, [entity.eid for entity in entities] |
1043 print('DELETE entities', etype, [entity.eid for entity in entities]) |
1042 self.hm.call_hooks('before_delete_entity', cnx, entities=entities) |
1044 self.hm.call_hooks('before_delete_entity', cnx, entities=entities) |
1043 self._delete_cascade_multi(cnx, entities) |
1045 self._delete_cascade_multi(cnx, entities) |
1044 source.delete_entities(cnx, entities) |
1046 source.delete_entities(cnx, entities) |
1045 source.delete_info_multi(cnx, entities) |
1047 source.delete_info_multi(cnx, entities) |
1046 self.hm.call_hooks('after_delete_entity', cnx, entities=entities) |
1048 self.hm.call_hooks('after_delete_entity', cnx, entities=entities) |
1061 objects_by_types = {} |
1063 objects_by_types = {} |
1062 activintegrity = cnx.is_hook_category_activated('activeintegrity') |
1064 activintegrity = cnx.is_hook_category_activated('activeintegrity') |
1063 for rtype, eids_subj_obj in relations.iteritems(): |
1065 for rtype, eids_subj_obj in relations.iteritems(): |
1064 if server.DEBUG & server.DBG_REPO: |
1066 if server.DEBUG & server.DBG_REPO: |
1065 for subjeid, objeid in eids_subj_obj: |
1067 for subjeid, objeid in eids_subj_obj: |
1066 print 'ADD relation', subjeid, rtype, objeid |
1068 print('ADD relation', subjeid, rtype, objeid) |
1067 for subjeid, objeid in eids_subj_obj: |
1069 for subjeid, objeid in eids_subj_obj: |
1068 if rtype in relations_by_rtype: |
1070 if rtype in relations_by_rtype: |
1069 relations_by_rtype[rtype].append((subjeid, objeid)) |
1071 relations_by_rtype[rtype].append((subjeid, objeid)) |
1070 else: |
1072 else: |
1071 relations_by_rtype[rtype] = [(subjeid, objeid)] |
1073 relations_by_rtype[rtype] = [(subjeid, objeid)] |
1111 rtype=rtype, eids_from_to=source_relations) |
1113 rtype=rtype, eids_from_to=source_relations) |
1112 |
1114 |
1113 def glob_delete_relation(self, cnx, subject, rtype, object): |
1115 def glob_delete_relation(self, cnx, subject, rtype, object): |
1114 """delete a relation from the repository""" |
1116 """delete a relation from the repository""" |
1115 if server.DEBUG & server.DBG_REPO: |
1117 if server.DEBUG & server.DBG_REPO: |
1116 print 'DELETE relation', subject, rtype, object |
1118 print('DELETE relation', subject, rtype, object) |
1117 source = self.system_source |
1119 source = self.system_source |
1118 self.hm.call_hooks('before_delete_relation', cnx, |
1120 self.hm.call_hooks('before_delete_relation', cnx, |
1119 eidfrom=subject, rtype=rtype, eidto=object) |
1121 eidfrom=subject, rtype=rtype, eidto=object) |
1120 source.delete_relation(cnx, subject, rtype, object) |
1122 source.delete_relation(cnx, subject, rtype, object) |
1121 rschema = self.schema.rschema(rtype) |
1123 rschema = self.schema.rschema(rtype) |