activerecord-jdbc-adapter 0.9.2 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (175) hide show
  1. data/History.txt +163 -0
  2. data/Manifest.txt +130 -65
  3. data/README.txt +64 -72
  4. data/lib/active_record/connection_adapters/derby_adapter.rb +1 -13
  5. data/lib/active_record/connection_adapters/h2_adapter.rb +1 -13
  6. data/lib/active_record/connection_adapters/hsqldb_adapter.rb +1 -13
  7. data/lib/active_record/connection_adapters/informix_adapter.rb +1 -1
  8. data/lib/active_record/connection_adapters/jdbc_adapter.rb +1 -633
  9. data/lib/active_record/connection_adapters/jndi_adapter.rb +1 -1
  10. data/lib/active_record/connection_adapters/mssql_adapter.rb +1 -0
  11. data/lib/active_record/connection_adapters/mysql2_adapter.rb +1 -0
  12. data/lib/active_record/connection_adapters/mysql_adapter.rb +1 -13
  13. data/lib/active_record/connection_adapters/oracle_adapter.rb +1 -1
  14. data/lib/active_record/connection_adapters/postgresql_adapter.rb +1 -13
  15. data/lib/active_record/connection_adapters/sqlite3_adapter.rb +1 -13
  16. data/lib/activerecord-jdbc-adapter.rb +6 -0
  17. data/lib/arel/engines/sql/compilers/db2_compiler.rb +9 -0
  18. data/lib/arel/engines/sql/compilers/derby_compiler.rb +6 -0
  19. data/lib/arel/engines/sql/compilers/h2_compiler.rb +6 -0
  20. data/lib/arel/engines/sql/compilers/hsqldb_compiler.rb +15 -0
  21. data/lib/arel/engines/sql/compilers/jdbc_compiler.rb +6 -0
  22. data/lib/arel/engines/sql/compilers/mssql_compiler.rb +46 -0
  23. data/lib/arel/visitors/db2.rb +15 -0
  24. data/lib/arel/visitors/derby.rb +19 -0
  25. data/lib/arel/visitors/hsqldb.rb +24 -0
  26. data/lib/arel/visitors/mssql.rb +44 -0
  27. data/lib/arjdbc.rb +29 -0
  28. data/lib/arjdbc/db2.rb +2 -0
  29. data/lib/arjdbc/db2/adapter.rb +413 -0
  30. data/lib/arjdbc/derby.rb +7 -0
  31. data/lib/{jdbc_adapter/jdbc_derby.rb → arjdbc/derby/adapter.rb} +58 -132
  32. data/lib/arjdbc/derby/connection_methods.rb +18 -0
  33. data/lib/arjdbc/discover.rb +92 -0
  34. data/lib/arjdbc/firebird.rb +2 -0
  35. data/lib/{jdbc_adapter/jdbc_firebird.rb → arjdbc/firebird/adapter.rb} +36 -14
  36. data/lib/arjdbc/h2.rb +4 -0
  37. data/lib/arjdbc/h2/adapter.rb +36 -0
  38. data/lib/arjdbc/h2/connection_methods.rb +12 -0
  39. data/lib/arjdbc/hsqldb.rb +4 -0
  40. data/lib/{jdbc_adapter/jdbc_hsqldb.rb → arjdbc/hsqldb/adapter.rb} +34 -62
  41. data/lib/arjdbc/hsqldb/connection_methods.rb +14 -0
  42. data/lib/arjdbc/informix.rb +3 -0
  43. data/lib/{jdbc_adapter/jdbc_informix.rb → arjdbc/informix/adapter.rb} +10 -19
  44. data/lib/arjdbc/informix/connection_methods.rb +10 -0
  45. data/lib/arjdbc/jdbc.rb +2 -0
  46. data/lib/arjdbc/jdbc/adapter.rb +285 -0
  47. data/lib/arjdbc/jdbc/adapter_java.jar +0 -0
  48. data/lib/arjdbc/jdbc/callbacks.rb +44 -0
  49. data/lib/arjdbc/jdbc/column.rb +38 -0
  50. data/lib/arjdbc/jdbc/compatibility.rb +51 -0
  51. data/lib/arjdbc/jdbc/connection.rb +128 -0
  52. data/lib/arjdbc/jdbc/connection_methods.rb +16 -0
  53. data/lib/arjdbc/jdbc/core_ext.rb +24 -0
  54. data/lib/arjdbc/jdbc/discover.rb +18 -0
  55. data/lib/arjdbc/jdbc/driver.rb +44 -0
  56. data/lib/arjdbc/jdbc/extension.rb +47 -0
  57. data/lib/arjdbc/jdbc/java.rb +14 -0
  58. data/lib/{jdbc_adapter → arjdbc/jdbc}/jdbc.rake +36 -26
  59. data/lib/{jdbc_adapter → arjdbc/jdbc}/missing_functionality_helper.rb +5 -5
  60. data/lib/arjdbc/jdbc/quoted_primary_key.rb +28 -0
  61. data/lib/arjdbc/jdbc/railtie.rb +9 -0
  62. data/lib/arjdbc/jdbc/rake_tasks.rb +10 -0
  63. data/lib/arjdbc/jdbc/require_driver.rb +16 -0
  64. data/lib/arjdbc/jdbc/type_converter.rb +126 -0
  65. data/lib/arjdbc/mimer.rb +2 -0
  66. data/lib/{jdbc_adapter/jdbc_mimer.rb → arjdbc/mimer/adapter.rb} +17 -16
  67. data/lib/arjdbc/mssql.rb +4 -0
  68. data/lib/arjdbc/mssql/adapter.rb +472 -0
  69. data/lib/arjdbc/mssql/connection_methods.rb +30 -0
  70. data/lib/arjdbc/mssql/limit_helpers.rb +92 -0
  71. data/lib/{jdbc_adapter → arjdbc/mssql}/tsql_helper.rb +2 -1
  72. data/lib/arjdbc/mysql.rb +4 -0
  73. data/lib/arjdbc/mysql/adapter.rb +416 -0
  74. data/lib/arjdbc/mysql/connection_methods.rb +27 -0
  75. data/lib/arjdbc/oracle.rb +3 -0
  76. data/lib/{jdbc_adapter/jdbc_oracle.rb → arjdbc/oracle/adapter.rb} +68 -33
  77. data/lib/arjdbc/oracle/connection_methods.rb +11 -0
  78. data/lib/arjdbc/postgresql.rb +4 -0
  79. data/lib/{jdbc_adapter/jdbc_postgre.rb → arjdbc/postgresql/adapter.rb} +147 -72
  80. data/lib/arjdbc/postgresql/connection_methods.rb +21 -0
  81. data/lib/arjdbc/sqlite3.rb +4 -0
  82. data/lib/arjdbc/sqlite3/adapter.rb +381 -0
  83. data/lib/arjdbc/sqlite3/connection_methods.rb +34 -0
  84. data/lib/arjdbc/sybase.rb +2 -0
  85. data/lib/arjdbc/sybase/adapter.rb +46 -0
  86. data/lib/arjdbc/version.rb +8 -0
  87. data/lib/generators/jdbc/jdbc_generator.rb +9 -0
  88. data/lib/jdbc_adapter.rb +2 -27
  89. data/lib/jdbc_adapter/rake_tasks.rb +3 -10
  90. data/lib/jdbc_adapter/version.rb +3 -5
  91. data/lib/pg.rb +23 -1
  92. data/rails_generators/jdbc_generator.rb +2 -2
  93. data/rails_generators/templates/{jdbc.rb → config/initializers/jdbc.rb} +1 -1
  94. data/rails_generators/templates/{jdbc.rake → lib/tasks/jdbc.rake} +2 -2
  95. data/rakelib/compile.rake +5 -3
  96. data/rakelib/db.rake +19 -0
  97. data/rakelib/package.rake +12 -6
  98. data/rakelib/test.rake +24 -14
  99. data/src/java/{jdbc_adapter/JdbcDerbySpec.java → arjdbc/derby/DerbyModule.java} +63 -34
  100. data/src/java/arjdbc/h2/H2RubyJdbcConnection.java +70 -0
  101. data/src/java/{jdbc_adapter/MssqlRubyJdbcConnection.java → arjdbc/informix/InformixRubyJdbcConnection.java} +15 -12
  102. data/src/java/{jdbc_adapter/JdbcAdapterInternalService.java → arjdbc/jdbc/AdapterJavaService.java} +21 -8
  103. data/src/java/{jdbc_adapter → arjdbc/jdbc}/JdbcConnectionFactory.java +6 -6
  104. data/src/java/{jdbc_adapter → arjdbc/jdbc}/RubyJdbcConnection.java +210 -67
  105. data/src/java/arjdbc/jdbc/SQLBlock.java +48 -0
  106. data/src/java/arjdbc/mssql/MssqlRubyJdbcConnection.java +127 -0
  107. data/src/java/{jdbc_adapter/JdbcMySQLSpec.java → arjdbc/mysql/MySQLModule.java} +12 -12
  108. data/src/java/arjdbc/mysql/MySQLRubyJdbcConnection.java +87 -0
  109. data/src/java/arjdbc/oracle/OracleRubyJdbcConnection.java +85 -0
  110. data/src/java/{jdbc_adapter/PostgresRubyJdbcConnection.java → arjdbc/postgresql/PostgresqlRubyJdbcConnection.java} +11 -9
  111. data/src/java/arjdbc/sqlite3/Sqlite3RubyJdbcConnection.java +64 -0
  112. data/test/abstract_db_create.rb +98 -19
  113. data/test/activerecord/connection_adapters/type_conversion_test.rb +1 -1
  114. data/test/db/db2.rb +4 -2
  115. data/test/db/derby.rb +12 -14
  116. data/test/db/hsqldb.rb +3 -2
  117. data/test/db/jndi_config.rb +22 -12
  118. data/test/db/mssql.rb +5 -5
  119. data/test/db/sqlite3.rb +2 -6
  120. data/test/db2_simple_test.rb +56 -0
  121. data/test/derby_migration_test.rb +50 -3
  122. data/test/derby_simple_test.rb +87 -0
  123. data/test/generic_jdbc_connection_test.rb +21 -1
  124. data/test/h2_simple_test.rb +35 -0
  125. data/test/jdbc_common.rb +4 -5
  126. data/test/jndi_callbacks_test.rb +3 -1
  127. data/test/jndi_test.rb +1 -11
  128. data/test/models/entry.rb +20 -0
  129. data/test/models/mixed_case.rb +7 -2
  130. data/test/models/string_id.rb +18 -0
  131. data/test/mssql_db_create_test.rb +26 -0
  132. data/test/mssql_identity_insert_test.rb +19 -0
  133. data/test/mssql_legacy_types_test.rb +58 -0
  134. data/test/mssql_limit_offset_test.rb +136 -0
  135. data/test/mssql_multibyte_test.rb +18 -0
  136. data/test/mssql_simple_test.rb +49 -0
  137. data/test/mysql_db_create_test.rb +8 -6
  138. data/test/mysql_info_test.rb +123 -0
  139. data/test/mysql_simple_test.rb +19 -1
  140. data/test/oracle_simple_test.rb +9 -20
  141. data/test/oracle_specific_test.rb +83 -0
  142. data/test/pick_rails_version.rb +3 -0
  143. data/test/postgres_db_create_test.rb +11 -0
  144. data/test/postgres_drop_db_test.rb +16 -0
  145. data/test/postgres_mixed_case_test.rb +11 -1
  146. data/test/postgres_nonseq_pkey_test.rb +0 -2
  147. data/test/postgres_schema_search_path_test.rb +44 -0
  148. data/test/postgres_simple_test.rb +53 -0
  149. data/test/postgres_table_alias_length_test.rb +15 -0
  150. data/test/simple.rb +103 -9
  151. data/test/sqlite3_simple_test.rb +1 -0
  152. data/test/sybase_jtds_simple_test.rb +22 -0
  153. metadata +239 -137
  154. data/lib/active_record/connection_adapters/cachedb_adapter.rb +0 -1
  155. data/lib/active_record/connection_adapters/jdbc_adapter_spec.rb +0 -26
  156. data/lib/jdbc_adapter/jdbc_adapter_internal.jar +0 -0
  157. data/lib/jdbc_adapter/jdbc_cachedb.rb +0 -33
  158. data/lib/jdbc_adapter/jdbc_db2.rb +0 -191
  159. data/lib/jdbc_adapter/jdbc_mssql.rb +0 -333
  160. data/lib/jdbc_adapter/jdbc_mysql.rb +0 -236
  161. data/lib/jdbc_adapter/jdbc_sqlite3.rb +0 -379
  162. data/lib/jdbc_adapter/jdbc_sybase.rb +0 -50
  163. data/src/java/jdbc_adapter/SQLBlock.java +0 -27
  164. data/src/java/jdbc_adapter/Sqlite3RubyJdbcConnection.java +0 -41
  165. data/test/cachedb_simple_test.rb +0 -6
  166. data/test/db/cachedb.rb +0 -9
  167. data/test/jdbc_adapter/jdbc_db2_test.rb +0 -26
  168. data/test/jdbc_adapter/jdbc_sybase_test.rb +0 -33
  169. data/test/minirunit.rb +0 -109
  170. data/test/minirunit/testConnect.rb +0 -14
  171. data/test/minirunit/testH2.rb +0 -73
  172. data/test/minirunit/testHsqldb.rb +0 -73
  173. data/test/minirunit/testLoadActiveRecord.rb +0 -3
  174. data/test/minirunit/testMysql.rb +0 -83
  175. data/test/minirunit/testRawSelect.rb +0 -24
