cubicweb/dataimport/stores.py
changeset 12504 362fdb399ff5
parent 12021 cc8135ecfbb8
child 12542 85194bd49119
equal deleted inserted replaced
12503:b01dd0ef43aa 12504:362fdb399ff5
    66 from six import add_metaclass
    66 from six import add_metaclass
    67 
    67 
    68 import pytz
    68 import pytz
    69 
    69 
    70 from logilab.common.decorators import cached
    70 from logilab.common.decorators import cached
    71 from logilab.common.deprecation import deprecated, class_deprecated
    71 from logilab.common.deprecation import class_deprecated
    72 
    72 
    73 from cubicweb.schema import META_RTYPES, VIRTUAL_RTYPES
    73 from cubicweb.schema import META_RTYPES, VIRTUAL_RTYPES
    74 from cubicweb.server.edition import EditedEntity
    74 from cubicweb.server.edition import EditedEntity
    75 
    75 
    76 
    76 
   146         self.rql('SET X %s Y WHERE X eid %%(x)s, Y eid %%(y)s' % rtype,
   146         self.rql('SET X %s Y WHERE X eid %%(x)s, Y eid %%(y)s' % rtype,
   147                  {'x': int(eid_from), 'y': int(eid_to)})
   147                  {'x': int(eid_from), 'y': int(eid_to)})
   148 
   148 
   149     def commit(self):
   149     def commit(self):
   150         return self._commit()
   150         return self._commit()
   151 
       
   152     @deprecated("[3.19] use cnx.find(*args, **kwargs).entities() instead")
       
   153     def find_entities(self, *args, **kwargs):
       
   154         return self._cnx.find(*args, **kwargs).entities()
       
   155 
       
   156     @deprecated("[3.19] use cnx.find(*args, **kwargs).one() instead")
       
   157     def find_one_entity(self, *args, **kwargs):
       
   158         return self._cnx.find(*args, **kwargs).one()
       
   159 
       
   160     @deprecated('[3.21] use prepare_insert_entity instead')
       
   161     def create_entity(self, *args, **kwargs):
       
   162         eid = self.prepare_insert_entity(*args, **kwargs)
       
   163         return self._cnx.entity_from_eid(eid)
       
   164 
       
   165     @deprecated('[3.21] use prepare_insert_relation instead')
       
   166     def relate(self, eid_from, rtype, eid_to, **kwargs):
       
   167         self.prepare_insert_relation(eid_from, rtype, eid_to, **kwargs)
       
   168 
   151 
   169 
   152 
   170 class NoHookRQLObjectStore(RQLObjectStore):
   153 class NoHookRQLObjectStore(RQLObjectStore):
   171     """Store that works by accessing low-level CubicWeb's source API, with all hooks deactivated. It
   154     """Store that works by accessing low-level CubicWeb's source API, with all hooks deactivated. It
   172     may be given a metadata generator object to handle metadata which are usually handled by hooks.
   155     may be given a metadata generator object to handle metadata which are usually handled by hooks.
   239         self._add_relation(self._cnx, eid_from, rtype, eid_to, rschema.inlined)
   222         self._add_relation(self._cnx, eid_from, rtype, eid_to, rschema.inlined)
   240         if rschema.symmetric:
   223         if rschema.symmetric:
   241             self._add_relation(self._cnx, eid_to, rtype, eid_from, rschema.inlined)
   224             self._add_relation(self._cnx, eid_to, rtype, eid_from, rschema.inlined)
   242         self._nb_inserted_relations += 1
   225         self._nb_inserted_relations += 1
   243 
   226 
   244     @property
       
   245     @deprecated('[3.21] deprecated')
       
   246     def nb_inserted_entities(self):
       
   247         return self._nb_inserted_entities
       
   248 
       
   249     @property
       
   250     @deprecated('[3.21] deprecated')
       
   251     def nb_inserted_types(self):
       
   252         return self._nb_inserted_types
       
   253 
       
   254     @property
       
   255     @deprecated('[3.21] deprecated')
       
   256     def nb_inserted_relations(self):
       
   257         return self._nb_inserted_relations
       
   258 
       
   259 
   227 
   260 class MetadataGenerator(object):
   228 class MetadataGenerator(object):
   261     """Class responsible for generating standard metadata for imported entities. You may want to
   229     """Class responsible for generating standard metadata for imported entities. You may want to
   262     derive it to add application specific's metadata. This class (or a subclass) may either be
   230     derive it to add application specific's metadata. This class (or a subclass) may either be
   263     given to a nohook or massive store.
   231     given to a nohook or massive store.