Wednesday, March 23, 2011

The coolest thing since sliced cheese...

I've been put in charge of a new project - we're building an application that is a bit secret - so I can't get into details. But - it's effectively an app that let's you build documents. Naturally, I was looking for a backend architecture that was document-oriented - not relational. I initially thought to make it xml based and use XSLT or an equivalent xpath based transform technology.

Then we started looking into MongoDB. It really fit the bill; however, it was JSON based. So what to do - I want to avoid an ORM or anything that requires a lot of data binding defintions - I want the app to be loose, lightweight and incredibly agile. JSON is all of that - but how do I validate? XML has XSD but what do I do for JSON? Also, I want to efficiently query documents - XPATH is a very efficient way to query. How do I achieve the equivalent with MongoDB?

Well I then discovered Spring DATA. Wow! Where have you been all my life!?! What does Spring Data do? Well, it provides access services to noSQL DBs. But the magic isn't that it's simply a DAO but it's the way it implemented these services. I wish Hibernate or MyBatis worked the same way. Basically all you have to do is define your Pojos, create a repository interface by descending from the MongoRepository interface, set the host name and port of your MongoDB and that's it!! Spring implements all CRUD automagically from the interface. Additionally if you add "find" methods on the interface, Spring automagically generates queries. No mapping files, no schema, no mastering of various query language - heck, you don't even have to annotate your code! Seriously, this one of the most useful and productive bit of technology that I ever used.

So there you have it - I have a data model/persistence layer that is easy to create and modify. It is just the right balance of strong typing without the headache that comes with a formal persistence mechanism.

To the Spring Data Team : awesome job!!! You guys are rock stars!!