dcsimg

Rails vs. Grails vs. Helma: The JVM Web Framework Smackdown, Part 1

It's the ultimate JVM Web Framework Smackdown! Three will enter the cage. Only one will exit the victor. Will it be JRuby on Rails? Groovy on Grails? Or Helma?

Before the advent of Ruby on Rails, many Web developers worked with Perl or vanilla PHP. Perl’s legacy dated back to the earliest dynamic Web sites. In heady days, the “Perl Mongers” were active proponents and evangelists, and the community nurtured and maintained a vast repository of contributed code. PHP was simple to learn, a snap to deploy and host on virtually any platform, and thus quickly earned a devout following. Indeed, both languages grew popular because it was easy to start an application. However, as Perl and PHP applications grew, developers inevitably became tangled in a mess of code.

Other developers eschewed scripting languages and opted for more heavyweight Web frameworks, especially those written in Java. Applications written in Java were bullet-proof and backed by a rich set of libraries, but were far from perfect, too. Java frameworks exacted a high price, miring developers in the pits of XML hell. While the Java frameworks scaled well, the initial inertia left many Java web developers jealous of the rapid, early progress Perl and PHP developers enjoyed.

Ruby on Rails, to a large degree, delivered the best of both worlds. Rails featured a well-thought out organization that guided developers toward a clean MVC design, and through a philosophy of Convention over configuration, developing new applications was only marginally more difficult than with straight PHP. Web developers, it seemed, could finally have it both ways.

But the story does not end with the advent of Rails. More and more sites began to use Rails, but as several endeavors became successful, developers also ran into new challenges. Twitter gained notoriety when the company moved part of its architecture to Scala. And, despite the benefits of Rails, many developers have begun to miss the wealth of libraries and tools commonly found with Java.

Fortunately, several Java frameworks now combine ease and robustness. Relying on JVM scripting languages and the Rails philosophy of convention over configuration, these new frameworks provide the flexibility of Rails and the enterprise-worthy support of Java. This article compares three of the most promising modern Java frameworks: JRuby on Rails (JRoR); Grails, powered by Groovy; and Helma, with Rhino JavaScript.

The Sample Application: PenguinMusic

To test JRoR, Grails, and Helma, let’s build a music site from scratch with each framework. The sample site, PenguinMusic (shown), allows users to browse songs ordered by popularity, view details about an artist and album, and leave comments if logged in to the application. The application also handles user registration.

While this sample application does not take advantage of all the bells and whistles each framework offers, it does focus on a core subset of features that virtually every website must provide, including database interaction, user authentication, and form handling. The sample code also looks at automated testing and site administration to some extent. However, no attempt is made to build facilities for Ajax or address performance. Not every site needs Ajax support, and all these frameworks have at least adequate performance for the bulk of Web applications. The focus here is the ease of launching a new application.

Each of the three frameworks ships with an embedded databases, but odds are MySQL is your choice for a production database, so that’s what’s demonstrated here. However, since all the candidate frameworks rely on JDBC, you can interact with just about any major database engine.

If you would lke to follow along, you can download the source code for each implementation. Additionally, there are some helpful scripts to load test data for each of the database setups.

JRuby on Rails: The Classic, Now Playing at Your Local JVM

If you want the benefit of a Ruby on Rails-like framework for the JVM, one obvious option is, well, Ruby on Rails. The JRuby team has been focused on Rails from the beginning, and with JRuby 1.0, the team finally achieved full Rails compatibility. Performance was terrible initially, but the developers have done a great deal of work since and more recent versions are quite fast.

The source code for the JRuby on Rails implementation of PenginMusic can be downloaded here.

Getting Started with Rails, the JRuby Way

Installing JRuby on Rails is only a little more complicated than installing traditional Rails. You must download Gems and install it with JRuby and install the requisite libraries. The command to use is:

 $ jruby -S gem install mongrel activerecord-jdbcmysql-adapter rails
 

Running jruby -S rails jrorPM -d mysql creates a new application named jrorPM based on MySQL. After the initial code generation, your first task is to edit config/database.yml to match your database configuration. In particular, you must specify jdbcmysql as the adapter.

