activerecord-jdbc-adapter 1.3.2 → 1.3.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (41) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/Appraisals +6 -5
  4. data/Gemfile +1 -1
  5. data/History.md +19 -0
  6. data/README.md +4 -3
  7. data/gemfiles/rails23.gemfile +1 -1
  8. data/gemfiles/rails30.gemfile +1 -1
  9. data/gemfiles/rails31.gemfile +1 -1
  10. data/gemfiles/rails32.gemfile +1 -1
  11. data/gemfiles/rails32.gemfile.lock +13 -13
  12. data/gemfiles/rails40.gemfile +1 -1
  13. data/gemfiles/rails40.gemfile.lock +6 -9
  14. data/gemfiles/rails41.gemfile +1 -1
  15. data/gemfiles/rails41.gemfile.lock +12 -20
  16. data/lib/arjdbc.rb +1 -9
  17. data/lib/arjdbc/derby/adapter.rb +7 -0
  18. data/lib/arjdbc/h2/adapter.rb +8 -0
  19. data/lib/arjdbc/h2/connection_methods.rb +1 -0
  20. data/lib/arjdbc/hsqldb/adapter.rb +9 -0
  21. data/lib/arjdbc/hsqldb/connection_methods.rb +1 -0
  22. data/lib/arjdbc/jdbc/adapter_java.jar +0 -0
  23. data/lib/arjdbc/mssql/adapter.rb +9 -1
  24. data/lib/arjdbc/mssql/connection_methods.rb +3 -1
  25. data/lib/arjdbc/mysql/connection_methods.rb +3 -2
  26. data/lib/arjdbc/postgresql/adapter.rb +15 -0
  27. data/lib/arjdbc/postgresql/column.rb +1 -1
  28. data/lib/arjdbc/postgresql/connection_methods.rb +8 -5
  29. data/lib/arjdbc/tasks/database_tasks.rb +17 -16
  30. data/lib/arjdbc/tasks/databases.rake +4 -0
  31. data/lib/arjdbc/tasks/databases3.rake +2 -2
  32. data/lib/arjdbc/version.rb +1 -1
  33. data/lib/generators/jdbc/USAGE +2 -3
  34. data/lib/generators/jdbc/jdbc_generator.rb +8 -0
  35. data/lib/jdbc_adapter/rake_tasks.rb +3 -3
  36. data/lib/jdbc_adapter/version.rb +1 -2
  37. data/src/java/arjdbc/jdbc/RubyJdbcConnection.java +30 -23
  38. data/src/java/arjdbc/mssql/MSSQLRubyJdbcConnection.java +19 -1
  39. data/src/java/arjdbc/mysql/MySQLRubyJdbcConnection.java +34 -3
  40. data/src/java/arjdbc/sqlite3/SQLite3RubyJdbcConnection.java +44 -0
  41. metadata +3 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a0441e4d8245ad0891db71d08c1d484304c319ab
4
- data.tar.gz: a60418477bfbd7ad65c2a1517a6c53dec0158cf1
3
+ metadata.gz: afad2b1bdef2eebe2358aa5de395923a306d3485
4
+ data.tar.gz: 467e05b0176a944fa16b3011e902e549629ae222
5
5
  SHA512:
6
- metadata.gz: b0e278d10109cfb86a7eb626dda7ab13f2bd789eb64b9cf71b9f9a8b7d41411a0ec67a9811aa12b0a0fb78490e910292b10c542785045d6346b70ac5f3f2bece
7
- data.tar.gz: 8418e4e1f59bc327a899acd31639bb4f4f607f87fc693add1e056cc230f6a44bce189fc657d01be6d3e4f953f5e8826ac40c1f5d69721e32c7ad488bab9a7456
6
+ metadata.gz: c23850d472d6e6cb0ced6a598ec119cef76c6d1e34257682b37ace3fac27e50488e5bc8629e96bf3d9f7acaafdb0fe22d58179d4a6ad1f9efdf2dccda54abeac
7
+ data.tar.gz: 36092c2ad04aaa6b1f2da21f6dce1f6fe69ee937b02e68a9db189a97506ff5f2f4ae9e6cff69bd8e80d2125f4d6bcc187dc0b96c436789f2f292419a3649e13c
data/.gitignore CHANGED
@@ -29,3 +29,4 @@ jndi_test/jdbc/.bindings
29
29
  .bundle/config
30
30
  gemfiles/.bundle/config
31
31
  Gemfile.lock
32
+ /.idea
data/Appraisals CHANGED
@@ -1,26 +1,27 @@
1
1
  appraise "rails23" do
2
- gem "activerecord", "~> 2.3.18"
2
+ gem "activerecord", "~> 2.3.18", :require => false
3
3
  gem "rails", "~> 2.3.18"
4
4
  end
5
5
 
6
6
  appraise "rails30" do
7
- gem "activerecord", "~> 3.0.20"
7
+ gem "activerecord", "~> 3.0.20", :require => false
8
8
  end
9
9
 
10
10
  appraise "rails31" do
11
- gem "activerecord", "~> 3.1.12"
11
+ gem "activerecord", "~> 3.1.12", :require => false
12
12
  end
13
13
 
14
14
  appraise "rails32" do
15
- gem "activerecord", "~> 3.2.13"
15
+ gem "activerecord", "~> 3.2.15", :require => false
16
16
  end
17
17
 
18
18
  appraise "rails40" do
19
19
  # NOTE: make sure you're using --1.9 with AR-4.0
20
- gem "activerecord", "~> 4.0.0"
20
+ gem "activerecord", "~> 4.0.0", :require => false
21
21
  end
22
22
 
23
23
  appraise "rails41" do
24
24
  # NOTE: make sure you're using --1.9 with AR-4.1
25
+ gem "activerecord", :github => 'rails/rails', :branch => 'master', :require => false
25
26
  gem 'rails', :github => 'rails/rails', :branch => 'master'
26
27
  end
data/Gemfile CHANGED
@@ -1,6 +1,6 @@
1
1
  source "https://rubygems.org"
