re_len-support

master
Denis Knauf 2010-02-23 20:20:26 +01:00
parent 1ce9a8ab4c
commit 3c2ee96d63
2 changed files with 23 additions and 25 deletions

View File

@ -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 $!

View File

@ -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