activerecord-bogacs 0.5.0 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (32) hide show
  1. checksums.yaml +5 -5
  2. data/.github/workflows/test.yml +82 -0
  3. data/.travis.yml +32 -34
  4. data/Gemfile +2 -15
  5. data/LICENSE.txt +1 -1
  6. data/README.md +45 -21
  7. data/Rakefile +8 -6
  8. data/activerecord-bogacs.gemspec +6 -6
  9. data/lib/active_record/bogacs/autoload.rb +10 -0
  10. data/lib/active_record/bogacs/connection_handler.rb +36 -0
  11. data/lib/active_record/bogacs/default_pool.rb +278 -129
  12. data/lib/active_record/bogacs/false_pool.rb +95 -73
  13. data/lib/active_record/bogacs/pool_support.rb +26 -9
  14. data/lib/active_record/bogacs/railtie.rb +17 -0
  15. data/lib/active_record/bogacs/reaper.rb +4 -6
  16. data/lib/active_record/bogacs/shareable_pool.rb +12 -16
  17. data/lib/active_record/bogacs/thread_safe/synchronized.rb +18 -22
  18. data/lib/active_record/bogacs/thread_safe.rb +3 -67
  19. data/lib/active_record/bogacs/validator.rb +21 -26
  20. data/lib/active_record/bogacs/version.rb +2 -2
  21. data/lib/active_record/bogacs.rb +7 -54
  22. data/lib/active_record/connection_adapters/adapter_compat.rb +63 -17
  23. data/lib/active_record/connection_adapters/pool_class.rb +75 -0
  24. data/lib/activerecord-bogacs.rb +1 -0
  25. data/test/active_record/bogacs/false_pool_test.rb +66 -78
  26. data/test/active_record/bogacs/shareable_pool/connection_pool_test.rb +6 -3
  27. data/test/active_record/bogacs/shareable_pool/connection_sharing_test.rb +3 -2
  28. data/test/active_record/bogacs/shareable_pool_helper.rb +1 -1
  29. data/test/active_record/bogacs/validator_test.rb +22 -28
  30. data/test/active_record/connection_pool_test_methods.rb +24 -20
  31. data/test/test_helper.rb +42 -25
  32. metadata +35 -17
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 3da20a4a7e44c77643b1cf11b949e5fb818d43ca
4
- data.tar.gz: 4bd02da78f04b586079c01ef3d3429d13821337e
2
+ SHA256:
3
+ metadata.gz: 5010de8016e3c5896dc032a0fa6afc6ab5cbb1808f60e7c6f42b22b280910aeb
4
+ data.tar.gz: 3290de6d8265973c7efa237e18de7f96253580363b743785b069f34c5c92504a
5
5
  SHA512:
