activerecord-jdbc-adapter 1.2.9.1 → 1.3.0.beta1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (231) hide show
  1. data/.travis.yml +3 -0
  2. data/Appraisals +12 -4
  3. data/Gemfile +3 -3
  4. data/Gemfile.lock +19 -19
  5. data/History.txt +90 -16
  6. data/LICENSE.txt +2 -1
  7. data/README.md +14 -1
  8. data/activerecord-jdbc-adapter.gemspec +2 -2
  9. data/gemfiles/rails23.gemfile +5 -5
  10. data/gemfiles/rails23.gemfile.lock +27 -27
  11. data/gemfiles/rails30.gemfile +3 -3
  12. data/gemfiles/rails30.gemfile.lock +8 -8
  13. data/gemfiles/rails31.gemfile +4 -4
  14. data/gemfiles/rails31.gemfile.lock +18 -18
  15. data/gemfiles/rails32.gemfile +4 -4
  16. data/gemfiles/rails32.gemfile.lock +17 -17
  17. data/gemfiles/rails40.gemfile +17 -0
  18. data/gemfiles/rails40.gemfile.lock +126 -0
  19. data/lib/activerecord-jdbc-adapter.rb +0 -7
  20. data/lib/arjdbc.rb +6 -5
  21. data/lib/arjdbc/db2.rb +1 -1
  22. data/lib/arjdbc/db2/adapter.rb +52 -29
  23. data/lib/arjdbc/db2/connection_methods.rb +13 -14
  24. data/lib/arjdbc/derby.rb +1 -1
  25. data/lib/arjdbc/derby/adapter.rb +29 -9
  26. data/lib/arjdbc/derby/connection_methods.rb +17 -20
  27. data/lib/arjdbc/firebird.rb +1 -1
  28. data/lib/arjdbc/h2.rb +2 -2
  29. data/lib/arjdbc/h2/adapter.rb +1 -1
  30. data/lib/arjdbc/h2/connection_methods.rb +12 -16
  31. data/lib/arjdbc/hsqldb.rb +1 -1
  32. data/lib/arjdbc/hsqldb/connection_methods.rb +13 -16
  33. data/lib/arjdbc/informix.rb +1 -1
  34. data/lib/arjdbc/informix/connection_methods.rb +8 -10
  35. data/lib/arjdbc/jdbc.rb +1 -1
  36. data/lib/arjdbc/jdbc/adapter.rb +125 -53
  37. data/lib/arjdbc/jdbc/adapter_java.jar +0 -0
  38. data/lib/arjdbc/jdbc/base_ext.rb +34 -9
  39. data/lib/arjdbc/jdbc/column.rb +15 -2
  40. data/lib/arjdbc/jdbc/connection.rb +0 -2
  41. data/lib/arjdbc/jdbc/connection_methods.rb +10 -3
  42. data/lib/arjdbc/jdbc/driver.rb +2 -2
  43. data/lib/arjdbc/jdbc/extension.rb +35 -21
  44. data/lib/arjdbc/jdbc/java.rb +0 -2
  45. data/lib/arjdbc/jdbc/missing_functionality_helper.rb +35 -25
  46. data/lib/arjdbc/jdbc/railtie.rb +2 -9
  47. data/lib/arjdbc/mimer.rb +1 -1
  48. data/lib/arjdbc/mssql.rb +2 -2
  49. data/lib/arjdbc/mssql/adapter.rb +271 -92
  50. data/lib/arjdbc/mssql/connection_methods.rb +30 -32
  51. data/lib/arjdbc/mssql/explain_support.rb +107 -0
  52. data/lib/arjdbc/mssql/limit_helpers.rb +48 -18
  53. data/lib/arjdbc/mysql.rb +1 -1
  54. data/lib/arjdbc/mysql/adapter.rb +63 -14
  55. data/lib/arjdbc/mysql/connection_methods.rb +22 -24
  56. data/lib/arjdbc/mysql/explain_support.rb +2 -5
  57. data/lib/arjdbc/oracle.rb +1 -1
  58. data/lib/arjdbc/oracle/adapter.rb +78 -38
  59. data/lib/arjdbc/oracle/connection_methods.rb +9 -10
  60. data/lib/arjdbc/postgresql.rb +1 -1
  61. data/lib/arjdbc/postgresql/adapter.rb +964 -380
  62. data/lib/arjdbc/postgresql/column_cast.rb +136 -0
  63. data/lib/arjdbc/postgresql/connection_methods.rb +19 -21
  64. data/lib/arjdbc/postgresql/explain_support.rb +3 -6
  65. data/lib/arjdbc/railtie.rb +9 -0
  66. data/lib/arjdbc/sqlite3.rb +1 -1
  67. data/lib/arjdbc/sqlite3/adapter.rb +73 -26
  68. data/lib/arjdbc/sqlite3/connection_methods.rb +27 -28
  69. data/lib/arjdbc/sqlite3/explain_support.rb +2 -5
  70. data/lib/arjdbc/sybase.rb +1 -1
  71. data/lib/arjdbc/version.rb +5 -4
  72. data/pom.xml +8 -0
  73. data/rakelib/02-test.rake +57 -51
  74. data/rakelib/compile.rake +17 -5
  75. data/rakelib/rails.rake +42 -31
  76. data/src/java/arjdbc/db2/DB2RubyJdbcConnection.java +4 -3
  77. data/src/java/arjdbc/derby/DerbyModule.java +98 -85
  78. data/src/java/arjdbc/derby/DerbyRubyJdbcConnection.java +70 -0
  79. data/src/java/arjdbc/h2/H2RubyJdbcConnection.java +0 -4
  80. data/src/java/arjdbc/jdbc/AdapterJavaService.java +26 -15
  81. data/src/java/arjdbc/jdbc/Callable.java +44 -0
  82. data/src/java/arjdbc/jdbc/JdbcConnectionFactory.java +10 -2
  83. data/src/java/arjdbc/jdbc/RubyJdbcConnection.java +1675 -834
  84. data/src/java/arjdbc/jdbc/SQLBlock.java +9 -3
  85. data/src/java/arjdbc/mssql/MSSQLRubyJdbcConnection.java +73 -36
  86. data/src/java/arjdbc/mysql/MySQLModule.java +11 -10
  87. data/src/java/arjdbc/mysql/MySQLRubyJdbcConnection.java +86 -80
  88. data/src/java/arjdbc/oracle/OracleRubyJdbcConnection.java +27 -7
  89. data/src/java/arjdbc/postgresql/PostgreSQLRubyJdbcConnection.java +214 -0
  90. data/src/java/arjdbc/postgresql/PostgresqlRubyJdbcConnection.java +25 -67
  91. data/src/java/arjdbc/sqlite3/SQLite3RubyJdbcConnection.java +52 -49
  92. data/src/java/arjdbc/util/QuotingUtils.java +6 -6
  93. data/test/abstract_db_create.rb +11 -11
  94. data/test/activerecord/connection_adapters/type_conversion_test.rb +18 -12
  95. data/test/db/db2.rb +1 -1
  96. data/test/{db2_binary_test.rb → db/db2/binary_test.rb} +0 -0
  97. data/test/db/db2/has_many_through_test.rb +6 -0
  98. data/test/{db2_reset_column_information_test.rb → db/db2/reset_column_information_test.rb} +1 -2
  99. data/test/{db2_serialize_test.rb → db/db2/serialize_test.rb} +0 -0
  100. data/test/{db2_simple_test.rb → db/db2/simple_test.rb} +1 -8
  101. data/test/db/db2/test_helper.rb +6 -0
  102. data/test/{db2_test.rb → db/db2/unit_test.rb} +1 -1
  103. data/test/db/derby.rb +1 -1
  104. data/test/{derby_binary_test.rb → db/derby/binary_test.rb} +0 -0
  105. data/test/{derby_migration_test.rb → db/derby/migration_test.rb} +0 -0
  106. data/test/{derby_reset_column_information_test.rb → db/derby/reset_column_information_test.rb} +0 -0
  107. data/test/{derby_row_locking_test.rb → db/derby/row_locking_test.rb} +1 -4
  108. data/test/db/derby/schema_dump_test.rb +5 -0
  109. data/test/{derby_serialize_test.rb → db/derby/serialize_test.rb} +0 -0
  110. data/test/{derby_simple_test.rb → db/derby/simple_test.rb} +23 -38
  111. data/test/db/derby/test_helper.rb +6 -0
  112. data/test/db/derby/unit_test.rb +32 -0
  113. data/test/db/derby/xml_column_test.rb +17 -0
  114. data/test/db/h2.rb +1 -1
  115. data/test/{h2_binary_test.rb → db/h2/binary_test.rb} +0 -0
  116. data/test/{h2_change_column_test.rb → db/h2/change_column_test.rb} +1 -0
  117. data/test/{h2_schema_dump_test.rb → db/h2/schema_dump_test.rb} +0 -0
  118. data/test/{h2_serialize_test.rb → db/h2/serialize_test.rb} +0 -0
  119. data/test/{h2_simple_test.rb → db/h2/simple_test.rb} +3 -1
  120. data/test/db/hsqldb.rb +1 -1
  121. data/test/{hsqldb_binary_test.rb → db/hsqldb/binary_test.rb} +0 -0
  122. data/test/{hsqldb_schema_dump_test.rb → db/hsqldb/schema_dump_test.rb} +0 -0
  123. data/test/{hsqldb_serialize_test.rb → db/hsqldb/serialize_test.rb} +0 -0
  124. data/test/{hsqldb_simple_test.rb → db/hsqldb/simple_test.rb} +3 -1
  125. data/test/db/informix.rb +1 -1
  126. data/test/db/jdbc.rb +3 -2
  127. data/test/db/jdbc_derby.rb +1 -1
  128. data/test/db/jdbc_h2.rb +1 -1
  129. data/test/db/jdbc_mysql.rb +1 -1
  130. data/test/db/jdbc_postgres.rb +1 -1
  131. data/test/db/jndi_config.rb +1 -2
  132. data/test/db/jndi_pooled_config.rb +2 -3
  133. data/test/db/mssql.rb +2 -2
  134. data/test/{mssql_binary_test.rb → db/mssql/binary_test.rb} +0 -0
  135. data/test/{mssql_db_create_test.rb → db/mssql/db_create_test.rb} +1 -1
  136. data/test/db/mssql/exec_proc_test.rb +46 -0
  137. data/test/{mssql_identity_insert_test.rb → db/mssql/identity_insert_test.rb} +0 -0
  138. data/test/db/mssql/ignore_system_views_test.rb +40 -0
  139. data/test/{mssql_limit_offset_test.rb → db/mssql/limit_offset_test.rb} +10 -1
  140. data/test/{mssql_multibyte_test.rb → db/mssql/multibyte_test.rb} +0 -0
  141. data/test/db/mssql/multiple_connections_test.rb +71 -0
  142. data/test/{mssql_reset_column_information_test.rb → db/mssql/reset_column_information_test.rb} +0 -0
  143. data/test/{mssql_row_locking_test.rb → db/mssql/row_locking_test.rb} +0 -0
  144. data/test/{mssql_serialize_test.rb → db/mssql/serialize_test.rb} +1 -1
  145. data/test/db/mssql/simple_test.rb +140 -0
  146. data/test/db/mssql/transaction_test.rb +6 -0
  147. data/test/db/mssql/types_test.rb +205 -0
  148. data/test/{mssql_test.rb → db/mssql/unit_test.rb} +2 -2
  149. data/test/db/mysql.rb +1 -2
  150. data/test/db/mysql/_rails_test_mysql.32.out +6768 -0
  151. data/test/{mysql_binary_test.rb → db/mysql/binary_test.rb} +0 -0
  152. data/test/db/mysql/connection_test.rb +51 -0
  153. data/test/{mysql_db_create_test.rb → db/mysql/db_create_test.rb} +0 -0
  154. data/test/{mysql_index_length_test.rb → db/mysql/index_length_test.rb} +0 -0
  155. data/test/{mysql_multibyte_test.rb → db/mysql/multibyte_test.rb} +0 -0
  156. data/test/{mysql_nonstandard_primary_key_test.rb → db/mysql/nonstandard_primary_key_test.rb} +0 -0
  157. data/test/{mysql_reset_column_information_test.rb → db/mysql/reset_column_information_test.rb} +0 -0
  158. data/test/{mysql_schema_dump_test.rb → db/mysql/schema_dump_test.rb} +9 -1
  159. data/test/{mysql_serialize_test.rb → db/mysql/serialize_test.rb} +0 -0
  160. data/test/{mysql_simple_test.rb → db/mysql/simple_test.rb} +16 -8
  161. data/test/db/mysql/transaction_test.rb +6 -0
  162. data/test/db/mysql/types_test.rb +30 -0
  163. data/test/{mysql_test.rb → db/mysql/unit_test.rb} +1 -1
  164. data/test/db/mysql_config.rb +1 -1
  165. data/test/db/oracle.rb +1 -1
  166. data/test/{oracle_binary_test.rb → db/oracle/binary_test.rb} +0 -0
  167. data/test/{oracle_limit_test.rb → db/oracle/limit_test.rb} +0 -0
  168. data/test/db/oracle/multibyte_test.rb +22 -0
  169. data/test/{oracle_reset_column_information_test.rb → db/oracle/reset_column_information_test.rb} +0 -0
  170. data/test/{oracle_serialize_test.rb → db/oracle/serialize_test.rb} +0 -0
  171. data/test/{oracle_simple_test.rb → db/oracle/simple_test.rb} +14 -19
  172. data/test/{oracle_specific_test.rb → db/oracle/specific_test.rb} +62 -16
  173. data/test/db/oracle/transaction_test.rb +31 -0
  174. data/test/db/oracle/unit_test.rb +31 -0
  175. data/test/db/postgres.rb +1 -1
  176. data/test/db/postgres/_rails_test_postgres.32.out +6777 -0
  177. data/test/db/postgres/a_custom_primary_key_test.rb +50 -0
  178. data/test/db/postgres/array_type_test.rb +101 -0
  179. data/test/{postgres_binary_test.rb → db/postgres/binary_test.rb} +0 -0
  180. data/test/db/postgres/connection_test.rb +55 -0
  181. data/test/db/postgres/data_types_test.rb +703 -0
  182. data/test/{postgres_db_create_test.rb → db/postgres/db_create_test.rb} +1 -1
  183. data/test/{postgres_drop_db_test.rb → db/postgres/db_drop_test.rb} +2 -0
  184. data/test/db/postgres/hstore_test.rb +200 -0
  185. data/test/db/postgres/information_schema_leak_test.rb +30 -0
  186. data/test/db/postgres/json_test.rb +86 -0
  187. data/test/db/postgres/ltree_test.rb +50 -0
  188. data/test/{postgres_mixed_case_test.rb → db/postgres/mixed_case_test.rb} +0 -0
  189. data/test/db/postgres/native_types_test.rb +128 -0
  190. data/test/{postgres_reserved_test.rb → db/postgres/reserved_test.rb} +0 -0
  191. data/test/{postgres_reset_column_information_test.rb → db/postgres/reset_column_information_test.rb} +0 -0
  192. data/test/{postgres_row_locking_test.rb → db/postgres/row_locking_test.rb} +0 -0
  193. data/test/{postgres_schema_dump_test.rb → db/postgres/schema_dump_test.rb} +4 -4
  194. data/test/db/postgres/schema_test.rb +113 -0
  195. data/test/{postgres_simple_test.rb → db/postgres/simple_test.rb} +48 -8
  196. data/test/{postgres_table_alias_length_test.rb → db/postgres/table_alias_length_test.rb} +2 -1
  197. data/test/db/postgres/transaction_test.rb +6 -0
  198. data/test/{postgres_test.rb → db/postgres/unit_test.rb} +3 -3
  199. data/test/db/sqlite3.rb +1 -1
  200. data/test/db/sqlite3/_rails_test_sqlite3.32.out +6502 -0
  201. data/test/db/sqlite3/has_many_though_test.rb +6 -0
  202. data/test/{sqlite3_reset_column_information_test.rb → db/sqlite3/reset_column_information_test.rb} +0 -0
  203. data/test/{sqlite3_schema_dump_test.rb → db/sqlite3/schema_dump_test.rb} +0 -0
  204. data/test/{sqlite3_serialize_test.rb → db/sqlite3/serialize_test.rb} +0 -0
  205. data/test/{sqlite3_simple_test.rb → db/sqlite3/simple_test.rb} +63 -63
  206. data/test/db/sqlite3/transaction_test.rb +32 -0
  207. data/test/{sqlite3_type_conversion_test.rb → db/sqlite3/type_conversion_test.rb} +0 -0
  208. data/test/has_many_through.rb +29 -64
  209. data/test/jdbc/oracle.rb +11 -0
  210. data/test/jndi_test.rb +16 -4
  211. data/test/models/auto_id.rb +1 -1
  212. data/test/models/rights_and_roles.rb +57 -0
  213. data/test/row_locking.rb +3 -0
  214. data/test/schema_dump.rb +24 -10
  215. data/test/simple.rb +359 -104
  216. data/test/test_helper.rb +4 -2
  217. data/test/transaction.rb +109 -0
  218. metadata +119 -86
  219. data/lib/arjdbc/jdbc/compatibility.rb +0 -51
  220. data/lib/arjdbc/jdbc/core_ext.rb +0 -24
  221. data/lib/arjdbc/jdbc/discover.rb +0 -18
  222. data/test/derby_schema_dump_test.rb +0 -9
  223. data/test/mssql_ignore_system_views_test.rb +0 -30
  224. data/test/mssql_legacy_types_test.rb +0 -58
  225. data/test/mssql_null_test.rb +0 -14
  226. data/test/mssql_simple_test.rb +0 -51
  227. data/test/postgres_information_schema_leak_test.rb +0 -28
  228. data/test/postgres_native_type_mapping_test.rb +0 -93
  229. data/test/postgres_nonseq_pkey_test.rb +0 -38
  230. data/test/postgres_schema_search_path_test.rb +0 -48
  231. data/test/postgres_type_conversion_test.rb +0 -33