development:
  adapter: jdbcmysql
  encoding: utf8
  reconnect: false
  database: jrorPM_development
  pool: 5
  username: root
  password:
  socket: /tmp/mysql.sock

# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
test:
  adapter: jdbcmysql
  encoding: utf8
  reconnect: false
  database: jrorPM_test
  pool: 5
  username: root
  password:
  socket: /tmp/mysql.sock

production:
  adapter: jdbcmysql
  encoding: utf8
  reconnect: false
  database: jrorPM_production
  pool: 5
  username: root
  password: 
  socket: /tmp/mysql.sock

Once the database has been configured, jruby -S rake db:create:all initializes the database, and jruby script/server starts the application.

Rails Models and Migrations

One of the hallmarks of Rails implementations is that the structure of the data model lives solely in the database. This avoids any repetition of logic, a core tenet of Rails’s Don’t Repeat Yourself (DRY) philosophy. However, most of the validation logic lives in the Ruby models. As a result, one must switch between the database table and the Ruby class to get a complete picture of the model. However, this is a relatively minor hindrance, as the strong connection between the database and the model class is one of Rails’s greatest strengths.

Once upon a time, Rails developers used SQL to create models, but the practice has gradually fallen out of favor. Today, developers are encouraged to use migrations instead. Migrations are Ruby scripts that create or update a database schema. A migration is also database-independent and is fairly straightforward to use. Migrations also offer an important advantage: versioning. Historically, tying a database version to a code version has been problematic. Migrations offer a solution.

However, migrations can also be brittle. If there is a problem in any of the migration scripts, the database can become stuck in an unusable state, forcing you to resort to SQL to fix the problem anyway. Migrations also are noticeably lacking in features. For instance, foreign key constraints are not available without a plugin.

SQL does provide fine-grained control and is an option with Rails, although you may be heckled by some Rails fanatics if you choose to use it. Here, let’s stick with migrations since they are the more conventional approach.

The Rails generate script creates new models and other components from the command line. Specify model as the first argument if you just want to create the required model class. More often than not, though, you’ll want to specify scaffold instead to generate a model and complementary administrative pages to create, edit, and delete records. The second argument to generate is your model name, and the remaining arguments are name:type pairs, one pair per field. (You can actually omit all of the fields and manually edit the migration script yourself if you prefer.)

To generate the code for the Song model and scaffold, the command is:

$ jruby script/generate scaffold song name:string album_id:integer \
  track_num:integer playlist_url:string duration_in_seconds:string \
  num_downloads:integer

