Posted by Nick Sieger
Thu, 14 Oct 2010 15:25:51 GMT
Just a quick note that
activerecord-jdbc-adapter has finally hit 1.0.0. Install it today:
gem install activerecord-jdbc-adapter
Included are adapters for MySQL, PostgreSQL, SQLite3, Derby, HSQLDB, H2, and Microsoft SQL Server.
gem install activerecord-jdbcmysql-adapter
gem install activerecord-jdbcpostgresql-adapter
gem install activerecord-jdbcsqlite3-adapter
gem install activerecord-jdbcderby-adapter
gem install activerecord-jdbchsqldb-adapter
gem install activerecord-jdbch2-adapter
gem install activerecord-jdbcmssql-adapter
You can also use
activerecord-jdbc-adapter with Oracle, DB2, Sybase, and Informix. Just ensure that the database JDBC driver jar files are mentioned in
require them directly in your script or application. Then, configure
adapter: set to one of
This release promises superb compatibility with Rails 3. We now have the ActiveRecord test suite running in CI and the 1.0.0 release is 100% green when run on MySQL. (SQLite3 is right behind with just 13 failures, and we hope to fix those soon.)
As mentioned before, to get started with Rails 3, JRuby and
activerecord-jdbc-adapter, simply run:
$ rails new app --database mysql --template http://jruby.org
$ cd app && bundle install
Using activerecord-jdbc-adapter (1.0.0)
Using jdbc-mysql (5.0.4)
Using rails (3.0.0)
Your bundle is complete! Use `bundle show [gemname]` ...
One new feature in 1.0.0 is the ability to define an extension adapter for your proprietary JDBC database without needing to hack the
activerecord-jdbc-adapter source code. To get you started we extracted the
activerecord-cachedb-adapter and put it on Github for you to use as a template.
The 1.0.0 release had over 200 commits poured into it and lots of great help from the community. Thanks to David Kellum, Dmitry Denisov, Dwayne Litzenberger, Gregor Schmidt, James Walker, John Duff, Joshua Suggs, Nicholas J Kreucher, Peter Donald, Geoff Longman, Uwe Kubosch, Youhei Kondou, Michael Pitman, Alex B, and Ryan Bell for their contributions to this release.
Posted by Nick Sieger
Mon, 12 Oct 2009 18:30:45 GMT
As announced last week on the jruby-user list, 0.9.2, the latest
activerecord-jdbc-adapter release, has been pushed out. Please install the gem in the usual fashion and try it out on your applications.
One of the most contentious bugs broke
db:drop, ruining the quick-start workflow that Rails is known for. To fix this, a creative solution was needed that ended up bringing some nice benefits.
The problem stemmed from the fact that some database setup tasks in Rails 2.3 no longer load the environment; instead they just load the configuration data and work with that. This means that there is no easy way to hook into Rails and override those tasks, which is what activerecord-jdbc needs to do.
The solution I ended up with was to create a
jdbc Rails generator that inserts a couple files into your rails application that inject the JDBC logic into ActiveRecord and the database rake tasks. To wit:
$ jruby script/generate jdbc
The upside of this new technique is that now that we have a way to ensure the JDBC adapter is properly injected into Rails, and you no longer need to use adapter names like
jdbcsqlite3 and the like. The net result is that database.yml no longer needs to be modified for the default Rails databases (
postgresql). So while we introduced one additional step in the process to bootstrap a Rails application under JRuby, the removal the step where
database.yml needs to be modified results in a more predictable workflow.
The new JRuby-specific Rails workflow looks like the following, assuming you’ve installed the
activerecord-jdbc-adapter gem into JRuby, along with the appropriate database driver gem (e.g,
jdbc-mysql). (Of course, the gems only need to be installed once per JRuby installation.)
- Create your Rails application as usual.
- Run the
jdbc generator as shown above.
Additionally, if you maintain a Rails application template that you use to start a new application, you can simply add
generate(:jdbc) to that template’s script.
What’s more, the presence of the JDBC files in your application are guarded and only inject JDBC support when running under JRuby, so you can safely keep them around when running Rails under multiple Ruby implementations.
For more details of what’s in the release please consult the mini-changelog on Rubyforge and the list of fixed issues in JIRA.
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
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:
Re-run your migrations, and you should now see a Derby database footprint in the
$ ls -l db/development
-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.
Posted by Nick Sieger
Sun, 02 Sep 2007 04:47:26 GMT
This one’s a bit late -- consider it part of my get-caught-up-since-unclogging-the-clogged-blog series.
ActiveRecord JDBC 0.5 is out, so you may have heard (it went out the door a week ago Friday; c.f.
Arun and Tom). The major feature you get in this version is a new
Ok, ok, so what’s the big deal? This is just Rails’ default database configuration. Well, that’s the
point -- you no longer have to know anything about JDBC URLs, driver class names, and all that. We’ve baked it in for you. This should make it easier than ever to try out your Rails application on JRuby, as the only piece of manual configuration left for you is the ugly bit of JRuby-specific code you need to activate ActiveRecord-JDBC lurking right above the
if RUBY_PLATFORM =~ /java/
If we can obliterate the need for this last bit of code, and make it easy to obtain the necessary driver bits, I’ll feel good enough to call this thing a 1.0 product.