@@ -0,0 +1,64 @@
1
+ /*
2
+ **** BEGIN LICENSE BLOCK *****
3
+ * Copyright (c) 2006-2010 Nick Sieger <nick@nicksieger.com>
4
+ * Copyright (c) 2006-2007 Ola Bini <ola.bini@gmail.com>
5
+ * Copyright (c) 2008-2009 Thomas E Enebo <enebo@acm.org>
6
+ *
7
+ * Permission is hereby granted, free of charge, to any person obtaining
8
+ * a copy of this software and associated documentation files (the
9
+ * "Software"), to deal in the Software without restriction, including
10
+ * without limitation the rights to use, copy, modify, merge, publish,
11
+ * distribute, sublicense, and/or sell copies of the Software, and to
12
+ * permit persons to whom the Software is furnished to do so, subject to
13
+ * the following conditions:
14
+ *
15
+ * The above copyright notice and this permission notice shall be
16
+ * included in all copies or substantial portions of the Software.
17
+ *
18
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
22
+ * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
23
+ * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
24
+ * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25
+ ***** END LICENSE BLOCK *****/
26
+
27
+ package arjdbc.sqlite3;
28
+
29
+ import arjdbc.jdbc.RubyJdbcConnection;
30
+
31
+ import org.jruby.Ruby;
32
+ import org.jruby.RubyClass;
33
+ import org.jruby.runtime.ObjectAllocator;
34
+ import org.jruby.runtime.ThreadContext;
35
+ import org.jruby.runtime.builtin.IRubyObject;
36
+
37
+ /**
38
+ *
39
+ * @author enebo
40
+ */
41
+ public class Sqlite3RubyJdbcConnection extends RubyJdbcConnection {
42
+ protected Sqlite3RubyJdbcConnection(Ruby runtime, RubyClass metaClass) {
43
+ super(runtime, metaClass);
44
+ }
45
+
46
+ public static RubyClass createSqlite3JdbcConnectionClass(Ruby runtime, RubyClass jdbcConnection) {
47
+ RubyClass clazz = RubyJdbcConnection.getConnectionAdapters(runtime).defineClassUnder("Sqlite3JdbcConnection",
48
+ jdbcConnection, SQLITE3_JDBCCONNECTION_ALLOCATOR);
49
+ clazz.defineAnnotatedMethods(Sqlite3RubyJdbcConnection.class);
50
+
51
+ return clazz;
52
+ }
53
+
54
+ private static ObjectAllocator SQLITE3_JDBCCONNECTION_ALLOCATOR = new ObjectAllocator() {
55
+ public IRubyObject allocate(Ruby runtime, RubyClass klass) {
56
+ return new Sqlite3RubyJdbcConnection(runtime, klass);
57
+ }
58
+ };
59
+
60
+ @Override
61
+ protected IRubyObject tables(ThreadContext context, String catalog, String schemaPattern, String tablePattern, String[] types) {
62
+ return (IRubyObject) withConnectionAndRetry(context, tableLookupBlock(context.getRuntime(), catalog, schemaPattern, tablePattern, types, true));
63
+ }
64
+ }
@@ -1,45 +1,124 @@
1
1
  require 'jdbc_common'
