Logo Search packages:      
Sourcecode: zeitgeist version File versions

def _zeitgeist::engine::base::Entity::lookup_or_create (   klass,
  value 
)

Find the entity matching the uri 'value' or create it if necessary

Definition at line 108 of file base.py.

00108                                         :
            """Find the entity matching the uri 'value' or create it if necessary"""
            #
            # The algorithm used here is as follows:
            #  1) Return it if we have it cached
            #  2) Try to create it
            #  3) Look it up and return it
            #
            if klass.CACHE is not None and value in klass.CACHE:
                  return klass.CACHE[value]
            
            value = unicode(value)
            ent = klass(value, add_to_store=False)
            try:
                  _store.execute(
                  "INSERT INTO %s (value) VALUES (?)" % klass.__storm_table__,
                  (value, ), noresult=True)
            except Exception, ex:
                  pass
            
            id_query = _store.execute(
                              "SELECT id FROM %s WHERE VALUE=?" % klass.__storm_table__,
                              (value, )).get_one()
            if not id_query:
                  log.error("Failed to insert %s entity: %s" % (
                        klass.__storm_table__,value))
                  return None
            ent.id = id_query[0]
            
            if klass.CACHE is not None:
                  klass.CACHE[value] = ent
            
            return ent

class Content(Entity):


Generated by  Doxygen 1.6.0   Back to index