@@ -1,18 +1,17 @@
1
- class ActiveRecord::Base
2
- class << self
3
- def db2_connection(config)
4
- config[:url] ||= begin
5
- if config[:host] # Type 4 URL: jdbc:db2://server:port/database
6
- config[:port] ||= 50000
7
- "jdbc:db2://#{config[:host]}:#{config[:port]}/#{config[:database]}"
8
- else # Type 2 URL: jdbc:db2:database
9
- "jdbc:db2:#{config[:database]}"
10
- end
1
+ ArJdbc::ConnectionMethods.module_eval do
2
+ def db2_connection(config)
3
+ config[:url] ||= begin
4
+ if config[:host] # Type 4 URL: jdbc:db2://server:port/database
5
+ config[:port] ||= 50000
6
+ "jdbc:db2://#{config[:host]}:#{config[:port]}/#{config[:database]}"
7
+ else # Type 2 URL: jdbc:db2:database
8
+ "jdbc:db2:#{config[:database]}"
11
9
  end
12
- config[:driver] ||= ::ArJdbc::DB2::DRIVER_NAME
13
- config[:adapter_spec] = ::ArJdbc::DB2
14
- jdbc_connection(config)
15
10
  end
16
- alias_method :jdbcdb2_connection, :db2_connection
11
+ config[:driver] ||= ::ArJdbc::DB2::DRIVER_NAME
12
+ config[:adapter_spec] = ::ArJdbc::DB2
13
+ config[:connection_alive_sql] ||= 'SELECT 1 FROM syscat.tables FETCH FIRST 1 ROWS ONLY'
14
+ jdbc_connection(config)
17
15
  end
