server/sources/native.py
changeset 8625 7ee0752178e5
parent 8573 ae0a567dff30
child 8694 d901c36bcfce
equal deleted inserted replaced
8624:7e415f457155 8625:7ee0752178e5
   959             raise
   959             raise
   960         else:
   960         else:
   961             cnx.commit()
   961             cnx.commit()
   962             return eid
   962             return eid
   963 
   963 
       
   964     def _handle_is_relation_sql(self, session, sql, attrs):
       
   965         """ Handler for specific is_relation sql that may be
       
   966         overwritten in some stores"""
       
   967         self.doexec(session, sql % attrs)
       
   968 
       
   969     _handle_insert_entity_sql = doexec
       
   970     _handle_is_instance_of_sql = _handle_source_relation_sql = _handle_is_relation_sql
       
   971 
   964     def add_info(self, session, entity, source, extid, complete):
   972     def add_info(self, session, entity, source, extid, complete):
   965         """add type and source info for an eid into the system table"""
   973         """add type and source info for an eid into the system table"""
   966         # begin by inserting eid/type/source/extid into the entities table
   974         # begin by inserting eid/type/source/extid into the entities table
   967         if extid is not None:
   975         if extid is not None:
   968             assert isinstance(extid, str)
   976             assert isinstance(extid, str)
   969             extid = b64encode(extid)
   977             extid = b64encode(extid)
   970         uri = 'system' if source.copy_based_source else source.uri
   978         uri = 'system' if source.copy_based_source else source.uri
   971         attrs = {'type': entity.__regid__, 'eid': entity.eid, 'extid': extid,
   979         attrs = {'type': entity.__regid__, 'eid': entity.eid, 'extid': extid,
   972                  'source': uri, 'asource': source.uri, 'mtime': datetime.utcnow()}
   980                  'source': uri, 'asource': source.uri, 'mtime': datetime.utcnow()}
   973         self.doexec(session, self.sqlgen.insert('entities', attrs), attrs)
   981         self._handle_insert_entity_sql(session, self.sqlgen.insert('entities', attrs), attrs)
   974         # insert core relations: is, is_instance_of and cw_source
   982         # insert core relations: is, is_instance_of and cw_source
   975         try:
   983         try:
   976             self.doexec(session, 'INSERT INTO is_relation(eid_from,eid_to) VALUES (%s,%s)'
   984             self._handle_is_relation_sql(session, 'INSERT INTO is_relation(eid_from,eid_to) VALUES (%s,%s)',
   977                         % (entity.eid, eschema_eid(session, entity.e_schema)))
   985                                          (entity.eid, eschema_eid(session, entity.e_schema)))
   978         except IndexError:
   986         except IndexError:
   979             # during schema serialization, skip
   987             # during schema serialization, skip
   980             pass
   988             pass
   981         else:
   989         else:
   982             for eschema in entity.e_schema.ancestors() + [entity.e_schema]:
   990             for eschema in entity.e_schema.ancestors() + [entity.e_schema]:
   983                 self.doexec(session, 'INSERT INTO is_instance_of_relation(eid_from,eid_to) VALUES (%s,%s)'
   991                 self._handle_is_relation_sql(session,
   984                            % (entity.eid, eschema_eid(session, eschema)))
   992                                              'INSERT INTO is_instance_of_relation(eid_from,eid_to) VALUES (%s,%s)',
       
   993                                              (entity.eid, eschema_eid(session, eschema)))
   985         if 'CWSource' in self.schema and source.eid is not None: # else, cw < 3.10
   994         if 'CWSource' in self.schema and source.eid is not None: # else, cw < 3.10
   986             self.doexec(session, 'INSERT INTO cw_source_relation(eid_from,eid_to) '
   995             self._handle_is_relation_sql(session, 'INSERT INTO cw_source_relation(eid_from,eid_to) VALUES (%s,%s)',
   987                         'VALUES (%s,%s)' % (entity.eid, source.eid))
   996                                          (entity.eid, source.eid))
   988         # now we can update the full text index
   997         # now we can update the full text index
   989         if self.do_fti and self.need_fti_indexation(entity.__regid__):
   998         if self.do_fti and self.need_fti_indexation(entity.__regid__):
   990             if complete:
   999             if complete:
   991                 entity.complete(entity.e_schema.indexable_attributes())
  1000                 entity.complete(entity.e_schema.indexable_attributes())
   992             self.index_entity(session, entity=entity)
  1001             self.index_entity(session, entity=entity)