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?



I know nothing about the object database. Can this persist beyond Application refreshes? Or is this just during-application persistence?
@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
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.
Please join our community at http://developer.db4o.com to get advice, demo apps, docs, etc.
We're waiting for you there =)
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.
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.
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 ;)