16
+ alias_method :jdbcdb2_connection, :db2_connection
18
17
  end
data/lib/arjdbc/derby.rb CHANGED
@@ -1,3 +1,3 @@
1
- require 'arjdbc/jdbc'
1
+ require 'arjdbc'
2
2
  require 'arjdbc/derby/connection_methods'
3
3
  require 'arjdbc/derby/adapter'
@@ -15,6 +15,10 @@ module ArJdbc
15
15
  def self.column_selector
16
16
  [ /derby/i, lambda { |cfg, column| column.extend(::ArJdbc::Derby::Column) } ]
17
17
  end
18
+
19
+ def self.jdbc_connection_class
20
+ ::ActiveRecord::ConnectionAdapters::DerbyJdbcConnection
21
+ end
18
22
 
19
23
  def configure_connection
20
24
  execute("SET ISOLATION = SERIALIZABLE")
@@ -36,6 +40,7 @@ module ArJdbc
36
40
  when /^timestamp/i then @sql_type = 'timestamp'; limit = nil
37
41
  when /^time/i then @sql_type = 'time'; limit = nil
38
42
  when /^date/i then @sql_type = 'date'; limit = nil
43
+ when /^xml/i then @sql_type = 'xml'; limit = nil
39
44
  else
40
45
  limit = super
