rod 0.7.1 → 0.7.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (76) hide show
  1. data/.travis.yml +1 -1
  2. data/README.rdoc +38 -10
  3. data/Rakefile +20 -9
  4. data/changelog.txt +25 -0
  5. data/contributors.txt +1 -0
  6. data/data/backward/0.7.0/_join_element.dat +0 -0
  7. data/data/backward/0.7.0/_polymorphic_join_element.dat +0 -0
  8. data/data/backward/0.7.0/char.dat +0 -0
  9. data/data/backward/0.7.0/database.yml +58 -0
  10. data/data/backward/0.7.0/rod_test__automobile.dat +0 -0
  11. data/data/backward/0.7.0/rod_test__caveman.dat +0 -0
  12. data/data/backward/0.7.0/rod_test__dog.dat +0 -0
  13. data/data/backward/0.7.0/rod_test__test_model.dat +0 -0
  14. data/data/portability/_join_element.dat +0 -0
  15. data/data/portability/_polymorphic_join_element.dat +0 -0
  16. data/data/portability/char.dat +0 -0
  17. data/data/portability/database.yml +49 -0
  18. data/data/portability/rod_test__automobile.dat +0 -0
  19. data/data/portability/rod_test__caveman.dat +0 -0
  20. data/data/portability/rod_test__dog.dat +0 -0
  21. data/data/portability/rod_test__test_model.dat +0 -0
  22. data/features/backward.feature +33 -0
  23. data/features/basic.feature +3 -0
  24. data/features/collection_proxy.feature +95 -0
  25. data/features/flat_indexing.feature +44 -2
  26. data/features/hash_indexing.feature +63 -9
  27. data/features/portability.feature +72 -0
  28. data/features/segmented_indexing.feature +45 -2
  29. data/features/steps/collection_proxy.rb +1 -1
  30. data/features/steps/model.rb +48 -5
  31. data/features/steps/rod.rb +15 -16
  32. data/lib/rod.rb +11 -1
  33. data/lib/rod/abstract_database.rb +52 -42
  34. data/lib/rod/berkeley/collection_proxy.rb +96 -0
  35. data/lib/rod/berkeley/database.rb +337 -0
  36. data/lib/rod/berkeley/environment.rb +209 -0
  37. data/lib/rod/berkeley/sequence.rb +222 -0
  38. data/lib/rod/berkeley/transaction.rb +233 -0
  39. data/lib/rod/collection_proxy.rb +76 -1
  40. data/lib/rod/constants.rb +3 -2
  41. data/lib/rod/database.rb +127 -14
  42. data/lib/rod/index/base.rb +12 -3
  43. data/lib/rod/index/hash_index.rb +295 -70
  44. data/lib/rod/index/segmented_index.rb +3 -0
  45. data/lib/rod/model.rb +154 -531
  46. data/lib/rod/property/base.rb +190 -0
  47. data/lib/rod/property/field.rb +258 -0
  48. data/lib/rod/property/plural_association.rb +145 -0
  49. data/lib/rod/property/singular_association.rb +139 -0
  50. data/rod.gemspec +6 -4
  51. data/spec/berkeley/database.rb +83 -0
  52. data/spec/berkeley/environment.rb +58 -0
  53. data/spec/berkeley/sequence.rb +101 -0
  54. data/spec/berkeley/transaction.rb +92 -0
  55. data/spec/collection_proxy.rb +38 -0
  56. data/spec/database.rb +36 -0
  57. data/spec/model.rb +26 -0
  58. data/spec/property/base.rb +73 -0
  59. data/spec/property/field.rb +244 -0
  60. data/spec/property/plural_association.rb +67 -0
  61. data/spec/property/singular_association.rb +65 -0
  62. data/tests/class_compatibility_create.rb +2 -2
  63. data/tests/eff1_test.rb +1 -1
  64. data/tests/eff2_test.rb +1 -1
  65. data/tests/full_runs.rb +1 -1
  66. data/tests/generate_classes_create.rb +14 -14
  67. data/tests/migration_create.rb +47 -47
  68. data/tests/migration_verify.rb +1 -1
  69. data/tests/missing_class_create.rb +6 -6
  70. data/tests/properties_order_create.rb +4 -4
  71. data/tests/read_on_create.rb +33 -34
  72. data/tests/save_struct.rb +40 -39
  73. data/tests/unit/database.rb +1 -1
  74. data/tests/unit/model_tests.rb +73 -65
  75. metadata +71 -15
  76. data/tests/unit/model.rb +0 -36
