server/sources/native.py
branchstable
changeset 3315 59220b704562
parent 3240 8604a15995d1
child 3399 2b84f4adb6f8
child 3497 63b9541dd36f
equal deleted inserted replaced
3298:caef98aa4a98 3315:59220b704562
    92 
    92 
    93 class NativeSQLSource(SQLAdapterMixIn, AbstractSource):
    93 class NativeSQLSource(SQLAdapterMixIn, AbstractSource):
    94     """adapter for source using the native cubicweb schema (see below)
    94     """adapter for source using the native cubicweb schema (see below)
    95     """
    95     """
    96     sqlgen_class = SQLGenerator
    96     sqlgen_class = SQLGenerator
    97     # need default value on class since migration doesn't call init method
       
    98     has_deleted_entitites_table = True
       
    99 
    97 
   100     passwd_rql = "Any P WHERE X is CWUser, X login %(login)s, X upassword P"
    98     passwd_rql = "Any P WHERE X is CWUser, X login %(login)s, X upassword P"
   101     auth_rql = "Any X WHERE X is CWUser, X login %(login)s, X upassword %(pwd)s"
    99     auth_rql = "Any X WHERE X is CWUser, X login %(login)s, X upassword %(pwd)s"
   102     _sols = ({'X': 'CWUser', 'P': 'Password'},)
   100     _sols = ({'X': 'CWUser', 'P': 'Password'},)
   103 
   101 
   224             if self.repo.config.open_connections_pools:
   222             if self.repo.config.open_connections_pools:
   225                 self.open_pool_connections()
   223                 self.open_pool_connections()
   226 
   224 
   227     def init(self):
   225     def init(self):
   228         self.init_creating()
   226         self.init_creating()
   229         pool = self.repo._get_pool()
       
   230         pool.pool_set()
       
   231         # XXX cubicweb < 2.42 compat
       
   232         if 'deleted_entities' in self.dbhelper.list_tables(pool['system']):
       
   233             self.has_deleted_entitites_table = True
       
   234         else:
       
   235             self.has_deleted_entitites_table = False
       
   236         pool.pool_reset()
       
   237         self.repo._free_pool(pool)
       
   238 
   227 
   239     def map_attribute(self, etype, attr, cb):
   228     def map_attribute(self, etype, attr, cb):
   240         self._rql_sqlgen.attr_map['%s.%s' % (etype, attr)] = cb
   229         self._rql_sqlgen.attr_map['%s.%s' % (etype, attr)] = cb
   241 
   230 
   242     # ISource interface #######################################################
   231     # ISource interface #######################################################
   243 
   232 
   244     def compile_rql(self, rql):
   233     def compile_rql(self, rql):
   245         rqlst = self.repo.querier._rqlhelper.parse(rql)
   234         rqlst = self.repo.vreg.rqlhelper.parse(rql)
   246         rqlst.restricted_vars = ()
   235         rqlst.restricted_vars = ()
   247         rqlst.children[0].solutions = self._sols
   236         rqlst.children[0].solutions = self._sols
   248         self.repo.querier.sqlgen_annotate(rqlst)
   237         self.repo.querier.sqlgen_annotate(rqlst)
   249         set_qdata(self.schema.rschema, rqlst, ())
   238         set_qdata(self.schema.rschema, rqlst, ())
   250         return rqlst
   239         return rqlst
   276         if write:
   265         if write:
   277             return not rtype in NONSYSTEM_RELATIONS
   266             return not rtype in NONSYSTEM_RELATIONS
   278         # due to current multi-sources implementation, the system source
   267         # due to current multi-sources implementation, the system source
   279         # can't claim not supporting a relation
   268         # can't claim not supporting a relation
   280         return True #not rtype == 'content_for'
   269         return True #not rtype == 'content_for'
       
   270 
       
   271     def may_cross_relation(self, rtype):
       
   272         return True
   281 
   273 
   282     def authenticate(self, session, login, password):
   274     def authenticate(self, session, login, password):
   283         """return CWUser eid for the given login/password if this account is
   275         """return CWUser eid for the given login/password if this account is
   284         defined in this source, else raise `AuthenticationError`
   276         defined in this source, else raise `AuthenticationError`
   285 
   277 
   547         """delete system information on deletion of an entity by transfering
   539         """delete system information on deletion of an entity by transfering
   548         record from the entities table to the deleted_entities table
   540         record from the entities table to the deleted_entities table
   549         """
   541         """
   550         attrs = {'eid': eid}
   542         attrs = {'eid': eid}
   551         session.system_sql(self.sqlgen.delete('entities', attrs), attrs)
   543         session.system_sql(self.sqlgen.delete('entities', attrs), attrs)
   552         if self.has_deleted_entitites_table:
   544         if extid is not None:
   553             if extid is not None:
   545             assert isinstance(extid, str), type(extid)
   554                 assert isinstance(extid, str), type(extid)
   546             extid = b64encode(extid)
   555                 extid = b64encode(extid)
   547         attrs = {'type': etype, 'eid': eid, 'extid': extid,
   556             attrs = {'type': etype, 'eid': eid, 'extid': extid,
   548                  'source': uri, 'dtime': datetime.now()}
   557                      'source': uri, 'dtime': datetime.now()}
   549         session.system_sql(self.sqlgen.insert('deleted_entities', attrs), attrs)
   558             session.system_sql(self.sqlgen.insert('deleted_entities', attrs), attrs)
       
   559 
   550 
   560     def fti_unindex_entity(self, session, eid):
   551     def fti_unindex_entity(self, session, eid):
   561         """remove text content for entity with the given eid from the full text
   552         """remove text content for entity with the given eid from the full text
   562         index
   553         index
   563         """
   554         """