Tuesday October 06, 2009
TOTD #110: JRuby on Rails application using Oracle on GlassFish
GlassFish v3 is the Reference Implementation for Java EE 6. Following the "extensibility" principle of Java EE 6, it also allows Ruby-on-Rails, Groovy and Grails and Python/Django applications to be seamlessly deployed as well, without any additional packaging. This blog has published multiple entries on deploying a Rails application on GlassFish as given below:
All the existing applications have used JavaDB, SQLite3, or MySQL as the database so far. In the process of getting ready for the upcoming Oracle Open World 2009, this Tip Of The Day will show how to use an Oracle database with a JRuby-on-Rails application deployed on GlassFish v3.
Lets get started!
>./bin/jruby -S gem install glassfish
JRuby limited openssl loaded. gem install jruby-openssl for full support.
http://wiki.jruby.org/wiki/JRuby_Builtin_OpenSSL
Successfully installed rack-1.0.0
Successfully installed glassfish-0.9.5-universal-java
2 gems installed
Installing ri documentation for rack-1.0.0...
Installing ri documentation for glassfish-0.9.5-universal-java...
Installing RDoc documentation for rack-1.0.0...
Installing RDoc documentation for glassfish-0.9.5-universal-java...
Macintosh-187:~ oracle$ sqlplus "/ as sysdba"
SQL*Plus: Release 10.2.0.4.0 - Production on Thu Oct 1 12:32:33 2009
Copyright (c) 1982, 2007, Oracle. All Rights Reserved.
Connected to:
Oracle Database 10g Release 10.2.0.4.0 - Production
SQL> CREATE USER glassfish IDENTIFIED BY glassfish DEFAULT tablespace users TEMPORARY tablespace temp;
User created.
SQL> GRANT CONNECT TO glassfish IDENTIFIED BY glassfish;
Grant succeeded.
SQL> GRANT UNLIMITED TABLESPACE TO glassfish;
Grant succeeded.
SQL> GRANT CREATE TABLE TO glassfish;
Grant succeeded.
SQL> GRANT CREATE SEQUENCE TO glassfish;
Grant succeeded.
SQL> exit
Disconnected from Oracle Database 10g Release 10.2.0.4.0 - Production
The user name and password are chosen as "glassfish" for simplicity. This is not a recommended setting for production usage though.
rails (2.3.4)
activerecord-jdbc-adapter (0.9.2)
glassfish (0.9.5)
jruby -S gem install rails activercord-jdbc-adapter glassfish
jruby -S rails bookstore -d oracle
ActionView::TemplateError (book_url failed to generate from {:controller=>"books", :action=>"show", :id=>#<Book id: #<BigDecimal:3feef1eb,'10000.0',1(8)>, title: "Ultramarathon Man", author: "Dean Karnazes", created_at: "2009-10-06 00:03:14", updated_at: "2009-10-06 00:03:14">}, expected: {:controller=>"books", :action=>"show"}, diff: {:id=>#<Book id: #<BigDecimal:459bdb65,'10000.0',1(8)>, title: "Ultramarathon Man", author: "Dean Karnazes", created_at: "2009-10-06 00:03:14", updated_at: "2009-10-06 00:03:14">}) on line #13 of app/views/books/index.html.erb:
bookstore >~/tools/jruby/bin/jruby -S gem install activerecord-oracle_enhanced-adapter
JRuby limited openssl loaded. gem install jruby-openssl for full support.
http://wiki.jruby.org/wiki/JRuby_Builtin_OpenSSL
Successfully installed activerecord-oracle_enhanced-adapter-1.2.2
1 gem installed
Installing ri documentation for activerecord-oracle_enhanced-adapter-1.2.2...
Installing RDoc documentation for activerecord-oracle_enhanced-adapter-1.2.2...
development:
adapter: oracle_enhanced
host: localhost
database: orcl
username: glassfish
password: glassfish
bookstore >~/tools/jruby/bin/jruby script/generate scaffold book title:string author:string
JRuby limited openssl loaded. gem install jruby-openssl for full support.
http://wiki.jruby.org/wiki/JRuby_Builtin_OpenSSL
exists app/models/
exists app/controllers/
exists app/helpers/
create app/views/books
exists app/views/layouts/
exists test/functional/
exists test/unit/
create test/unit/helpers/
exists public/stylesheets/
create app/views/books/index.html.erb
create app/views/books/show.html.erb
create app/views/books/new.html.erb
create app/views/books/edit.html.erb
create app/views/layouts/books.html.erb
create public/stylesheets/scaffold.css
create app/controllers/books_controller.rb
create test/functional/books_controller_test.rb
create app/helpers/books_helper.rb
create test/unit/helpers/books_helper_test.rb
route map.resources :books
dependency model
exists app/models/
exists test/unit/
exists test/fixtures/
create app/models/book.rb
create test/unit/book_test.rb
create test/fixtures/books.yml
create db/migrate
create db/migrate/20091005233152_create_books.rb
bookstore >~/tools/jruby/bin/jruby script/generate jdbc
JRuby limited openssl loaded. gem install jruby-openssl for full support.
http://wiki.jruby.org/wiki/JRuby_Builtin_OpenSSL
exists config/initializers
create config/initializers/jdbc.rb
exists lib/tasks
create lib/tasks/jdbc.rake
~/samples/v3/rails/oracle/bookstore >~/tools/jruby/bin/jruby -S rake db:migrate
(in /Users/arungupta/samples/v3/rails/oracle/bookstore)
== CreateBooks: migrating ====================================================
-- create_table(:books)
-> 0.0740s
-> 0 rows
== CreateBooks: migrated (0.0750s) ===========================================
~/samples/v3/rails/oracle/bookstore >~/tools/jruby/bin/jruby -S glassfish -l
Starting GlassFish server at: 129.145.133.197:3000 in development environment...
Writing log messages to: /Users/arungupta/samples/v3/rails/oracle/bookstore/log/development.log.
Press Ctrl+C to stop.
Oct 6, 2009 9:45:51 AM com.sun.enterprise.v3.services.impl.GrizzlyProxy start
INFO: Listening on port 3000
. . .






So we created a brand new JRuby/Rails application and ran it using GlassFish and Oracle backend. A subsequent blog entry will show how to create a similar application using an existing database.
A complete archive of all the TOTDs is available here. The complete list of Rails blog entries are available here.
This and other similar applications will be demonstrated at the upcoming Oracle Open World.
Technorati: totd oracle database glassfish v3 jruby rails oow
Posted by Arun Gupta in General | Comments[0]
|
|
|
|
|
Today's Page Hits: 190
Total # blog entries: 1002