server/sources/pyrorql.py
changeset 7398 26695dd703d8
parent 7293 97505b798975
child 7399 972ed1843bd8
equal deleted inserted replaced
7397:6a9e66d788b3 7398:26695dd703d8
   235         if dexturi == 'system' or not (
   235         if dexturi == 'system' or not (
   236             dexturi in self.repo.sources_by_uri or self._skip_externals):
   236             dexturi in self.repo.sources_by_uri or self._skip_externals):
   237             return self.repo.extid2eid(self, str(extid), etype, session), True
   237             return self.repo.extid2eid(self, str(extid), etype, session), True
   238         if dexturi in self.repo.sources_by_uri:
   238         if dexturi in self.repo.sources_by_uri:
   239             source = self.repo.sources_by_uri[dexturi]
   239             source = self.repo.sources_by_uri[dexturi]
   240             cnx = session.pool.connection(source.uri)
   240             cnx = session.cnxset.connection(source.uri)
   241             eid = source.local_eid(cnx, dextid, session)[0]
   241             eid = source.local_eid(cnx, dextid, session)[0]
   242             return eid, False
   242             return eid, False
   243         return None, None
   243         return None, None
   244 
   244 
   245     def synchronize(self, mtime=None):
   245     def synchronize(self, mtime=None):
   320     def check_connection(self, cnx):
   320     def check_connection(self, cnx):
   321         """check connection validity, return None if the connection is still valid
   321         """check connection validity, return None if the connection is still valid
   322         else a new connection
   322         else a new connection
   323         """
   323         """
   324         # we have to transfer manually thread ownership. This can be done safely
   324         # we have to transfer manually thread ownership. This can be done safely
   325         # since the pool to which belong the connection is affected to one
   325         # since the connections set holding the connection is affected to one
   326         # session/thread and can't be called simultaneously
   326         # session/thread and can't be called simultaneously
   327         try:
   327         try:
   328             cnx._repo._transferThread(threading.currentThread())
   328             cnx._repo._transferThread(threading.currentThread())
   329         except AttributeError:
   329         except AttributeError:
   330             # inmemory connection
   330             # inmemory connection
   357         results (but not the results themselves) may be cached using this key.
   357         results (but not the results themselves) may be cached using this key.
   358         """
   358         """
   359         if not args is None:
   359         if not args is None:
   360             args = args.copy()
   360             args = args.copy()
   361         # get cached cursor anyway
   361         # get cached cursor anyway
   362         cu = session.pool[self.uri]
   362         cu = session.cnxset[self.uri]
   363         if cu is None:
   363         if cu is None:
   364             # this is a ConnectionWrapper instance
   364             # this is a ConnectionWrapper instance
   365             msg = session._("can't connect to source %s, some data may be missing")
   365             msg = session._("can't connect to source %s, some data may be missing")
   366             session.set_shared_data('sources_error', msg % self.uri)
   366             session.set_shared_data('sources_error', msg % self.uri)
   367             return []
   367             return []
   388             for i, etype in enumerate(descr[0]):
   388             for i, etype in enumerate(descr[0]):
   389                 if (etype is None or not self.schema.eschema(etype).final
   389                 if (etype is None or not self.schema.eschema(etype).final
   390                     or uidtype(union, i, etype, args)):
   390                     or uidtype(union, i, etype, args)):
   391                     needtranslation.append(i)
   391                     needtranslation.append(i)
   392             if needtranslation:
   392             if needtranslation:
   393                 cnx = session.pool.connection(self.uri)
   393                 cnx = session.cnxset.connection(self.uri)
   394                 for rowindex in xrange(rset.rowcount - 1, -1, -1):
   394                 for rowindex in xrange(rset.rowcount - 1, -1, -1):
   395                     row = rows[rowindex]
   395                     row = rows[rowindex]
   396                     localrow = False
   396                     localrow = False
   397                     for colindex in needtranslation:
   397                     for colindex in needtranslation:
   398                         if row[colindex] is not None: # optional variable
   398                         if row[colindex] is not None: # optional variable
   432         raise NotImplementedError()
   432         raise NotImplementedError()
   433 
   433 
   434     def update_entity(self, session, entity):
   434     def update_entity(self, session, entity):
   435         """update an entity in the source"""
   435         """update an entity in the source"""
   436         relations, kwargs = self._entity_relations_and_kwargs(session, entity)
   436         relations, kwargs = self._entity_relations_and_kwargs(session, entity)
   437         cu = session.pool[self.uri]
   437         cu = session.cnxset[self.uri]
   438         cu.execute('SET %s WHERE X eid %%(x)s' % ','.join(relations), kwargs)
   438         cu.execute('SET %s WHERE X eid %%(x)s' % ','.join(relations), kwargs)
   439         self._query_cache.clear()
   439         self._query_cache.clear()
   440         entity.cw_clear_all_caches()
   440         entity.cw_clear_all_caches()
   441 
   441 
   442     def delete_entity(self, session, entity):
   442     def delete_entity(self, session, entity):
   443         """delete an entity from the source"""
   443         """delete an entity from the source"""
   444         cu = session.pool[self.uri]
   444         cu = session.cnxset[self.uri]
   445         cu.execute('DELETE %s X WHERE X eid %%(x)s' % entity.__regid__,
   445         cu.execute('DELETE %s X WHERE X eid %%(x)s' % entity.__regid__,
   446                    {'x': self.eid2extid(entity.eid, session)})
   446                    {'x': self.eid2extid(entity.eid, session)})
   447         self._query_cache.clear()
   447         self._query_cache.clear()
   448 
   448 
   449     def add_relation(self, session, subject, rtype, object):
   449     def add_relation(self, session, subject, rtype, object):
   450         """add a relation to the source"""
   450         """add a relation to the source"""
   451         cu = session.pool[self.uri]
   451         cu = session.cnxset[self.uri]
   452         cu.execute('SET X %s Y WHERE X eid %%(x)s, Y eid %%(y)s' % rtype,
   452         cu.execute('SET X %s Y WHERE X eid %%(x)s, Y eid %%(y)s' % rtype,
   453                    {'x': self.eid2extid(subject, session),
   453                    {'x': self.eid2extid(subject, session),
   454                     'y': self.eid2extid(object, session)})
   454                     'y': self.eid2extid(object, session)})
   455         self._query_cache.clear()
   455         self._query_cache.clear()
   456         session.entity_from_eid(subject).cw_clear_all_caches()
   456         session.entity_from_eid(subject).cw_clear_all_caches()
   457         session.entity_from_eid(object).cw_clear_all_caches()
   457         session.entity_from_eid(object).cw_clear_all_caches()
   458 
   458 
   459     def delete_relation(self, session, subject, rtype, object):
   459     def delete_relation(self, session, subject, rtype, object):
   460         """delete a relation from the source"""
   460         """delete a relation from the source"""
   461         cu = session.pool[self.uri]
   461         cu = session.cnxset[self.uri]
   462         cu.execute('DELETE X %s Y WHERE X eid %%(x)s, Y eid %%(y)s' % rtype,
   462         cu.execute('DELETE X %s Y WHERE X eid %%(x)s, Y eid %%(y)s' % rtype,
   463                    {'x': self.eid2extid(subject, session),
   463                    {'x': self.eid2extid(subject, session),
   464                     'y': self.eid2extid(object, session)})
   464                     'y': self.eid2extid(object, session)})
   465         self._query_cache.clear()
   465         self._query_cache.clear()
   466         session.entity_from_eid(subject).cw_clear_all_caches()
   466         session.entity_from_eid(subject).cw_clear_all_caches()