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"

We are devoted to helping our program members have the
greatest from their private healthcare overseas.

my homepage – medical insurance nz – ruspoc.ru -

By having you spend a share of the statement beginning with the first dollar just how
options without any function that is deductible is.

Here is my web page – health insurance nc

By selecting a strategy that addresses simple medications simply you may be preserving a lot
of money each month for you medical insurance malaysia
[http://www.comercialvolare.com]
premium.

To get a monthly charge, they provide you with entry to wellness vendors who provide lower costs.

Here is my web-site … http://thestratuszone.com/viewtopic.php?pid=298435

Hello there, You’ve done a fantastic job. I’ll certainly
digg it and personally suggest to my friends.
I am sure they’ll be benefited from this site.

Locate wise practice strategies for picking on great prospects
and distinguishing the telltale symptoms of the dubious opportunities.

Feel free to visit my webpage … forex trading reviews (http://forums.cat.com/t5/user/viewprofilepage/user-id/37461)

After you have a trading strategy, stick
to it and don’t transform it due to your greediness.

My web site: https://www.eventbrite.com/e/best-forex-brokers-tickets-18349758622

Many new dealers who attempt trading using their finances of skills that are trading in forex trading (http://kitouyuka.s25.xrea.com)
free money very quickly because of the inexperience and lack.

An investor must remember that both largest feelings in trading are dread and
greed before getting brain into the forex trading basics (http://furniture.biz.ua) industry.

It’s also include with 4 trading signals forex brokers that accept us residents you need
to put in into specialist platform.

Metatrader is just a forex trading lessons free and planning program that you business and can investigation with-it.
MT4 expert advisor suggests Metatrader 4 specialist consultant.

The impetus that arises from having the ability to identify option and get ideas from foreign currency markets all over
the world is sought by active top u.s. forex brokers investors.

Until you have realized the skills you have to generate profits trading the forex
you, however, will not risk a dime.

Look into my web-site … http://cgi.geocities.jp/kanahodobb/cgi-bin/schedule/scheduler.cgi?mode=view&no=506

You have to rely upon your forex currency trading training as well as oneself to
reach the degree of elite forex trading tutorial; math1tour.co-story.net, trader.

Join the Free eCourse on forex brokers australia (Gabriella) Trading of John Eather Keep up currently with
the latest info concerning Computerized Trading.

Ailments in the trial account cannot often reasonably reveal all the market
conditions that may affect pricing and execution in a
live trading environment.

Feel free to visit my web site – forex brokers usa (Isabella)

OK, our principal function is always to build an automatic forex trading signals (http://www.caliltattoo.com.br) technique that could supply $1Million in 2010.

Developing a forex trading software, http://semya.muslim.kz/?option=com_k2&view=itemlist&task=user&id=131576, plan is
crucial to trading objectively in place of on gut sensation, any broker
trading on his feelings is at risk of sacrificing his cash!

When choosing a brokerage, it’s necessary to study critiques and do your investigation.

Also visit my web site: http://raul.gallery/index.php/item/212-colibr%E9%93%86-

Following the class you’ll have entry to our Pro
Data Startup movie line showing you change and
how to get your system that is planning.

Stop by my page :: http://cgi.www5c.biglobe.ne.jp/~mokada/cgi-bin/g_book.cgi

Forex trading entails purchases in which one-party
expenditures a volume of one currency by spending in a
level of another currency.

Also visit my blog post … http://www.peopleneedhelp.org/members-44/shanicethynne/activity/1375484/

While still generating above normal results, an automatic forex
trading training (transdanant.com)
account works together with minimal influence to limit danger.

The chance is arriving not just from forex trading platforms currency trading but additionally
out of your selections.

For the present time, your emphasis must squarely be on understanding trading using
forex currency trading tools’ basics.

Stop by my web-site … http://rennes.catholique.fr/spip.php?page=recherche&recherche=http%3A%2F%2Fforums.cat.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F37461&debut_articles=495

Acquire that teaching task of your desires with tricks and these tips from a teacher who completed
that and ‘s been there.

Look at my web-site … forex trading reviews (http://mlpburitialegre.com/index.php/c%C3%A9lulas/mensagens/item/137-vestibulum-sit.html?ref_ucid=ad157a02027a15ad0001027a15ad)

The business delivers trading cars about the foreign exchange markets but also expands its podium to commodities and stock trading.

Have a look at my homepage … http://www.apextrainingafrica.org/index.php/component/k2/itemlist/user/298398

InstaForex providers are of a wonderful curiosity for more
than 2 000-000 forex brokers in cyprus professionals all around the planet today.

You are going to discover two amounts on the forex
brokers list – Dulcie – quote: the bet value on the
remaining and the request value about the right.

A powerful economy could have a strong currency plus a negative economy might
have a currency that is weak.

My website – forex brokers canada

You identified the fantastic new earth of currency trading and now you would like to generate profits out of your new
discovery.

my homepage :: http://cgi.geocities.jp/kanahodobb/cgi-bin/schedule/scheduler.cgi?mode=view&no=572

When you are trading forex trading signals (pittinglish.com),
the spread (the variation between your purchase and sell
cost of a currency match) comprises the price of trading.

I highly recommend testing any EA’s on a simulated forex account before
activating it on your consideration that is genuine!

Also visit my page … http://massbands.org/wiki/index.php?title=User:BetseyWoodard53

Finally, maybe one of the most significant factors when selecting
Metatrader Forex Brokers to consider is their capability to make you cash.

Also visit my homepage :: http://100.fdnufh.com/prediksi-chelsea-vs-shakhtar-donetsk/

On several forex trading in india assets, you will discover that arbitrage is performed to be able to take advantage of pricing disturbances.

Good info. Lucky me I discovered your blog by
chance (stumbleupon). I have saved as a favorite for later!

What are NADEX bull spreads provide a full fresh angle on derivative trading on products, share indexes and forex brokers in cyprus (www2u.biglobe.ne.jp).

This is why, when contemplating and selecting trading on Forex, you must consult with a financial
manager or an expert forex trading basics trader first.

It’s important which you figure out your trading approach; before lodging
many money if you begin your currency trading.

my web page; forex brokers uk [Camilla]

How big is a pip in currency forex trading for dummies (lifeafter50.com.au) depends on which currencies
are being exchanged.

Heya! I realize this is sort of off-topic however I had to ask.

Does running a well-established website such as yours take a
lot of work? I’m completely new to writing
a blog but I do write in my diary everyday.
I’d like to start a blog so I can easily share my experience and thoughts online.
Please let me know if you have any kind of ideas or tips for brand new aspiring
bloggers. Thankyou!

It is an information into what it requires to produce a binary options
trading system that is successful.

Here is my web page forex brokers inc (http://sendmoneycheaper.com/moneytransfer/2014/03/27/send-money-cheaper/)

Ultimately, you wish to study a strategy from an individual who is currently not unsuccessful using the same tactic.

my weblog – http://www.paw.hi-ho.ne.jp/cgi-bin/user/garuu/yybbs.cgi

You’ll also not be unable to try the quality of other
and help solutions FX broker promises to offer.

Feel free to surf to my homepage :: forex trading software (http://www.world-aluminium.org)

Therefore; you must make sure that you have the appropriate
information about the rate of a given country whose currency you wish to industry.

Also visit my web site: http://grindstop.com/groups/web-trading-tools-suitable-perhaps-for-your-beginner/

In any given marketplace, day trading basically
signifies trading of currency inside a given amount of time.

Visit my webpage … http://www.hi-tekss.com/?option=com_k2&view=itemlist&task=user&id=286900

While a political put up would have a currency varying horribly for example a strong political base would provide
a continuous and every improving currency.

Feel free to surf to my web site: forex brokers rating (http://www.natiscrea.ch)

The main benefits of currency forex trading signals [my.jbssoft.co.kr] are
you may make money while residing at home
and that you want a relatively modest original deposit to start
trading.

We’re a group of volunteers and opening a new scheme in our community.
Your web site provided us with valuable information to work on.
You have done an impressive job and our whole community
will be grateful to you.

Fap Turbo can be an appealing automated currency trading software,
that tested and has been most widely used for over 9 years.

my weblog – http://plantenmaes.com/?option=com_k2&view=itemlist&task=user&id=121835

Switching values from various places was a hazardous and risky exchange, frequently performed by
multinational companies in concert with huge trading homes.

Here is my web site: http://makemoneyonline.net.in/data/mw/index.php?title=How-To_Put_In_Place_A_Forex_Currency_Trading_Company_7_Methods

Leave a Reply