There exists a medium size Java application that requires some refactoring.

We're thinking about moving towards JRuby on Rails. Mainly due to the productivity that Ruby on Rails offers but for the many existing plug ins which will reimplement the net logic.

However most from the application should remain in Java, we don't want to rewrite all of the business logic (specifically because it uses many Java technologies for example RMI).

An important factor for the refactoring is cleaning our database management, that is presently a mixture of hands coded SQL procedures plus some objects saved in db4o.

From JRuby we are able to call any legacy java code. Great!

However many Ruby on Rails plug ins asume using ActiveRecord to handle the database. Being able to access the ActiveRecord data from Java appears non trivial.

That is best technique to manage the database between JRuby on Rails and also the legacy Java code?

  • We're able to use db4o for everything, but would loose the advantage of some Ruby on Rails plug ins, and will have to manage objects "by hand" around the Ruby side
  • We're able to use ActiveRecord for everything and define some type redundant mapping around the Java side. Which will be the best strategy?
  • We'd make use of a Java ORM technology (Hibernate, Cayenne?) after which map the model in ActiveRecord. So how exactly does this concept rival the prior one?
  • Are we able to perform some miracle using Jruby 1.4 become_java!?

What is your opinion?

JRuby is a superb language but it's really Ruby running around the Java Virtual Machine. You'll be able to integrate legacy Java code in however it does not fit well in to the core language.

If you are looking at a brand new dynamic language having a solid web framework, I recommend searching at Groovy and Groovy is develop the JVM. You legacy classes could be top class citizen within the application. I believe this is much simpler emigrate to new things since you can reuse that which you have, spinning the various components you'll need.

It may sound like you are likely to perform a a great deal of refactoring around the Java side additionally to writing new code in Ruby. That being the situation, I'd recommend:

1) pick a Java ORM: Hibernate or db4o, and employ it moving forward in most your Java refactorings. Around Let me say, use ActiveRecord for everything, tha harsh truth here's that it's going to considerably simpler to convince JRuby to utilize a Java ORM than it might be to coerce your Java code into dealing with ActiveRecord objects.

2) You will find a minimum of prototype-good examples of Ruby connects for Hibernate and db4o. Locate one to enable you to get began, after which add onto it as being required to supply the ORM capabilties you'll need.

3) Don't be concerned about Rails plug ins that expect ActiveRecord. Not every do, as well as less will later on as Rails 3 (the merger of Rails and Merb) uncouples ActiveRecord. And even when there is a wordpress plugin that you simply absolutely need to have that does require ActiveRecord, what exactly? It is simply Ruby code. Download it, see what it really needs, and throw together a facade class for the ORM to supply the techniques the wordpress plugin wants. (Ideas see the good thing about Ruby--an item does not need to <> a duck as lengthy because it saunters and quacks like one). Alternately, you are able to monkey patch the wordpress plugin to get rid of the ActiveRecord dependency, or just implement the functionality the wordpress plugin provides yourself. Your circumstances will probably dictate which of individuals approaches is sensible.