diametric 0.0.4 → 0.1.1

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 (67) hide show
  1. checksums.yaml +15 -0
  2. data/Gemfile +21 -18
  3. data/Jarfile +15 -1
  4. data/README.md +22 -14
  5. data/Rakefile +17 -1
  6. data/bin/datomic-rest +33 -0
  7. data/bin/download-datomic +13 -0
  8. data/datomic_version.yml +4 -0
  9. data/diametric.gemspec +9 -6
  10. data/ext/diametric/DiametricCollection.java +147 -0
  11. data/ext/diametric/DiametricConnection.java +113 -0
  12. data/ext/diametric/DiametricDatabase.java +107 -0
  13. data/ext/diametric/DiametricEntity.java +90 -0
  14. data/ext/diametric/DiametricListenableFuture.java +47 -0
  15. data/ext/diametric/DiametricObject.java +66 -0
  16. data/ext/diametric/DiametricPeer.java +414 -0
  17. data/ext/diametric/DiametricService.java +102 -0
  18. data/ext/diametric/DiametricUUID.java +61 -0
  19. data/ext/diametric/DiametricUtils.java +183 -0
  20. data/lib/boolean_type.rb +3 -0
  21. data/lib/diametric.rb +24 -0
  22. data/lib/diametric/entity.rb +219 -14
  23. data/lib/diametric/generators/active_model.rb +2 -2
  24. data/lib/diametric/persistence.rb +0 -1
  25. data/lib/diametric/persistence/common.rb +28 -9
  26. data/lib/diametric/persistence/peer.rb +122 -87
  27. data/lib/diametric/persistence/rest.rb +4 -3
  28. data/lib/diametric/query.rb +94 -23
  29. data/lib/diametric/rest_service.rb +74 -0
  30. data/lib/diametric/service_base.rb +77 -0
  31. data/lib/diametric/transactor.rb +86 -0
  32. data/lib/diametric/version.rb +1 -1
  33. data/lib/diametric_service.jar +0 -0
  34. data/lib/value_enums.rb +8 -0
  35. data/spec/conf_helper.rb +55 -0
  36. data/spec/config/free-transactor-template.properties +73 -0
  37. data/spec/config/logback.xml +59 -0
  38. data/spec/data/seattle-data0.dtm +452 -0
  39. data/spec/data/seattle-data1.dtm +326 -0
  40. data/spec/developer_create_sample.rb +39 -0
  41. data/spec/developer_query_spec.rb +120 -0
  42. data/spec/diametric/config_spec.rb +1 -1
  43. data/spec/diametric/entity_spec.rb +263 -0
  44. data/spec/diametric/peer_api_spec.rb +147 -0
  45. data/spec/diametric/persistence/peer_many2many_spec.rb +76 -0
  46. data/spec/diametric/persistence/peer_spec.rb +13 -22
  47. data/spec/diametric/persistence/rest_spec.rb +12 -19
  48. data/spec/diametric/query_spec.rb +4 -5
  49. data/spec/diametric/rest_service_spec.rb +56 -0
  50. data/spec/diametric/transactor_spec.rb +68 -0
  51. data/spec/integration_spec.rb +5 -3
  52. data/spec/parent_child_sample.rb +42 -0
  53. data/spec/peer_integration_spec.rb +106 -22
  54. data/spec/peer_seattle_spec.rb +200 -0
  55. data/spec/rc2013_seattle_big.rb +82 -0
  56. data/spec/rc2013_seattle_small.rb +60 -0
  57. data/spec/rc2013_simple_sample.rb +72 -0
  58. data/spec/seattle_integration_spec.rb +106 -0
  59. data/spec/simple_validation_sample.rb +31 -0
  60. data/spec/spec_helper.rb +31 -45
  61. data/spec/support/entities.rb +157 -0
  62. data/spec/support/gen_entity_class.rb +2 -0
  63. data/spec/support/persistence_examples.rb +9 -5
  64. data/spec/test_version_file.yml +4 -0
  65. metadata +131 -75
  66. data/Jarfile.lock +0 -134
  67. data/lib/jrclj.rb +0 -63
