ThoughtPark

     
 
Rapid web development without the RDBMS

by Steve

When I first came across Ruby on Rails, I was sceptical. This was not because of the use of Ruby (although I have some concerns, which I have mentioned in previous posts here), but mainly because of the Active Record pattern. Why take a fully object-oriented language like Ruby and define the data model relationally? It seems me that the developer is losing much in terms of ease of development and flexibility by using such a thin layer over relational stores and having to express relationships between classes in relational terms. Maybe this effort would be justified if the relational database was shared with other applications, but my impression is that this isn‘t the target of RoR.

There are other ways of using relational databases in combination with OOP development that allow the data model to expressed more fully in terms of objects rather than relationally; such as ORM. We develop using JDO and JPA using Kodo and OpenJPA for this reason. There are alternatives to ActiveRecord in Ruby (such as Og). There are various noteworthy projects in Python (e.g. Dejavu), and Perl (e.g. RDBO). For RoR-style development on the JVM there is Grails, based around Groovy. But there is still this focus on relational stores. I do wonder what the point of that is for small, one-off web projects.

I started to think about this again when I took another look (after several years) at db4o, a pure object store for Java and .NET. It did not take me long to realise the advantages for small projects. Java code to open a store and save an object consists of only a few lines, and with no need for
mapping or any kind of “instrumentation” of classes; at least not just to get going or for small applications.

I decided to try this using Groovy. It was just as easy:

class AClass {
def id
def name
String toString() { return "$id:$name" }
}

// Connect (this is simple file access.  Db4o can work multi-user)
def db = Db4o.openFile("data.db");
try {

// Store
db.set(new AClass(id:1,name:"Jon"))
db.set(new AClass(id:2,name:"Steve"))

// Retrieve
db.query(AClass.class).each { println it }

// Delete all instances
db.query(AClass.class).each { db.delete(it) }
} finally {
db.close()
}

The incredible simplicity of this hit me immediately. Suddenly all those paragraphs of instructions about how to set up different databases for RoR, and all the rules of how to configure different types of relational connections beteen classes looked very tedious, especially as Rails was supposed to be the great time-saver.

So, I am going to start a long-term project, that I will report on here. The aim is to see how simple Grails could be with an object database; without the use of Hibernate or JPA; without ORM at all. This is purely a spare-time project, but I think it could be interesting. Even if doesn‘t work, it would be good to know why. I decided to start with Groovy for this because it integrates very cleanly with Java libraries, such as the db4o implementation for the JVM, and Grails is pretty stable.
I will take a look at other languages later.

Posted by ThoughtPark @ 02:27 PM GMT [ Comments [5] ]
 
 
 
 
Comments:

Very Nice!

I am a fan of db4o and just today was talking to someone that it would be really interesting to see what Groovy, Grails, and db40 looked like together.

I look forward to seeing the results.

Jim

Posted by Jim Shingler on January 15, 2008 at 02:04 AM GMT #

Nice! I think that must be easy create a Grails plugin to deals with Db4o. Well, one questions: Because you define attributes using dynamic typing, how Db4o store objects schema?

Kind Regards

Posted by Marcos Silva Pereira on January 15, 2008 at 02:09 AM GMT #

hello, you might be interested in
http://errtheblog.com/posts/63-full-of-ambition

Posted by mclay on January 15, 2008 at 06:11 AM GMT #

Nice thing.
I would like to see somebody try to play
groovy, grails, GORM, db4o, xmldb all together!!

Posted by glassde on January 27, 2008 at 02:52 AM GMT #

This is something that's been missing. Why to use Hibernate + RDBMS if you can use just db4o and get rid of the impedance mismatch! Could you inform me/us about the progress? I'm also interested in helping you with this, because this is something I really want to happen.

Posted by Hannu on April 23, 2008 at 04:14 PM BST #

Post a Comment:

Name:
E-Mail:
URL:

Your Comment:

HTML Syntax: NOT allowed
 
Thoughts from ZP: Steve Zara and Jonathan Harley, directors of UK software consultancy company Zac Parkplatz Ltd.
 
 
« November 2008
MonTueWedThuFriSatSun
     
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

[RSS Newsfeed]

[This is a Roller site]
 
© Zac Parkplatz Ltd