activerecord-jdbc-adapter 0.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (65) hide show
  1. data/History.txt +61 -0
  2. data/LICENSE +21 -0
  3. data/Manifest.txt +64 -0
  4. data/README.txt +116 -0
  5. data/Rakefile +146 -0
  6. data/lib/active_record/connection_adapters/derby_adapter.rb +13 -0
  7. data/lib/active_record/connection_adapters/h2_adapter.rb +1 -0
  8. data/lib/active_record/connection_adapters/hsqldb_adapter.rb +13 -0
  9. data/lib/active_record/connection_adapters/jdbc_adapter.rb +575 -0
  10. data/lib/active_record/connection_adapters/jdbc_adapter_spec.rb +10 -0
  11. data/lib/active_record/connection_adapters/jndi_adapter.rb +1 -0
  12. data/lib/active_record/connection_adapters/mysql_adapter.rb +13 -0
  13. data/lib/active_record/connection_adapters/oracle_adapter.rb +1 -0
  14. data/lib/active_record/connection_adapters/postgresql_adapter.rb +13 -0
  15. data/lib/jdbc_adapter.rb +32 -0
  16. data/lib/jdbc_adapter/jdbc_db2.rb +104 -0
  17. data/lib/jdbc_adapter/jdbc_derby.rb +362 -0
  18. data/lib/jdbc_adapter/jdbc_firebird.rb +109 -0
  19. data/lib/jdbc_adapter/jdbc_hsqldb.rb +168 -0
  20. data/lib/jdbc_adapter/jdbc_mimer.rb +134 -0
  21. data/lib/jdbc_adapter/jdbc_mssql.rb +356 -0
  22. data/lib/jdbc_adapter/jdbc_mysql.rb +168 -0
  23. data/lib/jdbc_adapter/jdbc_oracle.rb +340 -0
  24. data/lib/jdbc_adapter/jdbc_postgre.rb +347 -0
  25. data/lib/jdbc_adapter/missing_functionality_helper.rb +72 -0
  26. data/lib/jdbc_adapter/version.rb +5 -0
  27. data/lib/jdbc_adapter_internal.jar +0 -0
  28. data/lib/tasks/jdbc_databases.rake +72 -0
  29. data/src/java/JDBCDerbySpec.java +323 -0
  30. data/src/java/JDBCMySQLSpec.java +89 -0
  31. data/src/java/JdbcAdapterInternalService.java +953 -0
  32. data/test/activerecord/connection_adapters/type_conversion_test.rb +31 -0
  33. data/test/activerecord/connections/native_jdbc_mysql/connection.rb +25 -0
  34. data/test/db/derby.rb +18 -0
  35. data/test/db/h2.rb +11 -0
  36. data/test/db/hsqldb.rb +15 -0
  37. data/test/db/jdbc.rb +11 -0
  38. data/test/db/jndi_config.rb +30 -0
  39. data/test/db/logger.rb +3 -0
  40. data/test/db/mysql.rb +9 -0
  41. data/test/db/postgres.rb +9 -0
  42. data/test/derby_multibyte_test.rb +12 -0
  43. data/test/derby_simple_test.rb +12 -0
  44. data/test/generic_jdbc_connection_test.rb +9 -0
  45. data/test/h2_simple_test.rb +7 -0
  46. data/test/hsqldb_simple_test.rb +6 -0
  47. data/test/jdbc_adapter/jdbc_db2_test.rb +21 -0
  48. data/test/jdbc_common.rb +6 -0
  49. data/test/jndi_test.rb +37 -0
  50. data/test/manualTestDatabase.rb +195 -0
  51. data/test/minirunit.rb +109 -0
  52. data/test/minirunit/testConnect.rb +14 -0
  53. data/test/minirunit/testH2.rb +73 -0
  54. data/test/minirunit/testHsqldb.rb +73 -0
  55. data/test/minirunit/testLoadActiveRecord.rb +3 -0
  56. data/test/minirunit/testMysql.rb +83 -0
  57. data/test/minirunit/testRawSelect.rb +24 -0
  58. data/test/models/auto_id.rb +18 -0
  59. data/test/models/data_types.rb +18 -0
  60. data/test/models/entry.rb +20 -0
  61. data/test/mysql_multibyte_test.rb +6 -0
  62. data/test/mysql_simple_test.rb +13 -0
  63. data/test/postgres_simple_test.rb +12 -0
  64. data/test/simple.rb +157 -0
  65. metadata +112 -0
