Method: PEROBS::ObjectBase#_restore

Defined in:
lib/perobs/ObjectBase.rb

#_restore(level) ⇒ Object

Restore the object state from the storage back-end.

Parameters:

  • level (Integer)

    the transaction nesting level



257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
# File 'lib/perobs/ObjectBase.rb', line 257

def _restore(level)
  # Find the most recently stored state of this object. This could be on
  # any previous stash level or in the regular object DB. If the object
  # was created during the transaction, there is no previous state to
  # restore to.
  data = nil
  if @_stash_map
    (level - 1).downto(0) do |lvl|
      break if (data = @_stash_map[lvl])
    end
  end
  if data
    # We have a stashed version that we can restore from.
    _deserialize(data)
  elsif @store.db.include?(@_id)
    # We have no stashed version but can restore from the database.
    db_obj = store.db.get_object(@_id)
    _deserialize(db_obj['data'])
  end
end