Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » Trouble with Proxy Resolution
Trouble with Proxy Resolution [message #423581] Thu, 02 October 2008 14:55 Go to next message
Greg Fox is currently offline Greg FoxFriend
Messages: 39
Registered: July 2009
Member
I am having trouble with proxy resolution. My model doesn't use
containment relationships, they are all references.

A hasManyBs
B hasManyCs

An instance of A is created during resource load and added to the resource
contents.

When I do "a.hasManyBs.toArray()" the Bs resolve but are not contained in
the resource.

If I then try to do "b.hasManyCs.toArray()", the proxy resolution seems to
fail because B does not belong to a resource.

I have tried to add each object to the resource as they are loaded but I
get exceptions when doing that. I am not sure if this is the correct
approach or not anyway.

What approach should I use to make this model behave as expected in EMF?
Re: Trouble with Proxy Resolution [message #423588 is a reply to message #423581] Thu, 02 October 2008 15:48 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: cdamus.zeligsoft.com

Hi, Greg,

When the Bs are resolved, the ResourceSet is ultimately responsible for
resolving them by loading the resources that contain the Bs. Thus, the
Bs should already be contained by resources in the same resource set as
A, but they would never be expected to be in the same *resource* as A
because then they wouldn't have been proxies in the first place.

I think the question is how does proxy resolution yield B instances that
aren't in any resource. They must be in a resource. Does your
application somehow customize the proxy-resolution code in the
ResourceSet (the getEObject(...) method)?

Cheers,

Christian


Greg wrote:
> I am having trouble with proxy resolution. My model doesn't use
> containment relationships, they are all references.
> A hasManyBs
> B hasManyCs
>
> An instance of A is created during resource load and added to the
> resource contents.
>
> When I do "a.hasManyBs.toArray()" the Bs resolve but are not contained
> in the resource.
>
> If I then try to do "b.hasManyCs.toArray()", the proxy resolution seems
> to fail because B does not belong to a resource.
>
> I have tried to add each object to the resource as they are loaded but I
> get exceptions when doing that. I am not sure if this is the correct
> approach or not anyway.
>
> What approach should I use to make this model behave as expected in EMF?
Re: Trouble with Proxy Resolution [message #423589 is a reply to message #423581] Thu, 02 October 2008 15:50 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33137
Registered: July 2009
Senior Member
Greg,

Comments below.

Greg wrote:
> I am having trouble with proxy resolution. My model doesn't use
> containment relationships, they are all references.
> A hasManyBs
> B hasManyCs
>
> An instance of A is created during resource load and added to the
> resource contents.
>
> When I do "a.hasManyBs.toArray()" the Bs resolve but are not contained
> in the resource.
This sounds impossible. To resolve they must be found in a resource...
>
> If I then try to do "b.hasManyCs.toArray()", the proxy resolution
> seems to fail because B does not belong to a resource.
It sounds like it failed earlier on B. How can B not be in a resource?
>
> I have tried to add each object to the resource as they are loaded but
> I get exceptions when doing that.
Each object should have been in a resource when it was saved and all
these inter-object references should be resolved against those.
> I am not sure if this is the correct approach or not anyway.
No, it's not. You should not have to intervene.
>
> What approach should I use to make this model behave as expected in EMF?
If there are no containment references, all objects need to be in the
root of the resource initially when you save, and then you'll definitely
need to use an XMIResourceImpl because an XMLResourceImpl won't save
anything except the first root object (which is probably the source of
your problem).


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Trouble with Proxy Resolution [message #423596 is a reply to message #423589] Thu, 02 October 2008 18:29 Go to previous messageGo to next message
Greg Fox is currently offline Greg FoxFriend
Messages: 39
Registered: July 2009
Member
The source for the data is not an XML file it is a custom data format. I
have a custom ResourceImpl that I expected to represent the whole data
set. It is in this ResourceImpl that I thought I needed to add the
objects to the resource contents as they were being resolved.

When object B is getting resolved through the proxy mechanism I have code
in the getEObjectById that populates the data. This part seems to work
correctly but does not automatically add it to the resource since it is
not contained.
Re: Trouble with Proxy Resolution [message #423597 is a reply to message #423588] Thu, 02 October 2008 18:33 Go to previous messageGo to next message
Greg Fox is currently offline Greg FoxFriend
Messages: 39
Registered: July 2009
Member
Yes we customize the proxy resolution since we are not reading from an XML
file and we have customized data source. We put the code to populate the
object into the getEObjectById and use the URI to look the data value up
in our data store. It is at this point that I thought I needed to add the
resolved object instance to the resource.
Re: Trouble with Proxy Resolution [message #423598 is a reply to message #423596] Thu, 02 October 2008 18:37 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33137
Registered: July 2009
Senior Member
Greg,

I see. If the objects are not indirectly contained by the resource,
then they need to be directly contained...


Greg Fox wrote:
> The source for the data is not an XML file it is a custom data
> format. I have a custom ResourceImpl that I expected to represent the
> whole data set. It is in this ResourceImpl that I thought I needed to
> add the objects to the resource contents as they were being resolved.
>
> When object B is getting resolved through the proxy mechanism I have
> code in the getEObjectById that populates the data. This part seems
> to work correctly but does not automatically add it to the resource
> since it is not contained.
>
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Trouble with Proxy Resolution [message #423599 is a reply to message #423597] Thu, 02 October 2008 18:42 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33137
Registered: July 2009
Senior Member
Greg,

So what kind of exceptions do you get? If you have some way of fluffing
up the object on demand, you need to ensure it's attached to the
resource while doing that...


Greg Fox wrote:
> Yes we customize the proxy resolution since we are not reading from an
> XML file and we have customized data source. We put the code to
> populate the object into the getEObjectById and use the URI to look
> the data value up in our data store. It is at this point that I
> thought I needed to add the resolved object instance to the resource.


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Trouble with Proxy Resolution [message #423602 is a reply to message #423599] Thu, 02 October 2008 19:12 Go to previous messageGo to next message
Greg Fox is currently offline Greg FoxFriend
Messages: 39
Registered: July 2009
Member
I tracked it down to the TransactionChangeListener.

IllegalStateException ise =
new IllegalStateException(Messages.noWriteTx);


Here is my method from my ResourceImpl :
protected EObject getEObjectByID(String id) {
EObject result = null;
MMObj obj = MMObj.getInstance(getModelSource().getModel(), ObjId
.getInstance(Long.valueOf(id)));

// If the MMObj is in a deleted status, then do not continue
if (obj.getChgStatus() == ChgStatus.DELETED_ITEM) {
return null;
} else {
MetaModelResourceSync synch = ResourceSyncFactory
.getResourceSyncByOTC(obj.getObjTypeCode());
if (synch != null) {
result = (EObject) synch.load(this, obj.getId().getValue());
this.contents.add(result);
}
}
return result;
}
Re: Trouble with Proxy Resolution [message #423608 is a reply to message #423602] Thu, 02 October 2008 20:26 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: cdamus.zeligsoft.com

Hi, Greg,

Your TransactionalEditingDomain will consider this addition of the
object to a resource as a model change, which requires a read/write
transaction. Ordinary proxy resolution is compatible with a read-only
context because it doesn't actually change the "abstract state" of any
EObjects or Resources.

You will need to do one of:

- execute a command with the Transaction.UNPROTECTED option to
add the object to the resource. This option is required in
case the current thread has a read-only transaction in progress,
which is probably likely. Also, you probably don't want this
change to be undoable

- toggle the eDeliver() state of the resource off and on around
the insertion of the object, so that the editing domain doesn't
hear about the change

HTH,

Christian


Greg Fox wrote:
> I tracked it down to the TransactionChangeListener.
>
> IllegalStateException ise = new
> IllegalStateException(Messages.noWriteTx);
>
>
> Here is my method from my ResourceImpl :
> protected EObject getEObjectByID(String id) {
> EObject result = null;
> MMObj obj = MMObj.getInstance(getModelSource().getModel(), ObjId
> .getInstance(Long.valueOf(id)));
>
> // If the MMObj is in a deleted status, then do not continue
> if (obj.getChgStatus() == ChgStatus.DELETED_ITEM) {
> return null;
> } else {
> MetaModelResourceSync synch = ResourceSyncFactory
> .getResourceSyncByOTC(obj.getObjTypeCode());
> if (synch != null) {
> result = (EObject) synch.load(this, obj.getId().getValue());
> this.contents.add(result);
> }
> }
> return result;
> }
>
Re: Trouble with Proxy Resolution [message #423609 is a reply to message #423608] Thu, 02 October 2008 20:51 Go to previous message
Greg Fox is currently offline Greg FoxFriend
Messages: 39
Registered: July 2009
Member
That is what was missing. Thanks to both of you for the help
Previous Topic:Eclipse/JUnit test works, Maven test fails...
Next Topic:NPE in EPackageImpl.initializeFromLoadedEPackage when loadInitialization="true"
Goto Forum:
  


Current Time: Fri Apr 19 11:15:46 GMT 2024

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

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

Back to the top