Exemple #1
0
    def store(self, oid, serial, data, version, transaction):
        assert version=='', "versions aren't supported"
        if transaction is not self._transaction:
            raise ZODB.POSException.StorageTransactionError(self, transaction)

        # Since the OID is being used, we don't have to keep up with it any
        # more. Save it now so we can forget it later. :)
        self._stored_oids.add(oid)

        # See if we already have changes for this oid
        try:
            old = self.changes.load(oid, '')[1]
        except ZODB.POSException.POSKeyError:
            try:
                old = self.base.load(oid, '')[1]
            except ZODB.POSException.POSKeyError:
                old = serial
                
        if old != serial:
            # <patch>
            rdata = tryToResolveConflict(self, oid, old, serial, data)
            if rdata is None:
                raise ZODB.POSException.ConflictError(
                    oid=oid, serials=(old, serial), data=data)
            self.changes.store(oid, old, rdata, '', transaction)
            return ResolvedSerial
            # </patch>

        return self.changes.store(oid, serial, data, '', transaction)
Exemple #2
0
    def store(self, oid, serial, data, version, transaction):
        if transaction is not self._transaction:
            raise POSException.StorageTransactionError(self, transaction)

        self._lock_acquire()
        try:
            old = self._index.get(oid, None)
            if old is None:
                # Hm, nothing here, check the base version:
                if self._base:
                    try:
                        p, tid = self._base.load(oid, '')
                    except KeyError:
                        pass
                    else:
                        old = oid, None, None, p, tid

            nv=None
            if old:
                oid, pre, vdata, p, tid = old

                if vdata:
                    if vdata[0] != version:
                        raise POSException.VersionLockError, oid

                    nv=vdata[1]
                else:
                    nv=old

                if serial != tid:
                  # <patch>
                  rdata = tryToResolveConflict(self, oid, tid, serial, data)
                  if rdata is None:
                    raise POSException.ConflictError(
                        oid=oid, serials=(tid, serial), data=data)
                  data = rdata
                  # </patch>

            r = [oid, old, version and (version, nv) or None, data, self._tid]
            self._tindex.append(r)

            s=self._tsize
            s=s+72+(data and (16+len(data)) or 4)
            if version: s=s+32+len(version)

            if self._quota is not None and s > self._quota:
                raise POSException.StorageError, (
                    '''<b>Quota Exceeded</b><br>
                    The maximum quota for this demonstration storage
                    has been exceeded.<br>Have a nice day.''')

        finally: self._lock_release()
        # <patch>
        if old and serial != tid:
            return ResolvedSerial
        # </patch>
        return self._tid