activerecord-jdbc-adapter 1.2.1 → 1.2.2
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.
- data/.travis.yml +3 -0
- data/Gemfile.lock +13 -15
- data/History.txt +19 -0
- data/README.rdoc +2 -0
- data/Rakefile +2 -1
- data/lib/arel/visitors/derby.rb +9 -2
- data/lib/arel/visitors/sql_server.rb +2 -0
- data/lib/arjdbc/db2/adapter.rb +3 -1
- data/lib/arjdbc/derby/adapter.rb +10 -3
- data/lib/arjdbc/jdbc/adapter.rb +5 -2
- data/lib/arjdbc/jdbc/adapter_java.jar +0 -0
- data/lib/arjdbc/jdbc/base_ext.rb +15 -0
- data/lib/arjdbc/jdbc/connection.rb +5 -1
- data/lib/arjdbc/jdbc/missing_functionality_helper.rb +1 -0
- data/lib/arjdbc/mssql/adapter.rb +31 -28
- data/lib/arjdbc/mssql/lock_helpers.rb +72 -0
- data/lib/arjdbc/mysql/adapter.rb +110 -45
- data/lib/arjdbc/oracle/adapter.rb +7 -0
- data/lib/arjdbc/postgresql/adapter.rb +327 -153
- data/lib/arjdbc/sqlite3/adapter.rb +9 -4
- data/lib/arjdbc/version.rb +1 -1
- data/rakelib/db.rake +17 -5
- data/src/java/arjdbc/jdbc/RubyJdbcConnection.java +14 -4
- data/src/java/arjdbc/postgresql/PostgresqlRubyJdbcConnection.java +25 -0
- data/test/db/jdbc.rb +4 -3
- data/test/db2_reset_column_information_test.rb +8 -0
- data/test/derby_reset_column_information_test.rb +8 -0
- data/test/derby_row_locking_test.rb +9 -0
- data/test/derby_simple_test.rb +40 -0
- data/test/h2_simple_test.rb +2 -2
- data/test/helper.rb +15 -2
- data/test/jdbc_common.rb +1 -0
- data/test/jndi_callbacks_test.rb +5 -9
- data/test/manualTestDatabase.rb +31 -31
- data/test/models/validates_uniqueness_of_string.rb +1 -1
- data/test/mssql_ignore_system_views_test.rb +27 -0
- data/test/mssql_null_test.rb +14 -0
- data/test/mssql_reset_column_information_test.rb +8 -0
- data/test/mssql_row_locking_sql_test.rb +159 -0
- data/test/mssql_row_locking_test.rb +9 -0
- data/test/mysql_reset_column_information_test.rb +8 -0
- data/test/mysql_simple_test.rb +69 -5
- data/test/oracle_reset_column_information_test.rb +8 -0
- data/test/oracle_specific_test.rb +1 -1
- data/test/postgres_nonseq_pkey_test.rb +1 -1
- data/test/postgres_reset_column_information_test.rb +8 -0
- data/test/postgres_simple_test.rb +72 -1
- data/test/row_locking.rb +90 -0
- data/test/simple.rb +82 -2
- data/test/sqlite3_reset_column_information_test.rb +8 -0
- data/test/sqlite3_simple_test.rb +47 -0
- data/test/sybase_reset_column_information_test.rb +8 -0
- metadata +33 -3
data/test/row_locking.rb
ADDED
@@ -0,0 +1,90 @@
|
|
1
|
+
#! /usr/bin/env jruby
|
2
|
+
|
3
|
+
require 'thread'
|
4
|
+
|
5
|
+
module RowLockingTestMethods
|
6
|
+
|
7
|
+
def test_row_locking
|
8
|
+
row_locking_test_template
|
9
|
+
end
|
10
|
+
|
11
|
+
def test_row_locking_with_limit
|
12
|
+
row_locking_test_template(:limit => 1)
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
|
17
|
+
def row_locking_test_template(options={})
|
18
|
+
# Create two rows that we will work with
|
19
|
+
@row1_id = Entry.create!(:title => "row1").id
|
20
|
+
@row2_id = Entry.create!(:title => "row2").id
|
21
|
+
|
22
|
+
@result_queue = Queue.new
|
23
|
+
signal_queue = Queue.new
|
24
|
+
t1 = Thread.new { thread_helper { thread1_main(signal_queue, options) } }
|
25
|
+
t2 = Thread.new { thread_helper { thread2_main(signal_queue, options) } }
|
26
|
+
t1.join
|
27
|
+
t2.join
|
28
|
+
|
29
|
+
result = []
|
30
|
+
result << @result_queue.shift until @result_queue.empty? # Convert the queue into an array
|
31
|
+
|
32
|
+
expected = [
|
33
|
+
:t1_locking_row2,
|
34
|
+
:t1_locked_row2,
|
35
|
+
|
36
|
+
:t2_locking_row1,
|
37
|
+
:t2_locked_row1,
|
38
|
+
|
39
|
+
:t2_locking_row2, # thread 2 tries to lock row2 ...
|
40
|
+
:t1_committed,
|
41
|
+
:t2_locked_row2, # ... but it doesn't succeed until after thread 1 commits its transaction
|
42
|
+
|
43
|
+
:t2_committed,
|
44
|
+
]
|
45
|
+
|
46
|
+
assert_equal expected, result, "thread2 should lock row1 immediately but wait for thread1 to commit before getting the lock on row2"
|
47
|
+
end
|
48
|
+
|
49
|
+
def thread1_main(signal_queue, options={})
|
50
|
+
Entry.transaction do
|
51
|
+
@result_queue << :t1_locking_row2
|
52
|
+
Entry.find(@row2_id, {:lock=>true}.merge(options)) # acquire a row lock on r2
|
53
|
+
@result_queue << :t1_locked_row2
|
54
|
+
signal_queue << :go # signal thread2 to start
|
55
|
+
sleep 2.0 # Wait for a few seconds, to allow the other thread to race with this thread.
|
56
|
+
@result_queue << :t1_committed
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
def thread2_main(signal_queue, options={})
|
61
|
+
Entry.transaction do
|
62
|
+
signal_queue.shift # wait until we get the signal from thread1
|
63
|
+
@result_queue << :t2_locking_row1
|
64
|
+
Entry.find(@row1_id, {:lock=>true}.merge(options)) # should return immediately
|
65
|
+
@result_queue << :t2_locked_row1
|
66
|
+
@result_queue << :t2_locking_row2
|
67
|
+
Entry.find(@row2_id, {:lock=>true}.merge(options)) # should block until thread1 commits its transaction
|
68
|
+
@result_queue << :t2_locked_row2
|
69
|
+
@result_queue << :t2_committed
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
def thread_helper
|
74
|
+
yield
|
75
|
+
rescue Exception => exc
|
76
|
+
# Output backtrace, since otherwise we won't see anything until the main thread joins this thread.
|
77
|
+
display_exception(exc)
|
78
|
+
raise
|
79
|
+
ensure
|
80
|
+
# This is needed. Otherwise, the database connections aren't returned to the pool and things break.
|
81
|
+
ActiveRecord::Base.connection_handler.clear_active_connections!
|
82
|
+
end
|
83
|
+
|
84
|
+
def display_exception(exception)
|
85
|
+
lines = []
|
86
|
+
lines << "#{exception.class.name}: #{exception.message}\n"
|
87
|
+
lines += exception.backtrace.map{|line| "\tfrom #{line}"}
|
88
|
+
$stderr.puts lines.join("\n")
|
89
|
+
end
|
90
|
+
end
|
data/test/simple.rb
CHANGED
@@ -98,6 +98,14 @@ end
|
|
98
98
|
module SimpleTestMethods
|
99
99
|
include FixtureSetup
|
100
100
|
|
101
|
+
def test_substitute_binds_has_no_side_effect_on_binds_parameter
|
102
|
+
binds = [[Entry.columns_hash['title'], 'test1']]
|
103
|
+
binds2 = binds.dup
|
104
|
+
sql = 'select * from entries where title = ?'
|
105
|
+
Entry.connection.substitute_binds(sql, binds)
|
106
|
+
assert_equal binds2, binds
|
107
|
+
end
|
108
|
+
|
101
109
|
def test_entries_created
|
102
110
|
assert ActiveRecord::Base.connection.tables.find{|t| t =~ /^entries$/i}, "entries not created"
|
103
111
|
end
|
@@ -358,6 +366,19 @@ module SimpleTestMethods
|
|
358
366
|
end
|
359
367
|
end
|
360
368
|
|
369
|
+
def test_remove_nonexistent_index
|
370
|
+
assert_raise(ArgumentError, ActiveRecord::StatementInvalid, ActiveRecord::JDBCError) do
|
371
|
+
@connection.remove_index :entries, :nonexistent_index
|
372
|
+
end
|
373
|
+
end
|
374
|
+
|
375
|
+
def test_add_index_with_invalid_name_length
|
376
|
+
index_name = 'x' * (@connection.index_name_length + 1)
|
377
|
+
assert_raise(ArgumentError) do
|
378
|
+
@connection.add_index "entries", "title", :name => index_name
|
379
|
+
end
|
380
|
+
end
|
381
|
+
|
361
382
|
def test_dumping_schema
|
362
383
|
require 'active_record/schema_dumper'
|
363
384
|
@connection.add_index :entries, :title
|
@@ -410,9 +431,9 @@ module SimpleTestMethods
|
|
410
431
|
|
411
432
|
class Animal < ActiveRecord::Base; end
|
412
433
|
|
413
|
-
# ENEBO: Is this really ar-jdbc-specific or a bug in our adapter?
|
414
434
|
def test_fetching_columns_for_nonexistent_table_should_raise
|
415
|
-
assert_raises(ActiveRecord::
|
435
|
+
assert_raises(ActiveRecord::ActiveRecordError,
|
436
|
+
ActiveRecord::StatementInvalid, ActiveRecord::JDBCError) do
|
416
437
|
Animal.columns
|
417
438
|
end
|
418
439
|
end
|
@@ -629,9 +650,68 @@ module ActiveRecord3TestMethods
|
|
629
650
|
end
|
630
651
|
|
631
652
|
module Tests
|
653
|
+
if ActiveRecord::VERSION::MINOR == 2
|
654
|
+
def test_visitor_accessor
|
655
|
+
adapter = Entry.connection
|
656
|
+
expected_visitors = adapter.config[:adapter_spec].
|
657
|
+
arel2_visitors(adapter).values
|
658
|
+
assert !adapter.visitor.nil?
|
659
|
+
assert expected_visitors.include?(adapter.visitor.class)
|
660
|
+
end
|
661
|
+
end
|
662
|
+
|
632
663
|
def test_where
|
633
664
|
entries = Entry.where(:title => @entry.title)
|
634
665
|
assert_equal @entry, entries.first
|
635
666
|
end
|
636
667
|
end
|
637
668
|
end
|
669
|
+
|
670
|
+
module ResetColumnInformationTestMethods
|
671
|
+
class Fhqwhgad < ActiveRecord::Base
|
672
|
+
end
|
673
|
+
|
674
|
+
def test_reset_column_information
|
675
|
+
drop_fhqwhgads_table!
|
676
|
+
create_fhqwhgads_table_1!
|
677
|
+
Fhqwhgad.reset_column_information
|
678
|
+
assert_equal ["id", "come_on"].sort, Fhqwhgad.columns.map{|c| c.name}.sort, "columns should be correct the first time"
|
679
|
+
|
680
|
+
drop_fhqwhgads_table!
|
681
|
+
create_fhqwhgads_table_2!
|
682
|
+
Fhqwhgad.reset_column_information
|
683
|
+
assert_equal ["id", "to_the_limit"].sort, Fhqwhgad.columns.map{|c| c.name}.sort, "columns should be correct the second time"
|
684
|
+
ensure
|
685
|
+
drop_fhqwhgads_table!
|
686
|
+
end
|
687
|
+
|
688
|
+
private
|
689
|
+
|
690
|
+
def drop_fhqwhgads_table!
|
691
|
+
ActiveRecord::Schema.define do
|
692
|
+
suppress_messages do
|
693
|
+
drop_table :fhqwhgads if table_exists? :fhqwhgads
|
694
|
+
end
|
695
|
+
end
|
696
|
+
end
|
697
|
+
|
698
|
+
def create_fhqwhgads_table_1!
|
699
|
+
ActiveRecord::Schema.define do
|
700
|
+
suppress_messages do
|
701
|
+
create_table :fhqwhgads do |t|
|
702
|
+
t.string :come_on
|
703
|
+
end
|
704
|
+
end
|
705
|
+
end
|
706
|
+
end
|
707
|
+
|
708
|
+
def create_fhqwhgads_table_2!
|
709
|
+
ActiveRecord::Schema.define do
|
710
|
+
suppress_messages do
|
711
|
+
create_table :fhqwhgads do |t|
|
712
|
+
t.string :to_the_limit, :null=>false, :default=>'everybody'
|
713
|
+
end
|
714
|
+
end
|
715
|
+
end
|
716
|
+
end
|
717
|
+
end
|
data/test/sqlite3_simple_test.rb
CHANGED
@@ -189,6 +189,53 @@ class SQLite3SimpleTest < Test::Unit::TestCase
|
|
189
189
|
assert_equal col.type, :integer
|
190
190
|
end
|
191
191
|
|
192
|
+
def test_change_column_with_new_precision_and_scale
|
193
|
+
Entry.delete_all
|
194
|
+
Entry.
|
195
|
+
connection.
|
196
|
+
change_column "entries", "rating", :decimal, :precision => 9, :scale => 7
|
197
|
+
Entry.reset_column_information
|
198
|
+
change_column = Entry.columns_hash["rating"]
|
199
|
+
assert_equal 9, change_column.precision
|
200
|
+
assert_equal 7, change_column.scale
|
201
|
+
end
|
202
|
+
|
203
|
+
def test_change_column_preserve_other_column_precision_and_scale
|
204
|
+
Entry.delete_all
|
205
|
+
Entry.
|
206
|
+
connection.
|
207
|
+
change_column "entries", "rating", :decimal, :precision => 9, :scale => 7
|
208
|
+
Entry.reset_column_information
|
209
|
+
|
210
|
+
rating_column = Entry.columns_hash["rating"]
|
211
|
+
assert_equal 9, rating_column.precision
|
212
|
+
assert_equal 7, rating_column.scale
|
213
|
+
|
214
|
+
Entry.
|
215
|
+
connection.
|
216
|
+
change_column "entries", "title", :string, :null => false
|
217
|
+
Entry.reset_column_information
|
218
|
+
|
219
|
+
rating_column = Entry.columns_hash["rating"]
|
220
|
+
assert_equal 9, rating_column.precision
|
221
|
+
assert_equal 7, rating_column.scale
|
222
|
+
end
|
223
|
+
|
224
|
+
def test_create_xml_column
|
225
|
+
assert_nothing_raised do
|
226
|
+
@connection.create_table :xml_testings do |t|
|
227
|
+
t.xml :xml_test
|
228
|
+
end
|
229
|
+
end
|
230
|
+
|
231
|
+
xml_test = @connection.columns(:xml_testings).detect do |c|
|
232
|
+
c.name == "xml_test"
|
233
|
+
end
|
234
|
+
|
235
|
+
assert_equal "text", xml_test.sql_type
|
236
|
+
ensure
|
237
|
+
@connection.drop_table :xml_testings rescue nil
|
238
|
+
end
|
192
239
|
end
|
193
240
|
|
194
241
|
# assert_raise ActiveRecord::RecordInvalid do
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: activerecord-jdbc-adapter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 1.2.
|
5
|
+
version: 1.2.2
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Nick Sieger, Ola Bini and JRuby contributors
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date:
|
13
|
+
date: 2012-01-28 00:00:00 Z
|
14
14
|
dependencies: []
|
15
15
|
|
16
16
|
description: |-
|
@@ -89,6 +89,7 @@ files:
|
|
89
89
|
- lib/arjdbc/jdbc.rb
|
90
90
|
- lib/arjdbc/jdbc/adapter.rb
|
91
91
|
- lib/arjdbc/jdbc/adapter_java.jar
|
92
|
+
- lib/arjdbc/jdbc/base_ext.rb
|
92
93
|
- lib/arjdbc/jdbc/callbacks.rb
|
93
94
|
- lib/arjdbc/jdbc/column.rb
|
94
95
|
- lib/arjdbc/jdbc/compatibility.rb
|
@@ -112,6 +113,7 @@ files:
|
|
112
113
|
- lib/arjdbc/mssql/adapter.rb
|
113
114
|
- lib/arjdbc/mssql/connection_methods.rb
|
114
115
|
- lib/arjdbc/mssql/limit_helpers.rb
|
116
|
+
- lib/arjdbc/mssql/lock_helpers.rb
|
115
117
|
- lib/arjdbc/mssql/tsql_helper.rb
|
116
118
|
- lib/arjdbc/mysql.rb
|
117
119
|
- lib/arjdbc/mysql/adapter.rb
|
@@ -175,9 +177,12 @@ files:
|
|
175
177
|
- test/db/oracle.rb
|
176
178
|
- test/db/postgres.rb
|
177
179
|
- test/db/sqlite3.rb
|
180
|
+
- test/db2_reset_column_information_test.rb
|
178
181
|
- test/db2_simple_test.rb
|
179
182
|
- test/derby_migration_test.rb
|
180
183
|
- test/derby_multibyte_test.rb
|
184
|
+
- test/derby_reset_column_information_test.rb
|
185
|
+
- test/derby_row_locking_test.rb
|
181
186
|
- test/derby_simple_test.rb
|
182
187
|
- test/generic_jdbc_connection_test.rb
|
183
188
|
- test/h2_change_column_test.rb
|
@@ -201,16 +206,23 @@ files:
|
|
201
206
|
- test/models/validates_uniqueness_of_string.rb
|
202
207
|
- test/mssql_db_create_test.rb
|
203
208
|
- test/mssql_identity_insert_test.rb
|
209
|
+
- test/mssql_ignore_system_views_test.rb
|
204
210
|
- test/mssql_legacy_types_test.rb
|
205
211
|
- test/mssql_limit_offset_test.rb
|
206
212
|
- test/mssql_multibyte_test.rb
|
213
|
+
- test/mssql_null_test.rb
|
214
|
+
- test/mssql_reset_column_information_test.rb
|
215
|
+
- test/mssql_row_locking_sql_test.rb
|
216
|
+
- test/mssql_row_locking_test.rb
|
207
217
|
- test/mssql_simple_test.rb
|
208
218
|
- test/mysql_db_create_test.rb
|
209
219
|
- test/mysql_index_length_test.rb
|
210
220
|
- test/mysql_info_test.rb
|
211
221
|
- test/mysql_multibyte_test.rb
|
212
222
|
- test/mysql_nonstandard_primary_key_test.rb
|
223
|
+
- test/mysql_reset_column_information_test.rb
|
213
224
|
- test/mysql_simple_test.rb
|
225
|
+
- test/oracle_reset_column_information_test.rb
|
214
226
|
- test/oracle_simple_test.rb
|
215
227
|
- test/oracle_specific_test.rb
|
216
228
|
- test/postgres_db_create_test.rb
|
@@ -220,13 +232,17 @@ files:
|
|
220
232
|
- test/postgres_native_type_mapping_test.rb
|
221
233
|
- test/postgres_nonseq_pkey_test.rb
|
222
234
|
- test/postgres_reserved_test.rb
|
235
|
+
- test/postgres_reset_column_information_test.rb
|
223
236
|
- test/postgres_schema_search_path_test.rb
|
224
237
|
- test/postgres_simple_test.rb
|
225
238
|
- test/postgres_table_alias_length_test.rb
|
226
239
|
- test/postgres_type_conversion_test.rb
|
240
|
+
- test/row_locking.rb
|
227
241
|
- test/simple.rb
|
242
|
+
- test/sqlite3_reset_column_information_test.rb
|
228
243
|
- test/sqlite3_simple_test.rb
|
229
244
|
- test/sybase_jtds_simple_test.rb
|
245
|
+
- test/sybase_reset_column_information_test.rb
|
230
246
|
homepage: https://github.com/jruby/activerecord-jdbc-adapter
|
231
247
|
licenses: []
|
232
248
|
|
@@ -257,7 +273,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
257
273
|
requirements: []
|
258
274
|
|
259
275
|
rubyforge_project: jruby-extras
|
260
|
-
rubygems_version: 1.8.
|
276
|
+
rubygems_version: 1.8.15
|
261
277
|
signing_key:
|
262
278
|
specification_version: 3
|
263
279
|
summary: JDBC adapter for ActiveRecord, for use within JRuby on Rails.
|
@@ -280,9 +296,12 @@ test_files:
|
|
280
296
|
- test/db/oracle.rb
|
281
297
|
- test/db/postgres.rb
|
282
298
|
- test/db/sqlite3.rb
|
299
|
+
- test/db2_reset_column_information_test.rb
|
283
300
|
- test/db2_simple_test.rb
|
284
301
|
- test/derby_migration_test.rb
|
285
302
|
- test/derby_multibyte_test.rb
|
303
|
+
- test/derby_reset_column_information_test.rb
|
304
|
+
- test/derby_row_locking_test.rb
|
286
305
|
- test/derby_simple_test.rb
|
287
306
|
- test/generic_jdbc_connection_test.rb
|
288
307
|
- test/h2_change_column_test.rb
|
@@ -306,16 +325,23 @@ test_files:
|
|
306
325
|
- test/models/validates_uniqueness_of_string.rb
|
307
326
|
- test/mssql_db_create_test.rb
|
308
327
|
- test/mssql_identity_insert_test.rb
|
328
|
+
- test/mssql_ignore_system_views_test.rb
|
309
329
|
- test/mssql_legacy_types_test.rb
|
310
330
|
- test/mssql_limit_offset_test.rb
|
311
331
|
- test/mssql_multibyte_test.rb
|
332
|
+
- test/mssql_null_test.rb
|
333
|
+
- test/mssql_reset_column_information_test.rb
|
334
|
+
- test/mssql_row_locking_sql_test.rb
|
335
|
+
- test/mssql_row_locking_test.rb
|
312
336
|
- test/mssql_simple_test.rb
|
313
337
|
- test/mysql_db_create_test.rb
|
314
338
|
- test/mysql_index_length_test.rb
|
315
339
|
- test/mysql_info_test.rb
|
316
340
|
- test/mysql_multibyte_test.rb
|
317
341
|
- test/mysql_nonstandard_primary_key_test.rb
|
342
|
+
- test/mysql_reset_column_information_test.rb
|
318
343
|
- test/mysql_simple_test.rb
|
344
|
+
- test/oracle_reset_column_information_test.rb
|
319
345
|
- test/oracle_simple_test.rb
|
320
346
|
- test/oracle_specific_test.rb
|
321
347
|
- test/postgres_db_create_test.rb
|
@@ -325,10 +351,14 @@ test_files:
|
|
325
351
|
- test/postgres_native_type_mapping_test.rb
|
326
352
|
- test/postgres_nonseq_pkey_test.rb
|
327
353
|
- test/postgres_reserved_test.rb
|
354
|
+
- test/postgres_reset_column_information_test.rb
|
328
355
|
- test/postgres_schema_search_path_test.rb
|
329
356
|
- test/postgres_simple_test.rb
|
330
357
|
- test/postgres_table_alias_length_test.rb
|
331
358
|
- test/postgres_type_conversion_test.rb
|
359
|
+
- test/row_locking.rb
|
332
360
|
- test/simple.rb
|
361
|
+
- test/sqlite3_reset_column_information_test.rb
|
333
362
|
- test/sqlite3_simple_test.rb
|
334
363
|
- test/sybase_jtds_simple_test.rb
|
364
|
+
- test/sybase_reset_column_information_test.rb
|