server/repository.py
changeset 7237 9f619715665b
parent 7134 01544b6d98fa
child 7238 576abb8c4626
equal deleted inserted replaced
7236:b91205ada414 7237:9f619715665b
  1373                 self.hm.call_hooks('after_delete_entity', session, entities=entities)
  1373                 self.hm.call_hooks('after_delete_entity', session, entities=entities)
  1374         # don't clear cache here this is done in a hook on commit
  1374         # don't clear cache here this is done in a hook on commit
  1375 
  1375 
  1376     def glob_add_relation(self, session, subject, rtype, object):
  1376     def glob_add_relation(self, session, subject, rtype, object):
  1377         """add a relation to the repository"""
  1377         """add a relation to the repository"""
  1378         if server.DEBUG & server.DBG_REPO:
  1378         self.glob_add_relations(session, {rtype: [(subject, object)]})
  1379             print 'ADD relation', subject, rtype, object
  1379 
  1380         source = self.locate_relation_source(session, subject, rtype, object)
  1380     def glob_add_relations(self, session, relations):
  1381         if source.should_call_hooks:
  1381         """add several relations to the repository
  1382             del_existing_rel_if_needed(session, subject, rtype, object)
  1382 
  1383             self.hm.call_hooks('before_add_relation', session,
  1383         relations is a dictionary rtype: [(subj_eid, obj_eid), ...]
  1384                                eidfrom=subject, rtype=rtype, eidto=object)
  1384         """
  1385         source.add_relation(session, subject, rtype, object)
  1385         sources = {}
  1386         rschema = self.schema.rschema(rtype)
  1386         for rtype, eids_subj_obj in relations.iteritems():
  1387         session.update_rel_cache_add(subject, rtype, object, rschema.symmetric)
  1387             if server.DEBUG & server.DBG_REPO:
  1388         if source.should_call_hooks:
  1388                 for subject, object in relations:
  1389             self.hm.call_hooks('after_add_relation', session,
  1389                     print 'ADD relation', subject, rtype, object
  1390                                eidfrom=subject, rtype=rtype, eidto=object)
  1390             for subject, object in eids_subj_obj:
       
  1391                 source = self.locate_relation_source(session, subject, rtype, object)
       
  1392                 if source in sources:
       
  1393                     sources[source][1].append((subject, object))
       
  1394                 else:
       
  1395                     sources[source] = rtype, [(subject, object)]
       
  1396         for source, (rtype, source_relations) in sources.iteritems():
       
  1397             if source.should_call_hooks:
       
  1398                 for subject, object in source_relations:
       
  1399                     del_existing_rel_if_needed(session, subject, rtype, object)
       
  1400                 self.hm.call_hooks('before_add_relation', session,
       
  1401                                     rtype=rtype, eids_from_to=source_relations)
       
  1402             source.add_relations(session, rtype, source_relations)
       
  1403             rschema = self.schema.rschema(rtype)
       
  1404             for subject, object in source_relations:
       
  1405                 session.update_rel_cache_add(subject, rtype, object, rschema.symmetric)
       
  1406             if source.should_call_hooks:
       
  1407                 self.hm.call_hooks('after_add_relation', session,
       
  1408                                    rtype=rtype, eids_from_to=source_relations)
  1391 
  1409 
  1392     def glob_delete_relation(self, session, subject, rtype, object):
  1410     def glob_delete_relation(self, session, subject, rtype, object):
  1393         """delete a relation from the repository"""
  1411         """delete a relation from the repository"""
  1394         if server.DEBUG & server.DBG_REPO:
  1412         if server.DEBUG & server.DBG_REPO:
  1395             print 'DELETE relation', subject, rtype, object
  1413             print 'DELETE relation', subject, rtype, object