2
2
  require 'rake'
3
3
 
4
+ module Rails
5
+ class Configuration
6
+ end
7
+ class Application
8
+ def self.config
9
+ @config ||= Object.new
10
+ end
11
+ end
12
+ def self.application
13
+ Rails::Application
14
+ end
15
+ end
16
+
4
17
  module AbstractDbCreate
5
18
  def setup
6
19
  @prevapp = Rake.application
7
20
  Rake.application = Rake::Application.new
8
21
  verbose(true)
9
- @prevenv = Object.const_get("RAILS_ENV") rescue nil
10
- @prevroot = Object.const_get("RAILS_ENV") rescue nil
11
- Object.const_set("RAILS_ENV", "unittest")
12
- Object.const_set("RAILS_ROOT", ".")
22
+ do_setup
23
+ end
24
+
25
+ def do_setup(env = 'unittest', db = 'test_rake_db_create')
26
+ @env = env
13
27
  @prevconfigs = ActiveRecord::Base.configurations
14
28
  ActiveRecord::Base.connection.disconnect!
15
- @db_name = 'test_rake_db_create'
16
- require 'initializer'
17
- the_db_name = @db_name
18
- the_db_config = db_config
19
- Rails::Configuration.class_eval do
20
- define_method(:database_configuration) do
21
- { "unittest" => the_db_config.merge({:database => the_db_name}).stringify_keys! }
22
- end
29
+ @db_name = db
30
+ setup_rails
31
+ set_rails_constant("env", @env)
32
+ set_rails_constant("root", ".")
33
+ load File.dirname(__FILE__) + '/../lib/arjdbc/jdbc/jdbc.rake' if jruby?
34
+ task :environment do
35
+ ActiveRecord::Base.configurations = configurations
36
+ @full_env_loaded = true
37
+ end
38
+ task :rails_env do
39
+ @rails_env_set = true
23
40
  end
