Re: Cayenne Annotations

From: Andrus Adamchik (andru..bjectstyle.org)
Date: Tue Jan 09 2007 - 08:59:57 EST

  • Next message: Andrus Adamchik: "Re: Problems with schema reverse engineer on Sybase 12.5.4 Solaris"

    > So what do people think of this approach?

    Nice if you can do it in one place. If you want Cayenne only to
    supply extra metadata, but Tapestry do the validation, you can turn
    off Cayenne validation by unchecking "object validation" checkbox in
    the DataDomain panel in the Modeler.

    Cheers,
    Andrus

    On Jan 7, 2007, at 9:27 AM, Steve Wells wrote:

    > 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
    > them.
    >
    > You can also add in annotations that can't be guessed from your data
    > model into your subclass, just override the superclass eg:
    >..mail
    >..equired
    > 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
    > ..pperCase
    > 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, field must be upper case etc;
    > So what do people think of this approach?
    >
    >
    > Cheers,
    >
    > Steve



    This archive was generated by hypermail 2.0.0 : Tue Jan 09 2007 - 09:00:47 EST