Andrus Adamchik wrote:


((Integer) DataObjectUtils.pkForObject(this)).intValue();


An equivalent shorter form will be this:

    DataObjectUtils.intPkForObject(this));


  ObjectId objectId = new ObjectId("Contact", CONTACT_ID_PK_COLUMN,
id);
       setObjectId(objectId);


Theoretically this should work as Cayenne checks for manual id changes on commit and does the right thing. The catch is that the old id is used as a key to look up the registered object in DataContext, so there may be undesired side effects. A cleaner way may look like this:

this.objectId.getReplacementIdMap().put(CONTACT_ID_PK_COLUMN, new Integer(id));

Andrus

On Jun 16, 2006, at 5:14 AM, Malcolm Edgar wrote:

Hi All,

I am looking at using Cayenne with Flex. Flex provides a Data Services layer
which transforms Java object into matching JavaScript classes.  As  Flex
needs to get and set the object id values, I want to know if what I am doing
below is the correct pattern?

regards Malcolm Edgar


package samples.contact;
..

public class Contact extends _Contact
{
   public int getContactId() {
       return ((Integer) DataObjectUtils.pkForObject(this)).intValue ();
   }

   public void setContactId(int id) {
       ObjectId objectId = new ObjectId("Contact",  CONTACT_ID_PK_COLUMN,
id);
       setObjectId(objectId);
   }

}




Thanks for that. It is working well so far, these products will be a pretty sweat combination.

regards Malcolm Edgar

Reply via email to