261 'want trusted authentication for the database connection', |
261 'want trusted authentication for the database connection', |
262 'group': 'native-source', 'level': 2, |
262 'group': 'native-source', 'level': 2, |
263 }), |
263 }), |
264 ) |
264 ) |
265 |
265 |
266 def __init__(self, repo, appschema, source_config, *args, **kwargs): |
266 def __init__(self, repo, source_config, *args, **kwargs): |
267 SQLAdapterMixIn.__init__(self, source_config) |
267 SQLAdapterMixIn.__init__(self, source_config) |
268 self.authentifiers = [LoginPasswordAuthentifier(self)] |
268 self.authentifiers = [LoginPasswordAuthentifier(self)] |
269 AbstractSource.__init__(self, repo, appschema, source_config, |
269 AbstractSource.__init__(self, repo, source_config, *args, **kwargs) |
270 *args, **kwargs) |
|
271 # sql generator |
270 # sql generator |
272 self._rql_sqlgen = self.sqlgen_class(appschema, self.dbhelper, |
271 self._rql_sqlgen = self.sqlgen_class(self.schema, self.dbhelper, |
273 ATTR_MAP.copy()) |
272 ATTR_MAP.copy()) |
274 # full text index helper |
273 # full text index helper |
275 self.do_fti = not repo.config['delay-full-text-indexation'] |
274 self.do_fti = not repo.config['delay-full-text-indexation'] |
276 # sql queries cache |
275 # sql queries cache |
277 self._cache = Cache(repo.config['rql-cache-size']) |
276 self._cache = Cache(repo.config['rql-cache-size']) |
878 assert isinstance(extid, str) |
877 assert isinstance(extid, str) |
879 extid = b64encode(extid) |
878 extid = b64encode(extid) |
880 attrs = {'type': entity.__regid__, 'eid': entity.eid, 'extid': extid, |
879 attrs = {'type': entity.__regid__, 'eid': entity.eid, 'extid': extid, |
881 'source': source.uri, 'mtime': datetime.now()} |
880 'source': source.uri, 'mtime': datetime.now()} |
882 self.doexec(session, self.sqlgen.insert('entities', attrs), attrs) |
881 self.doexec(session, self.sqlgen.insert('entities', attrs), attrs) |
|
882 # insert core relations: is, is_instance_of and cw_source |
|
883 if not hasattr(entity, '_cw_recreating'): |
|
884 try: |
|
885 self.doexec(session, 'INSERT INTO is_relation(eid_from,eid_to) VALUES (%s,%s)' |
|
886 % (entity.eid, eschema_eid(session, entity.e_schema))) |
|
887 except IndexError: |
|
888 # during schema serialization, skip |
|
889 pass |
|
890 else: |
|
891 for eschema in entity.e_schema.ancestors() + [entity.e_schema]: |
|
892 self.doexec(session, 'INSERT INTO is_instance_of_relation(eid_from,eid_to) VALUES (%s,%s)' |
|
893 % (entity.eid, eschema_eid(session, eschema))) |
|
894 if 'CWSource' in self.schema and source.eid is not None: # else, cw < 3.10 |
|
895 self.doexec(session, 'INSERT INTO cw_source_relation(eid_from,eid_to) ' |
|
896 'VALUES (%s,%s)' % (entity.eid, source.eid)) |
883 # now we can update the full text index |
897 # now we can update the full text index |
884 if self.do_fti and self.need_fti_indexation(entity.__regid__): |
898 if self.do_fti and self.need_fti_indexation(entity.__regid__): |
885 if complete: |
899 if complete: |
886 entity.complete(entity.e_schema.indexable_attributes()) |
900 entity.complete(entity.e_schema.indexable_attributes()) |
887 self.index_entity(session, entity=entity) |
901 self.index_entity(session, entity=entity) |
924 * list of (etype, eid) of entities of the given types which have been |
938 * list of (etype, eid) of entities of the given types which have been |
925 deleted since the given timestamp |
939 deleted since the given timestamp |
926 """ |
940 """ |
927 for etype in etypes: |
941 for etype in etypes: |
928 if not etype in self.multisources_etypes: |
942 if not etype in self.multisources_etypes: |
929 self.critical('%s not listed as a multi-sources entity types. ' |
943 self.error('%s not listed as a multi-sources entity types. ' |
930 'Modify your configuration' % etype) |
944 'Modify your configuration' % etype) |
931 self.multisources_etypes.add(etype) |
945 self.multisources_etypes.add(etype) |
932 modsql = _modified_sql('entities', etypes) |
946 modsql = _modified_sql('entities', etypes) |
933 cursor = self.doexec(session, modsql, {'time': mtime}) |
947 cursor = self.doexec(session, modsql, {'time': mtime}) |
934 modentities = cursor.fetchall() |
948 modentities = cursor.fetchall() |
1155 self.repo.hm.call_hooks('before_add_entity', session, entity=entity) |
1169 self.repo.hm.call_hooks('before_add_entity', session, entity=entity) |
1156 # restore the entity |
1170 # restore the entity |
1157 action.changes['cw_eid'] = eid |
1171 action.changes['cw_eid'] = eid |
1158 sql = self.sqlgen.insert(SQL_PREFIX + etype, action.changes) |
1172 sql = self.sqlgen.insert(SQL_PREFIX + etype, action.changes) |
1159 self.doexec(session, sql, action.changes) |
1173 self.doexec(session, sql, action.changes) |
1160 # add explicitly is / is_instance_of whose deletion is not recorded for |
|
1161 # consistency with addition (done by sql in hooks) |
|
1162 self.doexec(session, 'INSERT INTO is_relation(eid_from, eid_to) ' |
|
1163 'VALUES(%s, %s)' % (eid, eschema_eid(session, eschema))) |
|
1164 for eschema in entity.e_schema.ancestors() + [entity.e_schema]: |
|
1165 self.doexec(session, 'INSERT INTO is_instance_of_relation(eid_from,' |
|
1166 'eid_to) VALUES(%s, %s)' % (eid, eschema_eid(session, eschema))) |
|
1167 # restore record in entities (will update fti if needed) |
1174 # restore record in entities (will update fti if needed) |
1168 self.add_info(session, entity, self, None, True) |
1175 self.add_info(session, entity, self, None, True) |
1169 # remove record from deleted_entities if entity's type is multi-sources |
1176 # remove record from deleted_entities if entity's type is multi-sources |
1170 if entity.__regid__ in self.multisources_etypes: |
1177 if entity.__regid__ in self.multisources_etypes: |
1171 self.doexec(session, |
1178 self.doexec(session, |
1224 self.repo.hm.call_hooks('before_delete_entity', session, entity=entity) |
1231 self.repo.hm.call_hooks('before_delete_entity', session, entity=entity) |
1225 # remove is / is_instance_of which are added using sql by hooks, hence |
1232 # remove is / is_instance_of which are added using sql by hooks, hence |
1226 # unvisible as transaction action |
1233 # unvisible as transaction action |
1227 self.doexec(session, 'DELETE FROM is_relation WHERE eid_from=%s' % eid) |
1234 self.doexec(session, 'DELETE FROM is_relation WHERE eid_from=%s' % eid) |
1228 self.doexec(session, 'DELETE FROM is_instance_of_relation WHERE eid_from=%s' % eid) |
1235 self.doexec(session, 'DELETE FROM is_instance_of_relation WHERE eid_from=%s' % eid) |
|
1236 self.doexec(session, 'DELETE FROM cw_source_relation WHERE eid_from=%s' % self.eid) |
1229 # XXX check removal of inlined relation? |
1237 # XXX check removal of inlined relation? |
1230 # delete the entity |
1238 # delete the entity |
1231 attrs = {'cw_eid': eid} |
1239 attrs = {'cw_eid': eid} |
1232 sql = self.sqlgen.delete(SQL_PREFIX + entity.__regid__, attrs) |
1240 sql = self.sqlgen.delete(SQL_PREFIX + entity.__regid__, attrs) |
1233 self.doexec(session, sql, attrs) |
1241 self.doexec(session, sql, attrs) |