Re: Object validation

From: Andrus Adamchik (andru..bjectstyle.org)
Date: Fri Aug 29 2003 - 10:41:21 EDT

  • Next message: Andrus Adamchik: "Re: Flattened Relationship Insert Problem"

    On Tuesday, July 29, 2003, at 11:19 AM, Fabricio Voznika wrote:
    >     The static method does what I need for now, I just need to
    > remember to call it and I tend to forget these things :-)
    >     But anyway, I believe Cayenne should support some kind of
    > validation. What's the best way to do it? I don't know. I agree with
    > the suggestion of copying this static method to the beginning of
    > commit, including delete on it (an object may decide it shouldn't be
    > deleted).

    Yeah, all this logic can exist as a part of
    DataContext.commitChanges(). Now, do we want to split "validateForSave"
    into separate "validateForInsert", "validateForDelete", etc., just like
    EOF does? I don't think it matters either way. I vote for a single
    method since object internally can determine its state. Maybe instead
    of "DataObject.validateForSave" call it "DataObject.validateForCommit"?

    > Also, it would be very nice if the modeller generated some of the
    > validation, like field length, nulls, etc.

    This can be done in a generic way in runtime based on DataMap
    information, so no code generation is needed. Though this maybe
    somewhat slower than a precompiled code,for now I wouldn't bother to
    change class generation.

    >     As for return vs. exception, I vote for validateForSave() to
    > return it, so we can collect all errors and commit() to throw an
    > exception, because the code that handles the errors might not be the
    > same that commits the context. The exception breaks the execution and
    > back-tracks to the right place, it would be a pain to do the same with
    > return.

    I agree.

    >     Once we decide how we're going to do it, I'm willing to implement
    > it for beer :-)

    If you ever come to New York City, beer is on me :-)

    Andrus



    This archive was generated by hypermail 2.0.0 : Fri Aug 29 2003 - 10:41:08 EDT