activerecord-jdbc-adapter 1.2.2.1 → 1.2.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (126) hide show
  1. data/.gitignore +1 -2
  2. data/.travis.yml +18 -3
  3. data/Appraisals +16 -0
  4. data/Gemfile +10 -10
  5. data/Gemfile.lock +27 -17
  6. data/LICENSE.txt +20 -17
  7. data/README.rdoc +29 -14
  8. data/Rakefile +4 -4
  9. data/activerecord-jdbc-adapter.gemspec +2 -1
  10. data/gemfiles/rails23.gemfile +12 -0
  11. data/gemfiles/rails23.gemfile.lock +44 -0
  12. data/gemfiles/rails30.gemfile +11 -0
  13. data/gemfiles/rails30.gemfile.lock +39 -0
  14. data/gemfiles/rails31.gemfile +11 -0
  15. data/gemfiles/rails31.gemfile.lock +41 -0
  16. data/gemfiles/rails32.gemfile +11 -0
  17. data/gemfiles/rails32.gemfile.lock +41 -0
  18. data/lib/arel/visitors/sql_server.rb +7 -0
  19. data/lib/arjdbc/db2/adapter.rb +82 -32
  20. data/lib/arjdbc/derby.rb +0 -4
  21. data/lib/arjdbc/derby/adapter.rb +1 -1
  22. data/lib/arjdbc/derby/connection_methods.rb +3 -2
  23. data/lib/arjdbc/discover.rb +16 -1
  24. data/lib/arjdbc/firebird/adapter.rb +5 -1
  25. data/lib/arjdbc/h2.rb +0 -1
  26. data/lib/arjdbc/h2/connection_methods.rb +3 -1
  27. data/lib/arjdbc/hsqldb.rb +0 -1
  28. data/lib/arjdbc/hsqldb/adapter.rb +4 -3
  29. data/lib/arjdbc/hsqldb/connection_methods.rb +3 -3
  30. data/lib/arjdbc/informix/adapter.rb +5 -1
  31. data/lib/arjdbc/jdbc/adapter.rb +22 -24
  32. data/lib/arjdbc/jdbc/adapter_java.jar +0 -0
  33. data/lib/arjdbc/jdbc/base_ext.rb +1 -1
  34. data/lib/arjdbc/jdbc/connection.rb +23 -29
  35. data/lib/arjdbc/jdbc/core_ext.rb +1 -1
  36. data/lib/arjdbc/jdbc/discover.rb +1 -1
  37. data/lib/arjdbc/jdbc/driver.rb +1 -1
  38. data/lib/arjdbc/jdbc/extension.rb +3 -3
  39. data/lib/arjdbc/jdbc/jdbc.rake +15 -5
  40. data/lib/arjdbc/mssql.rb +0 -1
  41. data/lib/arjdbc/mssql/adapter.rb +10 -4
  42. data/lib/arjdbc/mssql/connection_methods.rb +15 -15
  43. data/lib/arjdbc/mssql/limit_helpers.rb +24 -2
  44. data/lib/arjdbc/mssql/tsql_helper.rb +0 -8
  45. data/lib/arjdbc/mysql.rb +0 -1
  46. data/lib/arjdbc/mysql/adapter.rb +82 -0
  47. data/lib/arjdbc/mysql/connection_methods.rb +3 -4
  48. data/lib/arjdbc/oracle/adapter.rb +12 -2
  49. data/lib/arjdbc/postgresql.rb +0 -1
  50. data/lib/arjdbc/postgresql/adapter.rb +127 -27
  51. data/lib/arjdbc/postgresql/connection_methods.rb +3 -4
  52. data/lib/arjdbc/sqlite3.rb +0 -1
  53. data/lib/arjdbc/sqlite3/adapter.rb +13 -14
  54. data/lib/arjdbc/sqlite3/connection_methods.rb +3 -4
  55. data/lib/arjdbc/version.rb +1 -1
  56. data/rakelib/01-tomcat.rake +52 -0
  57. data/rakelib/02-test.rake +111 -0
  58. data/rakelib/db.rake +4 -3
  59. data/src/java/arjdbc/db2/DB2RubyJdbcConnection.java +7 -0
  60. data/src/java/arjdbc/jdbc/RubyJdbcConnection.java +8 -3
  61. data/test/abstract_db_create.rb +5 -1
  62. data/test/activerecord/connection_adapters/type_conversion_test.rb +0 -1
  63. data/test/activerecord/jall.sh +0 -0
  64. data/test/activerecord/jtest.sh +0 -0
  65. data/test/db/db2.rb +2 -0
  66. data/test/db/derby.rb +3 -5
  67. data/test/db/h2.rb +3 -1
  68. data/test/db/hsqldb.rb +2 -0
  69. data/test/db/informix.rb +2 -0
  70. data/test/db/jdbc.rb +11 -10
  71. data/test/db/jdbc_derby.rb +14 -0
  72. data/test/db/jdbc_h2.rb +17 -0
  73. data/test/db/jdbc_mysql.rb +13 -0
  74. data/test/db/jdbc_postgres.rb +23 -0
  75. data/test/db/jndi_config.rb +28 -33
  76. data/test/db/jndi_pooled_config.rb +35 -0
  77. data/test/db/logger.rb +1 -1
  78. data/test/db/mssql.rb +2 -0
  79. data/test/db/mysql.rb +2 -7
  80. data/test/db/mysql_config.rb +7 -0
  81. data/test/db/oracle.rb +2 -0
  82. data/test/db/postgres.rb +9 -7
  83. data/test/db/postgres_config.rb +10 -0
  84. data/test/db/sqlite3.rb +2 -0
  85. data/test/db2_reset_column_information_test.rb +0 -2
  86. data/test/derby_migration_test.rb +0 -1
  87. data/test/derby_multibyte_test.rb +0 -1
  88. data/test/derby_reset_column_information_test.rb +0 -3
  89. data/test/derby_row_locking_test.rb +0 -3
  90. data/test/derby_simple_test.rb +0 -1
  91. data/test/generic_jdbc_connection_test.rb +72 -17
  92. data/test/h2_change_column_test.rb +0 -1
  93. data/test/h2_simple_test.rb +0 -1
  94. data/test/helper.rb +22 -91
  95. data/test/jdbc_common.rb +98 -3
  96. data/test/jndi_callbacks_test.rb +6 -5
  97. data/test/jndi_test.rb +40 -15
  98. data/test/models/custom_pk_name.rb +14 -0
  99. data/test/mssql_ignore_system_views_test.rb +7 -4
  100. data/test/mssql_limit_offset_test.rb +30 -0
  101. data/test/mssql_multibyte_test.rb +1 -2
  102. data/test/mssql_reset_column_information_test.rb +0 -2
  103. data/test/mssql_row_locking_sql_test.rb +0 -2
  104. data/test/mssql_row_locking_test.rb +0 -2
  105. data/test/mysql_reset_column_information_test.rb +0 -2
  106. data/test/mysql_simple_test.rb +3 -18
  107. data/test/oracle_limit_test.rb +23 -0
  108. data/test/oracle_reset_column_information_test.rb +0 -2
  109. data/test/postgres_db_create_test.rb +0 -1
  110. data/test/postgres_drop_db_test.rb +0 -1
  111. data/test/postgres_information_schema_leak_test.rb +0 -1
  112. data/test/postgres_native_type_mapping_test.rb +17 -14
  113. data/test/postgres_nonseq_pkey_test.rb +0 -1
  114. data/test/postgres_reserved_test.rb +1 -2
  115. data/test/postgres_reset_column_information_test.rb +0 -3
  116. data/test/postgres_schema_search_path_test.rb +0 -1
  117. data/test/postgres_simple_test.rb +40 -1
  118. data/test/postgres_table_alias_length_test.rb +0 -1
  119. data/test/postgres_type_conversion_test.rb +0 -1
  120. data/test/row_locking.rb +6 -2
  121. data/test/simple.rb +57 -20
  122. data/test/sqlite3_reset_column_information_test.rb +0 -2
  123. data/test/sqlite3_simple_test.rb +1 -16
  124. data/test/sybase_reset_column_information_test.rb +0 -2
  125. metadata +366 -343
  126. data/lib/arjdbc/jdbc/require_driver.rb +0 -16
