Re: getPrimaryKeys ?

From: Arnaud Garcia (arnaud.garci..im.hcuge.ch)
Date: Wed Feb 01 2006 - 08:07:14 EST

  • Next message: Tore Halset: "Re: getPrimaryKeys ?"

    Hi robert,

    yes, it exactly what I want: is o1 equivalent o2, if yes not add o2 to O.
    you right I can overide equals (I already did this), what I would like
    to know is, if there a way to find all the fiels of o1 that are PK.
    If there is such method, I can create a general method to check if two
    objets are equivalent ...

    (I have this problem, because I have another datasource (XML) and I
    build my object from XML, and I need to check if there are already in my
    dataContect before adding them )
    thanks,
    arnaud

    Robert Zeigler a écrit :

    >Hm... if you were to register and commit object2, it would end up with a
    >different pk than o1 anyway, so comparing object id's in this case is
    >probably not what you want to do; it sounds like you're interested more
    >in whether o1 and o2 are equivalent, rather than if they "come from" the
    >same underlying db row. In which case, overriding "equals" and doing the
    >field comparison is probably what you want.
    >
    >Robert
    >
    >Arnaud Garcia wrote:
    >
    >
    >
    >>thanks Andrus,
    >>
    >>Well, I can't do this....
    >>if o1 is in a dataContext, for example o1 is a child of O.
    >>if I build o2 from nothing, o2 = new o2(), o2.set ... ect..
    >>then if I do:
    >>system.out.println(o1.getObjectid()), I will have all the values of o1
    >>BUT
    >>a println of o2.getObjectid() return null !
    >>
    >>So to solve my problem, I did a simple fields comparison between the
    >>PK attributes of o1 and o2 and it works ... but I thought there was
    >>another way.
    >>
    >>thanks
    >>arnaud
    >>
    >>
    >>Andrus Adamchik a écrit :
    >>
    >>
    >>
    >>>getPrimaryKeys() in Cayenne is getObjectId()... So you can do
    >>>"o1.getObjectid().equals(o2.getObjectId())" comparison.
    >>>
    >>>Andrus
    >>>
    >>>
    >>>On Jan 31, 2006, at 12:25 PM, Arnaud Garcia wrote:
    >>>
    >>>
    >>>
    >>>>Hello,
    >>>>
    >>>>Is there a way to get all the primary keys attributes of a
    >>>>CayenneDataObject to compare it with another one?
    >>>>
    >>>>What I need to do:
    >>>>I have another xml datasource which sends some objects, and I need
    >>>>to compare these objects before adding them to another object (one
    >>>>to many relationship) ... so I need to compare them with their
    >>>>primary keys.
    >>>>
    >>>>if anObject.getPrimaryKeys().equal(maybeTheSameObject.getPrimaryKeys()
    >>>>then
    >>>> // do nothing
    >>>>else
    >>>>containerObject.addTo(anObject)
    >>>>
    >>>>=> If I don't test the object before adding it, I have a violation
    >>>>constrainst ...
    >>>>
    >>>>thanks for help
    >>>>
    >>>>arnaud
    >>>>
    >>>>
    >>>>
    >>>>
    >>>>
    >>>
    >>>
    >
    >
    >
    >



    This archive was generated by hypermail 2.0.0 : Wed Feb 01 2006 - 08:06:36 EST