activerecord-jdbc-adapter 52.8-java → 60.0-java

Sign up to get free protection for your applications and to get access to all the features.
Files changed (64) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -2
  3. data/.travis.yml +58 -37
  4. data/Gemfile +9 -2
  5. data/README.md +25 -9
  6. data/Rakefile +1 -1
  7. data/Rakefile.jdbc +8 -1
  8. data/activerecord-jdbc-adapter.gemspec +5 -8
  9. data/lib/arjdbc/abstract/connection_management.rb +7 -0
  10. data/lib/arjdbc/abstract/core.rb +16 -23
  11. data/lib/arjdbc/abstract/database_statements.rb +26 -2
  12. data/lib/arjdbc/abstract/statement_cache.rb +2 -5
  13. data/lib/arjdbc/abstract/transaction_support.rb +5 -3
  14. data/lib/arjdbc/db2/column.rb +0 -39
  15. data/lib/arjdbc/derby/adapter.rb +1 -20
  16. data/lib/arjdbc/firebird/adapter.rb +0 -21
  17. data/lib/arjdbc/h2/adapter.rb +0 -15
  18. data/lib/arjdbc/hsqldb/adapter.rb +0 -14
  19. data/lib/arjdbc/informix/adapter.rb +0 -23
  20. data/lib/arjdbc/jdbc/adapter.rb +3 -1
  21. data/lib/arjdbc/jdbc/adapter_java.jar +0 -0
  22. data/lib/arjdbc/jdbc/adapter_require.rb +3 -1
  23. data/lib/arjdbc/jdbc/base_ext.rb +3 -1
  24. data/lib/arjdbc/jdbc/callbacks.rb +2 -0
  25. data/lib/arjdbc/jdbc/column.rb +2 -0
  26. data/lib/arjdbc/jdbc/connection.rb +2 -0
  27. data/lib/arjdbc/jdbc/connection_methods.rb +2 -0
  28. data/lib/arjdbc/jdbc/error.rb +2 -0
  29. data/lib/arjdbc/jdbc/extension.rb +2 -0
  30. data/lib/arjdbc/jdbc/java.rb +3 -1
  31. data/lib/arjdbc/jdbc/railtie.rb +3 -1
  32. data/lib/arjdbc/jdbc/rake_tasks.rb +3 -1
  33. data/lib/arjdbc/jdbc/serialized_attributes_helper.rb +3 -1
  34. data/lib/arjdbc/jdbc/type_cast.rb +2 -0
  35. data/lib/arjdbc/jdbc/type_converter.rb +2 -0
  36. data/lib/arjdbc/mysql/adapter.rb +47 -18
  37. data/lib/arjdbc/mysql/connection_methods.rb +0 -1
  38. data/lib/arjdbc/postgresql/adapter.rb +220 -213
  39. data/lib/arjdbc/postgresql/base/array_decoder.rb +2 -0
  40. data/lib/arjdbc/postgresql/base/array_encoder.rb +4 -2
  41. data/lib/arjdbc/postgresql/base/array_parser.rb +4 -2
  42. data/lib/arjdbc/postgresql/base/pgconn.rb +2 -0
  43. data/lib/arjdbc/postgresql/column.rb +6 -4
  44. data/lib/arjdbc/postgresql/connection_methods.rb +0 -1
  45. data/lib/arjdbc/postgresql/name.rb +2 -0
  46. data/lib/arjdbc/postgresql/oid_types.rb +2 -0
  47. data/lib/arjdbc/sqlite3/adapter.rb +175 -180
  48. data/lib/arjdbc/sqlite3/connection_methods.rb +15 -5
  49. data/lib/arjdbc/tasks/databases.rake +13 -10
  50. data/lib/arjdbc/util/quoted_cache.rb +3 -1
  51. data/lib/arjdbc/util/serialized_attributes.rb +3 -1
  52. data/lib/arjdbc/util/table_copier.rb +3 -1
  53. data/lib/arjdbc/version.rb +1 -1
  54. data/pom.xml +4 -4
  55. data/rakelib/01-tomcat.rake +2 -2
  56. data/rakelib/rails.rake +1 -1
  57. data/src/java/arjdbc/ArJdbcModule.java +5 -5
  58. data/src/java/arjdbc/jdbc/DriverWrapper.java +1 -9
  59. data/src/java/arjdbc/jdbc/RubyJdbcConnection.java +434 -701
  60. data/src/java/arjdbc/mssql/MSSQLRubyJdbcConnection.java +0 -51
  61. data/src/java/arjdbc/mysql/MySQLRubyJdbcConnection.java +13 -23
  62. data/src/java/arjdbc/postgresql/PostgreSQLRubyJdbcConnection.java +31 -24
  63. data/src/java/arjdbc/sqlite3/SQLite3RubyJdbcConnection.java +94 -99
  64. metadata +7 -9
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3fcd23bc0bc83be277637d917d014b73f88f47f8131f6e3da8133438a2061c5b
4
- data.tar.gz: 969acebe81158341aa35d20c4825f990ac4d0c2ee802f813ef82d4f2c0e645c3
3
+ metadata.gz: 807d5401be5ff0aba3877e221cd597609d8b88b7388cd2bde43861565b3e008c
4
+ data.tar.gz: ac01cd946ad85a3c4b854d198408f61bff55ddd6a97dd6e3b47ceab20eb78e6a
5
5
  SHA512:
