server/session.py
changeset 9079 f8c8e79218e1
parent 9078 cfefd64c7039
child 9081 7c9a6dc4ee5d
equal deleted inserted replaced
9078:cfefd64c7039 9079:f8c8e79218e1
   588         If eid is None, the whole cache is dropped"""
   588         If eid is None, the whole cache is dropped"""
   589         if eid is None:
   589         if eid is None:
   590             self.transaction_data.pop('ecache', None)
   590             self.transaction_data.pop('ecache', None)
   591         else:
   591         else:
   592             del self.transaction_data['ecache'][eid]
   592             del self.transaction_data['ecache'][eid]
       
   593 
       
   594     # relations handling #######################################################
       
   595 
       
   596     def add_relation(self, fromeid, rtype, toeid):
       
   597         """provide direct access to the repository method to add a relation.
       
   598 
       
   599         This is equivalent to the following rql query:
       
   600 
       
   601           SET X rtype Y WHERE X eid  fromeid, T eid toeid
       
   602 
       
   603         without read security check but also all the burden of rql execution.
       
   604         You may use this in hooks when you know both eids of the relation you
       
   605         want to add.
       
   606         """
       
   607         self.add_relations([(rtype, [(fromeid,  toeid)])])
       
   608 
       
   609     def add_relations(self, relations):
       
   610         '''set many relation using a shortcut similar to the one in add_relation
       
   611 
       
   612         relations is a list of 2-uples, the first element of each
       
   613         2-uple is the rtype, and the second is a list of (fromeid,
       
   614         toeid) tuples
       
   615         '''
       
   616         edited_entities = {}
       
   617         relations_dict = {}
       
   618         with self.security_enabled(False, False):
       
   619             for rtype, eids in relations:
       
   620                 if self.vreg.schema[rtype].inlined:
       
   621                     for fromeid, toeid in eids:
       
   622                         if fromeid not in edited_entities:
       
   623                             entity = self.entity_from_eid(fromeid)
       
   624                             edited = EditedEntity(entity)
       
   625                             edited_entities[fromeid] = edited
       
   626                         else:
       
   627                             edited = edited_entities[fromeid]
       
   628                         edited.edited_attribute(rtype, toeid)
       
   629                 else:
       
   630                     relations_dict[rtype] = eids
       
   631             self.repo.glob_add_relations(self, relations_dict)
       
   632             for edited in edited_entities.itervalues():
       
   633                 self.repo.glob_update_entity(self, edited)
       
   634 
       
   635 
       
   636     def delete_relation(self, fromeid, rtype, toeid):
       
   637         """provide direct access to the repository method to delete a relation.
       
   638 
       
   639         This is equivalent to the following rql query:
       
   640 
       
   641           DELETE X rtype Y WHERE X eid  fromeid, T eid toeid
       
   642 
       
   643         without read security check but also all the burden of rql execution.
       
   644         You may use this in hooks when you know both eids of the relation you
       
   645         want to delete.
       
   646         """
       
   647         with self.security_enabled(False, False):
       
   648             if self.vreg.schema[rtype].inlined:
       
   649                 entity = self.entity_from_eid(fromeid)
       
   650                 entity.cw_attr_cache[rtype] = None
       
   651                 self.repo.glob_update_entity(self, entity, set((rtype,)))
       
   652             else:
       
   653                 self.repo.glob_delete_relation(self, fromeid, rtype, toeid)
   593 
   654 
   594     # relations cache handling #################################################
   655     # relations cache handling #################################################
   595 
   656 
   596     def update_rel_cache_add(self, subject, rtype, object, symmetric=False):
   657     def update_rel_cache_add(self, subject, rtype, object, symmetric=False):
   597         self._update_entity_rel_cache_add(subject, rtype, 'subject', object)
   658         self._update_entity_rel_cache_add(subject, rtype, 'subject', object)
  1059         The `free_cnxset` will be given to rollback/commit methods to indicate
  1120         The `free_cnxset` will be given to rollback/commit methods to indicate
  1060         wether the connections set should be freed or not.
  1121         wether the connections set should be freed or not.
  1061         """
  1122         """
  1062         return transaction(self, free_cnxset)
  1123         return transaction(self, free_cnxset)
  1063 
  1124 
  1064     def add_relation(self, fromeid, rtype, toeid):
  1125     add_relation = cnx_meth('add_relation')
  1065         """provide direct access to the repository method to add a relation.
  1126     add_relations = cnx_meth('add_relations')
  1066 
  1127     delete_relation = cnx_meth('delete_relation')
  1067         This is equivalent to the following rql query:
       
  1068 
       
  1069           SET X rtype Y WHERE X eid  fromeid, T eid toeid
       
  1070 
       
  1071         without read security check but also all the burden of rql execution.
       
  1072         You may use this in hooks when you know both eids of the relation you
       
  1073         want to add.
       
  1074         """
       
  1075         self.add_relations([(rtype, [(fromeid,  toeid)])])
       
  1076 
       
  1077     def add_relations(self, relations):
       
  1078         '''set many relation using a shortcut similar to the one in add_relation
       
  1079 
       
  1080         relations is a list of 2-uples, the first element of each
       
  1081         2-uple is the rtype, and the second is a list of (fromeid,
       
  1082         toeid) tuples
       
  1083         '''
       
  1084         edited_entities = {}
       
  1085         relations_dict = {}
       
  1086         with self.security_enabled(False, False):
       
  1087             for rtype, eids in relations:
       
  1088                 if self.vreg.schema[rtype].inlined:
       
  1089                     for fromeid, toeid in eids:
       
  1090                         if fromeid not in edited_entities:
       
  1091                             entity = self.entity_from_eid(fromeid)
       
  1092                             edited = EditedEntity(entity)
       
  1093                             edited_entities[fromeid] = edited
       
  1094                         else:
       
  1095                             edited = edited_entities[fromeid]
       
  1096                         edited.edited_attribute(rtype, toeid)
       
  1097                 else:
       
  1098                     relations_dict[rtype] = eids
       
  1099             self.repo.glob_add_relations(self, relations_dict)
       
  1100             for edited in edited_entities.itervalues():
       
  1101                 self.repo.glob_update_entity(self, edited)
       
  1102 
       
  1103 
       
  1104     def delete_relation(self, fromeid, rtype, toeid):
       
  1105         """provide direct access to the repository method to delete a relation.
       
  1106 
       
  1107         This is equivalent to the following rql query:
       
  1108 
       
  1109           DELETE X rtype Y WHERE X eid  fromeid, T eid toeid
       
  1110 
       
  1111         without read security check but also all the burden of rql execution.
       
  1112         You may use this in hooks when you know both eids of the relation you
       
  1113         want to delete.
       
  1114         """
       
  1115         with self.security_enabled(False, False):
       
  1116             if self.vreg.schema[rtype].inlined:
       
  1117                 entity = self.entity_from_eid(fromeid)
       
  1118                 entity.cw_attr_cache[rtype] = None
       
  1119                 self.repo.glob_update_entity(self, entity, set((rtype,)))
       
  1120             else:
       
  1121                 self.repo.glob_delete_relation(self, fromeid, rtype, toeid)
       
  1122 
  1128 
  1123     # relations cache handling #################################################
  1129     # relations cache handling #################################################
  1124 
  1130 
  1125     update_rel_cache_add = cnx_meth('update_rel_cache_add')
  1131     update_rel_cache_add = cnx_meth('update_rel_cache_add')
  1126     update_rel_cache_del = cnx_meth('update_rel_cache_del')
  1132     update_rel_cache_del = cnx_meth('update_rel_cache_del')