activerecord-jdbc-adapter 1.3.0.beta2 → 1.3.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (282) hide show
  1. data/.gitignore +14 -8
  2. data/.travis.yml +40 -31
  3. data/.yardopts +4 -0
  4. data/Appraisals +2 -5
  5. data/CONTRIBUTING.md +46 -0
  6. data/Gemfile +21 -4
  7. data/Gemfile.lock +42 -17
  8. data/{History.txt → History.md} +142 -75
  9. data/README.md +102 -104
  10. data/RUNNING_TESTS.md +76 -0
  11. data/Rakefile.jdbc +20 -0
  12. data/activerecord-jdbc-adapter.gemspec +35 -18
  13. data/gemfiles/rails23.gemfile +4 -3
  14. data/gemfiles/rails23.gemfile.lock +9 -6
  15. data/gemfiles/rails30.gemfile +4 -3
  16. data/gemfiles/rails30.gemfile.lock +9 -6
  17. data/gemfiles/rails31.gemfile +4 -3
  18. data/gemfiles/rails31.gemfile.lock +9 -6
  19. data/gemfiles/rails32.gemfile +4 -3
  20. data/gemfiles/rails32.gemfile.lock +17 -14
  21. data/gemfiles/rails40.gemfile +5 -5
  22. data/gemfiles/rails40.gemfile.lock +17 -69
  23. data/lib/active_record/connection_adapters/firebird_adapter.rb +1 -0
  24. data/lib/active_record/connection_adapters/sqlserver_adapter.rb +1 -0
  25. data/lib/arel/visitors/compat.rb +22 -3
  26. data/lib/arel/visitors/db2.rb +8 -4
  27. data/lib/arel/visitors/derby.rb +14 -13
  28. data/lib/arel/visitors/firebird.rb +5 -4
  29. data/lib/arel/visitors/hsqldb.rb +11 -9
  30. data/lib/arel/visitors/sql_server.rb +89 -61
  31. data/lib/arjdbc.rb +1 -1
  32. data/lib/arjdbc/db2/adapter.rb +181 -212
  33. data/lib/arjdbc/db2/as400.rb +31 -18
  34. data/lib/arjdbc/db2/column.rb +167 -0
  35. data/lib/arjdbc/db2/connection_methods.rb +2 -0
  36. data/lib/arjdbc/derby/adapter.rb +206 -107
  37. data/lib/arjdbc/derby/connection_methods.rb +4 -9
  38. data/lib/arjdbc/firebird.rb +1 -0
  39. data/lib/arjdbc/firebird/adapter.rb +202 -64
  40. data/lib/arjdbc/firebird/connection_methods.rb +20 -0
  41. data/lib/arjdbc/h2/adapter.rb +56 -36
  42. data/lib/arjdbc/hsqldb/adapter.rb +99 -68
  43. data/lib/arjdbc/jdbc/adapter.rb +474 -265
  44. data/lib/arjdbc/jdbc/adapter_java.jar +0 -0
  45. data/lib/arjdbc/jdbc/adapter_require.rb +8 -7
  46. data/lib/arjdbc/jdbc/arel_support.rb +132 -0
  47. data/lib/arjdbc/jdbc/base_ext.rb +8 -7
  48. data/lib/arjdbc/jdbc/callbacks.rb +16 -10
  49. data/lib/arjdbc/jdbc/column.rb +25 -3
  50. data/lib/arjdbc/jdbc/connection.rb +28 -55
  51. data/lib/arjdbc/jdbc/extension.rb +14 -14
  52. data/lib/arjdbc/jdbc/java.rb +6 -3
  53. data/lib/arjdbc/jdbc/jdbc.rake +1 -1
  54. data/lib/arjdbc/jdbc/quoted_primary_key.rb +2 -2
  55. data/lib/arjdbc/jdbc/rake_tasks.rb +1 -1
  56. data/lib/arjdbc/jdbc/type_converter.rb +5 -2
  57. data/lib/arjdbc/mssql/adapter.rb +160 -280
  58. data/lib/arjdbc/mssql/column.rb +182 -0
  59. data/lib/arjdbc/mssql/connection_methods.rb +37 -4
  60. data/lib/arjdbc/mssql/explain_support.rb +13 -21
  61. data/lib/arjdbc/mssql/limit_helpers.rb +79 -42
  62. data/lib/arjdbc/mssql/lock_methods.rb +77 -0
  63. data/lib/arjdbc/mssql/utils.rb +11 -11
  64. data/lib/arjdbc/mysql/adapter.rb +165 -247
  65. data/lib/arjdbc/mysql/column.rb +123 -0
  66. data/lib/arjdbc/mysql/connection_methods.rb +3 -6
  67. data/lib/arjdbc/oracle/adapter.rb +282 -288
  68. data/lib/arjdbc/oracle/column.rb +122 -0
  69. data/lib/arjdbc/oracle/connection_methods.rb +3 -0
  70. data/lib/arjdbc/postgresql/adapter.rb +336 -574
  71. data/lib/arjdbc/postgresql/column.rb +458 -0
  72. data/lib/arjdbc/postgresql/connection_methods.rb +1 -2
  73. data/lib/arjdbc/postgresql/schema_creation.rb +38 -0
  74. data/lib/arjdbc/sqlite3/adapter.rb +189 -145
  75. data/lib/arjdbc/sqlite3/explain_support.rb +1 -1
  76. data/lib/arjdbc/tasks/oracle/enhanced_structure_dump.rb +8 -8
  77. data/lib/arjdbc/util/quoted_cache.rb +60 -0
  78. data/lib/arjdbc/util/table_copier.rb +110 -0
  79. data/lib/arjdbc/version.rb +6 -7
  80. data/pom.xml +56 -2
  81. data/rakelib/02-test.rake +72 -83
  82. data/rakelib/db.rake +29 -17
  83. data/src/java/arjdbc/ArJdbcModule.java +21 -18
  84. data/src/java/arjdbc/db2/DB2RubyJdbcConnection.java +84 -12
  85. data/src/java/arjdbc/derby/DerbyModule.java +140 -143
  86. data/src/java/arjdbc/derby/DerbyRubyJdbcConnection.java +58 -7
  87. data/src/java/arjdbc/h2/H2Module.java +43 -0
  88. data/src/java/arjdbc/informix/InformixRubyJdbcConnection.java +7 -6
  89. data/src/java/arjdbc/jdbc/RubyJdbcConnection.java +1223 -648
  90. data/src/java/arjdbc/mssql/MSSQLRubyJdbcConnection.java +24 -23
  91. data/src/java/arjdbc/mysql/MySQLModule.java +33 -32
  92. data/src/java/arjdbc/mysql/MySQLRubyJdbcConnection.java +147 -30
  93. data/src/java/arjdbc/oracle/OracleModule.java +13 -13
  94. data/src/java/arjdbc/oracle/OracleRubyJdbcConnection.java +114 -6
  95. data/src/java/arjdbc/postgresql/PostgreSQLRubyJdbcConnection.java +166 -36
  96. data/src/java/arjdbc/sqlite3/SQLite3RubyJdbcConnection.java +101 -19
  97. data/src/java/arjdbc/util/QuotingUtils.java +19 -19
  98. metadata +240 -394
  99. data/bench/bench_attributes.rb +0 -13
  100. data/bench/bench_attributes_new.rb +0 -14
  101. data/bench/bench_create.rb +0 -12
  102. data/bench/bench_find_all.rb +0 -12
  103. data/bench/bench_find_all_mt.rb +0 -25
  104. data/bench/bench_model.rb +0 -85
  105. data/bench/bench_new.rb +0 -12
  106. data/bench/bench_new_valid.rb +0 -12
  107. data/bench/bench_valid.rb +0 -13
  108. data/lib/arel/engines/sql/compilers/db2_compiler.rb +0 -9
  109. data/lib/arel/engines/sql/compilers/derby_compiler.rb +0 -6
  110. data/lib/arel/engines/sql/compilers/h2_compiler.rb +0 -6
  111. data/lib/arel/engines/sql/compilers/hsqldb_compiler.rb +0 -15
  112. data/lib/arel/engines/sql/compilers/jdbc_compiler.rb +0 -6
  113. data/lib/arel/engines/sql/compilers/mssql_compiler.rb +0 -46
  114. data/lib/arjdbc/jdbc/missing_functionality_helper.rb +0 -98
  115. data/lib/arjdbc/mssql/lock_helpers.rb +0 -76
  116. data/lib/arjdbc/mssql/tsql_methods.rb +0 -58
  117. data/lib/arjdbc/postgresql/column_cast.rb +0 -134
  118. data/test/activerecord/connections/native_jdbc_mysql/connection.rb +0 -25
  119. data/test/activerecord/jall.sh +0 -7
  120. data/test/activerecord/jtest.sh +0 -3
  121. data/test/assets/flowers.jpg +0 -0
  122. data/test/binary.rb +0 -67
  123. data/test/db/db2.rb +0 -43
  124. data/test/db/db2/binary_test.rb +0 -6
  125. data/test/db/db2/has_many_through_test.rb +0 -6
  126. data/test/db/db2/rake_test.rb +0 -82
  127. data/test/db/db2/rake_test_data.sql +0 -35
  128. data/test/db/db2/reset_column_information_test.rb +0 -5
  129. data/test/db/db2/serialize_test.rb +0 -6
  130. data/test/db/db2/simple_test.rb +0 -81
  131. data/test/db/db2/test_helper.rb +0 -6
  132. data/test/db/db2/unit_test.rb +0 -73
  133. data/test/db/derby.rb +0 -12
  134. data/test/db/derby/binary_test.rb +0 -6
  135. data/test/db/derby/migration_test.rb +0 -74
  136. data/test/db/derby/rake_test.rb +0 -96
  137. data/test/db/derby/reset_column_information_test.rb +0 -6
  138. data/test/db/derby/row_locking_test.rb +0 -20
  139. data/test/db/derby/schema_dump_test.rb +0 -5
  140. data/test/db/derby/serialize_test.rb +0 -6
  141. data/test/db/derby/simple_test.rb +0 -173
  142. data/test/db/derby/test_helper.rb +0 -6
  143. data/test/db/derby/unit_test.rb +0 -32
  144. data/test/db/derby/xml_column_test.rb +0 -17
  145. data/test/db/h2.rb +0 -11
  146. data/test/db/h2/binary_test.rb +0 -6
  147. data/test/db/h2/change_column_test.rb +0 -68
  148. data/test/db/h2/identity_column_test.rb +0 -35
  149. data/test/db/h2/offset_test.rb +0 -49
  150. data/test/db/h2/rake_test.rb +0 -98
  151. data/test/db/h2/schema_dump_test.rb +0 -29
  152. data/test/db/h2/serialize_test.rb +0 -6
  153. data/test/db/h2/simple_test.rb +0 -56
  154. data/test/db/hsqldb.rb +0 -11
  155. data/test/db/hsqldb/binary_test.rb +0 -6
  156. data/test/db/hsqldb/rake_test.rb +0 -101
  157. data/test/db/hsqldb/schema_dump_test.rb +0 -19
  158. data/test/db/hsqldb/serialize_test.rb +0 -6
  159. data/test/db/hsqldb/simple_test.rb +0 -17
  160. data/test/db/informix.rb +0 -13
  161. data/test/db/jdbc.rb +0 -16
  162. data/test/db/jdbc_derby.rb +0 -14
  163. data/test/db/jdbc_h2.rb +0 -17
  164. data/test/db/jdbc_mysql.rb +0 -13
  165. data/test/db/jdbc_postgres.rb +0 -23
  166. data/test/db/jndi_config.rb +0 -32
  167. data/test/db/jndi_pooled_config.rb +0 -32
  168. data/test/db/mssql.rb +0 -11
  169. data/test/db/mssql/binary_test.rb +0 -6
  170. data/test/db/mssql/exec_proc_test.rb +0 -46
  171. data/test/db/mssql/identity_insert_test.rb +0 -18
  172. data/test/db/mssql/ignore_system_views_test.rb +0 -40
  173. data/test/db/mssql/limit_offset_test.rb +0 -190
  174. data/test/db/mssql/multibyte_test.rb +0 -16
  175. data/test/db/mssql/multiple_connections_test.rb +0 -71
  176. data/test/db/mssql/rake_test.rb +0 -143
  177. data/test/db/mssql/reset_column_information_test.rb +0 -6
  178. data/test/db/mssql/row_locking_test.rb +0 -7
  179. data/test/db/mssql/serialize_test.rb +0 -6
  180. data/test/db/mssql/simple_test.rb +0 -140
  181. data/test/db/mssql/transaction_test.rb +0 -6
  182. data/test/db/mssql/types_test.rb +0 -205
  183. data/test/db/mssql/unit_test.rb +0 -249
  184. data/test/db/mysql.rb +0 -4
  185. data/test/db/mysql/_rails_test_mysql.32.out +0 -6585
  186. data/test/db/mysql/binary_test.rb +0 -6
  187. data/test/db/mysql/connection_test.rb +0 -51
  188. data/test/db/mysql/index_length_test.rb +0 -58
  189. data/test/db/mysql/multibyte_test.rb +0 -10
  190. data/test/db/mysql/nonstandard_primary_key_test.rb +0 -39
  191. data/test/db/mysql/rake_test.rb +0 -97
  192. data/test/db/mysql/reset_column_information_test.rb +0 -6
  193. data/test/db/mysql/schema_dump_test.rb +0 -228
  194. data/test/db/mysql/serialize_test.rb +0 -6
  195. data/test/db/mysql/simple_test.rb +0 -187
  196. data/test/db/mysql/statement_escaping_test.rb +0 -46
  197. data/test/db/mysql/transaction_test.rb +0 -6
  198. data/test/db/mysql/types_test.rb +0 -30
  199. data/test/db/mysql/unit_test.rb +0 -93
  200. data/test/db/mysql_config.rb +0 -7
  201. data/test/db/oracle.rb +0 -27
  202. data/test/db/oracle/binary_test.rb +0 -6
  203. data/test/db/oracle/limit_test.rb +0 -24
  204. data/test/db/oracle/multibyte_test.rb +0 -22
  205. data/test/db/oracle/rake_test.rb +0 -100
  206. data/test/db/oracle/reset_column_information_test.rb +0 -6
  207. data/test/db/oracle/serialize_test.rb +0 -6
  208. data/test/db/oracle/simple_test.rb +0 -140
  209. data/test/db/oracle/specific_test.rb +0 -180
  210. data/test/db/oracle/transaction_test.rb +0 -31
  211. data/test/db/oracle/unit_test.rb +0 -31
  212. data/test/db/postgres.rb +0 -11
  213. data/test/db/postgres/_rails_test_postgres.32.out +0 -6405
  214. data/test/db/postgres/a_custom_primary_key_test.rb +0 -50
  215. data/test/db/postgres/active_schema_unit_test.rb +0 -68
  216. data/test/db/postgres/array_type_test.rb +0 -101
  217. data/test/db/postgres/binary_test.rb +0 -6
  218. data/test/db/postgres/connection_test.rb +0 -63
  219. data/test/db/postgres/data_types_test.rb +0 -703
  220. data/test/db/postgres/hstore_test.rb +0 -200
  221. data/test/db/postgres/information_schema_leak_test.rb +0 -30
  222. data/test/db/postgres/json_test.rb +0 -86
  223. data/test/db/postgres/ltree_test.rb +0 -51
  224. data/test/db/postgres/mixed_case_test.rb +0 -29
  225. data/test/db/postgres/native_types_test.rb +0 -124
  226. data/test/db/postgres/rake_test.rb +0 -117
  227. data/test/db/postgres/reserved_test.rb +0 -22
  228. data/test/db/postgres/reset_column_information_test.rb +0 -6
  229. data/test/db/postgres/row_locking_test.rb +0 -21
  230. data/test/db/postgres/schema_dump_test.rb +0 -95
  231. data/test/db/postgres/schema_test.rb +0 -115
  232. data/test/db/postgres/simple_test.rb +0 -260
  233. data/test/db/postgres/table_alias_length_test.rb +0 -16
  234. data/test/db/postgres/transaction_test.rb +0 -6
  235. data/test/db/postgres/unit_test.rb +0 -31
  236. data/test/db/postgres_config.rb +0 -10
  237. data/test/db/sqlite3.rb +0 -6
  238. data/test/db/sqlite3/_rails_test_sqlite3.32.out +0 -6274
  239. data/test/db/sqlite3/has_many_though_test.rb +0 -6
  240. data/test/db/sqlite3/rake_test.rb +0 -71
  241. data/test/db/sqlite3/reset_column_information_test.rb +0 -6
  242. data/test/db/sqlite3/schema_dump_test.rb +0 -6
  243. data/test/db/sqlite3/serialize_test.rb +0 -6
  244. data/test/db/sqlite3/simple_test.rb +0 -268
  245. data/test/db/sqlite3/transaction_test.rb +0 -32
  246. data/test/db/sqlite3/type_conversion_test.rb +0 -104
  247. data/test/has_many_through.rb +0 -61
  248. data/test/informix_simple_test.rb +0 -48
  249. data/test/jdbc/db2.rb +0 -36
  250. data/test/jdbc/oracle.rb +0 -34
  251. data/test/jdbc_column_test.rb +0 -23
  252. data/test/jdbc_common.rb +0 -16
  253. data/test/jdbc_connection_test.rb +0 -196
  254. data/test/jndi_callbacks_test.rb +0 -33
  255. data/test/jndi_test.rb +0 -55
  256. data/test/manualTestDatabase.rb +0 -191
  257. data/test/models/add_not_null_column_to_table.rb +0 -9
  258. data/test/models/auto_id.rb +0 -15
  259. data/test/models/binary.rb +0 -18
  260. data/test/models/custom_pk_name.rb +0 -15
  261. data/test/models/data_types.rb +0 -40
  262. data/test/models/entry.rb +0 -41
  263. data/test/models/mixed_case.rb +0 -22
  264. data/test/models/reserved_word.rb +0 -15
  265. data/test/models/rights_and_roles.rb +0 -57
  266. data/test/models/string_id.rb +0 -17
  267. data/test/models/thing.rb +0 -17
  268. data/test/models/topic.rb +0 -32
  269. data/test/models/validates_uniqueness_of_string.rb +0 -19
  270. data/test/rails/mysql.rb +0 -13
  271. data/test/rails/sqlite3/version.rb +0 -6
  272. data/test/rails_stub.rb +0 -31
  273. data/test/rake_test_support.rb +0 -298
  274. data/test/row_locking.rb +0 -102
  275. data/test/schema_dump.rb +0 -182
  276. data/test/serialize.rb +0 -275
  277. data/test/shared_helper.rb +0 -35
  278. data/test/simple.rb +0 -1317
  279. data/test/sybase_jtds_simple_test.rb +0 -28
  280. data/test/sybase_reset_column_information_test.rb +0 -6
  281. data/test/test_helper.rb +0 -304
  282. data/test/transaction.rb +0 -109
