server/sources/__init__.py
branchstable
changeset 8134 7f93da785e3a
parent 7922 d307c3817782
child 8228 fe53c7e1625f
equal deleted inserted replaced
8133:b0a70092946a 8134:7f93da785e3a
   234 
   234 
   235     # connections handling #####################################################
   235     # connections handling #####################################################
   236 
   236 
   237     def get_connection(self):
   237     def get_connection(self):
   238         """open and return a connection to the source"""
   238         """open and return a connection to the source"""
   239         raise NotImplementedError()
   239         raise NotImplementedError(self)
   240 
   240 
   241     def check_connection(self, cnx):
   241     def check_connection(self, cnx):
   242         """Check connection validity, return None if the connection is still
   242         """Check connection validity, return None if the connection is still
   243         valid else a new connection (called when the connections set using the
   243         valid else a new connection (called when the connections set using the
   244         given connection is being attached to a session). Do nothing by default.
   244         given connection is being attached to a session). Do nothing by default.
   386         """if the source support CWUser entity type, it should implement
   386         """if the source support CWUser entity type, it should implement
   387         this method which should return CWUser eid for the given login/password
   387         this method which should return CWUser eid for the given login/password
   388         if this account is defined in this source and valid login / password is
   388         if this account is defined in this source and valid login / password is
   389         given. Else raise `AuthenticationError`
   389         given. Else raise `AuthenticationError`
   390         """
   390         """
   391         raise NotImplementedError()
   391         raise NotImplementedError(self)
   392 
   392 
   393     # RQL query api ############################################################
   393     # RQL query api ############################################################
   394 
   394 
   395     def syntax_tree_search(self, session, union,
   395     def syntax_tree_search(self, session, union,
   396                            args=None, cachekey=None, varmap=None, debug=0):
   396                            args=None, cachekey=None, varmap=None, debug=0):
   397         """return result from this source for a rql query (actually from a rql
   397         """return result from this source for a rql query (actually from a rql
   398         syntax tree and a solution dictionary mapping each used variable to a
   398         syntax tree and a solution dictionary mapping each used variable to a
   399         possible type). If cachekey is given, the query necessary to fetch the
   399         possible type). If cachekey is given, the query necessary to fetch the
   400         results (but not the results themselves) may be cached using this key.
   400         results (but not the results themselves) may be cached using this key.
   401         """
   401         """
   402         raise NotImplementedError()
   402         raise NotImplementedError(self)
   403 
   403 
   404     def flying_insert(self, table, session, union, args=None, varmap=None):
   404     def flying_insert(self, table, session, union, args=None, varmap=None):
   405         """similar as .syntax_tree_search, but inserts data in the temporary
   405         """similar as .syntax_tree_search, but inserts data in the temporary
   406         table (on-the-fly if possible, eg for the system source whose the given
   406         table (on-the-fly if possible, eg for the system source whose the given
   407         cursor come from). If not possible, inserts all data by calling
   407         cursor come from). If not possible, inserts all data by calling
   413     # write modification api ###################################################
   413     # write modification api ###################################################
   414     # read-only sources don't have to implement methods below
   414     # read-only sources don't have to implement methods below
   415 
   415 
   416     def get_extid(self, entity):
   416     def get_extid(self, entity):
   417         """return the external id for the given newly inserted entity"""
   417         """return the external id for the given newly inserted entity"""
   418         raise NotImplementedError()
   418         raise NotImplementedError(self)
   419 
   419 
   420     def add_entity(self, session, entity):
   420     def add_entity(self, session, entity):
   421         """add a new entity to the source"""
   421         """add a new entity to the source"""
   422         raise NotImplementedError()
   422         raise NotImplementedError(self)
   423 
   423 
   424     def update_entity(self, session, entity):
   424     def update_entity(self, session, entity):
   425         """update an entity in the source"""
   425         """update an entity in the source"""
   426         raise NotImplementedError()
   426         raise NotImplementedError(self)
   427 
   427 
   428     def delete_entities(self, session, entities):
   428     def delete_entities(self, session, entities):
   429         """delete several entities from the source"""
   429         """delete several entities from the source"""
   430         for entity in entities:
   430         for entity in entities:
   431             self.delete_entity(session, entity)
   431             self.delete_entity(session, entity)
   432 
   432 
   433     def delete_entity(self, session, entity):
   433     def delete_entity(self, session, entity):
   434         """delete an entity from the source"""
   434         """delete an entity from the source"""
   435         raise NotImplementedError()
   435         raise NotImplementedError(self)
   436 
   436 
   437     def add_relation(self, session, subject, rtype, object):
   437     def add_relation(self, session, subject, rtype, object):
   438         """add a relation to the source"""
   438         """add a relation to the source"""
   439         raise NotImplementedError()
   439         raise NotImplementedError(self)
   440 
   440 
   441     def add_relations(self, session,  rtype, subj_obj_list):
   441     def add_relations(self, session,  rtype, subj_obj_list):
   442         """add a relations to the source"""
   442         """add a relations to the source"""
   443         # override in derived classes if you feel you can
   443         # override in derived classes if you feel you can
   444         # optimize
   444         # optimize
   445         for subject, object in subj_obj_list:
   445         for subject, object in subj_obj_list:
   446             self.add_relation(session, subject, rtype, object)
   446             self.add_relation(session, subject, rtype, object)
   447 
   447 
   448     def delete_relation(self, session, subject, rtype, object):
   448     def delete_relation(self, session, subject, rtype, object):
   449         """delete a relation from the source"""
   449         """delete a relation from the source"""
   450         raise NotImplementedError()
   450         raise NotImplementedError(self)
   451 
   451 
   452     # system source interface #################################################
   452     # system source interface #################################################
   453 
   453 
   454     def eid_type_source(self, session, eid):
   454     def eid_type_source(self, session, eid):
   455         """return a tuple (type, source, extid) for the entity with id <eid>"""
   455         """return a tuple (type, source, extid) for the entity with id <eid>"""
   456         raise NotImplementedError()
   456         raise NotImplementedError(self)
   457 
   457 
   458     def create_eid(self, session):
   458     def create_eid(self, session):
   459         raise NotImplementedError()
   459         raise NotImplementedError(self)
   460 
   460 
   461     def add_info(self, session, entity, source, extid):
   461     def add_info(self, session, entity, source, extid):
   462         """add type and source info for an eid into the system table"""
   462         """add type and source info for an eid into the system table"""
   463         raise NotImplementedError()
   463         raise NotImplementedError(self)
   464 
   464 
   465     def update_info(self, session, entity, need_fti_update):
   465     def update_info(self, session, entity, need_fti_update):
   466         """mark entity as being modified, fulltext reindex if needed"""
   466         """mark entity as being modified, fulltext reindex if needed"""
   467         raise NotImplementedError()
   467         raise NotImplementedError(self)
   468 
   468 
   469     def delete_info_multi(self, session, entities, uri):
   469     def delete_info_multi(self, session, entities, uri):
   470         """delete system information on deletion of a list of entities with the
   470         """delete system information on deletion of a list of entities with the
   471         same etype and belinging to the same source
   471         same etype and belinging to the same source
   472         """
   472         """
   473         raise NotImplementedError()
   473         raise NotImplementedError(self)
   474 
   474 
   475     def modified_entities(self, session, etypes, mtime):
   475     def modified_entities(self, session, etypes, mtime):
   476         """return a 2-uple:
   476         """return a 2-uple:
   477         * list of (etype, eid) of entities of the given types which have been
   477         * list of (etype, eid) of entities of the given types which have been
   478           modified since the given timestamp (actually entities whose full text
   478           modified since the given timestamp (actually entities whose full text
   479           index content has changed)
   479           index content has changed)
   480         * list of (etype, eid) of entities of the given types which have been
   480         * list of (etype, eid) of entities of the given types which have been
   481           deleted since the given timestamp
   481           deleted since the given timestamp
   482         """
   482         """
   483         raise NotImplementedError()
   483         raise NotImplementedError(self)
   484 
   484 
   485     def index_entity(self, session, entity):
   485     def index_entity(self, session, entity):
   486         """create an operation to [re]index textual content of the given entity
   486         """create an operation to [re]index textual content of the given entity
   487         on commit
   487         on commit
   488         """
   488         """
   489         raise NotImplementedError()
   489         raise NotImplementedError(self)
   490 
   490 
   491     def fti_unindex_entities(self, session, entities):
   491     def fti_unindex_entities(self, session, entities):
   492         """remove text content for entities from the full text index
   492         """remove text content for entities from the full text index
   493         """
   493         """
   494         raise NotImplementedError()
   494         raise NotImplementedError(self)
   495 
   495 
   496     def fti_index_entities(self, session, entities):
   496     def fti_index_entities(self, session, entities):
   497         """add text content of created/modified entities to the full text index
   497         """add text content of created/modified entities to the full text index
   498         """
   498         """
   499         raise NotImplementedError()
   499         raise NotImplementedError(self)
   500 
   500 
   501     # sql system source interface #############################################
   501     # sql system source interface #############################################
   502 
   502 
   503     def sqlexec(self, session, sql, args=None):
   503     def sqlexec(self, session, sql, args=None):
   504         """execute the query and return its result"""
   504         """execute the query and return its result"""
   505         raise NotImplementedError()
   505         raise NotImplementedError(self)
   506 
   506 
   507     def temp_table_def(self, selection, solution, table, basemap):
   507     def temp_table_def(self, selection, solution, table, basemap):
   508         raise NotImplementedError()
   508         raise NotImplementedError(self)
   509 
   509 
   510     def create_index(self, session, table, column, unique=False):
   510     def create_index(self, session, table, column, unique=False):
   511         raise NotImplementedError()
   511         raise NotImplementedError(self)
   512 
   512 
   513     def drop_index(self, session, table, column, unique=False):
   513     def drop_index(self, session, table, column, unique=False):
   514         raise NotImplementedError()
   514         raise NotImplementedError(self)
   515 
   515 
   516     def create_temp_table(self, session, table, schema):
   516     def create_temp_table(self, session, table, schema):
   517         raise NotImplementedError()
   517         raise NotImplementedError(self)
   518 
   518 
   519     def clean_temp_data(self, session, temptables):
   519     def clean_temp_data(self, session, temptables):
   520         """remove temporary data, usually associated to temporary tables"""
   520         """remove temporary data, usually associated to temporary tables"""
   521         pass
   521         pass
   522 
   522