Re: Object validation classes

From: Fabricio Voznika (fabricio.voznik..artmouth.EDU)
Date: Mon Sep 15 2003 - 15:07:51 EDT

  • Next message: Andrus Adamchik: "Re: Object validation classes"

    Andrus Adamchik wrote:

    > Fabricio,
    >
    > Just browsed through your code. Cool! A few notes.
    >
    > 1. Using JDK 1.4 assertions is unfortunately not an option for us,
    > since core framework must be JDK 1.3 compatible. There are quiet a few
    > users that do not have an option of upgrading their deployment
    > environment. Of course Modeler is 1.4, but core cayenne.jar is 1.3.
    > Many of the assertions, e.g. argument checking is better done by
    > throwing IllegalArgumentExceptions anyway. E.g.:
    >
    > http://java.sun.com/j2se/1.4.2/docs/guide/lang/assert.html#usage

    Ok, replaced asserts with ifs. Too bad we can use them though :-(, it's
    nice to be able to remove them when the application is released.

    >
    > 2. I suggest package name to be "org.objectstyle.cayenne.validation",
    > since the validation mechanism that you've implemented is generic
    > enough and is not tied to the access layer. I hope to eventually
    > switch most of the things in "project.validation" to this generic
    > mechanism.

    Done.

    >
    > 3. One very important piece is not implemented, or at least I am not
    > seeing it - CayenneDataObject.validateForSave(..) - this is where a
    > DataObject should pull entity info and check things like max length
    > exceeding the allowed value, nulls where nulls are not allowed and
    > such...

    I wasn't actually planning on doing that, since you've mention it, I'll
    try... :-)

    >
    > 4.Since Cayenne imports Jakarta org.apache.commons.beanutils, there is
    > no need for a custom implementation of property reading in Validator
    > class. Just use BeanUtils.readSimpleProperty(..). But note that for
    > DataObjects, a special handling using
    > "CayenneDataObject.readNestedProperty(..)" is preferable since it is
    > *much* faster than reflection.

    BeanUtils returns only a string representation of the object :-(.
    readNestedProperty() breaks object encapsulation (it's not calling the
    getter) and works only with properties defined in Cayenne. The idea of
    Validator is to add utilities methods for manual validation. There are
    only 3 method there now, but the idea it to have much more
    (checkLessThan, checkLength, checkDateFormat, etc)

    >
    > An alternative to 3. and 4. would be using class generation to create
    > validateForSave for each class, but for now I am still unsure if this
    > is the way to go. Doing too many things via class generation is a
    > conceptual shift in Cayenne and requires more thought.

    I was afraid it would be costly to make the validations on the fly, but
    thinking more about it, it shouldn't be so bad I guess. I'll implement
    it and if it's bad you help me optimize it, ok?
    I'll send it all to you once I'm finished. I'm not updating my project
    since 9/11/2003 though.

    > Thanks
    >
    > Andrus

    Cheers,
    Fabricio.

    >
    >
    >
    > On Friday, September 12, 2003, at 09:10 PM, Andrus Adamchik wrote:
    >
    >> Hi Fabricio,
    >>
    >> I will look at your code over the weekend.
    >>
    >> We have a bit of a dilemma though. 1.0 Release shouldn't really
    >> include any new features to avoid destabilizing it. On the other hand
    >> branching it now, so that all 1.1 stuff would go into CVS HEAD, is a
    >> bit premature, given that there is some work still being done on
    >> FireBird and DB2 adapters, and the documentation.
    >>
    >> I personally vote for branching now and releasing the FireBird
    >> adapter as "experimental" with 1.0 (which it is in all respects). I
    >> know Holger is on vacation. What is the feeling among other
    >> committers? Are we ready to get 1.0 out of the door and open the gate
    >> for all the new features?
    >>
    >> Andrus
    >>
    >>
    >> On Thursday, September 11, 2003, at 04:49 PM, Fabricio Voznika wrote:
    >>
    >>> Hi all,
    >>>
    >>>
    >>> I've implemented the object validation objects. I'm sending the
    >>> new classes in 2 tars:
    >>>
    >>> src.tar.gz - new classes, all in ...cayenne.access.validation package.
    >>> tests.tar.gz - just 1 class with junit tests.
    >>>
    >>> The file diff.txt contains the result of a diff -ru for the
    >>> modified classes. I diffed it against 9/11/2003 nightly build due to
    >>> the already mentioned problems with CVS.
    >>> I'm haven't done any documentation yet, but I plan to do so. I
    >>> would appreciate if someone could have a look and validate what I
    >>> did. There are some TODO tags to move methods to an Utility class, I
    >>> would appreciate if someone could tell me where to put them.
    >>>
    >>> Thanks,
    >>> Fabricio.
    >>
    >



    This archive was generated by hypermail 2.0.0 : Mon Sep 15 2003 - 15:06:03 EDT