activerecord_bulkoperation 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (48) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +1 -0
  3. data/.ruby-version +1 -0
  4. data/Gemfile +13 -0
  5. data/README.md +1 -0
  6. data/Rakefile +25 -0
  7. data/activerecord_bulkoperation.gemspec +23 -0
  8. data/gemfiles/4.2.gemfile +14 -0
  9. data/lib/activerecord_bulkoperation.rb +20 -0
  10. data/lib/activerecord_bulkoperation/active_record/adapters/abstract_adapter.rb +49 -0
  11. data/lib/activerecord_bulkoperation/active_record/adapters/oracle_enhanced_adapter.rb +10 -0
  12. data/lib/activerecord_bulkoperation/active_record/associations/associations.rb +169 -0
  13. data/lib/activerecord_bulkoperation/adapters/abstract_adapter.rb +43 -0
  14. data/lib/activerecord_bulkoperation/adapters/oracle_enhanced_adapter.rb +44 -0
  15. data/lib/activerecord_bulkoperation/base.rb +53 -0
  16. data/lib/activerecord_bulkoperation/bulkoperation.rb +260 -0
  17. data/lib/activerecord_bulkoperation/connection_adapters/oracle_enhanced/jdbc_connection.rb +111 -0
  18. data/lib/activerecord_bulkoperation/connection_adapters/oracle_enhanced/oci_connection.rb +106 -0
  19. data/lib/activerecord_bulkoperation/group_operations.rb +296 -0
  20. data/lib/activerecord_bulkoperation/group_operations_select.rb +60 -0
  21. data/lib/activerecord_bulkoperation/util/connection_object.rb +22 -0
  22. data/lib/activerecord_bulkoperation/util/entity_hash.rb +78 -0
  23. data/lib/activerecord_bulkoperation/util/flush_dirty_objects.rb +126 -0
  24. data/lib/activerecord_bulkoperation/util/sequence_cache.rb +52 -0
  25. data/lib/activerecord_bulkoperation/util/transaction_object.rb +36 -0
  26. data/lib/activerecord_bulkoperation/version.rb +5 -0
  27. data/test/active_record_connection_test.rb +41 -0
  28. data/test/adapters/oracle_enhanced.rb +1 -0
  29. data/test/bulkoperation_test.rb +176 -0
  30. data/test/database.yml +8 -0
  31. data/test/entity_hash_test.rb +11 -0
  32. data/test/find_group_by_test.rb +132 -0
  33. data/test/flush_dirty_objects_test.rb +11 -0
  34. data/test/models/assembly.rb +3 -0
  35. data/test/models/course.rb +3 -0
  36. data/test/models/group.rb +3 -0
  37. data/test/models/item.rb +2 -0
  38. data/test/models/part.rb +3 -0
  39. data/test/models/product.rb +7 -0
  40. data/test/models/student.rb +3 -0
  41. data/test/models/test_table.rb +2 -0
  42. data/test/postgresql/bulk_test.rb +13 -0
  43. data/test/schema/generic_schema.rb +59 -0
  44. data/test/sequence_cache_test.rb +31 -0
  45. data/test/support/postgresql/bulk_examples.rb +8 -0
  46. data/test/test_helper.rb +45 -0
  47. data/test/transaction_object_test.rb +11 -0
  48. metadata +141 -0