6
- metadata.gz: 6bca062cfc904fb675cbf6d20fc92c09d5824010d4d72dae1f57d86b2c7bc14fcf18b197eebfdecf6c53617c7a4e39e79a2ce00a6be2cd59b5407ab9a1e67301
7
- data.tar.gz: ebf78548344f64fe6a853c6d94ea8a2cdafe32915e8cb140a0a05dfffade36acfae932f4835fca49e16052988c49002f388d53dc37093ed1acc1751599001d7a
6
+ metadata.gz: a8e2cbd16ca12f5fcd1403a899ca97328f5887b670789939e3ca83dc9046dff670c75def5e294ad0a19433a528355147f9974cfaac077f838491286f6786af47
7
+ data.tar.gz: cc77979db17af2578c841b16d95bf7f7b4203e437fb490016509498c43348486399b046c8b0140795848d6cd44f67e3fa17bd1f6bd16a854bbc3569959bf3522
data/.gitignore CHANGED
@@ -2,7 +2,6 @@
2
2
  *.tgz
3
3
  *~
4
4
  *.log
5
- /log/
6
5
  patches*
7
6
  *#
8
7
  TAGS
@@ -31,4 +30,4 @@ Gemfile.lock
31
30
  .idea
32
31
  .settings
33
32
  activerecord-jdbc.iml
34
- lib/arjdbc/jdbc/adapter_java.jar
33
+ lib/arjdbc/jdbc/adapter_java.jar
data/.travis.yml CHANGED
@@ -3,8 +3,6 @@ dist: xenial
3
3
 
4
4
  services:
5
5
  - mysql
6
- addons:
7
- postgresql: 9.4
8
6
 
9
7
  before_install:
10
8
  - unset _JAVA_OPTIONS
@@ -17,7 +15,7 @@ install:
17
15
 
18
16
  language: ruby
19
17
  rvm:
20
- - jruby-9.1.16.0
18
+ - jruby-9.2.7.0
21
19
  jdk:
22
20
  - openjdk8
23
21
 
@@ -49,45 +47,58 @@ before_script:
49
47
  || true
50
48
 
51
49
  env:
52
- - DB=mysql2 PREPARED_STATEMENTS=false
53
- - DB=mysql2 PREPARED_STATEMENTS=true
54
- - DB=mysql2 DRIVER=MariaDB
55
- - DB=postgresql PREPARED_STATEMENTS=false INSERT_RETURNING=false
56
- - DB=postgresql PREPARED_STATEMENTS=false INSERT_RETURNING=true
57
- - DB=postgresql PREPARED_STATEMENTS=true
58
- - DB=postgresql PREPARED_STATEMENTS=true INSERT_RETURNING=true
59
- - DB=sqlite3 PREPARED_STATEMENTS=false
60
- - DB=sqlite3 PREPARED_STATEMENTS=true
61
- - DB=jndi PREPARED_STATEMENTS=false
62
- - DB=jndi PREPARED_STATEMENTS=true
50
+ global:
51
+ - AR_VERSION="6-0-stable"
63
52
  matrix:
64
53
  allow_failures:
65
54
  - rvm: jruby-head
66
55
  include:
67
- # jruby-9.2
68
- - rvm: jruby-9.2.6.0
69
- env: DB=mysql2
70
- - rvm: jruby-9.2.6.0
71
- env: DB=postgresql
72
- - rvm: jruby-9.2.6.0
73
- env: DB=sqlite3
74
- # jruby-9.2 + Java 11
75
- - rvm: jruby-9.2.6.0
76
- env: DB=mysql2
77
- jdk: openjdk11
78
- - rvm: jruby-9.2.6.0
79
- env: DB=postgresql
80
- jdk: openjdk11
81
- - rvm: jruby-9.2.6.0
82
- env: DB=sqlite3
83
- jdk: openjdk11
56
+ - env: DB=mysql2 PREPARED_STATEMENTS=false
57
+ - env: DB=mysql2 PREPARED_STATEMENTS=true
58
+ - env: DB=mysql2 DRIVER=MariaDB
59
+
60
+ - addons:
61
+ postgresql: "10"
62
+ env: DB=postgresql PREPARED_STATEMENTS=false INSERT_RETURNING=false
63
+ - addons:
64
+ postgresql: "10"
65
+ env: DB=postgresql PREPARED_STATEMENTS=false INSERT_RETURNING=true
66
+ - addons:
67
+ postgresql: "10"
68
+ env: DB=postgresql PREPARED_STATEMENTS=true
69
+ - addons:
70
+ postgresql: "10"
71
+ env: DB=postgresql PREPARED_STATEMENTS=true INSERT_RETURNING=true
72
+ - addons:
73
+ postgresql: "9.4"
74
+ env: DB=postgresql PREPARED_STATEMENTS=true
75
+
76
+ - env: DB=sqlite3 PREPARED_STATEMENTS=false
77
+ - env: DB=sqlite3 PREPARED_STATEMENTS=true
78
+
79
+ - env: DB=jndi PREPARED_STATEMENTS=false
80
+ - env: DB=jndi PREPARED_STATEMENTS=true
81
+
82
+ # Java 11
83
+ - env: DB=mysql2
84
+ jdk: oraclejdk11
85
+ - env: DB=postgresql
86
+ jdk: oraclejdk11
87
+ addons:
88
+ postgresql: "10"
89
+ - env: DB=sqlite3
90
+ jdk: oraclejdk11
91
+
84
92
  # jruby-head
85
93
  - rvm: jruby-head
86
94
  env: DB=mysql2
87
95
  - rvm: jruby-head
88
96
  env: DB=postgresql
97
+ addons:
98
+ postgresql: "10"
89
99
  - rvm: jruby-head
90
100
  env: DB=sqlite3
101
+
91
102
  # testing against MariaDB
92
103
  - addons:
93
104
  mariadb: 10.2
@@ -95,10 +106,20 @@ matrix:
95
106
  - addons:
96
107
  mariadb: 10.3
97
108
  env: DB=mariadb PREPARED_STATEMENTS=true
109
+
98
110
  # Rails test-suite :
99
- - env: DB=mysql2 TEST_PREFIX="rails:" AR_VERSION="v5.2.3" # PS off by default
100
- - env: DB=mysql2 TEST_PREFIX="rails:" AR_VERSION="v5.2.3" PREPARED_STATEMENTS=true
101
- - env: DB=mysql2 TEST_PREFIX="rails:" AR_VERSION="v5.2.3" DRIVER=MariaDB
102
- - env: DB=postgresql TEST_PREFIX="rails:" AR_VERSION="v5.2.3" # PS on by default
103
- - env: DB=postgresql TEST_PREFIX="rails:" AR_VERSION="v5.2.3" PREPARED_STATEMENTS=false
104
- - env: DB=sqlite3 TEST_PREFIX="rails:" AR_VERSION="v5.2.3"
111
+ - env: DB=mysql2 TEST_PREFIX="rails:" AR_VERSION="6-0-stable" # PS off by default
112
+ - env: DB=mysql2 TEST_PREFIX="rails:" AR_VERSION="6-0-stable" PREPARED_STATEMENTS=true
113
+ - env: DB=mysql2 TEST_PREFIX="rails:" AR_VERSION="6-0-stable" DRIVER=MariaDB
114
+
115
+ - addons:
116
+ postgresql: "10"
117
+ env: DB=postgresql TEST_PREFIX="rails:" AR_VERSION="6-0-stable" # PS on by default
118
+ - addons:
119
+ postgresql: "10"
120
+ env: DB=postgresql TEST_PREFIX="rails:" AR_VERSION="6-0-stable" PREPARED_STATEMENTS=false
121
+ - addons:
122
+ postgresql: "9.4"
123
+ env: DB=postgresql TEST_PREFIX="rails:" AR_VERSION="6-0-stable" # PS on by default
124
+
125
+ - env: DB=sqlite3 TEST_PREFIX="rails:" AR_VERSION="6-0-stable"
data/Gemfile CHANGED
@@ -10,10 +10,15 @@ if ENV['RAILS'] # Use local clone of Rails
10
10
 
