Nick Sieger: JRuby on Rails and ActiveRecord on JDBC http://blog.nicksieger.com/articles/2006/05/15/jruby-on-rails-and-activerecord-on-jdbc en-us 40 JRuby on Rails and ActiveRecord on JDBC <p><a href="http://www.bloglines.com/blog/ThomasEEnebo?id=16">Tom</a> and <a href="http://headius.blogspot.com/2006/05/and-they-said-jruby-was-dead.html">Charlie</a> have just experienced what can only be described as a watershed moment in the grand scheme of dynamic languages on the JVM&#46; The Rails experience may soon be visiting a Java application server near you! Even though JRuby will be in perpetual catch&#45;up mode with C Ruby, Tom and Charlie and the rest of the JRuby contributors have shown incredible perseverance in tracking the Ruby language despite <em>the lack of any formal specification</em>&#46; Maybe Rails will never be mainstream, but the possibilities just got a whole lot more interesting&#46; I agree with <a href="http://jroller.com/page/obie?entry=jruby_on_rails_is_born">Obie</a> that this could be a game&#45;changer&#46;</p> <p>Now, a few comments about the ActiveRecord JDBC adapter&#46; This code can still be considered alpha quality at best&#46; It&#8217;s awesome that Tom and Charlie will be able to demo a top&#45;to&#45;bottom, working Rails app on JRuby, but don&#8217;t jump to conclusions yet that this will be anything like a write&#45;once, deploy&#45;to&#45;any&#45;database kind of experience&#46; But you didn&#8217;t think it would, did you? We all learned that about Java a long time ago, right?</p> <p>You can <a href="http://svn.caldersphere.net/svn/main/activerecord-jdbc/trunk/">check out the code here</a>&#46; At the moment, I&#8217;ve only tried it with MySQL&#46; Most of the problems with it come from the lossy mapping from ActiveRecord&#8217;s abstraction of the database to JDBC&#8217;s&#46; (Although I suspect as more JDBC drivers are tried that there will eventually be compatibility issues with different implementations of the JDBC spec&#46;)</p> <p>Probably the thorniest issue is the one of type conversion&#46; ActiveRecord has a fairly simple notion of types: <code>:string, :text, :integer, :float, :datetime</code> etc&#46; Compare this to <a href="http://java.sun.com/j2se/1.4.2/docs/api/java/sql/Types.html">JDBC&#8217;s</a>&#46; What a mess! Right now there are arrays of <code>proc</code>s for each AR type that try to guess the best JDBC type to use&#46; This will certainly need improvement to become a more robust solution&#46;</p> <p>Probably the most promising approach may be to create a patch that refactors much of the AR adapters&#8217; type conversion methods into separate modules that could be included into instances of the JDBC adapter depending on the underlying database&#46; Then the JDBC types wouldn&#8217;t be needed at all &#45;&#45; the existing AR database metadata could be reused&#46; Presumably this would require some petitioning of the Rails core team to accept the changes even though the changes don&#8217;t buy AR itself any additional flexibility&#46;</p> <p>If you have a chance to try out the code or can think of any additional tricks that would help the ActiveRecord JDBC implementation along, let me know!</p> Mon, 15 May 2006 03:12:00 +0000 urn:uuid:091b1464-16fe-49ee-9d4b-ce18ddf2da0d Nick Sieger http://blog.nicksieger.com/articles/2006/05/15/jruby-on-rails-and-activerecord-on-jdbc java ruby jruby rails http://blog.nicksieger.com/articles/trackback/13