activerecord-jdbc-adapter 1.2.5 → 1.2.8

Sign up to get free protection for your applications and to get access to all the features.
Files changed (155) hide show
  1. data/.gitignore +1 -0
  2. data/.travis.yml +5 -1
  3. data/Appraisals +5 -5
  4. data/Gemfile +9 -1
  5. data/Gemfile.lock +44 -10
  6. data/History.txt +126 -2
  7. data/README.md +246 -0
  8. data/Rakefile +34 -25
  9. data/activerecord-jdbc-adapter.gemspec +1 -1
  10. data/gemfiles/rails23.gemfile +5 -3
  11. data/gemfiles/rails23.gemfile.lock +26 -18
  12. data/gemfiles/rails30.gemfile +4 -2
  13. data/gemfiles/rails30.gemfile.lock +16 -8
  14. data/gemfiles/rails31.gemfile +4 -2
  15. data/gemfiles/rails31.gemfile.lock +16 -9
  16. data/gemfiles/rails32.gemfile +4 -2
  17. data/gemfiles/rails32.gemfile.lock +15 -8
  18. data/lib/active_record/connection_adapters/db2_adapter.rb +1 -0
  19. data/lib/arel/visitors/sql_server.rb +3 -0
  20. data/lib/arjdbc.rb +3 -5
  21. data/lib/arjdbc/db2.rb +1 -0
  22. data/lib/arjdbc/db2/adapter.rb +302 -196
  23. data/lib/arjdbc/db2/connection_methods.rb +18 -0
  24. data/lib/arjdbc/derby/active_record_patch.rb +12 -0
  25. data/lib/arjdbc/derby/adapter.rb +180 -158
  26. data/lib/arjdbc/derby/connection_methods.rb +5 -1
  27. data/lib/arjdbc/firebird/adapter.rb +27 -19
  28. data/lib/arjdbc/h2/adapter.rb +162 -7
  29. data/lib/arjdbc/h2/connection_methods.rb +5 -1
  30. data/lib/arjdbc/hsqldb.rb +1 -1
  31. data/lib/arjdbc/hsqldb/adapter.rb +96 -61
  32. data/lib/arjdbc/hsqldb/connection_methods.rb +5 -1
  33. data/lib/arjdbc/hsqldb/explain_support.rb +35 -0
  34. data/lib/arjdbc/informix/adapter.rb +56 -55
  35. data/lib/arjdbc/jdbc/adapter.rb +173 -86
  36. data/lib/arjdbc/jdbc/adapter_java.jar +0 -0
  37. data/lib/arjdbc/jdbc/column.rb +28 -23
  38. data/lib/arjdbc/jdbc/connection.rb +10 -6
  39. data/lib/arjdbc/jdbc/driver.rb +13 -5
  40. data/lib/arjdbc/jdbc/serialized_attributes_helper.rb +21 -0
  41. data/lib/arjdbc/mssql.rb +1 -1
  42. data/lib/arjdbc/mssql/adapter.rb +51 -53
  43. data/lib/arjdbc/mssql/connection_methods.rb +8 -1
  44. data/lib/arjdbc/mysql.rb +1 -1
  45. data/lib/arjdbc/mysql/adapter.rb +186 -150
  46. data/lib/arjdbc/mysql/connection_methods.rb +9 -9
  47. data/lib/arjdbc/mysql/explain_support.rb +85 -0
  48. data/lib/arjdbc/oracle.rb +1 -1
  49. data/lib/arjdbc/oracle/adapter.rb +232 -125
  50. data/lib/arjdbc/oracle/connection_methods.rb +2 -2
  51. data/lib/arjdbc/postgresql.rb +1 -1
  52. data/lib/arjdbc/postgresql/adapter.rb +134 -86
  53. data/lib/arjdbc/postgresql/connection_methods.rb +6 -4
  54. data/lib/arjdbc/postgresql/explain_support.rb +55 -0
  55. data/lib/arjdbc/sqlite3.rb +1 -1
  56. data/lib/arjdbc/sqlite3/adapter.rb +176 -108
  57. data/lib/arjdbc/sqlite3/connection_methods.rb +5 -5
  58. data/lib/arjdbc/sqlite3/explain_support.rb +32 -0
  59. data/lib/arjdbc/sybase/adapter.rb +7 -6
  60. data/lib/arjdbc/version.rb +1 -1
  61. data/pom.xml +1 -1
  62. data/rakelib/02-test.rake +9 -11
  63. data/rakelib/rails.rake +18 -10
  64. data/src/java/arjdbc/db2/DB2Module.java +70 -0
  65. data/src/java/arjdbc/derby/DerbyModule.java +24 -5
  66. data/src/java/arjdbc/hsqldb/HSQLDBModule.java +66 -0
  67. data/src/java/arjdbc/jdbc/AdapterJavaService.java +14 -7
  68. data/src/java/arjdbc/jdbc/RubyJdbcConnection.java +111 -89
  69. data/src/java/arjdbc/mysql/MySQLModule.java +79 -70
  70. data/src/java/arjdbc/oracle/OracleModule.java +74 -0
  71. data/src/java/arjdbc/oracle/OracleRubyJdbcConnection.java +5 -10
  72. data/src/java/arjdbc/sqlite3/SQLite3Module.java +77 -0
  73. data/src/java/arjdbc/sqlite3/SQLite3RubyJdbcConnection.java +127 -0
  74. data/src/java/arjdbc/sqlite3/Sqlite3RubyJdbcConnection.java +25 -111
  75. data/src/java/arjdbc/util/QuotingUtils.java +104 -0
  76. data/test/abstract_db_create.rb +6 -6
  77. data/test/activerecord/connection_adapters/type_conversion_test.rb +2 -2
  78. data/test/assets/flowers.jpg +0 -0
  79. data/test/binary.rb +67 -0
  80. data/test/db/db2.rb +30 -7
  81. data/test/db/jdbc.rb +4 -2
  82. data/test/db/oracle.rb +18 -27
  83. data/test/db2_binary_test.rb +6 -0
  84. data/test/db2_serialize_test.rb +6 -0
  85. data/test/db2_simple_test.rb +20 -25
  86. data/test/db2_test.rb +71 -0
  87. data/test/derby_binary_test.rb +6 -0
  88. data/test/derby_migration_test.rb +42 -35
  89. data/test/derby_reset_column_information_test.rb +1 -0
  90. data/test/derby_row_locking_test.rb +17 -0
  91. data/test/derby_schema_dump_test.rb +9 -0
  92. data/test/derby_serialize_test.rb +6 -0
  93. data/test/derby_simple_test.rb +59 -17
  94. data/test/generic_jdbc_connection_test.rb +112 -5
  95. data/test/h2_binary_test.rb +6 -0
  96. data/test/h2_change_column_test.rb +1 -1
  97. data/test/h2_schema_dump_test.rb +25 -0
  98. data/test/h2_serialize_test.rb +6 -0
  99. data/test/h2_simple_test.rb +23 -9
  100. data/test/has_many_through.rb +18 -4
  101. data/test/hsqldb_binary_test.rb +6 -0
  102. data/test/hsqldb_schema_dump_test.rb +15 -0
  103. data/test/hsqldb_serialize_test.rb +6 -0
  104. data/test/hsqldb_simple_test.rb +1 -0
  105. data/test/informix_simple_test.rb +1 -1
  106. data/test/jdbc/db2.rb +23 -0
  107. data/test/jdbc/oracle.rb +23 -0
  108. data/test/jdbc_common.rb +3 -110
  109. data/test/jndi_callbacks_test.rb +0 -2
  110. data/test/jndi_test.rb +2 -0
  111. data/test/models/binary.rb +18 -0
  112. data/test/models/custom_pk_name.rb +1 -0
  113. data/test/models/data_types.rb +11 -2
  114. data/test/models/entry.rb +1 -1
  115. data/test/models/string_id.rb +2 -2
  116. data/test/models/thing.rb +1 -1
  117. data/test/models/topic.rb +32 -0
  118. data/test/mssql_legacy_types_test.rb +1 -1
  119. data/test/mssql_limit_offset_test.rb +13 -3
  120. data/test/mssql_serialize_test.rb +6 -0
  121. data/test/mysql_binary_test.rb +6 -0
  122. data/test/mysql_schema_dump_test.rb +220 -0
  123. data/test/mysql_serialize_test.rb +6 -0
  124. data/test/mysql_simple_test.rb +22 -2
  125. data/test/mysql_test.rb +93 -0
  126. data/test/oracle_binary_test.rb +6 -0
  127. data/test/oracle_limit_test.rb +2 -1
  128. data/test/oracle_serialize_test.rb +6 -0
  129. data/test/oracle_simple_test.rb +61 -0
  130. data/test/oracle_specific_test.rb +77 -26
  131. data/test/postgres_binary_test.rb +6 -0
  132. data/test/postgres_native_type_mapping_test.rb +12 -11
  133. data/test/postgres_nonseq_pkey_test.rb +1 -0
  134. data/test/postgres_reserved_test.rb +1 -0
  135. data/test/postgres_reset_column_information_test.rb +1 -0
  136. data/test/postgres_row_locking_test.rb +21 -0
  137. data/test/postgres_schema_dump_test.rb +88 -0
  138. data/test/postgres_schema_search_path_test.rb +1 -0
  139. data/test/postgres_simple_test.rb +62 -89
  140. data/test/postgres_table_alias_length_test.rb +1 -0
  141. data/test/postgres_test.rb +31 -0
  142. data/test/postgres_type_conversion_test.rb +16 -16
  143. data/test/row_locking.rb +69 -64
  144. data/test/schema_dump.rb +168 -0
  145. data/test/serialize.rb +277 -0
  146. data/test/simple.rb +326 -122
  147. data/test/sqlite3_serialize_test.rb +6 -0
  148. data/test/sqlite3_simple_test.rb +51 -84
  149. data/test/sqlite3_type_conversion_test.rb +101 -0
  150. data/test/test_helper.rb +224 -0
  151. metadata +325 -366
  152. data/README.rdoc +0 -214
  153. data/test/db/logger.rb +0 -3
  154. data/test/derby_multibyte_test.rb +0 -11
  155. data/test/mysql_info_test.rb +0 -123