6
- metadata.gz: bc86fe344a38859c20e2c41c4017a5d5e3d1c802a2879cc80376c8f9f286d7ec9496851217f98197869558edfb08aca4c37eab0c873a4b1538a6f2d1aadbd39b
7
- data.tar.gz: 8de7842694c6ad26a9a904c0c8656dc5b1a6924771e3c8a106a53a917f82928a59bfec09123317c93813d89c9a009e1e99c392fa2549d0e6a23e71dc6c805a65
6
+ metadata.gz: 559b6831696d5e7ca408c735bc1f61bcb5c3fcfad19b0806aff943a47c623ac322462e79c3cefc1aca745df5cdda19986651c405e2024eebb8fa3c4cf02d7296
7
+ data.tar.gz: 588ccb8e705390652de5162a26cee060ce8fe51887693069602a55cfecfb19175b23268a821a7c956d7494d6be542f486c6bda89a4814932e8ee4249965a97de
@@ -0,0 +1,82 @@
1
+ name: Test
2
+
3
+ on: [push, pull_request]
4
+
5
+ env:
6
+ JAVA_OPTS: '-XX:+TieredCompilation -XX:TieredStopAtLevel=1'
7
+
8
+ jobs:
9
+
10
+ rake-test:
11
+ runs-on: ubuntu-latest
12
+ services:
13
+ mysql:
14
+ image: mysql:5.7
15
+ env:
16
+ MYSQL_ALLOW_EMPTY_PASSWORD: yes
17
+ MYSQL_ROOT_PASSWORD: root
18
+ MYSQL_DATABASE: ar_bogacs
19
+ ports:
20
+ - 3306:3306
21
+ options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3
22
+
23
+ env:
24
+ AR_ADAPTER: mysql2
25
+ AR_USERNAME: root
26
+ AR_PASSWORD: root
27
+ AR_HOST: 127.0.0.1
28
+ AR_VERSION: "~> 4.2"
29
+ HIKARI_VERSION: 2.3.12
30
+
31
+ strategy:
32
+ matrix:
33
+ java-version: [ 11 ]
34
+ ruby-version: [ jruby-9.3.6.0 ]
35
+ include:
36
+ - java-version: 11
37
+ ruby-version: jruby-9.2.20.1
38
+ - java-version: 11
39
+ ruby-version: jruby-9.2.10.0
40
+ - java-version: 17
41
+ ruby-version: jruby-9.2.20.1
42
+ - java-version: 8
43
+ ruby-version: jruby-9.2.9.0
44
+ - java-version: 8
45
+ ruby-version: jruby-9.1.17.0
46
+ env:
47
+ AR_VERSION: "~> 4.1.14"
48
+
49
+ fail-fast: false
50
+
51
+ steps:
52
+ - name: check mysql from host
53
+ run: |
54
+ sudo apt install -y mysql-client
55
+ mysql --host 127.0.0.1 --port 3306 -uroot -proot -e "SHOW DATABASES"
56
+
57
+ - name: checkout
58
+ uses: actions/checkout@v2
59
+
60
+ - name: set up java ${{ matrix.java-version }}
61
+ uses: actions/setup-java@v1.4.3
62
+ with:
63
+ java-version: ${{ matrix.java-version }}
64
+
65
+ - name: set up ${{ matrix.ruby-version }}
66
+ uses: ruby/setup-ruby@v1
67
+ with:
68
+ ruby-version: ${{ matrix.ruby-version }}
69
+
70
+ - name: install bundler
71
+ run: jruby -S gem install bundler -v "~>2.2.28"
72
+
73
+ - name: bundle install
74
+ run: jruby -S bundle install
75
+
76
+ - name: download jars
77
+ run: jruby -rbundler/setup -S rake tomcat:jndi:download tomcat:jdbc:download tomcat:dbcp:download hikari:download
78
+ shell: bash
79
+
80
+ - name: rake test
81
+ run: jruby -rbundler/setup -S rake test
82
+ shell: bash
data/.travis.yml CHANGED
@@ -1,63 +1,61 @@
1
1
  language: ruby
2
2
  sudo: false
3
3
  jdk:
4
- #- openjdk6
5
- - oraclejdk7
4
+ - openjdk7
6
5
  - oraclejdk8
7
6
  rvm:
8
- - jruby-1.7.24
9
- #- 2.1.2
7
+ - jruby-1.7.25
10
8
  before_install:
11
- - ((jruby -v | grep 1.8.7) && jruby --1.9 -S gem update --system 2.1.11) || true
9
+ - unset _JAVA_OPTIONS
10
+ - export AR_JDBC_VERSION="~> 1.3.24" # due the 50.0 release mess -> not specifying AR ~> 5.0
12
11
  before_script:
13
- #- echo \"JRUBY_OPTS: $JRUBY_OPTS\"
14
- - export JRUBY_OPTS="$JRUBY_OPTS --server -Xcext.enabled=false -Xcompile.invokedynamic=false"
15
12
  - export JAVA_OPTS="$JAVA_OPTS" # -Xmx600M
13
+ - 'echo "JAVA_OPTS: $JAVA_OPTS"'
14
+ - export JRUBY_OPTS="--server -Xcompile.invokedynamic=false"
15
+ - 'echo "JRUBY_OPTS: $JRUBY_OPTS"'
16
16
  script:
17
- - bundle exec rake tomcat:jndi:download tomcat:jdbc:download tomcat:dbcp:download
18
- - bundle exec rake c3p0:download
19
- - bundle exec rake hikari:download
20
- - bundle exec rake dbcp:download
21
- - bundle exec rake db:create:mysql db:create:postgresql
17
+ - jruby -rbundler/setup -S rake tomcat:jndi:download tomcat:jdbc:download tomcat:dbcp:download
18
+ - jruby -rbundler/setup -S rake c3p0:download hikari:download dbcp:download
19
+ - jruby -rbundler/setup -S rake db:create:mysql db:create:postgresql
22
20
  env:
