You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@cayenne.apache.org by Malcolm Edgar <ma...@gmail.com> on 2006/06/16 03:14:19 UTC

Cayenne & Flex

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);
    }

}

Re: Cayenne & Flex

Posted by Malcolm Edgar <ma...@gmail.com>.
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


Re: Cayenne & Flex

Posted by Andrus Adamchik <an...@objectstyle.org>.

> ((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);
>    }
>
> }