41
46
  # handle maximum length for a VARCHAR string :
@@ -52,6 +57,7 @@ module ArJdbc
52
57
  when /^dec/i then # DEC is a DECIMAL alias
53
58
  extract_scale(field_type) == 0 ? :integer : :decimal
54
59
  when /^timestamp/i then :datetime
60
+ when /^xml/i then :xml
55
61
  else
56
62
  super
57
63
  end
@@ -104,6 +110,7 @@ module ArJdbc
104
110
  :time => { :name => "time" },
105
111
  :datetime => { :name => "timestamp" },
106
112
  :timestamp => { :name => "timestamp" },
113
+ :xml => { :name => "xml" },
107
114
  :boolean => { :name => "smallint" },
108
115
  }
109
116
 
@@ -115,7 +122,7 @@ module ArJdbc
115
122
  super(types)
116
123
  types[:primary_key] = NATIVE_DATABASE_TYPES[:primary_key]
117
124
  [ :string, :float, :decimal, :numeric, :integer,
118
- :smallint, :bigint, :real, :double ].each do |type|
125
+ :smallint, :bigint, :real, :double, :xml ].each do |type|
119
126
  types[type] = NATIVE_DATABASE_TYPES[type].dup
120
127
  end
121
128
  types[:boolean] = NATIVE_DATABASE_TYPES[:boolean].dup
@@ -133,6 +140,19 @@ module ArJdbc
133
140
  native_type.is_a?(Hash) ? native_type[:name] : native_type
134
141
  end
135
142
 
143
+ class TableDefinition < ActiveRecord::ConnectionAdapters::TableDefinition # :nodoc:
144
+
145
+ def xml(*args)
146
+ options = args.extract_options!
147
+ column(args[0], 'xml', options)
148
+ end
149
+
150
+ end
151
+
152
+ def table_definition(*args)
153
+ new_table_definition(TableDefinition, *args)
154
+ end
155
+
136
156
  # Override default -- fix case where ActiveRecord passes :default => nil, :null => true