23
- - JRUBY_OPTS="$JRUBY_OPTS" AR_ADAPTER=mysql AR_VERSION="~> 4.1.9" HIKARI_VERSION="2.3.12"
24
- - JRUBY_OPTS="$JRUBY_OPTS" AR_ADAPTER=postgresql AR_VERSION="~> 4.1.9" HIKARI_VERSION="2.3.2-java6"
25
- - JRUBY_OPTS="$JRUBY_OPTS" AR_ADAPTER=mysql AR_VERSION="~> 4.1.11" HIKARI_VERSION="2.0.1-java6"
21
+ - JRUBY_OPTS="$JRUBY_OPTS" AR_ADAPTER=mysql AR_VERSION="~> 4.1.13" HIKARI_VERSION="2.3.12"
22
+ - JRUBY_OPTS="$JRUBY_OPTS" AR_ADAPTER=postgresql AR_VERSION="~> 4.1.13" HIKARI_VERSION="2.3.2-java6"
23
+ - JRUBY_OPTS="$JRUBY_OPTS" AR_ADAPTER=mysql AR_VERSION="~> 4.1.13" HIKARI_VERSION="2.0.1-java6"
26
24
  - JRUBY_OPTS="$JRUBY_OPTS" AR_ADAPTER=postgresql AR_VERSION="~> 3.2.18" HIKARI_VERSION="1.4.0"
27
- - JRUBY_OPTS="--1.8 $JRUBY_OPTS" AR_ADAPTER=mysql AR_VERSION="~> 3.2.18" HIKARI_VERSION="2.2.5-java6"
25
+ - JRUBY_OPTS="$JRUBY_OPTS" AR_ADAPTER=mysql AR_VERSION="~> 4.2.8" HIKARI_VERSION="2.2.5-java6"
28
26
  matrix:
29
27
  #allow_failures:
30
28
  #- rvm: jruby-head
31
29
  exclude:
32
- - rvm: jruby-1.7.24
33
- env: JRUBY_OPTS="$JRUBY_OPTS" AR_ADAPTER=mysql AR_VERSION="~> 4.1.9" HIKARI_VERSION="2.3.12"
34
- jdk: oraclejdk7
35
- - rvm: jruby-1.7.24
36
- env: JRUBY_OPTS="$JRUBY_OPTS" AR_ADAPTER=postgresql AR_VERSION="~> 4.1.9" HIKARI_VERSION="2.3.2-java6"
30
+ - rvm: jruby-9.1.16.0
31
+ env: JRUBY_OPTS="$JRUBY_OPTS" AR_ADAPTER=mysql AR_VERSION="4.2.8" HIKARI_VERSION="2.3.12"
32
+ jdk: openjdk7
33
+ - rvm: jruby-9.1.16.0
34
+ env: JRUBY_OPTS="$JRUBY_OPTS" AR_ADAPTER=postgresql AR_VERSION="4.2.8" HIKARI_VERSION="2.3.2-java6"
37
35
  jdk: oraclejdk8
38
- - rvm: jruby-1.7.24
39
- env: JRUBY_OPTS="$JRUBY_OPTS" AR_ADAPTER=mysql AR_VERSION="~> 4.1.13" HIKARI_VERSION="2.0.1-java6"
36
+ - rvm: jruby-1.7.25
37
+ env: JRUBY_OPTS="$JRUBY_OPTS" AR_ADAPTER=mysql AR_VERSION="~> 4.1.16" HIKARI_VERSION="2.0.1-java6"
40
38
  jdk: oraclejdk8
41
- - rvm: jruby-1.7.24
39
+ - rvm: jruby-1.7.25
42
40
  env: JRUBY_OPTS="--1.8 $JRUBY_OPTS" AR_ADAPTER=mysql AR_VERSION="~> 3.2.18" HIKARI_VERSION="2.2.5-java6"
43
41
  jdk: oraclejdk8
44
42
  include:
45
43
  - rvm: jruby-9.0.5.0
46
44
  env: JRUBY_OPTS="$JRUBY_OPTS" AR_ADAPTER=mysql AR_VERSION="~> 4.1.13" HIKARI_VERSION="2.2.5-java6"
47
- jdk: oraclejdk7
48
- - rvm: jruby-9.1.2.0
45
+ jdk: openjdk7
46
+ - rvm: jruby-9.1.8.0
49
47
  env: JRUBY_OPTS="$JRUBY_OPTS" AR_ADAPTER=mysql AR_VERSION="~> 3.2.18" HIKARI_VERSION="2.3.9"
