From 586f239f001afae1a42b7967c553aef8446f9d5a Mon Sep 17 00:00:00 2001 From: Denis Knauf Date: Tue, 9 Mar 2010 19:09:22 +0100 Subject: [PATCH] transactions added, not tested --- lib/sbdb/db.rb | 4 +++- lib/sbdb/environment.rb | 14 +++++++++++++- sbdb.gemspec | 3 ++- 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/lib/sbdb/db.rb b/lib/sbdb/db.rb index adede68..2cf2347 100644 --- a/lib/sbdb/db.rb +++ b/lib/sbdb/db.rb @@ -14,6 +14,7 @@ module SBDB CONSUME_WAIT = Bdb::DB_CONSUME_WAIT attr_reader :home + attr_accessor :txn include Enumerable def bdb_object() @db 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 opts[:type] = TYPES.index(self.class) || UNKNOWN @db.re_len = opts[:re_len] if opts[:re_len] + txn = opts[:txn] || @txn 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 close raise $! diff --git a/lib/sbdb/environment.rb b/lib/sbdb/environment.rb index 94c4d63..c14006f 100644 --- a/lib/sbdb/environment.rb +++ b/lib/sbdb/environment.rb @@ -17,6 +17,11 @@ module SBDB PRIVATE = Bdb::DB_PRIVATE SYSTEM_MEM = Bdb::DB_SYSTEM_MEM 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. def bdb_object() @env end @@ -41,6 +46,11 @@ module SBDB open Unknown, file, *p, &e end + def transaction flags = nil, &e + Transaction.new flags, &e + end + alias txn transaction + # args: # args[0] => dir # args[1] => flags @@ -51,7 +61,9 @@ module SBDB opts = ::Hash === args.last ? args.pop : {} opts = {:dir => args[0], :flags => args[1], :mode => args[2]}.update opts @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 rescue Object close diff --git a/sbdb.gemspec b/sbdb.gemspec index 11e2da4..c36a377 100644 --- a/sbdb.gemspec +++ b/sbdb.gemspec @@ -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.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.email = %q{Denis.Knauf@gmail.com} s.extra_rdoc_files = [ @@ -23,6 +23,7 @@ Gem::Specification.new do |s| "lib/sbdb/cursor.rb", "lib/sbdb/db.rb", "lib/sbdb/environment.rb", + "lib/sbdb/transaction.rb", "lib/sbdb/weakhash.rb" ] s.homepage = %q{http://github.com/DenisKnauf/bdb}