Nice library for constraint checking

Lately I’ve search for a good solution to solve the common problem of providing constrain checking of domain objects. Domain objects which are used in combination with a data access layer are sometimes cumbersome to check because besides content based constraints there are also structural integrity properties which have to be checked as foreign keys and identity properties.
So my first idea was to look in the Hibernate Validator project because Hibernate is a well known and mature DAO framework. After downloading I’ve thought that was it what I need: annotation based, flexible for extensions and at least lightweigth. Adding the annotions too my domain objects was simple but then I implemented the actual validator logic, the ghost of Maven hits hard: the Validator framework itself is very lean but if you want to evaluate the violations, a lot of Hibernate projects are needed and, interestingly, also the base persistence framework is needed! This was to much for simple validation …
After searching once more for a solution, programming one  by my own was the last option, I’ve found OVal. This was finally what I’ve serched for! Constraints could be added as annotations or declarative defined by XML. The API is extremely lean and you only get additional dependencies if you use one of the supported script languages such as JavaScript, BeanShell, Groovy or MVEL (which is my favorite). Besides checking of violation for existing properties the library supports also contract based checks, also invariants, with the help of aspects, executed by AspectJ. Especially for domain objects there is also the nice feature that checks could be defined in profiles which are controllable at runtime. So you can build up your object tree, validate it semantically and if finally stored and retrieved on the data layer, you can check structural integrity.
OVal was the only project which supports constraint checking in this flexible and easy usable way I’ve found and because I know that the problem is a common one I recommended it highly. If you throw NullPointer- and IllegalArgumentExceptions on your own you certainly only get very “smelly” code …


No comments yet

Leave a Reply

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

You are commenting using your 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

%d bloggers like this: