RoR in GlassFish with Derby as the database

In my previous post I wrote about getting a RoR application to work on GlassFish as a web application. Since the Derby database is embedded in GlassFish why not try to use it as the backend datastore for the RoR-web-application.

Getting a Ruby on Rails application to work with a Derby database should be relatively straightforward. Well it is, but only after you've jumped through a few hoops trying to figure things out for the first time.

1. Modify config/database.yml to something like:

development:
 adapter: jdbc
 driver: org.apache.derby.jdbc.ClientDriver
 url: jdbc:derby://${database host}:${database port}/${database name}
 username: ${username}
 password: ${password}
Derby has the concept of 'database name' and 'schema'. If 'schema' is unspecified it defaults to 'username'

2. Create table(s) in Derby. Points to note here are:
   2.1 Use upper case for all table/column names
   2.2 To create the auto increment identifier column use the following SQL statement

CREATE TABLE ${table-name} ( ID INTEGER GENERATED ALWAYS AS IDENTITY PRIMARY KEY, ${other-columns-and-constraints} )


I'm not sure what the SQL standard is on auto increment column types but this was bit of a pain to figure out. Also remember that 'DESC' is a reserved work in SQL terminology so do not use that as a column name.

The Derby jdbc driver should by default be in the classpath of GlassFish application server so no tweaking needed on that account. However, if you are running the RoR application on JRuby/WEBrick combo you'll need to add the derby-jdbc-driver library to the classpath.

That's pretty much all there is to it. Give it a shot !

Comments:

Post a Comment:
Comments are closed for this entry.
About

whacko

Search

Categories
Archives
« April 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today