neo-activerecord-jdbc-adapter 5.0.pre2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +33 -0
- data/.travis.yml +438 -0
- data/.yardopts +4 -0
- data/Appraisals +41 -0
- data/CONTRIBUTING.md +44 -0
- data/Gemfile +62 -0
- data/History.md +1191 -0
- data/LICENSE.txt +25 -0
- data/README.md +266 -0
- data/RUNNING_TESTS.md +88 -0
- data/Rakefile +100 -0
- data/Rakefile.jdbc +20 -0
- data/activerecord-jdbc-adapter.gemspec +42 -0
- data/lib/active_record/connection_adapters/as400_adapter.rb +2 -0
- data/lib/active_record/connection_adapters/db2_adapter.rb +1 -0
- data/lib/active_record/connection_adapters/derby_adapter.rb +1 -0
- data/lib/active_record/connection_adapters/firebird_adapter.rb +1 -0
- data/lib/active_record/connection_adapters/h2_adapter.rb +1 -0
- data/lib/active_record/connection_adapters/hsqldb_adapter.rb +1 -0
- data/lib/active_record/connection_adapters/informix_adapter.rb +1 -0
- data/lib/active_record/connection_adapters/jdbc_adapter.rb +1 -0
- data/lib/active_record/connection_adapters/jndi_adapter.rb +1 -0
- data/lib/active_record/connection_adapters/mariadb_adapter.rb +1 -0
- data/lib/active_record/connection_adapters/mssql_adapter.rb +1 -0
- data/lib/active_record/connection_adapters/mysql2_adapter.rb +1 -0
- data/lib/active_record/connection_adapters/mysql_adapter.rb +1 -0
- data/lib/active_record/connection_adapters/oracle_adapter.rb +1 -0
- data/lib/active_record/connection_adapters/postgresql_adapter.rb +1 -0
- data/lib/active_record/connection_adapters/sqlite3_adapter.rb +1 -0
- data/lib/active_record/connection_adapters/sqlserver_adapter.rb +1 -0
- data/lib/activerecord-jdbc-adapter.rb +1 -0
- data/lib/arel/visitors/compat.rb +60 -0
- data/lib/arel/visitors/db2.rb +137 -0
- data/lib/arel/visitors/derby.rb +112 -0
- data/lib/arel/visitors/firebird.rb +79 -0
- data/lib/arel/visitors/h2.rb +25 -0
- data/lib/arel/visitors/hsqldb.rb +32 -0
- data/lib/arel/visitors/postgresql_jdbc.rb +6 -0
- data/lib/arel/visitors/sql_server.rb +225 -0
- data/lib/arel/visitors/sql_server/ng42.rb +293 -0
- data/lib/arjdbc.rb +19 -0
- data/lib/arjdbc/abstract/database_statements.rb +92 -0
- data/lib/arjdbc/abstract/transaction_support.rb +86 -0
- data/lib/arjdbc/common_jdbc_methods.rb +13 -0
- data/lib/arjdbc/db2.rb +4 -0
- data/lib/arjdbc/db2/adapter.rb +789 -0
- data/lib/arjdbc/db2/as400.rb +130 -0
- data/lib/arjdbc/db2/column.rb +167 -0
- data/lib/arjdbc/db2/connection_methods.rb +44 -0
- data/lib/arjdbc/derby.rb +3 -0
- data/lib/arjdbc/derby/active_record_patch.rb +13 -0
- data/lib/arjdbc/derby/adapter.rb +556 -0
- data/lib/arjdbc/derby/connection_methods.rb +20 -0
- data/lib/arjdbc/derby/schema_creation.rb +15 -0
- data/lib/arjdbc/discover.rb +115 -0
- data/lib/arjdbc/firebird.rb +4 -0
- data/lib/arjdbc/firebird/adapter.rb +434 -0
- data/lib/arjdbc/firebird/connection_methods.rb +23 -0
- data/lib/arjdbc/h2.rb +3 -0
- data/lib/arjdbc/h2/adapter.rb +303 -0
- data/lib/arjdbc/h2/connection_methods.rb +27 -0
- data/lib/arjdbc/hsqldb.rb +3 -0
- data/lib/arjdbc/hsqldb/adapter.rb +297 -0
- data/lib/arjdbc/hsqldb/connection_methods.rb +28 -0
- data/lib/arjdbc/hsqldb/explain_support.rb +35 -0
- data/lib/arjdbc/hsqldb/schema_creation.rb +11 -0
- data/lib/arjdbc/informix.rb +5 -0
- data/lib/arjdbc/informix/adapter.rb +162 -0
- data/lib/arjdbc/informix/connection_methods.rb +9 -0
- data/lib/arjdbc/jdbc.rb +59 -0
- data/lib/arjdbc/jdbc/adapter.rb +899 -0
- data/lib/arjdbc/jdbc/adapter_java.jar +0 -0
- data/lib/arjdbc/jdbc/adapter_require.rb +46 -0
- data/lib/arjdbc/jdbc/base_ext.rb +44 -0
- data/lib/arjdbc/jdbc/callbacks.rb +51 -0
- data/lib/arjdbc/jdbc/column.rb +97 -0
- data/lib/arjdbc/jdbc/connection.rb +133 -0
- data/lib/arjdbc/jdbc/connection_methods.rb +36 -0
- data/lib/arjdbc/jdbc/driver.rb +43 -0
- data/lib/arjdbc/jdbc/extension.rb +59 -0
- data/lib/arjdbc/jdbc/java.rb +15 -0
- data/lib/arjdbc/jdbc/jdbc.rake +4 -0
- data/lib/arjdbc/jdbc/quoted_primary_key.rb +28 -0
- data/lib/arjdbc/jdbc/railtie.rb +2 -0
- data/lib/arjdbc/jdbc/rake_tasks.rb +3 -0
- data/lib/arjdbc/jdbc/serialized_attributes_helper.rb +3 -0
- data/lib/arjdbc/jdbc/type_cast.rb +166 -0
- data/lib/arjdbc/jdbc/type_converter.rb +142 -0
- data/lib/arjdbc/mimer.rb +3 -0
- data/lib/arjdbc/mimer/adapter.rb +142 -0
- data/lib/arjdbc/mssql.rb +7 -0
- data/lib/arjdbc/mssql/adapter.rb +808 -0
- data/lib/arjdbc/mssql/column.rb +200 -0
- data/lib/arjdbc/mssql/connection_methods.rb +79 -0
- data/lib/arjdbc/mssql/explain_support.rb +99 -0
- data/lib/arjdbc/mssql/limit_helpers.rb +231 -0
- data/lib/arjdbc/mssql/lock_methods.rb +77 -0
- data/lib/arjdbc/mssql/types.rb +343 -0
- data/lib/arjdbc/mssql/utils.rb +82 -0
- data/lib/arjdbc/mysql.rb +3 -0
- data/lib/arjdbc/mysql/adapter.rb +1006 -0
- data/lib/arjdbc/mysql/bulk_change_table.rb +150 -0
- data/lib/arjdbc/mysql/column.rb +162 -0
- data/lib/arjdbc/mysql/connection_methods.rb +145 -0
- data/lib/arjdbc/mysql/explain_support.rb +82 -0
- data/lib/arjdbc/mysql/schema_creation.rb +58 -0
- data/lib/arjdbc/oracle.rb +4 -0
- data/lib/arjdbc/oracle/adapter.rb +952 -0
- data/lib/arjdbc/oracle/column.rb +126 -0
- data/lib/arjdbc/oracle/connection_methods.rb +21 -0
- data/lib/arjdbc/postgresql.rb +3 -0
- data/lib/arjdbc/postgresql/_bc_time_cast_patch.rb +21 -0
- data/lib/arjdbc/postgresql/adapter.rb +825 -0
- data/lib/arjdbc/postgresql/base/array_decoder.rb +26 -0
- data/lib/arjdbc/postgresql/base/array_encoder.rb +25 -0
- data/lib/arjdbc/postgresql/base/array_parser.rb +95 -0
- data/lib/arjdbc/postgresql/base/pgconn.rb +11 -0
- data/lib/arjdbc/postgresql/column.rb +51 -0
- data/lib/arjdbc/postgresql/connection_methods.rb +54 -0
- data/lib/arjdbc/postgresql/name.rb +24 -0
- data/lib/arjdbc/postgresql/oid_types.rb +178 -0
- data/lib/arjdbc/railtie.rb +11 -0
- data/lib/arjdbc/sqlite3.rb +3 -0
- data/lib/arjdbc/sqlite3/adapter.rb +703 -0
- data/lib/arjdbc/sqlite3/connection_methods.rb +40 -0
- data/lib/arjdbc/sybase.rb +2 -0
- data/lib/arjdbc/sybase/adapter.rb +47 -0
- data/lib/arjdbc/tasks.rb +13 -0
- data/lib/arjdbc/tasks/database_tasks.rb +54 -0
- data/lib/arjdbc/tasks/databases.rake +91 -0
- data/lib/arjdbc/tasks/databases3.rake +215 -0
- data/lib/arjdbc/tasks/databases4.rake +39 -0
- data/lib/arjdbc/tasks/db2_database_tasks.rb +104 -0
- data/lib/arjdbc/tasks/derby_database_tasks.rb +95 -0
- data/lib/arjdbc/tasks/h2_database_tasks.rb +31 -0
- data/lib/arjdbc/tasks/hsqldb_database_tasks.rb +70 -0
- data/lib/arjdbc/tasks/jdbc_database_tasks.rb +169 -0
- data/lib/arjdbc/tasks/mssql_database_tasks.rb +46 -0
- data/lib/arjdbc/tasks/oracle/enhanced_structure_dump.rb +297 -0
- data/lib/arjdbc/tasks/oracle_database_tasks.rb +65 -0
- data/lib/arjdbc/util/quoted_cache.rb +60 -0
- data/lib/arjdbc/util/serialized_attributes.rb +98 -0
- data/lib/arjdbc/util/table_copier.rb +110 -0
- data/lib/arjdbc/version.rb +8 -0
- data/lib/generators/jdbc/USAGE +9 -0
- data/lib/generators/jdbc/jdbc_generator.rb +17 -0
- data/lib/jdbc_adapter.rb +2 -0
- data/lib/jdbc_adapter/rake_tasks.rb +4 -0
- data/lib/jdbc_adapter/version.rb +4 -0
- data/pom.xml +114 -0
- data/rails_generators/jdbc_generator.rb +15 -0
- data/rails_generators/templates/config/initializers/jdbc.rb +10 -0
- data/rails_generators/templates/lib/tasks/jdbc.rake +11 -0
- data/rakelib/01-tomcat.rake +51 -0
- data/rakelib/02-test.rake +121 -0
- data/rakelib/bundler_ext.rb +11 -0
- data/rakelib/compile.rake +62 -0
- data/rakelib/db.rake +58 -0
- data/rakelib/rails.rake +75 -0
- data/src/java/arjdbc/ArJdbcModule.java +178 -0
- data/src/java/arjdbc/db2/DB2Module.java +71 -0
- data/src/java/arjdbc/db2/DB2RubyJdbcConnection.java +142 -0
- data/src/java/arjdbc/derby/DerbyModule.java +179 -0
- data/src/java/arjdbc/derby/DerbyRubyJdbcConnection.java +164 -0
- data/src/java/arjdbc/firebird/FirebirdRubyJdbcConnection.java +190 -0
- data/src/java/arjdbc/h2/H2Module.java +44 -0
- data/src/java/arjdbc/h2/H2RubyJdbcConnection.java +67 -0
- data/src/java/arjdbc/hsqldb/HSQLDBModule.java +68 -0
- data/src/java/arjdbc/informix/InformixRubyJdbcConnection.java +75 -0
- data/src/java/arjdbc/jdbc/AdapterJavaService.java +45 -0
- data/src/java/arjdbc/jdbc/Callable.java +44 -0
- data/src/java/arjdbc/jdbc/JdbcConnectionFactory.java +45 -0
- data/src/java/arjdbc/jdbc/RubyJdbcConnection.java +3616 -0
- data/src/java/arjdbc/jdbc/SQLBlock.java +54 -0
- data/src/java/arjdbc/mssql/MSSQLModule.java +102 -0
- data/src/java/arjdbc/mssql/MSSQLRubyJdbcConnection.java +195 -0
- data/src/java/arjdbc/mysql/MySQLModule.java +147 -0
- data/src/java/arjdbc/mysql/MySQLRubyJdbcConnection.java +397 -0
- data/src/java/arjdbc/oracle/OracleModule.java +75 -0
- data/src/java/arjdbc/oracle/OracleRubyJdbcConnection.java +465 -0
- data/src/java/arjdbc/postgresql/PostgreSQLRubyJdbcConnection.java +752 -0
- data/src/java/arjdbc/sqlite3/SQLite3Module.java +78 -0
- data/src/java/arjdbc/sqlite3/SQLite3RubyJdbcConnection.java +351 -0
- data/src/java/arjdbc/util/CallResultSet.java +826 -0
- data/src/java/arjdbc/util/QuotingUtils.java +111 -0
- metadata +255 -0
data/LICENSE.txt
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
Copyright (c) 2012-2014 Karol Bucek <self@kares.org>
|
2
|
+
Copyright (c) 2006-2012 Nick Sieger <nick@nicksieger.com>
|
3
|
+
Copyright (c) 2006-2008 Ola Bini <ola.bini@gmail.com>
|
4
|
+
|
5
|
+
All rights reserved.
|
6
|
+
|
7
|
+
Redistribution and use in source and binary forms, with or without modification,
|
8
|
+
are permitted provided that the following conditions are met:
|
9
|
+
|
10
|
+
- Redistributions of source code must retain the above copyright notice, this
|
11
|
+
list of conditions and the following disclaimer.
|
12
|
+
- Redistributions in binary form must reproduce the above copyright notice, this
|
13
|
+
list of conditions and the following disclaimer in the documentation and/or
|
14
|
+
other materials provided with the distribution.
|
15
|
+
|
16
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
17
|
+
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
18
|
+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
19
|
+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
20
|
+
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
21
|
+
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
22
|
+
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
23
|
+
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
24
|
+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
25
|
+
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
data/README.md
ADDED
@@ -0,0 +1,266 @@
|
|
1
|
+
# ActiveRecord JDBC Adapter
|
2
|
+
|
3
|
+
[![Gem Version](https://badge.fury.io/rb/activerecord-jdbc-adapter.png)][7]
|
4
|
+
|
5
|
+
ActiveRecord-JDBC-Adapter (AR-JDBC) is a database adapter for Rails'
|
6
|
+
*ActiveRecord* component that can be used with [JRuby][0]. It allows use of
|
7
|
+
virtually any JDBC-compliant database with your JRuby on Rails application.
|
8
|
+
|
9
|
+
We supports *ActiveRecord* **2.3**, **3.x** and **4.x** from a single code base.
|
10
|
+
You'll need JRuby >= **1.6.8** (we recommend using the latest and greatest of
|
11
|
+
JRubies) thus Java >= **1.6** is mandatory.
|
12
|
+
|
13
|
+
#### AR-JDBC **1.3.x** is a recommended update for all **1.2.x** users.
|
14
|
+
|
15
|
+
Our latest major version **1.3.x** represents a few months of refactoring and
|
16
|
+
updates covering (not just) new/old *ActiveRecord* features. It tries to stay
|
17
|
+
compatible with 1.2.9 as much as possible but please be aware that it's not always
|
18
|
+
possible(mostly for the best), please read our [migration guide][8] for details.
|
19
|
+
|
20
|
+
## Databases
|
21
|
+
|
22
|
+
ActiveRecord-JDBC-Adapter provides full or nearly full support for:
|
23
|
+
**MySQL**, **PostgreSQL**, **SQLite3**, **Oracle**, *MS-SQL** (SQL Server),
|
24
|
+
**DB2**, **Firebird**, **Derby**, **HSQLDB**, **H2**, and **Informix**.
|
25
|
+
|
26
|
+
Other databases will require testing and likely a custom configuration module.
|
27
|
+
Please join the JRuby [mailing list][1] to help us discover support for more
|
28
|
+
databases.
|
29
|
+
|
30
|
+
## Using ActiveRecord JDBC
|
31
|
+
|
32
|
+
### Inside Rails
|
33
|
+
|
34
|
+
To use AR-JDBC with JRuby on Rails:
|
35
|
+
|
36
|
+
1. Choose the adapter you wish to gem install. The following pre-packaged
|
37
|
+
adapters are available:
|
38
|
+
|
39
|
+
- Base JDBC (`activerecord-jdbc-adapter`) - supports all available databases
|
40
|
+
via JDBC, but requires you to download and manually setup a JDBC driver for
|
41
|
+
the database you're using
|
42
|
+
- MySQL (`activerecord-jdbcmysql-adapter`)
|
43
|
+
- PostgreSQL (`activerecord-jdbcpostgresql-adapter`)
|
44
|
+
- SQLite3 (`activerecord-jdbcsqlite3-adapter`)
|
45
|
+
- Derby (`activerecord-jdbcderby-adapter`)
|
46
|
+
- HSQLDB (`activerecord-jdbchsqldb-adapter`)
|
47
|
+
- H2 (`activerecord-jdbch2-adapter`)
|
48
|
+
- MSSQL (`activerecord-jdbcmssql-adapter`) - uses the OSS jTDS driver by default
|
49
|
+
which might have issues with the latest SQLServer (but should work using the
|
50
|
+
Microsoft JDBC Driver for SQL Server - we recommend using 4.0)
|
51
|
+
|
52
|
+
2a. If you're generating a new Rails application, use the following command:
|
53
|
+
|
54
|
+
jruby -S rails new sweetapp
|
55
|
+
|
56
|
+
2b. Otherwise, you might need to perform some extra configuration steps
|
57
|
+
to prepare your Rails application for JDBC.
|
58
|
+
|
59
|
+
You'll need to modify your *Gemfile* to use the *activerecord-jdbc-adapter* gem
|
60
|
+
(or one of the helper gems) under JRuby. Change your *Gemfile* to look something
|
61
|
+
like the following:
|
62
|
+
|
63
|
+
```ruby
|
64
|
+
gem 'mysql2', platform: :ruby
|
65
|
+
gem 'activerecord-jdbcmysql-adapter', platform: :jruby
|
66
|
+
```
|
67
|
+
|
68
|
+
If you're (stuck) using Rails 2.3, you might need to:
|
69
|
+
|
70
|
+
jruby script/generate jdbc
|
71
|
+
|
72
|
+
3. Configure your *database.yml* in the normal Rails style:
|
73
|
+
|
74
|
+
```yml
|
75
|
+
development:
|
76
|
+
adapter: mysql2 # or mysql
|
77
|
+
database: blog_development
|
78
|
+
username: blog
|
79
|
+
password: 1234
|
80
|
+
```
|
81
|
+
|
82
|
+
**Legacy Configuration:** If you use one of the *activerecord-jdbcxxx-adapter*
|
83
|
+
gems, you can still put a 'jdbc' prefix in front of the database adapter name,
|
84
|
+
e.g. `adapter: jdbcmysql`.
|
85
|
+
|
86
|
+
For plain JDBC database configurations, you'll need to know the database driver
|
87
|
+
class and URL (do not forget to put the driver .jar(s) on the class-path) e.g.:
|
88
|
+
|
89
|
+
```yml
|
90
|
+
development:
|
91
|
+
adapter: jdbc
|
92
|
+
username: blog
|
93
|
+
password: 1234
|
94
|
+
driver: com.mysql.jdbc.Driver
|
95
|
+
url: jdbc:mysql://localhost:3306/blog_development
|
96
|
+
```
|
97
|
+
|
98
|
+
For JNDI data sources, you may simply specify the JNDI location as follows, it's
|
99
|
+
recommended to use the same adapter: setting as one would configure when using
|
100
|
+
"bare" (JDBC) connections e.g. :
|
101
|
+
|
102
|
+
```yml
|
103
|
+
production:
|
104
|
+
adapter: postgresql
|
105
|
+
jndi: jdbc/PostgreDS
|
106
|
+
```
|
107
|
+
|
108
|
+
**NOTE:** any other settings such as *database:*, *username:*, *properties:* make
|
109
|
+
no difference since everything is already configured on the JNDI DataSource end.
|
110
|
+
|
111
|
+
JDBC driver specific properties might be set if you use an URL to specify the DB
|
112
|
+
or preferably using the *properties:* syntax:
|
113
|
+
|
114
|
+
```yml
|
115
|
+
production:
|
116
|
+
adapter: mysql
|
117
|
+
username: blog
|
118
|
+
password: blog
|
119
|
+
url: "jdbc:mysql://localhost:3306/blog?profileSQL=true"
|
120
|
+
properties: # specific to com.mysql.jdbc.Driver
|
121
|
+
socketTimeout: 60000
|
122
|
+
connectTimeout: 60000
|
123
|
+
```
|
124
|
+
|
125
|
+
If you're really old school you might want to use AR-JDBC with a DB2 on z/OS:
|
126
|
+
|
127
|
+
```yml
|
128
|
+
development:
|
129
|
+
adapter: jdbc
|
130
|
+
url: jdbc:db2j:net://mightyzoshost:446/RAILS_DBT1
|
131
|
+
driver: com.ibm.db2.jcc.DB2Driver
|
132
|
+
schema: DB2XB12
|
133
|
+
database: RAILS_DB1
|
134
|
+
tablespace: TSDE911
|
135
|
+
lob_tablespaces:
|
136
|
+
first_table: TSDE912
|
137
|
+
username: business
|
138
|
+
password: machines
|
139
|
+
encoding: unicode
|
140
|
+
# you can force a (DB2) dialect using:
|
141
|
+
#dialect: as400
|
142
|
+
```
|
143
|
+
|
144
|
+
More information on (configuring) AR-JDBC might be found on our [wiki][5].
|
145
|
+
|
146
|
+
### Standalone with ActiveRecord
|
147
|
+
|
148
|
+
Once the setup is made (see below) you can establish a JDBC connection like this
|
149
|
+
(e.g. for `activerecord-jdbcderby-adapter`):
|
150
|
+
|
151
|
+
```ruby
|
152
|
+
ActiveRecord::Base.establish_connection(
|
153
|
+
adapter: 'derby',
|
154
|
+
database: 'db/my-database'
|
155
|
+
)
|
156
|
+
```
|
157
|
+
|
158
|
+
or using (requires that you manually put the driver jar on the class-path):
|
159
|
+
|
160
|
+
```ruby
|
161
|
+
ActiveRecord::Base.establish_connection(
|
162
|
+
:adapter => 'jdbc',
|
163
|
+
:driver => 'org.apache.derby.jdbc.EmbeddedDriver',
|
164
|
+
:url => 'jdbc:derby:sample_db;create=true'
|
165
|
+
)
|
166
|
+
```
|
167
|
+
|
168
|
+
#### Using Bundler
|
169
|
+
|
170
|
+
Proceed as with Rails; specify `ActiveRecord` in your Bundle along with the
|
171
|
+
chosen JDBC adapter(s), this time sample *Gemfile* for MySQL:
|
172
|
+
|
173
|
+
```ruby
|
174
|
+
gem 'activerecord', '~> 3.2.14'
|
175
|
+
gem 'activerecord-jdbcmysql-adapter', :platform => :jruby
|
176
|
+
```
|
177
|
+
|
178
|
+
When you `require 'bundler/setup'` everything will be set up for you as expected.
|
179
|
+
|
180
|
+
You do not need to use the 'helper' *activerecord-jdbcxxx-adapter* gem we provide
|
181
|
+
but than should make sure an appropriate JDBC driver is available at runtime, in
|
182
|
+
that case simply setup your *Gemfile* as:
|
183
|
+
|
184
|
+
```ruby
|
185
|
+
gem 'activerecord', '~> 4.0.0'
|
186
|
+
gem 'activerecord-jdbc-adapter', '~> 1.3.2', platform: :jruby
|
187
|
+
```
|
188
|
+
|
189
|
+
#### Without Bundler
|
190
|
+
|
191
|
+
Install the needed gems with JRuby, for example:
|
192
|
+
|
193
|
+
gem install activerecord -v "~> 3.2.10"
|
194
|
+
gem install activerecord-jdbc-adapter --ignore-dependencies
|
195
|
+
|
196
|
+
If you wish to use the adapter for a specific database, you can install it
|
197
|
+
directly and the (jdbc-) driver gem (dependency) will be installed as well:
|
198
|
+
|
199
|
+
jruby -S gem install activerecord-jdbcderby-adapter
|
200
|
+
|
201
|
+
Your program should include:
|
202
|
+
|
203
|
+
```ruby
|
204
|
+
require 'active_record'
|
205
|
+
require 'activerecord-jdbc-adapter' if defined? JRUBY_VERSION
|
206
|
+
# or in case you're using the pre-packaged adapter gem :
|
207
|
+
require 'activerecord-jdbcderby-adapter' if defined? JRUBY_VERSION
|
208
|
+
```
|
209
|
+
|
210
|
+
## Extending AR-JDBC
|
211
|
+
|
212
|
+
You can create your own extension to AR-JDBC for a JDBC-based database that core
|
213
|
+
AR-JDBC does not support. We've created an example project for the Intersystems
|
214
|
+
Cache database that you can examine as a template.
|
215
|
+
See the [cachedb-adapter project][4] for more information.
|
216
|
+
|
217
|
+
## Source
|
218
|
+
|
219
|
+
The source for activerecord-jdbc-adapter is available using git:
|
220
|
+
|
221
|
+
git clone git://github.com/jruby/activerecord-jdbc-adapter.git
|
222
|
+
|
223
|
+
Please note that the project manages multiple gems from a single repository,
|
224
|
+
if you're using *Bundler* >= 1.2 it should be able to locate all gemspecs from
|
225
|
+
the git repository. Sample *Gemfile* for running with (MySQL) master:
|
226
|
+
|
227
|
+
```ruby
|
228
|
+
gem 'activerecord-jdbc-adapter', :github => 'jruby/activerecord-jdbc-adapter'
|
229
|
+
gem 'activerecord-jdbcmysql-adapter', :github => 'jruby/activerecord-jdbc-adapter'
|
230
|
+
```
|
231
|
+
|
232
|
+
## Getting Involved
|
233
|
+
|
234
|
+
Please read our [CONTRIBUTING](CONTRIBUTING.md) & [RUNNING_TESTS](RUNNING_TESTS.md)
|
235
|
+
guides for starters. You can always help us by maintaining AR-JDBC's [wiki][5].
|
236
|
+
|
237
|
+
## Feedback
|
238
|
+
|
239
|
+
Please report bugs at our [issue tracker][3]. If you're not sure if
|
240
|
+
something's a bug, feel free to pre-report it on the [mailing lists][1] or
|
241
|
+
ask on the #JRuby IRC channel on http://freenode.net/ (try [web-chat][6]).
|
242
|
+
|
243
|
+
## Authors
|
244
|
+
|
245
|
+
This project was originally written by [Nick Sieger](http://github.com/nicksieger)
|
246
|
+
and [Ola Bini](http://github.com/olabini) with lots of help from the JRuby community.
|
247
|
+
Polished 3.x compatibility and 4.x support (for AR-JDBC >= 1.3.0) was managed by
|
248
|
+
[Karol Bucek](http://github.com/kares) among others.
|
249
|
+
|
250
|
+
## License
|
251
|
+
|
252
|
+
ActiveRecord-JDBC-Adapter is open-source released under the BSD/MIT license.
|
253
|
+
See [LICENSE.txt](LICENSE.txt) included with the distribution for details.
|
254
|
+
|
255
|
+
Open-source driver gems within AR-JDBC's sources are licensed under the same
|
256
|
+
license the database's drivers are licensed. See each driver gem's LICENSE.txt.
|
257
|
+
|
258
|
+
[0]: http://www.jruby.org/
|
259
|
+
[1]: http://jruby.org/community
|
260
|
+
[2]: http://github.com/jruby/activerecord-jdbc-adapter/blob/master/activerecord-jdbcmssql-adapter
|
261
|
+
[3]: https://github.com/jruby/activerecord-jdbc-adapter/issues
|
262
|
+
[4]: http://github.com/nicksieger/activerecord-cachedb-adapter
|
263
|
+
[5]: https://github.com/jruby/activerecord-jdbc-adapter/wiki
|
264
|
+
[6]: https://webchat.freenode.net/?channels=#jruby
|
265
|
+
[7]: http://badge.fury.io/rb/activerecord-jdbc-adapter
|
266
|
+
[8]: https://github.com/jruby/activerecord-jdbc-adapter/wiki/Migrating-from-1.2.x-to-1.3.0
|
data/RUNNING_TESTS.md
ADDED
@@ -0,0 +1,88 @@
|
|
1
|
+
|
2
|
+
## Running AR-JDBC's Tests
|
3
|
+
|
4
|
+
After you have built arjdbc (run rake), then you can try testing it (if you
|
5
|
+
do not build then adapter_java.jar is not put into the lib dir). If you
|
6
|
+
change any of the .java files you will need to rebuild.
|
7
|
+
|
8
|
+
Most DB specific unit tests hide under the **test/db** directory, the files
|
9
|
+
included in the *test* directory are mostly shared test modules and helpers.
|
10
|
+
|
11
|
+
Rake tasks are loaded from **rakelib/02-test-rake**, most adapters have a
|
12
|
+
corresponding test_[adapter] task e.g. `rake test_sqlite3` that run against DB.
|
13
|
+
To check all available (test related) tasks simply `rake -T | grep test`.
|
14
|
+
|
15
|
+
If the adapter supports creating a database it will try to do so automatically
|
16
|
+
(most embed databases such as SQLite3) for some adapters (MySQL, PostgreSQL) we
|
17
|
+
do this auto-magically (see the `rake db:create` tasks), but otherwise you'll
|
18
|
+
need to setup a database dedicated for tests (using the standard tools that come
|
19
|
+
with your DB installation).
|
20
|
+
|
21
|
+
Connection parameters: database, host etc. can usually be changed from the shell
|
22
|
+
`env` for adapters where there might be no direct control over the DB
|
23
|
+
instance/configuration, e.g. for Oracle (by looking at **test/db/oracle.rb**)
|
24
|
+
one might adapt the test database configuration using :
|
25
|
+
```
|
26
|
+
export ORACLE_HOST=192.168.1.2
|
27
|
+
export ORACLE_USER=SAMPLE
|
28
|
+
export ORACLE_PASS=sample
|
29
|
+
export ORACLE_SID=MAIN
|
30
|
+
```
|
31
|
+
|
32
|
+
Tests are by default run against the "current" ActiveRecord version locked down
|
33
|
+
by Bundler, however since we usually do support more versions from a single code
|
34
|
+
base run those with the (appraisal) provided task e.g. for MySQL :
|
35
|
+
|
36
|
+
rake appraisal:rails31 test_mysql TEST=test/db/mysql/rake_test.rb
|
37
|
+
|
38
|
+
Observe the **TEST** variable used to specify a single file to be used to resolve
|
39
|
+
test cases, you pick tests by matching their names as well using **TESTOPTS** :
|
40
|
+
|
41
|
+
rake appraisal:rails40 test_postgres TESTOPTS="--name=/integer/"
|
42
|
+
|
43
|
+
This of course also works when running the "plain" test (no appraisal:xxx) task.
|
44
|
+
|
45
|
+
Since 1.3.0 we also support prepared statements, these are off by default (AR)
|
46
|
+
but one can easily run tests with prepared statements enabled using env vars :
|
47
|
+
|
48
|
+
rake test_derby PS=true # or PREPARED_STATEMENTS=true
|
49
|
+
|
50
|
+
|
51
|
+
### ActiveRecord (Rails) Tests
|
52
|
+
|
53
|
+
We also have the ability to run our adapters against Rails ActiveRecord
|
54
|
+
tests as well. First, make sure you have the Rails repository cloned locally:
|
55
|
+
|
56
|
+
git clone git://github.com/rails/rails.git
|
57
|
+
|
58
|
+
If you clone Rails to the same parent directory this project is cloned to
|
59
|
+
then you may do either:
|
60
|
+
|
61
|
+
jruby -S rake rails:test:sqlite
|
62
|
+
jruby -S rake rails:test:postgres
|
63
|
+
jruby -S rake rails:test:mysql
|
64
|
+
|
65
|
+
If you have your rails source in another directory then you can pass
|
66
|
+
in **RAILS**:
|
67
|
+
|
68
|
+
jruby -S rake rails:test:sqlite RAILS=../../somewhere/rails
|
69
|
+
|
70
|
+
If you are working on a more exotic adapter you can also pass in **DRIVER**:
|
71
|
+
|
72
|
+
jruby -S rake rails:test:all DRIVER=derby
|
73
|
+
|
74
|
+
Note, that if you want to test against particular version of Rails you need
|
75
|
+
to check out the proper branch in Rails source (e.g. v5.0.2). If you are
|
76
|
+
just starting to debug an adapter then running:
|
77
|
+
|
78
|
+
jruby -S rake rails:test:sqlite:basic_test
|
79
|
+
jruby -S rake rails:test:postgres:basic_test
|
80
|
+
jruby -S rake rails:test:mysql:basic_test
|
81
|
+
|
82
|
+
is helpful since basic_test in active-record hits that 80% sweet spot.
|
83
|
+
|
84
|
+
[![Build Status][0]](http://travis-ci.org/#!/jruby/activerecord-jdbc-adapter)
|
85
|
+
|
86
|
+
Happy Testing!
|
87
|
+
|
88
|
+
[0]: https://secure.travis-ci.org/jruby/activerecord-jdbc-adapter.png
|
data/Rakefile
ADDED
@@ -0,0 +1,100 @@
|
|
1
|
+
require 'rake/testtask'
|
2
|
+
|
3
|
+
require 'rake/clean'
|
4
|
+
CLEAN.include 'derby*', 'test.db.*', '*test.sqlite3', 'test/reports'
|
5
|
+
CLEAN.include 'lib/**/*.jar', 'MANIFEST.MF', '*.log', 'target/*'
|
6
|
+
|
7
|
+
require 'bundler/gem_helper'
|
8
|
+
Bundler::GemHelper.install_tasks
|
9
|
+
|
10
|
+
require 'bundler/setup'
|
11
|
+
require 'appraisal'
|
12
|
+
|
13
|
+
task :default => [:jar, :test]
|
14
|
+
|
15
|
+
task :build => :jar
|
16
|
+
task :install => :jar
|
17
|
+
|
18
|
+
ADAPTERS = %w[derby h2 hsqldb mssql mysql postgresql sqlite3].map { |a| "activerecord-jdbc#{a}-adapter" }
|
19
|
+
DRIVERS = %w[derby h2 hsqldb jtds mysql postgres sqlite3].map { |a| "jdbc-#{a}" }
|
20
|
+
TARGETS = ( ADAPTERS + DRIVERS )
|
21
|
+
|
22
|
+
rake = lambda { |task| ruby "-S", "rake", task }
|
23
|
+
current_version = lambda { Bundler.load_gemspec('activerecord-jdbc-adapter.gemspec').version }
|
24
|
+
|
25
|
+
ADAPTERS.each do |target|
|
26
|
+
namespace target do
|
27
|
+
task :build do
|
28
|
+
version = current_version.call
|
29
|
+
Dir.chdir(target) { rake.call "build" }
|
30
|
+
cp FileList["#{target}/pkg/#{target}-#{version}.gem"], "pkg"
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
DRIVERS.each do |target|
|
35
|
+
namespace target do
|
36
|
+
task :build do
|
37
|
+
Dir.chdir(target) { rake.call "build" }
|
38
|
+
cp FileList["#{target}/pkg/#{target}-*.gem"], "pkg"
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
TARGETS.each do |target|
|
43
|
+
namespace target do
|
44
|
+
task :install do
|
45
|
+
Dir.chdir(target) { rake.call "install" }
|
46
|
+
end
|
47
|
+
task :release do
|
48
|
+
Dir.chdir(target) { rake.call "release" }
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
# DRIVERS
|
54
|
+
|
55
|
+
desc "Build drivers"
|
56
|
+
task "build:drivers" => DRIVERS.map { |name| "#{name}:build" }
|
57
|
+
task "drivers:build" => 'build:drivers'
|
58
|
+
|
59
|
+
desc "Install drivers"
|
60
|
+
task "install:drivers" => DRIVERS.map { |name| "#{name}:install" }
|
61
|
+
task "drivers:install" => 'install:drivers'
|
62
|
+
|
63
|
+
# desc "Release drivers"
|
64
|
+
# task "release:drivers" => DRIVERS.map { |name| "#{name}:release" }
|
65
|
+
# task "drivers:release" => DRIVERS.map { |name| "#{name}:release" }
|
66
|
+
|
67
|
+
# ADAPTERS
|
68
|
+
|
69
|
+
desc "Build adapters"
|
70
|
+
task "build:adapters" => [ 'build' ] + ADAPTERS.map { |name| "#{name}:build" }
|
71
|
+
task "adapters:build" => 'build:adapters'
|
72
|
+
|
73
|
+
desc "Install adapters"
|
74
|
+
task "install:adapters" => [ 'install' ] + ADAPTERS.map { |name| "#{name}:install" }
|
75
|
+
task "adapters:install" => 'install:adapters'
|
76
|
+
|
77
|
+
desc "Release adapters"
|
78
|
+
task "release:adapters" => [ 'release' ] + ADAPTERS.map { |name| "#{name}:release" }
|
79
|
+
task "adapters:release" => 'release:adapters'
|
80
|
+
|
81
|
+
task 'release:do' => 'build:adapters' do
|
82
|
+
version = current_version.call; version_tag = "v#{version}"
|
83
|
+
|
84
|
+
sh("git diff --no-patch --exit-code") { |ok| fail "git working dir is not clean" unless ok }
|
85
|
+
sh("git diff-index --quiet --cached HEAD") { |ok| fail "git index is not clean" unless ok }
|
86
|
+
|
87
|
+
sh "git tag -a -m \"AR-JDBC #{version}\" #{version_tag}"
|
88
|
+
branch = `git rev-parse --abbrev-ref HEAD`.strip
|
89
|
+
puts "releasing from (current) branch #{branch.inspect}"
|
90
|
+
sh "for gem in `ls pkg/*-#{version}.gem`; do gem push $gem; done" do |ok|
|
91
|
+
sh "git push origin #{branch} --tags" if ok
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
# ALL
|
96
|
+
|
97
|
+
task "build:all" => [ 'build' ] + TARGETS.map { |name| "#{name}:build" }
|
98
|
+
task "all:build" => 'build:all'
|
99
|
+
task "install:all" => [ 'install' ] + TARGETS.map { |name| "#{name}:install" }
|
100
|
+
task "all:install" => 'install:all'
|