Class: Jruby::Mapdb::DB

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/jruby/mapdb.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(dbname = nil) ⇒ DB

Returns a new instance of DB.



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/jruby/mapdb.rb', line 39

def initialize(dbname=nil)
  if dbname.nil?
    @type = :MemoryDB
    @mapdb = Java::OrgMapdb::DBMaker.
      newMemoryDB().
      closeOnJvmShutdown().
      make()
  else
    @type = :FileDB
    @mapdb = Java::OrgMapdb::DBMaker.
      newFileDB(Java::JavaIo::File.new("#{dbname}")).
      closeOnJvmShutdown().
      transactionDisable().
      make()
  end
end

Instance Attribute Details

#mapdbObject (readonly)

Returns the value of attribute mapdb.



38
39
40
# File 'lib/jruby/mapdb.rb', line 38

def mapdb
  @mapdb
end

#typeObject (readonly)

Returns the value of attribute type.



38
39
40
# File 'lib/jruby/mapdb.rb', line 38

def type
  @type
end

Instance Method Details

#tree(treename) ⇒ Object



55
56
57
58
59
60
61
# File 'lib/jruby/mapdb.rb', line 55

def tree(treename)
  raise "Tree '#{treename}' already defined" if Object.const_defined?(treename)
  Object.const_set treename, Class.new(Tree)
  Object.const_get(treename).instance_variable_set :@mapdb, @mapdb
  Object.const_get(treename).instance_variable_set :@tree, @mapdb.getTreeMap("#{treename}")
  Object.const_get treename
end

#treesObject



62
63
64
# File 'lib/jruby/mapdb.rb', line 62

def trees
  Hash[*(@mapdb.getAll.map(&:first).map(&:to_sym).zip(@mapdb.getAll.map(&:last).map(&:size)).flatten)]
end