Lesser parameters, more options
This commit is contained in:
parent
5f6a7d0038
commit
1ce9a8ab4c
2 changed files with 37 additions and 37 deletions
|
@ -22,9 +22,8 @@ module SBDB
|
||||||
|
|
||||||
def [] k
|
def [] k
|
||||||
@db.get nil, k.nil? ? nil : k.to_s, nil, 0
|
@db.get nil, k.nil? ? nil : k.to_s, nil, 0
|
||||||
rescue Bdb::DbError
|
rescue Bdb::KeyEmpty
|
||||||
return if $!.code == Bdb::DB_KEYEMPTY
|
return nil
|
||||||
raise $!
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def []= k, v
|
def []= k, v
|
||||||
|
@ -48,12 +47,17 @@ module SBDB
|
||||||
alias open new
|
alias open new
|
||||||
end
|
end
|
||||||
|
|
||||||
def initialize file, name = nil, type = nil, flags = nil, mode = nil, txn = nil, env = nil
|
def initialize file, *args
|
||||||
flags ||= 0
|
info args: args
|
||||||
type ||= UNKNOWN
|
opts = Hash === args.last ? args.pop : {}
|
||||||
|
opts.update :name => args[0], :type => args[1], :flags => args[2], :mode => args[3], :env => args[4]
|
||||||
#type = BTREE if type == UNKNOWN and (flags & CREATE) == CREATE
|
#type = BTREE if type == UNKNOWN and (flags & CREATE) == CREATE
|
||||||
@home, @db = env, env ? env.bdb_object.db : Bdb::Db.new
|
@home, @db = opts[:env], opts[:env] ? opts[:env].bdb_object.db : Bdb::Db.new
|
||||||
begin @db.open txn, file, name, type, flags, mode || 0
|
opts[:type] ||= TYPES.index(self.class) || UNKNOWN
|
||||||
|
info opts: opts
|
||||||
|
begin
|
||||||
|
@db.open opts[:txn], file, opts[:name], opts[:type], opts[:flags] || 0, opts[:mode] || 0
|
||||||
|
@db.re_len = opts[:re_len] if opts[:re_len]
|
||||||
rescue Object
|
rescue Object
|
||||||
close
|
close
|
||||||
raise $!
|
raise $!
|
||||||
|
@ -76,31 +80,21 @@ module SBDB
|
||||||
end
|
end
|
||||||
|
|
||||||
class Unknown < DB
|
class Unknown < DB
|
||||||
def self.new file, name, *p, &e
|
def self.new file, *p, &e
|
||||||
dbt = super( file, name, UNKNOWN, *p) {|db| db.bdb_object.get_type }
|
dbt = super( file, *p) {|db| db.bdb_object.get_type }
|
||||||
TYPES[dbt] ? TYPES[dbt].new( file, name, *p, &e) : super( file, name, UNKNOWN, *p, &e)
|
TYPES[dbt] ? TYPES[dbt].new( file, *p, &e) : super( file, *p, &e)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
class Btree < DB
|
class Btree < DB
|
||||||
def self.new file, name = nil, *p, &e
|
|
||||||
super file, name, BTREE, *p, &e
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
TYPES[DB::BTREE] = Btree
|
TYPES[DB::BTREE] = Btree
|
||||||
|
|
||||||
class Hash < DB
|
class Hash < DB
|
||||||
def self.new file, name = nil, *p, &e
|
|
||||||
super file, name, HASH, *p, &e
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
TYPES[DB::HASH] = Hash
|
TYPES[DB::HASH] = Hash
|
||||||
|
|
||||||
class Recno < DB
|
class Recno < DB
|
||||||
def self.new file, name = nil, *p, &e
|
|
||||||
super file, name, RECNO, *p, &e
|
|
||||||
end
|
|
||||||
|
|
||||||
def [] k
|
def [] k
|
||||||
super [k].pack('I')
|
super [k].pack('I')
|
||||||
end
|
end
|
||||||
|
@ -110,17 +104,13 @@ module SBDB
|
||||||
end
|
end
|
||||||
|
|
||||||
def push v
|
def push v
|
||||||
@db.put nil, nil, v, Bdb::DB_APPEND
|
@db.put nil, "\0\0\0\0", v, Bdb::DB_APPEND
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
Array = Recno
|
Array = Recno
|
||||||
TYPES[DB::RECNO] = Recno
|
TYPES[DB::RECNO] = Recno
|
||||||
|
|
||||||
class Queue < DB
|
class Queue < DB
|
||||||
def self.new file, name = nil, *p, &e
|
|
||||||
super file, name, QUEUE, *p, &e
|
|
||||||
end
|
|
||||||
|
|
||||||
def [] k
|
def [] k
|
||||||
super [k].pack('I')
|
super [k].pack('I')
|
||||||
end
|
end
|
||||||
|
@ -134,7 +124,7 @@ module SBDB
|
||||||
end
|
end
|
||||||
|
|
||||||
def push v
|
def push v
|
||||||
@db.put nil, nil, v, Bdb::DB_APPEND
|
@db.put nil, "\0\0\0\0", v, Bdb::DB_APPEND
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
TYPES[DB::QUEUE] = Queue
|
TYPES[DB::QUEUE] = Queue
|
||||||
|
|
|
@ -21,24 +21,34 @@ module SBDB
|
||||||
# returns the Bdb-object.
|
# returns the Bdb-object.
|
||||||
def bdb_object() @env end
|
def bdb_object() @env end
|
||||||
# Opens a Btree in this Environment
|
# Opens a Btree in this Environment
|
||||||
def btree file, name = nil, flags = nil, mode = nil, txn = nil, &e
|
def btree file, *p, &e
|
||||||
Btree.new file, name, flags, mode, txn, self, &e
|
p.push Hash.new if Hash === p.last
|
||||||
|
p.last[:env] = self
|
||||||
|
Btree.new file, *p, &e
|
||||||
end
|
end
|
||||||
# Opens a Hash in this Environment
|
# Opens a Hash in this Environment
|
||||||
def hash file, name = nil, flags = nil, mode = nil, txn = nil, &e
|
def hash file, *p, &e
|
||||||
Hash.new file, name, flags, mode, txn, self, &e
|
p.push Hash.new if Hash === p.last
|
||||||
|
p.last[:env] = self
|
||||||
|
Hash.new file, *p, &e
|
||||||
end
|
end
|
||||||
# Opens a Recno in this Environment
|
# Opens a Recno in this Environment
|
||||||
def recno file, name = nil, flags = nil, mode = nil, txn = nil, &e
|
def recno file, *p, &e
|
||||||
Recno.new file, name, flags, mode, txn, self, &e
|
p.push Hash.new if Hash === p.last
|
||||||
|
p.last[:env] = self
|
||||||
|
Recno.new file, *p, &e
|
||||||
end
|
end
|
||||||
# Opens a Queue in this Environment
|
# Opens a Queue in this Environment
|
||||||
def queue file, name = nil, flags = nil, mode = nil, txn = nil, &e
|
def queue file, *p, &e
|
||||||
Queue.new file, name, flags, mode, txn, self, &e
|
p.push Hash.new if Hash === p.last
|
||||||
|
p.last[:env] = self
|
||||||
|
Queue.new file, *p, &e
|
||||||
end
|
end
|
||||||
# Opens a DB of unknown type in this Environment
|
# Opens a DB of unknown type in this Environment
|
||||||
def unknown file, name = nil, flags = nil, mode = nil, txn = nil, &e
|
def unknown file, *p, &e
|
||||||
Unknown.new file, name, flags, mode, txn, self, &e
|
p.push Hash.new if Hash === p.last
|
||||||
|
p.last[:env] = self
|
||||||
|
Unknown.new file, *p, &e
|
||||||
end
|
end
|
||||||
|
|
||||||
def initialize dir = nil, flags = nil, mode = nil
|
def initialize dir = nil, flags = nil, mode = nil
|
||||||
|
|
Loading…
Reference in a new issue