Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » Avoiding "Cannot modify resource set without a write transaction" in lazy initialization
Avoiding "Cannot modify resource set without a write transaction" in lazy initialization [message #422549] Tue, 09 September 2008 00:19 Go to next message
Eclipse UserFriend
Originally posted by: juancappi.yahoo.es

Hi everyone,

I'm migrating the code from an existing application to use the
Transactional editing domain.
Part of the EMF related code consists in keeping some complicated cross
references by means of a "manager". The problem is that some of those
references are created in a lazy way (the code below is just a
simplified example of what is causing me troubles).
Now that I migrated the code, I get the well known error "Cannot modify
resource set without a write transaction" since the method in certain
cases modifies the underlying structure (and isn't invoked from a
command since supposedly it's just a getter that returns a collection).
On the other hand, my TransactionalEditingDomain was defined and is
always used from an external plugin that is more close to the UI than
the model so that I can't use it since there would be a circular
dependency... besides, I believe it wouldn't be right to instantiate and
invoke a command in the getAssociationFor method, right?

public EList getAssociationFor(SomeClass element) {
EList result = (EList) this.getMapping().get(element);
if (result == null) {
result = new ArrayList();
manager.getMapping().put(element,result);
}
return result;
}

So the question is, how do I make this right? In the worse case, is
there a way to temporarily disable the notifications (in the scope of
this method, for instance)?

Any help/hint would be greatly appreciated.
Thanks and regards,

-Juan
Re: Avoiding "Cannot modify resource set without a write transaction" in lazy initializati [message #422560 is a reply to message #422549] Tue, 09 September 2008 12:47 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33141
Registered: July 2009
Senior Member
Juan,

Comments below.


Juan Cappi wrote:
> Hi everyone,
>
> I'm migrating the code from an existing application to use the
> Transactional editing domain.
> Part of the EMF related code consists in keeping some complicated
> cross references by means of a "manager". The problem is that some of
> those references are created in a lazy way (the code below is just a
> simplified example of what is causing me troubles).
> Now that I migrated the code, I get the well known error "Cannot
> modify resource set without a write transaction" since the method in
> certain cases modifies the underlying structure (and isn't invoked
> from a command since supposedly it's just a getter that returns a
> collection).
> On the other hand, my TransactionalEditingDomain was defined and is
> always used from an external plugin that is more close to the UI than
> the model so that I can't use it since there would be a circular
> dependency... besides, I believe it wouldn't be right to instantiate
> and invoke a command in the getAssociationFor method, right?
>
> public EList getAssociationFor(SomeClass element) {
> EList result = (EList) this.getMapping().get(element);
> if (result == null) {
> result = new ArrayList();
Hmmm. ArrayList isn't an EList...
> manager.getMapping().put(element,result);
> }
> return result;
> }
>
> So the question is, how do I make this right? In the worse case, is
> there a way to temporarily disable the notifications (in the scope of
> this method, for instance)?
EObject inherits from Notifier and that has an eSetDeliver(false).
>
>
> Any help/hint would be greatly appreciated.
> Thanks and regards,
>
> -Juan


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Avoiding "Cannot modify resource set without a write transaction" in lazy initializati [message #422565 is a reply to message #422549] Tue, 09 September 2008 13:22 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: cdamus.zeligsoft.com

Hi, Juan,

To add to Ed's indication of eSetDeliver, I think it is safe to disable
notification for what is basically an "initial value" in this case,
because it is a modification to a feature that hasn't yet been observed
by any reader. However, it does have a potential concurrency issue in
possible multiple-initialization of the list, which wold result in
multiple threads seeing distinct lists, of which only one is the "real"
value.

I'm not sure that there is much that you could do about this without the
probably considerable overhead of checking whether a transaction is in
progress and creating a read-only transaction ("runExclusive") if there
isn't one.

HTH,

Christian


Juan Cappi wrote:
> Hi everyone,
>
> I'm migrating the code from an existing application to use the
> Transactional editing domain.
> Part of the EMF related code consists in keeping some complicated cross
> references by means of a "manager". The problem is that some of those
> references are created in a lazy way (the code below is just a
> simplified example of what is causing me troubles).
> Now that I migrated the code, I get the well known error "Cannot modify
> resource set without a write transaction" since the method in certain
> cases modifies the underlying structure (and isn't invoked from a
> command since supposedly it's just a getter that returns a collection).
> On the other hand, my TransactionalEditingDomain was defined and is
> always used from an external plugin that is more close to the UI than
> the model so that I can't use it since there would be a circular
> dependency... besides, I believe it wouldn't be right to instantiate and
> invoke a command in the getAssociationFor method, right?
>
> public EList getAssociationFor(SomeClass element) {
> EList result = (EList) this.getMapping().get(element);
> if (result == null) {
> result = new ArrayList();
> manager.getMapping().put(element,result);
> }
> return result;
> }
>
> So the question is, how do I make this right? In the worse case, is
> there a way to temporarily disable the notifications (in the scope of
> this method, for instance)?
>
> Any help/hint would be greatly appreciated.
> Thanks and regards,
>
> -Juan
Re: Avoiding "Cannot modify resource set without a write transaction" in lazy initializati [message #422575 is a reply to message #422560] Tue, 09 September 2008 19:11 Go to previous message
Eclipse UserFriend
Originally posted by: juancappi.yahoo.es

Hi Ed, Christian,

Thanks a lot for the fast response. It worked perfectly.
Thanks Christian for the warning too. I think it makes a lot of sense.
I'm now more convinced that for this case may be just fine to disable
notifications.
Thanks and regards,

-Juan

Ed Merks wrote:
> Juan,
>
> Comments below.
>
>
> Juan Cappi wrote:
>> Hi everyone,
>>
>> I'm migrating the code from an existing application to use the
>> Transactional editing domain.
>> Part of the EMF related code consists in keeping some complicated
>> cross references by means of a "manager". The problem is that some of
>> those references are created in a lazy way (the code below is just a
>> simplified example of what is causing me troubles).
>> Now that I migrated the code, I get the well known error "Cannot
>> modify resource set without a write transaction" since the method in
>> certain cases modifies the underlying structure (and isn't invoked
>> from a command since supposedly it's just a getter that returns a
>> collection).
>> On the other hand, my TransactionalEditingDomain was defined and is
>> always used from an external plugin that is more close to the UI than
>> the model so that I can't use it since there would be a circular
>> dependency... besides, I believe it wouldn't be right to instantiate
>> and invoke a command in the getAssociationFor method, right?
>>
>> public EList getAssociationFor(SomeClass element) {
>> EList result = (EList) this.getMapping().get(element);
>> if (result == null) {
>> result = new ArrayList();
> Hmmm. ArrayList isn't an EList...
>> manager.getMapping().put(element,result);
>> }
>> return result;
>> }
>>
>> So the question is, how do I make this right? In the worse case, is
>> there a way to temporarily disable the notifications (in the scope of
>> this method, for instance)?
> EObject inherits from Notifier and that has an eSetDeliver(false).
>>
>>
>> Any help/hint would be greatly appreciated.
>> Thanks and regards,
>>
>> -Juan
Previous Topic:Re: OCL validation example violates extension point schema
Next Topic:[Teneo] 0..* associations, how to fetch parent from child
Goto Forum:
  


Current Time: Thu Apr 25 15:29:21 GMT 2024

Powered by FUDForum. Page generated in 0.03205 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top