Object validation

From: Fabricio Voznika (fabricio.voznik..artmouth.EDU)
Date: Fri Jul 25 2003 - 10:55:14 EDT

  • Next message: Holger Hoffstätte: "Re: Object validation"

    Hi,

        How are you guys doing validation in your objects using cayenne?
        The way I like to do it is to have a validate method in every
    object, and then call this method before the transaction commits. This
    validate method checks for mandatory values as well as simple business
    rules, like start date before end date, and more complicated ones, like
    the sum of all items in a budget cannot be larger than a limit amount,
    if an amount is given and the sky is cloudy.
        The way I tried to do is to make my objects implement
    DataObjectTransactionEventListener.willCommit(DataContextEvent) and do
    all the checks there. But I haven't found a way to abort the commit from
    there. If I throw an exception, it just get logged (see
    Invocation.fire(Object[])) if I call DataContext.rollbackChanges() it
    crashes (I was expecting that actually).
        Is there any other way of doing something like this? How are you
    guys doing?

    Thanks for your help,

    -- 
    Fabricio Voznika
    Senior Programmer/Analyst
    Administrative Computing
    Dartmouth College
    Phone: 603-646-2007
    



    This archive was generated by hypermail 2.0.0 : Fri Jul 25 2003 - 10:52:17 EDT