dm-hibernate-adapter 0.1pre-java

Sign up to get free protection for your applications and to get access to all the features.
Files changed (34) hide show
  1. data/lib/dm-hibernate-adapter.rb +471 -0
  2. data/lib/dm-hibernate-adapter/dialects.rb +37 -0
  3. data/lib/dm-hibernate-adapter/hibernate.rb +403 -0
  4. data/lib/dm-hibernate-adapter/spec/setup.rb +27 -0
  5. data/lib/dm-hibernate-adapter/transaction.rb +27 -0
  6. data/lib/dm-hibernate-adapter_ext.jar +0 -0
  7. data/lib/jibernate.rb +2 -0
  8. data/spec/abstract_adapter/adapter_shared_spec.rb +514 -0
  9. data/spec/abstract_adapter/dm-hibernate-adapter_spec.rb +25 -0
  10. data/spec/abstract_adapter/rcov.opts +6 -0
  11. data/spec/abstract_adapter/spec.opts +4 -0
  12. data/spec/abstract_adapter/spec_helper.rb +8 -0
  13. data/spec/dm_core/adapter_spec.rb +12 -0
  14. data/spec/dm_core/rcov.opts +6 -0
  15. data/spec/dm_core/spec.opts +5 -0
  16. data/spec/dm_core/spec_helper.rb +42 -0
  17. data/spec/log4j.properties +11 -0
  18. data/spec/transient/dm-hibernate-adapter_spec.rb +57 -0
  19. data/spec/transient/lib/adapter_helpers.rb +107 -0
  20. data/spec/transient/lib/collection_helpers.rb +18 -0
  21. data/spec/transient/lib/counter_adapter.rb +38 -0
  22. data/spec/transient/lib/pending_helpers.rb +46 -0
  23. data/spec/transient/lib/rspec_immediate_feedback_formatter.rb +54 -0
  24. data/spec/transient/rcov.opts +6 -0
  25. data/spec/transient/shared/adapter_shared_spec.rb +408 -0
  26. data/spec/transient/shared/finder_shared_spec.rb +1513 -0
  27. data/spec/transient/shared/model_spec.rb +165 -0
  28. data/spec/transient/shared/property_spec.rb +412 -0
  29. data/spec/transient/shared/resource_shared_spec.rb +1226 -0
  30. data/spec/transient/shared/resource_spec.rb +133 -0
  31. data/spec/transient/shared/sel_shared_spec.rb +112 -0
  32. data/spec/transient/spec.opts +4 -0
  33. data/spec/transient/spec_helper.rb +14 -0
  34. metadata +210 -0