50
48
  jdk: oraclejdk8
51
49
  # AR 4.2
52
- - rvm: jruby-1.7.22
50
+ - rvm: jruby-1.7.27
53
51
  env: JRUBY_OPTS="$JRUBY_OPTS" AR_ADAPTER=mysql AR_VERSION="~> 4.1.13" HIKARI_VERSION="2.2.5-java6"
54
- jdk: oraclejdk7
55
- - rvm: jruby-9.1.2.0
56
- env: JRUBY_OPTS="$JRUBY_OPTS" AR_ADAPTER=mysql AR_VERSION="~> 4.2.4" HIKARI_VERSION="2.3.12"
52
+ jdk: openjdk7
53
+ - rvm: jruby-9.1.16.0
54
+ env: JRUBY_OPTS="$JRUBY_OPTS" AR_ADAPTER=mysql AR_VERSION="~> 4.2.8" HIKARI_VERSION="2.3.12"
57
55
  jdk: oraclejdk8
58
- - rvm: jruby-1.7.22
59
- env: JRUBY_OPTS="$JRUBY_OPTS" AR_ADAPTER=postgresql AR_VERSION="~> 4.2.4" HIKARI_VERSION="2.2.5-java6"
56
+ - rvm: jruby-9.1.16.0
57
+ env: JRUBY_OPTS="$JRUBY_OPTS" AR_ADAPTER=postgresql AR_VERSION="~> 4.2.8" HIKARI_VERSION="2.2.5-java6"
60
58
  jdk: oraclejdk8
61
- - rvm: jruby-9.0.5.0
59
+ - rvm: jruby-9.1.16.0
62
60
  env: JRUBY_OPTS="$JRUBY_OPTS" AR_ADAPTER=postgresql AR_VERSION="~> 4.1.13" HIKARI_VERSION="2.3.12"
63
- jdk: oraclejdk7
61
+ jdk: openjdk7
data/Gemfile CHANGED
@@ -16,14 +16,6 @@ else
16
16
  gem 'activerecord', :require => nil
17
17
  end
18
18
 
19
- if RUBY_VERSION.index('1.8') == 0
20
- gem 'i18n', '< 0.7.0' # Gem::InstallError: i18n requires Ruby version >= 1.9.3
21
- gem 'atomic', '1.1.16' # concurrent-ruby gem only for Ruby version >= 1.9.3
22
- gem 'thread_safe', '~> 0.3'
23
- else
24
- gem 'concurrent-ruby', '~> 1.0.0', :require => nil
25
- end
26
-
27
19
  platform :jruby do
28
20
  if version = ENV['AR_JDBC_VERSION']
29
21
  if version.index('/') && ::File.exist?(version)
@@ -40,16 +32,11 @@ platform :jruby do
40
32
  end
41
33
  end
42
34
 
43
- #gem 'thread_safe', :require => nil # "optional" - we can roll without it
44
-
45
- if defined?(JRUBY_VERSION) && JRUBY_VERSION < '1.7.0'
46
- gem 'jruby-openssl', :platform => :jruby
47
- end
48
-
49
35
  group :test do
50
36
  gem 'jdbc-mysql', :require => nil, :platform => :jruby
51
37
  gem 'jdbc-postgres', :require => nil, :platform => :jruby
38
+ gem 'jdbc-sqlite3', :require => nil, :platform => :jruby
52
39
 
53
40
  gem 'mysql2', :require => nil, :platform => :mri
54
41
  gem 'pg', :require => nil, :platform => :mri