@@ -0,0 +1,11 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "http://rubygems.org"
4
+
5
+ gem "jruby-openssl", :platform=>:jruby
6
+ gem "appraisal"
7
+ gem "rake", :require=>nil
8
+ gem "test-unit", :group=>:test
9
+ gem "mocha", :group=>:test
10
+ gem "activerecord", "~> 3.2.9"
11
+
@@ -0,0 +1,41 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ activemodel (3.2.9)
5
+ activesupport (= 3.2.9)
6
+ builder (~> 3.0.0)
7
+ activerecord (3.2.9)
8
+ activemodel (= 3.2.9)
9
+ activesupport (= 3.2.9)
10
+ arel (~> 3.0.2)
11
+ tzinfo (~> 0.3.29)
12
+ activesupport (3.2.9)
13
+ i18n (~> 0.6)
14
+ multi_json (~> 1.0)
15
+ appraisal (0.5.1)
16
+ bundler
17
+ rake
18
+ arel (3.0.2)
19
+ bouncy-castle-java (1.5.0146.1)
20
+ builder (3.0.4)
21
+ i18n (0.6.1)
22
+ jruby-openssl (0.7.7)
23
+ bouncy-castle-java (>= 1.5.0146.1)
24
+ metaclass (0.0.1)
25
+ mocha (0.11.4)
26
+ metaclass (~> 0.0.1)
27
+ multi_json (1.3.7)
28
+ rake (10.0.3)
29
+ test-unit (2.5.3)
30
+ tzinfo (0.3.35)
31
+
32
+ PLATFORMS
33
+ java
34
+
35
+ DEPENDENCIES
36
+ activerecord (~> 3.2.9)
37
+ appraisal
38
+ jruby-openssl
39
+ mocha
40
+ rake
41
+ test-unit
@@ -37,6 +37,13 @@ module Arel
37
37
  add_lock!(sql, :lock => o.lock && true)
