File: transaction.rb

package info (click to toggle)
libdb-ruby 0.6.5-2
  • links: PTS, VCS
  • area: main
  • in suites: lenny
  • size: 2,596 kB
  • ctags: 3,978
  • sloc: ansic: 13,984; cpp: 8,739; ruby: 7,864; sh: 47; makefile: 6
file content (42 lines) | stat: -rwxr-xr-x 1,201 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#!/usr/local/bin/ruby
$LOAD_PATH.unshift("..", "../../src")
require 'bdbxml'
require 'find'

Find::find('tmp') do |f|
   File::unlink(f) if FileTest::file? f
end

env = BDB::Env.new("tmp", BDB::CREATE | BDB::INIT_TRANSACTION)
bdb = env.open_db(BDB::Btree, "tutu", nil, "a")
man = env.manager
doc = man.create_container("toto", BDB::XML::TRANSACTIONAL)
at_exit {
   doc.close
   man.close
}

2.times do |i|
   doc.put("#{i}", "<bk><ttl id='#{i}'>title nb #{i}</ttl></bk>")
   bdb[i] = "bdb#{i}"
end
que = man.prepare("collection('toto')/bk")
qc = man.create_query_context
man.begin(doc, bdb, que) do |txn, doc1, bdb1, que1|
   2.times do |i|
      bdb1[i+2] = "bdb#{i+2}"
      doc1.put("#{i+2}", "<bk><ttl id='#{i+2}'>title nb #{i+2}</ttl></bk>")
   end
   puts "=============== get ========================"
   p doc1.get("2")
   puts "================ each ======================"
   que1.execute(qc) {|x| p x }
   puts "================= bdb ======================"
   bdb1.each {|k,v| p "#{k} -- #{v}" }
   # implicit txn.abort
end
puts "=============== each ======================"
que.execute(qc) {|x| p x }
puts "================= bdb ====================="
bdb.each {|k,v| p "#{k} -- #{v}" }