More CF+Java: Compiling Classes And Persisting Objects

Last week I blogged about a simple proof of concept that I had come up with for compiling Java classes on the fly in ColdFusion. I played a bit more with my proof of concept over the weekend and came up with a bare bones application that does the following:

  • Compiles a directory of '.java' source files (and subdirectories) into a single JAR file
  • Drops the JAR into a local 'lib' folder
  • Loads the JAR (with Mark Mandel's JavaLoader)
  • Loads db4o (an Object database)

So once all that is done (in onApplicationStart) the application can immediately do the following:

  • Create an instance of any objects within the just compiled Java classes
  • Set properties on that class
  • Persist the object into db4o

Now why is this cool? Well for one there is not object to relational data mapping required. The object is persisted as is - composite objects/data and all. db4o supports a few query methods to retrieve the objects - none of which I've dug very deep into yet. Another benefit to this method is speed. Initialization is a bit of a hog (I was seeing around 2000-2500ms for onAppStart) but object creation is around 0-2ms.

I'm not planning on releasing any of the code yet (maybe ever). Plus it's all super rough around the edges right now. But I'm really interested in what folks think about this. Has anyone used an object database in their Java projects? Is it worth moving forward with this, or is it all just cool to know you can do it but not real practical?

Comments
@Todd,

I know nothing about the object database. Can this persist beyond Application refreshes? Or is this just during-application persistence?
# Posted By Ben Nadel | 5/28/08 1:32 PM
You have a bad link on the for the db4o.com website.
# Posted By Todd Rafferty | 5/28/08 1:49 PM
@Todd - thanks...fixed now.

@Ben - db4o is an Object database - so it is a total alternative to traditional relational database systems - so yes, it is a 'permanent' persistence mechanism.

Check out wikipedia for a better description:

http://en.wikipedia.org/wiki/Object_database
# Posted By todd sharp | 5/28/08 2:19 PM
"I'm not planning on releasing any of the code yet (maybe ever)".

What? But we want to see! (said in my best spoiled child voice). Seriously though, this sounds pretty interesting. I don't have any experience with object DBs but from what I read it sounds like something worth exploring. Given the popularity of OO it's surprising they haven't gotten more popular.
# Posted By Thomas Messier | 5/28/08 3:58 PM
db4o is a full persistence solution which requires no object relational mapping.

Please join our community at http://developer.db4o.com to get advice, demo apps, docs, etc.

We're waiting for you there =)
# Posted By German Viscuso | 5/28/08 5:37 PM
Nice work Todd!

I've been planning on experimenting in a very similar space (tho' not dbo).

I think you may well know this, but remember that each class you dynamically write and use, will take up memory, so if you start going crazy with how much you dynamically generate, it can be a potential memory leak.

This is very similar to the reasoning behind why to put JavaLoader in the server scope - so as to not have it reload.

So I would suggest before gen'ing your Java code, make sure to see if you already haven't, and then doing it. That way, you escape potential memory leak issues.
# Posted By Mark Mandel | 5/28/08 7:12 PM
That sounds pretty dreamy. I wana see that code.
# Posted By John Allen | 5/29/08 12:51 AM
While building prototype wrapper for Hibernate I had to do exactly what you have described.
http://riait.co.uk/2008/05/25/using-hibernate-with...
You can check how I'm using built-in JRUn compiler to do the work.
# Posted By radekg | 5/30/08 7:57 AM
Mark: If you didn't live in the future we could talk via IM ;)

Maybe we can hook up at CFUnited and I can show you what I've got. If you're interested we can collaborate (if you don't mind working with someone intelectually inferior to yourself ;)
# Posted By todd sharp | 6/4/08 12:55 PM
I have been attempting to get Db4o working in my CF application and I have not succeeded. I would love to see how you made this work. Pretty pleaaasseeeee......
# Posted By Getburl | 7/4/08 2:17 PM

Calendar

Sun Mon Tue Wed Thu Fri Sat
     12
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
31       

Subscribe

Enter your email address to subscribe to this blog.

Tags

actionscript ajax blogging cfsnippets coldfusion flash forms flex funny stuff misc model-glue off topic personal project learn slidesix sql

Recent Comments

Adding Auto Generated Code Downloads to BlogCFC
ada5fsa said: http://www.mountwashingto... http://extjs.com/forum/me... h... [More]

BlogCFC Survey #2
ada5fsa said: http://www.mountwashingto... http://extjs.com/forum/me... h... [More]

Most Difficult Captcha Of All Time
kokkooo said: [url=http://synchrophase.info/...]消費者金融 ブラック[/url] [url=http://geji-geji.com/]消費者金融ブラック[/url] [url=http... [More]

Most Difficult Captcha Of All Time
kokkooo said: <a href="http://synchrophase.info/...">消費者金融 ブラック</a> <a href="http://gej... [More]

Using A PlayStation 2 HDD In Your PC
Vodin said: Well dang. Thanks man, my uncle who owns a Video Game shop had a PS2 harddrive in the junk box, I sn... [More]

RSS


coldfusionbloggers

FullAsAGoog MXNA

Consumed By Feed-Squirrel.com