The command creates a file named db/migrate/*_create_songs.rb (the * is a serialized value that orders the migrations in a sequence) with the following contents:

class CreateSongs < ActiveRecord::Migration
  def self.up
    create_table :songs do |t|
      t.string :name
      t.integer :album_id
      t.integer :track_num
      t.string :playlist_url
      t.string :duration_in_seconds
      t.integer :num_downloads

      t.timestamps
    end
  end

  def self.down
    drop_table :songs
  end
end

Although you can use this migration as-is, let’s modify the code to improve the database representation. Let’s make album_id and name required fields and let’s assign a default value for num_downloads. This requires changes to three lines:

      t.string :name, :null=>false
      t.integer :album_id, :null=>false
      ...
      t.integer :num_downloads, :default=>0

The process is repeated for the other models, followed by a database update:

$ jruby script/generate scaffold album artist_id:integer genre_id:integer \
  title:string public_id:string url:string album_cover_url:string \
  album_cover_name:string price:float blurb:text
$ jruby script/generate scaffold artist name:string url:string
$ jruby script/generate scaffold genre name:string code:string
$ jruby script/generate scaffold user username:string \
  password:string email:string admin:boolean
$ jruby script/generate scaffold comment user_id:integer album_id:integer \
  title:string body:text post_date:datetime
$ jruby -S rake db:migrate

As a final step, the models must be tied together. This is done through the has_one, has_many, belongs_to, and the concisely named has_and_belongs_to_many functions.
As an example, here is the model class for Album:

class Album < ActiveRecord::Base
  belongs_to :artist
  belongs_to :genre
  has_many :songs
  has_many :comments
end

Comments on "Rails vs. Grails vs. Helma: The JVM Web Framework Smackdown, Part 1"

Uninsurable people would be gathered together inside the Atlanta health insurance australia (aquart.it) insurance pool.

The utilization of mass- security has been extended by distribution practices
to more and more individual s with no health or lifestyle
medical insurance canada (http://razysoft.net/) or little.

This web site is operated by health insurance nc Broker
ActiveQuote Ltd listed in Wales & Britain corporation amount 6765845.

This insurance carrier is possessed doctor, by Mark.
He is connected to Piedmont Hospital in Atlanta.

My web blog http://jaljukja.dnip.net/xe/?document_srl=103147

Republicans offered answers, like the ability to purchase health insurance definition (indiapalacevb.com) across collections.

Request your physician what he gives for medical insurance than you’ll have a better comprehension why
more screening is ordered by the physicians.

Here is my homepage :: http://www.skl69.es/index.php/component/k2/itemlist/user/43983

Prior to the FDA was given the duty to manage the drug organizations this by the
way was.

Feel free to surf to my blog medical insurance knowledge

Our health plan merely covers essential healthcare and we even have prescription coverage with charges centered on income.

Stop by my blog :: medical insurance companies

But the health insurance florida; Bert, Reform regulation that is new
leaves this duty while in the insurance company fingers.

I just like the valuable info you supply on your articles.
I’ll bookmark your weblog and test once more right here frequently.
I am relatively certain I’ll learn many new stuff proper here!
Good luck for the next!

All you need to complete is enter your zip code
and browse through the list of prices offered, to pick one which best fits your needs.

My website … medical insurance nz, http://www.emailmeform.com,

Lack of medical health insurance can result in a breadwinner’s death,
further evoking the undesirable decline on family income.

Here is my web blog – http://nextepbusinessbuilder.com/profile-20031/info/

Photocopy bank cards your passport, travelers medical insurance
plans (http://www.datunams.lv/blogs/item/2-ka-neapzinati-nenogalinat-savu-datoru) policy amount
and contact range and some other important documents you could have with you.

The real target should really be about the quality of health insurance quotes (drone-wiki.xyz) care
and never individuals who are insured’s quantity.

A web site is also for that federal government in which a person how to obtain the health insurance deductible insurance in Texas they require and could possibly get additional information about
Medicare.

I’d undoubtedly avoid small insurance providers with significantly
less than 10 million in Belongings and 99.9% of Association options.

Feel free to surf to my web-site http://www.burakboru.com/index.php/tr/burak-boru-teknik-bilgiler/item/6-haberler.html?limitstart=0

Something or some problem that is manufactured
worse by the insanely bad state of our health care.

Feel free to visit my weblog; http://www.simonsonghurst.co.uk/?p=91

Uber motorists are technicians and have to understand
the tough waters of buying and choosing their own health coverage.

Feel free to surf to my site :: http://www.info-tunisie.com/index.php/k2-demo/world-news/item/14-a-joomla-template-responsive-for-news/14-a-joomla-template-responsive-for-news

She’s helped produce sectors for Health Care Journalists on health care reform’s Association and noted on diabetes within the South
Bronx.

Here is my web-site: http://gazony.com.ua/?option=com_k2&view=itemlist&task=user&id=271963

Organizations should contemplate each one of these alternatives
as they seek out the health insurance new york that is most effective.

I agree that it is not fair for people who have to purchase it independently aftertax
and that utilized for their medical insurance dubai – snaffit.com, pre tax.

The majority of medical insurance (http://www.volcanol.fr)
coverage have equally a co-pay and deductible you’re accountable to cover.

While medical insurance malaysia (italia-senza-vivisezione.org) companies
are in company to greatly help their buyers, they’re also mindful of the underside line-that is to exhibit a revenue at
yearend.

Every one of them have house medical insurance uk (todofierro.com.ar) to fund
the rebuilding of the house in case of other or hearth disasters.

Examine your insurance premiums, mine went up 25
% in 2011 25%, in 2010 and today we have received a another 25% with larger deductibles can increase.

My blog post :: http://wiki.wein-fulda.com/index.php?title=Benutzer:Isabell8297

Nevertheless, nowadays many health insurance uk
providers have transferred to event supervision of the
clients’ industry.

Currently I have no variety to speak to a human being about
finding an alternative to my renewed card.

Visit my page :: health insurance loading

Nevertheless the Healthcare Change legislation that is fresh leaves this job inside the medical insurance philippines provider palms.

Your small business may be eligible for group medical care health insurance comparison (adqpal.org.br) by meeting specific eligibility requirements.

America seemingly have dug themselves a large ditch that is great,
as much a healthcare is anxious.

My page … http://www.uinys.org/index.php/activites/annonces/item/7-soiree-pour-la-celebration-de-la-victoire-des-elephants

You might already be included when you have
medical insurance australia; http://immo-cps.lu/,
care insurance at home region, thus seek advice from your provider if you want extra cover to learn.

Even Mexico has public-health care, it isn’t up to requirements or US, nonetheless it is better than nada.

My homepage http://thecrimsonworld.jaypapp.org/guestbook/guestbook/

Based on the Family Foundation, medical insurance rates for a
family’s average charge increased from $ 5 375 last year, to $13.

my blog … http://www.onefloridadynasty.com/sliders/

Compare medical insurance charges and start from these links Inexpensive Medical Health Insurance Quotes –
// Chimerenka Odimba will be the publisher of several finance
based websites.

Feel free to surf to my web page: http://www.whitecom.org/xe/?document_srl=556169

These firms do whatever by questioning insurance while increasing
premiums with impunity they could to save money.

My blog post … http://thestratuszone.com/viewtopic.php?pid=270946

This can be also known as discount programs that
were medical insurance travel (Brianna) and it’ll also
work for the dentist with sessions.

Lower or reduce your automobile or car insurance premiums,
charges, premiums or payments.

Also visit my web blog … http://www.smiledesigns.co.ke/index.php/uniforms/ongata-rongai/potters-light-academy

Each time check or a service is conducted and Medicare won’t accept,
payment will be also denied by a private supplement insurance in most cases.

my site :: http://exotopedia.tk/index.php?title=U%C5%BEivatel:MeiWan84373462

Dentists have warned that cash strapped customers of people performing
their very own dental work could possibly be performing critical injury to their oral
health insurance quotes.

Corporations buy medical insurance comparison (leisure-games.net) to avoid impairment that is fiscal due to an action that would produce the organization prone
to a 3rd party.

Lots of people who did not get insurance for a rainy day have gotten in debt
as a result of inappropriate health care administration.

my web blog … http://blogphuot.info/component/k2/author/329732.html

And frequently, the collection strategy these were enrolled
in, within their compensation deal, is not too cheap to pay out of wallet, when you’re from a job.

Also visit my page … http://www.selinas.gr/index.php/gr/wood/energy/item/130-d18/130-d18

Whatever certainly one of us doesn’t be eligible for a, or however have medical insurance nz
(en.cyberacmepedia.kiev.ua)
benefits for – then a different does (medicines).

Simply fill in the EHIC form properly before your trip,
or verify that your card that is current remains not invalid.

my blog: http://www.dunie-d.kz/index.php/component/k2/item/42-erkin-k-resten-yzylordaly-paluandar-5-zh-lde-olzhalady/products/configure/

The so-called medical insurance uganda cover offered to those in a job, simply offers fulfillment in the head and for all functional uses is really a big zero.

By joining an organization health medical insurance plans [http://www.testfrog.ch/sam/index.php/index.php?option=com_phocaguestbook&view=phocaguestbook&id=1&Itemid=81&t=20/rss/news/index.xml]
policy at your place of work, you will not need to move a exam by
a doctor to become acknowledged.

Lately a health Insurance system was released by Health Authority
for their dependants as well as the government workers.

Check out my web-site :: http://teamtrump.co.kr/?document_srl=198925

Consequently, while visiting such nations, deciding on a medical care health insurance florida coverage with minimal coverage would suffice.

The company currently includes a take care of Uber in which people will find affordable medical health insurance card.

Leave a Reply