activerecord-jdbc-adapter 1.1.3 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (68) hide show
  1. data/.gitignore +22 -0
  2. data/Gemfile +14 -0
  3. data/Gemfile.lock +42 -0
  4. data/History.txt +10 -3
  5. data/{README.txt → README.rdoc} +30 -14
  6. data/Rakefile +49 -0
  7. data/activerecord-jdbc-adapter.gemspec +23 -0
  8. data/bench/bench_attributes.rb +13 -0
  9. data/bench/bench_attributes_new.rb +14 -0
  10. data/bench/bench_create.rb +12 -0
  11. data/bench/bench_find_all.rb +12 -0
  12. data/bench/bench_find_all_mt.rb +25 -0
  13. data/bench/bench_model.rb +85 -0
  14. data/bench/bench_new.rb +12 -0
  15. data/bench/bench_new_valid.rb +12 -0
  16. data/bench/bench_valid.rb +13 -0
  17. data/lib/activerecord-jdbc-adapter.rb +1 -1
  18. data/lib/arel/visitors/derby.rb +5 -1
  19. data/lib/arjdbc.rb +12 -17
  20. data/lib/arjdbc/db2/adapter.rb +91 -4
  21. data/lib/arjdbc/derby/adapter.rb +8 -8
  22. data/lib/arjdbc/derby/connection_methods.rb +1 -0
  23. data/lib/arjdbc/firebird/adapter.rb +4 -4
  24. data/lib/arjdbc/h2/adapter.rb +3 -2
  25. data/lib/arjdbc/h2/connection_methods.rb +1 -0
  26. data/lib/arjdbc/hsqldb/adapter.rb +5 -2
  27. data/lib/arjdbc/hsqldb/connection_methods.rb +1 -0
  28. data/lib/arjdbc/informix/adapter.rb +2 -2
  29. data/lib/arjdbc/informix/connection_methods.rb +1 -0
  30. data/lib/arjdbc/jdbc/adapter.rb +92 -22
  31. data/lib/arjdbc/jdbc/adapter_java.jar +0 -0
  32. data/lib/arjdbc/mimer/adapter.rb +4 -4
  33. data/lib/arjdbc/mssql/adapter.rb +10 -8
  34. data/lib/arjdbc/mssql/connection_methods.rb +1 -0
  35. data/lib/arjdbc/mssql/limit_helpers.rb +7 -4
  36. data/lib/arjdbc/mysql/adapter.rb +30 -6
  37. data/lib/arjdbc/mysql/connection_methods.rb +1 -0
  38. data/lib/arjdbc/oracle/adapter.rb +15 -12
  39. data/lib/arjdbc/oracle/connection_methods.rb +1 -0
  40. data/lib/arjdbc/postgresql/adapter.rb +35 -16
  41. data/lib/arjdbc/postgresql/connection_methods.rb +1 -0
  42. data/lib/arjdbc/sqlite3/adapter.rb +13 -10
  43. data/lib/arjdbc/sqlite3/connection_methods.rb +1 -0
  44. data/lib/arjdbc/version.rb +1 -1
  45. data/lib/generators/jdbc/USAGE +10 -0
  46. data/pom.xml +57 -0
  47. data/rakelib/rails.rake +1 -1
  48. data/rakelib/test.rake +20 -6
  49. data/src/java/arjdbc/jdbc/RubyJdbcConnection.java +4 -1
  50. data/src/java/arjdbc/jdbc/SQLBlock.java +1 -1
  51. data/src/java/arjdbc/mysql/MySQLRubyJdbcConnection.java +74 -0
  52. data/test/abstract_db_create.rb +8 -1
  53. data/test/activerecord/jall.sh +7 -0
  54. data/test/activerecord/jtest.sh +3 -0
  55. data/test/jdbc_common.rb +6 -4
  56. data/test/models/data_types.rb +1 -1
  57. data/test/models/string_id.rb +2 -0
  58. data/test/models/thing.rb +16 -0
  59. data/test/mysql_index_length_test.rb +58 -0
  60. data/test/mysql_info_test.rb +3 -3
  61. data/test/postgres_db_create_test.rb +1 -1
  62. data/test/simple.rb +11 -3
  63. data/test/sqlite3_simple_test.rb +16 -2
  64. metadata +167 -108
  65. data/.gemtest +0 -0
  66. data/Manifest.txt +0 -187
  67. data/rakelib/package.rake +0 -92
  68. data/test/pick_rails_version.rb +0 -3
