server/sources/native.py
changeset 7237 9f619715665b
parent 7202 5b80f5ee61b5
child 7243 9ab01bf84eac
equal deleted inserted replaced
7236:b91205ada414 7237:9f619715665b
   626             sql = self.sqlgen.delete(SQL_PREFIX + entity.__regid__, attrs)
   626             sql = self.sqlgen.delete(SQL_PREFIX + entity.__regid__, attrs)
   627             self.doexec(session, sql, attrs)
   627             self.doexec(session, sql, attrs)
   628 
   628 
   629     def add_relation(self, session, subject, rtype, object, inlined=False):
   629     def add_relation(self, session, subject, rtype, object, inlined=False):
   630         """add a relation to the source"""
   630         """add a relation to the source"""
   631         self._add_relation(session, subject, rtype, object, inlined)
   631         self._add_relations(session,  rtype, [(subject, object)], inlined)
   632         if session.undoable_action('A', rtype):
   632         if session.undoable_action('A', rtype):
   633             self._record_tx_action(session, 'tx_relation_actions', 'A',
   633             self._record_tx_action(session, 'tx_relation_actions', 'A',
   634                                    eid_from=subject, rtype=rtype, eid_to=object)
   634                                    eid_from=subject, rtype=rtype, eid_to=object)
   635 
   635 
   636     def _add_relation(self, session, subject, rtype, object, inlined=False):
   636     def add_relations(self, session,  rtype, subj_obj_list, inlined=False):
       
   637         """add a relations to the source"""
       
   638         self._add_relations(session, rtype, subj_obj_list, inlined)
       
   639         if session.undoable_action('A', rtype):
       
   640             for subject, object in subj_obj_list:
       
   641                 self._record_tx_action(session, 'tx_relation_actions', 'A',
       
   642                                        eid_from=subject, rtype=rtype, eid_to=object)
       
   643                 
       
   644     def _add_relations(self, session, rtype, subj_obj_list, inlined=False):
   637         """add a relation to the source"""
   645         """add a relation to the source"""
   638         if inlined is False:
   646         if inlined is False:
   639             attrs = {'eid_from': subject, 'eid_to': object}
   647             attrs = [{'eid_from': subject, 'eid_to': object}
   640             sql = self.sqlgen.insert('%s_relation' % rtype, attrs)
   648                      for subject, object in subj_obj_list]
       
   649             sql = self.sqlgen.insert('%s_relation' % rtype, attrs[0])
   641         else: # used by data import
   650         else: # used by data import
   642             etype = session.describe(subject)[0]
   651             etype = session.describe(subject)[0]
   643             attrs = {'cw_eid': subject, SQL_PREFIX + rtype: object}
   652             attrs = [{'cw_eid': subject, SQL_PREFIX + rtype: object}
   644             sql = self.sqlgen.update(SQL_PREFIX + etype, attrs,
   653                      for subject, object in subj_obj_list]
       
   654             sql = self.sqlgen.update(SQL_PREFIX + etype, attrs[0],
   645                                      ['cw_eid'])
   655                                      ['cw_eid'])
   646         self.doexec(session, sql, attrs)
   656         self.doexecmany(session, sql, attrs)
   647 
   657 
   648     def delete_relation(self, session, subject, rtype, object):
   658     def delete_relation(self, session, subject, rtype, object):
   649         """delete a relation from the source"""
   659         """delete a relation from the source"""
   650         rschema = self.schema.rschema(rtype)
   660         rschema = self.schema.rschema(rtype)
   651         self._delete_relation(session, subject, rtype, object, rschema.inlined)
   661         self._delete_relation(session, subject, rtype, object, rschema.inlined)