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
      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       

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

Ajax Form Submission Revisited And Advice Needed
Hammo777 said: To solve your original problem: document.formname.onsubmit(); just call the onsubmit method yourse... [More]

Editing A Query In A SQL Server DTS Package
JD said: Thanks for your post. Never unlike Microsoft to hide stuff in the hardest part time find. [More]

Mashing Spry Effects With CF8 Ajax Goodness
Mark Pitts said: I have had moderate success implementing Spry Accordian. Sadly the part that does is not working wil... [More]

Chinese Birth Calendar Accuracy Test
Toni Lehman said: This calendar was accurate for both my daughters and 4 grandchildren. I tried it for 11 of my other ... [More]

Virtual Memory - Am I The Last To Know?
Larry Miller said: The authors friend was right. Windows virtual memory system was designed by experts and they fully u... [More]

RSS


coldfusionbloggers

FullAsAGoog MXNA

Consumed By Feed-Squirrel.com