@@ -0,0 +1,65 @@
1
+ require 'bundler/setup'
2
+ require 'minitest/autorun'
3
+ require 'rod'
4
+
5
+ describe Rod::Property::SingularAssociation do
6
+ before do
7
+ @klass = MiniTest::Mock.new
8
+ @builder = MiniTest::Mock.new
9
+ @klass.expect :nil?,false
10
+ end
11
+
12
+ after do
13
+ @klass.verify
14
+ @builder.verify
15
+ end
16
+
17
+ describe "a singular association" do
18
+ before do
19
+ @association = Rod::Property::SingularAssociation.new(@klass,:user,
20
+ :polymorphic => true)
21
+ end
22
+
23
+ it "must not be a field" do
24
+ @association.field?.wont_equal true
25
+ end
26
+
27
+ it "must be an association" do
28
+ @association.association?.must_equal true
29
+ end
30
+
31
+ it "must be a singular association" do
32
+ @association.singular?.must_equal true
33
+ end
34
+
35
+ it "must not be a plural association" do
36
+ @association.plural?.wont_equal true
37
+ end
38
+
39
+ it "must produce proper metadata" do
40
+ @association.metadata.must_equal({:polymorphic => true})
41
+ end
42
+
43
+ it "must define C accessors" do
44
+ @klass.expect :struct_name, "struct_name"
45
+ @builder.expect :c,nil,[String]
46
+ @association.define_c_accessors(@builder)
47
+ end
48
+
49
+ it "must seal C accessors" do
50
+ @klass.expect :send,nil,[:private,String]
51
+ @association.seal_c_accessors
52
+ end
53
+
54
+ it "must define getter" do
55
+ @klass.expect :send,nil,[:define_method,"user"]
56
+ @klass.expect :scope_name,"Rod"
57
+ @association.define_getter
58
+ end
59
+
60
+ it "must define setter" do
61
+ @klass.expect :send,nil,[:define_method,"user="]
62
+ @association.define_setter
63
+ end
64
+ end
65
+ end
@@ -10,5 +10,5 @@ class TestClass < Rod::Model
10
10
  database_class TestDatabase
11
11
  end
12
12
 
13
- TestDatabase.instance.create_database("tmp/class_compatibility")
14
- TestDatabase.instance.close_database
13
+ TestDatabase.instance.create_database("tmp/class_compatibility") do
14
+ end
@@ -22,7 +22,7 @@ module RodTest
22
22
  FILENAME = "tmp/eff1"
23
23
 
24
24
  def setup
25
- Model.create_database(FILENAME)
25
+ Model.instance.create_database(FILENAME)
26
26
  @structs = {}
27
27
  %w{A B C D E}.each do |letter|
28
28
  @structs[letter.to_sym] = []
@@ -36,7 +36,7 @@ module RodTest
36
36
 
37
37
  def main
38
38
  start_t = Time.now.to_f
39
- Model.create_database(FILENAME)
39
+ Model.instance.create_database(FILENAME)
40
40
  %w{A B C D E}.each do |letter|
41
41
  (MAGNITUDE / 2).times {|i| @structs[letter.to_sym][i].store }
42
42
  end
@@ -10,7 +10,7 @@ module RodTest
10
10
  MAGNITUDE = 10000
11
11
  def setup
12
12
  @test_filename = "tmp/noncontinuous_pages"
13
- Model.create_database(@test_filename)
13
+ Model.instance.create_database(@test_filename)
14
14
  @hs = []
15
15
  (MAGNITUDE).times do |i|
16
16
  @hs[i] = HisStruct.new
@@ -5,21 +5,21 @@ require File.join(".",File.dirname(__FILE__),"generate_classes_model")
5
5
  Rod::Database.development_mode = true
6
6
 
7
7
 
8
- Database.instance.create_database("tmp/generate_classes")
8
+ Database.instance.create_database("tmp/generate_classes") do
9
9
 