24
- load rails_databases_rake_file
25
- load File.dirname(__FILE__) + '/../lib/jdbc_adapter/jdbc.rake' if jruby?
26
- task :environment; task :rails_env # dummy environment, rails_env tasks
27
41
  end
28
42
 
29
43
  def teardown
30
44
  Rake::Task["db:drop"].invoke
31
45
  Rake.application = @prevapp
32
- Object.const_set("RAILS_ENV", @prevenv) if @prevenv
33
- Object.const_set("RAILS_ROOT", @prevroot) if @prevroot
46
+ restore_rails
34
47
  ActiveRecord::Base.configurations = @prevconfigs
35
48
  ActiveRecord::Base.establish_connection(db_config)
49
+ @rails_env_set = nil
50
+ @full_env_loaded = nil
36
51
  end
37
52
 
38
- def rails_databases_rake_file
53
+ def setup_rails
54
+ if ActiveRecord::VERSION::MAJOR == 3
55
+ setup_rails3
56
+ else
57
+ setup_rails2
58
+ end
59
+ end
60
+
61
+ def configurations
62
+ the_db_name = @db_name
63
+ the_db_config = db_config
64
+ the_db_config = the_db_config.merge({:database => the_db_name}) if the_db_name
65
+ the_db_config.stringify_keys!
66
+ @configs = { @env => the_db_config }
67
+ @configs["test"] = @configs[@env].dup
68
+ @configs
69
+ end
70
+
71
+ def setup_rails2
72
+ configs = configurations
73
+ Rails::Configuration.class_eval do
74
+ define_method(:database_configuration) { configs }
75
+ end
39
76
  ar_version = $LOADED_FEATURES.grep(%r{active_record/version}).first