@@ -1,4 +1,4 @@
1
- module ::ArJdbc
1
+ module ArJdbc
2
2
  module SQLite3
3
3
  module ExplainSupport
4
4
  def supports_explain?
@@ -73,7 +73,7 @@ module ActiveRecord #:nodoc:
73
73
 
74
74
  def structure_dump_primary_key(table) #:nodoc:
75
75
  opts = {:name => '', :cols => []}
76
- pks = select_all(<<-SQL, "Primary Keys")
76
+ pks = select_all(<<-SQL, "Primary Keys")
77
77
  SELECT a.constraint_name, a.column_name, a.position
78
78
  FROM user_cons_columns a
79
79
  JOIN user_constraints c
@@ -91,7 +91,7 @@ module ActiveRecord #:nodoc:
91
91
 
92
92
  def structure_dump_unique_keys(table) #:nodoc:
93
93
  keys = {}
94
- uks = select_all(<<-SQL, "Primary Keys")
94
+ uks = select_all(<<-SQL, "Primary Keys")
95
95
  SELECT a.constraint_name, a.column_name, a.position
96
96
  FROM user_cons_columns a
97
97
  JOIN user_constraints c
@@ -152,21 +152,21 @@ module ActiveRecord #:nodoc:
152
152
  AND name NOT LIKE 'BIN$%'