11
11
  activemodel_dir = ::File.join(rails_dir, 'activemodel')
12
12
  activesupport_dir = ::File.join(rails_dir, 'activesupport')
13
-
13
+ actionpack_dir = ::File.join(rails_dir, 'actionpack')
14
+ actionview_dir = ::File.join(rails_dir, 'actionview')
15
+
14
16
  gem 'activerecord', require: false, path: activerecord_dir
15
17
  gem 'activemodel', require: false, path: activemodel_dir
16
18
  gem 'activesupport', require: false, path: activesupport_dir
19
+ gem 'actionpack', require: false, path: actionpack_dir
20
+ gem 'actionview', require: false, path: actionview_dir
21
+
17
22
  elsif ENV['AR_VERSION'] # Use specific version of AR and not .gemspec version
18
23
  version = ENV['AR_VERSION']
19
24
 
@@ -28,11 +33,13 @@ elsif ENV['AR_VERSION'] # Use specific version of AR and not .gemspec version
28
33
  else # branch
29
34
  opts = {branch: version}
30
35
  end
31
-
36
+
32
37
  git 'https://github.com/rails/rails.git', **opts do
33
38
  gem 'activerecord', require: false
34
39
  gem 'activemodel', require: false
35
40
  gem 'activesupport', require: false
41
+ gem 'actionpack', require: false
42
+ gem 'actionview', require: false
36
43
  end
37
44
  end
38
45
  end
data/README.md CHANGED
@@ -18,15 +18,15 @@ is not something we can do with the resources we currently have.
18
18
 
19
19
  Versions are targeted at certain versions of Rails and live on their own branches.
20
20
 
21
- | Gem Version | Rails Version | Branch |
22
- | ----------- | ------------- | ------ |
23
- | 50.x | 5.0.x | 50-stable |
24
- | 51.x | 5.1.x | 51-stable |
25
- | 52.x | 5.2.x | 52-stable |
26
- | future | latest | master |
21
+ | Gem Version | Rails Version | Branch | min JRuby | min Java |
22
+ | ----------- | ------------- | --------- | --------- | -------- |
23
+ | 50.x | 5.0.x | 50-stable | 9.1.x | 7 |
24
+ | 51.x | 5.1.x | 51-stable | 9.1.x | 7 |
25
+ | 52.x | 5.2.x | 52-stable | 9.1.x | 7 |
26
+ | 60.x | 6.0.x | master | 9.2.7 | 8 |
27
27
 
28
- The minimum version of JRuby for 50+ is JRuby **9.1.x** and
29
- JRuby 9.1+ requires Java 7 or newer (we recommend Java 8 at minimum).
28
+ Note that JRuby 9.1.x is end-of-life. We recommend Java 8 at a minimum for all
29
+ versions.
30
30
 
31
31
  ## Using ActiveRecord JDBC
32
32
 
@@ -83,6 +83,21 @@ production:
83
83
  connectTimeout: 60000