137
157
  def add_column_options!(sql, options)
138
158
  options.delete(:default) if options.has_key?(:default) && options[:default].nil?
@@ -250,13 +270,7 @@ module ArJdbc
250
270
  end
251
271
  definition
252
272
  end
253
-
254
- def remove_column(table_name, *column_names) # :nodoc:
255
- for column_name in column_names.flatten
256
- execute "ALTER TABLE #{quote_table_name(table_name)} DROP COLUMN #{quote_column_name(column_name)} RESTRICT"
257
- end
258
- end
259
-
273
+
260
274
  AUTO_INC_STMT2 = "" +
261
275
  "SELECT AUTOINCREMENTSTART, AUTOINCREMENTINC, COLUMNNAME, REFERENCEID, COLUMNDEFAULT " +
262
276
  "FROM SYS.SYSCOLUMNS WHERE REFERENCEID = " +
@@ -279,6 +293,12 @@ module ArJdbc
279
293
  ""
280
294
  end
281
295
  private :auto_increment_stmt
296
+
297
+ def remove_column(table_name, *column_names) # :nodoc:
298
+ for column_name in column_names.flatten
299
+ execute "ALTER TABLE #{quote_table_name(table_name)} DROP COLUMN #{quote_column_name(column_name)} RESTRICT"
300
+ end
301
+ end
282
302
 
283
303
  # Notes about changing in Derby:
284
304
  # http://db.apache.org/derby/docs/10.2/ref/rrefsqlj81859.html#rrefsqlj81859__rrefsqlj37860)
@@ -328,7 +348,7 @@ module ArJdbc
328
348
  end
329
349
 
330
350
  def columns(table_name, name = nil)
331
- @connection.columns_internal(table_name.to_s, name, derby_schema)
351
+ @connection.columns_internal(table_name.to_s, nil, derby_schema)
332
352
  end
333
353
 
334
354
  def tables
@@ -1,24 +1,21 @@
1
- module ActiveRecord
2
- class Base
3
- class << self
4
- def derby_connection(config)
5
- begin
6
- require 'jdbc/derby'
7
- ::Jdbc::Derby.load_driver(:require) if defined?(::Jdbc::Derby.load_driver)
8
- rescue LoadError # assuming driver.jar is on the class-path
9
- end
1
+ ArJdbc::ConnectionMethods.module_eval do
2
+ def derby_connection(config)
3
+ begin
4
+ require 'jdbc/derby'
5
+ ::Jdbc::Derby.load_driver(:require) if defined?(::Jdbc::Derby.load_driver)
6
+ rescue LoadError # assuming driver.jar is on the class-path
7
+ end
10
8
 
11
- config[:url] ||= "jdbc:derby:#{config[:database]};create=true"
12
- config[:driver] ||= defined?(::Jdbc::Derby.driver_name) ? ::Jdbc::Derby.driver_name : 'org.apache.derby.jdbc.EmbeddedDriver'
13
- config[:adapter_spec] = ::ArJdbc::Derby
14
- conn = embedded_driver(config)
15
- md = conn.jdbc_connection.meta_data
16
- if md.database_major_version < 10 || (md.database_major_version == 10 && md.database_minor_version < 5)
17
- raise ::ActiveRecord::ConnectionFailed, "Derby adapter requires Derby 10.5 or later"
18
- end
19
- conn
20
- end
21
- alias_method :jdbcderby_connection, :derby_connection
9
+ config[:url] ||= "jdbc:derby:#{config[:database]};create=true"
10
+ config[:driver] ||= defined?(::Jdbc::Derby.driver_name) ? ::Jdbc::Derby.driver_name : 'org.apache.derby.jdbc.EmbeddedDriver'
11
+ config[:adapter_spec] = ::ArJdbc::Derby
12
+ config[:connection_alive_sql] ||= 'SELECT 1 FROM SYS.SYSSCHEMAS FETCH FIRST 1 ROWS ONLY' # FROM clause is mandatory
13
+ connection = embedded_driver(config)
14
+ md = connection.jdbc_connection.meta_data
15
+ if md.database_major_version < 10 || (md.database_major_version == 10 && md.database_minor_version < 5)
16
+ raise ::ActiveRecord::ConnectionFailed, "Derby adapter requires Derby 10.5 or later"
22
17
  end
18
+ connection
23
19
  end
20
+ alias_method :jdbcderby_connection, :derby_connection
24
21
  end
@@ -1,2 +1,2 @@
1
- require 'arjdbc/jdbc'
1
+ require 'arjdbc'
2
2
  require 'arjdbc/firebird/adapter'
data/lib/arjdbc/h2.rb CHANGED
@@ -1,3 +1,3 @@
1
- require 'arjdbc/jdbc'
2
- require 'arjdbc/h2/connection_methods'
1
+ require 'arjdbc'
3
2
  require 'arjdbc/h2/adapter'
3
+ require 'arjdbc/h2/connection_methods'
@@ -152,7 +152,7 @@ module ArJdbc
152
152
  end
153
153
 
154
154
  def columns(table_name, name = nil)
155
- @connection.columns_internal(table_name.to_s, name, h2_schema)
155
+ @connection.columns_internal(table_name.to_s, nil, h2_schema)
156
156
  end
157
157
 
158
158
  def change_column(table_name, column_name, type, options = {}) #:nodoc:
