activerecord-jdbc-adapter 0.9.1 → 0.9.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (52) hide show
  1. data/History.txt +33 -0
  2. data/Manifest.txt +17 -0
  3. data/README.txt +48 -20
  4. data/Rakefile +2 -169
  5. data/lib/active_record/connection_adapters/jdbc_adapter.rb +11 -5
  6. data/lib/active_record/connection_adapters/jdbc_adapter_spec.rb +12 -0
  7. data/lib/jdbc_adapter.rb +1 -1
  8. data/lib/jdbc_adapter/jdbc.rake +43 -30
  9. data/lib/jdbc_adapter/jdbc_adapter_internal.jar +0 -0
  10. data/lib/jdbc_adapter/jdbc_db2.rb +2 -2
  11. data/lib/jdbc_adapter/jdbc_derby.rb +11 -0
  12. data/lib/jdbc_adapter/jdbc_hsqldb.rb +6 -1
  13. data/lib/jdbc_adapter/jdbc_mimer.rb +14 -7
  14. data/lib/jdbc_adapter/jdbc_mssql.rb +18 -2
  15. data/lib/jdbc_adapter/jdbc_mysql.rb +3 -0
  16. data/lib/jdbc_adapter/jdbc_oracle.rb +24 -14
  17. data/lib/jdbc_adapter/jdbc_postgre.rb +38 -18
  18. data/lib/jdbc_adapter/jdbc_sqlite3.rb +96 -26
  19. data/lib/jdbc_adapter/missing_functionality_helper.rb +40 -34
  20. data/lib/jdbc_adapter/rake_tasks.rb +1 -1
  21. data/lib/jdbc_adapter/tsql_helper.rb +1 -0
  22. data/lib/jdbc_adapter/version.rb +1 -1
  23. data/lib/pg.rb +4 -0
  24. data/rails_generators/jdbc_generator.rb +15 -0
  25. data/rails_generators/templates/jdbc.rake +8 -0
  26. data/rails_generators/templates/jdbc.rb +7 -0
  27. data/rakelib/compile.rake +23 -0
  28. data/rakelib/package.rake +85 -0
  29. data/rakelib/rails.rake +41 -0
  30. data/rakelib/test.rake +71 -0
  31. data/src/java/jdbc_adapter/JdbcAdapterInternalService.java +1 -0
  32. data/src/java/jdbc_adapter/JdbcDerbySpec.java +11 -46
  33. data/src/java/jdbc_adapter/JdbcMySQLSpec.java +3 -2
  34. data/src/java/jdbc_adapter/MssqlRubyJdbcConnection.java +71 -0
  35. data/src/java/jdbc_adapter/PostgresRubyJdbcConnection.java +24 -4
  36. data/src/java/jdbc_adapter/RubyJdbcConnection.java +57 -44
  37. data/test/abstract_db_create.rb +45 -0
  38. data/test/db/mysql.rb +2 -2
  39. data/test/db/postgres.rb +2 -2
  40. data/test/helper.rb +5 -0
  41. data/test/jdbc_adapter/jdbc_db2_test.rb +5 -0
  42. data/test/jdbc_common.rb +2 -0
  43. data/test/models/entry.rb +3 -0
  44. data/test/models/validates_uniqueness_of_string.rb +19 -0
  45. data/test/mysql_db_create_test.rb +25 -0
  46. data/test/mysql_nonstandard_primary_key_test.rb +42 -0
  47. data/test/mysql_simple_test.rb +5 -0
  48. data/test/postgres_db_create_test.rb +21 -0
  49. data/test/postgres_nonseq_pkey_test.rb +40 -0
  50. data/test/simple.rb +62 -1
  51. data/test/sqlite3_simple_test.rb +153 -10
  52. metadata +26 -5