55
- end
42
+ end
data/LICENSE.txt CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2013-2015 [Karol Bucek](http://kares.org)
1
+ Copyright (c) 2013-2018 [Karol Bucek](http://kares.org)
2
2
 
3
3
  MIT License
4
4
 
data/README.md CHANGED
@@ -6,7 +6,7 @@ ActiveRecord (all-year) pooling "alternatives" ... in a relaxed 'spa' fashion.
6
6
 
7
7
  Bogács is a village in Borsod-Abaúj-Zemplén county, Hungary.
8
8
 
9
- **WiP: do not put this on production if you do not understand the consequences!**
9
+ **NOTE: do not put this on production if you do not understand the consequences!**
10
10
 
11
11
  ## Install
12
12
 
@@ -22,8 +22,8 @@ add this line to your application's *Gemfile*:
22
22
 
23
23
  Bogacs' pools rely on a small monkey-patch that allows to change the AR pool.
24
24
  The desired pool class needs to be set before `establish_connection` happens,
25
- thus an initializer won't work, you might consider setting the pool class at
26
- the bottom of your *application.rb* e.g. :
25
+ thus an initializer (under Rails) won't work, you might consider setting the
26
+ pool class at the bottom of your *application.rb* e.g. :
27
27
 
28
28
  ```ruby
29
29
  Bundler.require(*Rails.groups)
@@ -34,29 +34,49 @@ module MyApp
34
34
  end
35
35
  end
36
36
 
37
- # sample AR-Bogacs setup using the "false" pool :
37
+ # sample AR-Bogacs setup using the "default" pool :
38
38
  if Rails.env.production?
39
- pool_class = ActiveRecord::Bogacs::FalsePool
39
+ pool_class = ActiveRecord::Bogacs::DefaultPool
40
40
  ActiveRecord::ConnectionAdapters::ConnectionHandler.connection_pool_class = pool_class
41
41
  end
42
42
  ```
43
43
 
44
- pools are expected to work with older ActiveRecord versions, if not let us know.
44
+ Alternatively, for `FalsePool`, there's a configuration convention (no need to path
45
+ and set the connection_pool_class) :
46
+ ```yaml
47
+ production:
48
+ adapter: mysql2
49
+ <% if $servlet_context %>
50
+ jndi: java:comp/env/jdbc/mydb
51
+ pool: false # use AR::Bogacs::FalsePool
52
+ <% else %>
53
+ port: <%= ENV['DATABASE_PORT'] || 3306 %>
54
+ database: mydb
55
+ # ...
56
+ <% end %>
57
+ ```
58
+
59
+ This works only as long as one doesn't set a custom connection handler, since
60
+ *Bogacs* only sets up its custom `ActiveRecord::Base.default_connection_handler`.
61
+
62
+ Pools are expected to work with older ActiveRecord versions: 3.x as well as 4.x.
45
63
 
46
- ### Default Pool
64
+ ### [Default Pool][2]
47
65
 
48
- Meant as a back-port for users stuck with old Rails versions (< 4.0) on production,
49
- facing potential (pool related) concurrency bugs e.g. with high-loads under JRuby.
66
+ Meant, primarily, as a back-port for users stuck with old Rails versions (< 4.0)
67
+ on production, facing potential (pool related) concurrency bugs e.g. with highly
68
+ concurrent loads under JRuby, although it also enhances some of the thread locking
69
+ issues present in 4.x's pool.
50
70
 
51
71
  Based on pool code from 4.x (which works much better than any previous version),
52
72
  with a few minor tunings and extensions such as `pool_initial: 0.5` which allows
53
73
  to specify how many connections to initialize in advance when the pool is created.
54
74
 
55
- ### False Pool
75
+ ### [False Pool][3]
56
76
 
57
77
  The false pool won't do any actual pooling, it is assumed that an underlying pool
58
78
  is configured. Still, it does maintain a hash of AR connections mapped to threads.
59
- Ignores pool related configurations such as `pool: 42` or `checkout_timeout: 2.5`.
79
+ Ignores pool related configuration such as `pool: 42` or `checkout_timeout: 2.5`.
60
80
 
61
81
  **NOTE:** be sure to configure an underlying pool e.g. with Trinidad (using the
62
82
  default Tomcat JDBC pool) :
@@ -70,7 +90,7 @@ default Tomcat JDBC pool) :
70
90
  mysql_dbpool:
71
91
  url: jdbc:mysql:///my_production
72
92
  username: root
73
- jndi: jdbc/BogacsDB
93
+ jndi: jdbc/MyDB
74
94
  initialSize: <%= ENV['POOL_INITIAL'] || 25 %> # connections created on start
75
95
  maxActive: <%= ENV['POOL_SIZE'] || 100 %> # default 100 (AR pool: size)
76
96
  maxIdle: <%= ENV['POOL_SIZE'] || 100 %> # max connections kept in the pool
@@ -82,13 +102,13 @@ default Tomcat JDBC pool) :
82
102
  maxWait: <%= (( ENV['POOL_TIMEOUT'] || 5.0 ).to_f * 1000).to_i %> # default 30s
83
103
  ```
84
104
 
85
- ActiveRecord-JDBC adapter allows you to lookup connection from JNDI using the
105
+ [ActiveRecord-JDBC][5] adapter allows you to lookup connection from JNDI using the
86
106
  following configuration :
87
107
 
88
108
  ```