38
38
  sql
39
39
  end
40
+
41
+ # MS-SQL doesn't support "SELECT...FOR UPDATE". Instead, it needs
42
+ # WITH(ROWLOCK,UPDLOCK) specified after each table in the FROM clause.
43
+ #
44
+ # So, we return nothing here and add the appropriate stuff using add_lock! above.
45
+ def visit_Arel_Nodes_Lock o
46
+ end
40
47
  end
41
48
 
42
49
  class SQLServer2000 < SQLServer
@@ -8,7 +8,11 @@ module ArJdbc
8
8
  lobfields = self.class.columns.select { |c| c.sql_type =~ /blob|clob/i }
9
9
  lobfields.each do |c|
10
10
  value = self[c.name]
11
- value = value.to_yaml if unserializable_attribute?(c.name, c)
11
+ if respond_to?(:unserializable_attribute?)
12
+ value = value.to_yaml if unserializable_attribute?(c.name, c)
13
+ else
14
+ value = value.to_yaml if value.is_a?(Hash)
15
+ end
12
16
  next if value.nil?
13
17
  connection.write_large_object(c.type == :binary, c.name, self.class.table_name, self.class.primary_key, quote_value(id), value)
14
18
  end
@@ -31,6 +35,32 @@ module ArJdbc
31
35
  ::ActiveRecord::ConnectionAdapters::DB2JdbcConnection
32
36
  end
33
37
 
38
+ NATIVE_DATABASE_TYPES = {
39
+ :double => { :name => "double" },
40
+ :bigint => { :name => "bigint" }
41
+ }
42
+
43
+ def native_database_types
44
+ super.merge(NATIVE_DATABASE_TYPES)
45
+ end
46
+
47
+ def explain(query, *binds)
48
+ # TODO: Explain this!
49
+ end
50
+
51
+ def prefetch_primary_key?(table_name = nil)
52
+ # TRUE if the table has no identity column
53
+ names = table_name.upcase.split(".")
54
+ sql = "SELECT 1 FROM SYSCAT.COLUMNS WHERE IDENTITY = 'Y' "
55
+ sql += "AND TABSCHEMA = '#{names.first}' " if names.size == 2
56
+ sql += "AND TABNAME = '#{names.last}'"
57
+ select_one(sql).nil?
58
+ end
59
+
60
+ def next_sequence_value(sequence_name)
61
+ select_value("select next value for #{sequence_name} from sysibm.sysdummy1")
62
+ end
63
+
34
64
  module Column