data/History.txt CHANGED
@@ -1,3 +1,36 @@
1
+ == 0.9.2
2
+
3
+ - The main, highly awaited fix for this release is a solution to the
4
+ rake db:create/db:drop issue. The main change is a new 'jdbc' rails
5
+ generator that should be run once to prepare a Rails application to
6
+ use JDBC. The upside of this generator is that you no longer will
7
+ need to alter database.yml for JDBC. See the README.txt for details.
8
+ - Cleanup and reconnect if errors occur during begin/rollback
9
+ (Jean-Dominique Morani, Christian Seiler)
10
+ - ACTIVERECORD_JDBC-1: Add #drop_database method for oracle (does the
11
+ same thing as recreate_database)
12
+ - Sqlite3 and MSSQL fixes (Jean-Dominique Morani)
13
+ - JRUBY-3512: Treat LONGVARCHAR as a CLOB for Mssql
14
+ - JRUBY-3624: Upgrade Derby to 10.5.3.0 and add native limit/offset
15
+ support (Christopher Saunders)
16
+ - JRUBY-3616: Fix postgres non-sequence primary keys (David Kellum)
17
+ - JRUBY-3669: Fix Oracle case with unconfigured schema (Dan Powell)
18
+ - Fixed quote_column_name of jdbc_oracle to accept numbers (Marcelo
19
+ Murad)
20
+ - Fix for mysql tables with non standard primary keys such that the
21
+ schema dump is correct (Nick Zalabak)
22
+ - MSSQL fixes from Mike Luu:
23
+ - add support for MSSQL uniqueidentifier datatype
24
+ - always quote strings using unicode identifier for MSSQL
25
+ - Changes primary_key generation to use always instead of by default
26
+ for DB2 (Amos King)
27
+ - Improves the SQLite adapter by fixing rename_column, change_column,
28
+ change_column_default, changing remove_column, and adding
29
+ remove_columns (Ryan Baumann)
30
+ - More oracle love courtesy Ben Browning and Jens Himmelreich
31
+ - JRUBY-3608: Add missing change_column_null method for postgres
32
+ - JRUBY-3508: Fix quoting of integer and float columns
33
+
1
34
  == 0.9.1
2
35
 
3
36
  - We did a lot of internal cleanup this release in the hopes of
data/Manifest.txt CHANGED
@@ -33,7 +33,9 @@ lib/jdbc_adapter/rake_tasks.rb
33
33
  lib/jdbc_adapter/tsql_helper.rb
34
34
  lib/jdbc_adapter/version.rb
35
35
  lib/jdbc_adapter.rb
36
+ lib/pg.rb
36
37
  lib/jdbc_adapter/jdbc_adapter_internal.jar
38
+ test/abstract_db_create.rb
37
39
  test/activerecord/connection_adapters/type_conversion_test.rb
38
40
  test/activerecord/connections/native_jdbc_mysql/connection.rb
39
41
  test/cachedb_simple_test.rb
@@ -58,6 +60,7 @@ test/derby_simple_test.rb
58
60
  test/generic_jdbc_connection_test.rb
59
61
  test/h2_simple_test.rb
60
62
  test/has_many_through.rb
63
+ test/helper.rb
61
64
  test/hsqldb_simple_test.rb
62
65
  test/informix_simple_test.rb
63
66
  test/jdbc_adapter/jdbc_db2_test.rb
@@ -79,11 +82,16 @@ test/models/data_types.rb
79
82
  test/models/entry.rb
80
83
  test/models/mixed_case.rb
81
84
  test/models/reserved_word.rb
85
+ test/models/validates_uniqueness_of_string.rb
82
86
  test/mssql_simple_test.rb
87
+ test/mysql_db_create_test.rb
83
88
  test/mysql_multibyte_test.rb
89
+ test/mysql_nonstandard_primary_key_test.rb
84
90
  test/mysql_simple_test.rb
85
91
  test/oracle_simple_test.rb
92
+ test/postgres_db_create_test.rb
86
93
  test/postgres_mixed_case_test.rb
94
+ test/postgres_nonseq_pkey_test.rb
87
95
  test/postgres_reserved_test.rb
88
96
  test/postgres_simple_test.rb
89
97
  test/simple.rb
@@ -94,7 +102,16 @@ src/java/jdbc_adapter/JdbcAdapterInternalService.java
94
102
  src/java/jdbc_adapter/JdbcConnectionFactory.java
95
103
  src/java/jdbc_adapter/JdbcDerbySpec.java
96
104
  src/java/jdbc_adapter/JdbcMySQLSpec.java
105
+ src/java/jdbc_adapter/MssqlRubyJdbcConnection.java
97
106
  src/java/jdbc_adapter/PostgresRubyJdbcConnection.java
98
107
  src/java/jdbc_adapter/RubyJdbcConnection.java
99
108
  src/java/jdbc_adapter/SQLBlock.java
100
109
  src/java/jdbc_adapter/Sqlite3RubyJdbcConnection.java