@@ -0,0 +1,11 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/test_helper')
2
+
3
+ class EntityHashTest < ActiveSupport::TestCase
4
+
5
+ def test_object_exists
6
+ obj = ActiveRecord::Bulkoperation::Util::EntityHash.new
7
+ assert_not_nil obj
8
+ end
9
+
10
+ end
11
+
@@ -0,0 +1,132 @@
1
+
2
+ require File.expand_path(File.dirname(__FILE__) + '/test_helper')
3
+
4
+ class FindGroupByTest < ActiveSupport::TestCase
5
+
6
+ def teardown
7
+ Item.delete_all
8
+ end
9
+
10
+ def setup
11
+ Item.new( :itemno => 'A', :sizen => 1, :company => 21).save!
12
+ Item.new( :itemno => 'B', :sizen => 2, :company => 22).save!
13
+ Item.new( :itemno => 'C', :sizen => 3, :company => 23).save!
14
+ Item.new( :itemno => 'D', :sizen => 4, :company => 24).save!
15
+ Item.new( :itemno => 'E', :sizen => 5, :company => 25).save!
16
+ Item.new( :itemno => 'F', :sizen => 6, :company => 26).save!
17
+ Item.new( :itemno => 'G', :sizen => 7, :company => 27).save!
18
+ Item.new( :itemno => 'H', :sizen => 8, :company => 28).save!
19
+ Item.new( :itemno => 'I', :sizen => 9, :company => 29).save!
20
+ Item.new( :itemno => 'J', :sizen => 10, :company => 30).save!
21
+ Item.new( :itemno => 'K', :sizen => 11, :company => 31).save!
22
+ Item.new( :itemno => 'L', :sizen => 12, :company => 32).save!
23
+ Item.new( :itemno => 'M', :sizen => 13, :company => 33).save!
24
+ Item.new( :itemno => 'N', :sizen => 14, :company => 34).save!
25
+ end
26
+
27
+ def test_items_exist
28
+ assert_equal( 14, Item.all.count)
29
+ i1 = Item.find_by( itemno: 'A')
30
+ assert_not_nil( i1 )
31
+ assert_equal( 'A', i1.itemno)
32
+ assert_equal( 1, i1.sizen)
33
+ assert_equal( 21, i1.company)
34
+ i2 = Item.find_by( itemno: 'B')
35
+ assert_not_nil( i2 )
36
+ assert_equal( 'B', i2.itemno)
37
+ assert_equal( 2, i2.sizen)
38
+ assert_equal( 22, i2.company)
39
+
40
+ assert_equal( 23, Item.find_by( itemno: 'C').company)
41
+ assert_equal( 24, Item.find_by( itemno: 'D').company)
42
+ assert_equal( 25, Item.find_by( itemno: 'E').company)
43
+ assert_equal( 26, Item.find_by( itemno: 'F').company)
44
+ assert_equal( 27, Item.find_by( itemno: 'G').company)
45
+ assert_equal( 28, Item.find_by( itemno: 'H').company)
46
+ assert_equal( 29, Item.find_by( itemno: 'I').company)
47
+ assert_equal( 30, Item.find_by( itemno: 'J').company)
48
+ assert_equal( 31, Item.find_by( itemno: 'K').company)
49
+ assert_equal( 32, Item.find_by( itemno: 'L').company)
50
+ assert_equal( 33, Item.find_by( itemno: 'M').company)
51
+ assert_equal( 34, Item.find_by( itemno: 'N').company)
52
+ end
53
+
54
+ def test_find_group_by_params_test
55
+ column_set = [ :itemno, :sizen, :company ]
56
+ assert_raises { Item.where_tuple(nil, nil) }
57
+ assert_raises { Item.where_tuple(column_set, nil) }
58
+ assert_raises { Item.where_tuple([], nil) }
59
+ assert_raises { Item.where_tuple(['string', 'strang'], nil) }
60
+ assert_raises { Item.where_tuple(column_set, []) }
61
+ assert_raises { Item.where_tuple(column_set, ['strong']) }
62
+ end
63
+
64
+ def test_find_group_by
65
+
66
+ i1 = Item.find_by( itemno: 'A')
67
+ i2 = Item.find_by( itemno: 'B')
68
+ i3 = Item.find_by( itemno: 'C')
69
+
70
+ is = Item.find_group_by( :itemno => [ 'A', 'B', 'C'], :sizen => [1, 2, 3], :company => [21, 22, 23] )
71
+
72
+ assert_not_nil( is )
73
+ assert_equal( 3, is.count)
74
+ assert_includes( is, i1)
75
+ assert_includes( is, i2)
76
+ assert_includes( is, i3)
77
+
78
+ is = Item.find_group_by( :itemno => [ 'A', 'B', 'C'], :sizen => [2, 3, 1], :company => [21, 22, 23] )
79
+ assert_not_nil( is )
80
+ assert_equal( 0, is.count)
81
+
82
+ is = Item.find_group_by( :itemno => [ 'A', 'B', 'C'], :sizen => [1, 2, 3], :company => [21, 22, 24] )
83
+ assert_not_nil( is )
84
+ assert_equal( 2, is.count)
85
+ assert_includes( is, i1)
86
+ assert_includes( is, i2)
87
+
88
+ is = Item.find_group_by( :itemno => [ 'A', 'B', 'C'], :sizen => [1, 2, 3], :company => [23, 23, 23] )
89
+ assert_not_nil( is )
90
+ assert_equal( 1, is.count)
91
+ assert_includes( is, i3)
92
+
93
+ is = Item.find_group_by( :itemno => [ 'A', 'A', 'A'], :sizen => [1, 2, 3], :company => [21, 22, 23] )
94
+ assert_equal( 1, is.count)
95
+ assert_includes( is, i1)
96
+ end
97
+
98
+ def test_find_by_multiple_columns
99
+
100
+ i1 = Item.find_by( itemno: 'A')
101
+ i2 = Item.find_by( itemno: 'B')
102
+ i3 = Item.find_by( itemno: 'C')
103
+
104
+ column_set = [ :itemno, :sizen, :company ]
105
+ is = Item.where_tuple( column_set, [ ['A', 1, 21], ['B', 2, 22], ['C', 3, 23] ] )
106
+
107
+ assert_not_nil( is )
108
+ assert_equal( 3, is.count)
109
+ assert_equal( i1, is[0])
110
+ assert_equal( i2, is[1])
111
+ assert_equal( i3, is[2])
112
+
113
+ is = Item.where_tuple( column_set, [ ['A', 2, 21], ['B', 3, 22], ['C', 1, 23] ] )
114
+ assert_not_nil( is )
115
+ assert_equal( 0, is.count)
116
+
117
+ is = Item.where_tuple( column_set, [ ['A', 1, 21], ['B', 2, 22], ['C', 3, 24] ] )
118
+ assert_not_nil( is )
119
+ assert_equal( 2, is.count)
120
+ assert_equal( i1, is[0])
121
+ assert_equal( i2, is[1])
122
+
123
+ is = Item.where_tuple( column_set, [ ['A', 1, 23], ['B', 2, 23], ['C', 3, 23] ] )
124
+ assert_not_nil( is )
125
+ assert_equal( 1, is.count)
126
+ assert_equal( i3, is[0])
127
+
128
+ is = Item.where_tuple( column_set, [ ['A', 1, 21], ['A', 2, 22], ['A', 3, 23] ] )
129
+ assert_equal( 1, is.count)
130
+ assert_equal( i1, is[0])
131
+ end
132
+ end
@@ -0,0 +1,11 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/test_helper')
2
+
3
+ class FlushDirtyObjectsTest < ActiveSupport::TestCase
4
+
5
+ def test_object_exists
6
+ obj = ActiveRecord::Bulkoperation::Util::FlushDirtyObjects.new
7
+ assert_not_nil obj
8
+ end
9
+
10
+ end
11
+
@@ -0,0 +1,3 @@
1
+ class Assembly < ActiveRecord::Base
2
+ has_and_belongs_to_many :parts
3
+ end
@@ -0,0 +1,3 @@
1
+ class Course < ActiveRecord::Base
2
+ has_and_belongs_to_many :students,:association_primary_key => :the_other_course_id,:association_foreign_key => :the_other_student_id,:join_table => "students_related_courses",:primary_key => :course_id,:foreign_key => :student_id
3
+ end
@@ -0,0 +1,3 @@
1
+ class Group < ActiveRecord::Base
2
+ has_many :test_tables
3
+ end
@@ -0,0 +1,2 @@
1
+ class Item < ActiveRecord::Base
2
+ end
@@ -0,0 +1,3 @@
1
+ class Part < ActiveRecord::Base
2
+ has_and_belongs_to_many :assemblies
3
+ end
@@ -0,0 +1,7 @@
1
+ class Product < ActiveRecord::Base
2
+ has_and_belongs_to_many :related_products,
3
+ class_name: "Product",
4
+ association_primary_key: "product_id",
5
+ join_table: "products_related_products",
6
+ association_foreign_key: "related_product_id"
7
+ end
@@ -0,0 +1,3 @@
1
+ class Student < ActiveRecord::Base
2
+ has_and_belongs_to_many :courses,:association_primary_key => 'the_other_student_id',:association_foreign_key => 'the_other_course_id',:join_table => "students_related_courses",:primary_key => 'student_id',:foreign_key => 'course_id'
3
+ end
@@ -0,0 +1,2 @@
1
+ class TestTable < ActiveRecord::Base
2
+ end
@@ -0,0 +1,13 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../test_helper')
2
+ #require File.expand_path(File.dirname(__FILE__) + '/../support/postgresql/bulk_examples')
3
+
4
+ class TestCalculations < ActiveSupport::TestCase
5
+
6
+ def test_count_distinct
7
+ assert_equal(3, 3)
8
+ assert ActiveRecord::Base.respond_to? :schedule_merge, "test"
9
+ end
10
+
11
+ end
12
+
13
+ #should_support_postgresql_import_functionality
@@ -0,0 +1,59 @@
1
+ ActiveRecord::Schema.define do
2
+ create_table :groups, :force => true do |t|
3
+ t.column :order_col, :string
4
+ t.timestamps null: true
5
+ end
6
+ create_table :test_tables, :force => true do |t|
7
+ t.column :author_name, :string
8
+ t.integer :group_id
9
+ t.timestamps null: true
10
+ end
11
+ create_table :items, :force => true do |t|
12
+ t.column :itemno, :string
13
+ t.column :sizen, :integer
14
+ t.column :company, :integer
15
+ t.timestamps null: true
16
+ end
17
+ create_table :assemblies, :force => true do |t|
18
+ t.string :name
19
+ t.timestamps null: true
20
+ end
21
+
22
+ create_table :parts, :force => true do |t|
23
+ t.string :part_number
24
+ t.timestamps null: true
25
+ end
26
+
27
+ create_table :assemblies_parts, :force => true, id: false do |t|
28
+ t.belongs_to :assembly
29
+ t.belongs_to :part
30
+ end
31
+
32
+ create_table :students, :force => true do |t|
33
+ t.string :name
34
+ t.integer :student_id
35
+ t.timestamps null: true
36
+ end
37
+
38
+ create_table :courses, :force => true do |t|
39
+ t.string :name
40
+ t.integer :course_id
41
+ t.timestamps null: true
42
+ end
43
+
44
+ create_table :students_related_courses,:force => true, id: false do |t|
45
+ t.belongs_to :the_other_student
46
+ t.belongs_to :the_other_course
47
+ end
48
+
49
+ create_table :products,:force => true do |t|
50
+ t.string :name
51
+ t.timestamps null: true
52
+ end
53
+
54
+ create_table :products_related_products,:force => true, id: false do |t|
55
+ t.belongs_to :product
56
+ t.belongs_to :related_product
57
+ end
58
+ #add_foreign_key :test_tables, :groups
59
+ end
@@ -0,0 +1,31 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/test_helper')
2
+
3
+ class SequenceCacheTest < ActiveSupport::TestCase
4
+
5
+ def test_object_exists
6
+ obj = ActiveRecord::Bulkoperation::Util::SequenceCache.new('groups_seq')
7
+ assert_not_nil obj
8
+ end
9
+
10
+ def test_seq_cache_multi_thread
11
+ cache = ActiveRecord::Bulkoperation::Util::SequenceCache.new('groups_seq')
12
+ res1 = []
13
+ res2 = []
14
+ t = Thread.new do
15
+ 1000.times do |i|
16
+ res1 << cache.next_value
17
+ end
18
+ end
19
+ t2 = Thread.new do
20
+ 1000.times do |i|
21
+ res2 << cache.next_value
22
+ end
23
+ end
24
+ t.join
25
+ t2.join
26
+
27
+ assert_equal 2000 , (res1 + res2).count
28
+ end
29
+
30
+ end
31
+
@@ -0,0 +1,8 @@
1
+ # encoding: UTF-8
2
+ def should_support_postgresql_import_functionality
3
+ describe "#supports_imports?" do
4
+ it "should support import" do
5
+ assert ActiveRecord::Base.supports_import?
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,45 @@
1
+ require "rubygems"
2
+ require 'pathname'
3
+ test_dir = Pathname.new File.dirname(__FILE__)
4
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
5
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
6
+
7
+ require "fileutils"
8
+
9
+ ENV["RAILS_ENV"] = "test"
10
+
11
+ require "bundler"
12
+ Bundler.setup
13
+
14
+ require "active_record"
15
+ require "active_record/fixtures"
16
+ require "active_support/test_case"
17
+
18
+ if ActiveSupport::VERSION::STRING < "4.1"
19
+ require 'test/unit'
20
+ else
21
+ require 'active_support/testing/autorun'
22
+ end
23
+
24
+ require "mocha/test_unit"
25
+
26
+ ActiveSupport::TestCase.test_order = :sorted
27
+ adapter = ENV["DB_ADAPTER"] || "oracle_enhanced"
28
+
29
+ FileUtils.mkdir_p 'log'
30
+ ActiveRecord::Base.logger = Logger.new("log/test.log")
31
+ ActiveRecord::Base.logger.level = Logger::DEBUG
32
+ ActiveRecord::Base.configurations['test'] = YAML.load_file(test_dir.join("database.yml"))[adapter]
33
+ ActiveRecord::Base.default_timezone = :utc
34
+
35
+ require "activerecord_bulkoperation"
36
+
37
+ ActiveRecord::Base.establish_connection :test
38
+
39
+ #ActiveSupport::Notifications.subscribe(/active_record.sql/) do |event, _, _, _, hsh|
40
+ # ActiveRecord::Base.logger.info hsh[:sql]
41
+ #end
42
+
43
+ require test_dir.join("schema/generic_schema")
44
+
45
+ Dir[File.dirname(__FILE__) + "/models/*.rb"].each{ |file| require file }
@@ -0,0 +1,11 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/test_helper')
2
+
3
+ class TransactionObjectTest < ActiveSupport::TestCase
4
+
5
+ def test_object_exists
6
+ obj = ActiveRecord::Bulkoperation::Util::TransactionObject.new
7
+ assert_not_nil obj
8
+ end
9
+
10
+ end
11
+
metadata ADDED
@@ -0,0 +1,141 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: activerecord_bulkoperation
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - OSP
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2018-11-23 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activerecord
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '4.2'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '4.2'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description: ''
42
+ email:
43
+ - ''
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - ".gitignore"
49
+ - ".ruby-version"
50
+ - Gemfile
51
+ - README.md
52
+ - Rakefile
53
+ - activerecord_bulkoperation.gemspec
54
+ - gemfiles/4.2.gemfile
55
+ - lib/activerecord_bulkoperation.rb
56
+ - lib/activerecord_bulkoperation/active_record/adapters/abstract_adapter.rb
57
+ - lib/activerecord_bulkoperation/active_record/adapters/oracle_enhanced_adapter.rb
58
+ - lib/activerecord_bulkoperation/active_record/associations/associations.rb
59
+ - lib/activerecord_bulkoperation/adapters/abstract_adapter.rb
60
+ - lib/activerecord_bulkoperation/adapters/oracle_enhanced_adapter.rb
61
+ - lib/activerecord_bulkoperation/base.rb
62
+ - lib/activerecord_bulkoperation/bulkoperation.rb
63
+ - lib/activerecord_bulkoperation/connection_adapters/oracle_enhanced/jdbc_connection.rb
64
+ - lib/activerecord_bulkoperation/connection_adapters/oracle_enhanced/oci_connection.rb
65
+ - lib/activerecord_bulkoperation/group_operations.rb
66
+ - lib/activerecord_bulkoperation/group_operations_select.rb
67
+ - lib/activerecord_bulkoperation/util/connection_object.rb
68
+ - lib/activerecord_bulkoperation/util/entity_hash.rb
69
+ - lib/activerecord_bulkoperation/util/flush_dirty_objects.rb
70
+ - lib/activerecord_bulkoperation/util/sequence_cache.rb
71
+ - lib/activerecord_bulkoperation/util/transaction_object.rb
72
+ - lib/activerecord_bulkoperation/version.rb
73
+ - test/active_record_connection_test.rb
74
+ - test/adapters/oracle_enhanced.rb
75
+ - test/bulkoperation_test.rb
76
+ - test/database.yml
77
+ - test/entity_hash_test.rb
78
+ - test/find_group_by_test.rb
79
+ - test/flush_dirty_objects_test.rb
80
+ - test/log/test.log
81
+ - test/models/assembly.rb
82
+ - test/models/course.rb
83
+ - test/models/group.rb
84
+ - test/models/item.rb
85
+ - test/models/part.rb
86
+ - test/models/product.rb
87
+ - test/models/student.rb
88
+ - test/models/test_table.rb
89
+ - test/postgresql/bulk_test.rb
90
+ - test/schema/generic_schema.rb
91
+ - test/sequence_cache_test.rb
92
+ - test/support/postgresql/bulk_examples.rb
93
+ - test/test_helper.rb
94
+ - test/transaction_object_test.rb
95
+ homepage: ''
96
+ licenses:
97
+ - Ruby
98
+ metadata: {}
99
+ post_install_message:
100
+ rdoc_options: []
101
+ require_paths:
102
+ - lib
103
+ required_ruby_version: !ruby/object:Gem::Requirement
104
+ requirements:
105
+ - - ">="
106
+ - !ruby/object:Gem::Version
107
+ version: 1.9.2
108
+ required_rubygems_version: !ruby/object:Gem::Requirement
109
+ requirements:
110
+ - - ">="
111
+ - !ruby/object:Gem::Version
112
+ version: '0'
113
+ requirements: []
114
+ rubyforge_project:
115
+ rubygems_version: 2.7.7
116
+ signing_key:
117
+ specification_version: 4
118
+ summary: ''
119
+ test_files:
120
+ - test/active_record_connection_test.rb
121
+ - test/adapters/oracle_enhanced.rb
122
+ - test/bulkoperation_test.rb
123
+ - test/database.yml
124
+ - test/entity_hash_test.rb
125
+ - test/find_group_by_test.rb
126
+ - test/flush_dirty_objects_test.rb
127
+ - test/log/test.log
128
+ - test/models/assembly.rb
129
+ - test/models/course.rb
130
+ - test/models/group.rb
131
+ - test/models/item.rb
132
+ - test/models/part.rb
133
+ - test/models/product.rb
134
+ - test/models/student.rb
135
+ - test/models/test_table.rb
136
+ - test/postgresql/bulk_test.rb
137
+ - test/schema/generic_schema.rb
138
+ - test/sequence_cache_test.rb
139
+ - test/support/postgresql/bulk_examples.rb
140
+ - test/test_helper.rb
141
+ - test/transaction_object_test.rb