40
77
  ar_lib_path = $LOAD_PATH.detect {|p| p if File.exist?File.join(p, ar_version)}
41
78
  ar_lib_path = ar_lib_path.sub(%r{activerecord/lib}, 'railties/lib') # edge rails
42
79
  rails_lib_path = ar_lib_path.sub(/activerecord/, 'rails') # gem rails
43
- "#{rails_lib_path}/tasks/databases.rake"
80
+ load "#{rails_lib_path}/tasks/databases.rake"
81
+ end
82
+
83
+ def setup_rails3
84
+ configs = configurations
85
+ (class << Rails::Application.config; self ; end).instance_eval do
86
+ define_method(:database_configuration) { configs }
87
+ end
88
+ ar_version = $LOADED_FEATURES.grep(%r{active_record/version}).first
89
+ ar_lib_path = $LOAD_PATH.detect {|p| p if File.exist?File.join(p, ar_version)}
90
+ load "#{ar_lib_path}/active_record/railties/databases.rake"
91
+ end
92
+
93
+ def set_rails_constant(name, value)
94
+ cname ="RAILS_#{name.upcase}"
95
+ @constants ||= {}
96
+ @constants[name] = Object.const_get(cname) rescue nil
97
+ silence_warnings { Object.const_set(cname, value) }
98
+ Rails.instance_eval do
99
+ if instance_methods(false).include?(name)
100
+ alias_method "orig_#{name}", name
101
+ define_method(name) { value }
102
+ end
103
+ end
104
+ end
105
+
106
+ def restore_rails
107
+ @constants.each do |key,value|
108
+ silence_warnings { Object.const_set("RAILS_#{key.upcase}", value) }
109
+ Rails.instance_eval do
110
+ if instance_methods(false).include?(name)
111
+ remove_method name
112
+ alias_method name, "orig_#{name}"
113
+ end
114
+ end
115
+ end
116
+ end
117
+
118
+ def silence_warnings
119
+ prev, $VERBOSE = $VERBOSE, nil
120
+ yield
121
+ ensure
122
+ $VERBOSE = prev
44
123
  end