@@ -1,19 +1,15 @@
1
- module ActiveRecord
2
- class Base
3
- class << self
4
- def h2_connection(config)
5
- begin
6
- require 'jdbc/h2'
7
- ::Jdbc::H2.load_driver(:require) if defined?(::Jdbc::H2.load_driver)
8
- rescue LoadError # assuming driver.jar is on the class-path
9
- end
10
-
11
- config[:url] ||= "jdbc:h2:#{config[:database]}"
12
- config[:driver] ||= defined?(::Jdbc::H2.driver_name) ? ::Jdbc::H2.driver_name : 'org.h2.Driver'
13
- config[:adapter_spec] = ::ArJdbc::H2
14
- embedded_driver(config)
15
- end
16
- alias_method :jdbch2_connection, :h2_connection
1
+ ArJdbc::ConnectionMethods.module_eval do
2
+ def h2_connection(config)
3
+ begin
4
+ require 'jdbc/h2'
5
+ ::Jdbc::H2.load_driver(:require) if defined?(::Jdbc::H2.load_driver)
6
+ rescue LoadError # assuming driver.jar is on the class-path
17
7
  end
8
+
9
+ config[:url] ||= "jdbc:h2:#{config[:database]}"
10
+ config[:driver] ||= defined?(::Jdbc::H2.driver_name) ? ::Jdbc::H2.driver_name : 'org.h2.Driver'
11
+ config[:adapter_spec] = ::ArJdbc::H2
12
+ embedded_driver(config)
18
13
  end
14
+ alias_method :jdbch2_connection, :h2_connection
19
15
  end
data/lib/arjdbc/hsqldb.rb CHANGED
@@ -1,3 +1,3 @@
1
- require 'arjdbc/jdbc'
1
+ require 'arjdbc'
2
2
  require 'arjdbc/hsqldb/adapter'
3
3
  require 'arjdbc/hsqldb/connection_methods'
@@ -1,19 +1,16 @@
1
- module ActiveRecord
2
- class Base
3
- class << self
4
- def hsqldb_connection(config)
5
- begin
6
- require 'jdbc/hsqldb'
7
- ::Jdbc::HSQLDB.load_driver(:require) if defined?(::Jdbc::HSQLDB.load_driver)
8
- rescue LoadError # assuming driver.jar is on the class-path
9
- end
10
-
11
- config[:url] ||= "jdbc:hsqldb:#{config[:database]}"
12
- config[:driver] ||= defined?(::Jdbc::HSQLDB.driver_name) ? ::Jdbc::HSQLDB.driver_name : 'org.hsqldb.jdbcDriver'
13
- config[:adapter_spec] = ::ArJdbc::HSQLDB
14
- embedded_driver(config)
15
- end
16
- alias_method :jdbchsqldb_connection, :hsqldb_connection
1
+ ArJdbc::ConnectionMethods.module_eval do
2
+ def hsqldb_connection(config)
3
+ begin
4
+ require 'jdbc/hsqldb'
5
+ ::Jdbc::HSQLDB.load_driver(:require) if defined?(::Jdbc::HSQLDB.load_driver)
6
+ rescue LoadError # assuming driver.jar is on the class-path
17
7
  end
8
+
9
+ config[:url] ||= "jdbc:hsqldb:#{config[:database]}"
10
+ config[:driver] ||= defined?(::Jdbc::HSQLDB.driver_name) ? ::Jdbc::HSQLDB.driver_name : 'org.hsqldb.jdbcDriver'
11
+ config[:adapter_spec] = ::ArJdbc::HSQLDB
12
+ config[:connection_alive_sql] ||= 'CALL PI()' # does not like 'SELECT 1'
13
+ embedded_driver(config)
18
14
  end
15
+ alias_method :jdbchsqldb_connection, :hsqldb_connection
19
16
  end
@@ -1,3 +1,3 @@
1
- require 'arjdbc/jdbc'
1
+ require 'arjdbc'
2
2
  require 'arjdbc/informix/connection_methods'
3
3
  require 'arjdbc/informix/adapter'
@@ -1,11 +1,9 @@
1
- class ActiveRecord::Base
2
- class << self
3
- def informix_connection(config)
4
- config[:port] ||= 9088
5
- config[:url] ||= "jdbc:informix-sqli://#{config[:host]}:#{config[:port]}/#{config[:database]}:INFORMIXSERVER=#{config[:servername]}"
6
- config[:driver] = 'com.informix.jdbc.IfxDriver'
7
- config[:adapter_spec] = ::ArJdbc::Informix
8
- jdbc_connection(config)
9
- end
1
+ ArJdbc::ConnectionMethods.module_eval do
2
+ def informix_connection(config)
3
+ config[:port] ||= 9088
4
+ config[:url] ||= "jdbc:informix-sqli://#{config[:host]}:#{config[:port]}/#{config[:database]}:INFORMIXSERVER=#{config[:servername]}"
5
+ config[:driver] = 'com.informix.jdbc.IfxDriver'
6
+ config[:adapter_spec] = ::ArJdbc::Informix
7
+ jdbc_connection(config)
10
8
  end
11
- end
9
+ end
data/lib/arjdbc/jdbc.rb CHANGED
@@ -1,2 +1,2 @@
1
1
  require 'arjdbc/jdbc/adapter'
2
- require 'arjdbc/jdbc/discover'
2
+ module ArJdbc; self.discover_extensions; end
@@ -1,11 +1,10 @@
1
1
  require 'active_record/version'
2
2
  require 'active_record/connection_adapters/abstract_adapter'
3
+
3
4
  require 'arjdbc/version'
5
+ require 'arjdbc/jdbc/java'
4
6
  require 'arjdbc/jdbc/base_ext'
5
7
  require 'arjdbc/jdbc/connection_methods'
6
- require 'arjdbc/jdbc/compatibility'
7
- require 'arjdbc/jdbc/core_ext'
8
- require 'arjdbc/jdbc/java'
9
8
  require 'arjdbc/jdbc/driver'
10
9
  require 'arjdbc/jdbc/column'
11
10
  require 'arjdbc/jdbc/connection'
@@ -17,9 +16,8 @@ module ActiveRecord
17
16
  module ConnectionAdapters
18
17
  class JdbcAdapter < AbstractAdapter
19
18
  extend ShadowCoreMethods
