activerecord-jdbc-adapter 1.3.0 → 1.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +2 -0
- data/.travis.yml +28 -4
- data/Appraisals +7 -2
- data/Gemfile +2 -2
- data/History.md +16 -0
- data/gemfiles/rails41.gemfile +19 -0
- data/gemfiles/rails41.gemfile.lock +129 -0
- data/lib/arjdbc/db2/as400.rb +2 -3
- data/lib/arjdbc/derby/adapter.rb +43 -31
- data/lib/arjdbc/derby/schema_creation.rb +15 -0
- data/lib/arjdbc/hsqldb/adapter.rb +2 -1
- data/lib/arjdbc/hsqldb/schema_creation.rb +11 -0
- data/lib/arjdbc/jdbc/adapter.rb +19 -3
- data/lib/arjdbc/jdbc/adapter_java.jar +0 -0
- data/lib/arjdbc/mssql/adapter.rb +15 -0
- data/lib/arjdbc/mysql/adapter.rb +14 -13
- data/lib/arjdbc/mysql/schema_creation.rb +35 -0
- data/lib/arjdbc/oracle/adapter.rb +15 -4
- data/lib/arjdbc/postgresql/adapter.rb +18 -25
- data/lib/arjdbc/postgresql/schema_creation.rb +7 -3
- data/lib/arjdbc/tasks/databases.rake +19 -21
- data/lib/arjdbc/version.rb +1 -1
- data/pom.xml +3 -7
- data/src/java/arjdbc/jdbc/RubyJdbcConnection.java +2 -2
- data/src/java/arjdbc/postgresql/PostgreSQLRubyJdbcConnection.java +43 -2
- metadata +10 -13
- data/Gemfile.lock +0 -115
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 124d430b6ebfe8dea7139529cba9765cbbf4bbec
|
4
|
+
data.tar.gz: 8284f14f06a740097c25cdd949acda28a540cb67
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 7c8a1b98c72e0f34833754c73776b1b97f2518bead5f39da18ef7ae1f37ef19f1ec9571d7056bcb7d327cb492c0b909736b791ad20e361e392552398df481ee5
|
7
|
+
data.tar.gz: 7d6f465fcc7cf7cf38a560c73dbf75c9ce39337a4bb8fea3a4452811d8df2b4ec6f665a7544734a6cae60e9241a818e05f764cf03a5f8f4698fb575a92b7128f
|
data/.gitignore
CHANGED
data/.travis.yml
CHANGED
@@ -10,6 +10,7 @@ gemfile:
|
|
10
10
|
- gemfiles/rails31.gemfile
|
11
11
|
- gemfiles/rails32.gemfile
|
12
12
|
- gemfiles/rails40.gemfile
|
13
|
+
- gemfiles/rails41.gemfile
|
13
14
|
env:
|
14
15
|
- JRUBY_OPTS="--1.8 $JRUBY_OPTS" DB=mysql
|
15
16
|
- JRUBY_OPTS="--1.9 $JRUBY_OPTS" DB=mysql PREPARED_STATEMENTS=false
|
@@ -28,6 +29,7 @@ env:
|
|
28
29
|
- JRUBY_OPTS="--1.9 $JRUBY_OPTS" DB=hsqldb PREPARED_STATEMENTS=true
|
29
30
|
- JRUBY_OPTS="--1.8 $JRUBY_OPTS" DB=jndi
|
30
31
|
- JRUBY_OPTS="--1.9 $JRUBY_OPTS" DB=jndi PREPARED_STATEMENTS=true
|
32
|
+
# TODO: not sure why it can't connect :
|
31
33
|
#- JRUBY_OPTS="--1.8 $JRUBY_OPTS" DB=jdbc
|
32
34
|
#- JRUBY_OPTS="--1.9 $JRUBY_OPTS" DB=jdbc
|
33
35
|
branches:
|
@@ -36,10 +38,7 @@ branches:
|
|
36
38
|
- 1-2-stable
|
37
39
|
matrix:
|
38
40
|
allow_failures:
|
39
|
-
|
40
|
-
#- gemfile: gemfiles/rails23.gemfile
|
41
|
-
# NOTE: not sure why it can't connect :
|
42
|
-
#- env: DB=jdbc
|
41
|
+
- gemfile: gemfiles/rails41.gemfile
|
43
42
|
exclude:
|
44
43
|
# Rails 4 prefers Ruby 2.0 (or at least >= 1.9.3) :
|
45
44
|
- rvm: jruby
|
@@ -66,3 +65,28 @@ matrix:
|
|
66
65
|
- rvm: jruby
|
67
66
|
gemfile: gemfiles/rails40.gemfile
|
68
67
|
env: JRUBY_OPTS="--1.8 $JRUBY_OPTS" DB=jdbc
|
68
|
+
# Rails 4.1 does not support Ruby 1.8 :
|
69
|
+
- rvm: jruby
|
70
|
+
gemfile: gemfiles/rails41.gemfile
|
71
|
+
env: JRUBY_OPTS="--1.8 $JRUBY_OPTS" DB=mysql
|
72
|
+
- rvm: jruby
|
73
|
+
gemfile: gemfiles/rails41.gemfile
|
74
|
+
env: JRUBY_OPTS="--1.8 $JRUBY_OPTS" DB=postgresql
|
75
|
+
- rvm: jruby
|
76
|
+
gemfile: gemfiles/rails41.gemfile
|
77
|
+
env: JRUBY_OPTS="--1.8 $JRUBY_OPTS" DB=sqlite3
|
78
|
+
- rvm: jruby
|
79
|
+
gemfile: gemfiles/rails41.gemfile
|
80
|
+
env: JRUBY_OPTS="--1.8 $JRUBY_OPTS" DB=derby
|
81
|
+
- rvm: jruby
|
82
|
+
gemfile: gemfiles/rails41.gemfile
|
83
|
+
env: JRUBY_OPTS="--1.8 $JRUBY_OPTS" DB=h2
|
84
|
+
- rvm: jruby
|
85
|
+
gemfile: gemfiles/rails41.gemfile
|
86
|
+
env: JRUBY_OPTS="--1.8 $JRUBY_OPTS" DB=hsqldb
|
87
|
+
- rvm: jruby
|
88
|
+
gemfile: gemfiles/rails41.gemfile
|
89
|
+
env: JRUBY_OPTS="--1.8 $JRUBY_OPTS" DB=jndi
|
90
|
+
- rvm: jruby
|
91
|
+
gemfile: gemfiles/rails41.gemfile
|
92
|
+
env: JRUBY_OPTS="--1.8 $JRUBY_OPTS" DB=jdbc
|
data/Appraisals
CHANGED
@@ -15,7 +15,12 @@ appraise "rails32" do
|
|
15
15
|
gem "activerecord", "~> 3.2.13"
|
16
16
|
end
|
17
17
|
|
18
|
-
appraise "rails40" do
|
18
|
+
appraise "rails40" do
|
19
|
+
# NOTE: make sure you're using --1.9 with AR-4.0
|
19
20
|
gem "activerecord", "~> 4.0.0"
|
20
|
-
#gem 'rails', :github => 'rails/rails', :branch => '4-0-stable'
|
21
21
|
end
|
22
|
+
|
23
|
+
appraise "rails41" do
|
24
|
+
# NOTE: make sure you're using --1.9 with AR-4.1
|
25
|
+
gem 'rails', :github => 'rails/rails', :branch => 'master'
|
26
|
+
end
|
data/Gemfile
CHANGED
@@ -2,9 +2,9 @@ source "https://rubygems.org"
|
|
2
2
|
|
3
3
|
gem 'activerecord'
|
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
|
7
|
-
|
7
|
+
end
|
8
8
|
|
9
9
|
group :development do
|
10
10
|
gem 'ruby-debug', :require => nil # if ENV['DEBUG']
|
data/History.md
CHANGED
@@ -1,3 +1,17 @@
|
|
1
|
+
## 1.3.1 (09/17/13)
|
2
|
+
|
3
|
+
- helper gems should contain all files from lib/* (#463)
|
4
|
+
- [postgres] hstore values should be returned as Hash instances (#454)
|
5
|
+
- we should first allow super AbstractAdapter to initialize then extend spec
|
6
|
+
otherwise using *adapter: jdbc* configuration might no work (#457)
|
7
|
+
- return early (from `table_exists?`) if table name is nil (#460)
|
8
|
+
- [MS-SQL] handle change_column error when column has default binding or indexes
|
9
|
+
- AR's `distinct` compatible with 4.x (and 3.x) for Oracle, Derby and Postgres
|
10
|
+
- re-invent `add_column_options!` (due next AR 4.1) to provide compatibility
|
11
|
+
- backport SchemaCreation (from AR 4.0/master) + support for all adapters
|
12
|
+
|
13
|
+
Code Contributors (in no particular order): Grant Hutchins, Avin Mathew, @emassip
|
14
|
+
|
1
15
|
## 1.3.0 (08/29/13)
|
2
16
|
|
3
17
|
- [oracle] fix structure_dump: `column['data_default']` might come back as ''
|
@@ -28,6 +42,8 @@
|
|
28
42
|
there's now a new `update_lob_columns` helper hooked onto AR::Base for adapters
|
29
43
|
that send clob/blob values in a separate statement DB2, Oracle, MSSQL, Firebird
|
30
44
|
|
45
|
+
Code Contributors (in no particular order): Alexandros Giouzenis
|
46
|
+
|
31
47
|
## 1.3.0.rc1 (08/03/13)
|
32
48
|
|
33
49
|
- add activerecord gem as a dependency of the main AR-JDBC gem
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# This file was generated by Appraisal
|
2
|
+
|
3
|
+
source "https://rubygems.org"
|
4
|
+
|
5
|
+
gem "activerecord"
|
6
|
+
gem "thread_safe", :require=>nil
|
7
|
+
gem "jruby-openssl", :platform=>:jruby
|
8
|
+
gem "rake", :require=>nil
|
9
|
+
gem "appraisal", :require=>nil
|
10
|
+
gem "test-unit", "2.5.4", :group=>:test
|
11
|
+
gem "test-unit-context", ">= 0.3.0", :group=>:test
|
12
|
+
gem "mocha", "~> 0.13.1", :require=>nil, :group=>:test
|
13
|
+
gem "simplecov", :require=>nil, :group=>:test
|
14
|
+
gem "bcrypt-ruby", "~> 3.0.0", :require=>nil, :group=>:test
|
15
|
+
gem "mysql2", :require=>nil, :platform=>:mri, :group=>:test
|
16
|
+
gem "pg", :require=>nil, :platform=>:mri, :group=>:test
|
17
|
+
gem "sqlite3", :require=>nil, :platform=>:mri, :group=>:test
|
18
|
+
gem "rails", :github=>"rails/rails", :branch=>"master"
|
19
|
+
|
@@ -0,0 +1,129 @@
|
|
1
|
+
GIT
|
2
|
+
remote: git://github.com/rails/rails.git
|
3
|
+
revision: 0b3a078a24819fae8b9df0b0f63a264cece70a7c
|
4
|
+
branch: master
|
5
|
+
specs:
|
6
|
+
actionmailer (4.1.0.beta)
|
7
|
+
actionpack (= 4.1.0.beta)
|
8
|
+
actionview (= 4.1.0.beta)
|
9
|
+
mail (~> 2.5.4)
|
10
|
+
actionpack (4.1.0.beta)
|
11
|
+
activesupport (= 4.1.0.beta)
|
12
|
+
rack (~> 1.5.2)
|
13
|
+
rack-test (~> 0.6.2)
|
14
|
+
actionview (4.1.0.beta)
|
15
|
+
activemodel (= 4.1.0.beta)
|
16
|
+
activesupport (= 4.1.0.beta)
|
17
|
+
builder (~> 3.1.0)
|
18
|
+
erubis (~> 2.7.0)
|
19
|
+
activemodel (4.1.0.beta)
|
20
|
+
activesupport (= 4.1.0.beta)
|
21
|
+
builder (~> 3.1.0)
|
22
|
+
activerecord (4.1.0.beta)
|
23
|
+
activemodel (= 4.1.0.beta)
|
24
|
+
activesupport (= 4.1.0.beta)
|
25
|
+
arel (~> 4.0.0)
|
26
|
+
activesupport (4.1.0.beta)
|
27
|
+
i18n (~> 0.6, >= 0.6.4)
|
28
|
+
json (~> 1.7)
|
29
|
+
minitest (~> 5.0)
|
30
|
+
thread_safe (~> 0.1)
|
31
|
+
tzinfo (~> 0.3.37)
|
32
|
+
rails (4.1.0.beta)
|
33
|
+
actionmailer (= 4.1.0.beta)
|
34
|
+
actionpack (= 4.1.0.beta)
|
35
|
+
actionview (= 4.1.0.beta)
|
36
|
+
activerecord (= 4.1.0.beta)
|
37
|
+
activesupport (= 4.1.0.beta)
|
38
|
+
bundler (>= 1.3.0, < 2.0)
|
39
|
+
railties (= 4.1.0.beta)
|
40
|
+
sprockets-rails (~> 2.0.0)
|
41
|
+
railties (4.1.0.beta)
|
42
|
+
actionpack (= 4.1.0.beta)
|
43
|
+
activesupport (= 4.1.0.beta)
|
44
|
+
rake (>= 0.8.7)
|
45
|
+
thor (>= 0.18.1, < 2.0)
|
46
|
+
|
47
|
+
GEM
|
48
|
+
remote: https://rubygems.org/
|
49
|
+
specs:
|
50
|
+
appraisal (0.5.2)
|
51
|
+
bundler
|
52
|
+
rake
|
53
|
+
arel (4.0.0)
|
54
|
+
atomic (1.1.13)
|
55
|
+
atomic (1.1.13-java)
|
56
|
+
bcrypt-ruby (3.0.1)
|
57
|
+
bcrypt-ruby (3.0.1-java)
|
58
|
+
bouncy-castle-java (1.5.0147)
|
59
|
+
builder (3.1.4)
|
60
|
+
erubis (2.7.0)
|
61
|
+
hike (1.2.3)
|
62
|
+
i18n (0.6.5)
|
63
|
+
jruby-openssl (0.8.8)
|
64
|
+
bouncy-castle-java (>= 1.5.0147)
|
65
|
+
json (1.8.0)
|
66
|
+
json (1.8.0-java)
|
67
|
+
mail (2.5.4)
|
68
|
+
mime-types (~> 1.16)
|
69
|
+
treetop (~> 1.4.8)
|
70
|
+
metaclass (0.0.1)
|
71
|
+
mime-types (1.24)
|
72
|
+
minitest (5.0.6)
|
73
|
+
mocha (0.13.3)
|
74
|
+
metaclass (~> 0.0.1)
|
75
|
+
multi_json (1.7.9)
|
76
|
+
mysql2 (0.3.13)
|
77
|
+
pg (0.16.0)
|
78
|
+
polyglot (0.3.3)
|
79
|
+
rack (1.5.2)
|
80
|
+
rack-test (0.6.2)
|
81
|
+
rack (>= 1.0)
|
82
|
+
rake (10.1.0)
|
83
|
+
simplecov (0.7.1)
|
84
|
+
multi_json (~> 1.0)
|
85
|
+
simplecov-html (~> 0.7.1)
|
86
|
+
simplecov-html (0.7.1)
|
87
|
+
sprockets (2.10.0)
|
88
|
+
hike (~> 1.2)
|
89
|
+
multi_json (~> 1.0)
|
90
|
+
rack (~> 1.0)
|
91
|
+
tilt (~> 1.1, != 1.3.0)
|
92
|
+
sprockets-rails (2.0.0)
|
93
|
+
actionpack (>= 3.0)
|
94
|
+
activesupport (>= 3.0)
|
95
|
+
sprockets (~> 2.8)
|
96
|
+
sqlite3 (1.3.8)
|
97
|
+
test-unit (2.5.4)
|
98
|
+
test-unit-context (0.3.1)
|
99
|
+
test-unit (>= 2.4.0)
|
100
|
+
thor (0.18.1)
|
101
|
+
thread_safe (0.1.2)
|
102
|
+
atomic
|
103
|
+
thread_safe (0.1.2-java)
|
104
|
+
atomic
|
105
|
+
tilt (1.4.1)
|
106
|
+
treetop (1.4.15)
|
107
|
+
polyglot
|
108
|
+
polyglot (>= 0.3.1)
|
109
|
+
tzinfo (0.3.37)
|
110
|
+
|
111
|
+
PLATFORMS
|
112
|
+
java
|
113
|
+
ruby
|
114
|
+
|
115
|
+
DEPENDENCIES
|
116
|
+
activerecord
|
117
|
+
appraisal
|
118
|
+
bcrypt-ruby (~> 3.0.0)
|
119
|
+
jruby-openssl
|
120
|
+
mocha (~> 0.13.1)
|
121
|
+
mysql2
|
122
|
+
pg
|
123
|
+
rails!
|
124
|
+
rake
|
125
|
+
simplecov
|
126
|
+
sqlite3
|
127
|
+
test-unit (= 2.5.4)
|
128
|
+
test-unit-context (>= 0.3.0)
|
129
|
+
thread_safe
|
data/lib/arjdbc/db2/as400.rb
CHANGED
@@ -91,9 +91,8 @@ module ArJdbc
|
|
91
91
|
|
92
92
|
# disable all schemas browsing when default schema is specified
|
93
93
|
def table_exists?(name)
|
94
|
-
|
95
|
-
|
96
|
-
@connection.table_exists?(name)
|
94
|
+
return false unless name
|
95
|
+
schema ? @connection.table_exists?(name, schema) : @connection.table_exists?(name)
|
97
96
|
end
|
98
97
|
|
99
98
|
DRIVER_NAME = 'com.ibm.as400.access.AS400JDBCDriver'.freeze
|
data/lib/arjdbc/derby/adapter.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
ArJdbc.load_java_part :Derby
|
2
2
|
|
3
3
|
require 'arjdbc/util/table_copier'
|
4
|
+
require 'arjdbc/derby/schema_creation' # AR 4.x
|
4
5
|
|
5
6
|
module ArJdbc
|
6
7
|
module Derby
|
@@ -223,13 +224,6 @@ module ArJdbc
|
|
223
224
|
new_table_definition(TableDefinition, *args)
|
224
225
|
end
|
225
226
|
|
226
|
-
# @override fix case where AR passes `:default => nil, :null => true`
|
227
|
-
def add_column_options!(sql, options)
|
228
|
-
options.delete(:default) if options.has_key?(:default) && options[:default].nil?
|
229
|
-
sql << " DEFAULT #{quote(options.delete(:default))}" if options.has_key?(:default)
|
230
|
-
super
|
231
|
-
end
|
232
|
-
|
233
227
|
# @override
|
234
228
|
def empty_insert_statement_value
|
235
229
|
'VALUES ( DEFAULT )' # won't work as Derby does need to know the columns count
|
@@ -270,37 +264,21 @@ module ArJdbc
|
|
270
264
|
add_column_sql = "ALTER TABLE #{quote_table_name(table_name)} ADD #{quote_column_name(column_name)} #{type_to_sql(type, options[:limit], options[:precision], options[:scale])}"
|
271
265
|
add_column_options!(add_column_sql, options)
|
272
266
|
execute(add_column_sql)
|
273
|
-
end
|
274
|
-
|
275
|
-
# SELECT DISTINCT clause for a given set of columns and a given ORDER BY clause.
|
276
|
-
#
|
277
|
-
# Derby requires the ORDER BY columns in the select list for distinct queries, and
|
278
|
-
# requires that the ORDER BY include the distinct column.
|
279
|
-
# ```
|
280
|
-
# distinct("posts.id", "posts.created_at desc")
|
281
|
-
# ```
|
282
|
-
# @note This is based on distinct method for the PostgreSQL Adapter.
|
283
|
-
# @override
|
284
|
-
def distinct(columns, order_by)
|
285
|
-
return "DISTINCT #{columns}" if order_by.blank?
|
286
|
-
|
287
|
-
# construct a clean list of column names from the ORDER BY clause, removing
|
288
|
-
# any asc/desc modifiers
|
289
|
-
order_columns = [order_by].flatten.map{|o| o.split(',').collect { |s| s.split.first } }.flatten.reject(&:blank?)
|
290
|
-
order_columns = order_columns.zip((0...order_columns.size).to_a).map { |s,i| "#{s} AS alias_#{i}" }
|
267
|
+
end unless const_defined? :SchemaCreation
|
291
268
|
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
sql
|
296
|
-
|
269
|
+
# @override fix case where AR passes `:default => nil, :null => true`
|
270
|
+
def add_column_options!(sql, options)
|
271
|
+
options.delete(:default) if options.has_key?(:default) && options[:default].nil?
|
272
|
+
sql << " DEFAULT #{quote(options.delete(:default))}" if options.has_key?(:default)
|
273
|
+
super
|
274
|
+
end unless const_defined? :SchemaCreation
|
297
275
|
|
298
276
|
# @override
|
299
277
|
def remove_column(table_name, *column_names)
|
300
278
|
for column_name in column_names.flatten
|
301
279
|
execute "ALTER TABLE #{quote_table_name(table_name)} DROP COLUMN #{quote_column_name(column_name)} RESTRICT"
|
302
280
|
end
|
303
|
-
end
|
281
|
+
end unless const_defined? :SchemaCreation
|
304
282
|
|
305
283
|
# @override
|
306
284
|
def change_column(table_name, column_name, type, options = {})
|
@@ -354,6 +332,40 @@ module ArJdbc
|
|
354
332
|
" TO #{quote_column_name(new_column_name)}"
|
355
333
|
end
|
356
334
|
|
335
|
+
# SELECT DISTINCT clause for a given set of columns and a given ORDER BY clause.
|
336
|
+
#
|
337
|
+
# Derby requires the ORDER BY columns in the select list for distinct queries, and
|
338
|
+
# requires that the ORDER BY include the distinct column.
|
339
|
+
# ```
|
340
|
+
# distinct("posts.id", "posts.created_at desc")
|
341
|
+
# ```
|
342
|
+
# @note This is based on distinct method for the PostgreSQL Adapter.
|
343
|
+
# @override
|
344
|
+
def distinct(columns, order_by)
|
345
|
+
"DISTINCT #{columns_for_distinct(columns, order_by)}"
|
346
|
+
end
|
347
|
+
|
348
|
+
# @override Since AR 4.0 (on 4.1 {#distinct} is gone and won't be called).
|
349
|
+
def columns_for_distinct(columns, orders)
|
350
|
+
return columns if orders.blank?
|
351
|
+
|
352
|
+
# construct a clean list of column names from the ORDER BY clause,
|
353
|
+
# removing any ASC/DESC modifiers
|
354
|
+
order_columns = [ orders ]; order_columns.flatten! # AR 3.x vs 4.x
|
355
|
+
order_columns.map! do |column|
|
356
|
+
column = column.to_sql unless column.is_a?(String) # handle AREL node
|
357
|
+
column.split(',').collect! { |s| s.split.first }
|
358
|
+
end.flatten!
|
359
|
+
order_columns.reject!(&:blank?)
|
360
|
+
order_columns = order_columns.zip (0...order_columns.size).to_a
|
361
|
+
order_columns = order_columns.map { |s, i| "#{s} AS alias_#{i}" }
|
362
|
+
|
363
|
+
columns = [ columns ]; columns.flatten!
|
364
|
+
columns.push( *order_columns ).join(', ')
|
365
|
+
# return a DISTINCT clause that's distinct on the columns we want but
|
366
|
+
# includes all the required columns for the ORDER BY to work properly
|
367
|
+
end
|
368
|
+
|
357
369
|
# @override
|
358
370
|
def primary_keys(table_name)
|
359
371
|
@connection.primary_keys table_name.to_s.upcase
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module ArJdbc
|
2
|
+
module Derby
|
3
|
+
# @private
|
4
|
+
class SchemaCreation < ::ActiveRecord::ConnectionAdapters::AbstractAdapter::SchemaCreation
|
5
|
+
|
6
|
+
private
|
7
|
+
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
def schema_creation
|
12
|
+
SchemaCreation.new self
|
13
|
+
end
|
14
|
+
|
15
|
+
end if ::ActiveRecord::ConnectionAdapters::AbstractAdapter.const_defined? :SchemaCreation
|
@@ -1,5 +1,6 @@
|
|
1
1
|
ArJdbc.load_java_part :HSQLDB
|
2
2
|
require 'arjdbc/hsqldb/explain_support'
|
3
|
+
require 'arjdbc/hsqldb/schema_creation' # AR 4.x
|
3
4
|
|
4
5
|
module ArJdbc
|
5
6
|
module HSQLDB
|
@@ -166,7 +167,7 @@ module ArJdbc
|
|
166
167
|
add_column_sql = "ALTER TABLE #{quote_table_name(table_name)} ADD #{quote_column_name(column_name)} #{type_to_sql(type, options[:limit], options[:precision], options[:scale])}"
|
167
168
|
add_column_options!(add_column_sql, options)
|
168
169
|
execute(add_column_sql)
|
169
|
-
end
|
170
|
+
end unless const_defined? :SchemaCreation
|
170
171
|
|
171
172
|
# @override
|
172
173
|
def change_column(table_name, column_name, type, options = {})
|
@@ -0,0 +1,11 @@
|
|
1
|
+
module ArJdbc
|
2
|
+
module HSQLDB
|
3
|
+
# @private
|
4
|
+
SchemaCreation = ::ActiveRecord::ConnectionAdapters::AbstractAdapter::SchemaCreation
|
5
|
+
|
6
|
+
def schema_creation
|
7
|
+
SchemaCreation.new self
|
8
|
+
end
|
9
|
+
|
10
|
+
end
|
11
|
+
end if ::ActiveRecord::ConnectionAdapters::AbstractAdapter.const_defined? :SchemaCreation
|
data/lib/arjdbc/jdbc/adapter.rb
CHANGED
@@ -64,14 +64,15 @@ module ActiveRecord
|
|
64
64
|
@config[:adapter_spec] = adapter_spec(@config) unless @config.key?(:adapter_spec)
|
65
65
|
spec = @config[:adapter_spec]
|
66
66
|
|
67
|
-
# kind of like `extend ArJdbc::MyDB if self.class == JdbcAdapter` :
|
68
|
-
klass = @config[:adapter_class]
|
69
|
-
extend spec if spec && ( ! klass || klass == JdbcAdapter)
|
70
67
|
# NOTE: adapter spec's init_connection only called if instantiated here :
|
71
68
|
connection ||= jdbc_connection_class(spec).new(@config, self)
|
72
69
|
|
73
70
|
super(connection, logger)
|
74
71
|
|
72
|
+
# kind of like `extend ArJdbc::MyDB if self.class == JdbcAdapter` :
|
73
|
+
klass = @config[:adapter_class]
|
74
|
+
extend spec if spec && ( ! klass || klass == JdbcAdapter)
|
75
|
+
|
75
76
|
# NOTE: should not be necessary for JNDI due reconnect! on checkout :
|
76
77
|
configure_connection if respond_to?(:configure_connection)
|
77
78
|
|
@@ -571,6 +572,7 @@ module ActiveRecord
|
|
571
572
|
|
572
573
|
# @override
|
573
574
|
def table_exists?(name)
|
575
|
+
return false unless name
|
574
576
|
@connection.table_exists?(name) # schema_name = nil
|
575
577
|
end
|
576
578
|
|
@@ -702,6 +704,20 @@ module ActiveRecord
|
|
702
704
|
end
|
703
705
|
private :new_table_definition
|
704
706
|
|
707
|
+
#
|
708
|
+
|
709
|
+
# Provides backwards-compatibility on ActiveRecord 4.1 for DB adapters
|
710
|
+
# that override this and than call super expecting to work.
|
711
|
+
# @note This method is available in 4.0 but won't be in 4.1
|
712
|
+
# @private
|
713
|
+
def add_column_options!(sql, options)
|
714
|
+
sql << " DEFAULT #{quote(options[:default], options[:column])}" if options_include_default?(options)
|
715
|
+
# must explicitly check for :null to allow change_column to work on migrations
|
716
|
+
sql << " NOT NULL" if options[:null] == false
|
717
|
+
sql << " AUTO_INCREMENT" if options[:auto_increment] == true
|
718
|
+
end
|
719
|
+
public :add_column_options!
|
720
|
+
|
705
721
|
end
|
706
722
|
|
707
723
|
# @return whether `:prepared_statements` are to be used
|
Binary file
|
data/lib/arjdbc/mssql/adapter.rb
CHANGED
@@ -363,9 +363,24 @@ module ArJdbc
|
|
363
363
|
|
364
364
|
# @override
|
365
365
|
def change_column(table_name, column_name, type, options = {})
|
366
|
+
|
367
|
+
indexes = []
|
368
|
+
column_object = columns(table_name).detect { |c| c.name.to_s == column_name.to_s }
|
369
|
+
|
370
|
+
if options_include_default?(options) || (column_object && column_object.type != type.to_sym)
|
371
|
+
remove_default_constraint(table_name, column_name)
|
372
|
+
indexes = indexes(table_name).select{ |index| index.columns.include?(column_name.to_s) }
|
373
|
+
remove_indexes(table_name, column_name)
|
374
|
+
end
|
375
|
+
|
366
376
|
clear_cached_table(table_name)
|
367
377
|
change_column_type(table_name, column_name, type, options)
|
368
378
|
change_column_default(table_name, column_name, options[:default]) if options_include_default?(options)
|
379
|
+
|
380
|
+
#Add any removed indexes back
|
381
|
+
indexes.each do |index|
|
382
|
+
execute "CREATE INDEX #{quote_table_name(index.name)} ON #{quote_table_name(table_name)} (#{index.columns.collect {|c|quote_column_name(c)}.join(', ')})"
|
383
|
+
end
|
369
384
|
end
|
370
385
|
|
371
386
|
def change_column_type(table_name, column_name, type, options = {})
|
data/lib/arjdbc/mysql/adapter.rb
CHANGED
@@ -4,6 +4,7 @@ require 'bigdecimal'
|
|
4
4
|
require 'active_record/connection_adapters/abstract/schema_definitions'
|
5
5
|
require 'arjdbc/mysql/column'
|
6
6
|
require 'arjdbc/mysql/explain_support'
|
7
|
+
require 'arjdbc/mysql/schema_creation' # AR 4.x
|
7
8
|
|
8
9
|
module ArJdbc
|
9
10
|
module MySQL
|
@@ -384,12 +385,12 @@ module ArJdbc
|
|
384
385
|
add_column_options!(add_column_sql, options)
|
385
386
|
add_column_position!(add_column_sql, options)
|
386
387
|
execute(add_column_sql)
|
387
|
-
end
|
388
|
+
end unless const_defined? :SchemaCreation
|
388
389
|
|
389
390
|
def change_column_default(table_name, column_name, default)
|
390
391
|
column = column_for(table_name, column_name)
|
391
392
|
change_column table_name, column_name, column.sql_type, :default => default
|
392
|
-
end
|
393
|
+
end # unless const_defined? :SchemaCreation
|
393
394
|
|
394
395
|
def change_column_null(table_name, column_name, null, default = nil)
|
395
396
|
column = column_for(table_name, column_name)
|
@@ -399,7 +400,7 @@ module ArJdbc
|
|
399
400
|
end
|
400
401
|
|
401
402
|
change_column table_name, column_name, column.sql_type, :null => null
|
402
|
-
end
|
403
|
+
end # unless const_defined? :SchemaCreation
|
403
404
|
|
404
405
|
# @override
|
405
406
|
def change_column(table_name, column_name, type, options = {})
|
@@ -417,7 +418,7 @@ module ArJdbc
|
|
417
418
|
add_column_options!(change_column_sql, options)
|
418
419
|
add_column_position!(change_column_sql, options)
|
419
420
|
execute(change_column_sql)
|
420
|
-
end
|
421
|
+
end unless const_defined? :SchemaCreation
|
421
422
|
|
422
423
|
# @override
|
423
424
|
def rename_column(table_name, column_name, new_column_name)
|
@@ -432,7 +433,15 @@ module ArJdbc
|
|
432
433
|
add_column_options!(rename_column_sql, options)
|
433
434
|
execute(rename_column_sql)
|
434
435
|
rename_column_indexes(table_name, column_name, new_column_name) if respond_to?(:rename_column_indexes) # AR-4.0 SchemaStatements
|
435
|
-
end
|
436
|
+
end # unless const_defined? :SchemaCreation
|
437
|
+
|
438
|
+
def add_column_position!(sql, options)
|
439
|
+
if options[:first]
|
440
|
+
sql << " FIRST"
|
441
|
+
elsif options[:after]
|
442
|
+
sql << " AFTER #{quote_column_name(options[:after])}"
|
443
|
+
end
|
444
|
+
end unless const_defined? :SchemaCreation
|
436
445
|
|
437
446
|
# @note Only used with (non-AREL) ActiveRecord **2.3**.
|
438
447
|
# @see Arel::Visitors::MySQL
|
@@ -515,14 +524,6 @@ module ArJdbc
|
|
515
524
|
end
|
516
525
|
end
|
517
526
|
|
518
|
-
def add_column_position!(sql, options)
|
519
|
-
if options[:first]
|
520
|
-
sql << " FIRST"
|
521
|
-
elsif options[:after]
|
522
|
-
sql << " AFTER #{quote_column_name(options[:after])}"
|
523
|
-
end
|
524
|
-
end
|
525
|
-
|
526
527
|
# @override
|
527
528
|
def empty_insert_statement_value
|
528
529
|
"VALUES ()"
|
@@ -0,0 +1,35 @@
|
|
1
|
+
module ArJdbc
|
2
|
+
module MySQL
|
3
|
+
# @private copied from native adapter 4.0/4.1
|
4
|
+
class SchemaCreation < ::ActiveRecord::ConnectionAdapters::AbstractAdapter::SchemaCreation
|
5
|
+
|
6
|
+
def visit_AddColumn(o)
|
7
|
+
add_column_position!(super, column_options(o))
|
8
|
+
end
|
9
|
+
|
10
|
+
private
|
11
|
+
def visit_ChangeColumnDefinition(o)
|
12
|
+
column = o.column
|
13
|
+
options = o.options
|
14
|
+
sql_type = type_to_sql(o.type, options[:limit], options[:precision], options[:scale])
|
15
|
+
change_column_sql = "CHANGE #{quote_column_name(column.name)} #{quote_column_name(options[:name])} #{sql_type}"
|
16
|
+
add_column_options!(change_column_sql, options)
|
17
|
+
add_column_position!(change_column_sql, options)
|
18
|
+
end
|
19
|
+
|
20
|
+
def add_column_position!(sql, options)
|
21
|
+
if options[:first]
|
22
|
+
sql << " FIRST"
|
23
|
+
elsif options[:after]
|
24
|
+
sql << " AFTER #{quote_column_name(options[:after])}"
|
25
|
+
end
|
26
|
+
sql
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def schema_creation
|
32
|
+
SchemaCreation.new self
|
33
|
+
end
|
34
|
+
|
35
|
+
end if ::ActiveRecord::ConnectionAdapters::AbstractAdapter.const_defined? :SchemaCreation
|
@@ -295,16 +295,27 @@ module ArJdbc
|
|
295
295
|
# making every row the same.
|
296
296
|
#
|
297
297
|
# distinct("posts.id", "posts.created_at desc")
|
298
|
+
#
|
299
|
+
# @override
|
298
300
|
def distinct(columns, order_by)
|
299
|
-
|
301
|
+
"DISTINCT #{columns_for_distinct(columns, order_by)}"
|
302
|
+
end
|
300
303
|
|
304
|
+
# @override Since AR 4.0 (on 4.1 {#distinct} is gone and won't be called).
|
305
|
+
def columns_for_distinct(columns, orders)
|
306
|
+
return columns if orders.blank?
|
307
|
+
if orders.is_a?(Array) # AR 3.x vs 4.x
|
308
|
+
orders = orders.map { |column| column.is_a?(String) ? column : column.to_sql }
|
309
|
+
else
|
310
|
+
orders = extract_order_columns(orders)
|
311
|
+
end
|
301
312
|
# construct a valid DISTINCT clause, ie. one that includes the ORDER BY columns, using
|
302
313
|
# FIRST_VALUE such that the inclusion of these columns doesn't invalidate the DISTINCT
|
303
|
-
order_columns =
|
314
|
+
order_columns = orders.map do |c, i|
|
304
315
|
"FIRST_VALUE(#{c.split.first}) OVER (PARTITION BY #{columns} ORDER BY #{c}) AS alias_#{i}__"
|
305
316
|
end
|
306
|
-
|
307
|
-
|
317
|
+
columns = [ columns ]; columns.flatten!
|
318
|
+
columns.push( *order_columns ).join(', ')
|
308
319
|
end
|
309
320
|
|
310
321
|
# ORDER BY clause for the passed order option.
|
@@ -11,6 +11,7 @@ module ArJdbc
|
|
11
11
|
|
12
12
|
require 'arjdbc/postgresql/column'
|
13
13
|
require 'arjdbc/postgresql/explain_support'
|
14
|
+
require 'arjdbc/postgresql/schema_creation' # AR 4.x
|
14
15
|
|
15
16
|
# @see ActiveRecord::ConnectionAdapters::JdbcAdapter#jdbc_connection_class
|
16
17
|
def self.jdbc_connection_class
|
@@ -250,13 +251,6 @@ module ArJdbc
|
|
250
251
|
super + [:array]
|
251
252
|
end if AR4_COMPAT
|
252
253
|
|
253
|
-
if ActiveRecord::VERSION::MAJOR > 3
|
254
|
-
|
255
|
-
require 'arjdbc/postgresql/schema_creation'
|
256
|
-
def schema_creation; SchemaCreation.new(self); end
|
257
|
-
|
258
|
-
end
|
259
|
-
|
260
254
|
# Enable standard-conforming strings if available.
|
261
255
|
def set_standard_conforming_strings
|
262
256
|
self.standard_conforming_strings=(true)
|
@@ -753,29 +747,28 @@ module ArJdbc
|
|
753
747
|
@multi_column_index_limit = limit
|
754
748
|
end
|
755
749
|
|
756
|
-
#
|
757
|
-
|
758
|
-
|
750
|
+
# @override
|
751
|
+
def distinct(columns, orders)
|
752
|
+
"DISTINCT #{columns_for_distinct(columns, orders)}"
|
753
|
+
end
|
754
|
+
|
759
755
|
# PostgreSQL requires the ORDER BY columns in the select list for distinct
|
760
756
|
# queries, and requires that the ORDER BY include the distinct column.
|
761
|
-
#
|
762
|
-
|
763
|
-
# # => "DISTINCT posts.id, posts.created_at AS alias_0"
|
764
|
-
def distinct(columns, orders)
|
757
|
+
# @override Since AR 4.0 (on 4.1 {#distinct} is gone and won't be called).
|
758
|
+
def columns_for_distinct(columns, orders)
|
765
759
|
if orders.is_a?(String)
|
766
760
|
orders = orders.split(','); orders.each(&:strip!)
|
767
761
|
end
|
768
762
|
|
769
|
-
order_columns = orders.map do |column|
|
763
|
+
order_columns = orders.reject(&:blank?).map! do |column|
|
770
764
|
column = column.to_sql unless column.is_a?(String) # handle AREL node
|
771
765
|
column.gsub(/\s+(ASC|DESC)\s*(NULLS\s+(FIRST|LAST)\s*)?/i, '') # remove ASC/DESC
|
772
|
-
end
|
773
|
-
|
774
|
-
return "DISTINCT #{columns}" if order_columns.empty?
|
775
|
-
|
766
|
+
end
|
767
|
+
order_columns.reject!(&:blank?)
|
776
768
|
i = -1; order_columns.map! { |c| "#{c} AS alias_#{i += 1}" }
|
777
769
|
|
778
|
-
|
770
|
+
columns = [ columns ]; columns.flatten!
|
771
|
+
columns.push( *order_columns ).join(', ')
|
779
772
|
end
|
780
773
|
|
781
774
|
# ORDER BY clause for the passed order option.
|
@@ -975,7 +968,7 @@ module ArJdbc
|
|
975
968
|
|
976
969
|
change_column_default(table_name, column_name, default) if options_include_default?(options)
|
977
970
|
change_column_null(table_name, column_name, false, default) if notnull
|
978
|
-
end
|
971
|
+
end if ActiveRecord::VERSION::MAJOR < 4
|
979
972
|
|
980
973
|
# Changes the column of a table.
|
981
974
|
def change_column(table_name, column_name, type, options = {})
|
@@ -1004,24 +997,24 @@ module ArJdbc
|
|
1004
997
|
|
1005
998
|
change_column_default(table_name, column_name, options[:default]) if options_include_default?(options)
|
1006
999
|
change_column_null(table_name, column_name, options[:null], options[:default]) if options.key?(:null)
|
1007
|
-
end
|
1000
|
+
end # unless const_defined? :SchemaCreation
|
1008
1001
|
|
1009
1002
|
# Changes the default value of a table column.
|
1010
1003
|
def change_column_default(table_name, column_name, default)
|
1011
1004
|
execute "ALTER TABLE #{quote_table_name(table_name)} ALTER COLUMN #{quote_column_name(column_name)} SET DEFAULT #{quote(default)}"
|
1012
|
-
end
|
1005
|
+
end # unless const_defined? :SchemaCreation
|
1013
1006
|
|
1014
1007
|
def change_column_null(table_name, column_name, null, default = nil)
|
1015
1008
|
unless null || default.nil?
|
1016
1009
|
execute("UPDATE #{quote_table_name(table_name)} SET #{quote_column_name(column_name)}=#{quote(default)} WHERE #{quote_column_name(column_name)} IS NULL")
|
1017
1010
|
end
|
1018
1011
|
execute("ALTER TABLE #{quote_table_name(table_name)} ALTER #{quote_column_name(column_name)} #{null ? 'DROP' : 'SET'} NOT NULL")
|
1019
|
-
end
|
1012
|
+
end # unless const_defined? :SchemaCreation
|
1020
1013
|
|
1021
1014
|
def rename_column(table_name, column_name, new_column_name)
|
1022
1015
|
execute "ALTER TABLE #{quote_table_name(table_name)} RENAME COLUMN #{quote_column_name(column_name)} TO #{quote_column_name(new_column_name)}"
|
1023
1016
|
rename_column_indexes(table_name, column_name, new_column_name) if respond_to?(:rename_column_indexes) # AR-4.0 SchemaStatements
|
1024
|
-
end
|
1017
|
+
end # unless const_defined? :SchemaCreation
|
1025
1018
|
|
1026
1019
|
def add_index(table_name, column_name, options = {})
|
1027
1020
|
index_name, index_type, index_columns, index_options, index_algorithm, index_using = add_index_options(table_name, column_name, options)
|
@@ -1,7 +1,7 @@
|
|
1
|
-
# NOTE: kindly borrowed from AR 4.0.0 (rc1) - only to be used on AR >= 4.0 !
|
2
1
|
module ArJdbc
|
3
2
|
module PostgreSQL
|
4
|
-
|
3
|
+
# @private copied from native adapter 4.0/4.1
|
4
|
+
class SchemaCreation < ::ActiveRecord::ConnectionAdapters::AbstractAdapter::SchemaCreation
|
5
5
|
|
6
6
|
private
|
7
7
|
|
@@ -32,7 +32,11 @@ module ArJdbc
|
|
32
32
|
super
|
33
33
|
end
|
34
34
|
end
|
35
|
+
end
|
35
36
|
|
37
|
+
def schema_creation
|
38
|
+
SchemaCreation.new self
|
36
39
|
end
|
40
|
+
|
37
41
|
end
|
38
|
-
end
|
42
|
+
end if ::ActiveRecord::ConnectionAdapters::AbstractAdapter.const_defined? :SchemaCreation
|
@@ -1,7 +1,7 @@
|
|
1
1
|
raise "ArJdbc needs rake 0.9.x or newer" unless Rake.const_defined?(:VERSION)
|
2
2
|
|
3
3
|
Rake::DSL.module_eval do
|
4
|
-
|
4
|
+
|
5
5
|
def redefine_task(*args, &block)
|
6
6
|
if Hash === args.first
|
7
7
|
task_name = args.first.keys[0]
|
@@ -10,9 +10,9 @@ Rake::DSL.module_eval do
|
|
10
10
|
task_name = args.first; old_prereqs = []
|
11
11
|
# args[0] = { task_name => old_prereqs }
|
12
12
|
end
|
13
|
-
|
13
|
+
|
14
14
|
full_name = Rake::Task.scope_name(Rake.application.current_scope, task_name)
|
15
|
-
|
15
|
+
|
16
16
|
if old_task = Rake.application.lookup(task_name)
|
17
17
|
old_comment = old_task.full_comment
|
18
18
|
old_prereqs = old_task.prerequisites.dup if old_prereqs
|
@@ -25,14 +25,14 @@ Rake::DSL.module_eval do
|
|
25
25
|
else
|
26
26
|
# raise "could not find rake task with (full) name '#{full_name}'"
|
27
27
|
end
|
28
|
-
|
28
|
+
|
29
29
|
new_task = task(*args, &block)
|
30
30
|
new_task.comment = old_comment # if old_comment
|
31
31
|
new_task.actions.concat(old_actions) if old_actions
|
32
32
|
new_task.prerequisites.concat(old_prereqs) if old_prereqs
|
33
33
|
new_task
|
34
34
|
end
|
35
|
-
|
35
|
+
|
36
36
|
end
|
37
37
|
|
38
38
|
namespace :db do
|
@@ -40,44 +40,42 @@ namespace :db do
|
|
40
40
|
def rails_env
|
41
41
|
defined?(Rails.env) ? Rails.env : ( RAILS_ENV || 'development' )
|
42
42
|
end
|
43
|
-
|
43
|
+
|
44
44
|
def adapt_jdbc_config(config)
|
45
45
|
return config unless config['adapter']
|
46
46
|
config.merge 'adapter' => config['adapter'].sub(/^jdbc/, '')
|
47
47
|
end
|
48
|
-
|
48
|
+
|
49
49
|
if defined? ActiveRecord::Tasks::DatabaseTasks # 4.0
|
50
|
-
|
50
|
+
|
51
51
|
def current_config(options = {})
|
52
52
|
ActiveRecord::Tasks::DatabaseTasks.current_config(options)
|
53
53
|
end
|
54
|
-
|
54
|
+
|
55
55
|
else # 3.x / 2.3
|
56
|
-
|
56
|
+
|
57
57
|
def current_config(options = {}) # not on 2.3
|
58
58
|
options = { :env => rails_env }.merge! options
|
59
59
|
if options[:config]
|
60
60
|
@current_config = options[:config]
|
61
61
|
else
|
62
|
-
@current_config ||=
|
63
|
-
|
64
|
-
database_url_config
|
65
|
-
else
|
66
|
-
ActiveRecord::Base.configurations[options[:env]]
|
67
|
-
end
|
62
|
+
@current_config ||= ENV['DATABASE_URL'] ?
|
63
|
+
database_url_config : ActiveRecord::Base.configurations[options[:env]]
|
68
64
|
end
|
69
65
|
end
|
70
66
|
|
71
67
|
def database_url_config(url = ENV['DATABASE_URL'])
|
68
|
+
# NOTE: ActiveRecord::ConnectionAdapters::ConnectionSpecification::Resolver
|
69
|
+
# since AR 4.0 that is handled by DatabaseTasks - only care about 2.3/3.x :
|
72
70
|
unless defined? ActiveRecord::Base::ConnectionSpecification::Resolver
|
73
|
-
raise "
|
71
|
+
raise "DATABASE_URL not supported on ActiveRecord #{ActiveRecord::VERSION::STRING}"
|
74
72
|
end
|
75
|
-
|
76
|
-
|
73
|
+
resolver = ActiveRecord::Base::ConnectionSpecification::Resolver.new(url, {})
|
74
|
+
resolver.spec.config.stringify_keys
|
77
75
|
end
|
78
|
-
|
76
|
+
|
79
77
|
end
|
80
|
-
|
78
|
+
|
81
79
|
end
|
82
80
|
|
83
81
|
require 'arjdbc/tasks/database_tasks'
|
data/lib/arjdbc/version.rb
CHANGED
data/pom.xml
CHANGED
@@ -72,19 +72,15 @@
|
|
72
72
|
<artifactId>jruby-complete</artifactId>
|
73
73
|
<version>${jruby.version}</version>
|
74
74
|
</dependency>
|
75
|
-
|
76
|
-
<!-- e.g.
|
77
|
-
mvn install:install-file -DgroupId=org.postgresql -DartifactId=pgjdbc -Dversion=9.2-1002 -Dpackaging=jar -Dfile=./jdbc-postgres/lib/postgresql-9.2-1002.jdbc4.jar
|
78
|
-
-->
|
79
75
|
<dependency>
|
80
76
|
<groupId>org.postgresql</groupId>
|
81
|
-
<artifactId>
|
82
|
-
<version>9.2-
|
77
|
+
<artifactId>postgresql</artifactId>
|
78
|
+
<version>9.2-1003-jdbc4</version>
|
83
79
|
</dependency>
|
84
80
|
</dependencies>
|
85
81
|
|
86
82
|
<build>
|
87
|
-
|
83
|
+
|
88
84
|
<sourceDirectory>src/java</sourceDirectory>
|
89
85
|
<resources>
|
90
86
|
<resource>
|
@@ -102,7 +102,7 @@ public class RubyJdbcConnection extends RubyObject {
|
|
102
102
|
super(runtime, metaClass);
|
103
103
|
}
|
104
104
|
|
105
|
-
private static ObjectAllocator
|
105
|
+
private static final ObjectAllocator ALLOCATOR = new ObjectAllocator() {
|
106
106
|
public IRubyObject allocate(Ruby runtime, RubyClass klass) {
|
107
107
|
return new RubyJdbcConnection(runtime, klass);
|
108
108
|
}
|
@@ -110,7 +110,7 @@ public class RubyJdbcConnection extends RubyObject {
|
|
110
110
|
|
111
111
|
public static RubyClass createJdbcConnectionClass(final Ruby runtime) {
|
112
112
|
RubyClass jdbcConnection = getConnectionAdapters(runtime).
|
113
|
-
defineClassUnder("JdbcConnection", runtime.getObject(),
|
113
|
+
defineClassUnder("JdbcConnection", runtime.getObject(), ALLOCATOR);
|
114
114
|
jdbcConnection.defineAnnotatedMethods(RubyJdbcConnection.class);
|
115
115
|
return jdbcConnection;
|
116
116
|
}
|
@@ -36,6 +36,7 @@ import java.sql.Statement;
|
|
36
36
|
import java.sql.Timestamp;
|
37
37
|
import java.sql.Types;
|
38
38
|
import java.util.List;
|
39
|
+
import java.util.Map;
|
39
40
|
import java.util.UUID;
|
40
41
|
|
41
42
|
import org.jruby.Ruby;
|
@@ -43,6 +44,7 @@ import org.jruby.RubyArray;
|
|
43
44
|
import org.jruby.RubyBoolean;
|
44
45
|
import org.jruby.RubyClass;
|
45
46
|
import org.jruby.RubyFloat;
|
47
|
+
import org.jruby.RubyHash;
|
46
48
|
import org.jruby.RubyIO;
|
47
49
|
import org.jruby.RubyString;
|
48
50
|
import org.jruby.anno.JRubyMethod;
|
@@ -388,13 +390,23 @@ public class PostgreSQLRubyJdbcConnection extends arjdbc.jdbc.RubyJdbcConnection
|
|
388
390
|
return sqlType;
|
389
391
|
}
|
390
392
|
|
393
|
+
private static final int HSTORE_TYPE = 100000 + 1111;
|
394
|
+
|
391
395
|
@Override
|
392
396
|
protected int jdbcTypeFor(final ThreadContext context, final Ruby runtime,
|
393
397
|
final IRubyObject column, final Object value) throws SQLException {
|
394
398
|
// NOTE: likely wrong but native adapters handles this thus we should
|
395
399
|
// too - used from #table_exists? `binds << [ nil, schema ] if schema`
|
396
400
|
if ( column == null || column.isNil() ) return Types.VARCHAR; // assume type == :string
|
397
|
-
|
401
|
+
final int type = super.jdbcTypeFor(context, runtime, column, value);
|
402
|
+
/*
|
403
|
+
if ( type == Types.OTHER ) {
|
404
|
+
final IRubyObject columnType = column.callMethod(context, "type");
|
405
|
+
if ( "hstore" == (Object) columnType.asJavaString() ) {
|
406
|
+
return HSTORE_TYPE;
|
407
|
+
}
|
408
|
+
} */
|
409
|
+
return type;
|
398
410
|
}
|
399
411
|
|
400
412
|
/**
|
@@ -467,6 +479,7 @@ public class PostgreSQLRubyJdbcConnection extends arjdbc.jdbc.RubyJdbcConnection
|
|
467
479
|
protected IRubyObject objectToRuby(final ThreadContext context,
|
468
480
|
final Ruby runtime, final ResultSet resultSet, final int column)
|
469
481
|
throws SQLException {
|
482
|
+
|
470
483
|
final Object object = resultSet.getObject(column);
|
471
484
|
|
472
485
|
if ( object == null && resultSet.wasNull() ) return runtime.getNil();
|
@@ -485,6 +498,16 @@ public class PostgreSQLRubyJdbcConnection extends arjdbc.jdbc.RubyJdbcConnection
|
|
485
498
|
return runtime.newString( object.toString() );
|
486
499
|
}
|
487
500
|
|
501
|
+
if ( object instanceof Map ) { // hstore
|
502
|
+
if ( rawHstoreType ) {
|
503
|
+
return runtime.newString( resultSet.getString(column) );
|
504
|
+
}
|
505
|
+
// by default we avoid double parsing by driver and than column :
|
506
|
+
final RubyHash rubyObject = RubyHash.newHash(runtime);
|
507
|
+
rubyObject.putAll((Map) object); // converts keys/values to ruby
|
508
|
+
return rubyObject;
|
509
|
+
}
|
510
|
+
|
488
511
|
return JavaUtil.convertJavaToRuby(runtime, object);
|
489
512
|
}
|
490
513
|
|
@@ -529,6 +552,24 @@ public class PostgreSQLRubyJdbcConnection extends arjdbc.jdbc.RubyJdbcConnection
|
|
529
552
|
return str.toString();
|
530
553
|
}
|
531
554
|
|
555
|
+
protected static boolean rawHstoreType = Boolean.getBoolean("arjdbc.postgresql.hstore.raw");
|
556
|
+
|
557
|
+
@JRubyMethod(name = "raw_hstore_type?")
|
558
|
+
public static IRubyObject useRawHstoreType(final ThreadContext context, final IRubyObject self) {
|
559
|
+
return context.getRuntime().newBoolean(rawHstoreType);
|
560
|
+
}
|
561
|
+
|
562
|
+
@JRubyMethod(name = "raw_hstore_type=")
|
563
|
+
public static IRubyObject setRawHstoreType(final IRubyObject self, final IRubyObject value) {
|
564
|
+
if ( value instanceof RubyBoolean ) {
|
565
|
+
rawHstoreType = ((RubyBoolean) value).isTrue();
|
566
|
+
}
|
567
|
+
else {
|
568
|
+
rawHstoreType = ! value.isNil();
|
569
|
+
}
|
570
|
+
return value;
|
571
|
+
}
|
572
|
+
|
532
573
|
// whether to use "raw" interval values off by default - due native adapter compatibilty :
|
533
574
|
// RAW values :
|
534
575
|
// - 2 years 0 mons 0 days 0 hours 3 mins 0.00 secs
|
@@ -549,7 +590,7 @@ public class PostgreSQLRubyJdbcConnection extends arjdbc.jdbc.RubyJdbcConnection
|
|
549
590
|
rawIntervalType = ((RubyBoolean) value).isTrue();
|
550
591
|
}
|
551
592
|
else {
|
552
|
-
rawIntervalType = value.isNil();
|
593
|
+
rawIntervalType = ! value.isNil();
|
553
594
|
}
|
554
595
|
return value;
|
555
596
|
}
|
metadata
CHANGED
@@ -1,15 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: activerecord-jdbc-adapter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
version: 1.3.0
|
4
|
+
version: 1.3.1
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Nick Sieger, Ola Bini and JRuby contributors
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date: 2013-
|
11
|
+
date: 2013-09-17 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: activerecord
|
@@ -18,13 +17,11 @@ dependencies:
|
|
18
17
|
- - '>='
|
19
18
|
- !ruby/object:Gem::Version
|
20
19
|
version: '2.2'
|
21
|
-
none: false
|
22
20
|
requirement: !ruby/object:Gem::Requirement
|
23
21
|
requirements:
|
24
22
|
- - '>='
|
25
23
|
- !ruby/object:Gem::Version
|
26
24
|
version: '2.2'
|
27
|
-
none: false
|
28
25
|
prerelease: false
|
29
26
|
type: :runtime
|
30
27
|
description: 'AR-JDBC is a database adapter for Rails'' ActiveRecord component designed
|
@@ -46,7 +43,6 @@ files:
|
|
46
43
|
- Appraisals
|
47
44
|
- CONTRIBUTING.md
|
48
45
|
- Gemfile
|
49
|
-
- Gemfile.lock
|
50
46
|
- History.md
|
51
47
|
- LICENSE.txt
|
52
48
|
- README.md
|
@@ -64,6 +60,8 @@ files:
|
|
64
60
|
- gemfiles/rails32.gemfile.lock
|
65
61
|
- gemfiles/rails40.gemfile
|
66
62
|
- gemfiles/rails40.gemfile.lock
|
63
|
+
- gemfiles/rails41.gemfile
|
64
|
+
- gemfiles/rails41.gemfile.lock
|
67
65
|
- lib/active_record/connection_adapters/as400_adapter.rb
|
68
66
|
- lib/active_record/connection_adapters/db2_adapter.rb
|
69
67
|
- lib/active_record/connection_adapters/derby_adapter.rb
|
@@ -97,6 +95,7 @@ files:
|
|
97
95
|
- lib/arjdbc/derby/active_record_patch.rb
|
98
96
|
- lib/arjdbc/derby/adapter.rb
|
99
97
|
- lib/arjdbc/derby/connection_methods.rb
|
98
|
+
- lib/arjdbc/derby/schema_creation.rb
|
100
99
|
- lib/arjdbc/discover.rb
|
101
100
|
- lib/arjdbc/firebird.rb
|
102
101
|
- lib/arjdbc/firebird/adapter.rb
|
@@ -108,6 +107,7 @@ files:
|
|
108
107
|
- lib/arjdbc/hsqldb/adapter.rb
|
109
108
|
- lib/arjdbc/hsqldb/connection_methods.rb
|
110
109
|
- lib/arjdbc/hsqldb/explain_support.rb
|
110
|
+
- lib/arjdbc/hsqldb/schema_creation.rb
|
111
111
|
- lib/arjdbc/informix.rb
|
112
112
|
- lib/arjdbc/informix/adapter.rb
|
113
113
|
- lib/arjdbc/informix/connection_methods.rb
|
@@ -145,6 +145,7 @@ files:
|
|
145
145
|
- lib/arjdbc/mysql/column.rb
|
146
146
|
- lib/arjdbc/mysql/connection_methods.rb
|
147
147
|
- lib/arjdbc/mysql/explain_support.rb
|
148
|
+
- lib/arjdbc/mysql/schema_creation.rb
|
148
149
|
- lib/arjdbc/oracle.rb
|
149
150
|
- lib/arjdbc/oracle/adapter.rb
|
150
151
|
- lib/arjdbc/oracle/column.rb
|
@@ -224,6 +225,7 @@ files:
|
|
224
225
|
homepage: https://github.com/jruby/activerecord-jdbc-adapter
|
225
226
|
licenses:
|
226
227
|
- BSD
|
228
|
+
metadata: {}
|
227
229
|
post_install_message:
|
228
230
|
rdoc_options:
|
229
231
|
- --main
|
@@ -237,22 +239,17 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
237
239
|
requirements:
|
238
240
|
- - '>='
|
239
241
|
- !ruby/object:Gem::Version
|
240
|
-
segments:
|
241
|
-
- 0
|
242
|
-
hash: 2
|
243
242
|
version: '0'
|
244
|
-
none: false
|
245
243
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
246
244
|
requirements:
|
247
245
|
- - '>='
|
248
246
|
- !ruby/object:Gem::Version
|
249
247
|
version: '0'
|
250
|
-
none: false
|
251
248
|
requirements: []
|
252
249
|
rubyforge_project: jruby-extras
|
253
|
-
rubygems_version: 1.
|
250
|
+
rubygems_version: 2.1.0
|
254
251
|
signing_key:
|
255
|
-
specification_version:
|
252
|
+
specification_version: 4
|
256
253
|
summary: JDBC adapter for ActiveRecord, for use within JRuby on Rails.
|
257
254
|
test_files: []
|
258
255
|
has_rdoc:
|
data/Gemfile.lock
DELETED
@@ -1,115 +0,0 @@
|
|
1
|
-
GIT
|
2
|
-
remote: git://github.com/kares/yard-method-overrides.git
|
3
|
-
revision: 7b4967860c997920ab6184a0bab7aa6b68f195a1
|
4
|
-
specs:
|
5
|
-
yard-method-overrides (0.2.0)
|
6
|
-
yard (>= 0.7.0)
|
7
|
-
|
8
|
-
GEM
|
9
|
-
remote: https://rubygems.org/
|
10
|
-
specs:
|
11
|
-
actionpack (3.2.14)
|
12
|
-
activemodel (= 3.2.14)
|
13
|
-
activesupport (= 3.2.14)
|
14
|
-
builder (~> 3.0.0)
|
15
|
-
erubis (~> 2.7.0)
|
16
|
-
journey (~> 1.0.4)
|
17
|
-
rack (~> 1.4.5)
|
18
|
-
rack-cache (~> 1.2)
|
19
|
-
rack-test (~> 0.6.1)
|
20
|
-
sprockets (~> 2.2.1)
|
21
|
-
activemodel (3.2.14)
|
22
|
-
activesupport (= 3.2.14)
|
23
|
-
builder (~> 3.0.0)
|
24
|
-
activerecord (3.2.14)
|
25
|
-
activemodel (= 3.2.14)
|
26
|
-
activesupport (= 3.2.14)
|
27
|
-
arel (~> 3.0.2)
|
28
|
-
tzinfo (~> 0.3.29)
|
29
|
-
activesupport (3.2.14)
|
30
|
-
i18n (~> 0.6, >= 0.6.4)
|
31
|
-
multi_json (~> 1.0)
|
32
|
-
appraisal (0.5.2)
|
33
|
-
bundler
|
34
|
-
rake
|
35
|
-
arel (3.0.2)
|
36
|
-
atomic (1.1.10)
|
37
|
-
atomic (1.1.10-java)
|
38
|
-
bcrypt-ruby (3.0.1)
|
39
|
-
bcrypt-ruby (3.0.1-java)
|
40
|
-
bouncy-castle-java (1.5.0147)
|
41
|
-
builder (3.0.4)
|
42
|
-
columnize (0.3.6)
|
43
|
-
erubis (2.7.0)
|
44
|
-
hike (1.2.3)
|
45
|
-
i18n (0.6.4)
|
46
|
-
journey (1.0.4)
|
47
|
-
jruby-openssl (0.8.8)
|
48
|
-
bouncy-castle-java (>= 1.5.0147)
|
49
|
-
kramdown (1.1.0)
|
50
|
-
linecache (0.46)
|
51
|
-
rbx-require-relative (> 0.0.4)
|
52
|
-
metaclass (0.0.1)
|
53
|
-
mocha (0.13.3)
|
54
|
-
metaclass (~> 0.0.1)
|
55
|
-
multi_json (1.7.7)
|
56
|
-
mysql2 (0.3.13)
|
57
|
-
pg (0.16.0)
|
58
|
-
rack (1.4.5)
|
59
|
-
rack-cache (1.2)
|
60
|
-
rack (>= 0.4)
|
61
|
-
rack-test (0.6.2)
|
62
|
-
rack (>= 1.0)
|
63
|
-
rake (10.1.0)
|
64
|
-
rbx-require-relative (0.0.9)
|
65
|
-
ruby-debug (0.10.4)
|
66
|
-
columnize (>= 0.1)
|
67
|
-
ruby-debug-base (~> 0.10.4.0)
|
68
|
-
ruby-debug-base (0.10.4)
|
69
|
-
linecache (>= 0.3)
|
70
|
-
ruby-debug-base (0.10.4-java)
|
71
|
-
simplecov (0.7.1)
|
72
|
-
multi_json (~> 1.0)
|
73
|
-
simplecov-html (~> 0.7.1)
|
74
|
-
simplecov-html (0.7.1)
|
75
|
-
sprockets (2.2.2)
|
76
|
-
hike (~> 1.2)
|
77
|
-
multi_json (~> 1.0)
|
78
|
-
rack (~> 1.0)
|
79
|
-
tilt (~> 1.1, != 1.3.0)
|
80
|
-
sqlite3 (1.3.8)
|
81
|
-
test-unit (2.5.4)
|
82
|
-
test-unit-context (0.3.1)
|
83
|
-
test-unit (>= 2.4.0)
|
84
|
-
thread_safe (0.1.2)
|
85
|
-
atomic
|
86
|
-
thread_safe (0.1.2-java)
|
87
|
-
atomic
|
88
|
-
tilt (1.4.1)
|
89
|
-
tzinfo (0.3.37)
|
90
|
-
yard (0.8.7)
|
91
|
-
|
92
|
-
PLATFORMS
|
93
|
-
java
|
94
|
-
ruby
|
95
|
-
|
96
|
-
DEPENDENCIES
|
97
|
-
actionpack
|
98
|
-
activerecord
|
99
|
-
appraisal
|
100
|
-
bcrypt-ruby (~> 3.0.0)
|
101
|
-
erubis
|
102
|
-
jruby-openssl
|
103
|
-
kramdown
|
104
|
-
mocha (~> 0.13.1)
|
105
|
-
mysql2
|
106
|
-
pg
|
107
|
-
rake
|
108
|
-
ruby-debug
|
109
|
-
simplecov
|
110
|
-
sqlite3
|
111
|
-
test-unit (= 2.5.4)
|
112
|
-
test-unit-context (>= 0.3.0)
|
113
|
-
thread_safe
|
114
|
-
yard
|
115
|
-
yard-method-overrides!
|