ActiveRecord-JDBC 0.6 Released!
Posted by Nick Sieger Tue, 06 Nov 2007 15:00:00 GMT
Just out is ActiveRecord-JDBC 0.6, the post-RubyConf release.
The sparkly new feature is Rails 2.0 support. In the soon-to-be-released Rails 2.0 (edge), Rails will automatically look for and load an adapter gem based on the name of the adapter you specify in
development: adapter: funkdb ...
With this database configuration, Rails will attempt to load the
activerecord-funkdb-adapter gem, require the
active_record/connection_adapters/funkdb_adapter library, and call the method
ActiveRecord::Base.funkdb_connection in order to obtain a connection to the database. (This is the mechanism used to off-load non-core adapters out of the Rails codebase.)
We can leverage this convention to make it easier than ever to get started using JRuby with your Rails application. So, the first thing new in the 0.6 release is the name. You now install
jruby -S gem install activerecord-jdbc-adapter
But wait, there’s more! We also have adapters for four open-source databases, including MySQL, PostgreSQL, and two embedded Java databases, Derby and HSQLDB. And, for your convenience, we’ve bundled the JDBC drivers in dependent gems, so you don’t have to go hunting them down if you don’t have them handy.
Check this out. Get a fresh copy of JRuby 1.0.2, unpack it, and add the
bin directory to your path. Install the adapter:
$ jruby -S gem install activerecord-jdbcderby-adapter --include-dependencies Successfully installed activerecord-jdbcderby-adapter-0.6 Successfully installed activerecord-jdbc-adapter-0.6 Successfully installed jdbc-derby-10.2.2.0
In your Rails application, freeze to edge Rails (soon to be Rails 2.0).
Re-run the Rails command, regenerating configuration files.
jruby ./vendor/rails/railties/bin/rails .
Currently, Rails 2.0 uses
openssl for the HMAC digest used in the new cookie session store, so we have to install the
jruby -S gem install jruby-openssl
Now, update your config/database.yml as follows:
development: adapter: jdbcderby database: db/development
Re-run your migrations, and you should now see a Derby database footprint in the
$ ls -l db/development total 24 -rw-r--r-- 1 nicksieg nicksieg 38 Nov 6 08:24 db.lck -rw-r--r-- 1 nicksieg nicksieg 4 Nov 6 08:24 dbex.lck drwxr-xr-x 5 nicksieg nicksieg 170 Nov 6 08:24 log/ drwxr-xr-x 65 nicksieg nicksieg 2210 Nov 6 08:24 seg0/ -rw-r--r-- 1 nicksieg nicksieg 882 Nov 6 08:24 service.properties drwxr-xr-x 2 nicksieg nicksieg 68 Nov 6 08:24 tmp/
That’s it! To re-emphasize, to make your application run under JRuby, no longer will you need to a) find and download appropriate JDBC drivers, b) wonder where they should be placed so that JRuby will find them, or c) make custom changes to
config/environment.rb. All that’s taken care of you if you use one of the following adapters:
If you need to connect to a different database, you’ll still need to place your database’s JDBC driver jar file in the appropriate place and use the straight
activerecord-jdbc-adapter. Also note that in this case, and for Rails 1.2.x in general, you’ll still need to add that pesky
require statement to
As always, there are bug fixes too (though we haven’t been tracking exactly which ones are fixed). We’re starting to file ActiveRecord-JDBC bugs in the JRuby JIRA now, and will be putting in future AR-JDBC versions to target soon too. So, please file new bugs in JIRA (and select component “ActiveRecord-JDBC”) rather than in the antiquated Rubyforge tracker.