45
124
  end
@@ -1,6 +1,6 @@
1
1
  require 'java'
2
2
  require 'models/data_types'
3
- require 'active_record/connection_adapters/jdbc_adapter'
3
+ require 'arjdbc'
4
4
  require 'db/derby'
5
5
  require 'test/unit'
6
6
 
@@ -1,6 +1,8 @@
1
1
  config = {
2
- :username => "blog",
3
- :password => "",
2
+ # DB2 uses $USER if running locally, just add
3
+ # yourself to your db2 groups in /etc/group
4
+ # :username => "blog",
5
+ # :password => "",
4
6
  :adapter => "jdbc",
5
7
  :driver => "com.ibm.db2.jcc.DB2Driver",
6
8
  :url => "jdbc:db2:weblog_development"
@@ -1,14 +1,12 @@
1
- require 'logger'
2
-
3
- config = {
4
- :adapter => 'derby',
5
- :database => "derby-testdb"
6
- }
7
-
8
- ActiveRecord::Base.establish_connection(config)
9
-
10
- at_exit {
11
- # Clean up derby files
12
- require 'fileutils'
13
- FileUtils.rm_rf('derby-testdb')
14
- }
1
+ config = {
2
+ :adapter => 'derby',
3
+ :database => "derby-testdb"
4
+ }
5
+
6
+ ActiveRecord::Base.establish_connection(config)
7
+
8
+ at_exit {
9
+ # Clean up derby files
10
+ require 'fileutils'
11
+ FileUtils.rm_rf('derby-testdb')
12
+ }
@@ -7,6 +7,7 @@ ActiveRecord::Base.establish_connection(config)
7
7
 
8
8
  at_exit {
9
9
  # Clean up hsqldb when done
10
- Dir['test.db*'].each {|f| File.delete(f)}
11
- File.delete('hsqldb-testdb.log') rescue nil #can't delete on windows
10
+ require "fileutils"
11
+ Dir['test.db*'].each {|f| FileUtils.rm_rf(f)}
12
+ FileUtils.rm_rf('hsqldb-testdb.log') rescue nil #can't delete on windows
12
13
  }
@@ -1,12 +1,24 @@
1
1
  require 'fileutils'
2
- require 'active_record/connection_adapters/jdbc_adapter'
2
+ require 'arjdbc'
3
+
4
+ JNDI_CONFIG = {
5
+ :adapter => "jdbc",
6
+ :jndi => 'jdbc/derbydb'
7
+ }
8
+
9
+ # To test JNDI, grab fscontext-1_2-beta3.zip from
10
+ # http://java.sun.com/products/jndi/downloads/index.html
11
+ # and put fscontext.jar and providerutil.jar in test/
12
+ require 'test/fscontext.jar'
13
+ require 'test/providerutil.jar'
14
+ require 'jdbc/derby'
3
15
 
4
16
  System = java.lang.System
5
17
  Context = javax.naming.Context
6
18
  InitialContext = javax.naming.InitialContext
7
19
  Reference = javax.naming.Reference
8
20
  StringRefAddr = javax.naming.StringRefAddr
9
-
21
+
10
22
  System.set_property(Context::INITIAL_CONTEXT_FACTORY,
11
23
  'com.sun.jndi.fscontext.RefFSContextFactory')
12
24
  project_path = File.expand_path(File.dirname(__FILE__) + '/../..')
@@ -15,16 +27,14 @@ jdbc_dir = jndi_dir + '/jdbc'
15
27
  FileUtils.mkdir_p jdbc_dir unless File.exist?(jdbc_dir)
16
28
 
17
29
  System.set_property(Context::PROVIDER_URL, "file://#{jndi_dir}")
18
- derby_ref = Reference.new('javax.sql.DataSource',
19
- 'org.apache.commons.dbcp.BasicDataSourceFactory',
20
- nil)
21
- derby_ref.add StringRefAddr.new('driverClassName',
22
- 'org.apache.derby.jdbc.EmbeddedDriver')
23
- derby_ref.add StringRefAddr.new('url',
24
- 'jdbc:derby:derby-testdb;create=true')
25
- derby_ref.add StringRefAddr.new('username', 'sa')
26
- derby_ref.add StringRefAddr.new('password', '')
27
30
 
28
31
  ic = InitialContext.new
29
- ic.rebind("jdbc/derbydb", derby_ref)
32
+ ic.rebind(JNDI_CONFIG[:jndi],
33
+ org.apache.derby.jdbc.EmbeddedDataSource.new.tap {|ds|
34
+ ds.database_name = "derby-testdb-jndi"
35
+ ds.create_database = "create"
36
+ ds.user = "sa"
37
+ ds.password = ""})
38
+
30
39
 
40
+ ActiveRecord::Base.establish_connection(JNDI_CONFIG)
@@ -1,9 +1,9 @@
1
- config = {
1
+ MSSQL_CONFIG = {
2
2
  :username => 'blog',
3
3
  :password => '',
4
- :adapter => 'jdbc',
5
- :url => "jdbc:jtds:sqlserver://localhost:1433/weblog_development",
6
- :driver => 'net.sourceforge.jtds.jdbc.Driver'
4
+ :adapter => 'mssql',
5
+ :database => 'weblog_development'
7
6
  }
7
+ MSSQL_CONFIG[:host] = ENV['SQLHOST'] if ENV['SQLHOST']
8
8
 
9
- ActiveRecord::Base.establish_connection( config )
9
+ ActiveRecord::Base.establish_connection(MSSQL_CONFIG)
@@ -1,10 +1,6 @@
1
- require 'jdbc/sqlite3' if jruby?
2
-
3
1
  config = {
4
- :adapter => jruby? ? 'jdbcsqlite3' : 'sqlite3',
5
- :dbfile => 'test.sqlite3.db'
6
- # :url => 'jdbc:sqlite:test.sqlite3.db',
7
- # :driver => 'org.sqlite.JDBC'
2
+ :adapter => 'sqlite3',
3
+ :database => 'test.sqlite3.db'
8
4
  }
9
5
 
10
6
  ActiveRecord::Base.establish_connection(config)
@@ -3,8 +3,64 @@ require 'db/db2'
3
3
 
4
4
  class DB2SimpleTest < Test::Unit::TestCase
5
5
  include SimpleTestMethods
6
+
7
+ # For backwards compatibility with how the DB2 code in
8
+ # jdbc_adapter 0.9.x handled booleans.
9
+ #
10
+ # The old DB2 jdbc_db2.rb driver was broken enough that
11
+ # applications were exposed to the underlying type (was DECIMAL)
12
+ # and used 0 and 1 as false and true, respectively.
13
+ #
14
+ # This driver now uses SMALLINT as a boolean, and properly
15
+ # type cast's it to a Ruby boolean. Need to make sure we don't
16
+ # break existing apps!
17
+ def test_boolean_as_integer
18
+ e = DbType.find(:first)
19
+
20
+ # true
21
+ e.sample_boolean = 1
22
+ assert_equal true, e.sample_boolean
23
+ assert_equal true, e.sample_boolean?
24
+ e.save!
25
+
26
+ e = DbType.find(:first)
27
+ assert_equal true, e.sample_boolean
28
+ assert_equal true, e.sample_boolean?
29
+
30
+ # false
31
+ e.sample_boolean = 0
32
+ assert_equal false, e.sample_boolean
33
+ assert_equal false, e.sample_boolean?
34
+ e.save!
35
+
36
+ e = DbType.find(:first)
37
+ assert_equal false, e.sample_boolean
38
+ assert_equal false, e.sample_boolean?
39
+ end
6
40
  end
7
41
 
8
42
  class DB2HasManyThroughTest < Test::Unit::TestCase
9
43
  include HasManyThroughMethods
10
44
  end
45
+
46
+ class DB2Test < Test::Unit::TestCase
47
+ def setup
48
+ @inst = Object.new
49
+ @inst.extend ArJdbc::DB2
50
+ @column = Object.new
51
+ class << @column
52
+ attr_accessor :type
53
+ end
54
+ end
55
+
56
+ def test_quote_decimal
57
+ assert_equal %q{'123.45'}, @inst.quote("123.45")
58
+ @column.type = :decimal
59
+ assert_equal %q{123.45}, @inst.quote("123.45", @column), "decimal columns should not have quotes"
60
+ end
61
+
62
+ def test_primary_key_generation
63
+ @column.type = :primary_key
64
+ assert_equal 'int not null generated by default as identity (start with 1) primary key', @inst.modify_types({:string => {}, :integer => {}, :boolean => {}})[:primary_key]
65
+ end
66
+ end
@@ -8,14 +8,61 @@ class CreateDummies < ActiveRecord::Migration
8
8
  end
9
9
  add_index :dummies, :year, :unique => true
10
10
  end
11
-
11
+
12
+ end
13
+
14
+ class ChangeColumn < ActiveRecord::Migration
15
+ def self.up
16
+ create_table :people, :id => false, :force => true do |t|
17
+ t.string :id, :limit => 22, :null => false
18
+ t.string :name, :null => false
19
+ end
20
+ change_column(:people, :name, :string, {:limit=>22})
21
+ execute("SELECT id FROM people WHERE id = 'some string'")
22
+ end
23
+
24
+ def self.down
25
+ end
26
+
27
+ end
28
+
29
+ class CreateIndex < ActiveRecord::Migration
30
+ def self.up
31
+ create_table :people, :id => false, :force => true do |t|
32
+ t.string :id, :limit => 22, :null => false
33
+ t.string :first_name, :null => false
34
+ t.string :last_name, :null => false
35
+ t.string :nickname, :null => false
36
+ t.string :long_name, :null => false
37
+ t.string :very_long_name, :null => false
38
+ t.string :extremely_long_name, :null => false
39
+ end
40
+
41
+ add_index(:people, [:first_name, :last_name, :nickname, :long_name, :very_long_name, :extremely_long_name], :unique => true)
42
+
43
+ remove_index(:people, [:first_name, :last_name, :nickname, :long_name, :very_long_name, :extremely_long_name])
44
+ end
45
+
46
+ def self.down
47
+ end
48
+
12
49
  end
13
50
 
14
- class DerbyQuotingTest < Test::Unit::TestCase
51
+ class DerbyMigrationTest < Test::Unit::TestCase
15
52
  include FixtureSetup
16
53
 
17
54
  def test_create_table_column_quoting_vs_keywords
18
55
  CreateDummies.up
19
56
  end
20
-
57
+
58
+ def test_migrate_change_column_for_non_standard_id
59
+ ChangeColumn.up
60
+ ChangeColumn.down
61
+ end
62
+
63
+ def test_migrate_create_index
64
+ CreateIndex.up
65
+ CreateIndex.down
66
+ end
67
+
21
68
  end