84
84
  ```
85
85
 
86
+ #### MySQL specific notes
87
+
88
+ Depending on the MySQL server configuration, it might be required to set
89
+ additional connection properties for date/time support to work correctly. If you
90
+ encounter problems, try adding this to your database configuration:
91
+
92
+ ```yml
93
+ properties:
94
+ serverTimezone: <%= java.util.TimeZone.getDefault.getID %>
95
+ ```
96
+
97
+ The correct timezone depends on the system setup, but the one shown is a good
98
+ place to start and is actually the correct setting for many systems.
99
+
100
+
86
101
  ### Standalone with ActiveRecord
87
102
 
88
103
  Once the setup is made (see below) you can establish a JDBC connection like this
@@ -157,7 +172,8 @@ ask on the #JRuby IRC channel on http://freenode.net/ (try [web-chat][6]).
157
172
  This project was originally written by [Nick Sieger](http://github.com/nicksieger)
158
173
  and [Ola Bini](http://github.com/olabini) with lots of help from the JRuby community.
159
174
  Polished 3.x compatibility and 4.x support (for AR-JDBC >= 1.3.0) was managed by
160
- [Karol Bucek](http://github.com/kares) among others.
175
+ [Karol Bucek](http://github.com/kares) among others. Support for Rails 6 was
176
+ contributed by [shellyBits GmbH](https://shellybits.ch/)
161
177
 
162
178
  ## License
163
179
 
data/Rakefile CHANGED
@@ -185,7 +185,7 @@ if defined? JRUBY_VERSION
185
185
  #directory classes = 'pkg/classes'; CLEAN << classes
186
186
 
187
187
  file jar_file => FileList[ 'src/java/**/*.java' ] do
188
- source = target = '1.7'; debug = true
188
+ source = target = '1.8'; debug = true
189
189
 
190
190
  get_driver_jars_local = lambda do |*args|
191
191
  driver_deps = args.empty? ? [ :Postgres, :MySQL ] : args
data/Rakefile.jdbc CHANGED
@@ -17,4 +17,11 @@ desc "Build and install #{name}-#{version} gem into system gems"
17
17
  task('install') { gem_helper.install_gem }
18
18
 
19
19
  desc "Create tag #{version_tag} build and push #{name}-#{version} gem to Rubygems"
20
- task('release') { gem_helper.release_gem }
20
+ task('release') do
21
+ gem_helper.instance_eval do
22
+ guard_clean
23
+ built_gem_path = build_gem
24
+ tag_version unless already_tagged?
25
+ rubygem_push(built_gem_path) if gem_push?
26
+ end
27
+ end
@@ -11,13 +11,10 @@ Gem::Specification.new do |gem|
11
11
  gem.license = 'BSD-2-Clause'
12
12
  gem.summary = 'JDBC adapter for ActiveRecord, for use within JRuby on Rails.'
13
13
  gem.description = "" <<
14
- "AR-JDBC is a database adapter for Rails' ActiveRecord component designed " <<
15
- "to be used with JRuby built upon Java's JDBC API for database access. " <<
16
- "Provides (ActiveRecord) built-in adapters: MySQL, PostgreSQL and SQLite3 " <<
17
- "as well as adapters for popular databases such as Oracle, SQLServer, " <<
18
- "DB2, FireBird and even Java (embed) databases: Derby, HSQLDB and H2. " <<
19
- "It allows to connect to virtually any JDBC-compliant database with your " <<
20
- "JRuby on Rails application."
14
+ "AR-JDBC is a database adapter for Rails' ActiveRecord component " <<
15
+ "designed to be used with JRuby built upon Java's JDBC API for " <<
16
+ "database access. Provides (ActiveRecord) built-in adapters: MySQL, " <<
17
+ "PostgreSQL, SQLite3, and SQLServer."
21
18
 
22
19
  gem.require_paths = ["lib"]
23
20
 
@@ -44,7 +41,7 @@ Gem::Specification.new do |gem|
44
41
  gem.executables = gem.files.grep(%r{^bin/}).map { |f| File.basename(f) }
45
42
  gem.test_files = gem.files.grep(%r{^test/})
46
43
 
47
- gem.add_dependency 'activerecord', '~> 5.2.0'
44
+ gem.add_dependency 'activerecord', '~> 6.0.0'
48
45
 
49
46
  #gem.add_development_dependency 'test-unit', '2.5.4'
50
47
  #gem.add_development_dependency 'test-unit-context', '>= 0.3.0'
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module ArJdbc
2
4
  module Abstract
3
5
  module ConnectionManagement
@@ -8,6 +10,11 @@ module ArJdbc
8
10
  @connection.active?
9
11
  end
10
12
 
13
+ def really_valid?
14
+ return unless @connection
15
+ @connection.really_valid?
16
+ end
17
+
11
18
  # @override
12
19
  def reconnect!
13
20
  super # clear_cache! && reset_transaction
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module ArJdbc
2
4
  module Abstract
3
5
 
@@ -34,28 +36,26 @@ module ArJdbc
34
36
 
35
37
  protected
36
38
 
37
- def translate_exception_class(e, sql)
38
- begin
39
- message = "#{e.class.name}: #{e.message}: #{sql}"
40
- rescue Encoding::CompatibilityError
41
- message = "#{e.class.name}: #{e.message.force_encoding sql.encoding}: #{sql}"
42
- end
39
+ def translate_exception_class(e, sql, binds)
40
+ message = "#{e.class.name}: #{e.message}"
43
41
 
44
- exception = translate_exception(e, message)
45
- exception.set_backtrace e.backtrace unless e.equal?(exception)
42
+ exception = translate_exception(
43
+ e, message: message, sql: sql, binds: binds
44
+ )
45
+ exception.set_backtrace e.backtrace
46
46
  exception
47
47
  end
48
48
 
49
- def translate_exception(e, message)
49
+ def translate_exception(exception, message:, sql:, binds:)
50
50
  # override in derived class
51
51
 
52
52
  # we shall not translate native "Java" exceptions as they might
53
53
  # swallow an ArJdbc / driver bug into an AR::StatementInvalid !
54
- return e if e.is_a?(Java::JavaLang::Throwable)
54
+ return exception if exception.is_a?(Java::JavaLang::Throwable)
55
55
 
56
- case e
57
- when SystemExit, SignalException, NoMemoryError then e
58
- when ActiveModel::RangeError, TypeError, RuntimeError then e
56
+ case exception
57
+ when SystemExit, SignalException, NoMemoryError then exception
58
+ when ActiveModel::RangeError, TypeError, RuntimeError then exception
59
59
  else super
60
60
  end
61
61
  end
@@ -74,13 +74,6 @@ module ArJdbc
74
74
  end
75
75
  end
76
76
 
77
- module LogSubscriber
78
- JDBC_GEM_ROOT = File.expand_path("../../../..", __FILE__) + "/"
79
-
80
- # Remove this gem from log trace so that query shows where it was called in application
81
- def ignored_callstack(path)
82
- super || path.start_with?(JDBC_GEM_ROOT)
83
- end
84
- end
85
- ActiveRecord::LogSubscriber.prepend(ArJdbc::LogSubscriber)
86
- end
77
+ JDBC_GEM_ROOT = File.expand_path("../../../..", __FILE__) + "/"
78
+ ActiveRecord::LogSubscriber.backtrace_cleaner.add_silencer { |line| line.start_with?(JDBC_GEM_ROOT) }
79
+ end
@@ -10,13 +10,19 @@ module ArJdbc
10
10
  NO_BINDS = [].freeze
11
11
 
12
12
  def exec_insert(sql, name = nil, binds = NO_BINDS, pk = nil, sequence_name = nil)
13
+ if preventing_writes?
14
+ raise ActiveRecord::ReadOnlyError, "Write query attempted while in readonly mode: #{sql}"
15
+ end
16
+
17
+ materialize_transactions
18
+
13
19
  binds = convert_legacy_binds_to_attributes(binds) if binds.first.is_a?(Array)
14
20
 
15
21
  if without_prepared_statement?(binds)
16
- log(sql, name) { @connection.execute_insert_pk(sql, pk) }
22
+ log(sql, name) { @connection.execute_insert(sql) }
17
23
  else
18
24
  log(sql, name, binds) do
19
- @connection.execute_insert_pk(sql, binds, pk)
25
+ @connection.execute_insert(sql, binds)
20
26
  end
21
27
  end
22
28
  end
@@ -24,6 +30,12 @@ module ArJdbc
24
30
  # It appears that at this point (AR 5.0) "prepare" should only ever be true
25
31
  # if prepared statements are enabled
26
32
  def exec_query(sql, name = nil, binds = NO_BINDS, prepare: false)
33
+ if preventing_writes? && write_query?(sql)
34
+ raise ActiveRecord::ReadOnlyError, "Write query attempted while in readonly mode: #{sql}"
35
+ end
36
+
37
+ materialize_transactions
38
+
27
39
  binds = convert_legacy_binds_to_attributes(binds) if binds.first.is_a?(Array)
28
40
 
29
41
  if without_prepared_statement?(binds)
@@ -38,6 +50,12 @@ module ArJdbc
38
50
  end
39
51
 
40
52
  def exec_update(sql, name = nil, binds = NO_BINDS)
53
+ if preventing_writes?
54
+ raise ActiveRecord::ReadOnlyError, "Write query attempted while in readonly mode: #{sql}"
55
+ end
56
+
57
+ materialize_transactions
58
+
41
59
  binds = convert_legacy_binds_to_attributes(binds) if binds.first.is_a?(Array)
42
60
 
43
61
  if without_prepared_statement?(binds)
@@ -49,6 +67,12 @@ module ArJdbc
49
67
  alias :exec_delete :exec_update
50
68
 
51
69
  def execute(sql, name = nil)
70
+ if preventing_writes? && write_query?(sql)
71
+ raise ActiveRecord::ReadOnlyError, "Write query attempted while in readonly mode: #{sql}"
72
+ end
73
+
74
+ materialize_transactions
75
+
52
76
  log(sql, name) { @connection.execute(sql) }
53
77
  end
54
78
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'active_record/connection_adapters/statement_pool'
2
4
 
3
5
  module ArJdbc
@@ -41,11 +43,6 @@ module ArJdbc
41
43
  @statements[sql_key(sql)] ||= @connection.prepare_statement(sql)
42
44
  end
43
45
 
44
- def supports_statement_cache?
45
- ActiveSupport::Deprecation.deprecation_warning(__method__)
46
- @jdbc_statement_cache_enabled
47
- end
48
-
49
46
  private
50
47
 
51
48
  # This should be overridden by the adapter if the sql itself
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module ArJdbc
2
4
  module Abstract
3
5
 
@@ -22,7 +24,7 @@ module ArJdbc
22
24
  # Starts a database transaction.
23
25
  # @override
24
26
  def begin_db_transaction
25
- log('BEGIN TRANSACTION'.freeze, nil) { @connection.begin }
27
+ log('BEGIN TRANSACTION', nil) { @connection.begin }
26
28
  end
27
29
 
28
30
  # Starts a database transaction.
@@ -34,14 +36,14 @@ module ArJdbc
34
36
  # Commits the current database transaction.
35
37
  # @override
36
38
  def commit_db_transaction
37
- log('COMMIT TRANSACTION'.freeze, nil) { @connection.commit }
39
+ log('COMMIT TRANSACTION', nil) { @connection.commit }
38
40
  end
39
41
 
40
42
  # Rolls back the current database transaction.
41
43
  # Called from 'rollback_db_transaction' in the AbstractAdapter
42
44
  # @override
43
45
  def exec_rollback_db_transaction
44
- log('ROLLBACK TRANSACTION'.freeze, nil) { @connection.rollback }
46
+ log('ROLLBACK TRANSACTION', nil) { @connection.rollback }
45
47
  end
46
48
 
47
49
  ########################## Savepoint Interface ############################
@@ -80,45 +80,6 @@ module ArJdbc
80
80
 
81
81
  private
82
82
 
83
- def simplified_type(field_type)
84
- case field_type
85
- when /^decimal\(1\)$/i then DB2.emulate_booleans? ? :boolean : :integer
86
- when /smallint/i then DB2.emulate_booleans? ? :boolean : :integer
87
- when /boolean/i then :boolean
88
- when /^real|double/i then :float
89
- when /int|serial/i then :integer
90
- # if a numeric column has no scale, lets treat it as an integer.
91
- # The AS400 rpg guys do this ALOT since they have no integer datatype ...
92
- when /decimal|numeric|decfloat/i
93
- extract_scale(field_type) == 0 ? :integer : :decimal
94
- when /timestamp/i then :timestamp
95
- when /datetime/i then :datetime
96
- when /time/i then :time
97
- when /date/i then :date
98
- # DB2 provides three data types to store these data objects as strings of up to 2 GB in size:
99
- # Character large objects (CLOBs)
100
- # Use the CLOB data type to store SBCS or mixed data, such as documents that contain
101
- # single character set. Use this data type if your data is larger (or might grow larger)
102
- # than the VARCHAR data type permits.
103
- # Double-byte character large objects (DBCLOBs)
104
- # Use the DBCLOB data type to store large amounts of DBCS data, such as documents that
105
- # use a DBCS character set.
106
- # Binary large objects (BLOBs)
107
- # Use the BLOB data type to store large amounts of noncharacter data, such as pictures,
108
- # voice, and mixed media.
109
- when /clob|text/i then :text # handles DBCLOB
110
- when /^long varchar/i then :text # :limit => 32700
111
- when /blob|binary/i then :binary
112
- # varchar () for bit data, char () for bit data, long varchar for bit data
113
- when /for bit data/i then :binary
114
- when /xml/i then :xml
115
- when /graphic/i then :graphic # vargraphic, long vargraphic
116
- when /rowid/i then :rowid # rowid is a supported datatype on z/OS and i/5
117
- else
118
- super
119
- end
120
- end
121
-
122
83
  # Post process default value from JDBC into a Rails-friendly format (columns{-internal})
123
84
  def default_value(value)
124
85
  # IBM i (AS400) will return an empty string instead of null for no default
@@ -65,25 +65,6 @@ module ArJdbc
65
65
  limit
66
66
  end
67
67
 
68
- def simplified_type(field_type)
69
- case field_type
70
- when /^smallint/i then Derby.emulate_booleans? ? :boolean : :integer
71
- when /^bigint|int/i then :integer
72
- when /^real|double/i then :float
73
- when /^dec/i then # DEC is a DECIMAL alias
74
- extract_scale(field_type) == 0 ? :integer : :decimal
75
- when /^timestamp/i then :datetime
76
- when /^xml/i then :xml
77
- when 'long varchar' then :text
78
- when /for bit data/i then :binary
79
- # :name=>"long varchar for bit data", :limit=>32700
80
- # :name=>"varchar() for bit data", :limit=>32672
81
- # :name=>"char() for bit data", :limit=>254}
82
- else
83
- super
84
- end
85
- end
86
-
87
68
  # Post process default value from JDBC into a Rails-friendly format (columns{-internal})
88
69
  def default_value(value)
89
70
  # JDBC returns column default strings with actual single quotes around the value.
@@ -420,7 +401,7 @@ module ArJdbc
420
401
 
421
402
  # @override
422
403
  def supports_ddl_transactions?; true end
423
-
404
+
424
405
  # @override
425
406
  def supports_foreign_keys?; true end
426
407
 
@@ -38,27 +38,6 @@ module ArJdbc
38
38
  return $1 unless $1.upcase == 'NULL'
39
39
  end
40
40
  end
41
-
42
- private
43
-
44
- def simplified_type(field_type)
45
- case field_type
46
- when /timestamp/i then :datetime
47
- when /^smallint/i then :integer
48
- when /^bigint|int/i then :integer
49
- when /^double/i then :float # double precision
50
- when /^decimal/i then
51
- extract_scale(field_type) == 0 ? :integer : :decimal
52
- when /^char\(1\)$/i then Firebird.emulate_booleans? ? :boolean : :string
53
- when /^char/i then :string
54
- when /^blob\ssub_type\s(\d)/i
55
- return :binary if $1 == '0'
56
- return :text if $1 == '1'
57
- else
58
- super
59
- end
60
- end
61
-
62
41
  end
63
42
 
64
43
  # @see ActiveRecord::ConnectionAdapters::JdbcAdapter#jdbc_column_class
@@ -47,21 +47,6 @@ module ArJdbc
47
47
  limit
48
48
  end
49
49
 
50
- def simplified_type(field_type)
51
- case field_type
52
- when /^bit|bool/i then :boolean
53
- when /^signed|year/i then :integer
54
- when /^real|double/i then :float
55
- when /^varchar/i then :string
56
- when /^longvarchar/i then :text
57
- when /^binary|raw|bytea/i then :binary
58
- when /varbinary/i then :binary # longvarbinary, varbinary
59
- when /^blob|image|oid/i then :binary
60
- else
61
- super
62
- end
63
- end
64
-
65
50
  # Post process default value from JDBC into a Rails-friendly format (columns{-internal})
66
51
  def default_value(value)
67
52
  # H2 auto-generated key default value
@@ -42,20 +42,6 @@ module ArJdbc
42
42
  limit
43
43
  end
44
44
 
45
- def simplified_type(field_type)
46
- case field_type
47
- when /^nvarchar/i then :string
48
- when /^character/i then :string
49
- when /^longvarchar/i then :text
50
- when /int/i then :integer # TINYINT, SMALLINT, BIGINT, INT
51
- when /real|double/i then :float
52
- when /^bit/i then :boolean
53
- when /binary/i then :binary # VARBINARY, LONGVARBINARY
54
- else
55
- super
56
- end
57
- end
58
-
59
45
  # Post process default value from JDBC into a Rails-friendly format (columns{-internal})
60
46
  def default_value(value)
61
47
  # JDBC returns column default strings with actual single quotes around the value.