Re: Testing for Valid Objects

From: Mike Kienenberger (mkienen..laska.net)
Date: Fri Aug 06 2004 - 14:24:02 EDT

  • Next message: Orion Fields: "RE: Testing for Valid Objects"

    Orion Fields <ofield..martserv.com> wrote:
    > for the many to single or single to single relationships, how
    > does one go about testing to see if the object exists?
    >
    > What I have is a try catch block around the resolveFault of the object
    > which may or may not exist. I'd rather not catch a
    > cayenneruntimeexception for this. Is there a better way, prefetching
    > aside? (I say prefetching aside b/c the object is nested a few objects
    > down. I tried the read property, ie myobject.readProperty("Artist"), but
    > that doesn't returns the same hollow object as myobject.getartist.

    For most cases, I'd think you could just check for null.

    I know that I do have one case where my restricting qualifer hides the
    object from Cayenne, and I may have dangling database references because of
    this.

    In that particular case, I resort to using the following:

                                            PaymentMethod aPaymentMethod =
    aPaymentHistoryObject.getPaymentMethod();

                        // If the fault doesn't resolve, then the payment method
    must have been invalidated
                        aPaymentMethod.resolveFault();
                        if (PersistenceState.TRANSIENT ==
    aPaymentMethod.getPersistenceState())
                        {
                            aPaymentMethod = null;
                        }

    I can't think of any other places in my code where I have a non-mandatory
    one-to-one relationship that I don't just handle by checking against null.

    -Mike



    This archive was generated by hypermail 2.0.0 : Fri Aug 06 2004 - 14:23:10 EDT