20
- include CompatibilityMethods if CompatibilityMethods.needed?(self)
21
19
  include JdbcConnectionPoolCallbacks if JdbcConnectionPoolCallbacks.needed?
22
-
20
+
23
21
  attr_reader :config
24
22
 
25
23
  def initialize(connection, logger, config)
@@ -222,11 +220,6 @@ module ActiveRecord
222
220
  alias_chained_method :select_all, :query_cache, :jdbc_select_all
223
221
  alias_chained_method :update, :query_dirty, :jdbc_update
224
222
  alias_chained_method :insert, :query_dirty, :jdbc_insert
225
-
226
- # Do we need this? Not in AR 3.
227
- def select_one(sql, name = nil)
228
- select(sql, name).first
229
- end
230
223
 
231
224
  end
232
225
 
@@ -238,30 +231,57 @@ module ActiveRecord
238
231
  # Executes +sql+ statement in the context of this connection using
239
232
  # +binds+ as the bind substitutes. +name+ is logged along with
240
233
  # the executed +sql+ statement.
241
- def exec_query(sql, name = 'SQL', binds = [])
242
- execute(sql, name, binds)
234
+ def exec_query(sql, name = 'SQL', binds = []) # :nodoc:
235
+ log(sql, name || 'SQL') { @connection.execute_query(to_sql(sql, binds)) }
243
236
  end
244
237
 
245
238
  # Executes insert +sql+ statement in the context of this connection using
246
239
  # +binds+ as the bind substitutes. +name+ is the logged along with
247
240
  # the executed +sql+ statement.
248
- def exec_insert(sql, name, binds)
249
- exec_query(sql, name, binds)
241
+ def exec_insert(sql, name, binds, pk = nil, sequence_name = nil) # :nodoc:
242
+ log(sql, name || 'SQL') { @connection.execute_insert(to_sql(sql, binds)) }
250
243
  end
251
244
 
252
245
  # Executes delete +sql+ statement in the context of this connection using
253
246
  # +binds+ as the bind substitutes. +name+ is the logged along with
254
247
  # the executed +sql+ statement.
255
- def exec_delete(sql, name, binds)
256
- exec_query(sql, name, binds)
248
+ def exec_delete(sql, name, binds) # :nodoc:
249
+ log(sql, name || 'SQL') { @connection.execute_delete(to_sql(sql, binds)) }
257
250
  end
258
251
 
259
252
  # Executes update +sql+ statement in the context of this connection using
260
253
  # +binds+ as the bind substitutes. +name+ is the logged along with
261
254
  # the executed +sql+ statement.
262
- def exec_update(sql, name, binds)
255
+ def exec_update(sql, name, binds) # :nodoc:
256
+ log(sql, name || 'SQL') { @connection.execute_update(to_sql(sql, binds)) }
257
+ end
258
+
259
+ # Similar to {#exec_query} except it returns "raw" results in an array
260
+ # where each rows is a hash with keys as columns (just like Rails used to
261
+ # do up until 3.0) instead of wrapping them in a {#ActiveRecord::Result}.
262
+ def exec_query_raw(sql, name = 'SQL', binds = [], &block) # :nodoc:
263
+ log(sql, name || 'SQL') do
264
+ @connection.execute_query_raw(to_sql(sql, binds), &block)
265
+ end
266
+ end
267
+
268
+ def select_rows(sql, name = nil)
269
+ exec_query_raw(sql, name).map!(&:values)
270
+ end
271
+
272
+ if ActiveRecord::VERSION::MAJOR > 3 # expects AR::Result e.g. from select_all
273
+
274
+ def select(sql, name = nil, binds = [])
263
275
  exec_query(sql, name, binds)
264
276
  end
277
+
278
+ else
279
+
280
+ def select(sql, name = nil, binds = []) # NOTE: only (sql, name) on AR < 3.1
281
+ exec_query_raw(sql, name, binds)
282
+ end
283
+
284
+ end
265
285
 
266
286
  if ActiveRecord::VERSION::MAJOR < 3 # 2.3.x
267
287
 
@@ -273,7 +293,7 @@ module ActiveRecord
273
293
  if name == :skip_logging
274
294
  _execute(sql, name)
275
295
  else
276
- log(sql, name) { _execute(sql, name ||= "SQL") }
296
+ log(sql, name ||= 'SQL') { _execute(sql, name) }
277
297
  end
278
298
  end
279
299
 
@@ -305,20 +325,6 @@ module ActiveRecord
305
325
  @connection.execute(sql)
306
326
  end
307
327
  private :_execute
308
-
309
- # Returns an array of record hashes with the column names as keys and
310
- # column values as values.
311
- # @note on AR-3.2 expects "only" 2 arguments `select(sql, name = nil)`
312
- # we accept 3 arguments as well `select(sql, name = nil, binds = [])`
313
- def select(*args)
314
- execute(*args)
315
- end
316
-
317
- def select_rows(sql, name = nil)
318
- rows = []
319
- select(sql, name).each {|row| rows << row.values }
320
- rows
321
- end
322
328
 
323
329
  # NOTE: we have an extra binds argument at the end due 2.3 support (due {#jdbc_insert}).
324
330
  def insert_sql(sql, name = nil, pk = nil, id_value = nil, sequence_name = nil, binds = []) # :nodoc:
@@ -331,7 +337,7 @@ module ActiveRecord
331
337
  end
332
338
 
333
339
  def table_exists?(name)
334
- jdbc_columns(name) rescue nil
340
+ @connection.table_exists?(name) # schema_name = nil
335
341
  end
336
342
 
337
343
  def indexes(table_name, name = nil, schema_name = nil)
@@ -350,13 +356,23 @@ module ActiveRecord
350
356
  @connection.rollback
351
357
  end
352
358
 