35
65
  def type_cast(value)
36
66
  return nil if value.nil? || value =~ /^\s*null\s*$/i
@@ -63,7 +93,10 @@ module ArJdbc
63
93
  def self.cast_to_date_or_time(value)
64
94
  return value if value.is_a? Date
65
95
  return nil if value.blank?
96
+ return Time.now if value =~ /^CURRENT/
66
97
  guess_date_or_time((value.is_a? Time) ? value : cast_to_time(value))
98
+ rescue
99
+ value
67
100
  end
68
101
 
69
102
  def self.cast_to_time(value)
@@ -82,21 +115,12 @@ module ArJdbc
82
115
  end
83
116
 
84
117
  private
85
- # <b>DEPRECATED:</b> SMALLINT is now used for boolean field types. Please
86
- # convert your tables using DECIMAL(5) for boolean values to SMALLINT instead.
87
- def use_decimal5_for_boolean
88
- warn "[DEPRECATION] using DECIMAL(5) for boolean is deprecated. Convert your columns to SMALLINT instead."
89
- :boolean
90
- end
91
-
92
118
  # http://publib.boulder.ibm.com/infocenter/db2luw/v9r7/topic/com.ibm.db2.luw.apdv.java.doc/doc/rjvjdata.html
93
119
  def simplified_type(field_type)
94
120
  case field_type
95
- # old jdbc_db2.rb used decimal(5,0) as boolean
96
- when /^smallint/i then :boolean
97
- when /^decimal\(5\)$/i then use_decimal5_for_boolean
98
- when /^real/i then :float
99
- when /^timestamp/i then :datetime
121
+ when /^decimal\(1\)$/i then :boolean
122
+ when /^real/i then :float
123
+ when /^timestamp/i then :datetime
100
124
  else
101
125
  super
102
126
  end
@@ -148,9 +172,7 @@ module ArJdbc
148
172
 
149
173
  def last_insert_id(sql)
150
174
  table_name = sql.split(/\s/)[2]
