BSF, JRuby and ActiveRecord

3 10 2006

I’ve had some success on my current project. The other day I wrote a Ruby script that runs in JRuby and updates SQLServer using a JDBC connection. I used ActiveRecord and ActiveRecord – JDBC (both very hot). Tonight I embedded JRuby in a Java process using BSF and was still able to successfully execute the script. I discovered that, once the ActiveRecord stuff initializes during the first execution, each subsequent execution runs well. I figured that would be the case, but it’s always nice to have the proof.

Next, I’d like to extend the ActiveRecord – JDBC so that it will retrieve connections from a JNDI Datasource. If anyone’s already done some work in that direction, I’d be interested in hearing about it.

Advertisements

Actions

Information

4 responses

3 12 2006
Fred

Hi,

Looks like you have some experience with Java and Activerecord/Jruby and I am experiencing some pb to run jruby from java… to be more precise I want to write into a database but am getting:
org.jruby.exceptions.RaiseException: undefined method `cattr_accessor’ for ActiveRecord::Base:Class

with

runJRuby.evalScript(“require \’active_record/connection_adapters/jdbc_adapter\'”);

Hope you can help. Thanx in advance.

Fred

3 12 2006
kofno

Make sure that you require ‘active_record’ before using ActiveRecord::Base.

4 12 2006
Fred

Thanx I will trie that.
One other question… JRuby is new for me, do you know nice tutorials that explain how to call JRuby from Java? I only found tutorial to do it the other way around.

4 12 2006
kofno

Here’s how you embed JRuby using BSF:
http://www.headius.com/jrubywiki/index.php/Java_Integration

After that, you call it like you would any other BSF enabled scripting language.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s




%d bloggers like this: