Inspired by Charlie's reports of progress on the generator scripts, I wanted to chime in here that I'm making some small progress on using ActiveRecord on JRuby.  I've been putting in a couple hours here and there and have been able to require ActiveRecord, connect to a MySQL database over JDBC, and execute a manual select statement over the JDBC connection.  I'm not really exercising the real ActiveRecord magic yet, hopefully once I get the JDBC adapter more flushed out progress on that will come much more quickly.

A couple of questions:

* I've been writing all ruby code so far -- if I package up a patch, where should this code go?  Do the other developers have a standard place where you're installing Rails code?  I have a directory in my tree called "site-lib" (looking for a better name/place) into which I downloaded Rails 1.0, and in my test scripts, I'm doing the following.  I also have my jdbc_adapter.rb in a src/vendor directory.

$:.unshift(File.dirname(__FILE__) + '/../../src/vendor')
$:.unshift(File.dirname(__FILE__) + '/../../site-lib/rails/vendor
/rails/activerecord/lib')
$:.unshift(File.dirname(__FILE__) + '/../../site-lib/rails/vendor/rails/activesupport/lib')

* Any suggestions on the best way to convert java.sql.Date, Time, and Timestamp to ruby equivalents?  RIght now all I have is Time.at(javaDate.getTime()) which doesn't seem to be appropriate.

Here's what I have working.  I had to run a regular ruby setup script 'confidenceBuilderSetup.rb' in the zip [1] to get the MySQL database and table set up.

require 'test/minirunit'
require 'test/rails/pathsetup'
RAILS_CONNECTION_ADAPTERS = ['abstract', 'jdbc']
require 'active_record'

connspec = ActiveRecord::Base.establish_connection(
  :adapter  => 'jdbc',
  :driver   => 'com.mysql.jdbc.Driver',
  :url      => 'jdbc:mysql://localhost:3306/weblog_development',
  :username => 'blog',
  :password => ''
)

connection = ActiveRecord::Base.connection

results = connection.execute "select * from entries"

test_equal results.length, 1

row = results.first
test_equal 'First post', row['title']
test_equal 'First post d00d!', row['content']

puts row.inspect

Comments appreciated!

/Nick

[1] http://radio.weblogs.com/0141460/gems/ar-early.zip

Reply via email to