An easy way to version your objects

Imagine that you have a Customer object that has an Address and a BankAccount. In other words, John lives in Los Angeles and has the bank account number 123456 (V1.0). Imagine then that John decides to move to New York (V1.1) and several months later changes bank accounts (V1.2). Tired of the city stress, he moves to Alaska (V1.3) where he closes his bank account (V1.4) and starts fishing.

How do you keep all this information in your system ? How can you get V1.2 of all your object ? You never delete data, you add version numbers when you make updates, add a timestamp, a version to your class definition (imagine that the Customer class has changed and has different attributes) and, of course, lots of data manipulation and processing to be able to visualise your objects at a certain version.

A couple of years ago I worked on a project that had these exact needs : we couldn?t delete any data but instead version it (versioning becomes tricky when there are several layers of associations and inheritance between objects). The other important requirement was that the versioned data was not accessed very often. Because of that we decided to use something not really efficient but easy to develop : JRCS.

What we did was very simple : we marshalled the Customer objects (and its relationed Address and BankAccount) into an XML stream (using Castor), we used JRCS to version this stream and we stored the XML stream, with the JRCS tags, in a database. JRCS has the same effect as versioning a text file with CVS. If you look at the content of a CVS versioned file you see special tags that tell CVS what piece of text was added/deleted or updated for which version. The same thing happens with JRCS. To retreive your objects at a certain version, you get the XML stream (with JRCS tags) from the database, you ask JRCS to give you the version 1.3 of your Customer object, and you get an XML stream that you unmarshall into your object model.

Of course you will get performance issues if you process huge amounts of data, hundreds time a second. But if you don?t have these counstraints, using JRCS as a versioning tool really helps.

Categories: Java

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s