10
- files = 10.times.map{|i| UserFile.new(:data => "#{i} data")}
11
- files.each{|f| f.store}
10
+ files = 10.times.map{|i| UserFile.new(:data => "#{i} data")}
11
+ files.each{|f| f.store}
12
12
 
13
- account = Account.new(:login => "john")
14
- account.store
15
- user = User.new(:name => "John", :account => account,
16
- :files => [files[0],files[1],files[2]])
17
- user.store
13
+ account = Account.new(:login => "john")
14
+ account.store
15
+ user = User.new(:name => "John", :account => account,
16
+ :files => [files[0],files[1],files[2]])
17
+ user.store
18
18
 
19
- account = Account.new(:login => "amanda")
20
- account.store
21
- user = User.new(:name => "Amanda", :account => account,
22
- :files => [files[0],files[4],files[5],nil,files[6]])
23
- user.store
19
+ account = Account.new(:login => "amanda")
20
+ account.store
21
+ user = User.new(:name => "Amanda", :account => account,
22
+ :files => [files[0],files[4],files[5],nil,files[6]])
23
+ user.store
24
24
 
25
- Database.instance.close_database
25
+ end
@@ -5,51 +5,51 @@ require File.join(".",File.dirname(__FILE__),"migration_model1")
5
5
  Rod::Database.development_mode = true
6
6
 
7
7
  FileUtils.rm_rf("tmp/migration")
8
- Database.instance.create_database("tmp/migration")
9
-
10
- count = (ARGV[0] || 10).to_i
11
- puts "Count in migration test: #{count}"
12
-
13
- files = count.times.map{|i| UserFile.new(:data => "#{i} data")}
14
- files.each{|f| f.store}
15
-
16
- users = []
17
- count.times do |index|
18
- account = Account.new(:login => "john#{index}",
19
- :nick => "j#{index}")
20
- account.store
21
- user1 = User.new(:name => "John#{index}",
22
- :surname => "Smith#{index}",
23
- :city => "City#{index}",
24
- :street => "Street#{index}",
25
- :number => index,
26
- :account => account,
27
- :mother => users[index-1],
28
- :father => users[index-2],
29
- :friends => [users[index-3],users[index-4]],
30
- :files => [files[index],files[index + 1],files[index + 2]])
31
- user1.store
32
-
33
- account = Account.new(:login => "amanda#{index}",
34
- :nick => "a#{index}")
35
- account.store
36
- user2 = User.new(:name => "Amanda#{index}",
37
- :surname => "Amanda#{index}",
38
- :city => "Bigcity#{index}",
39
- :street => "Small street#{index}",
40
- :number => index,
41
- :account => account,
42
- :mother => users[index-1],
43
- :father => users[index-2],
44
- :friends => [users[index-5],users[index-6]],
45
- :files => [files[index],files[index+4],files[index+5],
46
- nil,files[index+6]])
47
- user2.store
48
- users << user1
49
- users << user2
50
- end
51
-
52
- house = House.new(:name => "cottage house")
53
- house.store
8
+ Database.instance.create_database("tmp/migration") do
9
+
10
+ count = (ARGV[0] || 10).to_i
11
+ puts "Count in migration test: #{count}"
12
+
13
+ files = count.times.map{|i| UserFile.new(:data => "#{i} data")}
14
+ files.each{|f| f.store}
15
+
16
+ users = []
17
+ count.times do |index|
18
+ account = Account.new(:login => "john#{index}",
19
+ :nick => "j#{index}")
20
+ account.store
21
+ user1 = User.new(:name => "John#{index}",
22
+ :surname => "Smith#{index}",
23
+ :city => "City#{index}",
24
+ :street => "Street#{index}",
25
+ :number => index,
26
+ :account => account,
27
+ :mother => users[index-1],
28
+ :father => users[index-2],
29
+ :friends => [users[index-3],users[index-4]],
30
+ :files => [files[index],files[index + 1],files[index + 2]])
31
+ user1.store
32
+
33
+ account = Account.new(:login => "amanda#{index}",
34
+ :nick => "a#{index}")
35
+ account.store
36
+ user2 = User.new(:name => "Amanda#{index}",
37
+ :surname => "Amanda#{index}",
38
+ :city => "Bigcity#{index}",
39
+ :street => "Small street#{index}",
40
+ :number => index,
41
+ :account => account,
42
+ :mother => users[index-1],
43
+ :father => users[index-2],
44
+ :friends => [users[index-5],users[index-6]],
45
+ :files => [files[index],files[index+4],files[index+5],
46
+ nil,files[index+6]])
47
+ user2.store
48
+ users << user1
49
+ users << user2
50
+ end
51
+
52
+ house = House.new(:name => "cottage house")
53
+ house.store
54
54
 
