Monday, June 8, 2009

db4o in Coldfusion, anyone?

DB4O is an object database. It allows you to store objects (at whatever state they happen to be in) and retrieve them for use later.
This can be really useful if:
1. You want a simple, quick way to store data
2. You want to create an application that can run without an SQL database
3. You hate SQL (or SQL hates you)

I did some research and found a guy named Todd Sharp who installed db4o for Coldfusion. He hasn't released his code, so that got me thinking: "Hey, I know some Java and I know how to install Java classes in Coldfusion. Why don't I do it myself?"

So I tried it, and it worked! But... I've run into a couple serious issues that I can't seem to figure out.

Firstly, after about four or five "save" operations, the database becomes corrupt. No matter how simple the objects are, this always happens. If I can't figure this out, my experiment is basically a failure.

Second, I cannot store CFCs. If I try, my CPU goes full throttle until I kill Coldfusion. I'm guessing this is due to the underlying complexity of CFCs, but it sure puts a damper on things. I've been using CF 8's JSON functions to "simplify" my Coldfusion objects like so: DeserializeJSON(SerializeJSON(myCFCinstance))

Does anyone else have any experience with db4o? I'll provide my source code and installation instructions to anyone who wants to try it.

Here is a great tutorial for db4o

My system specs:
Java version: Open JDK 1.6.0_0
CF Version: 8,0,1,195765
OS: Ubuntu 9.04 (2.6.28-11-generic)
Hardware: Dell Vostro 1000

4 comments:

hhrogersii said...

Russ, I'm very interested in trying to get db4o implemented in CF. Been hacking around with db4o for a while but have limited Java skills. Seems like Adobe is taking care of persistence using ORM in CF9 via Hibernate. But implementing an object database just seems to make sense when writing OO CF code. No?

Russ said...

An object database would be useful for some things I think. I just found Transfer ORM, which works for CF7+. Have you been able to get db4o working in Coldfusion?

hhrogersii said...

I've worked through db4o examples enough to know that there is some potential there. That's about it.

I recently converted our corporate marketing website to OO-style CFCs. In the reengineering process I implemented both Transfer and Reactor and found the overhead was just to much for our server infrastructure in production. That was over a year ago so probably much improved now.

My local dev environment was ok in execution time but something about our production env did not execute these ORMs well. Since our data model was fairly stable at this point, I ended up using Brian Rinaldi's Illudium code generator (http://cfcgenerator.riaforge.org/) to build a static Data Mapper layer with a service facade so I can replumb the data persistence side later without affecting the business objects. Works great.

Do you use Mark Mandel's Java class loader (http://javaloader.riaforge.org/) or register the jar in the CF administrator?

Not sure if I'd be much help to you but if you want me to test the Save issue myself, I'd be happy to have a look.

Russ said...

Thanks for the tip about the Illudium. I didn't use the java class loader, I just put the .jar file into the Coldfusion classes folder. Do you yhink that makes a difference?