lib/perobs/ObjectBase.rb in perobs-2.1.0 vs lib/perobs/ObjectBase.rb in perobs-2.1.1
- old
+ new
@@ -125,11 +125,12 @@
unless @store.object_creation_in_progress
::Kernel.raise ::RuntimeError,
"All PEROBS objects must exclusively be created by calling " +
"Store.new(). Never call the object constructor directly."
end
- @_id = @store.db.new_id
+ @_id = @store._new_id
+ @store._register_in_memory(self, @_id)
ObjectSpace.define_finalizer(self, ObjectBase._finalize(@store, @_id))
@_stash_map = nil
# Allocate a proxy object for this object. User code should only operate
# on this proxy, never on self.
@myself = POXReference.new(@store, @_id)
@@ -144,12 +145,10 @@
# method is not intended for users to call.
def ObjectBase._finalize(store, id)
proc { store._collect(id) }
end
- public
-
# This method can be overloaded by derived classes to do some massaging on
# the data after it has been restored from the database. This could either
# be some sanity check or code to migrate the object from one version to
# another.
def post_restore
@@ -224,19 +223,21 @@
'class' => self.class.to_s,
'data' => _serialize
}
@_stash_map = [] unless @_stash_map
# Get a new ID to store this version of the object.
- @_stash_map[level] = stash_id = @store.db.new_id
+ @_stash_map[level] = stash_id = @store._new_id
@store.db.put_object(db_obj, stash_id)
end
# Library internal method. Do not use outside of this library.
# @private
def _change_id(id)
# Unregister the object with the old ID from the write cache to prevent
# cache corruption. The objects are index by ID in the cache.
@store.cache.unwrite(self)
+ @store._collect(@_id)
+ @store._register_in_memory(self, id)
@_id = id
end
end