data/.gitignore ADDED
@@ -0,0 +1,22 @@
1
+ pkg
2
+ *.gem
3
+ *.tgz
4
+ derby-testdb*
5
+ derby.log
6
+ test.*
7
+ doc
8
+ build.xml
9
+ nbproject
10
+ TAGS
11
+ *~
12
+ *.log
13
+ patches*
14
+ *#
15
+ .stgit-edit.txt
16
+ /.classpath
17
+ /.project
18
+ /bin
19
+ /jndi_test/jdbc/.bindings
20
+ target
21
+ /test/fscontext.jar
22
+ /test/providerutil.jar
data/Gemfile ADDED
@@ -0,0 +1,14 @@
1
+ source "http://rubygems.org"
2
+
3
+ # This may wreak havoc on the lockfile, but we need a way to test
4
+ # different AR versions
5
+ gem 'activerecord', ENV['AR_VERSION']
6
+
7
+ gem 'rake'
8
+
9
+ gem 'jruby-openssl', :group => :development
10
+
11
+ group :test do
12
+ gem 'ruby-debug'
13
+ gem 'mocha'
14
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,42 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ activemodel (3.1.0)
5
+ activesupport (= 3.1.0)
6
+ bcrypt-ruby (~> 3.0.0)
7
+ builder (~> 3.0.0)
8
+ i18n (~> 0.6)
9
+ activerecord (3.1.0)
10
+ activemodel (= 3.1.0)
11
+ activesupport (= 3.1.0)
12
+ arel (~> 2.2.1)
13
+ tzinfo (~> 0.3.29)
14
+ activesupport (3.1.0)
15
+ multi_json (~> 1.0)
16
+ arel (2.2.1)
17
+ bcrypt-ruby (3.0.0-java)
18
+ bouncy-castle-java (1.5.0146.1)
19
+ builder (3.0.0)
20
+ columnize (0.3.1)
21
+ i18n (0.6.0)
22
+ jruby-openssl (0.7.4)
23
+ bouncy-castle-java
24
+ mocha (0.9.8)
25
+ rake
26
+ multi_json (1.0.3)
27
+ rake (0.9.2)
28
+ ruby-debug (0.10.4)
29
+ columnize (>= 0.1)
30
+ ruby-debug-base (~> 0.10.4.0)
31
+ ruby-debug-base (0.10.4-java)
32
+ tzinfo (0.3.29)
33
+
34
+ PLATFORMS
35
+ java
36
+
37
+ DEPENDENCIES
38
+ activerecord
39
+ jruby-openssl
40
+ mocha
41
+ rake
42
+ ruby-debug
data/History.txt CHANGED
@@ -1,4 +1,11 @@
1
- == 1.1.3
1
+ == 1.2.0 (09/13/11)
2
+
3
+ - Support for Rails 3.1
4
+ - Improvements to index usage on PostgreSQL (albertosaurus and
5
+ pazustep)
6
+ - Compatibility: tested with Rails 2.3, 3.0 and 3.1
7
+
8
+ == 1.1.3 (07/26/11)
2
9
 
3
10
  - Remove AR version < 3 guard around some caching methods (sugg. invadersmustdie)
4
11
  - Small bug in arjdbc/discover logic, thanks autotelik.
@@ -7,7 +14,7 @@
7
14
  - #71: fix yield called out of block error
8
15
  - Silence Rake::DSL warnings for Rake > 0.9
9
16
 
10
- == 1.1.2
17
+ == 1.1.2 (06/20/11)
11
18
 
12
19
  - Update version of H2 driver from 1.1.107 to 1.3.153 (Ketan
13
20
  Padegaonkar, Jeremy Stephens)
@@ -46,7 +53,7 @@
46
53
  - GH#31: mssql: Remove extra code breaking mssql w/o limit
47
54
  - ACTIVERECORD_JDBC-156: mssql: Logic fix for detecting select_count?
48
55
 
49
- == 1.1.1
56
+ == 1.1.1 (01/14/11)
50
57
 
51
58
  - Arel 2.0.7 compatibility: fix bugs arising from use of Arel 2.0.7 +
52
59
  ArJdbc 1.1.0.
@@ -1,3 +1,5 @@
1
+ = Activerecord-jdbc-adapter
2
+
1
3
  activerecord-jdbc-adapter is a database adapter for Rails' ActiveRecord