2
2
 
3
- gem 'activerecord'
3
+ gem 'activerecord', :require => nil
4
4
  gem 'thread_safe', :require => nil
5
5
  if defined?(JRUBY_VERSION) && JRUBY_VERSION < '1.7.0'
6
6
  gem 'jruby-openssl', :platform => :jruby
data/History.md CHANGED
@@ -1,3 +1,22 @@
1
+ ## 1.3.3 (11/12/13)
2
+
3
+ - [mysql] allow encoding to be server-detected (using `encoding: false`)
4
+ due compatibility we still default to `encoding: utf8` if not set (fixes #481)
5
+ - need to match AR 4.0 built-in patterns to re-define (oracle) tasks correctly
6
+ - [postgres] support some of libpg's ENV variables when connecting
7
+ - [derby] allow multiple parallell nested transactions on DERBY
8
+ - [mssql] when using the Microsoft SQL Server driver, fall back to
9
+ rollback_savepoint when release_savepoint is called (#484)
10
+ - [mysql] only kill the connections cancel timer for driver < 5.1.11
11
+ - [sqlite3] work-around driver ignoring passed schema for table (fixes #483)
12
+ - now using explicit adapter classes with H2/HSQLDB
13
+ - [postgres] Add support for array as root element in JSON (#491)
14
+ - [postgres] MRI compat - make sure we have a `query` method (fixes #486)
15
+ - db:structure:load does not create schema for test db (#480)
16
+
17
+ Code Contributors (in no particular order): Glenn Goodrich, Joao Carlos,
18
+ Jason Franklin, Dominique d'Argent, Sean McCarthy, Uwe Kubosch
19
+
1
20
  ## 1.3.2 (10/11/13)
2
21
 
3
22
  - when "pop-ing" current savepoint name - consider open transaction count (#477)
data/README.md CHANGED
@@ -179,14 +179,15 @@ that case simply setup your *Gemfile* as:
179
179
 
180
180
  ```ruby
181
181
  gem 'activerecord', '~> 4.0.0'
182
- gem 'activerecord-jdbc-adapter', '~> 1.3.0', platform: :jruby
182
+ gem 'activerecord-jdbc-adapter', '~> 1.3.2', platform: :jruby
183
183
  ```
184
184
 
185
185
  #### Without Bundler
186
186
 
187
- Install the needed gems with JRuby:
187
+ Install the needed gems with JRuby, for example:
188
188
 
189
- jruby -S gem install activerecord activerecord-jdbc-adapter
189
+ gem install activerecord -v "~> 3.2.10"
190
+ gem install activerecord-jdbc-adapter --ignore-dependencies
190
191
 
191
192
  If you wish to use the adapter for a specific database, you can install it
192
193
  directly and the (jdbc-) driver gem (dependency) will be installed as well:
@@ -13,6 +13,6 @@ gem "bcrypt-ruby", "~> 3.0.0", :require=>nil, :group=>:test
13
13
  gem "mysql2", :require=>nil, :platform=>:mri, :group=>:test
14
14
  gem "pg", :require=>nil, :platform=>:mri, :group=>:test
15
15
  gem "sqlite3", :require=>nil, :platform=>:mri, :group=>:test
16
- gem "activerecord", "~> 2.3.18"
16
+ gem "activerecord", "~> 2.3.18", :require=>false
17
17
  gem "rails", "~> 2.3.18"
18
18
 
@@ -13,5 +13,5 @@ gem "bcrypt-ruby", "~> 3.0.0", :require=>nil, :group=>:test
13
13
  gem "mysql2", :require=>nil, :platform=>:mri, :group=>:test
14
14
  gem "pg", :require=>nil, :platform=>:mri, :group=>:test
15
15
  gem "sqlite3", :require=>nil, :platform=>:mri, :group=>:test
16
- gem "activerecord", "~> 3.0.20"
16
+ gem "activerecord", "~> 3.0.20", :require=>false
17
17
 
@@ -13,5 +13,5 @@ gem "bcrypt-ruby", "~> 3.0.0", :require=>nil, :group=>:test
13
13
  gem "mysql2", :require=>nil, :platform=>:mri, :group=>:test
14
14
  gem "pg", :require=>nil, :platform=>:mri, :group=>:test
15
15
  gem "sqlite3", :require=>nil, :platform=>:mri, :group=>:test
16
- gem "activerecord", "~> 3.1.12"
16
+ gem "activerecord", "~> 3.1.12", :require=>false
17
17
 
@@ -13,5 +13,5 @@ gem "bcrypt-ruby", "~> 3.0.0", :require=>nil, :group=>:test
13
13
  gem "mysql2", :require=>nil, :platform=>:mri, :group=>:test
14
14
  gem "pg", :require=>nil, :platform=>:mri, :group=>:test
15
15
  gem "sqlite3", :require=>nil, :platform=>:mri, :group=>:test
16
- gem "activerecord", "~> 3.2.13"
16
+ gem "activerecord", "~> 3.2.15", :require=>false
17
17
 
@@ -1,27 +1,27 @@
1
1
  GEM
2
2
  remote: https://rubygems.org/
3
3
  specs:
4
- activemodel (3.2.14)
5
- activesupport (= 3.2.14)
4
+ activemodel (3.2.15)
5
+ activesupport (= 3.2.15)
6
6
  builder (~> 3.0.0)
7
- activerecord (3.2.14)
8
- activemodel (= 3.2.14)
9
- activesupport (= 3.2.14)
7
+ activerecord (3.2.15)
8
+ activemodel (= 3.2.15)
9
+ activesupport (= 3.2.15)
10
10
  arel (~> 3.0.2)
11
11
  tzinfo (~> 0.3.29)
12
- activesupport (3.2.14)
12
+ activesupport (3.2.15)
13
13
  i18n (~> 0.6, >= 0.6.4)
14
14
  multi_json (~> 1.0)
15
15
  appraisal (0.5.2)
16
16
  bundler
17
17
  rake
18
18
  arel (3.0.2)
19
- atomic (1.1.10)
20
- atomic (1.1.10-java)
19
+ atomic (1.1.14)
20
+ atomic (1.1.14-java)
21
21
  bcrypt-ruby (3.0.1)
22
22
  bcrypt-ruby (3.0.1-java)
23
23
  builder (3.0.4)
24
- i18n (0.6.4)
24
+ i18n (0.6.5)
25
25
  metaclass (0.0.1)
26
26
  mocha (0.13.3)
27
27
  metaclass (~> 0.0.1)
@@ -37,18 +37,18 @@ GEM
37
37
  test-unit (2.5.4)
38
38
  test-unit-context (0.3.1)
39
39
  test-unit (>= 2.4.0)
40
- thread_safe (0.1.2)
40
+ thread_safe (0.1.3)
41
41
  atomic
42
- thread_safe (0.1.2-java)
42
+ thread_safe (0.1.3-java)
43
43
  atomic
44
- tzinfo (0.3.37)
44
+ tzinfo (0.3.38)
45
45
 
46
46
  PLATFORMS
47
47
  java
48
48
  ruby
49
49
 
50
50
  DEPENDENCIES
51
- activerecord (~> 3.2.13)
51
+ activerecord (~> 3.2.15)
52
52
  appraisal
53
53
  bcrypt-ruby (~> 3.0.0)
54
54
  mocha (~> 0.13.1)
@@ -13,5 +13,5 @@ gem "bcrypt-ruby", "~> 3.0.0", :require=>nil, :group=>:test
13
13
  gem "mysql2", :require=>nil, :platform=>:mri, :group=>:test
14
14
  gem "pg", :require=>nil, :platform=>:mri, :group=>:test
15
15
  gem "sqlite3", :require=>nil, :platform=>:mri, :group=>:test
16
- gem "activerecord", "~> 4.0.0"
16
+ gem "activerecord", "~> 4.0.0", :require=>false
17
17
 
@@ -19,18 +19,16 @@ GEM
19
19
  appraisal (0.5.2)
20
20
  bundler
21
21
  rake
22
- arel (4.0.0)
23
- atomic (1.1.10)
24
- atomic (1.1.10-java)
25
- bcrypt-ruby (3.0.1)
22
+ arel (4.0.1)
23
+ atomic (1.1.14-java)
26
24
  bcrypt-ruby (3.0.1-java)
27
25
  builder (3.1.4)
28
- i18n (0.6.4)
26
+ i18n (0.6.5)
29
27
  metaclass (0.0.1)
30
28
  minitest (4.7.5)
31
29
  mocha (0.13.3)
32
30
  metaclass (~> 0.0.1)
33
- multi_json (1.7.7)
31
+ multi_json (1.8.2)
34
32
  rake (10.1.0)
35
33
  simplecov (0.7.1)
36
34
  multi_json (~> 1.0)
@@ -39,13 +37,12 @@ GEM
39
37
  test-unit (2.5.4)
40
38
  test-unit-context (0.3.1)
41
39
  test-unit (>= 2.4.0)
42
- thread_safe (0.1.0)
40
+ thread_safe (0.1.3-java)
43
41
  atomic
44
- tzinfo (0.3.37)
42
+ tzinfo (0.3.38)
45
43
 
46
44
  PLATFORMS
47
45
  java
48
- ruby
49
46
 
50
47
  DEPENDENCIES
51
48
  activerecord (~> 4.0.0)
@@ -2,7 +2,6 @@
2
2
 
3
3
  source "https://rubygems.org"
4
4
 
5
- gem "activerecord"
6
5
  gem "thread_safe", :require=>nil
7
6
  gem "rake", :require=>nil
8
7
  gem "appraisal", :require=>nil
@@ -14,5 +13,6 @@ gem "bcrypt-ruby", "~> 3.0.0", :require=>nil, :group=>:test
14
13
  gem "mysql2", :require=>nil, :platform=>:mri, :group=>:test
15
14
  gem "pg", :require=>nil, :platform=>:mri, :group=>:test
16
15
  gem "sqlite3", :require=>nil, :platform=>:mri, :group=>:test
16
+ gem "activerecord", :github=>"rails/rails", :branch=>"master", :require=>false
17
17
  gem "rails", :github=>"rails/rails", :branch=>"master"
18
18
 
@@ -1,6 +1,6 @@
1
1
  GIT
2
2
  remote: git://github.com/rails/rails.git
3
- revision: 0941a109fda0a96403fc9b51249ced7b7ca63447
3
+ revision: 094e31ce6700993759c6f36db52afb0a43bfa71f
4
4
  branch: master
5
5
  specs:
6
6
  actionmailer (4.1.0.beta)
@@ -33,6 +33,7 @@ GIT
33
33
  actionmailer (= 4.1.0.beta)
34
34
  actionpack (= 4.1.0.beta)
35
35
  actionview (= 4.1.0.beta)
36
+ activemodel (= 4.1.0.beta)
36
37
  activerecord (= 4.1.0.beta)
37
38
  activesupport (= 4.1.0.beta)
38
39
  bundler (>= 1.3.0, < 2.0)
@@ -50,28 +51,23 @@ GEM
50
51
  appraisal (0.5.2)
51
52
  bundler
52
53
  rake
53
- arel (4.0.0)
54
- atomic (1.1.13)
55
- atomic (1.1.13-java)
56
- bcrypt-ruby (3.0.1)
54
+ arel (4.0.1)
55
+ atomic (1.1.14-java)
57
56
  bcrypt-ruby (3.0.1-java)
58
57
  builder (3.1.4)
59
58
  erubis (2.7.0)
60
59
  hike (1.2.3)
61
60
  i18n (0.6.5)
62
- json (1.8.0)
63
- json (1.8.0-java)
61
+ json (1.8.1-java)
64
62
  mail (2.5.4)
65
63
  mime-types (~> 1.16)
66
64
  treetop (~> 1.4.8)
67
65
  metaclass (0.0.1)
68
- mime-types (1.24)
69
- minitest (5.0.6)
66
+ mime-types (1.25)
67
+ minitest (5.0.8)
70
68
  mocha (0.13.3)
71
69
  metaclass (~> 0.0.1)
72
- multi_json (1.7.9)
73
- mysql2 (0.3.13)
74
- pg (0.16.0)
70
+ multi_json (1.8.2)
75
71
  polyglot (0.3.3)
76
72
  rack (1.5.2)
77
73
  rack-test (0.6.2)
@@ -86,31 +82,27 @@ GEM
86
82
  multi_json (~> 1.0)
87
83
  rack (~> 1.0)
88
84
  tilt (~> 1.1, != 1.3.0)
89
- sprockets-rails (2.0.0)
85
+ sprockets-rails (2.0.1)
90
86
  actionpack (>= 3.0)
91
87
  activesupport (>= 3.0)
92
88
  sprockets (~> 2.8)
93
- sqlite3 (1.3.8)
94
89
  test-unit (2.5.4)
95
90
  test-unit-context (0.3.1)
96
91
  test-unit (>= 2.4.0)
97
92
  thor (0.18.1)
98
- thread_safe (0.1.2)
99
- atomic
100
- thread_safe (0.1.2-java)
93
+ thread_safe (0.1.3-java)
101
94
  atomic
102
95
  tilt (1.4.1)
103
96
  treetop (1.4.15)
104
97
  polyglot
105
98
  polyglot (>= 0.3.1)
106
- tzinfo (0.3.37)
99
+ tzinfo (0.3.38)
107
100
 
108
101
  PLATFORMS
109
102
  java
110
- ruby
111
103
 
112
104
  DEPENDENCIES
113
- activerecord
105
+ activerecord!
114
106
  appraisal
115
107
  bcrypt-ruby (~> 3.0.0)
116
108
  mocha (~> 0.13.1)
data/lib/arjdbc.rb CHANGED
@@ -1,15 +1,7 @@
1
1
  if defined?(JRUBY_VERSION)
2
2
  begin
3
3
  require 'active_record/version'
4
- if ActiveRecord::VERSION::MAJOR < 2
5
- if defined?(RAILS_CONNECTION_ADAPTERS)
6
- RAILS_CONNECTION_ADAPTERS << %q(jdbc)
7
- else
8
- RAILS_CONNECTION_ADAPTERS = %w(jdbc)
9
- end
10
- else
11
- require 'active_record'
12
- end
4
+ require 'active_record'
13
5
  rescue LoadError => e
14
6
  warn "activerecord-jdbc-adapter requires the activerecord gem at runtime"
15
7
  raise e
@@ -147,6 +147,13 @@ module ArJdbc
147
147
  NATIVE_DATABASE_TYPES
148
148
  end
149
149
 
150
+ # Ensure the savepoint name is unused before creating it.
151
+ # @override
152
+ def create_savepoint(name = current_savepoint_name(true))
153
+ release_savepoint(name) if @connection.marked_savepoint_names.include?(name)
154
+ super(name)
155
+ end
156
+
150
157
  # @override
151
158
  def quote(value, column = nil)
152
159
  return value.quoted_id if value.respond_to?(:quoted_id)
@@ -261,3 +261,11 @@ module ArJdbc
261
261
 
262
262
  end
263
263
  end
264
+
265
+ module ActiveRecord::ConnectionAdapters
266
+
267
+ class H2Adapter < JdbcAdapter
268
+ include ArJdbc::H2
269
+ end
270
+
271
+ end
@@ -16,6 +16,7 @@ ArJdbc::ConnectionMethods.module_eval do
16
16
  end
17
17
  config[:driver] ||= defined?(::Jdbc::H2.driver_name) ? ::Jdbc::H2.driver_name : 'org.h2.Driver'
18
18
  config[:adapter_spec] ||= ::ArJdbc::H2
19
+ config[:adapter_class] = ActiveRecord::ConnectionAdapters::H2Adapter unless config.key?(:adapter_class)
19
20
 
20
21
  embedded_driver(config)
21
22
  end
@@ -275,3 +275,12 @@ module ArJdbc
275
275
 
276
276
  end
277
277
  end
278
+
279
+ module ActiveRecord::ConnectionAdapters
280
+
281
+ class HsqldbAdapter < JdbcAdapter
282
+ include ArJdbc::HSQLDB
283
+ end
284
+
285
+ end
286
+
@@ -16,6 +16,7 @@ ArJdbc::ConnectionMethods.module_eval do
16
16
  end
17
17
  config[:driver] ||= defined?(::Jdbc::HSQLDB.driver_name) ? ::Jdbc::HSQLDB.driver_name : 'org.hsqldb.jdbcDriver'
18
18
  config[:adapter_spec] ||= ::ArJdbc::HSQLDB
19
+ config[:adapter_class] = ActiveRecord::ConnectionAdapters::HsqldbAdapter unless config.key?(:adapter_class)
19
20
  config[:connection_alive_sql] ||= 'CALL PI()' # does not like 'SELECT 1'
20
21
 
21
22
  embedded_driver(config)
Binary file
@@ -11,7 +11,6 @@ module ArJdbc
11
11
  module MSSQL
12
12
  include LimitHelpers
13
13
  include Utils
14
-
15
14
  include ExplainSupport
16
15
 
17
16
  # @private
@@ -578,6 +577,15 @@ module ArJdbc
578
577
  end
579
578
  end
580
579
 
580
+ # @override
581
+ def release_savepoint(name = current_savepoint_name)
582
+ if @connection.jtds_driver?
583
+ @connection.release_savepoint(name)
584
+ else # MS invented it's "own" way
585
+ @connection.rollback_savepoint(name)
586
+ end
587
+ end
588
+
581
589
  private
582
590
 
583
591
  def _execute(sql, name = nil)
@@ -5,6 +5,8 @@ ArJdbc::ConnectionMethods.module_eval do
5
5
  # If you'd like to use the "official" MS's SQL-JDBC driver, it's preferable
6
6
  # to use the {#sqlserver_connection} method (set `adapter: sqlserver`).
7
7
  def mssql_connection(config)
8
+ # NOTE: this detection ain't perfect and is only meant as a temporary hack
9
+ # users will get a deprecation eventually to use `adapter: sqlserver` ...
8
10
  if config[:driver] =~ /SQLServerDriver$/ || config[:url] =~ /^jdbc:sqlserver:/
9
11
  return sqlserver_connection(config)
10
12
  end
@@ -68,4 +70,4 @@ ArJdbc::ConnectionMethods.module_eval do
68
70
  end
69
71
  alias_method :jdbcsqlserver_connection, :sqlserver_connection
70
72
 
71
- end
73
+ end
@@ -25,8 +25,9 @@ ArJdbc::ConnectionMethods.module_eval do
25
25
  properties = ( config[:properties] ||= {} )
26
26
  properties['zeroDateTimeBehavior'] ||= 'convertToNull'
27
27
  properties['jdbcCompliantTruncation'] ||= 'false'
28
- properties['useUnicode'] ||= 'true'
29
- properties['characterEncoding'] = config[:encoding] || 'utf8'
28
+ properties['useUnicode'] = 'true' unless properties.key?('useUnicode') # otherwise platform default
29
+ encoding = config.key?(:encoding) ? config[:encoding] : 'utf8'
30
+ properties['characterEncoding'] = encoding if encoding
30
31
 
31
32
  jdbc_connection(config)
32
33
  end
@@ -552,6 +552,18 @@ module ArJdbc
552
552
  end
553
553
  end
554
554
 
555
+ # @note Only for "better" AR 4.0 compatibility.
556
+ # @private
557
+ def query(sql, name = nil)
558
+ log(sql, name) do
559
+ result = []
560
+ @connection.execute_query_raw(sql, nil) do |*values|
561
+ result << values
562
+ end
563
+ result
564
+ end
565
+ end
566
+
555
567
  # Returns an array of schema names.
556
568
  def schema_names
557
569
  select_values(
@@ -817,6 +829,9 @@ module ArJdbc
817
829
  if AR4_COMPAT && column.array? # will be always falsy in AR < 4.0
818
830
  column_class = ::ActiveRecord::ConnectionAdapters::PostgreSQLColumn
819
831
  "'#{column_class.array_to_string(value, column, self).gsub(/'/, "''")}'"
832
+ elsif column.type == :json # only in AR-4.0
833
+ column_class = ::ActiveRecord::ConnectionAdapters::PostgreSQLColumn
834
+ super(column_class.json_to_string(value), column)
820
835
  else super
821
836
  end
822
837
  when Hash
@@ -362,7 +362,7 @@ module ArJdbc
362
362
  end
363
363
 
364
364
  def json_to_string(object)
365
- if Hash === object
365
+ if Hash === object || Array === object
366
366
  ActiveSupport::JSON.encode(object)
367
367
  else
368
368
  object
@@ -6,21 +6,24 @@ ArJdbc::ConnectionMethods.module_eval do
6
6
  rescue LoadError # assuming driver.jar is on the class-path
7
7
  end
8
8
 
9
- host = config[:host] ||= ( config[:hostaddr] || 'localhost' )
10
- port = config[:port] ||= 5432
11
- database = config[:database] || config[:dbname]
9
+ host = config[:host] ||= ( config[:hostaddr] || ENV['PGHOST'] || 'localhost' )
10
+ port = config[:port] ||= ( ENV['PGPORT'] || 5432 )
11
+ database = config[:database] || config[:dbname] || ENV['PGDATABASE']
12
12
 
13
13
  config[:url] ||= "jdbc:postgresql://#{host}:#{port}/#{database}"
14
14
  config[:url] << config[:pg_params] if config[:pg_params] # should go away
15
15
 
16
- config[:username] ||= config[:user] || ENV_JAVA['user.name']
16
+ config[:username] ||= ( config[:user] || ENV['PGUSER'] || ENV_JAVA['user.name'] )
17
+ config[:password] ||= ENV['PGPASSWORD'] unless config.key?(:password)
17
18
  properties = ( config[:properties] ||= {} )
18
19
  # PG :connect_timeout - maximum time to wait for connection to succeed
19
- if connect_timeout = config[:connect_timeout]
20
+ if connect_timeout = ( config[:connect_timeout] || ENV['PGCONNECT_TIMEOUT'] )
20
21
  properties['socketTimeout'] ||= connect_timeout
21
22
  # NOTE: maybe set options['loginTimeout'] as well?
22
23
  end
23
24
  sslmode = config.key?(:sslmode) ? config[:sslmode] : config[:requiressl]
25
+ # NOTE: makes not much sense since this needs some JVM options :
26
+ # sslmode = ENV['PGSSLMODE'] || ENV['PGREQUIRESSL'] if sslmode.nil?
24
27
  unless sslmode.nil? # PG :sslmode - disable|allow|prefer|require
25
28
  # JRuby/JVM needs to be started with :
26
29
  # -Djavax.net.ssl.trustStore=mystore -Djavax.net.ssl.trustStorePassword=...
@@ -1,14 +1,14 @@
1
1
  module ArJdbc
2
2
  module Tasks
3
-
3
+
4
4
  if defined? ActiveRecord::Tasks::DatabaseTasks # AR-4.x
5
-
5
+
6
6
  def self.register_tasks(pattern, task)
7
7
  ActiveRecord::Tasks::DatabaseTasks.register_task(pattern, task)
8
8
  end
9
-
9
+
10
10
  else
11
-
11
+
12
12
  @@tasks = {}
13
13
 
14
14
  def self.register_tasks(pattern, task)
@@ -20,9 +20,9 @@ module ArJdbc
20
20
  key = @@tasks.keys.detect { |pattern| adapter[pattern] }
21
21
  ( @@tasks[key] || JdbcDatabaseTasks ).new(config)
22
22
  end
23
-
23
+
24
24
  end
25
-
25
+
26
26
  require 'arjdbc/tasks/jdbc_database_tasks'
27
27
  require 'arjdbc/tasks/db2_database_tasks'
28
28
  require 'arjdbc/tasks/derby_database_tasks'
@@ -30,21 +30,22 @@ module ArJdbc
30
30
  require 'arjdbc/tasks/hsqldb_database_tasks'
31
31
  require 'arjdbc/tasks/mssql_database_tasks'
32
32
  require 'arjdbc/tasks/oracle_database_tasks'
33
-
33
+
34
34
  # re-invent built-in (but deprecated on 4.0) tasks :
35
- register_tasks(/(mssql|sqlserver)/i, MSSQLDatabaseTasks)
36
- register_tasks(/(oci|oracle)/i, OracleDatabaseTasks)
35
+ register_tasks(/sqlserver/, MSSQLDatabaseTasks)
36
+ register_tasks(/(oci|oracle)/, OracleDatabaseTasks)
37
+ register_tasks(/mssql/, MSSQLDatabaseTasks) # (built-in) alias
37
38
  # tasks for custom (JDBC) adapters :
38
- register_tasks(/db2/i, DB2DatabaseTasks)
39
- register_tasks(/derby/i, DerbyDatabaseTasks)
40
- register_tasks(/h2/i, H2DatabaseTasks)
41
- register_tasks(/hsqldb/i, HSQLDBDatabaseTasks)
39
+ register_tasks(/db2/, DB2DatabaseTasks)
40
+ register_tasks(/derby/, DerbyDatabaseTasks)
41
+ register_tasks(/h2/, H2DatabaseTasks)
42
+ register_tasks(/hsqldb/, HSQLDBDatabaseTasks)
42
43
  # (default) generic JDBC task :
43
- register_tasks(/^jdbc$/i, JdbcDatabaseTasks)
44
-
44
+ register_tasks(/^jdbc$/, JdbcDatabaseTasks)
45
+
45
46
  # NOTE: no need to register "built-in" adapters such as MySQL
46
47
  # - on 4.0 these are registered and will be instantiated
47
48
  # - while on 2.3/3.x we keep the AR built-in task behavior
48
-
49
+
49
50
  end
50
51
  end
@@ -41,6 +41,10 @@ namespace :db do
41
41
  defined?(Rails.env) ? Rails.env : ( RAILS_ENV || 'development' )
42
42
  end
43
43
 
44
+ if defined? adapt_jdbc_config
45
+ puts "ArJdbc: double loading #{__FILE__} please delete lib/rasks/jdbc.rake if present!"
46
+ end
47
+
44
48
  def adapt_jdbc_config(config)
45
49
  return config unless config['adapter']
46
50
  config.merge 'adapter' => config['adapter'].sub(/^jdbc/, '')
@@ -118,7 +118,7 @@ namespace :db do
118
118
  end
119
119
 
120
120
  redefine_task :load do
121
- config = ActiveRecord::Base.configurations[rails_env] # current_config
121
+ config = current_config
122
122
  filename = structure_sql
123
123
 
124
124
  case config['adapter']
@@ -200,4 +200,4 @@ namespace :db do
200
200
 
201
201
  end
202
202
 
203
- end
203
+ end
@@ -1,5 +1,5 @@
1
1
  module ArJdbc
2
- VERSION = "1.3.2"
2
+ VERSION = "1.3.3"
3
3
  # @deprecated
4
4
  module Version
5
5
  # @private 1.2.x compatibility
@@ -1,10 +1,9 @@
1
1
  Description:
2
- Creates stubs that ensure activerecord-jdbc is bootstrapped in
3
- your Rails application.
2
+ Creates stubs that ensure AR-JDBC is bootstrapped in your Rails application.
4
3
 
5
4
  Example:
6
5
  ./script/generate jdbc
7
6
 
8
7
  This will create:
9
8
  config/initializers/jdbc.rb
10
- lib/tasks/jdbc.rake
9
+ lib/tasks/jdbc.rake
@@ -6,4 +6,12 @@ class JdbcGenerator < Rails::Generators::Base
6
6
  def create_jdbc_files
7
7
  directory '.', '.'
8
8
  end
9
+
10
+ def self.desc(description=nil)
11
+ return super if description
12
+ "Description:\n" <<
13
+ " Creates stubs that ensure AR-JDBC is bootstrapped in your Rails application.\n" <<
14
+ " NOTE: you should not need this if you're on Rails >= 3.0 (using Bundler) ..."
15
+ end
16
+
9
17
  end
@@ -1,3 +1,3 @@
1
- warn "DEPRECATED: require 'arjdbc/rake_tasks' instead of 'jdbc_adapter/rake_tasks'."
2
- require 'arjdbc/jdbc/rake_tasks'
3
-
1
+ # @deprecated
2
+ warn "DEPRECATED: load 'arjdbc/tasks.rb' instead of 'jdbc_adapter/rake_tasks.rb'"
3
+ require 'arjdbc/tasks.rb'
@@ -1,3 +1,2 @@
1
1
  warn "DEPRECATED: require 'arjdbc/version' instead of 'jdbc_adapter/version'."
2
- require 'arjdbc/version'
3
-
2
+ require 'arjdbc/version'
@@ -991,32 +991,37 @@ public class RubyJdbcConnection extends RubyObject {
991
991
  return context.getRuntime().newArray(primaryKeys);
992
992
  }
993
993
 
994
- private static final int PRIMARY_KEYS_COLUMN_NAME = 4;
994
+ protected static final int PRIMARY_KEYS_COLUMN_NAME = 4;
995
995
 
996
+ @Deprecated // NOTE: this should go private
996
997
  protected List<RubyString> primaryKeys(final ThreadContext context, final String tableName) {
997
998
  return withConnection(context, new Callable<List<RubyString>>() {
998
999
  public List<RubyString> call(final Connection connection) throws SQLException {
999
- final Ruby runtime = context.getRuntime();
1000
1000
  final String _tableName = caseConvertIdentifierForJdbc(connection, tableName);
1001
- final DatabaseMetaData metaData = connection.getMetaData();
1002
- ResultSet resultSet = null;
1003
- final List<RubyString> keyNames = new ArrayList<RubyString>();
1004
- try {
1005
- TableName components = extractTableName(connection, null, _tableName);
1006
- resultSet = metaData.getPrimaryKeys(components.catalog, components.schema, components.name);
1007
-
1008
- while (resultSet.next()) {
1009
- String columnName = resultSet.getString(PRIMARY_KEYS_COLUMN_NAME);
1010
- columnName = caseConvertIdentifierForRails(connection, columnName);
1011
- keyNames.add( RubyString.newUnicodeString(runtime, columnName) );
1012
- }
1013
- }
1014
- finally { close(resultSet); }
1015
- return keyNames;
1001
+ final TableName table = extractTableName(connection, null, _tableName);
1002
+ return primaryKeys(context, connection, table);
1016
1003
  }
1017
1004
  });
1018
1005
  }
1019
1006
 
1007
+ protected List<RubyString> primaryKeys(final ThreadContext context,
1008
+ final Connection connection, final TableName table) throws SQLException {
1009
+ final DatabaseMetaData metaData = connection.getMetaData();
1010
+ ResultSet resultSet = null;
1011
+ final List<RubyString> keyNames = new ArrayList<RubyString>();
1012
+ try {
1013
+ resultSet = metaData.getPrimaryKeys(table.catalog, table.schema, table.name);
1014
+ final Ruby runtime = context.getRuntime();
1015
+ while ( resultSet.next() ) {
1016
+ String columnName = resultSet.getString(PRIMARY_KEYS_COLUMN_NAME);
1017
+ columnName = caseConvertIdentifierForRails(connection, columnName);
1018
+ keyNames.add( RubyString.newUnicodeString(runtime, columnName) );
1019
+ }
1020
+ }
1021
+ finally { close(resultSet); }
1022
+ return keyNames;
1023
+ }
1024
+
1020
1025
  @JRubyMethod(name = "tables")
1021
1026
  public IRubyObject tables(ThreadContext context) {
1022
1027
  return tables(context, null, null, null, TABLE_TYPE);
@@ -1156,13 +1161,15 @@ public class RubyJdbcConnection extends RubyObject {
1156
1161
 
1157
1162
  String _tableName = caseConvertIdentifierForJdbc(connection, tableName);
1158
1163
  String _schemaName = caseConvertIdentifierForJdbc(connection, schemaName);
1159
- final DatabaseMetaData metaData = connection.getMetaData();
1164
+ final TableName table = extractTableName(connection, _schemaName, _tableName);
1165
+
1166
+ final List<RubyString> primaryKeys = primaryKeys(context, connection, table);
1160
1167
 
1161
- final List<RubyString> primaryKeys = primaryKeys(context, _tableName);
1162
1168
  ResultSet indexInfoSet = null;
1163
1169
  final List<IRubyObject> indexes = new ArrayList<IRubyObject>();
1164
1170
  try {
1165
- indexInfoSet = metaData.getIndexInfo(null, _schemaName, _tableName, false, true);
1171
+ final DatabaseMetaData metaData = connection.getMetaData();
1172
+ indexInfoSet = metaData.getIndexInfo(table.catalog, table.schema, table.name, false, true);
1166
1173
  String currentIndex = null;
1167
1174
 
1168
1175
  while ( indexInfoSet.next() ) {
@@ -3445,15 +3452,15 @@ public class RubyJdbcConnection extends RubyObject {
3445
3452
  name = nameParts[2];
3446
3453
  }
3447
3454
 
3448
- if (schema != null) {
3455
+ if ( schema != null ) {
3449
3456
  schema = caseConvertIdentifierForJdbc(connection, schema);
3450
3457
  }
3451
3458
  name = caseConvertIdentifierForJdbc(connection, name);
3452
3459
 
3453
- if (schema != null && ! databaseSupportsSchemas()) {
3460
+ if ( schema != null && ! databaseSupportsSchemas() ) {
3454
3461
  catalog = schema;
3455
3462
  }
3456
- if (catalog == null) catalog = connection.getCatalog();
3463
+ if ( catalog == null ) catalog = connection.getCatalog();
3457
3464
 
3458
3465
  return new TableName(catalog, schema, name);
3459
3466
  }
@@ -25,6 +25,9 @@
25
25
  ***** END LICENSE BLOCK *****/
26
26
  package arjdbc.mssql;
27
27
 
28
+ import arjdbc.jdbc.Callable;
29
+ import arjdbc.jdbc.RubyJdbcConnection;
30
+
28
31
  import java.sql.Connection;
29
32
  import java.sql.DatabaseMetaData;
30
33
  import java.sql.ResultSet;
@@ -47,7 +50,7 @@ import org.jruby.util.ByteList;
47
50
  *
48
51
  * @author nicksieger
49
52
  */
50
- public class MSSQLRubyJdbcConnection extends arjdbc.jdbc.RubyJdbcConnection {
53
+ public class MSSQLRubyJdbcConnection extends RubyJdbcConnection {
51
54
 
52
55
  protected MSSQLRubyJdbcConnection(Ruby runtime, RubyClass metaClass) {
53
56
  super(runtime, metaClass);
@@ -162,4 +165,19 @@ public class MSSQLRubyJdbcConnection extends arjdbc.jdbc.RubyJdbcConnection {
162
165
  return columns;
163
166
  }
164
167
 
168
+ // internal helper not meant as a "public" API - used in one place thus every
169
+ @JRubyMethod(name = "jtds_driver?")
170
+ public IRubyObject jtds_driver_p(final ThreadContext context) throws SQLException {
171
+ // "jTDS Type 4 JDBC Driver for MS SQL Server and Sybase"
172
+ // SQLJDBC: "Microsoft JDBC Driver 4.0 for SQL Server"
173
+ return withConnection(context, new Callable<IRubyObject>() {
174
+ // NOTE: only used in one place for now (on release_savepoint) ...
175
+ // might get optimized to only happen once since driver won't change
176
+ public IRubyObject call(final Connection connection) throws SQLException {
177
+ final String driver = connection.getMetaData().getDriverName();
178
+ return context.getRuntime().newBoolean( driver.indexOf("jTDS") >= 0 );
179
+ }
180
+ });
181
+ }
182
+
165
183
  }
@@ -41,6 +41,8 @@ import java.sql.Types;
41
41
  import java.util.ArrayList;
42
42
  import java.util.List;
43
43
  import java.util.TimeZone;
44
+ import java.util.regex.Matcher;
45
+ import java.util.regex.Pattern;
44
46
 
45
47
  import org.jruby.Ruby;
46
48
  import org.jruby.RubyClass;
@@ -232,17 +234,46 @@ public class MySQLRubyJdbcConnection extends RubyJdbcConnection {
232
234
  @Override
233
235
  protected Connection newConnection() throws RaiseException, SQLException {
234
236
  final Connection connection = super.newConnection();
235
- killCancelTimer(connection);
237
+ if ( doKillCancelTimer(connection) ) killCancelTimer(connection);
236
238
  return connection;
237
239
  }
238
240
 
241
+ private static Boolean killCancelTimer;
242
+ static {
243
+ final String killTimer = System.getProperty("arjdbc.mysql.kill_cancel_timer");
244
+ if ( killTimer != null ) killCancelTimer = Boolean.parseBoolean(killTimer);
245
+ }
246
+
247
+ private static boolean doKillCancelTimer(final Connection connection) throws SQLException {
248
+ if ( killCancelTimer == null ) {
249
+ synchronized (MySQLRubyJdbcConnection.class) {
250
+ final String version = connection.getMetaData().getDriverVersion();
251
+ if ( killCancelTimer == null ) {
252
+ String regex = "mysql\\-connector\\-java-(\\d)\\.(\\d)\\.(\\d+)";
253
+ Matcher match = Pattern.compile(regex).matcher(version);
254
+ if ( match.find() ) {
255
+ final int major = Integer.parseInt( match.group(1) );
256
+ final int minor = Integer.parseInt( match.group(2) );
257
+ if ( major < 5 || ( major == 5 && minor <= 1 ) ) {
258
+ final int patch = Integer.parseInt( match.group(3) );
259
+ killCancelTimer = patch < 11;
260
+ }
261
+ }
262
+ else {
263
+ killCancelTimer = Boolean.FALSE;
264
+ }
265
+ }
266
+ }
267
+ }
268
+ return killCancelTimer;
269
+ }
270
+
239
271
  /**
240
272
  * HACK HACK HACK See http://bugs.mysql.com/bug.php?id=36565
241
273
  * MySQL's statement cancel timer can cause memory leaks, so cancel it
242
274
  * if we loaded MySQL classes from the same class-loader as JRuby
243
275
  *
244
- * NOTE: this will likely do nothing on a recent driver esp. since MySQL's
245
- * Connector/J supports JDBC 4.0 (Java 6+) which we now require at minimum
276
+ * NOTE: MySQL Connector/J 5.1.11 (2010-01-21) fixed the issue !
246
277
  */
247
278
  private void killCancelTimer(final Connection connection) {
248
279
  if (connection.getClass().getClassLoader() == getRuntime().getJRubyClassLoader()) {
@@ -116,6 +116,50 @@ public class SQLite3RubyJdbcConnection extends RubyJdbcConnection {
116
116
  return statement;
117
117
  }
118
118
 
119
+ @Override
120
+ protected IRubyObject indexes(final ThreadContext context, String tableName, final String name, String schemaName) {
121
+ int i = -1;
122
+ if ( tableName != null ) i = tableName.indexOf('.');
123
+ if ( i > 0 && schemaName == null ) {
124
+ schemaName = tableName.substring(0, i);
125
+ tableName = tableName.substring(i + 1);
126
+ }
127
+ return super.indexes(context, tableName, name, schemaName);
128
+ }
129
+
130
+ @Override
131
+ protected TableName extractTableName(
132
+ final Connection connection, String catalog, String schema,
133
+ final String tableName) throws IllegalArgumentException, SQLException {
134
+
135
+ final String[] nameParts = tableName.split("\\.");
136
+ if ( nameParts.length > 3 ) {
137
+ throw new IllegalArgumentException("table name: " + tableName + " should not contain more than 2 '.'");
138
+ }
139
+
140
+ String name = tableName;
141
+
142
+ if ( nameParts.length == 2 ) {
143
+ schema = nameParts[0];
144
+ name = nameParts[1];
145
+ }
146
+ else if ( nameParts.length == 3 ) {
147
+ catalog = nameParts[0];
148
+ schema = nameParts[1];
149
+ name = nameParts[2];
150
+ }
151
+
152
+ name = caseConvertIdentifierForJdbc(connection, name);
153
+
154
+ if ( schema != null ) {
155
+ schema = caseConvertIdentifierForJdbc(connection, schema);
156
+ // NOTE: hack to work-around SQLite JDBC ignoring schema :
157
+ return new TableName(catalog, null, schema + '.' + name);
158
+ }
159
+
160
+ return new TableName(catalog, schema, name);
161
+ }
162
+
119
163
  @Override
120
164
  protected IRubyObject jdbcToRuby(final ThreadContext context,
121
165
  final Ruby runtime, final int column, int type, final ResultSet resultSet)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activerecord-jdbc-adapter
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.2
4
+ version: 1.3.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nick Sieger, Ola Bini and JRuby contributors
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-10-11 00:00:00.000000000 Z
11
+ date: 2013-11-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -248,7 +248,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
248
248
  version: '0'
249
249
  requirements: []
250
250
  rubyforge_project: jruby-extras
251
- rubygems_version: 2.1.0
251
+ rubygems_version: 2.1.9
252
252
  signing_key:
253
253
  specification_version: 4
254
254
  summary: JDBC adapter for ActiveRecord, for use within JRuby on Rails.