February 08, 2012, 03:58:33 AM

Author Topic: Persistence layer!  (Read 274 times)

Scott

  • ForumNazi
  • BNU Leader
  • THE TURKISH EMPEROR
  • *****
  • Posts: 1146
  • Karma: +6/-6
  • BNU-Camel since December 2002
    • View Profile
    • Clan BNU
Persistence layer!
« on: April 02, 2008, 10:37:07 PM »
I hope everyone had a happy April fools day! There were quite a few people who were totally thrown by the changelog I put up - to clarify, everything between the lines ending in (Issue 61), inclusive, was in the real changelog. The rest were mostly outstanding feature requrests from bnubot.net.

So, here's what's happening in BNU-Bot these days: I'm in the process of adding a real persistence layer to replace the cheap query runner I've been using.

A persistence layer a library to abstract the application code from dealing with database-specific quirks. It handles things like connection state, building queries that are compatible with the specific type of database, and other things that make application logic messy. Databases are relational, and it makes sense that the application layer's view of the database should be too. The persistence layer takes the concept of primary keys and id numbers out and hides them behind a velvet rope of object-references that the programmer rarely need to subvert.

I chose Apache's Cayenne, because they have an active development community, and more importantly, because the modeler rocks. It supports the two databases I already support in BNU-Bot (Derby and MySQL) as well as many others! This means that users should be able to use any type of relational database they would like, provided they're able to do it without asking me for help. :)

So, how does this alll affect you? For starters, you're going to see a huge drop in the number of database-related exceptions. The notorious touchUser() exception is completely off the radar, and this time it's not just because I silenced the message! Plugin developers (not that there are any) will also have a much simpler time accessing and modifying the database, since they can go directly to the Cayenne objects.

Cayenne also offers the ability to cache data in-memory, to avoid what could potentially become a bottleneck if you're using a slow database. Since this will probably never happen to the typical BNU-Bot user (Derby already caches data, and most MySQL databases are local), I'll leave this one disabled by default - but you'll be able to jump in to the configuration files and edit this setting if you choose to.

What's the catch? It's pretty tricky to deploy! For starters, there are several libraries that have to be on the classpath - that's something that's pretty easy to take care of with the new auto-update module. Cayenne also requires three configuration files: one to tell it where the other two files are, one to tell it how to connect to the database, and a mapping file that tells Cayenne what the database looks like. On top of that, Cayenne is just an abstraction of the database; the database can still reject input, and the application still has to deal with the consequences if it does.

For those of you who are keeping up with nightly builds, keep in touch with me and let me know what's going on in your environments. There are going to be a lot of bugs with commands (some of you may recall that it took months to stamp them out the first time around), and I wont be able to catch them all without your help!

Thanks for the continued support!
It's like saying, "Hello, my name is Camel and I don't know what I'm talking about."