server/repository.py
branchstable
changeset 3694 33dbb1da1db9
parent 3689 deb13e88e037
child 3720 5376aaadd16b
child 3757 122a01751d59
equal deleted inserted replaced
3693:92581287726f 3694:33dbb1da1db9
    93             session.repo.index_entity(session, container)
    93             session.repo.index_entity(session, container)
    94 
    94 
    95     def commit_event(self):
    95     def commit_event(self):
    96         pass
    96         pass
    97 
    97 
       
    98 
    98 def del_existing_rel_if_needed(session, eidfrom, rtype, eidto):
    99 def del_existing_rel_if_needed(session, eidfrom, rtype, eidto):
    99     """delete existing relation when adding a new one if card is 1 or ?
   100     """delete existing relation when adding a new one if card is 1 or ?
   100 
   101 
   101     have to be done once the new relation has been inserted to avoid having
   102     have to be done once the new relation has been inserted to avoid having
   102     an entity without a relation for some time
   103     an entity without a relation for some time
   107     # skip delete queries (only?) if session is an internal session. This is
   108     # skip delete queries (only?) if session is an internal session. This is
   108     # hooks responsability to ensure they do not violate relation's cardinality
   109     # hooks responsability to ensure they do not violate relation's cardinality
   109     if session.is_super_session:
   110     if session.is_super_session:
   110         return
   111         return
   111     ensure_card_respected(session.unsafe_execute, session, eidfrom, rtype, eidto)
   112     ensure_card_respected(session.unsafe_execute, session, eidfrom, rtype, eidto)
       
   113 
   112 
   114 
   113 def ensure_card_respected(execute, session, eidfrom, rtype, eidto):
   115 def ensure_card_respected(execute, session, eidfrom, rtype, eidto):
   114     card = rproperty(session, rtype, eidfrom, eidto, 'cardinality')
   116     card = rproperty(session, rtype, eidfrom, eidto, 'cardinality')
   115     # one may be tented to check for neweids but this may cause more than one
   117     # one may be tented to check for neweids but this may cause more than one
   116     # relation even with '1?'  cardinality if thoses relations are added in the
   118     # relation even with '1?'  cardinality if thoses relations are added in the
   124             execute('DELETE X %s Y WHERE X eid %%(x)s,NOT Y eid %%(y)s' % rtype,
   126             execute('DELETE X %s Y WHERE X eid %%(x)s,NOT Y eid %%(y)s' % rtype,
   125                     {'x': eidfrom, 'y': eidto}, 'x')
   127                     {'x': eidfrom, 'y': eidto}, 'x')
   126     if card[1] in '1?':
   128     if card[1] in '1?':
   127         execute('DELETE X %s Y WHERE NOT X eid %%(x)s, Y eid %%(y)s' % rtype,
   129         execute('DELETE X %s Y WHERE NOT X eid %%(x)s, Y eid %%(y)s' % rtype,
   128                 {'x': eidfrom, 'y': eidto}, 'y')
   130                 {'x': eidfrom, 'y': eidto}, 'y')
       
   131 
   129 
   132 
   130 class Repository(object):
   133 class Repository(object):
   131     """a repository provides access to a set of persistent storages for
   134     """a repository provides access to a set of persistent storages for
   132     entities and relations
   135     entities and relations
   133 
   136