359
+ def begin_isolated_db_transaction(isolation)
360
+ @connection.begin(isolation)
361
+ end
362
+
363
+ # Does this adapter support setting the isolation level for a transaction?
364
+ # @note We allow to ask for a specified transaction isolation level ...
365
+ def supports_transaction_isolation?(level = nil)
366
+ @connection.supports_transaction_isolation?(level)
367
+ end
368
+
353
369
  def write_large_object(*args)
354
370
  @connection.write_large_object(*args)
355
371
  end
356
372
 
357
373
  def pk_and_sequence_for(table)
358
374
  key = primary_key(table)
359
- [key, nil] if key
375
+ [ key, nil ] if key
360
376
  end
361
377
 
362
378
  def primary_key(table)
@@ -367,44 +383,88 @@ module ActiveRecord
367
383
  @connection.primary_keys(table)
368
384
  end
369
385
 
370
- if ActiveRecord::VERSION::MAJOR >= 3
371
-
372
- # Converts an arel AST to SQL
373
- def to_sql(arel, binds = [])
374
- if arel.respond_to?(:ast)
375
- visitor.accept(arel.ast) do
376
- quote(*binds.shift.reverse)
377
- end
378
- else # for backwards compatibility :
386
+ if ActiveRecord::VERSION::MAJOR == 3 && ActiveRecord::VERSION::MINOR == 0
387
+
388
+ #attr_reader :visitor unless method_defined?(:visitor) # not in 3.0
389
+
390
+ # Converts an AREL AST to SQL.
391
+ def to_sql(arel, binds = [])
392
+ # NOTE: can not handle `visitor.accept(arel.ast)` right thus
393
+ # convert AREL to a SQL string and simply substitute binds :
379
394
  sql = arel.respond_to?(:to_sql) ? arel.send(:to_sql) : arel
380
395
  return sql if binds.blank?
381
396
  sql.gsub('?') { quote(*binds.shift.reverse) }
382
397
  end
383
- end
398
+
399
+ elsif ActiveRecord::VERSION::MAJOR >= 3 # AR >= 3.1 or 4.0
400
+
401
+ # Converts an AREL AST to SQL.
402
+ def to_sql(arel, binds = [])
403
+ if arel.respond_to?(:ast)
404
+ visitor.accept(arel.ast) { quote(*binds.shift.reverse) }
405
+ else # for backwards compatibility :
406
+ sql = arel.respond_to?(:to_sql) ? arel.send(:to_sql) : arel
407
+ return sql if binds.blank?
408
+ sql.gsub('?') { quote(*binds.shift.reverse) }
409
+ end
410
+ end
384
411
 
385
412
  else # AR-2.3 no #to_sql method
386
413
 
387
- # Substitutes SQL bind (?) parameters
388
- def to_sql(sql, binds = [])
389
- sql = sql.send(:to_sql) if sql.respond_to?(:to_sql)
390
- return sql if binds.blank?
391
- copy = binds.dup
392
- sql.gsub('?') { quote(*copy.shift.reverse) }
393
- end
414
+ # Substitutes SQL bind parameters.
415
+ def to_sql(sql, binds = [])
416
+ sql = sql.send(:to_sql) if sql.respond_to?(:to_sql)
417
+ return sql if binds.blank?
418
+ copy = binds.dup
419
+ sql.gsub('?') { quote(*copy.shift.reverse) }
420
+ end
394
421
 
395
422
  end
396
423
 
397
424
  protected
398
425
 
399
426
  def translate_exception(e, message)
400
- puts e.backtrace if $DEBUG || ENV['DEBUG']
401
- super
427
+ # we shall not translate native "Java" exceptions as they might
428
+ # swallow an ArJdbc / driver bug into a AR::StatementInvalid ...
429
+ return e if e.is_a?(NativeException) # JRuby 1.6
430
+ return e if e.is_a?(Java::JavaLang::Throwable)
431
+ super # NOTE: wraps AR::JDBCError into AR::StatementInvalid, desired ?!
402
432
  end
403
433
 
404
434
  def last_inserted_id(result)
405
435
  result
406
436
  end
407
437
 
438
+ # Helper to handle 3.x/4.0 uniformly override #table_definition as :
439
+ #
440
+ # def table_definition(*args)
441
+ # new_table_definition(TableDefinition, *args)
442
+ # end
443
+ #
444
+ def new_table_definition(table_definition, *args)
445
+ table_definition.new(self) # args ignored only used for 4.0
446
+ end
447
+ private :new_table_definition
448
+
449
+ # if adapter overrides #table_definition it works on 3.x as well as 4.0
450
+ if ActiveRecord::VERSION::MAJOR > 3
451
+
452
+ # aliasing #create_table_definition as #table_definition :
453
+ alias table_definition create_table_definition
454
+
455
+ # TableDefinition.new native_database_types, name, temporary, options
456
+ def create_table_definition(name, temporary, options)
457
+ table_definition(name, temporary, options)
458
+ end
459
+
460
+ # arguments expected: (name, temporary, options)
461
+ def new_table_definition(table_definition, *args)
462
+ table_definition.new native_database_types, *args
463
+ end
464
+ private :new_table_definition
465
+
466
+ end
467
+
408
468
  private
409
469
 
410
470
  # #deprecated no longer used
@@ -436,7 +496,19 @@ module ActiveRecord
436
496
  def self.update?(sql)
437
497
  ! select?(sql) && ! insert?(sql)
438
498
  end
499
+
500
+ unless defined? AbstractAdapter.type_cast_config_to_integer
501
+
502
+ def self.type_cast_config_to_integer(config)
503
+ config =~ /\A\d+\z/ ? config.to_i : config
504
+ end
439
505
 
506
+ def self.type_cast_config_to_boolean(config)
507
+ config == "false" ? false : config
508
+ end
509
+
510
+ end
511
+
440
512
  end
441
513
  end
442
514
  end