1083 self._extid_cache[cachekey] = eid |
1083 self._extid_cache[cachekey] = eid |
1084 self._type_source_cache[eid] = (etype, uri, extid, source.uri) |
1084 self._type_source_cache[eid] = (etype, uri, extid, source.uri) |
1085 entity = source.before_entity_insertion( |
1085 entity = source.before_entity_insertion( |
1086 session, extid, etype, eid, sourceparams) |
1086 session, extid, etype, eid, sourceparams) |
1087 if source.should_call_hooks: |
1087 if source.should_call_hooks: |
|
1088 # get back a copy of operation for later restore if necessary, |
|
1089 # see below |
|
1090 pending_operations = session.pending_operations[:] |
1088 self.hm.call_hooks('before_add_entity', session, entity=entity) |
1091 self.hm.call_hooks('before_add_entity', session, entity=entity) |
1089 self.add_info(session, entity, source, extid, complete=complete) |
1092 self.add_info(session, entity, source, extid, complete=complete) |
1090 source.after_entity_insertion(session, extid, entity, sourceparams) |
1093 source.after_entity_insertion(session, extid, entity, sourceparams) |
1091 if source.should_call_hooks: |
1094 if source.should_call_hooks: |
1092 self.hm.call_hooks('after_add_entity', session, entity=entity) |
1095 self.hm.call_hooks('after_add_entity', session, entity=entity) |
1094 session.commit(free_cnxset) |
1097 session.commit(free_cnxset) |
1095 return eid |
1098 return eid |
1096 except Exception: |
1099 except Exception: |
1097 if commit or free_cnxset: |
1100 if commit or free_cnxset: |
1098 session.rollback(free_cnxset) |
1101 session.rollback(free_cnxset) |
|
1102 else: |
|
1103 # XXX do some cleanup manually so that the transaction has a |
|
1104 # chance to be commited, with simply this entity discarded |
|
1105 self._extid_cache.pop(cachekey, None) |
|
1106 self._type_source_cache.pop(eid, None) |
|
1107 if 'entity' in locals(): |
|
1108 hook.CleanupDeletedEidsCacheOp.get_instance(session).add_data(entity.eid) |
|
1109 self.system_source.delete_info_multi(session, [entity], uri) |
|
1110 if source.should_call_hooks: |
|
1111 session._threaddata.pending_operations = pending_operations |
1099 raise |
1112 raise |
1100 |
1113 |
1101 def add_info(self, session, entity, source, extid=None, complete=True): |
1114 def add_info(self, session, entity, source, extid=None, complete=True): |
1102 """add type and source info for an eid into the system table, |
1115 """add type and source info for an eid into the system table, |
1103 and index the entity with the full text index |
1116 and index the entity with the full text index |