activerecord-jdbc-adapter 50.2-java → 50.3-java
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -5
- data/.travis.yml +36 -15
- data/lib/arjdbc/abstract/database_statements.rb +2 -2
- data/lib/arjdbc/abstract/statement_cache.rb +4 -4
- data/lib/arjdbc/mysql/adapter.rb +8 -0
- data/lib/arjdbc/postgresql/adapter.rb +1 -58
- data/lib/arjdbc/postgresql/oid_types.rb +81 -7
- data/lib/arjdbc/version.rb +1 -1
- data/rakelib/rails.rake +4 -3
- data/src/java/arjdbc/ArJdbcModule.java +5 -15
- data/src/java/arjdbc/derby/DerbyRubyJdbcConnection.java +2 -2
- data/src/java/arjdbc/jdbc/ConnectionFactory.java +0 -87
- data/src/java/arjdbc/jdbc/DataSourceConnectionFactory.java +0 -1
- data/src/java/arjdbc/jdbc/RubyConnectionFactory.java +61 -0
- data/src/java/arjdbc/jdbc/RubyJdbcConnection.java +47 -19
- data/src/java/arjdbc/mysql/MySQLRubyJdbcConnection.java +2 -2
- data/src/java/arjdbc/postgresql/PgDateTimeUtils.java +52 -0
- data/src/java/arjdbc/postgresql/PostgreSQLResult.java +21 -13
- data/src/java/arjdbc/postgresql/PostgreSQLRubyJdbcConnection.java +30 -44
- data/src/java/arjdbc/util/DateTimeUtils.java +119 -0
- data/src/java/arjdbc/util/QuotingUtils.java +6 -7
- metadata +5 -5
- data/lib/arjdbc/postgresql/_bc_time_cast_patch.rb +0 -24
- data/src/java/arjdbc/postgresql/PgResultSetMetaDataWrapper.java +0 -23
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: fde4f57b66b6cae2acbbac6eba863c7423ed320b2e420b7a752ec8a9eb984846
|
4
|
+
data.tar.gz: e3a689f005016305b9e3e2b6c637fcd948135d821381d216007ba8a5a3a0eb50
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f55d6fbeecc3cc27ea2d5c8af4e31cb84c3ef82f8ea22d536772e61524798a89c2f88bf88dd09d97bd5c5fa3aeca45dc8fa21a4883fb5a4e8e80b6d98cac3d14
|
7
|
+
data.tar.gz: 8fb21f6c9c0f0919ed8215781329b3a8ecc012399593332c9a56432542d88036dbb36e05d6b6ddc5aa7c2b06d4df45035693c694a40ec71ce37834ca2bf68a57
|
data/.travis.yml
CHANGED
@@ -1,9 +1,18 @@
|
|
1
1
|
language: ruby
|
2
2
|
sudo: false
|
3
|
+
branches:
|
4
|
+
only:
|
5
|
+
- master
|
6
|
+
- /.*-stable$/
|
7
|
+
- /^test-.*/
|
8
|
+
- /maintenance|support/
|
9
|
+
- /.*dev$/
|
3
10
|
bundler_args: --without development
|
4
11
|
script: bundle exec rake ${TEST_PREFIX}test_$DB
|
5
12
|
before_install:
|
6
13
|
- unset _JAVA_OPTIONS
|
14
|
+
- rvm @default,@global do gem uninstall bundler -a -x -I || true
|
15
|
+
- gem install bundler -v "~>1.17.3"
|
7
16
|
before_script:
|
8
17
|
- echo "JAVA_OPTS=$JAVA_OPTS"
|
9
18
|
- export JRUBY_OPTS="-J-Xms64M -J-Xmx1024M"
|
@@ -33,6 +42,8 @@ rvm:
|
|
33
42
|
- jruby-9.1.16.0
|
34
43
|
jdk:
|
35
44
|
- openjdk8
|
45
|
+
addons:
|
46
|
+
postgresql: "9.4"
|
36
47
|
env:
|
37
48
|
- DB=mysql2 PREPARED_STATEMENTS=false
|
38
49
|
- DB=mysql2 PREPARED_STATEMENTS=true
|
@@ -43,19 +54,29 @@ env:
|
|
43
54
|
- DB=postgresql PREPARED_STATEMENTS=true INSERT_RETURNING=true
|
44
55
|
- DB=sqlite3 PREPARED_STATEMENTS=false
|
45
56
|
- DB=sqlite3 PREPARED_STATEMENTS=true
|
46
|
-
|
47
|
-
|
48
|
-
branches:
|
49
|
-
only:
|
50
|
-
- master
|
51
|
-
- /.*-stable$/
|
52
|
-
- /^test-.*/
|
53
|
-
- /maintenance|support/
|
54
|
-
- /.*dev$/
|
57
|
+
- DB=jndi PREPARED_STATEMENTS=false
|
58
|
+
- DB=jndi PREPARED_STATEMENTS=true
|
55
59
|
matrix:
|
56
60
|
allow_failures:
|
57
61
|
- rvm: jruby-head
|
58
62
|
include:
|
63
|
+
# jruby-9.2
|
64
|
+
- rvm: jruby-9.2.6.0
|
65
|
+
env: DB=mysql2
|
66
|
+
- rvm: jruby-9.2.6.0
|
67
|
+
env: DB=postgresql
|
68
|
+
- rvm: jruby-9.2.6.0
|
69
|
+
env: DB=sqlite3
|
70
|
+
# jruby-9.2 + Java 11
|
71
|
+
- rvm: jruby-9.2.6.0
|
72
|
+
env: DB=mysql2
|
73
|
+
jdk: openjdk11
|
74
|
+
- rvm: jruby-9.2.6.0
|
75
|
+
env: DB=postgresql
|
76
|
+
jdk: openjdk11
|
77
|
+
- rvm: jruby-9.2.6.0
|
78
|
+
env: DB=sqlite3
|
79
|
+
jdk: openjdk11
|
59
80
|
# jruby-head
|
60
81
|
- rvm: jruby-head
|
61
82
|
env: DB=mysql2
|
@@ -71,9 +92,9 @@ matrix:
|
|
71
92
|
mariadb: '10.1'
|
72
93
|
env: DB=mariadb PREPARED_STATEMENTS=true
|
73
94
|
# Rails test-suite :
|
74
|
-
- env: DB=mysql2 TEST_PREFIX="rails:" AR_VERSION="v5.0.7" # PS off by default
|
75
|
-
- env: DB=mysql2 TEST_PREFIX="rails:" AR_VERSION="v5.0.7" PREPARED_STATEMENTS=true
|
76
|
-
- env: DB=mysql2 TEST_PREFIX="rails:" AR_VERSION="v5.0.7" DRIVER=MariaDB
|
77
|
-
- env: DB=postgresql TEST_PREFIX="rails:" AR_VERSION="v5.0.7" # PS on by default
|
78
|
-
- env: DB=postgresql TEST_PREFIX="rails:" AR_VERSION="v5.0.7" PREPARED_STATEMENTS=false
|
79
|
-
- env: DB=sqlite3 TEST_PREFIX="rails:" AR_VERSION="v5.0.7"
|
95
|
+
- env: DB=mysql2 TEST_PREFIX="rails:" AR_VERSION="v5.0.7.1" # PS off by default
|
96
|
+
- env: DB=mysql2 TEST_PREFIX="rails:" AR_VERSION="v5.0.7.1" PREPARED_STATEMENTS=true
|
97
|
+
- env: DB=mysql2 TEST_PREFIX="rails:" AR_VERSION="v5.0.7.1" DRIVER=MariaDB
|
98
|
+
- env: DB=postgresql TEST_PREFIX="rails:" AR_VERSION="v5.0.7.1" # PS on by default
|
99
|
+
- env: DB=postgresql TEST_PREFIX="rails:" AR_VERSION="v5.0.7.1" PREPARED_STATEMENTS=false
|
100
|
+
- env: DB=sqlite3 TEST_PREFIX="rails:" AR_VERSION="v5.0.7.1"
|
@@ -26,8 +26,8 @@ module ArJdbc
|
|
26
26
|
log(sql, name) { @connection.execute_query(sql) }
|
27
27
|
else
|
28
28
|
log(sql, name, binds) do
|
29
|
-
#
|
30
|
-
cached_statement = fetch_cached_statement(sql) if prepare &&
|
29
|
+
# this is different from normal AR that always caches
|
30
|
+
cached_statement = fetch_cached_statement(sql) if prepare && @jdbc_statement_cache_enabled
|
31
31
|
@connection.execute_prepared_query(sql, binds, cached_statement)
|
32
32
|
end
|
33
33
|
end
|
@@ -23,7 +23,7 @@ module ArJdbc
|
|
23
23
|
# Only say we support the statement cache if we are using prepared statements
|
24
24
|
# and have a max number of statements defined
|
25
25
|
statement_limit = self.class.type_cast_config_to_integer(config[:statement_limit])
|
26
|
-
@jdbc_statement_cache_enabled =
|
26
|
+
@jdbc_statement_cache_enabled = prepared_statements && (statement_limit.nil? || statement_limit > 0)
|
27
27
|
|
28
28
|
@statements = StatementPool.new(statement_limit) # AR (5.0) expects this to be stored as @statements
|
29
29
|
end
|
@@ -34,11 +34,11 @@ module ArJdbc
|
|
34
34
|
end
|
35
35
|
|
36
36
|
def delete_cached_statement(sql)
|
37
|
-
@statements.delete(
|
37
|
+
@statements.delete(sql_key(sql))
|
38
38
|
end
|
39
39
|
|
40
40
|
def fetch_cached_statement(sql)
|
41
|
-
@statements[
|
41
|
+
@statements[sql_key(sql)] ||= @connection.prepare_statement(sql)
|
42
42
|
end
|
43
43
|
|
44
44
|
def supports_statement_cache?
|
@@ -49,7 +49,7 @@ module ArJdbc
|
|
49
49
|
|
50
50
|
# This should be overridden by the adapter if the sql itself
|
51
51
|
# is not enough to make the key unique
|
52
|
-
def
|
52
|
+
def sql_key(sql)
|
53
53
|
sql
|
54
54
|
end
|
55
55
|
|
data/lib/arjdbc/mysql/adapter.rb
CHANGED
@@ -32,7 +32,15 @@ module ActiveRecord
|
|
32
32
|
include ArJdbc::MySQL
|
33
33
|
|
34
34
|
def initialize(connection, logger, connection_parameters, config)
|
35
|
+
# workaround to skip version check on JNDI to be lazy, dummy version is high enough for Rails 5.0 - 6.0
|
36
|
+
is_jndi = ::ActiveRecord::ConnectionAdapters::JdbcConnection.jndi_config?(config)
|
37
|
+
@version = '8.1.5' if is_jndi
|
38
|
+
|
35
39
|
super
|
40
|
+
|
41
|
+
# set to nil to have it lazy-load the real value when required
|
42
|
+
@version = nil if is_jndi
|
43
|
+
|
36
44
|
@prepared_statements = false unless config.key?(:prepared_statements)
|
37
45
|
# configure_connection taken care of at ArJdbc::Abstract::Core
|
38
46
|
end
|
@@ -522,61 +522,6 @@ module ArJdbc
|
|
522
522
|
execute "TRUNCATE TABLE #{quote_table_name(table_name)}", name
|
523
523
|
end
|
524
524
|
|
525
|
-
# Returns an array of indexes for the given table.
|
526
|
-
def indexes(table_name, name = nil)
|
527
|
-
# FIXME: AR version => table = Utils.extract_schema_qualified_name(table_name.to_s)
|
528
|
-
schema, table = extract_schema_and_table(table_name.to_s)
|
529
|
-
|
530
|
-
result = query(<<-SQL, 'SCHEMA')
|
531
|
-
SELECT distinct i.relname, d.indisunique, d.indkey, pg_get_indexdef(d.indexrelid), t.oid,
|
532
|
-
pg_catalog.obj_description(i.oid, 'pg_class') AS comment,
|
533
|
-
(SELECT COUNT(*) FROM pg_opclass o
|
534
|
-
JOIN (SELECT unnest(string_to_array(d.indclass::text, ' '))::int oid) c
|
535
|
-
ON o.oid = c.oid WHERE o.opcdefault = 'f')
|
536
|
-
FROM pg_class t
|
537
|
-
INNER JOIN pg_index d ON t.oid = d.indrelid
|
538
|
-
INNER JOIN pg_class i ON d.indexrelid = i.oid
|
539
|
-
LEFT JOIN pg_namespace n ON n.oid = i.relnamespace
|
540
|
-
WHERE i.relkind = 'i'
|
541
|
-
AND d.indisprimary = 'f'
|
542
|
-
AND t.relname = '#{table}'
|
543
|
-
AND n.nspname = #{schema ? "'#{schema}'" : 'ANY (current_schemas(false))'}
|
544
|
-
ORDER BY i.relname
|
545
|
-
SQL
|
546
|
-
|
547
|
-
result.map do |row|
|
548
|
-
index_name = row[0]
|
549
|
-
# FIXME: These values [1,2] are returned in a different format than AR expects, maybe we could update it on the Java side to be more accurate
|
550
|
-
unique = row[1].is_a?(String) ? row[1] == 't' : row[1] # JDBC gets us a boolean
|
551
|
-
indkey = row[2].is_a?(Java::OrgPostgresqlUtil::PGobject) ? row[2].value : row[2]
|
552
|
-
indkey = indkey.split(" ").map(&:to_i)
|
553
|
-
inddef = row[3]
|
554
|
-
oid = row[4]
|
555
|
-
comment = row[5]
|
556
|
-
opclass = row[6]
|
557
|
-
|
558
|
-
using, expressions, where = inddef.scan(/ USING (\w+?) \((.+?)\)(?: WHERE (.+))?\z/).flatten
|
559
|
-
|
560
|
-
if indkey.include?(0) || opclass > 0
|
561
|
-
columns = expressions
|
562
|
-
else
|
563
|
-
columns = Hash[query(<<-SQL.strip_heredoc, "SCHEMA")].values_at(*indkey).compact
|
564
|
-
SELECT a.attnum, a.attname
|
565
|
-
FROM pg_attribute a
|
566
|
-
WHERE a.attrelid = #{oid}
|
567
|
-
AND a.attnum IN (#{indkey.join(",")})
|
568
|
-
SQL
|
569
|
-
|
570
|
-
# add info on sort order for columns (only desc order is explicitly specified, asc is the default)
|
571
|
-
orders = Hash[
|
572
|
-
expressions.scan(/(\w+) DESC/).flatten.map { |order_column| [order_column, :desc] }
|
573
|
-
]
|
574
|
-
end
|
575
|
-
|
576
|
-
IndexDefinition.new(table_name, index_name, unique, columns, [], orders, where, nil, using.to_sym, comment.presence)
|
577
|
-
end.compact
|
578
|
-
end
|
579
|
-
|
580
525
|
# @private
|
581
526
|
def column_name_for_operation(operation, node)
|
582
527
|
case operation
|
@@ -682,8 +627,6 @@ module ActiveRecord::ConnectionAdapters
|
|
682
627
|
require 'arjdbc/postgresql/oid_types'
|
683
628
|
include ::ArJdbc::PostgreSQL::OIDTypes
|
684
629
|
|
685
|
-
load 'arjdbc/postgresql/_bc_time_cast_patch.rb'
|
686
|
-
|
687
630
|
include ::ArJdbc::PostgreSQL::ColumnHelpers
|
688
631
|
|
689
632
|
include ::ArJdbc::Util::QuotedCache
|
@@ -736,7 +679,7 @@ module ActiveRecord::ConnectionAdapters
|
|
736
679
|
|
737
680
|
# Prepared statements aren't schema aware so we need to make sure we
|
738
681
|
# store different PreparedStatement objects for different schemas
|
739
|
-
def
|
682
|
+
def sql_key(sql)
|
740
683
|
"#{schema_search_path}-#{sql}"
|
741
684
|
end
|
742
685
|
|
@@ -9,6 +9,61 @@ module ArJdbc
|
|
9
9
|
# @private
|
10
10
|
OID = ::ActiveRecord::ConnectionAdapters::PostgreSQL::OID
|
11
11
|
|
12
|
+
# this version makes sure to register the types by name as well
|
13
|
+
# we still need to version with OID since it's used from SchemaStatements as well
|
14
|
+
class ArjdbcTypeMapInitializer < OID::TypeMapInitializer
|
15
|
+
private
|
16
|
+
|
17
|
+
def name_with_ns(row)
|
18
|
+
if row['in_ns']
|
19
|
+
row['typname']
|
20
|
+
else
|
21
|
+
%Q("#{row['nspname']}"."#{row['typname']}")
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def register_enum_type(row)
|
26
|
+
super
|
27
|
+
register name_with_ns(row), OID::Enum.new
|
28
|
+
end
|
29
|
+
|
30
|
+
def register_array_type(row)
|
31
|
+
super
|
32
|
+
register_with_subtype(name_with_ns(row), row['typelem'].to_i) do |subtype|
|
33
|
+
OID::Array.new(subtype, row['typdelim'])
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def register_range_type(row)
|
38
|
+
super
|
39
|
+
name = name_with_ns(row)
|
40
|
+
register_with_subtype(name, row['rngsubtype'].to_i) do |subtype|
|
41
|
+
OID::Range.new(subtype, name.to_sym)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def register_domain_type(row)
|
46
|
+
if base_type = @store.lookup(row['typbasetype'].to_i)
|
47
|
+
register row['oid'], base_type
|
48
|
+
register name_with_ns(row), base_type
|
49
|
+
else
|
50
|
+
warn "unknown base type (OID: #{row['typbasetype']}) for domain #{row['typname']}."
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def register_composite_type(row)
|
55
|
+
if subtype = @store.lookup(row['typelem'].to_i)
|
56
|
+
register row['oid'], OID::Vector.new(row['typdelim'], subtype)
|
57
|
+
register name_with_ns(row), OID::Vector.new(row['typdelim'], subtype)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
def assert_valid_registration(oid, oid_type)
|
62
|
+
ret = super
|
63
|
+
ret == 0 ? oid : ret
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
12
67
|
# @private
|
13
68
|
module OIDTypes
|
14
69
|
|
@@ -41,7 +96,7 @@ module ArJdbc
|
|
41
96
|
|
42
97
|
def get_oid_type(oid, fmod, column_name, sql_type = '') # :nodoc:
|
43
98
|
if !type_map.key?(oid)
|
44
|
-
load_additional_types(type_map,
|
99
|
+
load_additional_types(type_map, oid)
|
45
100
|
end
|
46
101
|
|
47
102
|
type_map.fetch(oid, fmod, sql_type) {
|
@@ -138,26 +193,45 @@ module ArJdbc
|
|
138
193
|
end
|
139
194
|
|
140
195
|
load_additional_types(m)
|
196
|
+
|
197
|
+
# pgjdbc returns these if the column is auto-incrmenting
|
198
|
+
m.alias_type 'serial', 'int4'
|
199
|
+
m.alias_type 'bigserial', 'int8'
|
141
200
|
end
|
142
201
|
|
143
|
-
def load_additional_types(type_map,
|
144
|
-
initializer =
|
202
|
+
def load_additional_types(type_map, oid = nil) # :nodoc:
|
203
|
+
initializer = ArjdbcTypeMapInitializer.new(type_map)
|
145
204
|
|
146
205
|
if supports_ranges?
|
147
206
|
query = <<-SQL
|
148
|
-
SELECT t.oid, t.typname, t.typelem, t.typdelim, t.typinput, r.rngsubtype, t.typtype, t.typbasetype
|
207
|
+
SELECT t.oid, t.typname, t.typelem, t.typdelim, t.typinput, r.rngsubtype, t.typtype, t.typbasetype,
|
208
|
+
ns.nspname, ns.nspname = ANY(current_schemas(true)) in_ns
|
149
209
|
FROM pg_type as t
|
150
210
|
LEFT JOIN pg_range as r ON oid = rngtypid
|
211
|
+
JOIN pg_namespace AS ns ON t.typnamespace = ns.oid
|
151
212
|
SQL
|
152
213
|
else
|
153
214
|
query = <<-SQL
|
154
|
-
SELECT t.oid, t.typname, t.typelem, t.typdelim, t.typinput, t.typtype, t.typbasetype
|
215
|
+
SELECT t.oid, t.typname, t.typelem, t.typdelim, t.typinput, t.typtype, t.typbasetype,
|
216
|
+
ns.nspname, ns.nspname = ANY(current_schemas(true)) in_ns
|
155
217
|
FROM pg_type as t
|
218
|
+
JOIN pg_namespace AS ns ON t.typnamespace = ns.oid
|
156
219
|
SQL
|
157
220
|
end
|
158
221
|
|
159
|
-
if
|
160
|
-
|
222
|
+
if oid
|
223
|
+
if oid.is_a? Numeric || oid.match(/^\d+$/)
|
224
|
+
# numeric OID
|
225
|
+
query += "WHERE t.oid::integer = %s" % oid
|
226
|
+
|
227
|
+
elsif m = oid.match(/"?(\w+)"?\."?(\w+)"?/)
|
228
|
+
# namespace and type name
|
229
|
+
query += "WHERE ns.nspname = '%s' AND t.typname = '%s'" % [m[1], m[2]]
|
230
|
+
|
231
|
+
else
|
232
|
+
# only type name
|
233
|
+
query += "WHERE t.typname = '%s' AND ns.nspname = ANY(current_schemas(true))" % oid
|
234
|
+
end
|
161
235
|
else
|
162
236
|
query += initializer.query_conditions_for_initial_load(type_map)
|
163
237
|
end
|
data/lib/arjdbc/version.rb
CHANGED
data/rakelib/rails.rake
CHANGED
@@ -9,14 +9,15 @@ namespace :rails do
|
|
9
9
|
if ENV['RAILS']
|
10
10
|
ar_path = File.join(ENV['RAILS'], 'activerecord')
|
11
11
|
end
|
12
|
-
|
12
|
+
|
13
13
|
unless ar_path && File.exist?(ar_path)
|
14
|
-
ar_path = `bundle info --path activerecord`.chomp
|
14
|
+
ar_path = `bundle info --path activerecord`.lines.last.chomp
|
15
15
|
end
|
16
16
|
|
17
17
|
unless File.exist? ar_test_dir = File.join(ar_path, 'test')
|
18
18
|
raise "can not directly load Rails tests;" +
|
19
|
-
" try setting a local repository path e.g. export RAILS=`pwd`/../rails"
|
19
|
+
" try setting a local repository path e.g. export RAILS=`pwd`/../rails;" +
|
20
|
+
" failed guess: #{ar_path}"
|
20
21
|
end
|
21
22
|
|
22
23
|
driver = "jdbc-#{ENV['DRIVER'] ? ENV['DRIVER'].downcase : (adapter =~ /postgres/i ? 'postgres' : adapter)}"
|
@@ -29,7 +29,6 @@ import java.util.HashMap;
|
|
29
29
|
import java.util.Map;
|
30
30
|
import java.util.WeakHashMap;
|
31
31
|
|
32
|
-
import org.jruby.NativeException;
|
33
32
|
import org.jruby.Ruby;
|
34
33
|
import org.jruby.RubyArray;
|
35
34
|
import org.jruby.RubyClass;
|
@@ -148,13 +147,7 @@ public class ArJdbcModule {
|
|
148
147
|
}
|
149
148
|
}
|
150
149
|
catch (ClassNotFoundException e) { /* ignored */ }
|
151
|
-
catch (NoSuchMethodException e) {
|
152
|
-
throw newNativeException(runtime, e);
|
153
|
-
}
|
154
|
-
catch (IllegalAccessException e) {
|
155
|
-
throw newNativeException(runtime, e);
|
156
|
-
}
|
157
|
-
catch (InvocationTargetException e) {
|
150
|
+
catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) {
|
158
151
|
throw newNativeException(runtime, e);
|
159
152
|
}
|
160
153
|
|
@@ -263,18 +256,15 @@ public class ArJdbcModule {
|
|
263
256
|
try {
|
264
257
|
return klass.getMethod(name, argType).invoke(null, arg);
|
265
258
|
}
|
266
|
-
catch (IllegalAccessException e) {
|
267
|
-
throw newNativeException(runtime, e);
|
268
|
-
}
|
269
|
-
catch (InvocationTargetException e) {
|
259
|
+
catch (IllegalAccessException | InvocationTargetException e) {
|
270
260
|
throw newNativeException(runtime, e);
|
271
261
|
}
|
272
262
|
}
|
273
263
|
|
274
264
|
private static RaiseException newNativeException(final Ruby runtime, final Throwable cause) {
|
275
|
-
|
276
|
-
|
277
|
-
return
|
265
|
+
final RaiseException error = runtime.newRuntimeError(cause.toString());
|
266
|
+
error.initCause(cause);
|
267
|
+
return error;
|
278
268
|
}
|
279
269
|
|
280
270
|
@JRubyMethod(meta = true)
|
@@ -83,8 +83,8 @@ public class DerbyRubyJdbcConnection extends RubyJdbcConnection {
|
|
83
83
|
final int minor = jdbcDriver.getMinorVersion();
|
84
84
|
if ( major < 10 || ( major == 10 && minor < 5 ) ) {
|
85
85
|
final RubyClass errorClass = getConnectionNotEstablished(context.runtime);
|
86
|
-
throw
|
87
|
-
"adapter requires Derby >= 10.5 got: " + major + "." + minor + ""
|
86
|
+
throw context.runtime.newRaiseException(errorClass,
|
87
|
+
"adapter requires Derby >= 10.5 got: " + major + "." + minor + "");
|
88
88
|
}
|
89
89
|
if ( major == 10 && minor < 8 ) { // 10.8 ~ supports JDBC 4.1
|
90
90
|
// config[:connection_alive_sql] ||= 'SELECT 1 FROM SYS.SYSSCHEMAS FETCH FIRST 1 ROWS ONLY'
|
@@ -27,12 +27,6 @@ package arjdbc.jdbc;
|
|
27
27
|
|
28
28
|
import java.sql.Connection;
|
29
29
|
import java.sql.SQLException;
|
30
|
-
import javax.sql.DataSource;
|
31
|
-
|
32
|
-
import org.jruby.RubyObject;
|
33
|
-
import org.jruby.RubyString;
|
34
|
-
import org.jruby.runtime.ThreadContext;
|
35
|
-
import org.jruby.runtime.builtin.IRubyObject;
|
36
30
|
|
37
31
|
/**
|
38
32
|
* Interface to be implemented in Ruby for retrieving a new connection.
|
@@ -49,84 +43,3 @@ public interface ConnectionFactory {
|
|
49
43
|
Connection newConnection() throws SQLException;
|
50
44
|
|
51
45
|
}
|
52
|
-
|
53
|
-
class DataSourceConnectionFactoryImpl implements ConnectionFactory {
|
54
|
-
|
55
|
-
private final DataSource dataSource;
|
56
|
-
final String username, password; // optional
|
57
|
-
|
58
|
-
public DataSourceConnectionFactoryImpl(final DataSource dataSource) {
|
59
|
-
this.dataSource = dataSource;
|
60
|
-
this.username = null; this.password = null;
|
61
|
-
}
|
62
|
-
|
63
|
-
public DataSourceConnectionFactoryImpl(final DataSource dataSource,
|
64
|
-
final String username, final String password) {
|
65
|
-
this.dataSource = dataSource;
|
66
|
-
this.username = username; this.password = password;
|
67
|
-
}
|
68
|
-
|
69
|
-
@Override
|
70
|
-
public Connection newConnection() throws SQLException {
|
71
|
-
if ( username != null ) {
|
72
|
-
dataSource.getConnection(username, password);
|
73
|
-
}
|
74
|
-
return dataSource.getConnection();
|
75
|
-
}
|
76
|
-
|
77
|
-
DataSource getDataSource() { return dataSource; } /* for tests */
|
78
|
-
|
79
|
-
}
|
80
|
-
|
81
|
-
class DriverConnectionFactoryImpl implements ConnectionFactory {
|
82
|
-
|
83
|
-
private final DriverWrapper driverWrapper;
|
84
|
-
final String url;
|
85
|
-
final String username, password; // null allowed
|
86
|
-
|
87
|
-
public DriverConnectionFactoryImpl(final DriverWrapper driver, final String url) {
|
88
|
-
this.driverWrapper = driver; this.url = url;
|
89
|
-
this.username = null; this.password = null;
|
90
|
-
}
|
91
|
-
|
92
|
-
public DriverConnectionFactoryImpl(final DriverWrapper driver, final String url,
|
93
|
-
final String username, final String password) {
|
94
|
-
this.driverWrapper = driver; this.url = url;
|
95
|
-
this.username = username; this.password = password;
|
96
|
-
}
|
97
|
-
|
98
|
-
@Override
|
99
|
-
public Connection newConnection() throws SQLException {
|
100
|
-
return driverWrapper.connect(url, username, password);
|
101
|
-
}
|
102
|
-
|
103
|
-
DriverWrapper getDriverWrapper() { return driverWrapper; } /* for tests */
|
104
|
-
|
105
|
-
}
|
106
|
-
|
107
|
-
// @legacy ActiveRecord::ConnectionAdapters::JdbcDriver
|
108
|
-
class RubyConnectionFactoryImpl implements ConnectionFactory {
|
109
|
-
|
110
|
-
private final IRubyObject driver;
|
111
|
-
final RubyString url;
|
112
|
-
final IRubyObject username, password; // null allowed
|
113
|
-
|
114
|
-
private final RubyObject contextProvider;
|
115
|
-
|
116
|
-
public RubyConnectionFactoryImpl(final IRubyObject driver, final RubyString url,
|
117
|
-
final IRubyObject username, final IRubyObject password) {
|
118
|
-
this.driver = driver; this.url = url;
|
119
|
-
this.username = username; this.password = password;
|
120
|
-
contextProvider = (RubyObject) driver;
|
121
|
-
}
|
122
|
-
|
123
|
-
@Override
|
124
|
-
public Connection newConnection() throws SQLException {
|
125
|
-
final ThreadContext context = contextProvider.getRuntime().getCurrentContext();
|
126
|
-
final IRubyObject connection = driver.callMethod(context, "connection", new IRubyObject[] { url, username, password });
|
127
|
-
return (Connection) connection.toJava(Connection.class);
|
128
|
-
}
|
129
|
-
|
130
|
-
IRubyObject getDriver() { return driver; } /* for tests */
|
131
|
-
|
132
|
-
}
|