@@ -1,214 +0,0 @@
1
- = Activerecord-jdbc-adapter
2
-
3
- activerecord-jdbc-adapter is a database adapter for Rails' ActiveRecord
4
- component that can be used with JRuby[http://www.jruby.org/]. It allows use of
5
- virtually any JDBC-compliant database with your JRuby on Rails application.
6
-
7
- == Databases
8
-
9
- Activerecord-jdbc-adapter provides full or nearly full support for:
10
- MySQL, PostgreSQL, SQLite3, Oracle, Microsoft SQL Server, DB2,
11
- FireBird, Derby, HSQLDB, H2, and Informix.
12
-
13
- Other databases will require testing and likely a custom configuration module.
14
- Please join the JRuby {mailing list}[http://jruby.org/community] to help us
15
- discover support for more databases.
16
-
17
- == Using ActiveRecord JDBC
18
-
19
- === Inside Rails
20
-
21
- To use activerecord-jdbc-adapter with JRuby on Rails:
22
-
23
- 1. Choose the adapter you wish to gem install. The following pre-packaged
24
- adapters are available:
25
-
26
- - base jdbc (activerecord-jdbc-adapter). Supports all available databases via
27
- JDBC, but requires you to download and manually install the database vendor's
28
- JDBC driver .jar file.
29
- - mysql (activerecord-jdbcmysql-adapter)
30
- - postgresql (activerecord-jdbcpostgresql-adapter)
31
- - sqlite3 (activerecord-jdbcsqlite3-adapter)
32
- - derby (activerecord-jdbcderby-adapter)
33
- - hsqldb (activerecord-jdbchsqldb-adapter)
34
- - h2 (activerecord-jdbch2-adapter)
35
- - mssql (activerecord-jdbcmssql-adapter). Does not support SQL Azure by default,
36
- see the {project's readme}[https://github.com/jruby/activerecord-jdbc-adapter/blob/master/activerecord-jdbcmssql-adapter/README.rdoc]
37
- for more information.
38
-
39
- 2a. For Rails 3, if you're generating a new application, use the
40
- following command to generate your application:
41
-
42
- jruby -S rails new sweetapp
43
-
44
- 2b. Otherwise, you'll need to perform some extra configuration steps
45
- to prepare your Rails application for JDBC.
46
-
47
- If you're using Rails 3, you'll need to modify your Gemfile to use the
48
- activerecord-jdbc-adapter gem under JRuby. Change your Gemfile to look
49
- like the following (using sqlite3 as an example):
50
-
51
- platforms :ruby do
52
- gem 'sqlite3'
53
- end
54
-
55
- platforms :jruby do
56
- gem 'jruby-openssl'
57
- gem 'activerecord-jdbcsqlite3-adapter'
58
- end
59
-
60
- If you're using Rails 2:
61
-
62
- jruby script/generate jdbc
63
-
64
- 3. Configure your database.yml in the normal Rails style.
65
-
66
- Legacy configuration: If you use one of the convenience
67
- 'activerecord-jdbcXXX-adapter' adapters, you can still put a 'jdbc'
68
- prefix in front of the database adapter name as below.
69
-
70
- development:
71
- adapter: jdbcmysql
72
- username: blog
73
- password:
74
- host: localhost
75
- database: weblog_development
76
-
77
- For other databases, you'll need to know the database driver class and
78
- URL. Example:
79
-
80
- development:
81
- adapter: jdbc
82
- username: blog
83
- password:
84
- driver: com.mysql.jdbc.Driver
85
- url: jdbc:mysql://localhost:3306/weblog_development
86
-
87
- For JNDI data sources, you may simply specify the JNDI location as follows
88
- (the adapter will be automatically detected):
89
-
90
- production:
91
- adapter: jdbc
92
- jndi: jdbc/mysqldb
93
-
94
- If you're really old school you might want to use ARJDBC with a DB2 on z/OS.
95
-
96
- development:
97
- adapter: jdbc
98
- encoding: unicode
99
- url: jdbc:db2j:net://mightyzoshost:446/RAILS_DBT1
100
- driver: com.ibm.db2.jcc.DB2Driver
101
- schema: DB2XB12
102
- database: RAILS_DB1
103
- tablespace: TSDE911
104
- lob_tablespaces:
105
- first_table: TSDE912
106
- username: scott
107
- password: lion
108
-
109
- === Standalone, with ActiveRecord
110
-
111
- 1. Install the gem with JRuby:
112
-
113
- jruby -S gem install activerecord-jdbc-adapter
114
-
115
- If you wish to use the adapter for a specific database, you can
116
- install it directly and a driver gem will be installed as well:
117
-
118
- jruby -S gem install activerecord-jdbcderby-adapter
119
-
120
- 2. After this you can establish a JDBC connection like this:
121
-
122
- ActiveRecord::Base.establish_connection(
123
- :adapter => 'jdbcderby',
124
- :database => "db/my-database"
125
- )
126
-
127
- or like this (but requires that you manually put the driver jar on the classpath):
128
-
129
- ActiveRecord::Base.establish_connection(
130
- :adapter => 'jdbc',
131
- :driver => 'org.apache.derby.jdbc.EmbeddedDriver',
132
- :url => 'jdbc:derby:test_ar;create=true'
133
- )
134
-
135
- == Extending AR-JDBC
136
-
137
- You can create your own extension to AR-JDBC for a JDBC-based database
138
- that core AR-JDBC does not support. We've created an example project
139
- for the Intersystems Cache database that you can examine as a
140
- template. See the project for more information at the following URL:
141
-
142
- http://github.com/nicksieger/activerecord-cachedb-adapter
143
-
144
- == Getting the source
145
-
146
- The source for activerecord-jdbc-adapter is available using git.
147
-
148
- git clone git://github.com/jruby/activerecord-jdbc-adapter.git
149
-
150
- == Feedback
151
-
152
- Please file bug reports at
153
- http://kenai.com/jira/browse/ACTIVERECORD_JDBC. If you're not sure if
154
- something's a bug, feel free to pre-report it on the mailing lists.
155
-
156
- == Project Info
157
-
158
- * Mailing Lists: http://jruby.org/community
159
- * Issues: https://github.com/jruby/activerecord-jdbc-adapter/issues
160
- * Source: git://github.com/jruby/activerecord-jdbc-adapter.git
161
-
162
- == Running AR-JDBC's Tests
163
-
164
- Drivers for 6 open-source databases are included. Provided you have
165
- MySQL installed, you can simply type <tt>jruby -S rake</tt> to run the
166
- tests. A database named <tt>weblog_development</tt> is needed
167
- beforehand with a connection user of "blog" and an empty password. You
168
- alse need to grant "blog" create privileges on
169
- 'test_rake_db_create.*'.
170
-
171
- If you also have PostgreSQL available, those tests will be run if the
172
- `psql' executable can be found. Also ensure you have a database named
173
- <tt>weblog_development</tt> and a user named "blog" and an empty
174
- password. You can control the host and port the tests will attempt to
175
- by setting the environment variables PGHOST and PGPORT.
176
-
177
- If you want rails logging enabled during these test runs you can edit
178
- test/jdbc_common.rb and add the following line:
179
-
180
- require 'db/logger'
181
-
182
- To execute a single test case, you can run:
183
-
184
- rake appraisal:{version} test_{db} TEST=test/{tests file}
185
-
186
- Substitute the version of ActiveRecord for version, which can be one of:
187
- rails23, rails30, rails31, or rails32
188
- The db can be one of these:
189
- mssql, mysql, oracle, postgres, sybase, sqlite3, db2, derby, h2
190
- Finally, the tests file will be whichever test case you want to run.
191
-
192
- == Running AR Tests
193
-
194
- To run the current AR-JDBC sources with ActiveRecord, just use the
195
- included "rails:test" task. Be sure to specify a driver and a path to
196
- the ActiveRecord sources.
197
-
198
- jruby -S rake rails:test DRIVER=mysql RAILS=/path/activerecord_source_dir
199
-
200
- == Travis Build Status {<img src="https://secure.travis-ci.org/jruby/activerecord-jdbc-adapter.png"/>}[http://travis-ci.org/#!/jruby/activerecord-jdbc-adapter]
201
-
202
- == Authors
203
-
204
- This project was written by Nick Sieger <nick@nicksieger.com> and Ola Bini
205
- <olabini@gmail.com> with lots of help from the JRuby community.
206
-
207
- == License
208
-
209
- activerecord-jdbc-adapter is released under a BSD license. See the LICENSE.txt
210
- file included with the distribution for details.
211
-
212
- Open-source driver gems for activerecord-jdbc-adapter are licensed under the
213
- same license the database's drivers are licensed. See each driver gem's
214
- LICENSE.txt file for details.
@@ -1,3 +0,0 @@
1
- require 'logger'
2
- ActiveRecord::Base.logger = Logger.new($stdout)
3
- ActiveRecord::Base.logger.level = $DEBUG || ENV['DEBUG'] ? Logger::DEBUG : Logger::WARN
@@ -1,11 +0,0 @@
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 'jdbc_common'
8
-
9
- class DerbyMultibyteTest < Test::Unit::TestCase
10
- include MultibyteTestMethods
11
- end
@@ -1,123 +0,0 @@
1
- require 'jdbc_common'
2
- require 'db/mysql'
3
- begin; require 'active_support/core_ext/numeric/bytes'; rescue LoadError; end
4
-
5
- class DBSetup < ActiveRecord::Migration
6
-
7
- def self.up
8
- create_table :books do |t|
9
- t.string :title
10
- t.timestamps
11
- end
12
-
13
- create_table :cars, :primary_key => 'legacy_id' do |t|
14
- t.string :name
15
- t.date :production_started_on
16
- end
17
-
18
- create_table :cats, :id => false do |t|
19
- t.string :name
20
- end
21
-
22
- create_table :memos do |t|
23
- t.text :text, :limit => 16.megabytes
24
- end
25
- end
26
-
27
- def self.down
28
- drop_table :books
29
- drop_table :cars
30
- drop_table :cats
31
- drop_table :memos
32
- end
33
-
34
- end
35
-
36
- class MysqlInfoTest < Test::Unit::TestCase
37
-
38
- def setup
39
- DBSetup.up
40
- @connection = ActiveRecord::Base.connection
41
- end
42
-
43
- def teardown
44
- DBSetup.down
45
- end
46
-
47
- ## primary_key
48
- def test_should_return_the_primary_key_of_a_table
49
- assert_equal 'id', @connection.primary_key('books')
50
- end
51
-
52
- def test_should_be_able_to_return_a_custom_primary_key
53
- assert_equal 'legacy_id', @connection.primary_key('cars')
54
- end
55
-
56
- def test_should_return_nil_for_a_table_without_a_primary_key
57
- assert_nil @connection.primary_key('cats')
58
- end
59
-
60
- ## structure_dump
61
- def test_should_include_the_tables_in_a_structure_dump
62
- # TODO: Improve these tests, I added this one because no other tests exists for this method.
63
- dump = @connection.structure_dump
64
- assert dump.include?('CREATE TABLE `books`')
65
- assert dump.include?('CREATE TABLE `cars`')
66
- assert dump.include?('CREATE TABLE `cats`')
67
- assert dump.include?('CREATE TABLE `memos`')
68
- end
69
-
70
- def test_should_include_longtext_in_schema_dump
71
- strio = StringIO.new
72
- ActiveRecord::SchemaDumper::dump(@connection, strio)
73
- dump = strio.string
74
- assert_match %r{t.text\s+"text",\s+:limit => 2147483647$}, dump
75
- end
76
-
77
- # JRUBY-5040
78
- def test_schema_dump_should_not_have_limits_on_datetime
79
- strio = StringIO.new
80
- ActiveRecord::SchemaDumper::dump(@connection, strio)
81
- dump = strio.string
82
- dump.lines.grep(/datetime/).each {|line| assert line !~ /limit/ }
83
- end
84
-
85
- def test_schema_dump_should_not_have_limits_on_date
86
- strio = StringIO.new
87
- ActiveRecord::SchemaDumper::dump(@connection, strio)
88
- dump = strio.string
89
- dump.lines.grep(/date/).each {|line| assert line !~ /limit/ }
90
- end
91
-
92
- def test_should_include_limit
93
- text_column = @connection.columns('memos').find { |c| c.name == 'text' }
94
- assert_equal 2147483647, text_column.limit
95
- end
96
-
97
- def test_should_set_sqltype_to_longtext
98
- text_column = @connection.columns('memos').find { |c| c.name == 'text' }
99
- assert text_column.sql_type =~ /^longtext/i
100
- end
101
-
102
- def test_should_set_type_to_text
103
- text_column = @connection.columns('memos').find { |c| c.name == 'text' }
104
- assert_equal :text, text_column.type
105
- end
106
-
107
- def test_verify_url_has_options
108
- url = @connection.config[:url]
109
- assert url =~ /characterEncoding=utf8/
110
- assert url =~ /useUnicode=true/
111
- assert url =~ /zeroDateTimeBehavior=convertToNull/
112
- end
113
-
114
- def test_no_limits_for_some_data_types
115
- DbTypeMigration.up
116
- strio = StringIO.new
117
- ActiveRecord::SchemaDumper.dump(@connection, strio)
118
- dump_lines = strio.string
119
- assert_nil dump_lines.lines.detect {|l| l =~ /\.(float|date|datetime|integer|time|timestamp) .* :limit/ && l !~ /sample_integer/ }
120
- ensure
121
- DbTypeMigration.down
122
- end
123
- end