@@ -0,0 +1,200 @@
1
+ require 'spec_helper'
2
+ require 'diametric/entity'
3
+ require 'datomic/client'
4
+
5
+ describe Diametric::Entity, :integration => true, :jruby => true do
6
+ context District do
7
+ before(:all) do
8
+ datomic_uri = "datomic:mem://district-#{SecureRandom.uuid}"
9
+ @d_conn1 = Diametric::Persistence::Peer.connect(datomic_uri)
10
+ end
11
+ after(:all) do
12
+ @d_conn1.release
13
+ end
14
+ let(:district) { District.create_schema(@d_conn1) }
15
+ it "should create schema" do
16
+ district.should_not be_nil
17
+ end
18
+ it "should return future object" do
19
+ district.should be_a(Diametric::Persistence::ListenableFuture)
20
+ end
21
+ it "should return object by get from future do" do
22
+ district.get.should_not be_nil
23
+ end
24
+ end
25
+
26
+ context District do
27
+ before(:all) do
28
+ datomic_uri = "datomic:mem://district-#{SecureRandom.uuid}"
29
+ @d_conn2 = Diametric::Persistence::Peer.connect(datomic_uri)
30
+ District.create_schema(@d_conn2).get
31
+ end
32
+ after(:all) do
33
+ @d_conn2.release
34
+ end
35
+ it "should save instance" do
36
+ district = District.new
37
+ district.name = "East"
38
+ district.region = District::Region::E
39
+ district.save(@d_conn2).should_not be_nil
40
+ district.tx_data.should be_empty
41
+ end
42
+ it "should get instance" do
43
+ query = Diametric::Query.new(District, @d_conn2, true)
44
+ district = query.where(:name => "East").first
45
+ district.name.should == "East"
46
+ district.region.should == District::Region::E
47
+ end
48
+ end
49
+
50
+ context Neighborhood do
51
+ before(:all) do
52
+ datomic_uri = "datomic:mem://neighborhood-#{SecureRandom.uuid}"
53
+ @n_conn1 = Diametric::Persistence::Peer.connect(datomic_uri)
54
+ end
55
+ after(:all) do
56
+ @n_conn1.release
57
+ end
58
+ it "should create schema" do
59
+ Neighborhood.create_schema(@n_conn1).get.should_not be_nil
60
+ end
61
+ end
62
+
63
+ context Neighborhood do
64
+ before(:all) do
65
+ datomic_uri = "datomic:mem://neighborhood-#{SecureRandom.uuid}"
66
+ @n_conn2 = Diametric::Persistence::Peer.connect(datomic_uri)
67
+ Neighborhood.create_schema(@n_conn2).get
68
+ District.create_schema(@n_conn2).get
69
+ end
70
+ after(:all) do
71
+ @n_conn2.release
72
+ end
73
+
74
+ it "should save instance" do
75
+ district = District.new
76
+ district.name = "East"
77
+ district.region = District::Region::E
78
+ neighborhood = Neighborhood.new
79
+ neighborhood.name = "Capitol Hill"
80
+ neighborhood.district = district
81
+ neighborhood.save(@n_conn2).should_not be_nil
82
+ district.tx_data.should be_empty
83
+ neighborhood.tx_data.should be_empty
84
+ end
85
+
86
+ it "should not include tx_data of saved entity" do
87
+ district = District.new
88
+ district.name = "Southwest"
89
+ district.region = District::Region::SW
90
+ district.save(@n_conn2)
91
+ neighborhood = Neighborhood.new
92
+ neighborhood.name = "Admiral (West Seattle)"
93
+ neighborhood.district = district
94
+
95
+ result = []
96
+ neighborhood.parse_tx_data(neighborhood.tx_data, result)
97
+ result.first[":neighborhood/district"].to_s.should match(/^\d+/)
98
+
99
+ neighborhood.save(@n_conn2)
100
+ district.tx_data.should be_empty
101
+ neighborhood.tx_data.should be_empty
102
+ end
103
+
104
+ it "should get instance" do
105
+ district = District.new
106
+ district.name = "East"
107
+ district.region = District::Region::E
108
+ neighborhood = Neighborhood.new
109
+ neighborhood.name = "Capitol Hill"
110
+ neighborhood.district = district
111
+ neighborhood.save(@n_conn2).should_not be_nil
112
+
113
+ query = Diametric::Query.new(Neighborhood, @n_conn2, true)
114
+ neighborhood = query.where(:name => "Capitol Hill").first
115
+ neighborhood.dbid.should_not be_nil
116
+ neighborhood.name.should == "Capitol Hill"
117
+ neighborhood.district.should be_a(District)
118
+ neighborhood.district.dbid.should_not be_nil
119
+ neighborhood.district.name.should == "East"
120
+ neighborhood.district.region.should == District::Region::E
121
+ end
122
+
123
+ it "should not resolve ref type dbid" do
124
+ district = District.new
125
+ district.name = "East"
126
+ district.region = District::Region::E
127
+ neighborhood = Neighborhood.new
128
+ neighborhood.name = "Capitol Hill"
129
+ neighborhood.district = district
130
+ neighborhood.save(@n_conn2).should_not be_nil
131
+
132
+ query = Diametric::Query.new(Neighborhood, @n_conn2, true)
133
+ neighborhood = query.where(:name => "Capitol Hill").first
134
+ neighborhood.name.should == "Capitol Hill"
135
+ neighborhood.district.should be_a(District)
136
+ end
137
+ end
138
+
139
+ context Community do
140
+ before(:all) do
141
+ datomic_uri = "datomic:mem://community-#{SecureRandom.uuid}"
142
+ @s_conn1 = Diametric::Persistence::Peer.connect(datomic_uri)
143
+ end
144
+ after(:all) do
145
+ @s_conn1.release
146
+ end
147
+ it "should create schema" do
148
+ Community.create_schema(@s_conn1).get.should_not be_nil
149
+ end
150
+ end
151
+
152
+ context Community do
153
+ before(:all) do
154
+ datomic_uri = "datomic:mem://community-#{SecureRandom.uuid}"
155
+ @s_conn2 = Diametric::Persistence::Peer.connect(datomic_uri)
156
+ Neighborhood.create_schema(@s_conn2).get
157
+ District.create_schema(@s_conn2).get
158
+ Community.create_schema(@s_conn2).get
159
+ end
160
+ after(:all) do
161
+ @s_conn2.release
162
+ end
163
+
164
+ it "should save instance" do
165
+ district = District.new
166
+ district.name = "East"
167
+ district.region = District::Region::E
168
+ neighborhood = Neighborhood.new
169
+ neighborhood.name = "Capitol Hill"
170
+ neighborhood.district = district
171
+ community = Community.new
172
+ community.name = "15th Ave Community"
173
+ community.url = "http://groups.yahoo.com/group/15thAve_Community/"
174
+ community.neighborhood = neighborhood
175
+ community.category = ["15th avenue residents"]
176
+ community.orgtype = Community::Orgtype::COMMUNITY
177
+ community.type = Community::Type::EMAIL_LIST
178
+ community.save(@n_conn2).should_not be_nil
179
+ end
180
+
181
+ it "should get instance" do
182
+ query = Diametric::Query.new(Community, @s_conn2, true)
183
+ community = query.where(:name => "15th Ave Community").first
184
+ community.dbid.should_not be_nil
185
+ community.name.should == "15th Ave Community"
186
+ community.url.should == "http://groups.yahoo.com/group/15thAve_Community/"
187
+ community.neighborhood.should be_a(Neighborhood)
188
+ community.neighborhood.dbid.should_not be_nil
189
+ community.neighborhood.name.should == "Capitol Hill"
190
+ community.neighborhood.district.should be_a(District)
191
+ community.neighborhood.district.dbid.should_not be_nil
192
+ community.neighborhood.district.name.should == "East"
193
+ community.neighborhood.district.region.should == District::Region::E
194
+ community.category == ["15th avenue residents"]
195
+ community.orgtype.should == Community::Orgtype::COMMUNITY
196
+ community.type.should == Community::Type::EMAIL_LIST
197
+ end
198
+ end
199
+
200
+ end
@@ -0,0 +1,82 @@
1
+ require 'conf_helper'
2
+ require 'support/entities'
3
+
4
+ describe "Seattle Sample", :jruby => true do
5
+ context Community do
6
+ before(:all) do
7
+ datomic_uri = "datomic:mem://seattle-#{SecureRandom.uuid}"
8
+ @conn = Diametric::Persistence::Peer.connect(datomic_uri)
9
+ Neighborhood.create_schema(@conn).get
10
+ District.create_schema(@conn).get
11
+ Community.create_schema(@conn).get
12
+ filename = File.join(File.dirname(__FILE__), "data", "seattle-data0.dtm")
13
+ list = Diametric::Persistence::Utils.read_all(filename)
14
+ map = @conn.transact(list.first).get
15
+ end
16
+
17
+ after(:all) do
18
+ @conn.release
19
+ end
20
+
21
+ it "should do queries" do
22
+ query = Diametric::Query.new(Community, @conn)
23
+ results = query.all #150
24
+ binding.pry
25
+
26
+ query = Diametric::Query.new(Neighborhood, @conn, true).where(:name => "Capitol Hill")
27
+ binding.pry
28
+ # Navigating up
29
+ #
30
+ # 6 communities have their neighborhood whoose name is "Capitol
31
+ # Hill"
32
+ #
33
+ communities = query.first.community_from_this_neighborhood(@conn)
34
+ binding.pry
35
+
36
+ communities.size.should == 6
37
+
38
+ communities.collect(&:name).should =~
39
+ ["15th Ave Community",
40
+ "Capitol Hill Community Council",
41
+ "Capitol Hill Housing",
42
+ "Capitol Hill Triangle",
43
+ "CHS Capitol Hill Seattle Blog",
44
+ "KOMO Communities - Captol Hill"]
45
+ binding.pry
46
+
47
+ #
48
+ # Adds another set of data
49
+ #
50
+ # Makes sure "before" state
51
+ #
52
+ query = Diametric::Query.new(Community, @conn)
53
+ results = query.all
54
+ results.size.should == 150
55
+ binding.pry
56
+
57
+ past = Time.now
58
+
59
+ binding.pry
60
+
61
+ filename1 = File.join(File.dirname(__FILE__), "data", "seattle-data1.dtm")
62
+ list = Diametric::Persistence::Utils.read_all(filename1)
63
+
64
+ map2 = @conn.transact(list.first).get
65
+ query = Diametric::Query.new(Community, @conn)
66
+ results = query.all
67
+ results.size.should == 258
68
+
69
+ binding.pry
70
+
71
+ past_db = @conn.db.as_of(past)
72
+
73
+ binding.pry
74
+
75
+ query = Diametric::Query.new(Community, past_db)
76
+ results = query.all
77
+ results.size.should == 150
78
+
79
+ binding.pry
80
+ end
81
+ end
82
+ end
@@ -0,0 +1,60 @@
1
+ require 'conf_helper'
2
+ require 'support/entities'
3
+
4
+ describe Diametric::Entity, :jruby => true do
5
+ context Community do
6
+ before(:all) do
7
+ datomic_uri = "datomic:mem://community-#{SecureRandom.uuid}"
8
+ @conn = Diametric::Persistence::Peer.connect(datomic_uri)
9
+ Neighborhood.create_schema(@conn).get
10
+ District.create_schema(@conn).get
11
+ Community.create_schema(@conn).get
12
+ binding.pry
13
+ end
14
+ after(:all) do
15
+ @conn.release
16
+ end
17
+
18
+ it "should save instance" do
19
+ district = District.new
20
+ district.name = "East"
21
+ district.region = District::Region::E
22
+ binding.pry
23
+ neighborhood = Neighborhood.new
24
+ neighborhood.name = "Capitol Hill"
25
+ neighborhood.district = district
26
+ community = Community.new
27
+ community.name = "15th Ave Community"
28
+ community.url = "http://groups.yahoo.com/group/15thAve_Community/"
29
+ community.neighborhood = neighborhood
30
+ community.category = ["15th avenue residents"]
31
+ community.orgtype = Community::Orgtype::COMMUNITY
32
+ community.type = Community::Type::EMAIL_LIST
33
+ binding.pry
34
+ res = community.save(@conn)
35
+ binding.pry
36
+
37
+ query = Diametric::Query.new(Community, @conn, true)
38
+ community = query.where(:name => "15th Ave Community").first
39
+ binding.pry
40
+ puts "community.name: #{community.name}"
41
+ puts "community.url: #{community.url}"
42
+ puts "community.category: #{community.category}"
43
+ puts "community.category: #{community.category.to_a.join(",")}"
44
+ puts "community.orgtype: #{community.orgtype}"
45
+ puts "community.orgtype == Community::Orgtype::COMMUNITY ? #{community.orgtype == Community::Orgtype::COMMUNITY}"
46
+ puts "community.type: #{community.type}"
47
+ puts "community.type == Community::Type::EMAIL_LIST ? #{community.type == Community::Type::EMAIL_LIST}"
48
+ binding.pry
49
+ puts "community.neighborhood.dbid: #{community.neighborhood.dbid}"
50
+ puts "community.neighborhood.name: #{community.neighborhood.name}"
51
+ binding.pry
52
+ puts "community.neighborhood.district.dbid: #{community.neighborhood.district.dbid}"
53
+ puts "community.neighborhood.district.name: #{community.neighborhood.district.name}"
54
+ puts "community.neighborhood.district.region: #{community.neighborhood.district.region}"
55
+ puts "community.neighborhood.district.region == District::Region::E ? #{community.neighborhood.district.region == District::Region::E}"
56
+ binding.pry
57
+ end
58
+ end
59
+
60
+ end
@@ -0,0 +1,72 @@
1
+ require 'conf_helper'
2
+
3
+ class Person
4
+ include Diametric::Entity
5
+ include Diametric::Persistence::Peer
6
+
7
+ attribute :name, String
8
+ attribute :nerd_rate, Integer
9
+ end
10
+
11
+ describe "RailsConf 2013", :jruby => true do
12
+ context Person do
13
+ before(:all) do
14
+ datomic_uri = "datomic:mem://person-#{SecureRandom.uuid}"
15
+ @conn = Diametric::Persistence::Peer.connect(datomic_uri)
16
+ binding.pry
17
+ end
18
+ after(:all) do
19
+ @conn.release
20
+ end
21
+
22
+ it "should create schema and save instaces" do
23
+ binding.pry
24
+ Person.create_schema(@conn).get
25
+
26
+ foo = Person.new
27
+ foo.name = "Yoko"
28
+ foo.nerd_rate = 50
29
+ binding.pry
30
+ foo.save
31
+
32
+ bar = Person.new(:name => "Clinton", :nerd_rate => 98)
33
+ binding.pry
34
+ bar.save
35
+
36
+ query = Diametric::Query.new(Person, @conn.db, true)
37
+ result = query.all
38
+ binding.pry
39
+
40
+ query = Diametric::Query.new(Person, @conn.db, true).where(:name => "Yoko")
41
+ result = query.all
42
+ binding.pry
43
+
44
+ past = Time.now
45
+ binding.pry
46
+
47
+ yoko = result.first
48
+ yoko.update_attributes(:nerd_rate => 70)
49
+ binding.pry
50
+
51
+ query = Diametric::Query.new(Person, @conn.db, true).where(:name => "Yoko")
52
+ result = query.all
53
+ binding.pry
54
+
55
+ past_db = @conn.db.as_of(past)
56
+ binding.pry
57
+
58
+ query = Diametric::Query.new(Person, past_db, true).where(:name => "Yoko")
59
+ result = query.all
60
+ binding.pry
61
+
62
+ query = Diametric::Query.new(Person, @conn.db, true).filter(:>, :nerd_rate, 60)
63
+ result = query.all
64
+ binding.pry
65
+
66
+ query = Diametric::Query.new(Person, past_db, true).filter(:>, :nerd_rate, 60)
67
+ result = query.all
68
+ binding.pry
69
+
70
+ end
71
+ end
72
+ end
@@ -0,0 +1,106 @@
1
+ require 'spec_helper'
2
+ require 'diametric/entity'
3
+ require 'datomic/client'
4
+
5
+ describe "Seattle Sample", :integration => true, :jruby => true do
6
+ context Diametric::Persistence::Utils do
7
+ before(:all) do
8
+ datomic_uri = "datomic:mem://utils-#{SecureRandom.uuid}"
9
+ @u_conn = Diametric::Persistence::Peer.connect(datomic_uri)
10
+ end
11
+
12
+ after(:all) do
13
+ @u_conn.release
14
+ end
15
+
16
+ it "should read all data from filename" do
17
+ filename = File.join(File.dirname(__FILE__), "data", "seattle-data0.dtm")
18
+ list = Diametric::Persistence::Utils.read_all(filename)
19
+ list.first.size.should == 450
20
+ end
21
+
22
+ it "should transact data read from file" do
23
+ Neighborhood.create_schema(@u_conn).get
24
+ District.create_schema(@u_conn).get
25
+ Community.create_schema(@u_conn).get
26
+ filename = File.join(File.dirname(__FILE__), "data", "seattle-data0.dtm")
27
+ list = Diametric::Persistence::Utils.read_all(filename)
28
+ map = @u_conn.transact(list.first).get
29
+ map.should_not be_nil
30
+ end
31
+ end
32
+
33
+ context Community do
34
+ before(:all) do
35
+ datomic_uri = "datomic:mem://community-#{SecureRandom.uuid}"
36
+ @s_conn1 = Diametric::Persistence::Peer.connect(datomic_uri)
37
+ Neighborhood.create_schema(@s_conn1).get
38
+ District.create_schema(@s_conn1).get
39
+ Community.create_schema(@s_conn1).get
40
+ filename = File.join(File.dirname(__FILE__), "data", "seattle-data0.dtm")
41
+ list = Diametric::Persistence::Utils.read_all(filename)
42
+ map = @s_conn1.transact(list.first).get
43
+ end
44
+
45
+ after(:all) do
46
+ @s_conn1.release
47
+ end
48
+
49
+ it "should get all community names" do
50
+ query = Diametric::Query.new(Community, @s_conn1)
51
+ results = query.all
52
+ results.size.should == 150
53
+ end
54
+
55
+ it "should get reverse reference" do
56
+ query = Diametric::Query.new(Neighborhood, @s_conn1, true).where(:name => "Capitol Hill")
57
+ communities = query.first.community_from_this_neighborhood(@s_conn1)
58
+ communities.size.should == 6
59
+ communities.collect(&:name).should =~
60
+ ["15th Ave Community",
61
+ "Capitol Hill Community Council",
62
+ "Capitol Hill Housing",
63
+ "Capitol Hill Triangle",
64
+ "CHS Capitol Hill Seattle Blog",
65
+ "KOMO Communities - Captol Hill"]
66
+ end
67
+ end
68
+
69
+ context Community do
70
+ before(:all) do
71
+ datomic_uri = "datomic:mem://community-#{SecureRandom.uuid}"
72
+ @s_conn2 = Diametric::Persistence::Peer.connect(datomic_uri)
73
+ Neighborhood.create_schema(@s_conn2).get
74
+ District.create_schema(@s_conn2).get
75
+ Community.create_schema(@s_conn2).get
76
+ filename0 = File.join(File.dirname(__FILE__), "data", "seattle-data0.dtm")
77
+ list = Diametric::Persistence::Utils.read_all(filename0)
78
+ map0 = @s_conn2.transact(list.first).get
79
+ end
80
+
81
+ after(:all) do
82
+ @s_conn2.release
83
+ end
84
+
85
+ it "should add another set of data" do
86
+ query = Diametric::Query.new(Community, @s_conn2)
87
+ results = query.all
88
+ results.size.should == 150
89
+
90
+ past = Time.now
91
+
92
+ filename1 = File.join(File.dirname(__FILE__), "data", "seattle-data1.dtm")
93
+ list = Diametric::Persistence::Utils.read_all(filename1)
94
+
95
+ map2 = @s_conn2.transact(list.first).get
96
+ query = Diametric::Query.new(Community, @s_conn2)
97
+ results = query.all
98
+ results.size.should == 258
99
+
100
+ past_db = @s_conn2.db.as_of(past)
101
+ query = Diametric::Query.new(Community, past_db)
102
+ results = query.all
103
+ results.size.should == 150
104
+ end
105
+ end
106
+ end