110
+ rakelib/compile.rake
111
+ rakelib/package.rake
112
+ rakelib/rails.rake
113
+ rakelib/test.rake
114
+ rails_generators/jdbc_generator.rb
115
+ rails_generators/templates
116
+ rails_generators/templates/jdbc.rake
117
+ rails_generators/templates/jdbc.rb
data/README.txt CHANGED
@@ -2,6 +2,13 @@ activerecord-jdbc-adapter is a database adapter for Rails' ActiveRecord
2
2
  component that can be used with JRuby[http://www.jruby.org/]. It allows use of
3
3
  virtually any JDBC-compliant database with your JRuby on Rails application.
4
4
 
5
+ == Project Info
6
+
7
+ * Mailing Lists: http://kenai.com/projects/activerecord-jdbc/lists
8
+ * Issues: http://kenai.com/jira/browse/ACTIVERECORD_JDBC
9
+ * Source: git://kenai.com/activerecord-jdbc~main
10
+ git://github.com/nicksieger/activerecord-jdbc-adapter.git
11
+
5
12
  == Databases
6
13
 
7
14
  What's there, and what is not there:
@@ -49,13 +56,23 @@ To use activerecord-jdbc-adapter with JRuby on Rails:
49
56
  * derby (<tt>activerecord-jdbcderby-adapter</tt>)
50
57
  * hsqldb (<tt>activerecord-jdbchsqldb-adapter</tt>)
51
58
  * h2 (<tt>activerecord-jdbch2-adapter</tt>)
59
+ * sqlite3 (<tt>activerecord-jdbcsqlite3-adapter</tt>)
60
+
61
+ 2. Run the "jdbc" generator to prepare your Rails application for
62
+ JDBC.
52
63
 
53
- 2. If you're using Rails 2.0, you may skip to the next step. For Rails prior to
54
- version 2.0, you'll need to add one-time setup to your config/environment.rb
55
- file in your Rails application. Add the following lines just before the
56
- <code>Rails::Initializer</code>. (If you're using activerecord-jdbc-adapter
57
- under the old gem name used in versions 0.5 and earlier (ActiveRecord-JDBC),
58
- replace 'activerecord-jdbc-adapter' with 'ActiveRecord-JDBC' below.)
64
+ jruby script/generate jdbc
65
+
66
+ The initializer and rake task files generated are guarded such that
67
+ they won't be loaded if you still run your application un C Ruby.
68
+
69
+ Legacy: If you're using Rails prior to version 2.0, you'll need to
70
+ add one-time setup to your config/environment.rb file in your Rails
71
+ application. Add the following lines just before the
72
+ <code>Rails::Initializer</code>. (If you're using
73
+ activerecord-jdbc-adapter under the old gem name used in versions
74
+ 0.5 and earlier (ActiveRecord-JDBC), replace
75
+ 'activerecord-jdbc-adapter' with 'ActiveRecord-JDBC' below.)
59
76
 
60
77
  if RUBY_PLATFORM =~ /java/
61
78
  require 'rubygems'
@@ -63,11 +80,11 @@ To use activerecord-jdbc-adapter with JRuby on Rails:
63
80
  require 'jdbc_adapter'
64
81
  end
65
82
 
66
- 3. Configure your database.yml to use the <code>jdbc</code> adapter. For mysql,
67
- postgres, derby, oracle, hsqldb, h2, and informix you can simply configure
68
- the database in the normal Rails style. If you use one of the convenience
69
- 'activerecord-jdbcXXX-adapter' adapters, be sure and put a 'jdbc' prefix in
70
- front of the databas adapter name as below.
83
+ 3. Configure your database.yml in the normal Rails style.
84
+
85
+ Legacy configuration: If you use one of the convenience
86
+ 'activerecord-jdbcXXX-adapter' adapters, you can still put a 'jdbc'
87
+ prefix in front of the databas adapter name as below.
71
88
 
72
89
  development:
73
90
  adapter: jdbcmysql
@@ -76,8 +93,8 @@ To use activerecord-jdbc-adapter with JRuby on Rails:
76
93
  hostname: localhost
77
94
  database: weblog_development
78
95
 
79
- For other databases, you'll need to know the database driver class and URL.
80
- Example:
96
+ For other databases, you'll need to know the database driver class
97
+ and URL. Example:
81
98
 
82
99
  development:
83
100
  adapter: jdbc
@@ -126,12 +143,23 @@ The source for activerecord-jdbc-adapter is available using git.
126
143
 
127
144
  git clone git://github.com/nicksieger/activerecord-jdbc-adapter.git
128
145
 
146
+ == Feedback
147
+
148
+ Please file bug reports at
149
+ http://kenai.com/jira/browse/ACTIVERECORD_JDBC. If you're not sure if
150
+ something's a bug, feel free to pre-report it on the mailing lists.
151
+
129
152
  == Running AR-JDBC's Tests
130
153
 
131
- Drivers for 4 open-source databases are included. Provided you have MySQL
154
+ Drivers for 6 open-source databases are included. Provided you have MySQL
132
155
  installed, you can simply type <tt>jruby -S rake</tt> to run the tests. A
133
156
  database named <tt>weblog_development</tt> is needed beforehand with a
134
- connection user of "blog" and password empty.
157
+ connection user of "blog" and an empty password.
158
+
159
+ If you also have PostgreSQL available, those tests will be run if the
160
+ `psql' executable can be found. Also ensure you have a database named
161
+ <tt>weblog_development</tt> and a user named "blog" and an empty
162
+ password.
135
163
 
136
164
  If you want rails logging enabled during these test runs you can edit
137
165
  test/jdbc_common.rb and add the following line:
@@ -140,11 +168,11 @@ require 'db/logger'
140
168
 
141
169
  == Running AR Tests
142
170
 
143
- # If you want to run MRI against Rails remember to re-export RUBYLIB to be
144
- # empty (or whatever you normally have it set to when you are done).
145
- export RUBYLIB=$(find $HOME/NetbeansProjects/activerecord-jdbc-adapter -name lib -type d | grep -v pkg | ruby -e 'puts $stdin.readlines.map{|l| l.chomp}.join(":")')
146
- cd active_record_source_dir
147
- jruby -S rake test_jdbcmysql (or specific adapter you want to test)
171
+ To run the current AR-JDBC sources with ActiveRecord, just use the
172
+ included "rails:test" task. Be sure to specify a driver and a path to
173
+ the ActiveRecord sources.
174
+
175
+ jruby -S rake rails:test DRIVER=mysql RAILS=/path/activerecord_source_dir
148
176
 
149
177
  == Authors
150
178
 
data/Rakefile CHANGED
@@ -1,177 +1,10 @@
1
- require 'rake'
2
1
  require 'rake/testtask'
2
+ require 'rake/clean'
3
+ CLEAN.include 'derby*', 'test.db.*','test/reports', 'test.sqlite3','lib/**/*.jar','manifest.mf', '*.log'
3
4
 
4
5
  task :default => [:java_compile, :test]
5
6
 
6
- def java_classpath_arg # myriad of ways to discover JRuby classpath
7
- begin
8
- cpath = Java::java.lang.System.getProperty('java.class.path').split(File::PATH_SEPARATOR)
9
- cpath += Java::java.lang.System.getProperty('sun.boot.class.path').split(File::PATH_SEPARATOR)
10
- jruby_cpath = cpath.compact.join(File::PATH_SEPARATOR)
11
- rescue => e
12
- end
13
- unless jruby_cpath
14
- jruby_cpath = ENV['JRUBY_PARENT_CLASSPATH'] || ENV['JRUBY_HOME'] &&
15
- FileList["#{ENV['JRUBY_HOME']}/lib/*.jar"].join(File::PATH_SEPARATOR)
16
- end
17
- jruby_cpath ? "-cp \"#{jruby_cpath}\"" : ""
18
- end
19
-
20
- desc "Compile the native Java code."
21
- task :java_compile do
22
- pkg_classes = File.join(*%w(pkg classes))
23
- jar_name = File.join(*%w(lib jdbc_adapter jdbc_adapter_internal.jar))
24
- mkdir_p pkg_classes
25
- sh "javac -target 1.5 -source 1.5 -d pkg/classes #{java_classpath_arg} #{FileList['src/java/**/*.java'].join(' ')}"
26
- sh "jar cf #{jar_name} -C #{pkg_classes} ."
27
- end
28
- file "lib/jdbc_adapter/jdbc_adapter_internal.jar" => :java_compile
29
-
30
7
  task :filelist do
31
8
  puts FileList['pkg/**/*'].inspect
32
9
  end
33
10
 
34
- if defined?(JRUBY_VERSION)
35
- # TODO: add more databases into the standard tests here.
36
- task :test => [:test_mysql, :test_jdbc, :test_derby, :test_hsqldb, :test_h2, :test_sqlite3]
37
- else
38
- task :test => [:test_mysql]
39
- end
40
-
41
- FileList['drivers/*'].each do |d|
42
- next unless File.directory?(d)
43
- driver = File.basename(d)
44
- Rake::TestTask.new("test_#{driver}") do |t|
45
- files = FileList["test/#{driver}*test.rb"]
46
- if driver == "derby"
47
- files << 'test/activerecord/connection_adapters/type_conversion_test.rb'
48
- end
49
- t.test_files = files
50
- t.libs = []
51
- if defined?(JRUBY_VERSION)
52
- t.ruby_opts << "-rjdbc/#{driver}"
53
- t.libs << "lib" << "#{d}/lib"
54
- t.libs.push *FileList["adapters/#{driver}*/lib"]
55
- end
56
- t.libs << "test"
57
- t.verbose = true
58
- end
59
- end
60
-
61
- Rake::TestTask.new(:test_jdbc) do |t|
62
- t.test_files = FileList['test/generic_jdbc_connection_test.rb', 'test/jndi_callbacks_test.rb']
63
- t.libs << 'test' << 'drivers/mysql/lib'
64
- end
65
-
66
- Rake::TestTask.new(:test_jndi) do |t|
67
- t.test_files = FileList['test/jndi_test.rb']
68
- t.libs << 'test' << 'drivers/derby/lib'
69
- end
70
-
71
- task :test_postgresql => [:test_postgres]
72
- task :test_pgsql => [:test_postgres]
73
-
74
- # Ensure driver for these DBs is on your classpath
75
- %w(oracle db2 cachedb mssql informix).each do |d|
76
- Rake::TestTask.new("test_#{d}") do |t|
77
- t.test_files = FileList["test/#{d}_simple_test.rb"]
78
- t.libs = []
79
- t.libs << 'lib' if defined?(JRUBY_VERSION)
80
- t.libs << 'test'
81
- end
82
- end
83
-
84
- # Tests for JDBC adapters that don't require a database.
85
- Rake::TestTask.new(:test_jdbc_adapters) do | t |
86
- t.test_files = FileList[ 'test/jdbc_adapter/jdbc_sybase_test.rb' ]
87
- t.libs << 'test'
88
- end
89
-
90
- # Ensure that the jTDS driver is in your classpath before launching rake
91
- Rake::TestTask.new(:test_sybase_jtds) do |t|
92
- t.test_files = FileList['test/sybase_jtds_simple_test.rb']
93
- t.libs << 'test'
94
- end
95
-
96
- # Ensure that the jConnect driver is in your classpath before launching rake
97
- Rake::TestTask.new(:test_sybase_jconnect) do |t|
98
- t.test_files = FileList['test/sybase_jconnect_simple_test.rb']
99
- t.libs << 'test'
100
- end
101
-
102
- MANIFEST = FileList["History.txt", "Manifest.txt", "README.txt",
103
- "Rakefile", "LICENSE.txt", "lib/**/*.rb", "lib/jdbc_adapter/jdbc_adapter_internal.jar", "test/**/*.rb",
104
- "lib/**/*.rake", "src/**/*.java"]
105
-
106
- file "Manifest.txt" => :manifest
107
- task :manifest do
108
- File.open("Manifest.txt", "w") {|f| MANIFEST.each {|n| f << "#{n}\n"} }
109
- end
110
- Rake::Task['manifest'].invoke # Always regen manifest, so Hoe has up-to-date list of files
111
-
112
- require File.dirname(__FILE__) + "/lib/jdbc_adapter/version"
113
- begin
114
- require 'hoe'
115
- Hoe.new("activerecord-jdbc-adapter", JdbcAdapter::Version::VERSION) do |p|
116
- p.rubyforge_name = "jruby-extras"
117
- p.url = "http://jruby-extras.rubyforge.org/activerecord-jdbc-adapter"
118
- p.author = "Nick Sieger, Ola Bini and JRuby contributors"
119
- p.email = "nick@nicksieger.com, ola.bini@gmail.com"
120
- p.summary = "JDBC adapter for ActiveRecord, for use within JRuby on Rails."
121
- p.changes = p.paragraphs_of('History.txt', 0..1).join("\n\n")
122
- p.description = p.paragraphs_of('README.txt', 0...1).join("\n\n")
123
- end.spec.dependencies.delete_if { |dep| dep.name == "hoe" }
124
- rescue LoadError
125
- puts "You really need Hoe installed to be able to package this gem"
126
- rescue => e
127
- puts "ignoring error while loading hoe: #{e.to_s}"
128
- end
129
-
130
- def rake(*args)
131
- ruby "-S", "rake", *args
132
- end
133
-
134
- %w(test package install_gem release clean).each do |task|
135
- desc "Run rake #{task} on all available adapters and drivers"
136
- task "all:#{task}" => task
137
- end
138
-
139
- (Dir["drivers/*/Rakefile"] + Dir["adapters/*/Rakefile"]).each do |rakefile|
140
- dir = File.dirname(rakefile)
141
- prefix = dir.sub(%r{/}, ':')
142
- tasks = %w(package install_gem debug_gem clean)
143
- tasks << "test" if File.directory?(File.join(dir, "test"))
144
- tasks.each do |task|
145
- desc "Run rake #{task} on #{dir}"
146
- task "#{prefix}:#{task}" do
147
- Dir.chdir(dir) do
148
- rake task
149
- end
150
- end
151
- task "#{File.dirname(dir)}:#{task}" => "#{prefix}:#{task}"
152
- task "all:#{task}" => "#{prefix}:#{task}"
153
- end
154
- desc "Run rake release on #{dir}"
155
- task "#{prefix}:release" do
156
- Dir.chdir(dir) do
157
- version = nil
158
- if dir =~ /adapters/
159
- version = ENV['VERSION']
160
- else
161
- Dir["lib/**/*.rb"].each do |file|
162
- version ||= File.open(file) {|f| f.read =~ /VERSION = "([^"]+)"/ && $1}
163
- end
164
- end
165
- rake "release", "VERSION=#{version}"
166
- end
167
- end
168
- # Only release adapters synchronously with main release. Drivers are versioned
169
- # according to their JDBC driver versions.
170
- if dir =~ /adapters/
171
- task "adapters:release" => "#{prefix}:release"
172
- task "all:release" => "#{prefix}:release"
173
- end
174
- end
175
-
176
- require 'rake/clean'
177
- CLEAN.include 'derby*', 'test.db.*','test/reports', 'test.sqlite3','lib/**/*.jar','manifest.mf', '*.log'
@@ -1,14 +1,10 @@
1
+ require 'active_record/version'
1
2
  require 'active_record/connection_adapters/abstract_adapter'
2
3
  require 'java'
3
4
  require 'active_record/connection_adapters/jdbc_adapter_spec'
4
5
  require 'jdbc_adapter/jdbc_adapter_internal'
5
6
  require 'bigdecimal'
6
7
 
7
- begin
8
- require 'jdbc_adapter/rake_tasks'
9
- rescue LoadError
10
- end if defined?(RAILS_ROOT)
11
-
12
8
  # AR's 2.2 version of this method is sufficient, but we need it for
13
9
  # older versions
14
10
  if ActiveRecord::VERSION::MAJOR <= 2 && ActiveRecord::VERSION::MINOR < 2
@@ -618,6 +614,16 @@ module ActiveRecord
618
614
  @connection.write_large_object(*args)
619
615
  end
620
616
 
617
+ def pk_and_sequence_for(table)
618
+ result_set = @connection.connection.get_meta_data.get_primary_keys(nil, nil, table)
619
+ if result_set.next
620
+ keys = [result_set.getString("COLUMN_NAME"), nil]
621
+ end
622
+ keys.blank? ? nil : keys
623
+ ensure
624
+ result_set.close
625
+ end
626
+
621
627
  private
622
628
  def select(sql, name=nil)
623
629
  execute(sql,name)
@@ -1,3 +1,15 @@
1
+ module JdbcSpec
2
+ module ActiveRecordExtensions
3
+ def self.add_method_to_remove_from_ar_base(meth)
4
+ @methods ||= []
5
+ @methods << meth
6
+ end
7
+
8
+ def self.extended(klass)
9
+ (@methods || []).each {|m| (class << klass; self; end).instance_eval { remove_method(m) rescue nil } }
10
+ end
11
+ end
12
+ end
1
13
 
2
14
  require 'jdbc_adapter/jdbc_mimer'
3
15
  require 'jdbc_adapter/jdbc_hsqldb'
data/lib/jdbc_adapter.rb CHANGED
@@ -1,4 +1,4 @@
1
- if RUBY_PLATFORM =~ /java/
1
+ if defined?(JRUBY_VERSION)
2
2
  begin
3
3
  tried_gem ||= false
4
4
  require 'active_record/version'
@@ -6,7 +6,7 @@ def redefine_task(*args, &block)
6
6
  public :instance_variable_set
7
7
  attr_reader :actions
8
8
  end
9
- existing_task.instance_variable_set "@prerequisites", FileList[]
9
+ existing_task.instance_variable_set "@prerequisites", FileList[]
10
10
  existing_task.actions.shift
11
11
  enhancements = existing_task.actions
12
12
  existing_task.instance_variable_set "@actions", []
@@ -16,46 +16,59 @@ def redefine_task(*args, &block)
16
16
  end
17
17
 
18
18
  namespace :db do
19
- if Rake::Task["db:create"]
20
- redefine_task :create => :environment do
21
- create_database(ActiveRecord::Base.configurations[RAILS_ENV])
19
+ redefine_task :create => :environment do
20
+ create_database(ActiveRecord::Base.configurations[RAILS_ENV])
21
+ end
22
+ task :create => :load_config if Rake.application.lookup(:load_config)
23
+
24
+ redefine_task :drop => :environment do
25
+ config = ActiveRecord::Base.configurations[RAILS_ENV]
26
+ begin
27
+ ActiveRecord::Base.establish_connection(config)
28
+ db = ActiveRecord::Base.connection.database_name
29
+ ActiveRecord::Base.connection.drop_database(db)
30
+ rescue
31
+ drop_database(config.merge('adapter' => config['adapter'].sub(/^jdbc/, '')))
22
32
  end
33
+ end
34
+ task :drop => :load_config if Rake.application.lookup(:load_config)
23
35
 
24
- class << self; alias_method :previous_create_database, :create_database; end
25
- def create_database(config)
26
- begin
27
- ActiveRecord::Base.establish_connection(config)
28
- ActiveRecord::Base.connection
29
- rescue
30
- begin
31
- url = config['url']
32
- if url
33
- if url =~ /^(.*\/)/
34
- url = $1
35
- end
36
- end
36
+ namespace :create do
37
+ task :all => :environment
38
+ end
37
39
 
38
- ActiveRecord::Base.establish_connection(config.merge({'database' => nil, 'url' => url}))
39
- ActiveRecord::Base.connection.create_database(config['database'])
40
- ActiveRecord::Base.establish_connection(config)
41
- rescue
42
- previous_create_database(config)
43
- end
44
- end
45
- end
40
+ namespace :drop do
41
+ task :all => :environment
42
+ end
46
43
 
47
- redefine_task :drop => :environment do
48
- config = ActiveRecord::Base.configurations[RAILS_ENV]
44
+ class << self
45
+ alias_method :previous_create_database, :create_database
46
+ alias_method :previous_drop_database, :drop_database
47
+ end
48
+
49
+ def create_database(config)
50
+ begin
51
+ ActiveRecord::Base.establish_connection(config)
52
+ ActiveRecord::Base.connection
53
+ rescue
49
54
  begin
55
+ if url = config['url'] && url =~ /^(.*(?<!\/)\/)(?=\w)/
56
+ url = $1
57
+ end
58
+
59
+ ActiveRecord::Base.establish_connection(config.merge({'database' => nil, 'url' => url}))
60
+ ActiveRecord::Base.connection.create_database(config['database'])
50
61
  ActiveRecord::Base.establish_connection(config)
51
- db = ActiveRecord::Base.connection.database_name
52
- ActiveRecord::Base.connection.drop_database(db)
53
62
  rescue
54
- drop_database(config)
63
+ previous_create_database(config.merge('adapter' => config['adapter'].sub(/^jdbc/, '')))
55
64
  end
56
65
  end
57
66
  end
58
67
 
68
+ def drop_database(config)
69
+ previous_drop_database(config.merge('adapter' => config['adapter'].sub(/^jdbc/, '')))
70
+ end
71
+
59
72
  namespace :structure do
60
73
  redefine_task :dump => :environment do
61
74
  abcs = ActiveRecord::Base.configurations