From 3c2ee96d630626443e90bea0047b3dc6c35a5448 Mon Sep 17 00:00:00 2001 From: Denis Knauf Date: Tue, 23 Feb 2010 20:20:26 +0100 Subject: [PATCH] re_len-support --- lib/sbdb/db.rb | 13 +++++++------ lib/sbdb/environment.rb | 35 ++++++++++++++++------------------- 2 files changed, 23 insertions(+), 25 deletions(-) diff --git a/lib/sbdb/db.rb b/lib/sbdb/db.rb index 5b94d38..04a1b10 100644 --- a/lib/sbdb/db.rb +++ b/lib/sbdb/db.rb @@ -48,16 +48,17 @@ module SBDB end def initialize file, *args - info args: args - opts = Hash === args.last ? args.pop : {} - opts.update :name => args[0], :type => args[1], :flags => args[2], :mode => args[3], :env => args[4] + opts = ::Hash === args.last ? args.pop : {} + opts = {:name => args[0], :type => args[1], :flags => args[2], :mode => args[3], :env => args[4]}.update opts #type = BTREE if type == UNKNOWN and (flags & CREATE) == CREATE @home, @db = opts[:env], opts[:env] ? opts[:env].bdb_object.db : Bdb::Db.new - opts[:type] ||= TYPES.index(self.class) || UNKNOWN - info opts: opts + opts[:type] = TYPES.index(self.class) || UNKNOWN + info self: self, opts: opts + info 're_len before' => @db.re_len + @db.re_len = opts[:re_len] if opts[:re_len] + info 're_len after' => @db.re_len 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 close raise $! diff --git a/lib/sbdb/environment.rb b/lib/sbdb/environment.rb index 051437f..de9b3c5 100644 --- a/lib/sbdb/environment.rb +++ b/lib/sbdb/environment.rb @@ -22,33 +22,23 @@ module SBDB def bdb_object() @env end # Opens a Btree in this Environment def btree file, *p, &e - p.push Hash.new if Hash === p.last - p.last[:env] = self - Btree.new file, *p, &e + open Btree, file, *p, &e end # Opens a Hash in this Environment def hash file, *p, &e - p.push Hash.new if Hash === p.last - p.last[:env] = self - Hash.new file, *p, &e + open Hash, file, *p, &e end # Opens a Recno in this Environment def recno file, *p, &e - p.push Hash.new if Hash === p.last - p.last[:env] = self - Recno.new file, *p, &e + open Recno, file, *p, &e end # Opens a Queue in this Environment def queue file, *p, &e - p.push Hash.new if Hash === p.last - p.last[:env] = self - Queue.new file, *p, &e + open Queue, file, *p, &e end # Opens a DB of unknown type in this Environment def unknown file, *p, &e - p.push Hash.new if Hash === p.last - p.last[:env] = self - Unknown.new file, *p, &e + open Unknown, file, *p, &e end def initialize dir = nil, flags = nil, mode = nil @@ -80,8 +70,10 @@ module SBDB # Opens a Database. # see SBDB::DB, SBDB::Btree, SBDB::Hash, SBDB::Recno, SBDB::Queue - def open type, file, name = nil, flags = nil, mode = nil, txn = nil, &e - (type || SBDB::Unkown).new file, name, flags, mode, txn, self, &e + def open type, file, *p, &e + p.push ::Hash.new unless ::Hash === p.last + p.last[:env] = self + (type || SBDB::Unkown).new file, *p, &e end alias db open alias open_db open @@ -90,8 +82,13 @@ module SBDB # it returns the old instance. # If you use this, never use close. It's possible somebody else use it too. # The Databases, which are opened, will close, if the Environment will close. - def [] file, name = nil, type = nil, flags = nil, mode = nil, &e - @dbs[ [file, name, flags | CREATE]] ||= (type || SBDB::Unknown).new file, name, flags, mode, nil, self, &e + def [] file, *p, &e + p.push ::Hash.new unless ::Hash === p.last + p.last[:env] = self + name = String === p[0] ? p[0] : p.last[:name] + flags = Fixnum === p[1] ? p[1] : p.last[:flags] + type = Fixnum === p[2] ? p[2] : p.last[:type] + @dbs[ [file, name, flags | CREATE]] ||= (type || SBDB::Unknown).new file, *p, &e end end Env = Environment