153
153
  AND owner = SYS_CONTEXT('userenv', 'session_user') ORDER BY type").each do |source|
154
154
  ddl = "CREATE OR REPLACE \n"
155
- lines = select_all(%Q{
155
+ select_all(%Q{
156
156
  SELECT text
157
157
  FROM all_source
158
158
  WHERE name = '#{source['name']}'
159
159
  AND type = '#{source['type']}'
160
160
  AND owner = SYS_CONTEXT('userenv', 'session_user')
161
161
  ORDER BY line
162
- }).map do |row|
162
+ }).each do |row|
163
163
  ddl << row['text']
164
164
  end
165
- ddl << ";" unless ddl.strip[-1,1] == ";"
165
+ ddl << ";" unless ddl.strip[-1,1] == ';'
166
166
  structure << ddl
167
167
  end
168
168
 
169
- # export views
169
+ # export views
170
170
  select_all("SELECT view_name, text FROM user_views").each do |view|
171
171
  structure << "CREATE OR REPLACE VIEW #{view['view_name']} AS\n #{view['text']}"
172
172
  end
@@ -243,14 +243,14 @@ module ActiveRecord #:nodoc:
243
243
 
244
244
  def execute_structure_dump(string)
245
245
  string.split(STATEMENT_TOKEN).each do |ddl|