55
- Database.instance.close_database
55
+ end
@@ -9,7 +9,7 @@ Database.instance.open_database("tmp/migration")
9
9
 
10
10
  count = (ARGV[0] || 10).to_i
11
11
  key_count = 0
12
- User.index_for(:street,:index => :hash).each do |key,proxy|
12
+ User.property(:street).index.each do |key,proxy|
13
13
  key_count += 1
14
14
  proxy.to_a.should == User.find_all_by_street(key).to_a
15
15
  proxy.count.should > 0
@@ -13,9 +13,9 @@ end
13
13
 
14
14
  Rod::Database.development_mode = true
15
15
 
16
- Rod::Database.instance.create_database("tmp/missing_class")
17
- user = User.new(:name => "John")
18
- user.store
19
- item = Item.new(:name => "hammer")
20
- item.store
21
- Rod::Database.instance.close_database
16
+ Rod::Database.instance.create_database("tmp/missing_class") do
17
+ user = User.new(:name => "John")
18
+ user.store
19
+ item = Item.new(:name => "hammer")
20
+ item.store
21
+ end
@@ -9,8 +9,8 @@ end
9
9
 
10
10
  Rod::Database.development_mode = true
11
11
 
12
- Rod::Database.instance.create_database("tmp/properties_order")
13
- user = User.new(:name => "John",:surname => "Smith")
14
- user.store
15
- Rod::Database.instance.close_database
12
+ Rod::Database.instance.create_database("tmp/properties_order") do
13
+ user = User.new(:name => "John",:surname => "Smith")
14
+ user.store
15
+ end
16
16
 
@@ -6,40 +6,39 @@ puts "-- Read data while creating DB --"
6
6
  Rod::Database.development_mode = true
7
7
 
8
8
 
9
- RodTest::Database.instance.create_database("tmp/read_write")
10
- my_structures = []
11
- MAGNITUDO.times do |index|
12
- your_struct = RodTest::YourStruct.new
13
- your_struct.counter = index
14
- your_struct.title = "Title_#{index}"
15
- your_struct.store
16
-
17
- my_struct = RodTest::MyStruct.new
18
- my_struct.count = index
19
- my_struct.your_struct = your_struct
20
- my_struct.title = "Title_#{index}"
21
- my_struct.title2 = "Title2_#{index}"
22
-
23
- my_struct.store
24
- my_structures << my_struct
25
- end
26
-
27
- MAGNITUDO.times do |index|
28
- # validate object fetched from cache
29
- struct = RodTest::MyStruct[index]
30
- validate(index,struct)
31
- # validate object referenced previously
32
- validate(index,my_structures[index])
33
- # validate referential integrity
34
- if struct.object_id != my_structures[index].object_id
35
- raise "Object stored and recived are different #{struct.object_id} " +
36
- "#{my_structures[index].object_id}"
9
+ RodTest::Database.instance.create_database("tmp/read_write") do
10
+ my_structures = []
11
+ MAGNITUDO.times do |index|
12
+ your_struct = RodTest::YourStruct.new
13
+ your_struct.counter = index
14
+ your_struct.title = "Title_#{index}"
15
+ your_struct.store
16
+
17
+ my_struct = RodTest::MyStruct.new
18
+ my_struct.count = index
19
+ my_struct.your_struct = your_struct
20
+ my_struct.title = "Title_#{index}"
21
+ my_struct.title2 = "Title2_#{index}"
22
+
23
+ my_struct.store
24
+ my_structures << my_struct
37
25
  end
38
- if struct != my_structures[index]
39
- raise "Object stored and recived are different #{struct} " +
40
- "#{my_structures[index]}"
41
- end
42
- end
43
26
 
