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.