@@ -0,0 +1,133 @@
1
+ require File.expand_path(File.join(File.dirname(__FILE__), '..', 'spec_helper'))
2
+
3
+ share_examples_for 'An Adapter with resource_spec support' do
4
+ describe DataMapper::Resource do
5
+ before :all do
6
+ # module ::Blog
7
+ class User
8
+ include DataMapper::Resource
9
+
10
+ property :id, Serial
11
+
12
+ property :name, String, :key => true
13
+ property :age, Integer
14
+ property :summary, Text
15
+ property :description, Text
16
+ property :admin, Boolean, :accessor => :private
17
+
18
+ belongs_to :parent, self, :required => false
19
+ has n, :children, self, :inverse => :parent
20
+
21
+ belongs_to :referrer, self, :required => false
22
+ has n, :comments
23
+
24
+ # FIXME: figure out a different approach than stubbing things out
25
+ def comment=(*)
26
+ # do nothing with comment
27
+ end
28
+ end
29
+
30
+ # TODO should be: Author < User
31
+ class Author
32
+ include DataMapper::Resource
33
+
34
+ property :id, Serial
35
+
36
+ property :name, String, :key => true
37
+ property :age, Integer
38
+ property :summary, Text
39
+ property :description, Text
40
+ property :admin, Boolean, :accessor => :private
41
+
42
+ belongs_to :parent, self, :required => false
43
+ has n, :children, self, :inverse => :parent
44
+
45
+ belongs_to :referrer, self, :required => false
46
+ has n, :comments
47
+
48
+ # FIXME: figure out a different approach than stubbing things out
49
+ def comment=(*)
50
+ # do nothing with comment
51
+ end
52
+ end
53
+
54
+ class Comment
55
+ include DataMapper::Resource
56
+
57
+ property :id, Serial
58
+ property :body, Text
59
+
60
+ belongs_to :user
61
+ end
62
+
63
+ class Article
64
+ include DataMapper::Resource
65
+
66
+ property :id, Serial
67
+ property :body, Text
68
+
69
+ has n, :paragraphs
70
+ end
71
+
72
+ class Paragraph
73
+ include DataMapper::Resource
74
+
75
+ property :id, Serial
76
+ property :text, String
77
+
78
+ belongs_to :article
79
+ end
80
+ # end
81
+
82
+ class ::Default
83
+ include DataMapper::Resource
84
+
85
+ property :name, String, :key => true, :default => 'a default value'
86
+ end
87
+
88
+
89
+ # # <addded>
90
+ # ::Blog::User.auto_migrate!
91
+ # ::Blog::Author.auto_migrate!
92
+ # ::Blog::Comment.auto_migrate!
93
+ # ::Blog::Article.auto_migrate!
94
+ # ::Blog::Paragraph.auto_migrate!
95
+ # # </addded>
96
+ #
97
+ #
98
+ # @user_model = Blog::User
99
+ # @author_model = Blog::Author
100
+ # @comment_model = Blog::Comment
101
+ # @article_model = Blog::Article
102
+ # @paragraph_model = Blog::Paragraph
103
+
104
+ # <addded>
105
+ User.auto_migrate!
106
+ Author.auto_migrate!
107
+ Comment.auto_migrate!
108
+ Article.auto_migrate!
109
+ Paragraph.auto_migrate!
110
+ Default.auto_migrate!
111
+ # </addded>
112
+
113
+
114
+ @user_model = User
115
+ @author_model = Author
116
+ @comment_model = Comment
117
+ @article_model = Article
118
+ @paragraph_model = Paragraph
119
+ end
120
+
121
+ # supported_by :all do
122
+ before :all do
123
+
124
+ user = @user_model.create(:name => 'dbussink', :age => 25, :description => 'Test')
125
+
126
+ @user = @user_model.get(*user.key)
127
+ end
128
+
129
+ it_should_behave_like 'A public Resource'
130
+ it_should_behave_like 'A Resource supporting Strategic Eager Loading'
131
+ # end
132
+ end
133
+ end
@@ -0,0 +1,112 @@
1
+ share_examples_for 'A Collection supporting Strategic Eager Loading' do
2
+ describe 'using SEL when looping within a loop' do
3
+ before :all do
4
+ @many_to_many = @articles.kind_of?(DataMapper::Associations::ManyToMany::Collection)
5
+ end
6
+
7
+ before :all do
8
+ attributes = {}
9
+
10
+ unless @many_to_many
11
+ attributes[:author] = @author
12
+ end
13
+
14
+ @revision = @article.revisions.create(attributes.merge(:title => 'Revision'))
15
+
16
+ @new_article = @article_model.create(attributes.merge(:title => 'Sample Article'))
17
+ @new_revision = @new_article.revisions.create(attributes.merge(:title => 'New Revision'))
18
+ end
19
+
20
+ before :all do
21
+ @original_adapter = @adapter
22
+
23
+ @adapter.meta_class.class_eval do
24
+ def eql?(other)
25
+ super || self == other
26
+ end
27
+ end
28
+
29
+ @adapter = DataMapper::Repository.adapters[@adapter.name] = CounterAdapter.new(@adapter)
30
+ @repository.instance_variable_set(:@adapter, @adapter)
31
+ end
32
+
33
+ before :all do
34
+ @results = []
35
+
36
+ @articles.each do |article|
37
+ article.revisions.each do |revision|
38
+ @results << [ article, revision ]
39
+ end
40
+ end
41
+ end
42
+
43
+ after :all do
44
+ @adapter = @original_adapter
45
+ end
46
+
47
+ it "should only execute the Adapter#read #{loaded ? 'once' : 'twice'}" do
48
+ @adapter.counts[:read].should == (loaded ? 1 : 2)
49
+ end
50
+
51
+ it 'should return the expected results' do
52
+ # if the collection is already loaded, then when it iterates it will
53
+ # not know about the newly added articles and their revisions
54
+ if loaded
55
+ @results.should == [ [ @article, @revision ] ]
56
+ else
57
+ pending_if 'TODO: make m:m not kick when delegating to the relationship', @many_to_many do
58
+ @results.should == [ [ @article, @revision ], [ @new_article, @new_revision ] ]
59
+ end
60
+ end
61
+ end
62
+ end
63
+ end
64
+
65
+ share_examples_for 'A Resource supporting Strategic Eager Loading' do
66
+ describe 'using SEL when inside a Collection' do
67
+ before :all do
68
+ @referrer = @user_model.create(:name => 'Referrer', :comment => @comment)
69
+
70
+ @user.update(:referrer => @referrer)
71
+
72
+ @new_user = @user_model.create(:name => 'Another User', :referrer => @referrer, :comment => @comment)
73
+ end
74
+
75
+ before :all do
76
+ @original_adapter = @adapter
77
+
78
+ @adapter.meta_class.class_eval do
79
+ def eql?(other)
80
+ super || other == self
81
+ end
82
+ end
83
+
84
+ @adapter = DataMapper::Repository.adapters[@adapter.name] = CounterAdapter.new(@adapter)
85
+ @repository.instance_variable_set(:@adapter, @adapter)
86
+ end
87
+
88
+ before :all do
89
+ @results = []
90
+
91
+ @user_model.all.each do |user|
92
+ @results << [ user, user.referrer ]
93
+ end
94
+
95
+ # some storage engines return the data in a different order
96
+ @results.sort!
97
+ end
98
+
99
+ after :all do
100
+ @adapter = @original_adapter
101
+ end
102
+
103
+ it 'should only execute the Adapter#read twice' do
104
+ @adapter.counts[:read].should == 2
105
+ end
106
+
107
+ it 'should return the expected results' do
108
+ # results are ordered alphabetically by the User name
109
+ @results.should == [ [ @new_user, @referrer ], [ @referrer, nil ], [ @user, @referrer ] ]
110
+ end
111
+ end
112
+ end
@@ -0,0 +1,4 @@
1
+ --colour
2
+ --loadby random
3
+ --format progress
4
+ --backtrace
@@ -0,0 +1,14 @@
1
+ require 'java'
2
+
3
+ org.apache.log4j.PropertyConfigurator.configure(File.dirname(__FILE__) + '/../log4j.properties')
4
+
5
+ require 'rubygems'
6
+ require 'spec'
7
+
8
+ require 'dm-hibernate-adapter'
9
+
10
+ dir = Pathname(__FILE__).dirname.expand_path.to_s
11
+
12
+ Dir[dir + "/lib/*.rb"].each{ |file| require dir+"/lib/" + File.basename(file, File.extname(file))}
13
+
14
+
metadata ADDED
@@ -0,0 +1,210 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: dm-hibernate-adapter
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: 3
5
+ version: 0.1pre
6
+ platform: java
7
+ authors:
8
+ - mkristian
9
+ - "Piotr G\xC4\x99ga"
10
+ - Douglas Ferreira
11
+ autorequire:
12
+ bindir: bin
13
+ cert_chain: []
14
+
15
+ date: 2011-07-27 00:00:00 +05:30
16
+ default_executable:
17
+ dependencies:
18
+ - !ruby/object:Gem::Dependency
19
+ name: dm-core
20
+ prerelease: false
21
+ requirement: &id001 !ruby/object:Gem::Requirement
22
+ none: false
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: 1.1.0
27
+ - - <
28
+ - !ruby/object:Gem::Version
29
+ version: 1.1.99999
30
+ type: :runtime
31
+ version_requirements: *id001
32
+ - !ruby/object:Gem::Dependency
33
+ name: dm-transactions
34
+ prerelease: false
35
+ requirement: &id002 !ruby/object:Gem::Requirement
36
+ none: false
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: 1.1.0
41
+ - - <
42
+ - !ruby/object:Gem::Version
43
+ version: 1.1.99999
44
+ type: :runtime
45
+ version_requirements: *id002
46
+ - !ruby/object:Gem::Dependency
47
+ name: dm-migrations
48
+ prerelease: false
49
+ requirement: &id003 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: 1.1.0
55
+ - - <
56
+ - !ruby/object:Gem::Version
57
+ version: 1.1.99999
58
+ type: :runtime
59
+ version_requirements: *id003
60
+ - !ruby/object:Gem::Dependency
61
+ name: slf4r
62
+ prerelease: false
63
+ requirement: &id004 !ruby/object:Gem::Requirement
64
+ none: false
65
+ requirements:
66
+ - - "="
67
+ - !ruby/object:Gem::Version
68
+ version: 0.3.1
69
+ type: :runtime
70
+ version_requirements: *id004
71
+ - !ruby/object:Gem::Dependency
72
+ name: yard
73
+ prerelease: false
74
+ requirement: &id005 !ruby/object:Gem::Requirement
75
+ none: false
76
+ requirements:
77
+ - - "="
78
+ - !ruby/object:Gem::Version
79
+ version: 0.5.3
80
+ type: :development
81
+ version_requirements: *id005
82
+ - !ruby/object:Gem::Dependency
83
+ name: rake
84
+ prerelease: false
85
+ requirement: &id006 !ruby/object:Gem::Requirement
86
+ none: false
87
+ requirements:
88
+ - - "="
89
+ - !ruby/object:Gem::Version
90
+ version: 0.8.7
91
+ type: :development
92
+ version_requirements: *id006
93
+ - !ruby/object:Gem::Dependency
94
+ name: rspec
95
+ prerelease: false
96
+ requirement: &id007 !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - "="
100
+ - !ruby/object:Gem::Version
101
+ version: 1.3.0
102
+ type: :development
103
+ version_requirements: *id007
104
+ - !ruby/object:Gem::Dependency
105
+ name: ruby-maven
106
+ prerelease: false
107
+ requirement: &id008 !ruby/object:Gem::Requirement
108
+ none: false
109
+ requirements:
110
+ - - "="
111
+ - !ruby/object:Gem::Version
112
+ version: 0.8.3.0.3.0.28.1
113
+ type: :development
114
+ version_requirements: *id008
115
+ - !ruby/object:Gem::Dependency
116
+ name: jruby-openssl
117
+ prerelease: false
118
+ requirement: &id009 !ruby/object:Gem::Requirement
119
+ none: false
120
+ requirements:
121
+ - - "="
122
+ - !ruby/object:Gem::Version
123
+ version: 0.7.4
124
+ type: :development
125
+ version_requirements: *id009
126
+ description:
127
+ email:
128
+ - m.kristian@web.de
129
+ - pietia.moo@gmail.com
130
+ - douglasrodrigo@gmail.com
131
+ executables: []
132
+
133
+ extensions: []
134
+
135
+ extra_rdoc_files: []
136
+
137
+ files:
138
+ - lib/dm-hibernate-adapter_ext.jar
139
+ - lib/dm-hibernate-adapter.rb
140
+ - lib/jibernate.rb
141
+ - lib/dm-hibernate-adapter/dialects.rb
142
+ - lib/dm-hibernate-adapter/hibernate.rb
143
+ - lib/dm-hibernate-adapter/transaction.rb
144
+ - lib/dm-hibernate-adapter/spec/setup.rb
145
+ - spec/log4j.properties
146
+ - spec/abstract_adapter/spec.opts
147
+ - spec/abstract_adapter/adapter_shared_spec.rb
148
+ - spec/abstract_adapter/spec_helper.rb
149
+ - spec/abstract_adapter/rcov.opts
150
+ - spec/abstract_adapter/dm-hibernate-adapter_spec.rb
151
+ - spec/transient/spec.opts
152
+ - spec/transient/spec_helper.rb
153
+ - spec/transient/rcov.opts
154
+ - spec/transient/dm-hibernate-adapter_spec.rb
155
+ - spec/transient/shared/resource_shared_spec.rb
156
+ - spec/transient/shared/resource_spec.rb
157
+ - spec/transient/shared/model_spec.rb
158
+ - spec/transient/shared/adapter_shared_spec.rb
159
+ - spec/transient/shared/sel_shared_spec.rb
160
+ - spec/transient/shared/property_spec.rb
161
+ - spec/transient/shared/finder_shared_spec.rb
162
+ - spec/transient/lib/collection_helpers.rb
163
+ - spec/transient/lib/pending_helpers.rb
164
+ - spec/transient/lib/rspec_immediate_feedback_formatter.rb
165
+ - spec/transient/lib/counter_adapter.rb
166
+ - spec/transient/lib/adapter_helpers.rb
167
+ - spec/dm_core/adapter_spec.rb
168
+ - spec/dm_core/spec.opts
169
+ - spec/dm_core/spec_helper.rb
170
+ - spec/dm_core/rcov.opts
171
+ has_rdoc: true
172
+ homepage:
173
+ licenses: []
174
+
175
+ post_install_message:
176
+ rdoc_options: []
177
+
178
+ require_paths:
179
+ - lib
180
+ required_ruby_version: !ruby/object:Gem::Requirement
181
+ none: false
182
+ requirements:
183
+ - - ">="
184
+ - !ruby/object:Gem::Version
185
+ version: "0"
186
+ required_rubygems_version: !ruby/object:Gem::Requirement
187
+ none: false
188
+ requirements:
189
+ - - ">"
190
+ - !ruby/object:Gem::Version
191
+ version: 1.3.1
192
+ requirements: []
193
+
194
+ rubyforge_project:
195
+ rubygems_version: 1.5.1
196
+ signing_key:
197
+ specification_version: 3
198
+ summary: dm-hibernate-adapter
199
+ test_files:
200
+ - spec/abstract_adapter/adapter_shared_spec.rb
201
+ - spec/abstract_adapter/dm-hibernate-adapter_spec.rb
202
+ - spec/transient/dm-hibernate-adapter_spec.rb
203
+ - spec/transient/shared/resource_shared_spec.rb
204
+ - spec/transient/shared/resource_spec.rb
205
+ - spec/transient/shared/model_spec.rb
206
+ - spec/transient/shared/adapter_shared_spec.rb
207
+ - spec/transient/shared/sel_shared_spec.rb
208
+ - spec/transient/shared/property_spec.rb
209
+ - spec/transient/shared/finder_shared_spec.rb
210
+ - spec/dm_core/adapter_spec.rb