cayenne-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Sébastien Pérès-Labourdette <sebastien.peres-labourde...@omerin.com>
Subject Re: Dynamic datasource switch
Date Mon, 29 Apr 2013 13:29:00 GMT
I mean at runtime, for the 2 nodes of the datadomain that needs it.

On 29/04/2013 14:33, Andrus Adamchik wrote:
> Can you do it in the Modeler (DataMap -> DataNode dropdown)?
>
> On Apr 29, 2013, at 3:31 PM, Sébastien Pérès-Labourdette <sebastien.peres-labourdette@omerin.com>
wrote:
>
>> Hi Andrus. I'm trying to set it up now.
>> Please, how do you bind a specific map to a specific node ?
>> I have 6 nodes and only 2 need the datasource configuration stuff (Module)
>>
>> SPL
>>
>> On 28/04/2013 08:40, Andrus Adamchik wrote:
>>> FWIW, it should be safe to use 3.1B2 already. The API is frozen, and most bugs
are fixed. But this is your decision of course.
>>>
>>> A.
>>>
>>> On Apr 26, 2013, at 4:55 PM, Sébastien Pérès-Labourdette <sebastien.peres-labourdette@omerin.com>
wrote:
>>>
>>>> I'll make it thread safe for the moment, and will refactor this stuff as
>>>> soon as 3.1 is released.
>>>> Thank you very much Andrus.
>>>>
>>>> SPL
>>>>
>>>> On 26/04/2013 15:00, Andrus Adamchik wrote:
>>>>> Hi,
>>>>>
>>>>> if that all happens in the same application, then it is not thread-safe.
Cayenne stack below DataContext is usually shared. Only DataContext is dedicated to a user
(if you make it so). A safer solution is to have 3 stacks. In Cayenne 3.0 this can be achieved
with multiple DataDomains per Configuration (although it is a pain to maintain). In Cayenne
3.1 you'd simply create 3 ServerRuntime's. 
>>>>>
>>>>> Then the trick is to use the right backend when creating a new DataContext.

>>>>>
>>>>> You are using the opposite method - switching stack underneath the same
DataContext. While it might work in some scenarios, it generally looks counterintuitive and
error-prone.
>>>>>
>>>>> Cheers,
>>>>> Andrus
>>>>>
>>>>>
>>>>> On Apr 26, 2013, at 8:21 AM, Sébastien Pérès-Labourdette <sebastien.peres-labourdette@omerin.com>
wrote:
>>>>>> Hi.
>>>>>>
>>>>>> I have 3 databases which shares exactly the same schema.
>>>>>> I sometimes need to switch from one to another programatically.
>>>>>>
>>>>>> For that purpose, i wrote the folowing code :
>>>>>>
>>>>>>  public void setCompany(int salesAgencyId) {
>>>>>>      this.salesAgencyId = salesAgencyId;
>>>>>>      switch (salesAgencyId) {
>>>>>>          case COMPANY_C1:
>>>>>>              setC1DataContext();
>>>>>>              break;
>>>>>>          case COMPANY_C2:
>>>>>>              setC2DataContext();
>>>>>>              break;
>>>>>>          case COMPANY_C3:
>>>>>>              setC3DataContext();
>>>>>>              break;
>>>>>>
>>>>>>          default:
>>>>>>              setC1DataContext();
>>>>>>              break;
>>>>>>      }
>>>>>>  }
>>>>>>
>>>>>>  private static void setC1DataContext() {
>>>>>>      if (COMPANY_CURRENT != COMPANY_C1) {
>>>>>>          LOG.debug("switching context from " + COMPANY_CURRENT +
" to
>>>>>> " + COMPANY_C1);
>>>>>>          COMPANY_CURRENT = COMPANY_C1;
>>>>>>          getDataContext().getQueryCache().clear();
>>>>>>          getDataContext().getObjectStore().getDataRowCache().clear();
>>>>>>
>>>>>>
>>>>>> Configuration.getSharedConfiguration().getDomain().getNode("c").setDataSource(c1DataSource);
>>>>>>      }
>>>>>>  }
>>>>>>
>>>>>> It just works perfectly most of the time.
>>>>>> But sometimes it fails and keep the connection on the previous datasource.
>>>>>>
>>>>>> Any of you may give me any hint on that issue ?
>>>>>>
>>>>>> Thanks in advance.
>>>>>> SPL
>>>>>>
>>



Mime
View raw message