Example #1
0
    def __setitem__(self, key, value):
        # Invalidate cache for given key
        if self.cache and key in self._cache:
            del self._cache[key]

        if self._keys is None:
            keys = self._get_data()
        else:
            keys = self._keys

        if isinstance(value, dbbase._dbbase):
            reobj = value
        else:
            reobj = dbbase._retype(value)(self._conn)
            reobj._initialize(value)

        if key in keys:
            self._get(keys[key])._ref_dec()

        keys[key] = reobj._id
        reobj._ref_inc()

        # Rewrite
        self._set(keys)

        # Reset cache
        self._keys = None
Example #2
0
    def __setitem__(self, index, value):
        if self._keys is None:
            self._keys = keys = self._get_data()
        else:
            keys = self._keys

        if index >= len(keys):
            raise Exception("Index %d is out of bounds" % index)

        if isinstance(value, dbbase._dbbase):
            reobj = value
        else:
            reobj = dbbase._retype(value)(self._conn)
            reobj._initialize(value)

        self._get(keys[index])._ref_dec()

        keys[index] = reobj._id
        reobj._ref_inc()

        # Rewrite
        self._set(keys)

        # Reset cache
        self._keys = None

        # Delete cached item
        if self.cache:
            del self._cache[index]
Example #3
0
    def _initialize(self, data):
        keys = []
        for d in data:
            reobj = dbbase._retype(d)(self._conn)
            reobj._initialize(d)
            keys.append(reobj._id)
            reobj._ref_inc()

        self._set(keys)
Example #4
0
    def _initialize(self, data):
        keys = {}

        # Set data
        for k in data.keys():
            reobj = dbbase._retype(data[k])(self._conn)
            reobj._initialize(data[k])
            keys[k] = reobj._id
            reobj._ref_inc()

        self._set(keys)
Example #5
0
    def append(self, data):
        if self._keys is None:
            self._keys = keys = self._get_data()
        else:
            keys = self._keys

        reobj = dbbase._retype(data)(self._conn)
        reobj._initialize(data)
        keys.append(reobj._id)
        reobj._ref_inc()

        self._set(keys)

        # Invalidate cache
        self._keys = None