151
- result = select(ActiveRecord::Base.send(:sanitize_sql,
152
- %[select IDENTITY_VAL_LOCAL() as last_insert_id from #{table_name}],
153
- nil))
175
+ result = select(ActiveRecord::Base.send(:sanitize_sql, %[select IDENTITY_VAL_LOCAL() as last_insert_id from #{table_name}], nil))
154
176
  result.last['last_insert_id']
155
177
  end
156
178
 
@@ -158,7 +180,7 @@ module ArJdbc
158
180
  tp[:primary_key] = 'int not null generated by default as identity (start with 1) primary key'
159
181
  tp[:string][:limit] = 255
160
182
  tp[:integer][:limit] = nil
161
- tp[:boolean] = {:name => "smallint"}
183
+ tp[:boolean] = {:name => "decimal(1)"}
162
184
  tp
163
185
  end
164
186
 
@@ -204,7 +226,7 @@ module ArJdbc
204
226
  create_sql << "#{quote_table_name(name)} ("
205
227
  create_sql << table_definition.to_sql
206
228
  create_sql << ") #{options[:options]}"
207
- create_sql << " IN #{@config[:database]}.#{@config[:tablespace]}"
229
+ create_sql << " IN #{@config[:database]}.#{@config[:tablespace]}" if @config[:database] && @config[:tablespace]
208
230
 
209
231
  execute create_sql
210
232
 
@@ -229,7 +251,7 @@ module ArJdbc
229
251
  end
230
252
  else
231
253
  offset = offset.to_i
232
- sql.gsub!(/SELECT/i, 'SELECT B.* FROM (SELECT A.*, row_number() over () AS internal$rownum FROM (SELECT')
254
+ sql.sub!(/SELECT/i, 'SELECT B.* FROM (SELECT A.*, row_number() over () AS internal$rownum FROM (SELECT')
233
255
  sql << ") A ) B WHERE B.internal$rownum > #{offset} AND B.internal$rownum <= #{limit + offset}"
234
256
  end
235
257
  end
@@ -247,7 +269,7 @@ module ArJdbc
247
269
  end
248
270
 
249
271
  def quote_column_name(column_name)
250
- column_name
272
+ column_name.to_s
251
273
  end
252
274
 
253
275
  def quote(value, column = nil) # :nodoc:
@@ -290,12 +312,17 @@ module ArJdbc
290
312
  end
291
313
  end
292
314
 
293
- def recreate_database(name)
315
+ def runstats_for_table(tablename, priority=10)
316
+ @connection.execute_update "call sysproc.admin_cmd('RUNSTATS ON TABLE #{tablename} WITH DISTRIBUTION AND DETAILED INDEXES ALL UTIL_IMPACT_PRIORITY #{priority}')"
317
+ end
318
+
319
+ def recreate_database(name, options = {})
294
320
  tables.each {|table| drop_table("#{db2_schema}.#{table}")}
295
321
  end
296
322
 
297
323
  def add_index(table_name, column_name, options = {})
298
324
  if (!zos? || (table_name.to_s == ActiveRecord::Migrator.schema_migrations_table_name.to_s))
325
+ column_name = column_name.to_s if column_name.is_a?(Symbol)
299
326
  super
300
327
  else
301
328
  statement ="CREATE"
@@ -326,19 +353,21 @@ module ArJdbc
326
353
 
327
354
  def change_column_null(table_name, column_name, null)
328
355
  if null
329
- execute_and_auto_confirm "ALTER TABLE #{table_name} ALTER COLUMN #{column_name} DROP NOT NULL"
356
+ sql = "ALTER TABLE #{table_name} ALTER COLUMN #{column_name} DROP NOT NULL"
330
357
  else
331
- execute_and_auto_confirm "ALTER TABLE #{table_name} ALTER COLUMN #{column_name} SET NOT NULL"
358
+ sql = "ALTER TABLE #{table_name} ALTER COLUMN #{column_name} SET NOT NULL"
332
359
  end
360
+ as400? ? execute_and_auto_confirm(sql) : execute(sql)
333
361
  reorg_table(table_name)
334
362
  end
335
363
 
336
364
  def change_column_default(table_name, column_name, default)
337
365
  if default.nil?
338
- execute_and_auto_confirm "ALTER TABLE #{table_name} ALTER COLUMN #{column_name} DROP DEFAULT"
366
+ sql = "ALTER TABLE #{table_name} ALTER COLUMN #{column_name} DROP DEFAULT"
339
367
  else
340
- execute_and_auto_confirm "ALTER TABLE #{table_name} ALTER COLUMN #{column_name} SET WITH DEFAULT #{quote(default)}"
368
+ sql = "ALTER TABLE #{table_name} ALTER COLUMN #{column_name} SET WITH DEFAULT #{quote(default)}"
341
369
  end
370
+ as400? ? execute_and_auto_confirm(sql) : execute(sql)
342
371
  reorg_table(table_name)
343
372
  end
344
373
 
@@ -434,11 +463,12 @@ module ArJdbc
434
463
 
435
464
  def structure_dump #:nodoc:
436
465
  definition=""
437
- rs = @connection.connection.meta_data.getTables(nil,db2_schema.upcase,nil,["TABLE"].to_java(:string))
466
+ schema_name = db2_schema.upcase if db2_schema.present?
467
+ rs = @connection.connection.meta_data.getTables(nil,schema_name,nil,["TABLE"].to_java(:string))
438
468
  while rs.next
439
469
  tname = rs.getString(3)
440
470
  definition << "CREATE TABLE #{tname} (\n"
441
- rs2 = @connection.connection.meta_data.getColumns(nil,db2_schema.upcase,tname,nil)
471
+ rs2 = @connection.connection.meta_data.getColumns(nil,schema_name,tname,nil)
442
472
  first_col = true
443
473
  while rs2.next
444
474
  col_name = add_quotes(rs2.getString(4));
@@ -461,13 +491,15 @@ module ArJdbc
461
491
  col_size = "(#{col_precision})"
462
492
  end
463
493
  nulling = (rs2.getString(18) == 'NO' ? " NOT NULL" : "")
494
+ autoincrement = (rs2.getString(23) == 'YES' ? " GENERATED ALWAYS AS IDENTITY" : "")
464
495
  create_col_string = add_quotes(expand_double_quotes(strip_quotes(col_name))) +
465
496
  " " +
466
497
  type +
467
498
  col_size +
468
499
  "" +
469
500
  nulling +
470
- default
501
+ default +
502
+ autoincrement
471
503
  if !first_col
472
504
  create_col_string = ",\n #{create_col_string}"
473
505
  else
@@ -479,17 +511,30 @@ module ArJdbc
479
511
  first_col = false
480
512
  end
481
513
  definition << ");\n\n"
514
+
515
+ pkrs = @connection.connection.meta_data.getPrimaryKeys(nil,schema_name,tname)
516
+ primary_key = {}
517
+ while pkrs.next
518
+ name = pkrs.getString(6)
519
+ primary_key[name] = [] unless primary_key[name]
520
+ primary_key[name] << pkrs.getString(4)
521
+ end
522
+ primary_key.each do |name, cols|
523
+ definition << "ALTER TABLE #{tname}\n"
524
+ definition << " ADD CONSTRAINT #{name}\n"
525
+ definition << " PRIMARY KEY (#{cols.join(', ')});\n\n"
526
+ end
482
527
  end
483
528
  definition
484
529
  end
485
530
 
486
531
  def zos?
487
- @config[:driver] == "com.ibm.db2.jcc.DB2Driver"
532
+ @config[:url] =~ /^jdbc:db2j:net:/ && @config[:driver] == "com.ibm.db2.jcc.DB2Driver"
488
533
  end
489
534
 
490
535
  private
491
536
  def as400?
492
- @config[:url] =~ /^jdbc:as400:/
537
+ @config[:url] =~ /^jdbc:as400:/
493
538
  end
494
539
 
495
540
  def db2_schema
@@ -498,9 +543,14 @@ module ArJdbc
498
543
  # AS400 implementation takes schema from library name (last part of url)
499
544
  schema = @config[:url].split('/').last.strip
500
545
  (schema[-1..-1] == ";") ? schema.chop : schema
501
- else
546
+ elsif @config[:username].present?
502
547
  # LUW implementation uses schema name of username by default
503
- @config[:username] or ENV['USER']
548
+ @config[:username]
549
+ elsif @config[:jndi].present?
550
+ # let jndi worry about schema
551
+ nil
552
+ else
553
+ ENV['USER']
504
554
  end
505
555
  else
506
556
  @config[:schema]
data/lib/arjdbc/derby.rb CHANGED
@@ -1,7 +1,3 @@
1
1
  require 'arjdbc/jdbc'
2
- jdbc_require_driver 'jdbc/derby'
3
2
  require 'arjdbc/derby/connection_methods'
4
3
  require 'arjdbc/derby/adapter'
5
-
6
-
7
-
@@ -315,7 +315,7 @@ module ::ArJdbc
315
315
  @connection.tables(nil, derby_schema)
316
316
  end
317
317
 
318
- def recreate_database(db_name)
318
+ def recreate_database(db_name, options = {})
319
319
  tables.each do |t|
320
320
  drop_table t
321
321
  end
@@ -2,8 +2,10 @@ module ActiveRecord
2
2
  class Base
3
3
  class << self
4
4
  def derby_connection(config)
5
+ require 'active_record/connection_adapters/jdbcderby_adapter'
6
+
5
7
  config[:url] ||= "jdbc:derby:#{config[:database]};create=true"
6
- config[:driver] ||= "org.apache.derby.jdbc.EmbeddedDriver"
8
+ config[:driver] ||= defined?(::Jdbc::Derby.driver_name) ? ::Jdbc::Derby.driver_name : 'org.apache.derby.jdbc.EmbeddedDriver'
7
9
  config[:adapter_spec] = ::ArJdbc::Derby
8
10
  conn = embedded_driver(config)
9
11
  md = conn.jdbc_connection.meta_data
@@ -12,7 +14,6 @@ module ActiveRecord
12
14
  end
13
15
  conn
14
16
  end
15
-
16
17
  alias_method :jdbcderby_connection, :derby_connection
17
18
  end
18
19
  end
@@ -27,9 +27,24 @@ module ::ArJdbc
27
27
  end
28
28
  end
29
29
 
30
- extension :Derby do |name|
30
+ extension :Derby do |name, config|
31
31
  if name =~ /derby/i
32
32
  require 'arjdbc/derby'
33
+
34
+ # Derby-specific hack
35
+ if config && ! config[:username] && ( config[:jndi] || config[:data_source] )
36
+ # Needed to set the correct database schema name (:username)
37
+ begin
38
+ data_source = config[:data_source] || Java::JavaxNaming::InitialContext.new.lookup(config[:jndi])
39
+ connection = data_source.getConnection
40
+ config[:username] = connection.getMetaData.getUserName
41
+ rescue Java::JavaSql::SQLException => e
42
+ warn "failed to set (derby) database :username from connection meda-data (#{e})"
43
+ ensure
44
+ ( connection.close rescue nil ) if connection # return to the pool
45
+ end
46
+ end
47
+
33
48
  true
34
49
  end
35
50
  end
@@ -7,7 +7,11 @@ module ::ArJdbc
7
7
  def after_save_with_firebird_blob
8
8
  self.class.columns.select { |c| c.sql_type =~ /blob/i }.each do |c|
9
9
  value = self[c.name]
10
- value = value.to_yaml if unserializable_attribute?(c.name, c)
10
+ if respond_to?(:unserializable_attribute?)
11
+ value = value.to_yaml if unserializable_attribute?(c.name, c)
12
+ else
13
+ value = value.to_yaml if value.is_a?(Hash)
14
+ end
11
15
  next if value.nil?
12
16
  connection.write_large_object(c.type == :binary, c.name, self.class.table_name, self.class.primary_key, quote_value(id), value)
13
17
  end
data/lib/arjdbc/h2.rb CHANGED
@@ -1,4 +1,3 @@
1
1
  require 'arjdbc/jdbc'
2
- jdbc_require_driver 'jdbc/h2'
3
2
  require 'arjdbc/h2/connection_methods'
4
3
  require 'arjdbc/h2/adapter'
@@ -2,8 +2,10 @@ module ActiveRecord
2
2
  class Base
3
3
  class << self
4
4
  def h2_connection(config)
5
+ require 'active_record/connection_adapters/jdbch2_adapter'
6
+
5
7
  config[:url] ||= "jdbc:h2:#{config[:database]}"
6
- config[:driver] ||= "org.h2.Driver"
8
+ config[:driver] ||= defined?(::Jdbc::H2.driver_name) ? ::Jdbc::H2.driver_name : 'org.h2.Driver'
7
9
  config[:adapter_spec] = ::ArJdbc::H2
8
10
  embedded_driver(config)
9
11
  end
data/lib/arjdbc/hsqldb.rb CHANGED
@@ -1,4 +1,3 @@
1
1
  require 'arjdbc/jdbc'
2
- jdbc_require_driver 'jdbc/hsqldb'
3
2
  require 'arjdbc/hsqldb/connection_methods'
4
3
  require 'arjdbc/hsqldb/adapter'
@@ -70,7 +70,7 @@ module ::ArJdbc
70
70
  if respond_to?(:h2_adapter) && value.empty?
71
71
  "''"
72
72
  elsif column && column.type == :binary
73
- "'#{value.unpack("H*")[0]}'"
73
+ "X'#{value.unpack("H*")[0]}'"
74
74
  elsif column && (column.type == :integer ||
75
75
  column.respond_to?(:primary) && column.primary && column.klass != String)
76
76
  value.to_i.to_s
@@ -133,7 +133,8 @@ module ::ArJdbc
133
133
  end
134
134
 
135
135
  def last_insert_id
136
- Integer(select_value("CALL IDENTITY()"))
136
+ identity = select_value("CALL IDENTITY()")
137
+ Integer(identity.nil? ? 0 : identity)
137
138
  end
138
139
 
139
140
  def _execute(sql, name = nil)
@@ -167,7 +168,7 @@ module ::ArJdbc
167
168
  execute "DROP INDEX #{quote_column_name(index_name(table_name, options))}"
168
169
  end
169
170
 
170
- def recreate_database(name)
171
+ def recreate_database(name, options = {})
171
172
  drop_database(name)
172
173
  end
173
174