89
109
  production:
90
110
  adapter: mysql2
91
- jndi: java:/comp/env/jdbc/BogacsDB
111
+ jndi: java:/comp/env/jdbc/MyDB
92
112
  ```
93
113
 
94
114
  **NOTE:** when using `FalsePool` there's nothing to configure (in *database.yml*)!
@@ -97,7 +117,7 @@ production:
97
117
 
98
118
  This pool allows for a database connection to be "shared" among threads, this is
99
119
  very **dangerous** normally. You will need to understand the underlying driver's
100
- connection whether it is thread-safe.
120
+ connection implementation (whether its thread-safe).
101
121
 
102
122
  You'll need to manually declare blocks that run with a shared connection (**make
103
123
  sure** only read operations happen within such blocks) similar to the built-in
@@ -109,15 +129,19 @@ cache_fetch( [ 'user', user_id ] ) do
109
129
  end
110
130
  ```
111
131
 
112
- The pool will only share connections among such blocks and only if it runs out
113
- of all connections (until than it will always prefer checking out a connection
114
- just like a "regular" pool).
132
+ The pool "might" share connections among such blocks but only if it runs out of
133
+ all connections (pool size is reached), until than it will always prefer checking
134
+ out a connection just like `with_connection` does.
115
135
 
116
- Only tested with ActiveRecord-JDBC-Adapter using the official Postgres' driver.
136
+ Tested with ActiveRecord-JDBC-Adapter using the official Postgres' driver (< 42).
117
137
 
118
138
  ## Copyright
119
139
 