27
+ MAGNITUDO.times do |index|
28
+ # validate object fetched from cache
29
+ struct = RodTest::MyStruct[index]
30
+ validate(index,struct)
31
+ # validate object referenced previously
32
+ validate(index,my_structures[index])
33
+ # validate referential integrity
34
+ if struct.object_id != my_structures[index].object_id
35
+ raise "Object stored and recived are different #{struct.object_id} " +
36
+ "#{my_structures[index].object_id}"
37
+ end
38
+ if struct != my_structures[index]
39
+ raise "Object stored and recived are different #{struct} " +
40
+ "#{my_structures[index]}"
41
+ end
42
+ end
44
43
 
45
- RodTest::Database.instance.close_database
44
+ end
@@ -3,47 +3,48 @@ require 'structures'
3
3
 
4
4
  puts "-- Save sample structures test --"
5
5
  Rod::Database.development_mode = true
6
- RodTest::Database.instance.create_database("tmp/abc")
6
+ RodTest::Database.instance.create_database("tmp/abc") do
7
7
 
8
- #MAGNITUDE = 100000
9
- MAGNITUDE = 50
8
+ #MAGNITUDE = 100000
9
+ MAGNITUDE = 50
10
10
 
11
- his = []
12
- (MAGNITUDE * 10).times do |i|
13
- his[i] = RodTest::HisStruct.new
14
- his[i].inde = i
15
- end
16
-
17
- ys = []
18
- (MAGNITUDE * 1).times do |i|
19
- ys[i] = RodTest::YourStruct.new
20
- ys[i].counter = 10
21
- ys[i].his_structs = his[i*10...(i+1)*10]
22
- end
11
+ his = []
12
+ (MAGNITUDE * 10).times do |i|
13
+ his[i] = RodTest::HisStruct.new
14
+ his[i].inde = i
15
+ end
23
16
 
24
- ms = []
25
- (MAGNITUDE * 1).times do |i|
26
- ms[i] = RodTest::MyStruct.new
27
- ms[i].count = 10 * i
28
- ms[i].precision = 0.1 * i
29
- ms[i].identifier = i
30
- ms[i].your_struct = ys[i]
31
- ms[i].title = "title_#{i}"
32
- ms[i].title2 = "title2_#{i}"
33
- ms[i].body = "body_#{i}"
34
- end
17
+ ys = []
18
+ (MAGNITUDE * 1).times do |i|
19
+ ys[i] = RodTest::YourStruct.new
20
+ ys[i].counter = 10
21
+ ys[i].his_structs = his[i*10...(i+1)*10]
22
+ end
35
23
 
36
- RodTest::Database.instance.print_layout
37
- ms.each_with_index{|s,i|
38
- begin
39
- puts i if i % 1000 == 0
40
- s.store
41
- rescue Exception => e
42
- puts e
43
- raise
24
+ ms = []
25
+ (MAGNITUDE * 1).times do |i|
26
+ ms[i] = RodTest::MyStruct.new
27
+ ms[i].count = 10 * i
28
+ ms[i].precision = 0.1 * i
29
+ ms[i].identifier = i
30
+ ms[i].your_struct = ys[i]
31
+ ms[i].title = "title_#{i}"
32
+ ms[i].title2 = "title2_#{i}"
33
+ ms[i].body = "body_#{i}"
44
34
  end
45
- }
46
- ys.each{|y| y.store}
47
- his.each{|h| h.store}
48
- RodTest::Database.instance.print_layout
49
- RodTest::Database.instance.close_database
35
+
36
+ RodTest::Database.instance.print_layout
37
+ ms.each_with_index{|s,i|
38
+ begin
39
+ puts i if i % 1000 == 0
40
+ s.store
41
+ rescue Exception => e
42
+ puts e
43
+ raise
44
+ end
45
+ }
46
+ ys.each{|y| y.store}
47
+ his.each{|h| h.store}
48
+ RodTest::Database.instance.print_layout
49
+
50
+ end
@@ -19,7 +19,7 @@ class DatabaseTest < Test::Unit::TestCase
19
19
 
20
20
  Rod::VERSION.sub!(/.*/,"0.1.1")
21
21
  file = "0.1.0"
22
- assert(not(@database.send(:valid_version?,file)))
22
+ assert !(@database.send(:valid_version?,file))
23
23
 
24
24
  Rod::VERSION.sub!(/.*/,"0.2.1")
25
25
  file = "0.2.0"