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,25 @@
1
+
2
+ dir = Pathname(__FILE__).dirname.expand_path.to_s
3
+
4
+ require dir + '/spec_helper'
5
+
6
+ require dir + '/adapter_shared_spec'
7
+
8
+ describe DataMapper::Adapters::HibernateAdapter do
9
+ DB_CONFIGS = {
10
+ :H2_EMB => { :adapter => "hibernate", :dialect => "H2", :username => "sa", :url => "jdbc:h2:target/jibernate" },
11
+ :DERBY_EMB => { :adapter => "hibernate", :dialect => "Derby", :url => "jdbc:derby:target/jibernate;create=true" },
12
+ :HSQL_EMB => { :adapter => "hibernate", :dialect => "HSQL", :username => "sa", :url => "jdbc:hsqldb:file:target/testdb;create=true" },
13
+ :MySQL5 => { :adapter => "hibernate", :dialect => "MySQL5", :username => "root", :password => "root",
14
+ :url => "jdbc:mysql://localhost:3306/jibernate"},
15
+ :PostgreSQL => { :adapter => "hibernate", :dialect => "PostgreSQL", :username => "postgres", :password => "postgres",
16
+ :url => "jdbc:postgresql://localhost:5432/jibernate"}
17
+ }
18
+
19
+ before :all do
20
+ @adapter = DataMapper.setup(:default,DB_CONFIGS[(ENV['DIALECT'] || :H2_EMB).to_sym])
21
+ end
22
+
23
+ it_should_behave_like 'An Adapter'
24
+
25
+ end
@@ -0,0 +1,6 @@
1
+ --exclude "spec"
2
+ --sort coverage
3
+ --callsites
4
+ --xrefs
5
+ --profile
6
+ --text-summary
@@ -0,0 +1,4 @@
1
+ --colour
2
+ --loadby random
3
+ --format progress
4
+ --backtrace
@@ -0,0 +1,8 @@
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'
@@ -0,0 +1,12 @@
1
+ require 'spec_helper'
2
+
3
+ require 'dm-core/spec/shared/adapter_spec'
4
+
5
+ describe 'DataMapper::Adapters::HibernateAdapter' do
6
+ before :all do
7
+ @adapter = DataMapper::Spec.adapter
8
+ @repository = DataMapper.repository(@adapter.name)
9
+ end
10
+
11
+ it_should_behave_like "An Adapter"
12
+ end
@@ -0,0 +1,6 @@
1
+ --exclude "spec,^/"
2
+ --sort coverage
3
+ --callsites
4
+ --xrefs
5
+ --profile
6
+ --text-summary
@@ -0,0 +1,5 @@
1
+ --colour
2
+ --loadby random
3
+ --require ./spec/lib/rspec_immediate_feedback_formatter.rb
4
+ --format Spec::Runner::Formatter::ImmediateFeedbackFormatter
5
+ --backtrace
@@ -0,0 +1,42 @@
1
+ require 'pathname'
2
+ require 'rubygems'
3
+ require 'spec'
4
+ require 'dm-transactions'
5
+ require 'dm-migrations'
6
+ require 'dm-hibernate-adapter/spec/setup'
7
+
8
+ ENV['ADAPTER'] = 'hibernate'
9
+ ENV['ADAPTER_SUPPORTS'] = 'all'
10
+
11
+ SPEC_ROOT = Pathname(__FILE__).dirname.expand_path
12
+ LIB_ROOT = $:.select{|path| path =~ /.+dm-core.+lib/}.first
13
+
14
+ Pathname.glob((LIB_ROOT + '/dm-core/spec/**/*.rb' ).to_s).each { |file| require file }
15
+ Pathname.glob((SPEC_ROOT + '{lib,support,*/shared}/**/*.rb').to_s).each { |file| require file }
16
+
17
+ Spec::Runner.configure do |config|
18
+
19
+ config.extend( DataMapper::Spec::Adapters::Helpers)
20
+ config.include(DataMapper::Spec::PendingHelpers)
21
+ config.include(DataMapper::Spec::Helpers)
22
+
23
+ config.after :all do
24
+ DataMapper::Spec.cleanup_models
25
+ Hibernate.reset_config
26
+ end
27
+
28
+ config.after :all do
29
+ # global ivar cleanup
30
+ DataMapper::Spec.remove_ivars(self, instance_variables.reject { |ivar| ivar[0, 2] == '@_' })
31
+ end
32
+
33
+ config.after :all do
34
+ # WTF: rspec holds a reference to the last match for some reason.
35
+ # When the object ivars are explicitly removed, this causes weird
36
+ # problems when rspec uses it (!). Why rspec does this I have no
37
+ # idea because I cannot determine the intention from the code.
38
+ DataMapper::Spec.remove_ivars(Spec::Matchers.last_matcher, %w[ @expected ])
39
+ end
40
+
41
+ end
42
+
@@ -0,0 +1,11 @@
1
+ log4j.rootCategory=warn, stdout
2
+ log4j.appender.stdout=org.apache.log4j.ConsoleAppender
3
+ log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
4
+ log4j.appender.stdout.layout.ConversionPattern=(%c) - %m%n
5
+
6
+ log4j.category.org.hibernate=warn
7
+ log4j.category.org.hibernate.SQL=warn
8
+ log4j.category.DataMapper=debug
9
+ log4j.category.DataMapper.Adapters.HibernateAdapter=warn
10
+ log4j.category.Hibernate=debug
11
+ log4j.category.Hibernate.Model=info
@@ -0,0 +1,57 @@
1
+
2
+ dir = Pathname(__FILE__).dirname.expand_path.to_s
3
+ dir_shared = dir + "/shared"
4
+
5
+ require dir + '/spec_helper'
6
+
7
+ require dir_shared + '/adapter_shared_spec'
8
+ require dir_shared + '/model_spec'
9
+ require dir_shared + '/finder_shared_spec'
10
+ require dir_shared + '/property_spec'
11
+ require dir_shared + '/resource_spec'
12
+ require dir_shared + '/resource_shared_spec'
13
+ require dir_shared + '/sel_shared_spec'
14
+
15
+ describe DataMapper::Adapters::HibernateAdapter do
16
+ DB_CONFIGS = {
17
+ :H2_EMB => { :adapter => "hibernate", :dialect => "H2", :username => "sa", :url => "jdbc:h2:target/jibernate" },
18
+ :DERBY_EMB => { :adapter => "hibernate", :dialect => "Derby", :url => "jdbc:derby:target/jibernate;create=true" },
19
+ :HSQL_EMB => { :adapter => "hibernate", :dialect => "HSQL", :username => "sa", :url => "jdbc:hsqldb:file:target/testdb;create=true" },
20
+ :MySQL5 => { :adapter => "hibernate", :dialect => "MySQL5", :username => "root", :password => "root",
21
+ :url => "jdbc:mysql://localhost:3306/jibernate"},
22
+ :PostgreSQL => { :adapter => "hibernate", :dialect => "PostgreSQL", :username => "postgres", :password => "postgres",
23
+ :url => "jdbc:postgresql://localhost:5432/jibernate"}
24
+ }.freeze
25
+
26
+ # XXX Add drivers to run specs against them
27
+ DRIVERS = [ (ENV['DIALECT'] || :H2_EMB).to_sym ]
28
+
29
+ # "big ones"
30
+ # DRIVERS = [ :MySQL5, :PostgreSQL ].freeze
31
+ # "small ones"
32
+ # DRIVERS = [ :H2_EMB, :DERBY_EMB, :HSQL_EMB ].freeze
33
+ # all
34
+ # DRIVERS = [ :H2_EMB, :DERBY_EMB, :HSQL_EMB, :MySQL5, :PostgreSQL ].freeze
35
+
36
+ # iterate over selected drivers and run specs
37
+ DRIVERS.collect{|d| [d, DB_CONFIGS[d]]}.each do |driver, connection_options|
38
+
39
+ describe "with +#{driver}+ driver => " do
40
+
41
+ before :all do
42
+ @adapter = DataMapper.setup(:default, connection_options )
43
+ end
44
+
45
+ # Abstract adapter spec
46
+ # it_should_behave_like 'An Adapter' # STATUS: ~OK
47
+ # property_spec.rb
48
+ it_should_behave_like 'An Adapter with property_spec support'
49
+
50
+ # model_spec.rb
51
+ # it_should_behave_like 'An Adapter with model_spec support' # STATUS: PENDING
52
+ # resource_spec.rb
53
+ # it_should_behave_like 'An Adapter with resource_spec support' # STATUS: PENDING
54
+
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,107 @@
1
+ require "benchmark"
2
+
3
+ module DataMapper::Spec
4
+ module AdapterHelpers
5
+ def self.current_adapters
6
+ @current_adapters ||= []
7
+ end
8
+
9
+ def supported_by(*adapters, &block)
10
+ adapters = get_adapters(*adapters)
11
+
12
+ PRIMARY.only(*adapters).each do |adapter, connection_uri|
13
+ # keep track of the current adapters
14
+ AdapterHelpers.current_adapters << adapters
15
+
16
+ describe("with #{adapter}") do
17
+ before :all do
18
+ # store these in instance vars for the shared adapter specs
19
+ @adapter = DataMapper.setup(:default, connection_uri)
20
+ @repository = DataMapper.repository(@adapter.name)
21
+
22
+ # create all tables and constraints before each spec
23
+ if @repository.respond_to?(:auto_migrate!)
24
+ @repository.auto_migrate!
25
+ end
26
+ end
27
+
28
+ after :all do
29
+ # remove all tables and constraints after each spec
30
+ if DataMapper.respond_to?(:auto_migrate_down!, true)
31
+ DataMapper.send(:auto_migrate_down!, @repository.name)
32
+ end
33
+
34
+ DataMapper::Repository.adapters.delete(@repository.name)
35
+ end
36
+
37
+ # TODO: add destroy_model_storage and migrations code
38
+ # that removes the YAML file and remove this code
39
+ after :all do
40
+ if defined?(DataMapper::Adapters::YamlAdapter) && @adapter.kind_of?(DataMapper::Adapters::YamlAdapter)
41
+ descendants = DataMapper::Model.descendants.to_a
42
+ while model = descendants.shift
43
+ descendants.concat(model.descendants.to_a - [ model ])
44
+
45
+ model.default_scope.clear
46
+ model.all(:repository => @repository).destroy!
47
+ end
48
+ end
49
+ end
50
+
51
+ instance_eval(&block)
52
+ end
53
+
54
+ AdapterHelpers.current_adapters.pop
55
+ end
56
+ end
57
+
58
+ def with_alternate_adapter(&block)
59
+ adapters = AdapterHelpers.current_adapters.last
60
+
61
+ ALTERNATE.only(*adapters).each do |adapter, connection_uri|
62
+ describe("and #{adapter}") do
63
+ before :all do
64
+ @alternate_adapter = DataMapper.setup(:alternate, connection_uri)
65
+ @alternate_repository = DataMapper.repository(@alternate_adapter.name)
66
+
67
+ # create all tables and constraints before each spec
68
+ if @alternate_repository.respond_to?(:auto_migrate!)
69
+ @alternate_repository.auto_migrate!
70
+ end
71
+ end
72
+
73
+ after :all do
74
+ # remove all tables and constraints after each spec
75
+ if DataMapper.respond_to?(:auto_migrate_down!, true)
76
+ DataMapper.send(:auto_migrate_down!, @alternate_repository.name)
77
+ end
78
+
79
+ DataMapper::Repository.adapters.delete(@alternate_repository.name)
80
+ end
81
+
82
+ # TODO: add destroy_model_storage and migrations code
83
+ # that removes the YAML file and remove this code
84
+ after :all do
85
+ if defined?(DataMapper::Adapters::YamlAdapter) && @alternate_adapter.kind_of?(DataMapper::Adapters::YamlAdapter)
86
+ descendants = DataMapper::Model.descendants.to_a
87
+ while model = descendants.shift
88
+ descendants.concat(model.descendants.to_a - [ model ])
89
+
90
+ model.default_scope.clear
91
+ model.all(:repository => @alternate_repository).destroy!
92
+ end
93
+ end
94
+ end
95
+
96
+ instance_eval(&block)
97
+ end
98
+ end
99
+ end
100
+
101
+ def get_adapters(*adapters)
102
+ adapters.map! { |adapter_name| adapter_name.to_s }
103
+ adapters = ADAPTERS if adapters.include?('all')
104
+ ADAPTERS & adapters
105
+ end
106
+ end
107
+ end
@@ -0,0 +1,18 @@
1
+ module DataMapper::Spec
2
+ module CollectionHelpers
3
+ module GroupMethods
4
+ def self.extended(base)
5
+ base.class_inheritable_accessor :loaded
6
+ base.loaded = false
7
+ end
8
+
9
+ def should_not_be_a_kicker(ivar = :@articles)
10
+ unless loaded
11
+ it 'should not be a kicker' do
12
+ instance_variable_get(ivar).should_not be_loaded
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,38 @@
1
+ class CounterAdapter < DataMapper::Adapters::AbstractAdapter
2
+ instance_methods.each do |method|
3
+ next if method =~ /\A__/ ||
4
+ %w[ send class dup object_id kind_of? instance_of? respond_to? equal? freeze frozen? should should_not instance_variables instance_variable_set instance_variable_get instance_variable_defined? remove_instance_variable extend hash inspect copy_object ].include?(method.to_s)
5
+ undef_method method
6
+ end
7
+
8
+ attr_reader :counts
9
+
10
+ def kind_of?(klass)
11
+ super || @adapter.kind_of?(klass)
12
+ end
13
+
14
+ def instance_of?(klass)
15
+ super || @adapter.instance_of?(klass)
16
+ end
17
+
18
+ def respond_to?(method, include_private = false)
19
+ super || @adapter.respond_to?(method, include_private)
20
+ end
21
+
22
+ private
23
+
24
+ def initialize(adapter)
25
+ @counts = Hash.new { |hash, key| hash[key] = 0 }
26
+ @adapter = adapter
27
+ @count = 0
28
+ end
29
+
30
+ def increment_count_for(method)
31
+ @counts[method] += 1
32
+ end
33
+
34
+ def method_missing(method, *args, &block)
35
+ increment_count_for(method)
36
+ @adapter.send(method, *args, &block)
37
+ end
38
+ end
@@ -0,0 +1,46 @@
1
+ module DataMapper::Spec
2
+ module PendingHelpers
3
+ def pending_if(*args)
4
+ message, boolean = parse_args(*args)
5
+
6
+ if boolean
7
+ pending(message) { yield }
8
+ else
9
+ yield
10
+ end
11
+ end
12
+
13
+ def rescue_if(*args)
14
+ message, boolean = parse_args(*args)
15
+
16
+ if boolean
17
+ raised = nil
18
+ begin
19
+ yield
20
+ raised = false
21
+ rescue Exception
22
+ raised = true
23
+ end
24
+
25
+ raise "should have raised: #{message || 'TODO'}" if raised == false
26
+ else
27
+ yield
28
+ end
29
+ end
30
+
31
+ private
32
+
33
+ def parse_args(*args)
34
+ case args.map { |arg| arg.class }
35
+ when [ String, TrueClass ], [ String, FalseClass ] then args
36
+ when [ String, NilClass ] then [ args.first, false ]
37
+ when [ String ] then [ args.first, true ]
38
+ when [ TrueClass ], [ FalseClass ] then [ '', args.first ]
39
+ when [ NilClass ] then [ '', false ]
40
+ when [] then [ '', true ] # defaults
41
+ else
42
+ raise ArgumentError, "Invalid arguments: #{args.inspect}"
43
+ end
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,54 @@
1
+ require 'spec/runner/formatter/base_text_formatter'
2
+
3
+ # Code is based on standard SpecdocFormatter, but will print full error details as soon as they are found.
4
+ # Successful or pending examples are written only as a dot in the output. Header is only printed if errors occur.
5
+ #
6
+ # To use it, add the following to your spec/spec.opts:
7
+ # --require
8
+ # lib/rspec_immediate_feedback_formatter.rb
9
+ # --format
10
+ # Spec::Runner::Formatter::ImmediateFeedbackFormatter
11
+
12
+ module Spec
13
+ module Runner
14
+ module Formatter
15
+ class ImmediateFeedbackFormatter < BaseTextFormatter
16
+
17
+ def add_example_group(example_group)
18
+ super
19
+ @current_group = example_group.description
20
+ end
21
+
22
+ def example_failed(example, counter, failure)
23
+ if @current_group
24
+ output.puts
25
+ output.puts @current_group
26
+ @current_group = nil # only print the group name once
27
+ end
28
+
29
+ message = if failure.expectation_not_met?
30
+ "- #{example.description} (FAILED - #{counter})"
31
+ else
32
+ "- #{example.description} (ERROR - #{counter})"
33
+ end
34
+
35
+ output.puts(red(message))
36
+ # output.puts(failure.expectation_not_met? ? red(message) : message)
37
+ dump_failure(counter, failure) # dump stacktrace immediately
38
+ output.flush
39
+ end
40
+
41
+ def example_passed(*)
42
+ output.print green('.')
43
+ output.flush
44
+ end
45
+
46
+ def example_pending(*)
47
+ super
48
+ output.print yellow('*')
49
+ output.flush
50
+ end
51
+ end
52
+ end
53
+ end
54
+ end