Thursday, February 26, 2009

JRuby on Rails: Rolling with Oracle 10g and Weblogic 10g (Part 1)

I've ran a sample app using JRuby (1.1.4 I think) and Oracle Weblogic 10 last October 2008. I had some challenge back then as you can see from this post and at the same time beginning rails.

Recently, I was working an 'enterprise' JRuby on Rails app requiring me to run it again on Weblogic 10 with Oracle 10g as database. I thought it will be seamless since I've done it before and I thought running on Oracle 10g is as simple as configuring the driver like what I always did back in J2EE. Unfortunately I ended app pulling out my hair once again trying to figure it all out. It was one hell of JRuby/Warbler/Jar/Windows/Oracle/Cygwin/Weblogic war!

To give you a background, I started running off with the ff:
  • Windows XP - as much as I don't want to develop on it,
  • JDK 1.5 - forgot which update; but don't worry I replaced it later on
  • JRuby 1.5
  • Rails 2.2.2
  • Cygwin

Rolling with Oracle 10g

I was quite happy with the app running very well on WEBrick and mySQL 5.x. All requirements (CRUD, screens, audit trail, logging, AJAX dropdown menus, etc.) were all satisfied. Then I first decided to migrate the database to Oracle 10g. So I installed Oracle XE and below was what I did to get it running.

Step 1: Installed Oracle 10g Express Edition - painless; I don't think I have to upgrade JDK at this point.
Step 2: Change you database.yml to point to your Oracle instance. Some things to note below:
  • If you are using Express Edition, your Oracle instance is XE.
  • Create a new user and give it access to creating a table, sequence, indices (if needed). Privileges depends on how you wrote/generated your migration script/s.
  • I used a JDBC adapter to connect to Oracle 10g. Install activerecords-jdbc-adapter. I followed this but as far as I could remember it didn't work because its for Ruby. So I followed this and works well with JRuby.
  • I ended up with the following configuration in my database.yml file. I needed UTF-8 encoding for I18n (which is a different story).
adapter: jdbc
driver: oracle.jdbc.driver.OracleDriver
url: jdbc:oracle:thin:@127.0.0.1:1521:XE
username: username
password: password
encoding: UTF8

Step 3: Download ojdbc.jar here for 10g (for 11g). Copy the jar file to your $JRUBY_HOME\lib.

Step 4: Run db:migrate and db:fixtures:load (if you need to). You should be able to see your instance with new tables and data.

Step 5: Run WEBrick.

Issues I encountered:

And now for fun stuff ....
  • I started off installing oracle adapter and configure my database.yml appropriately. I later found out it was meant for Ruby. I think I also went on the path of installing ruby-oci8, but it was unsuccessful. Stick with the JDBC adapter which was meant for JRuby.
  • I played around with different configuration parameters and values for my database.yml file (because that is what you'll read in Oracle website I mentioned above and I got configuration for oracle adapter and ruby-oci8 all messed up in my head). I ended up with the parameter/value combination above.
  • I ran with using system as user and running db:create before db:migrate. And boom! This messed up my schema.rb reflecting all tables (system tables) in my instance. Create a user and don't use system as user! It's best practice. I was getting impatient.
That's it for Part 1. It was seamless to develop with Oracle 10g like I did in mysql before. Only that it eats up a lot of memory and loading takes sometime. I have to turn it off manually in Windows Services. If you got a pimped machine or probably running Mac or Linux, it shouldn't be a problem.

Part 2 will be running the app on Oracle Weblogic 10.

No comments:

Post a Comment