Esempio n. 1
0
 def read_all(self, table, deserializer):
     result = {}
     query = "SELECT blob FROM %s" % table
     c = self.connection.cursor()
     c.execute(query)
     rss = c.fetchall()
     for rs in rss:
         data = decode_serialized_value(rs[0])  # dict repr() to dict
         item = deserializer.deserialize(data)
         if item:
             result[item.ID] = item
     return result
Esempio n. 2
0
    def _read_referenced_resources(self, query, id_type):
        statement = query

        ret = ReferencedResources()
        rs = statement.fetchall()
        cell_des = CellDeserializer(id_type)
        content_des = ContentDeserializer(id_type)
        for r in rs:
            try:
                v = Reference.deserialize(decode_serialized_value(r[0]))
                scontent = decode_serialized_value(r[2]) if r[2] else None
                res = Resource(cell_des.deserialize(decode_serialized_value(r[1])),
                               content_des.deserialize(scontent))
                cell_name = v.ref
                ret[v.block_version][cell_name] = res
                # logger.debug("Local found: %s/%s" % (str(v.block_version), str(cell_name)))
            except Exception as e:
                tb = traceback.format_exc()
                logger.error("Error while reading resources %s" % str(e))
                logger.debug(tb)

        return ret
Esempio n. 3
0
 def read_multi(self, ids, table, deserializer):
     result = {}
     for chunked_ids in self._chunks(ids):
         query = "SELECT blob FROM %s WHERE id in (%s)" % (table,
                                     ', '.join(['?'] * len(chunked_ids)))
         c = self.connection.cursor()
         c.execute(query, list(chunked_ids))
         rss = c.fetchall()
         for rs in rss:
             data = decode_serialized_value(rs[0])  # dict repr() to dict
             item = deserializer.deserialize(data)
             if item:
                 result[item.ID] = item
     return result
Esempio n. 4
0
 def read_multi(self, ids, table, deserializer):
     result = {}
     for chunked_ids in self._chunks(ids):
         query = "SELECT blob FROM %s WHERE id in (%s)" % (table, ', '.join(
             ['?'] * len(chunked_ids)))
         c = self.connection.cursor()
         c.execute(query, list(chunked_ids))
         rss = c.fetchall()
         for rs in rss:
             data = decode_serialized_value(rs[0])  # dict repr() to dict
             item = deserializer.deserialize(data)
             if item:
                 result[item.ID] = item
     return result
Esempio n. 5
0
    def read(self, ID, table, deserializer):
        query = "SELECT blob FROM %s WHERE id=\"%s\"" % (table, ID)
        c = self.connection.cursor()
        c.execute(query)
        rs = c.fetchone()
        if not rs:
            raise NotInStoreException('Not found %s in %s' % (ID, table))
        data = decode_serialized_value(rs[0])
        item = None
        if deserializer is not None:
            if hasattr(deserializer, 'deserialize'):
                item = deserializer.deserialize(data)
            else:
                item = deserializer(data)
        else:  # Don't want deserialization
            return data

        if item is None:
            raise NotInStoreException('Not found %s in %s' % (ID, table))
        return item
Esempio n. 6
0
    def read(self, ID, table, deserializer):
        query = "SELECT blob FROM %s WHERE id=\"%s\"" % (table, ID)
        c = self.connection.cursor()
        c.execute(query)
        rs = c.fetchone()
        if not rs:
            raise NotInStoreException('Not found %s in %s' % (ID, table))
        data = decode_serialized_value(rs[0])
        item = None
        if deserializer is not None:
            if hasattr(deserializer, 'deserialize'):
                item = deserializer.deserialize(data)
            else:
                item = deserializer(data)
        else:  # Don't want deserialization
            return data

        if item is None:
            raise NotInStoreException('Not found %s in %s' % (ID, table))
        return item