server/session.py
branch3.5
changeset 2940 db2fb2907389
parent 2874 acdd8d8c2cff
child 2968 0e3460341023
child 3084 096d680c9da2
equal deleted inserted replaced
2939:a613cc003ab7 2940:db2fb2907389
    76 
    76 
    77     @property
    77     @property
    78     def schema(self):
    78     def schema(self):
    79         return self.repo.schema
    79         return self.repo.schema
    80 
    80 
    81     def add_relation(self, fromeid, rtype, toeid):
    81     def _change_relation(self, cb, fromeid, rtype, toeid):
    82         if self.is_super_session:
    82         if self.is_super_session:
    83             self.repo.glob_add_relation(self, fromeid, rtype, toeid)
    83             cb(self, fromeid, rtype, toeid)
    84             return
    84             return
    85         self.is_super_session = True
    85         self.is_super_session = True
    86         try:
    86         try:
    87             self.repo.glob_add_relation(self, fromeid, rtype, toeid)
    87             cb(self, fromeid, rtype, toeid)
    88         finally:
    88         finally:
    89             self.is_super_session = False
    89             self.is_super_session = False
       
    90 
       
    91     def add_relation(self, fromeid, rtype, toeid):
       
    92         """provide direct access to the repository method to add a relation.
       
    93 
       
    94         This is equivalent to the following rql query:
       
    95 
       
    96           SET X rtype Y WHERE X eid  fromeid, T eid toeid
       
    97 
       
    98         without read security check but also all the burden of rql execution.
       
    99         You may use this in hooks when you know both eids of the relation you
       
   100         want to add.
       
   101         """
       
   102         self._change_relation(self.repo.glob_add_relation,
       
   103                               fromeid, rtype, toeid)
       
   104     def delete_relation(self, fromeid, rtype, toeid):
       
   105         """provide direct access to the repository method to delete a relation.
       
   106 
       
   107         This is equivalent to the following rql query:
       
   108 
       
   109           DELETE X rtype Y WHERE X eid  fromeid, T eid toeid
       
   110 
       
   111         without read security check but also all the burden of rql execution.
       
   112         You may use this in hooks when you know both eids of the relation you
       
   113         want to delete.
       
   114         """
       
   115         self._change_relation(self.repo.glob_delete_relation,
       
   116                               fromeid, rtype, toeid)
    90 
   117 
    91     def update_rel_cache_add(self, subject, rtype, object, symetric=False):
   118     def update_rel_cache_add(self, subject, rtype, object, symetric=False):
    92         self._update_entity_rel_cache_add(subject, rtype, 'subject', object)
   119         self._update_entity_rel_cache_add(subject, rtype, 'subject', object)
    93         if symetric:
   120         if symetric:
    94             self._update_entity_rel_cache_add(object, rtype, 'subject', subject)
   121             self._update_entity_rel_cache_add(object, rtype, 'subject', subject)