You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@cayenne.apache.org by akira <wi...@gmail.com> on 2009/09/02 09:45:37 UTC

How to get domain from context

Hi, i'm getting my context this way: ObjectContext context =  
DataContext.getThreadObjectContext(). How to know the domain that the  
context is using? If i get context as a DataContext type i can obtain  
the domain using : getParentDataDomain().getName() right? On my app i  
have to change the domain under certain circumstancies and on my code  
i'm trying to do something like this:
ObjectContext context = DataContext.getThreadObjectContext()
if (context.getDomain() == domainToQueryNow) {
  return context;
} else {
  DataContext.createDataContext(domainToQueryNow);
}

TIA.

Re: How to get domain from context

Posted by akira <wi...@gmail.com>.
Hi Andrus, thanks for replying, i didn't thinked about casting it to  
DataContext! Thanks.

On Sep 2, 2009, at 4:54 PM, Andrus Adamchik wrote:

> Hi akira,
>
> If you need explicit access to the domain, you will have to cast you  
> ObjectContext to DataContext and use 'getParentDataDomain':
>
> DataDomain domain = ((DataContext) context).getParentDataDomain();
>
> Andrus
>
> On Sep 2, 2009, at 10:45 AM, akira wrote:
>
>> Hi, i'm getting my context this way: ObjectContext context =  
>> DataContext.getThreadObjectContext(). How to know the domain that  
>> the context is using? If i get context as a DataContext type i can  
>> obtain the domain using : getParentDataDomain().getName() right? On  
>> my app i have to change the domain under certain circumstancies and  
>> on my code i'm trying to do something like this:
>> ObjectContext context = DataContext.getThreadObjectContext()
>> if (context.getDomain() == domainToQueryNow) {
>> return context;
>> } else {
>> DataContext.createDataContext(domainToQueryNow);
>> }
>>
>> TIA.
>


Re: How to get domain from context

Posted by Andrus Adamchik <an...@objectstyle.org>.
Hi akira,

If you need explicit access to the domain, you will have to cast you  
ObjectContext to DataContext and use 'getParentDataDomain':

DataDomain domain = ((DataContext) context).getParentDataDomain();

Andrus

On Sep 2, 2009, at 10:45 AM, akira wrote:

> Hi, i'm getting my context this way: ObjectContext context =  
> DataContext.getThreadObjectContext(). How to know the domain that  
> the context is using? If i get context as a DataContext type i can  
> obtain the domain using : getParentDataDomain().getName() right? On  
> my app i have to change the domain under certain circumstancies and  
> on my code i'm trying to do something like this:
> ObjectContext context = DataContext.getThreadObjectContext()
> if (context.getDomain() == domainToQueryNow) {
> return context;
> } else {
> DataContext.createDataContext(domainToQueryNow);
> }
>
> TIA.