@@ -0,0 +1,109 @@
1
+
2
+ $silentTests = false
3
+ $testnum=0
4
+ $ntest=0
5
+ $failed = []
6
+ $curtestOK=true
7
+
8
+ module MiniRUnit
9
+ class Failure
10
+ def initialize(what, testnum, msg, where)
11
+ @what, @testnum, @msg, @where = what, testnum, msg, where
12
+ end
13
+
14
+ def to_s
15
+ sprintf("FAILED %s %d %s-- %s\n", @what, @testnum, @msg, @where)
16
+ end
17
+ end
18
+
19
+ class Error
20
+ def initialize(what, testnum, boom)
21
+ @what, @testnum, @boom = what, testnum, boom
22
+ end
23
+
24
+ def to_s
25
+ sprintf("EXCEPTION raised %s %d -- \n\tException: %s\n\t%s",
26
+ @what, @testnum, @boom.to_s, @boom.backtrace.join("\n\t"))
27
+ end
28
+ end
29
+ end
30
+
31
+
32
+ def test_check(what)
33
+ printf "%s : ", what unless $silentTests
34
+ $what = what
35
+ $testnum = 0
36
+ end
37
+
38
+ def test_ok(cond, msg="")
39
+ $testnum+=1
40
+ $ntest+=1
41
+ if cond
42
+ print "." unless $silentTests
43
+ else
44
+ where = caller.reject {|where| where =~ /minirunit/}[0]
45
+ $failed.push(MiniRUnit::Failure.new($what, $testnum, msg, where))
46
+ print "F" unless $silentTests
47
+ $curtestOK=false
48
+ end
49
+ end
50
+
51
+ def test_fail(msg="")
52
+ test_ok(false, msg)
53
+ end
54
+
55
+ def test_equal(a,b)
56
+ test_ok(a == b, "expected #{a.inspect}, found #{b.inspect}")
57
+ end
58
+
59
+ def test_no_exception(&proc)
60
+ raised = false
61
+ begin
62
+ proc.call
63
+ rescue exception
64
+ raised = x
65
+ end
66
+ test_ok(!raised, "unexpected exception #{raised}")
67
+ end
68
+
69
+ def test_exception(type=Exception, &proc)
70
+ raised = false
71
+ begin
72
+ proc.call
73
+ rescue type=>e
74
+ raised = true
75
+ end
76
+ test_ok(raised, "#{type} expected")
77
+ e
78
+ end
79
+
80
+ def test_get_last_failed
81
+ if $failed.empty?
82
+ return nil
83
+ end
84
+ return $failed.last
85
+ end
86
+
87
+ def test_print_report
88
+ puts
89
+ puts "-" * 80
90
+ $failed.each { |error| puts error }
91
+ puts "-" * 80
92
+ puts "Tests: #$ntest. (Ok: #{$ntest - $failed.size}; Failed: #{$failed.size})"
93
+ end
94
+
95
+ def test_load(test)
96
+ begin
97
+ $curtestOK=true
98
+ load(test)
99
+ rescue Exception => boom
100
+ puts 'ERROR' unless $silentTests
101
+ $failed.push(MiniRUnit::Error.new($what, $testnum, boom))
102
+ else
103
+ if $curtestOK
104
+ puts 'OK' unless $silentTests
105
+ else
106
+ puts 'FAILED' unless $silentTests
107
+ end
108
+ end
109
+ end
@@ -0,0 +1,14 @@
1
+ require 'test/minirunit'
2
+ RAILS_CONNECTION_ADAPTERS = ['abstract', 'jdbc']
3
+ require 'active_record'
4
+
5
+ connspec = ActiveRecord::Base.establish_connection(
6
+ :adapter => 'jdbc',
7
+ :driver => 'com.mysql.jdbc.Driver',
8
+ :url => 'jdbc:mysql://localhost:3306/test',
9
+ :username => 'rlsmgr',
10
+ :password => ''
11
+ )
12
+
13
+ puts "#{connspec}"
14
+ puts "#{ActiveRecord::Base.connection}"
@@ -0,0 +1,73 @@
1
+
2
+ require 'minirunit'
3
+
4
+ config = {
5
+ :adapter => 'jdbc',
6
+ :username => 'sa',
7
+ :password => '',
8
+ :driver => 'org.h2.Driver',
9
+ :url => 'jdbc:h2:test.db'
10
+ }
11
+ RAILS_CONNECTION_ADAPTERS = ['abstract', 'jdbc']
12
+
13
+ require 'active_record'
14
+
15
+ ActiveRecord::Base.establish_connection(config)
16
+ require 'logger'
17
+ ActiveRecord::Base.logger = Logger.new($stdout)
18
+ ActiveRecord::Base.logger.level = Logger::DEBUG
19
+
20
+ class CreateEntries < ActiveRecord::Migration
21
+ def self.up
22
+ create_table "entries", :force => true do |t|
23
+ t.column :title, :string, :limit => 100
24
+ t.column :updated_on, :datetime
25
+ t.column :content, :text
26
+ end
27
+ end
28
+
29
+ def self.down
30
+ drop_table "entries"
31
+ end
32
+ end
33
+
34
+ CreateEntries.up
35
+
36
+ test_ok ActiveRecord::Base.connection.tables.include?('entries')
37
+
38
+ class Entry < ActiveRecord::Base
39
+ end
40
+
41
+ Entry.delete_all
42
+
43
+ test_equal 0, Entry.count
44
+
45
+ TITLE = "First post!"
46
+ CONTENT = "Hello from JRuby on Rails!"
47
+ NEW_TITLE = "First post updated title"
48
+
49
+ post = Entry.new
50
+ post.title = TITLE
51
+ post.content = CONTENT
52
+ post.save
53
+
54
+ test_equal 1, Entry.count
55
+
56
+ post = Entry.find(:first)
57
+ test_equal TITLE, post.title
58
+ test_equal CONTENT, post.content
59
+
60
+ post.title = NEW_TITLE
61
+ post.save
62
+
63
+ post = Entry.find(:first)
64
+ test_equal NEW_TITLE, post.title
65
+
66
+ post.destroy
67
+
68
+ test_equal 0, Entry.count
69
+
70
+ CreateEntries.down
71
+
72
+ # Clean up hsqldb when done
73
+ Dir['test.db*'].each {|f| File.delete(f)}
@@ -0,0 +1,73 @@
1
+
2
+ require 'minirunit'
3
+
4
+ config = {
5
+ :adapter => 'jdbc',
6
+ :username => 'sa',
7
+ :password => '',
8
+ :driver => 'org.hsqldb.jdbcDriver',
9
+ :url => 'jdbc:hsqldb:test.db'
10
+ }
11
+ RAILS_CONNECTION_ADAPTERS = ['abstract', 'jdbc']
12
+
13
+ require 'active_record'
14
+
15
+ ActiveRecord::Base.establish_connection(config)
16
+ require 'logger'
17
+ ActiveRecord::Base.logger = Logger.new($stdout)
18
+ ActiveRecord::Base.logger.level = Logger::DEBUG
19
+
20
+ class CreateEntries < ActiveRecord::Migration
21
+ def self.up
22
+ create_table "entries", :force => true do |t|
23
+ t.column :title, :string, :limit => 100
24
+ t.column :updated_on, :datetime
25
+ t.column :content, :text
26
+ end
27
+ end
28
+
29
+ def self.down
30
+ drop_table "entries"
31
+ end
32
+ end
33
+
34
+ CreateEntries.up
35
+
36
+ test_ok ActiveRecord::Base.connection.tables.include?('entries')
37
+
38
+ class Entry < ActiveRecord::Base
39
+ end
40
+
41
+ Entry.delete_all
42
+
43
+ test_equal 0, Entry.count
44
+
45
+ TITLE = "First post!"
46
+ CONTENT = "Hello from JRuby on Rails!"
47
+ NEW_TITLE = "First post updated title"
48
+
49
+ post = Entry.new
50
+ post.title = TITLE
51
+ post.content = CONTENT
52
+ post.save
53
+
54
+ test_equal 1, Entry.count
55
+
56
+ post = Entry.find(:first)
57
+ test_equal TITLE, post.title
58
+ test_equal CONTENT, post.content
59
+
60
+ post.title = NEW_TITLE
61
+ post.save
62
+
63
+ post = Entry.find(:first)
64
+ test_equal NEW_TITLE, post.title
65
+
66
+ post.destroy
67
+
68
+ test_equal 0, Entry.count
69
+
70
+ CreateEntries.down
71
+
72
+ # Clean up hsqldb when done
73
+ Dir['test.db*'].each {|f| File.delete(f)}
@@ -0,0 +1,3 @@
1
+ require 'test/minirunit'
2
+ RAILS_CONNECTION_ADAPTERS = ['abstract']
3
+ test_load 'active_record'
@@ -0,0 +1,83 @@
1
+ # To run this script, run the following in a mysql instance:
2
+ #
3
+ # drop database if exists weblog_development;
4
+ # create database weblog_development;
5
+ # grant all on weblog_development.* to blog@localhost;
6
+
7
+ require 'minirunit'
8
+
9
+ config = {
10
+ :username => 'blog',
11
+ :password => ''
12
+ }
13
+
14
+ if RUBY_PLATFORM =~ /java/
15
+ RAILS_CONNECTION_ADAPTERS = ['abstract', 'jdbc']
16
+ config.update({
17
+ :adapter => 'jdbc',
18
+ :driver => 'com.mysql.jdbc.Driver',
19
+ :url => 'jdbc:mysql://localhost:3306/weblog_development',
20
+ })
21
+ else
22
+ config.update({
23
+ :adapter => 'mysql',
24
+ :database => 'weblog_development',
25
+ :host => 'localhost'
26
+ })
27
+ end
28
+
29
+ require 'active_record'
30
+
31
+ ActiveRecord::Base.establish_connection(config)
32
+
33
+ class CreateEntries < ActiveRecord::Migration
34
+ def self.up
35
+ create_table "entries", :force => true do |t|
36
+ t.column :title, :string, :limit => 100
37
+ t.column :updated_on, :datetime
38
+ t.column :content, :text
39
+ end
40
+ end
41
+
42
+ def self.down
43
+ drop_table "entries"
44
+ end
45
+ end
46
+
47
+ CreateEntries.up
48
+
49
+ test_ok ActiveRecord::Base.connection.tables.include?('entries')
50
+
51
+ class Entry < ActiveRecord::Base
52
+ end
53
+
54
+ Entry.delete_all
55
+
56
+ test_equal 0, Entry.count
57
+
58
+ TITLE = "First post!"
59
+ CONTENT = "Hello from JRuby on Rails!"
60
+ NEW_TITLE = "First post updated title"
61
+
62
+ post = Entry.new
63
+ post.title = TITLE
64
+ post.content = CONTENT
65
+ post.save
66
+
67
+ test_equal 1, Entry.count
68
+
69
+ post = Entry.find(:first)
70
+ test_equal TITLE, post.title
71
+ test_equal CONTENT, post.content
72
+
73
+ post.title = NEW_TITLE
74
+ post.save
75
+
76
+ post = Entry.find(:first)
77
+ test_equal NEW_TITLE, post.title
78
+
79
+ post.destroy
80
+
81
+ test_equal 0, Entry.count
82
+
83
+ CreateEntries.down
@@ -0,0 +1,24 @@
1
+
2
+ require 'test/minirunit'
3
+ RAILS_CONNECTION_ADAPTERS = ['abstract', 'jdbc']
4
+ require 'active_record'
5
+
6
+ connspec = ActiveRecord::Base.establish_connection(
7
+ :adapter => 'jdbc',
8
+ :driver => 'com.mysql.jdbc.Driver',
9
+ :url => 'jdbc:mysql://localhost:3306/weblog_development',
10
+ :username => 'blog',
11
+ :password => ''
12
+ )
13
+
14
+ connection = ActiveRecord::Base.connection
15
+
16
+ results = connection.execute "select * from entries"
17
+
18
+ test_equal results.length, 1
19
+
20
+ row = results.first
21
+ test_equal 'First post', row['title']
22
+ test_equal 'First post d00d!', row['content']
23
+
24
+ puts row.inspect
@@ -0,0 +1,18 @@
1
+ require 'rubygems'
2
+ require 'active_record'
3
+
4
+ class CreateAutoIds < ActiveRecord::Migration
5
+ def self.up
6
+ create_table "auto_ids", :force => true do |t|
7
+ t.column :value, :integer
8
+ end
9
+ end
10
+
11
+ def self.down
12
+ drop_table "auto_ids"
13
+ end
14
+ end
15
+
16
+ class AutoId < ActiveRecord::Base
17
+ def self.table_name () "auto_ids" end
18
+ end
@@ -0,0 +1,18 @@
1
+ require 'rubygems'
2
+ require 'active_record'
3
+
4
+ class DbTypeMigration < ActiveRecord::Migration
5
+ def self.up
6
+ create_table "db_types", :force => true do |t|
7
+ t.column :sample_timestamp, :timestamp
8
+ t.column :sample_decimal, :decimal, :precision=> 15, :scale => 0
9
+ end
10
+ end
11
+
12
+ def self.down
13
+ drop_table "db_types"
14
+ end
15
+ end
16
+
17
+ class DbType < ActiveRecord::Base
18
+ end
@@ -0,0 +1,20 @@
1
+ require 'rubygems'
2
+ require 'active_record'
3
+
4
+ class CreateEntries < ActiveRecord::Migration
5
+ def self.up
6
+ create_table "entries", :force => true do |t|
7
+ t.column :title, :string, :limit => 100
8
+ t.column :updated_on, :datetime
9
+ t.column :content, :text
10
+ t.column :rating, :decimal, :precision => 10
11
+ end
12
+ end
13
+
14
+ def self.down
15
+ drop_table "entries"
16
+ end
17
+ end
18
+
19
+ class Entry < ActiveRecord::Base
20
+ end