transactions added, not tested
This commit is contained in:
parent
a4d1031d93
commit
586f239f00
|
@ -14,6 +14,7 @@ module SBDB
|
||||||
CONSUME_WAIT = Bdb::DB_CONSUME_WAIT
|
CONSUME_WAIT = Bdb::DB_CONSUME_WAIT
|
||||||
|
|
||||||
attr_reader :home
|
attr_reader :home
|
||||||
|
attr_accessor :txn
|
||||||
include Enumerable
|
include Enumerable
|
||||||
def bdb_object() @db end
|
def bdb_object() @db end
|
||||||
def sync() @db.sync end
|
def sync() @db.sync end
|
||||||
|
@ -54,8 +55,9 @@ module SBDB
|
||||||
@home, @db = opts[:env], opts[:env] ? opts[:env].bdb_object.db : Bdb::Db.new
|
@home, @db = opts[:env], opts[:env] ? opts[:env].bdb_object.db : Bdb::Db.new
|
||||||
opts[:type] = TYPES.index(self.class) || UNKNOWN
|
opts[:type] = TYPES.index(self.class) || UNKNOWN
|
||||||
@db.re_len = opts[:re_len] if opts[:re_len]
|
@db.re_len = opts[:re_len] if opts[:re_len]
|
||||||
|
txn = opts[:txn] || @txn
|
||||||
begin
|
begin
|
||||||
@db.open opts[:txn], file, opts[:name], opts[:type], opts[:flags] || 0, opts[:mode] || 0
|
@db.open txn && txn.bdb_object, file, opts[:name], opts[:type], opts[:flags] || 0, opts[:mode] || 0
|
||||||
rescue Object
|
rescue Object
|
||||||
close
|
close
|
||||||
raise $!
|
raise $!
|
||||||
|
|
|
@ -17,6 +17,11 @@ module SBDB
|
||||||
PRIVATE = Bdb::DB_PRIVATE
|
PRIVATE = Bdb::DB_PRIVATE
|
||||||
SYSTEM_MEM = Bdb::DB_SYSTEM_MEM
|
SYSTEM_MEM = Bdb::DB_SYSTEM_MEM
|
||||||
TXN_NOSYNC = Bdb::DB_TXN_NOSYNC
|
TXN_NOSYNC = Bdb::DB_TXN_NOSYNC
|
||||||
|
LOG_DIRECT = Bdb::DB_LOG_DIRECT
|
||||||
|
LOG_DSYNC = Bdb::DB_LOG_DSYNC
|
||||||
|
LOG_AUTO_REMOVE = Bdb::DB_LOG_AUTO_REMOVE
|
||||||
|
LOG_IN_MEMORY = Bdb::DB_LOG_IN_MEMORY
|
||||||
|
LOG_ZERO = Bdb::DB_LOG_ZERO
|
||||||
|
|
||||||
# returns the Bdb-object.
|
# returns the Bdb-object.
|
||||||
def bdb_object() @env end
|
def bdb_object() @env end
|
||||||
|
@ -41,6 +46,11 @@ module SBDB
|
||||||
open Unknown, file, *p, &e
|
open Unknown, file, *p, &e
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def transaction flags = nil, &e
|
||||||
|
Transaction.new flags, &e
|
||||||
|
end
|
||||||
|
alias txn transaction
|
||||||
|
|
||||||
# args:
|
# args:
|
||||||
# args[0] => dir
|
# args[0] => dir
|
||||||
# args[1] => flags
|
# args[1] => flags
|
||||||
|
@ -51,7 +61,9 @@ module SBDB
|
||||||
opts = ::Hash === args.last ? args.pop : {}
|
opts = ::Hash === args.last ? args.pop : {}
|
||||||
opts = {:dir => args[0], :flags => args[1], :mode => args[2]}.update opts
|
opts = {:dir => args[0], :flags => args[1], :mode => args[2]}.update opts
|
||||||
@dbs, @env = WeakHash.new, Bdb::Env.new( 0)
|
@dbs, @env = WeakHash.new, Bdb::Env.new( 0)
|
||||||
@env.log_config = opts[:log_config] if opts[:log_config]
|
@env.log_config opts[:log_config], 1 if opts[:log_config]
|
||||||
|
p lg_bsize: @env.lg_bsize
|
||||||
|
@env.lg_bsize = 5*2**20 if opts[:lg_bsize]
|
||||||
begin @env.open opts[:dir]||'.', opts[:flags]|| INIT_TRANSACTION|CREATE, opts[:mode]||0
|
begin @env.open opts[:dir]||'.', opts[:flags]|| INIT_TRANSACTION|CREATE, opts[:mode]||0
|
||||||
rescue Object
|
rescue Object
|
||||||
close
|
close
|
||||||
|
|
|
@ -9,7 +9,7 @@ Gem::Specification.new do |s|
|
||||||
|
|
||||||
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
||||||
s.authors = ["Denis Knauf"]
|
s.authors = ["Denis Knauf"]
|
||||||
s.date = %q{2010-02-23}
|
s.date = %q{2010-03-09}
|
||||||
s.description = %q{Simple Ruby Berkeley DB wrapper library for bdb.}
|
s.description = %q{Simple Ruby Berkeley DB wrapper library for bdb.}
|
||||||
s.email = %q{Denis.Knauf@gmail.com}
|
s.email = %q{Denis.Knauf@gmail.com}
|
||||||
s.extra_rdoc_files = [
|
s.extra_rdoc_files = [
|
||||||
|
@ -23,6 +23,7 @@ Gem::Specification.new do |s|
|
||||||
"lib/sbdb/cursor.rb",
|
"lib/sbdb/cursor.rb",
|
||||||
"lib/sbdb/db.rb",
|
"lib/sbdb/db.rb",
|
||||||
"lib/sbdb/environment.rb",
|
"lib/sbdb/environment.rb",
|
||||||
|
"lib/sbdb/transaction.rb",
|
||||||
"lib/sbdb/weakhash.rb"
|
"lib/sbdb/weakhash.rb"
|
||||||
]
|
]
|
||||||
s.homepage = %q{http://github.com/DenisKnauf/bdb}
|
s.homepage = %q{http://github.com/DenisKnauf/bdb}
|
||||||
|
|
Loading…
Reference in a new issue