def updateItem(self, obj, index, value): if not self.loadMode: print 'upd ' + `obj` + '[' + `index` + '] <--' + `value` # DEBUG if isAtomic(value): self.changeSet.append(Field(getId(obj), index, value)) else: self.changeSet.append(Field(getId(obj), index, Thunk(value.id)))
def write(stream, obj): def dump(value): pickle.dump(value, stream, pickle.HIGHEST_PROTOCOL) dump(Composite(getId(obj), obj.__class__)) for fieldName, fieldValue in obj.__dict__.iteritems(): if isAtomic(fieldValue): dump(Field(obj.id, fieldName, fieldValue)) else: dump(Field(obj.id, fieldName, Thunk(getId(fieldValue)))) write(stream, fieldValue)
def add(self, obj): """ Make given object persistent (along with objects it refers recursively). Add it to objects map and add to changeset. We should use only on-demand adopting as eager recursive adoption won't help if something external holds reference to inner object. Furthermore lazy adoption only in Updater objects will simplify code somehow. """ if not self.loadMode: if getId(obj) in self.objects: raise Exception("Object with id " + getId(obj) + " is already registered") else: self.changeSet.append(Composite(getId(obj), type(obj))) self.objects[obj.id] = obj
def getWrapped(self, object): """Get wrapped composite and cache wrapper.""" id = getId(object) if id in self.wrappers: return self.wrappers[id] else: wrapped = self.__class__(object, self.__dict__[self.CTX_ATTR]) self.wrappers[id] = wrapped return wrapped