server/repository.py
branch3.5
changeset 3250 65618fd34548
parent 3240 8604a15995d1
child 3293 69c0ba095536
child 3539 f3b14d052798
equal deleted inserted replaced
3249:280080eadb22 3250:65618fd34548
   106     """
   106     """
   107     # skip delete queries (only?) if session is an internal session. This is
   107     # skip delete queries (only?) if session is an internal session. This is
   108     # hooks responsability to ensure they do not violate relation's cardinality
   108     # hooks responsability to ensure they do not violate relation's cardinality
   109     if session.is_super_session:
   109     if session.is_super_session:
   110         return
   110         return
       
   111     ensure_card_respected(session.unsafe_execute, session, eidfrom, rtype, eidto)
       
   112 
       
   113 def ensure_card_respected(execute, session, eidfrom, rtype, eidto):
   111     card = rproperty(session, rtype, eidfrom, eidto, 'cardinality')
   114     card = rproperty(session, rtype, eidfrom, eidto, 'cardinality')
   112     # one may be tented to check for neweids but this may cause more than one
   115     # one may be tented to check for neweids but this may cause more than one
   113     # relation even with '1?'  cardinality if thoses relations are added in the
   116     # relation even with '1?'  cardinality if thoses relations are added in the
   114     # same transaction where the entity is being created. This never occurs from
   117     # same transaction where the entity is being created. This never occurs from
   115     # the web interface but may occurs during test or dbapi connection (though
   118     # the web interface but may occurs during test or dbapi connection (though
   116     # not expected for this).  So: don't do it, we pretend to ensure repository
   119     # not expected for this).  So: don't do it, we pretend to ensure repository
   117     # consistency.
   120     # consistency.
   118     if card[0] in '1?':
   121     if card[0] in '1?':
   119         rschema = session.repo.schema.rschema(rtype)
   122         rschema = session.repo.schema.rschema(rtype)
   120         if not rschema.inlined:
   123         if not rschema.inlined:
   121             session.unsafe_execute(
   124             execute('DELETE X %s Y WHERE X eid %%(x)s,NOT Y eid %%(y)s' % rtype,
   122                 'DELETE X %s Y WHERE X eid %%(x)s, NOT Y eid %%(y)s' % rtype,
   125                     {'x': eidfrom, 'y': eidto}, 'x')
   123                 {'x': eidfrom, 'y': eidto}, 'x')
       
   124     if card[1] in '1?':
   126     if card[1] in '1?':
   125         session.unsafe_execute(
   127         execute('DELETE X %s Y WHERE NOT X eid %%(x)s, Y eid %%(y)s' % rtype,
   126             'DELETE X %s Y WHERE NOT X eid %%(x)s, Y eid %%(y)s' % rtype,
   128                 {'x': eidfrom, 'y': eidto}, 'y')
   127             {'x': eidfrom, 'y': eidto}, 'y')
       
   128 
       
   129 
   129 
   130 class Repository(object):
   130 class Repository(object):
   131     """a repository provides access to a set of persistent storages for
   131     """a repository provides access to a set of persistent storages for
   132     entities and relations
   132     entities and relations
   133 
   133