120
- Copyright (c) 2015 [Karol Bucek](http://kares.org).
140
+ Copyright (c) 2018 [Karol Bucek](http://kares.org).
121
141
  See LICENSE (http://en.wikipedia.org/wiki/MIT_License) for details.
122
142
 
123
- [0]: http://res.cloudinary.com/kares/image/upload/c_scale,h_600,w_800/v1406451696/bogacs.jpg
143
+ [0]: http://res.cloudinary.com/kares/image/upload/c_scale,h_600,w_800/v1406451696/bogacs.jpg
144
+ [1]: http://www.rubydoc.info/gems/activerecord-bogacs/
145
+ [2]: http://www.rubydoc.info/gems/activerecord-bogacs/ActiveRecord/Bogacs/DefaultPool
146
+ [3]: http://www.rubydoc.info/gems/activerecord-bogacs/ActiveRecord/Bogacs/FalsePool
147
+ [5]: https://github.com/jruby/activerecord-jdbc-adapter
data/Rakefile CHANGED
@@ -105,9 +105,11 @@ def _download(uri, download_dir, as_file_name)
105
105
  FileUtils.rm_r temp_dir
106
106
  end
107
107
 
108
+ MAVEN_BASE_URL = 'https://repo.maven.apache.org/maven2'
109
+
108
110
  namespace :tomcat do
109
111
 
110
- tomcat_maven_repo = 'http://repo2.maven.org/maven2/org/apache/tomcat'
112
+ tomcat_maven_repo = "#{MAVEN_BASE_URL}/org/apache/tomcat"
111
113
  download_dir = File.expand_path('test/jars', File.dirname(__FILE__))
112
114
  version_default = '7.0.64'
113
115
 
@@ -191,7 +193,7 @@ end
191
193
 
192
194
  namespace :dbcp do # a.k.a DBCP2
193
195
 
194
- commons_repo = 'http://repo2.maven.org/maven2/org/apache/commons'
196
+ commons_repo = "#{MAVEN_BASE_URL}/org/apache/commons"
195
197
  download_dir = File.expand_path('test/jars', File.dirname(__FILE__))
196
198
  version_default = '2.0.1'
197
199
 
@@ -213,7 +215,7 @@ end
213
215
 
214
216
  namespace :c3p0 do
215
217
 
216
- mchange_base_repo = 'http://repo2.maven.org/maven2/com/mchange'
218
+ mchange_base_repo = "#{MAVEN_BASE_URL}/com/mchange"
217
219
  download_dir = File.expand_path('test/jars', File.dirname(__FILE__))
218
220
  c3p0_version = '0.9.5'
219
221
  mchange_commons_version = '0.2.9'
@@ -242,9 +244,9 @@ end
242
244
 
243
245
  namespace :hikari do
244
246
 
245
- hikari_base_repo = 'http://repo2.maven.org/maven2/com/zaxxer'
246
- slf4j_base_repo = 'http://repo2.maven.org/maven2/org/slf4j'
247
- javassist_base_repo = 'http://repo2.maven.org/maven2/org/javassist'
247
+ hikari_base_repo = "#{MAVEN_BASE_URL}/com/zaxxer"
248
+ slf4j_base_repo = "#{MAVEN_BASE_URL}/org/slf4j"
249
+ javassist_base_repo = "#{MAVEN_BASE_URL}/org/javassist"
248
250
  download_dir = File.expand_path('test/jars', File.dirname(__FILE__))
249
251
  hikari_version = '1.4.0'
250
252
  slf4j_version = '1.7.10'
@@ -9,10 +9,9 @@ Gem::Specification.new do |gem|
9
9
  gem.authors = ['Karol Bucek']
10
10
  gem.email = ['self@kares.org']
11
11
  gem.description = %q{Improved ActiveRecord::ConnectionAdapters::ConnectionPool alternatives}
12
- gem.summary = 'Bogacs contains several pool implementations that can be used as a replacement ' <<
13
- "for ActiveRecord's built-in pool, e.g. DefaultPool is an upstream tuned version with an API " <<
14
- 'that is compatible with older AR versions.' <<
15
- "\n\nNOTE: you'll need concurrent-ruby or thread_safe gem."
12
+ gem.summary = 'Bogacs contains several pool implementations that can be used as a replacement ' +
13
+ "for ActiveRecord's built-in pool, e.g. DefaultPool is an upstream tuned version with an API " +
14
+ 'that is compatible with older AR versions.'
16
15
  gem.homepage = "http://github.com/kares/activerecord-bogacs"
17
16
  gem.licenses = ['MIT']
18
17
 
@@ -21,8 +20,9 @@ Gem::Specification.new do |gem|
21
20
  gem.test_files = gem.files.grep(%r{^test/})
22
21
  gem.require_paths = ["lib"]
23
22
 
24
- gem.add_development_dependency 'concurrent-ruby', '>= 0.9' if RUBY_VERSION.index('1.8') != 0
23
+ gem.add_dependency 'activerecord', '< 6' # '>= 4.0' # depends on: concurrent-ruby ~> 1.0, >= 1.0.2
24
+ gem.add_dependency 'concurrent-ruby', '~> 1.0'
25
25
 
26
- gem.add_development_dependency 'rake', '~> 10.3'
26
+ gem.add_development_dependency 'rake'
27
27
  gem.add_development_dependency 'test-unit', '~> 2.5'
28
28
  end
@@ -0,0 +1,10 @@
1
+ module ActiveRecord
2
+ module Bogacs
3
+ autoload :DefaultPool, 'active_record/bogacs/default_pool'
4
+ autoload :FalsePool, 'active_record/bogacs/false_pool'
5
+ autoload :ShareablePool, 'active_record/bogacs/shareable_pool'
6
+ autoload :Reaper, 'active_record/bogacs/reaper'
7
+ autoload :Validator, 'active_record/bogacs/validator'
8
+ end
9
+ autoload :SharedConnection, 'active_record/shared_connection'
10
+ end
@@ -0,0 +1,36 @@
1
+ require 'active_record/version'
2
+
3
+ require 'active_record/connection_adapters/abstract/connection_pool'
4
+
5
+ module ActiveRecord
6
+ module Bogacs
7
+ class ConnectionHandler < ConnectionAdapters::ConnectionHandler
8
+
9
+ if ActiveRecord::VERSION::MAJOR < 5
10
+
11
+ def establish_connection(owner, spec)
12
+ @class_to_pool.clear
13
+ if spec.config[:pool].eql? false
14
+ owner_to_pool[owner.name] = ActiveRecord::Bogacs::FalsePool.new(spec)
15
+ else # super
16
+ owner_to_pool[owner.name] = ActiveRecord::ConnectionAdapters::ConnectionPool.new(spec)
17
+ end
18
+ end
19
+
20
+ else
21
+
22
+ def establish_connection(config) # (spec) in 5.0
23
+ pool = super
24
+ spec = pool.spec
25
+ if spec.config[:pool].eql? false
26
+ owner_to_pool[spec.name] = ActiveRecord::Bogacs::FalsePool.new(spec)
27
+ else
28
+ pool
29
+ end
30
+ end
31
+
32
+ end
33
+
34
+ end
35
+ end
36
+ end