JDBC params are ignored by ruote-rest on JRuby

3 views
Skip to first unread message

Nando

unread,
Jun 26, 2009, 7:04:48 AM6/26/09
to Ruote (OpenWFEru) users
Hi everyone,

As you might have guessed, we are in the midst of a ruote-rest+JRuby
testing frenzy. This issue has to do with the way "ruote-rest/lib/
database.yaml" is parsed, given that you use a JDBC driver, instead of
the convenience "adapter: jdbcXXX". For instance:

development:
adapter: jdbc
driver: com.mysql.jdbc.Driver
url: jdbc:mysql://localhost/ruoterest_development
username: rueda
password: secret

Now, you'd add "mysql-connector-java-5.0.8-bin.jar" to your CLASSPATH,
or maybe do a:

if RUBY_PLATFORM =~ /java/
require "#{RUOTE_BASE_DIR}/lib/jars/mysql-connector-java-5.0.8-
bin.jar"
end

before racking up ruote-rest.
(Note that I'm using MySQL for the test. Any other non-mysql driver
could do as well)

Under these circumstances JRuby would use the more generic
"activerecord-jdbc-adapter" [1]

Well, then let's fire the freshly git-cloned app: jruby --server lib/
start.rb

Now, open a browser and proceed to the web frontend: an exception!

TypeError at /
can't convert nil into String
Ruby /opt/jruby/jruby-1.3.1_x64/lib/ruby/gems/1.8/gems/activerecord-
jdbc-adapter-0.9.1/lib/active_record/connection_adapters/
jdbc_adapter.rb: in driver_class, line 240

After some raising and pprinting, I got the config params
"activerecord-jdbc-adapter" gets from ruote-rest:

#<ActiveRecord::Base::ConnectionSpecification:0x6cc
@adapter_method="jdbc_connection",
@config=
{:adapter=>"jdbc",
:database=>nil,
:username=>"root",
:password=>"2secure",
:host=>nil,
:encoding=>nil,
:pool=>30}>

To my surprise, "adapter" and "driver" are missing. Which led me to
"ruote-rest/lib/ar_conn.rb":

41 ActiveRecord::Base.establish_connection(
42 :adapter => configuration['adapter'],
43 :database => configuration['database'],
44 :username => configuration['username'],
45 :password => configuration['password'],
46 :host => configuration['host'],
47 :encoding => configuration['encoding'],
48 :pool => 30
49 )

It seems that only the parameters above reach activerecord. That's OK
for Ruby, but for JRuby + "activerecord-jdbc-adapter" to work, it
would be necessary to add these:

:driver => configuration['driver'],
:url => configuration['url'],

And, if you want to warble the app, thus using it on an application
server (then skip what I wrote about the CLASSPATH and the jar):

:jndi => configuration['jndi']

***
Having those extra lines added to "lib/ar_conn.rb" would help a lot to
those who wanted to take ruote-rest for a spin on JRuby. Besides, they
are quite harmless to Ruby's "activerecord".

Best regards. Have a nice weekend!
//nando

-------
[1] http://jruby-extras.rubyforge.org/activerecord-jdbc-adapter/

John Mettraux

unread,
Jun 26, 2009, 10:24:31 AM6/26/09
to openwfe...@googlegroups.com
On Fri, Jun 26, 2009 at 8:04 PM, Nando<nando...@gmail.com> wrote:
>
> Having those extra lines added to "lib/ar_conn.rb" would help a lot to
> those who wanted to take ruote-rest for a spin on JRuby. Besides, they
> are quite harmless to Ruby's "activerecord".

Hello Nando,

you are 100% right.

http://github.com/jmettraux/ruote-rest/issues#issue/4

Thanks a lot, have a nice week-end,

--
John Mettraux - http://jmettraux.wordpress.com

John Mettraux

unread,
Jun 29, 2009, 4:19:03 AM6/29/09
to openwfe...@googlegroups.com
On Fri, Jun 26, 2009 at 11:24 PM, John Mettraux<jmet...@openwfe.org> wrote:
> On Fri, Jun 26, 2009 at 8:04 PM, Nando<nando...@gmail.com> wrote:
>>
>> Having those extra lines added to "lib/ar_conn.rb" would help a lot to
>> those who wanted to take ruote-rest for a spin on JRuby. Besides, they
>> are quite harmless to Ruby's "activerecord".
>
> Hello Nando,
>
> you are 100% right.
>
>  http://github.com/jmettraux/ruote-rest/issues#issue/4

http://github.com/jmettraux/ruote-rest/commit/0901bd9236835294036ea9da85e8d3028b46bf40


Thanks again,

Reply all
Reply to author
Forward
0 new messages