Nick Sieger: Tag java http://blog.nicksieger.com/articles/tag/java?tag=java en-us 40 do what you love 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. The Rails experience may soon be visiting a Java application server near you! Even though JRuby will be in perpetual catch-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>. Maybe Rails will never be mainstream, but the possibilities just got a whole lot more interesting. I agree with <a href="http://jroller.com/page/obie?entry=jruby_on_rails_is_born">Obie</a> that this could be a game-changer.</p> <p>Now, a few comments about the ActiveRecord JDBC adapter. This code can still be considered alpha quality at best. It&#8217;s awesome that Tom and Charlie will be able to demo a top-to-bottom, working Rails app on JRuby, but don&#8217;t jump to conclusions yet that this will be anything like a write-once, deploy-to-any-database kind of experience. 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>. At the moment, I&#8217;ve only tried it with MySQL. Most of the problems with it come from the lossy mapping from ActiveRecord&#8217;s abstraction of the database to JDBC&#8217;s. (Although I suspect as more JDBC drivers are tried that there will eventually be compatibility issues with different implementations of the JDBC spec.)</p> <p>Probably the thorniest issue is the one of type conversion. ActiveRecord has a fairly simple notion of types: <code>:string, :text, :integer, :float, :datetime</code> etc. Compare this to <a href="http://java.sun.com/j2se/1.4.2/docs/api/java/sql/Types.html">JDBC&#8217;s</a>. 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. This will certainly need improvement to become a more robust solution.</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. Then the JDBC types wouldn&#8217;t be needed at all &#8211; the existing AR database metadata could be reused. 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.</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 Haikus for thought <p><a href="http://arstechnica.com/news.ars/post/20060517-6854.html">Open</a> <a href="http://blogs.zdnet.com/Gardner/?p=2291">source</a> <a href="http://blogs.guardian.co.uk/technology/archives/2006/05/17/sun_says_it_will_make_java_open_source_eventually.html">Java</a>.<br/> Who could possibly fork it<br/> What? Not IBM!</p> <p>Open source Java<br/> Rather be hacking Ruby<br/> Too late to matter</p> <p>Open source Java<br/> Need dynamic languages<br/> Use JRuby now</p> Thu, 18 May 2006 02:48:00 +0000 urn:uuid:29165f72-1b5e-46e4-b1a2-a50b5850fbd7 Nick Sieger http://blog.nicksieger.com/articles/2006/05/18/haikus-for-thought java jruby opensource http://blog.nicksieger.com/articles/trackback/14