cayenne-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Steve Wells" <>
Subject Cayenne Annotations
Date Sun, 07 Jan 2007 07:27:10 GMT
I've started working on a package of cayenne annotations, so far only for
validations.  My initial motivation was from using the Tapestry bean-form
component.  Bean-form will create a Html form for you including validations
dynamically based on a Bean passed to it.  There are a lot of customisations
that can be done.  It can save a lot of time, effort, errors.

What was annoying me was that you had to repeat your validations with
Cayenne DataObjects.  1. in the Cayenne model and 2 with the beanform.  This
was an obvious signal that something had to be done, it wasn't DRY.  What
I've come up with so far to solve this:
1. A modified Cayenne super class Velocity template to generate Cayenne
Annotations.  Generates Required and Length annotations
2. An annotations package based on OVal.  includes Min, Max, Required, Past,
Future, RegEx, Email, Length and whatever else you can dream up.
3. A bean-form Cayenne integrator.

All the user cares about then is practically very little.  Bean-form grabs
the Cayenne generated annotation and generates the Tapestry validator for

You can also add in annotations that can't be guessed from your data
model into your subclass, just override the superclass eg:
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
   public String getUpperCaseField() {
      return  upperCaseField;

Validation layer, eg Tapestry page class:
       Validator validator = new CayenneValidator();

        // collect the violated constraints
        List<ConstraintViolation> violations = validator.validate
        if (violations.size() > 0) // tell the user what is wrong from
annotation generated message, field must be upper case etc;
So what do people think of this approach?



  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message