This is the beginning of a set of Java 5 annotations for the Cayenne Object relational (ORM) framework. Currently only a validations package is supported.
The initial motivation came about from using the Tapestry Beanform component. Beanform will create a Tapestry/Html form for you at runtime including appropriate field types and validations dynamically based on a Bean passed to it. There are a lot of customisations that can be done. Powerful stuff, it can save a lot of time, effort, errors. There were annotations already available for other ORM's but I needed one for Cayenne.
What I've come up with so far to solve this:
<dependency> <groupId>cayenne-annotations</groupId> <artifactId>cayenne-annotations</artifactId> <version>1.0-SNAPSHOT</version> </dependency>
Once setup all the user cares about then is practically very little. Beanform grabs the Cayenne generated annotation and generates the Tapestry validator for them.
You can also add in annotations that can't be guessed from your data model into your subclass, just override the superclass eg:
@Email @Required public String getEmail() { return super.getEmail; }
Next step is when we want to add a validation that none of the frameworks support (maybe you have a rich client etc), this is where OVal really comes into it, eg:
Cayenne sub-class: // Must be uppercase and is required @UpperCase @Required public String getUpperCaseField() { return upperCaseField; } Validation layer, eg Tapestry page class: Validator validator = new CayenneValidator(); // collect the violated constraints List<ConstraintViolation> violations = validator.validate(myObjEntity); if (violations.size() > 0) // tell the user what is wrong from annotation generated message, required field must be upper case etc;