2
4
  component that can be used with JRuby[http://www.jruby.org/]. It allows use of
3
5
  virtually any JDBC-compliant database with your JRuby on Rails application.
@@ -9,8 +11,7 @@ MySQL, PostgreSQL, SQLite3, Oracle, Microsoft SQL Server, DB2,
9
11
  FireBird, Derby, HSQLDB, H2, and Informix.
10
12
 
11
13
  Other databases will require testing and likely a custom configuration module.
12
- Please join the activerecord-jdbc
13
- mailing-lists[http://kenai.com/projects/activerecord-jdbc/lists] to help us discover
14
+ Please join the JRuby mailing-list[http://jruby.org/community] to help us discover
14
15
  support for more databases.
15
16
 
16
17
  == Using ActiveRecord JDBC
@@ -34,7 +35,7 @@ adapters are available:
34
35
  2a. For Rails 3, if you're generating a new application, use the
35
36
  following command to generate your application:
36
37
 
37
- jruby -S rails new sweetapp -m http://jruby.org/rails3.rb
38
+ jruby -S rails new sweetapp
38
39
 
39
40
  2b. Otherwise, you'll need to perform some extra configuration steps
40
41
  to prepare your Rails application for JDBC.
@@ -43,11 +44,13 @@ If you're using Rails 3, you'll need to modify your Gemfile to use the
43
44
  activerecord-jdbc-adapter gem under JRuby. Change your Gemfile to look
44
45
  like the following (using sqlite3 as an example):
45
46
 
46
- if defined?(JRUBY_VERSION)
47
- gem 'activerecord-jdbc-adapter'
48
- gem 'jdbc-sqlite3'
49
- else
50
- gem 'sqlite3-ruby', :require => 'sqlite3'
47
+ platforms :ruby do
48
+ gem 'sqlite3'
49
+ end
50
+
51
+ platforms :jruby do
52
+ gem 'jruby-openssl'
53
+ gem 'activerecord-jdbcsqlite3-adapter'
51
54
  end
52
55
 
53
56
  If you're using Rails 2:
@@ -84,6 +87,21 @@ URL. Example:
84
87
  adapter: jdbc
85
88
  jndi: jdbc/mysqldb
86
89
 
90
+ If you're really old school you might want to use ARJDBC with a DB2 on z/OS.
91
+
92
+ development:
93
+ adapter: jdbc
94
+ encoding: unicode
95
+ url: jdbc:db2j:net://mightyzoshost:446/RAILS_DBT1
96
+ driver: com.ibm.db2.jcc.DB2Driver
97
+ schema: DB2XB12
98
+ database: RAILS_DB1
99
+ tablespace: TSDE911
100
+ lob_tablespaces:
101
+ first_table: TSDE912
102
+ username: scott
103
+ password: lion
104
+
87
105
  === Standalone, with ActiveRecord
88
106
 
89
107
  1. Install the gem with JRuby:
@@ -123,7 +141,7 @@ template. See the project for more information at the following URL:
123
141
 
124
142
  The source for activerecord-jdbc-adapter is available using git.
125
143
 
126
- git clone git://github.com/nicksieger/activerecord-jdbc-adapter.git
144
+ git clone git://github.com/jruby/activerecord-jdbc-adapter.git
127
145
 
128
146
  == Feedback
129
147
 
@@ -133,11 +151,9 @@ something's a bug, feel free to pre-report it on the mailing lists.
133
151
 
134
152
  == Project Info
135
153
 
136
- * Mailing Lists: http://kenai.com/projects/activerecord-jdbc/lists
137
- * Issues: http://kenai.com/jira/browse/ACTIVERECORD_JDBC
138
- * Source:
139
- git://github.com/nicksieger/activerecord-jdbc-adapter.git
140
- git://kenai.com/activerecord-jdbc~main
154
+ * Mailing Lists: http://jruby.org/community
155
+ * Issues: https://github.com/jruby/activerecord-jdbc-adapter/issues
156
+ * Source: git://github.com/jruby/activerecord-jdbc-adapter.git
141
157
 
142
158
  == Running AR-JDBC's Tests
143
159
 
data/Rakefile CHANGED
@@ -2,8 +2,57 @@ require 'rake/testtask'
2
2
  require 'rake/clean'
3
3
  CLEAN.include 'derby*', 'test.db.*','test/reports', 'test.sqlite3','lib/**/*.jar','manifest.mf', '*.log'
4
4
 
5
+ require 'bundler'
6
+ Bundler::GemHelper.install_tasks
7
+ require 'bundler/setup'
8
+
5
9
  task :default => [:java_compile, :test]
6
10
 
11
+ #ugh, bundler doesn't use tasks, so gotta hook up to both tasks.
12
+ task :build => :java_compile
13
+ task :install => :java_compile
14
+
15
+ ADAPTERS = %w[derby h2 hsqldb mssql mysql postgresql sqlite3].map {|a| "activerecord-jdbc#{a}-adapter" }
16
+ DRIVERS = %w[derby h2 hsqldb jtds mysql postgres sqlite3].map {|a| "jdbc-#{a}" }
17
+
18
+ def rake(args)
19
+ ruby "-S", "rake", *args
20
+ end
21
+
22
+ (ADAPTERS + DRIVERS).each do |adapter|
23
+ namespace adapter do
24
+
25
+ task :build do
26
+ Dir.chdir(adapter) do
27
+ rake "build"
28
+ end
29
+ cp FileList["#{adapter}/pkg/#{adapter}-*.gem"], "pkg"
30
+ end
31
+
32
+ # bundler handles install => build itself
33
+ task :install do
34
+ Dir.chdir(adapter) do
35
+ rake "install"
36
+ end
37
+ end
38
+
39
+ task :release do
40
+ Dir.chdir(adapter) do
41
+ rake "release"
42
+ end
43
+ end
44
+ end
45
+ end
46
+
47
+ desc "Build all adapters"
48
+ task "all:release" => ["release", *ADAPTERS.map { |f| "#{f}:release" }]
49
+
50
+ desc "Install all adapters"
51
+ task "all:install" => ["install", *ADAPTERS.map { |f| "#{f}:install" }]
52
+
53
+ desc "Release all adapters"
54
+ task "all:build" => ["build", *ADAPTERS.map { |f| "#{f}:build" }]
55
+
7
56
  task :filelist do
8
57
  puts FileList['pkg/**/*'].inspect
9
58
  end
@@ -0,0 +1,23 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require 'arjdbc/version'
4
+ version = ArJdbc::Version::VERSION
5
+ Gem::Specification.new do |s|
6
+ s.name = "activerecord-jdbc-adapter"
7
+ s.version = version
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ["Nick Sieger, Ola Bini and JRuby contributors"]
10
+ s.email = %q{nick@nicksieger.com, ola.bini@gmail.com}
11
+ s.homepage = %q{https://github.com/jruby/activerecord-jdbc-adapter}
12
+ s.summary = %q{JDBC adapter for ActiveRecord, for use within JRuby on Rails.}
13
+ s.description = %q{activerecord-jdbc-adapter is a database adapter for Rails\' ActiveRecord
14
+ component that can be used with JRuby[http://www.jruby.org/]. It allows use of
15
+ virtually any JDBC-compliant database with your JRuby on Rails application.}
16
+ s.files = `git ls-files`.split("\n").reject {|v| v =~ /^(activerecord-jdbc[^-]|jdbc-)/}
17
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
+ s.executables = `git ls-files -- bin/*`.split("\n").map{|f| File.basename(f) }
19
+ s.require_paths = ["lib"]
20
+ s.rdoc_options = ["--main", "README.txt", "-SHN", "-f", "darkfish"]
21
+ s.rubyforge_project = %q{jruby-extras}
22
+ end
23
+
@@ -0,0 +1,13 @@
1
+ require File.dirname(__FILE__) + '/bench_model'
2
+
3
+ puts "Widget.find(:first).attributes"
4
+ Benchmark.bm do |make|
5
+ TIMES.times do
6
+ w = Widget.find(:first)
7
+ make.report do
8
+ 10_000.times do
9
+ w.attributes # rails makes copy for every call
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,14 @@
1
+ require File.dirname(__FILE__) + '/bench_model'
2
+
3
+ puts "w = Widget.find(:first); Widget.new(w.attributes)"
4
+ Benchmark.bm do |make|
5
+ TIMES.times do
6
+ w = Widget.find(:first)
7
+ params = w.attributes
8
+ make.report do
9
+ 10_000.times do
10
+ Widget.new(params)
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,12 @@
1
+ require File.dirname(__FILE__) + '/bench_model'
2
+
3
+ puts "Widget.create"
4
+ Benchmark.bm do |make|
5
+ TIMES.times do
6
+ make.report do
7
+ 10_000.times do
8
+ Widget.create!(:name => "bench", :description => "Bench record")
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,12 @@
1
+ require File.dirname(__FILE__) + '/bench_model'
2
+
3
+ puts "Widget.find(:all)"
4
+ Benchmark.bm do |make|
5
+ TIMES.times do
6
+ make.report do
7
+ 10_000.times do
8
+ Widget.find(:all)
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,25 @@
1
+ require File.dirname(__FILE__) + '/bench_model'
2
+
3
+ Benchmark.bm do |make|
4
+ TIMES.times do
5
+ make.report do
6
+ thrs = []
7
+ errs = 0
8
+ 10.times do
9
+ thrs << Thread.new do
10
+ 1000.times do
11
+ begin
12
+ Widget.find(:all)
13
+ rescue Exception => e
14
+ errs += 1
15
+ Widget.logger.warn e.to_s
16
+ end
17
+ end
18
+ Widget.clear_active_connections!
19
+ end
20
+ end
21
+ thrs.each {|t| t.join}
22
+ puts "errors: #{errs}" if errs > 0
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,85 @@
1
+ =begin
2
+
3
+ * This scripts looks for an optional argv0 which is number of times to
4
+ execute the particular benchmark this file is getting required into. argv1
5
+ is an optional parameter which represents the number of rows to create.
6
+ * Use ENV['LOGGER'] (=severe|warn|info|debug) to turn on the logger
7
+ * Add ActiveRecord to load path to use a specific (non-gem version) for testing (e.g., edge).
8
+
9
+ +----------+------+-----+---------+-----------------+----------------+
10
+ | Field | Type | Null | Key | Default | Extra |
11
+ +-------------+--------------+------+-----+---------+----------------+
12
+ | id | int(11) | NO | PRI | NULL | auto_increment |
13
+ | name | varchar(255) | YES | | NULL | |
14
+ | description | text | YES | | NULL | |
15
+ | created_at | datetime | YES | | NULL | |
16
+ | updated_at | datetime | YES | | NULL | |
17
+ +-------------+--------------+------+-----+---------+----------------+
18
+ =end
19
+
20
+ TIMES = (ARGV[0] || 5).to_i
21
+ ROW_COUNT = (ARGV[1] || 10).to_i
22
+
23
+ ENV["RAILS_ENV"] = "production"
24
+ begin
25
+ print "Loading ActiveRecord w/o gems..."
26
+ require 'active_record'
27
+ require 'active_record/version'
28
+ puts "version #{ActiveRecord::VERSION::STRING}"
29
+ rescue LoadError
30
+ puts "FAILED."
31
+ print "Loading ActiveRecord with gems..."
32
+ require 'rubygems'
33
+ gem 'activerecord'
34
+ puts "version #{Gem.loaded_specs['activerecord'].version.version}"
35
+ require 'active_record'
36
+ end
37
+ require 'benchmark'
38
+
39
+ if defined?(RUBY_ENGINE) && RUBY_ENGINE == "jruby"
40
+ $LOAD_PATH.unshift File.dirname(__FILE__) + '/../lib'
41
+ $LOAD_PATH.unshift File.dirname(__FILE__) + '/../drivers/mysql/lib'
42
+ $LOAD_PATH.unshift File.dirname(__FILE__) + '/../adapters/mysql/lib'
43
+ require 'active_record/connection_adapters/jdbcmysql_adapter'
44
+ end
45
+
46
+ if ENV['LOGGER']
47
+ require 'logger'
48
+ ActiveRecord::Base.logger = Logger.new(File.expand_path(File.dirname(__FILE__) + "/debug.log"))
49
+ lvl = %(DEBUG INFO WARN ERROR FATAL).detect {|s| s =~ /#{ENV['LOGGER'].upcase}/}
50
+ ActiveRecord::Base.logger.level = lvl && Logger.const_get(lvl) || Logger::INFO
51
+ else
52
+ ActiveRecord::Base.logger = Logger.new($stdout)
53
+ ActiveRecord::Base.logger.level = Logger::UNKNOWN
54
+ end
55
+
56
+ ActiveRecord::Base.establish_connection(
57
+ :adapter => "mysql",
58
+ :host => "localhost",
59
+ :username => "root",
60
+ :database => "ar_bench",
61
+ :pool => 10,
62
+ :wait_timeout => 0.5
63
+ )
64
+
65
+ class CreateWidgets < ActiveRecord::Migration
66
+ def self.up
67
+ create_table :widgets do |t|
68
+ t.string :name
69
+ t.text :description
70
+ t.timestamps
71
+ end
72
+ end
73
+ end
74
+
75
+ CreateWidgets.up unless ActiveRecord::Base.connection.tables.include?("widgets")
76
+
77
+ class Widget < ActiveRecord::Base; end
78
+ Widget.destroy_all if Widget.count > ROW_COUNT
79
+ count = Widget.count
80
+ while (count < ROW_COUNT)
81
+ Widget.create!(:name => "bench#{count}", :description => "Bench record#{count}")
82
+ count = Widget.count
83
+ end
84
+
85
+ ActiveRecord::Base.clear_active_connections!