1387 if server.DEBUG & server.DBG_REPO: |
1387 if server.DEBUG & server.DBG_REPO: |
1388 for subject, object in relations: |
1388 for subject, object in relations: |
1389 print 'ADD relation', subject, rtype, object |
1389 print 'ADD relation', subject, rtype, object |
1390 for subject, object in eids_subj_obj: |
1390 for subject, object in eids_subj_obj: |
1391 source = self.locate_relation_source(session, subject, rtype, object) |
1391 source = self.locate_relation_source(session, subject, rtype, object) |
1392 if source in sources: |
1392 if source not in sources: |
1393 sources[source][1].append((subject, object)) |
1393 relations_by_rtype = {} |
|
1394 sources[source] = relations_by_rtype |
1394 else: |
1395 else: |
1395 sources[source] = rtype, [(subject, object)] |
1396 relations_by_rtype = sources[source] |
1396 for source, (rtype, source_relations) in sources.iteritems(): |
1397 if rtype in relations_by_rtype: |
|
1398 relations_by_rtype[rtype].append((subject, object)) |
|
1399 else: |
|
1400 relations_by_rtype[rtype] = [(subject, object)] |
|
1401 for source, relations_by_rtype in sources.iteritems(): |
1397 if source.should_call_hooks: |
1402 if source.should_call_hooks: |
|
1403 for rtype, source_relations in relations_by_rtype.iteritems(): |
|
1404 for subject, object in source_relations: |
|
1405 del_existing_rel_if_needed(session, subject, rtype, object) |
|
1406 self.hm.call_hooks('before_add_relation', session, |
|
1407 rtype=rtype, eids_from_to=source_relations) |
|
1408 for rtype, source_relations in relations_by_rtype.iteritems(): |
|
1409 source.add_relations(session, rtype, source_relations) |
|
1410 rschema = self.schema.rschema(rtype) |
1398 for subject, object in source_relations: |
1411 for subject, object in source_relations: |
1399 del_existing_rel_if_needed(session, subject, rtype, object) |
1412 session.update_rel_cache_add(subject, rtype, object, rschema.symmetric) |
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: |
1413 if source.should_call_hooks: |
1407 self.hm.call_hooks('after_add_relation', session, |
1414 for rtype, source_relations in relations_by_rtype.iteritems(): |
1408 rtype=rtype, eids_from_to=source_relations) |
1415 self.hm.call_hooks('after_add_relation', session, |
|
1416 rtype=rtype, eids_from_to=source_relations) |
1409 |
1417 |
1410 def glob_delete_relation(self, session, subject, rtype, object): |
1418 def glob_delete_relation(self, session, subject, rtype, object): |
1411 """delete a relation from the repository""" |
1419 """delete a relation from the repository""" |
1412 if server.DEBUG & server.DBG_REPO: |
1420 if server.DEBUG & server.DBG_REPO: |
1413 print 'DELETE relation', subject, rtype, object |
1421 print 'DELETE relation', subject, rtype, object |