246
- ddl.chop! if ddl[-1] == ';'
246
+ ddl.chop! if ddl[-1,1] == ';'
247
247
  execute(ddl) unless ddl.blank?
248
248
  end
249
249
  end
250
250
 
251
251
  private
252
252
 
253
- # virtual columns are an 11g feature. This returns [] if feature is not
253
+ # virtual columns are an 11g feature. This returns [] if feature is not
254
254
  # present or none are found.
255
255
  # return [{'column_name' => 'FOOS', 'data_default' => '...'}, ...]
256
256
  def virtual_columns_for(table)
@@ -0,0 +1,60 @@
1
+ module ArJdbc
2
+ module Util
3
+ # Caches table and column name (quoted) outcomes.
4
+ # Uses {ThreadSafe::Cache} as a concurrent lock free (on JRuby) cache backend.
5
+ # The thread_safe gem is a dependency since ActiveSupport 4.0, when using
6
+ # ActiveRecord <= 3.2 one should add `gem 'thread_safe'` into the *Gemfile*
7
+ # as it is not forced (currently) as an explicit gem dependency.
8
+ #
9
+ # Caching can also be disabled by setting the *arjdbc.quoted_cache.disabled*
10
+ # system property = 'true'.
11
+ module QuotedCache
12
+
13
+ # @private
14
+ DISABLED = Java::JavaLang::Boolean.getBoolean('arjdbc.quoted_cache.disabled')
15
+
16
+ def self.included(base)
17
+ # the thread_safe gem is an ActiveSupport dependency (since 4.0) :
18
+ begin; require 'thread_safe'; rescue LoadError; end unless DISABLED
19
+ if ! DISABLED && defined? ThreadSafe::Cache
20
+ base.const_set :QUOTED_TABLE_NAMES, ThreadSafe::Cache.new
21
+ base.const_set :QUOTED_COLUMN_NAMES, ThreadSafe::Cache.new
22
+ else
23
+ base.const_set :QUOTED_TABLE_NAMES, nil
24
+ base.const_set :QUOTED_COLUMN_NAMES, nil
25
+ end
26
+ end
27
+
28
+ # Caches quoted table names, the cache is stored in the class'
29
+ # `QUOTED_TABLE_NAMES` constant.
30
+ # @return [String]
31
+ def quote_table_name(name)
32
+ if cache = self.class::QUOTED_TABLE_NAMES
33
+ unless quoted = cache[name]
34
+ quoted = super
35
+ cache.put_if_absent name, quoted.freeze
36
+ end
37
+ quoted
38
+ else
39
+ super
40
+ end
41
+ end
42
+
43
+ # Caches quoted table names, the cache is stored in the class'
44
+ # `QUOTED_COLUMN_NAMES` constant.
45
+ # @return [String]
46
+ def quote_column_name(name)
47
+ if cache = self.class::QUOTED_COLUMN_NAMES
48
+ unless quoted = cache[name]
49
+ quoted = super
50
+ cache.put_if_absent name, quoted.freeze
51
+ end
52
+ quoted
53
+ else
54
+ super
55
+ end
56
+ end
57
+
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,110 @@
1
+ module ArJdbc
2
+ module Util
3
+ module TableCopier
4
+
5
+ # taken from SQLite adapter, code loosely based on http://git.io/P7tFQA
6
+
7
+ # Performs changes for table by first copying (and preserving contents)
8
+ # into another (temporary) table, than alters and copies all data back.
9
+ def alter_table(table_name, options = {})
10
+ table_name = table_name.to_s.downcase
11
+ altered_table_name = "a#{table_name}"
12
+ caller = lambda { |definition| yield definition if block_given? }
13
+
14
+ transaction do
15
+ # A temporary table might improve performance here, but
16
+ # it doesn't seem to maintain indices across the whole move.
17
+ move_table(table_name, altered_table_name, options)
18
+ move_table(altered_table_name, table_name, &caller)
19
+ end
20
+ end
21
+
22
+ # Move a table into another while preserving all content.
23
+ # @see #copy_table
24
+ def move_table(from, to, options = {}, &block)
25
+ copy_table(from, to, options, &block)
26
+ drop_table(from)
27
+ end
28
+
29
+ # @see #copy_table_contents
30
+ # @see #copy_table_indexes
31
+ def copy_table(from, to, options = {})
32
+ from_primary_key = primary_key(from)
33
+ create_table(to, options.merge(:id => false)) do |definition|
34
+ @definition = definition
35
+ @definition.primary_key(from_primary_key) if from_primary_key.present?
36
+ columns(from).each do |column|
37
+ column_name = options[:rename] ?
38
+ (options[:rename][column.name] ||
39
+ options[:rename][column.name.to_sym] ||
40
+ column.name) : column.name
41
+
42
+ next if column_name == from_primary_key
43
+
44
+ @definition.column(column_name, column.type,
45
+ :limit => column.limit, :default => column.default,
46
+ :precision => column.precision, :scale => column.scale,
47
+ :null => column.null)
48
+ end
49
+ yield @definition if block_given?
50
+ end
51
+
52
+ copy_table_indexes(from, to, options[:rename] || {})
53
+ copy_table_contents(from, to,
54
+ @definition.columns.map {|column| column.name},
55
+ options[:rename] || {})
56
+ end
57
+
58
+ # Copies indexes for a given table.
59
+ def copy_table_indexes(from, to, rename = {})
60
+ indexes(from).each do |index|
61
+ name = index.name.downcase
62
+ if to == "a#{from}"
63
+ name = "t#{name}"
64
+ elsif from == "a#{to}"
65
+ name = name[1..-1]
66
+ end
67
+
68
+ to_column_names = columns(to).map(&:name)
69
+ columns = index.columns.map { |column| rename[column] || column }
70
+ columns = columns.select { |column| to_column_names.include?(column) }
71
+
72
+ unless columns.empty?
73
+ # index name can't be the same
74
+ opts = { :name => name.gsub(/(^|_)(#{from})_/, "\\1#{to}_"), :internal => true }
75
+ opts[:unique] = true if index.unique
76
+ add_index(to, columns, opts)
77
+ end
78
+ end
79
+ end
80
+
81
+ # Copies the content of a table into another.
82
+ def copy_table_contents(from, to, columns, rename = {})
83
+ column_mappings = Hash[ columns.map { |name| [name, name] } ]
84
+ rename.each { |a| column_mappings[a.last] = a.first }
85
+ from_columns = columns(from).collect {|col| col.name}
86
+ columns = columns.find_all{ |col| from_columns.include?(column_mappings[col]) }
87
+ quoted_columns = columns.map { |col| quote_column_name(col) } * ','
88
+
89
+ quoted_to = quote_table_name(to)
90
+
91
+ raw_column_mappings = Hash[ columns(from).map { |c| [c.name, c] } ]
92
+
93
+ execute("SELECT * FROM #{quote_table_name(from)}", 'Copy Table').each do |row|
94
+ sql = "INSERT INTO #{quoted_to} (#{quoted_columns}) VALUES ("
95
+
96
+ column_values = columns.map do |col|
97
+ quote(row[column_mappings[col]], raw_column_mappings[col])
98
+ end
99
+
100
+ sql << column_values * ', '
101
+ sql << ')'
102
+ exec_insert sql, 'Copy Table', []
103
+ end
104
+ end
105
+
106
+ end
107
+ end
108
+ # @private @deprecated backwards compatibility
109
+ MissingFunctionalityHelper = Util::TableCopier
110
+ end
@@ -1,9 +1,8 @@
1
1
  module ArJdbc
2
- VERSION = "1.3.0.beta2"
3
- module Version # :nodoc:
4
- VERSION = ArJdbc::VERSION # :nodoc: 1.2.x compatibility
2
+ VERSION = "1.3.0.rc1"
3
+ # @deprecated
4
+ module Version
5
+ # @private 1.2.x compatibility
6
+ VERSION = ArJdbc::VERSION
5
7
  end
6
- end
7
- # Compatibility with older versions of ar-jdbc for other extensions out there
8
- JdbcAdapter = ArJdbc # :nodoc:
9
- JdbcSpec = ArJdbc # :nodoc:
8
+ end
data/pom.xml CHANGED
@@ -11,6 +11,10 @@
11
11
  </description>
12
12
  <url>http://github.com/jruby/activerecord-jdbc-adapter/wiki</url>
13
13
 
14
+ <properties>
15
+ <jruby.version>1.6.8</jruby.version>
16
+ </properties>
17
+
14
18
  <issueManagement>
15
19
  <system>GitHub</system>
16
20
  <url>http://github.com/jruby/activerecord-jdbc-adapter/issues</url>
@@ -28,14 +32,47 @@
28
32
  <url>http://www.opensource.org/licenses/bsd-license.php</url>
29
33
  <distribution>repo</distribution>
30
34
  </license>
35
+ <license>
36
+ <name>MIT License</name>
37
+ <url>http://www.opensource.org/licenses/mit-license.php</url>
38
+ <distribution>repo</distribution>
39
+ </license>
31
40
  </licenses>
41
+ <!--
42
+ <repositories>
43
+ <repository>
44
+ <id>codehaus</id>
45
+ <name>Codehaus Repository</name>
46
+ <releases>
47
+ <enabled>true</enabled>
48
+ </releases>
49
+ <snapshots>
50
+ <enabled>false</enabled>
51
+ </snapshots>
52
+ <url>http://repository.codehaus.org</url>
53
+ </repository>
54
+ </repositories>-->
55
+
56
+ <developers>
57
+ <developer>
58
+ <id>nicksieger</id>
59
+ <name>Nick Sieger</name>
60
+ <email>nicksieger@gmail.com</email>
61
+ </developer>
62
+ <developer>
63
+ <id>kares</id>
64
+ <name>Karol Bucek</name>
65
+ <email>self@kares.org</email>
66
+ </developer>
67
+ </developers>
32
68
 
33
69
  <dependencies>
34
70
  <dependency>
35
71
  <groupId>org.jruby</groupId>
36
72
  <artifactId>jruby-complete</artifactId>
37
- <version>1.6.8</version>
73
+ <version>${jruby.version}</version>
38
74
  </dependency>
75
+
39
76
  <!-- e.g.
40
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
41
78
  -->
@@ -47,18 +84,35 @@
47
84
  </dependencies>
48
85
 
49
86
  <build>
50
- <outputDirectory>pkg/classes</outputDirectory>
87
+
51
88
  <sourceDirectory>src/java</sourceDirectory>
89
+ <resources>
90
+ <resource>
91
+ <directory>lib</directory>
92
+ </resource>
93
+ </resources>
94
+ <!--
95
+ <testSourceDirectory>test/java</testSourceDirectory>-->
96
+ <testResources>
97
+ <testResource>
98
+ <directory>test</directory>
99
+ </testResource>
100
+ </testResources>
101
+
102
+ <outputDirectory>pkg/classes</outputDirectory>
103
+
52
104
  <plugins>
53
105
  <plugin>
54
106
  <groupId>org.apache.maven.plugins</groupId>
55
107
  <artifactId>maven-compiler-plugin</artifactId>
108
+ <version>2.5.1</version>
56
109
  <configuration>
57
110
  <source>1.6</source>
58
111
  <target>1.6</target>
59
112
  </configuration>
60
113
  </plugin>
61
114
  </plugins>
115
+
62
116
  </build>
63
117
 
64
118
  </project>
data/rakelib/02-test.rake CHANGED
@@ -14,118 +14,107 @@ else
14
14
  task :test => [ :test_mysql ]
15
15
  end
16
16
 
17
- def set_compat_version(task)
17
+ def set_test_task_compat_version(task)
18
18
  task.ruby_opts << '-v' if RUBY_VERSION =~ /1\.8/
19
19
  if defined?(JRUBY_VERSION)
20
20
  task.ruby_opts << "--#{RUBY_VERSION[/^(\d+\.\d+)/, 1]}"
21
21
  end
22
22
  end
23
23
 
24
- %w(derby h2 hsqldb mysql sqlite3 postgres mssql oracle db2 as400 informix sybase).each do
25
- |adapter| task "test_#{adapter}_pre" do
26
- unless (ENV['BUNDLE_GEMFILE'] rescue '') =~ /gemfiles\/.*?\.gemfile/
27
- appraisals = []; Appraisal::File.each { |file| appraisals << file.name }
28
- puts "Specify AR version with `rake appraisal:{version} test_#{adapter}'" +
29
- " where version=(#{appraisals.join('|')})"
30
- end
31
- end
24
+ def set_task_description(task, desc)
25
+ unless task.is_a?(Rake::Task)
26
+ task = task.name if task.is_a?(Rake::TestTask)
27
+ task = Rake::Task[task]
28
+ end
29
+ # reset the desc set-up by TestTask :
30
+ task.instance_variable_set(:@full_comment, nil)
31
+ task.add_description(desc)
32
+ end
33
+
34
+ task 'test_appraisal_hint' do
35
+ next if File.exists?('.disable-appraisal-hint')
36
+ unless (ENV['BUNDLE_GEMFILE'] rescue '') =~ /gemfiles\/.*?\.gemfile/
37
+ appraisals = []; Appraisal::File.each { |file| appraisals << file.name }
38
+ puts "HINT: specify AR version with `rake appraisal:{version} test_{adapter}'" +
39
+ " where version=(#{appraisals.join('|')}) (`touch .disable-appraisal-hint' to disable)"
40
+ end
32
41
  end
33
42
 
34
43
  Rake::TestTask.class_eval { attr_reader :test_files }
35
44
 
36
- def declare_test_task_for(adapter, options = {}, &block)
37
- driver = options[:driver] || adapter
45
+ def test_task_for(adapter, options = {})
46
+ desc = options[:desc] || options[:comment] ||
47
+ "Run tests against #{options[:database_name] || adapter}"
48
+ adapter = adapter.to_s.downcase
49
+ driver = options.key?(:driver) ? options[:driver] : adapter
38
50
  prereqs = options[:prereqs] || []
39
- prereqs = [ prereqs ].flatten
40
- prereqs << "test_#{adapter}_pre"
41
- Rake::TestTask.new("test_#{adapter}" => prereqs) do |task|
42
- files = FileList["test/#{adapter}*_test.rb"]
43
- files += FileList["test/db/#{adapter}/*_test.rb"]
44
- #task_name = task.name.keys.first.to_s
45
- #files.unshift "test/db/#{task_name.sub('test_','')}.rb"
46
- task.test_files = files
47
- task.libs = []
51
+ unless prereqs.frozen?
52
+ prereqs = [ prereqs ].flatten; prereqs << 'test_appraisal_hint'
53
+ end
54
+ name = options[:name] || "test_#{adapter}"
55
+ test_task = Rake::TestTask.new(name => prereqs) do |test_task|
56
+ files = options[:files] || begin
57
+ FileList["test/#{adapter}*_test.rb"] +
58
+ FileList["test/db/#{adapter}/*_test.rb"]
59
+ end
60
+ test_task.test_files = files
61
+ test_task.libs = []
48
62
  if defined?(JRUBY_VERSION)
49
- task.libs << "lib" << "jdbc-#{driver}/lib"
50
- task.libs.push *FileList["activerecord-jdbc#{adapter}*/lib"]
63
+ test_task.libs << 'lib'
64
+ test_task.libs << "jdbc-#{driver}/lib" if driver && File.exists?("jdbc-#{driver}/lib")
65
+ test_task.libs.push *FileList["activerecord-jdbc#{adapter}*/lib"]
51
66
  end
52
- task.libs << "test"
53
- set_compat_version(task)
54
- task.verbose = true if $VERBOSE
55
- yield(task) if block_given?
67
+ test_task.libs << 'test'
68
+ set_test_task_compat_version test_task
69
+ test_task.verbose = true if $VERBOSE
70
+ yield(test_task) if block_given?
56
71
  end
72
+ set_task_description name, desc
73
+ test_task
57
74
  end
58
75
 
59
- declare_test_task_for :derby
60
- declare_test_task_for :h2
61
- declare_test_task_for :hsqldb
62
- declare_test_task_for :mssql, :driver => :jtds
63
- declare_test_task_for :mysql, :prereqs => "db:mysql"
64
- declare_test_task_for :postgres, :prereqs => "db:postgres"
65
- task :test_postgresql => :test_postgres # alias
66
- task :test_pgsql => :test_postgres # alias
67
- declare_test_task_for :sqlite3
76
+ test_task_for :Derby, :desc => 'Run tests against (embedded) DerbyDB'
77
+ test_task_for :H2, :desc => 'Run tests against H2 database engine'
78
+ test_task_for :HSQLDB, :desc => 'Run tests against HyperSQL (Java) database'
79
+ test_task_for :MSSQL, :driver => :jtds, :database_name => 'MS-SQL (SQLServer)'
80
+ test_task_for :MySQL, :prereqs => 'db:mysql'
81
+ test_task_for :PostgreSQL, :prereqs => 'db:postgresql', :driver => 'postgres'
82
+ task :test_postgres => :test_postgresql # alias
83
+ task :test_pgsql => :test_postgresql # alias
84
+ test_task_for :SQLite3
85
+ test_task_for :FireBird
68
86
 
69
87
  # ensure driver for these DBs is on your class-path
70
- [ :oracle, :db2, :informix, :cachedb ].each do |adapter|
71
- Rake::TestTask.new("test_#{adapter}") do |task|
72
- test_files = FileList["test/#{adapter}*_test.rb"]
73
- test_files += FileList["test/db/#{adapter}/*_test.rb"]
74
- task.test_files = test_files
75
- task.libs = []
76
- task.libs << 'lib' if defined?(JRUBY_VERSION)
77
- task.libs << 'test'
78
- set_compat_version(task)
79
- end
88
+ [ :Oracle, :DB2, :Informix, :CacheDB ].each do |adapter|
89
+ test_task_for adapter, :desc => "Run tests against #{adapter} (ensure driver is on class-path)"
80
90
  end
81
91
 
82
- Rake::TestTask.new(:test_as400) do |task|
83
- test_files = FileList["test/db2*_test.rb"]
84
- test_files += FileList["test/db/db2/*_test.rb"]
85
- task.test_files = test_files
86
- task.libs = []
87
- task.libs << 'lib' if defined?(JRUBY_VERSION)
88
- task.libs << 'test'
89
- set_compat_version(task)
90
- end
92
+ #test_task_for :MSSQL, :name => 'test_sqlserver', :driver => nil, :database_name => 'MS-SQL using SQLJDBC'
91
93
 
92
- Rake::TestTask.new(:test_jdbc) do |task|
93
- task.test_files = FileList['test/*jdbc_*test.rb']
94
- task.libs << 'test' << 'jdbc-mysql/lib' << 'jdbc-derby/lib'
95
- set_compat_version(task)
96
- end
94
+ test_task_for :AS400, :desc => "Run tests against AS400 (DB2) (ensure driver is on class-path)",
95
+ :files => FileList["test/db2*_test.rb"] + FileList["test/db/db2/*_test.rb"]
97
96
 
98
- Rake::TestTask.new(:test_jndi => 'tomcat-jndi:check') do |task|
99
- task.test_files = FileList['test/*jndi_*test.rb']
100
- task.libs << 'test' << 'jdbc-derby/lib'
101
- set_compat_version(task)
97
+ test_task_for 'JDBC', :desc => 'Run tests against plain JDBC adapter (uses MySQL and Derby)',
98
+ :files => FileList['test/*jdbc_*test.rb'] do |test_task|
99
+ test_task.libs << 'jdbc-mysql/lib' << 'jdbc-derby/lib'
102
100
  end
103
101
 
104
- # tests for JDBC adapters that don't require a database :
105
- Rake::TestTask.new(:test_jdbc_adapters) do |task|
106
- task.test_files = FileList[ 'test/jdbc_adapter/jdbc_sybase_test.rb' ]
107
- task.libs << 'test'
108
- set_compat_version(task)
102
+ test_task_for 'JNDI', :desc => 'Run tests against a JNDI connection (uses Derby)',
103
+ :prereqs => 'tomcat-jndi:check',
104
+ :files => FileList['test/*jndi_*test.rb'] do |test_task|
105
+ test_task.libs << 'jdbc-derby/lib'
109
106
  end
110
107
 
111
- # ensure that the jTDS driver is in your class-path
112
- Rake::TestTask.new(:test_sybase_jtds) do |task|
113
- task.test_files = FileList['test/sybase_jtds_simple_test.rb']
114
- task.libs << 'test'
115
- set_compat_version(task)
116
- end
117
-
118
- # ensure that the jConnect driver is in your class-path
119
- Rake::TestTask.new(:test_sybase_jconnect) do |task|
120
- task.test_files = FileList['test/sybase_jconnect_simple_test.rb']
121
- task.libs << 'test'
122
- set_compat_version(task)
123
- end
108
+ # TODO Sybase testing is currently broken, please fix it if you're on Sybase :
109
+ #test_task_for :Sybase, :desc => "Run tests against Sybase (using jTDS driver)"
110
+ #task :test_sybase_jtds => :test_sybase # alias
111
+ #test_task_for :Sybase, :name => 'sybase_jconnect',
112
+ # :desc => "Run tests against Sybase (ensure jConnect driver is on class-path)"
124
113
 
125
114
  Rake::TraceOutput.module_eval do
126
115
 
127
116
  # NOTE: avoid TypeError: String can't be coerced into Fixnum
128
- # due this method gettings a strings == [ 1 ] argument ...
117
+ # due this method getting some strings == [ 1 ] argument ...
129
118
  def trace_on(out, *strings)
130
119
  sep = $\ || "\n"
131
120
  if strings.empty?
@@ -138,5 +127,5 @@ Rake::TraceOutput.module_eval do
138
127
  end
139
128
  out.print(output)
140
129
  end
141
-
130
+
142
131
  end