Class DbmStore
In: lib/storage/dbmstore.rb
Parent: Store
DbmStore
Store
dot/f_43.png

The SdbmStore class manages access to all object storage.

db
is a handle to the database.
dbtop
stores the highest id used in the database.
cache
is a handle to the cache

Methods

check   close   delete   each   get   inspect   makenoswap   makeswap   mark   new   put   save   stats  

Public Class methods

[Source]

# File lib/storage/dbmstore.rb, line 29
  def initialize(dbfile)
    super()
    @dbfile = "#{dbfile}"

    # check if database exists and build it if not
    build_database
    log.info "Loading world..."

    # open database and sets @dbtop to highest object id
    @db = DBM.open(@dbfile, 0666)
    @db.each_key do |o|
      @dbtop = o.to_i if o.to_i > @dbtop
    end

    @cache = CacheManager.new(@db)
    log.info "Database '#{@dbfile}' loaded...highest id = #{@dbtop}."
#    log.debug @db.inspect
  rescue
    log.fatal $!
    raise
  end

Public Instance methods

Check if an object is in the database by its id.

oid
is the id to use in the search.
return
true or false

[Source]

# File lib/storage/dbmstore.rb, line 94
  def check(oid)
    @db.has_key? oid.to_s
  end

Close the database

return
Undefined.

[Source]

# File lib/storage/dbmstore.rb, line 59
  def close
    @db.close
  end

Deletes an object from the database.

oid
is the id to to be deleted.
return
Undefined.

[Source]

# File lib/storage/dbmstore.rb, line 80
  def delete(oid)
    @cache.delete(oid)
  end

Iterate through all objects This needs to have all the possible keys first. So we need to fetch them from the cache and from the database and and produce a list of unique keys.

yield
Each object in database to block of caller.

[Source]

# File lib/storage/dbmstore.rb, line 124
  def each
    kys = @cache.keys
    @db.each_key {|k| kys << k.to_i}
    kys.uniq!
    kys.each {|k| yield @cache.get(k)}
  end

Finds an object in the database by its id.

oid
is the id to use in the search.
return
Handle to the object or nil.

[Source]

# File lib/storage/dbmstore.rb, line 87
  def get(oid)
    @cache.get(oid)
  end

inspect the store cache (only for caches)

return
string

[Source]

# File lib/storage/dbmstore.rb, line 65
  def inspect
    @cache.inspect
  end

Marks an object nonswappable

oid
is the object id
return
undefined

[Source]

# File lib/storage/dbmstore.rb, line 108
  def makenoswap(oid)
    @cache.makenoswap(oid)
  end

Marks an object swappable

oid
is the object id
return
undefined

[Source]

# File lib/storage/dbmstore.rb, line 115
  def makeswap(oid)
    @cache.makeswap(oid)
  end

Marks an object dirty

oid
is the id to use in the search.
return
undefined

[Source]

# File lib/storage/dbmstore.rb, line 101
  def mark(oid)
    @cache.mark(oid)
  end

Adds a new object to the database.

obj
is a reference to object to be added
return
Undefined.

[Source]

# File lib/storage/dbmstore.rb, line 72
  def put(obj)
    @cache.put(obj)
    obj # return really should not be checked
  end

Save the world

return
Undefined.

[Source]

# File lib/storage/dbmstore.rb, line 53
  def save
    @cache.sync
  end

produces a statistical report of the database

return
a string containing the report

[Source]

# File lib/storage/dbmstore.rb, line 133
  def stats
    stats = super
    stats << @cache.stats
  end

[Validate]