Recursively-stuffed fowl aside, the focus of this week was on Persistency (read: saving stuff). Prior to this, my only method of storing data was in a Property Map, or Static Class, which unfortunately didn't stick around after execution <insert guillotine joke here>. The answer of course is to put things in a database.
BerkeleyDB (BDB) is a neat little database service that runs in Java and a myriad of other languages (but most importantly, Java). Having worked with DBs and webservices before, let me tell you, this thing rocks. Set up is a breeze, and BDB is pretty darn flexible. The best part?
NO CONNECTION STRINGS.
In this exercise, I had Contact objects which had unique IDs as primary keys. All I had to do to was throw a @PrimaryKey attribute above the uniqueID attribute in the Contact class, and BDB associated it as the PrimaryKey. Then, in the ContactDAO Class, a few lines of code let me define a "mini-DB" object, which let me call out mini-DB.get(key), mini-DB.delete(key), etc. BDB supports multiple mini-DB objects for various keys; in Kata 01, I used two (one for the PrimaryKey, and one for the SecondaryKey). BDB even has built-in iterators if you need to return multiple entities. Long story short, if you need a java database, go with BDB.
While I praise BDB for its ease of use and great utility, I should point out that Wicket (*glare*) is not so nice and took up all of a very nice Saturday afternoon.
On to the Katas!
Kata 01:
Easy Peasy introduction into BDB, simply add a timestamp as a secondary key, and add functionalities for a get-timestamp and get-range function. <3 hrs (actually less than 2, but I accidentally overwrote it and had to do it again :c )
Kata 02:
The mastery Kata, combining Wicket, Restlet, and BDB to make an end-to-end Java-based web-service. I theoretically had all the pieces from previous Katas, but putting them together took some thought. I had to draw a diagram...twice. Coding the back end was easy enough, and took about an hour. Although many painful hours were spent on Wicket, which sent me maliciously deceptive error messages, before mysteriously clearing itself up.
BerkeleyDB: http://en.wikipedia.org/wiki/Berkeley_DB
Distribution:
NOTE* Katas are in two separate files in the zip.
http://ics414-spring2011.googlecode.com/files/BerkeleyDB-GBurgess.zip
No comments:
Post a Comment