Home » Modeling » EMF » Correct way to update transient crossrefs?
Correct way to update transient crossrefs? [message #1228436] |
Tue, 07 January 2014 08:28 |
Jens Rabe Messages: 81 Registered: September 2013 |
Member |
|
|
Hi,
I have the following problem:
A have two objects, A and B. A has a single-valued reference to B which is non-transient and proxy resolving is set to false. This is needed because A and B are serialized via Xtext. B has a many-valued reference to A which is transient and proxy resolving is set to true. The reference from B to A is the EOpposite of the one from A to B.
Now, when I create an A and a B and do myA.setB(myB) the back-reference is updated correctly. When I save both objects, the reference A.b is persisted correctly, the B.a is not persisted because it is transient. So far, so good.
Now, I need to load B and get the A's which reference my B (myB.getA()). When I only load B, this list is empty (correct, as the reference is transient). I now have to load all relevant files to the same resource set with which I loaded B, then, all references are set-up correctly (the order is not important for me).
Now, I have the following problem:
- I create a new A and B with no references to each other
- I load B into an Xtext editor (which uses its own resource set I cannot influence)
- I load A into another editor (so this A is in another resource set)
- In this editor, I tell the A to reference B.
- Now, I edit the B in the other editor. This must trigger changes to the referenced A. But because the B is in another resource set, it does not know that the A on disk has a new reference to it.
My first naive approach would be to re-scan all A's after saving B, and loading them to the resource set the B resides in. But this sounds like a brute-force approach.
Is there a better way of doing this?
|
|
|
Re: Correct way to update transient crossrefs? [message #1228512 is a reply to message #1228436] |
Tue, 07 January 2014 11:45 |
Ed Merks Messages: 33142 Registered: July 2009 |
Senior Member |
|
|
Jens,
Comments below.
On 07/01/2014 9:28 AM, Jens Rabe wrote:
> Hi,
>
> I have the following problem:
>
> A have two objects, A and B. A has a single-valued reference to B
> which is non-transient and proxy resolving is set to false. This is
> needed because A and B are serialized via Xtext. B has a many-valued
> reference to A which is transient and proxy resolving is set to true.
It will never typically never contain a proxy given you're not
serializing it...
> The reference from B to A is the EOpposite of the one from A to B.
>
> Now, when I create an A and a B and do myA.setB(myB) the
> back-reference is updated correctly. When I save both objects, the
> reference A.b is persisted correctly, the B.a is not persisted because
> it is transient. So far, so good.
>
> Now, I need to load B and get the A's which reference my B
> (myB.getA()). When I only load B, this list is empty (correct, as the
> reference is transient). I now have to load all relevant files to the
> same resource set with which I loaded B, then, all references are
> set-up correctly (the order is not important for me).
Given you need to load the other resources anyway, there's no so much
value in such a bidirectional reference is there?
>
> Now, I have the following problem:
> - I create a new A and B with no references to each other
> - I load B into an Xtext editor (which uses its own resource set I
> cannot influence)
> - I load A into another editor (so this A is in another resource set)
> - In this editor, I tell the A to reference B.
> - Now, I edit the B in the other editor. This must trigger changes to
> the referenced A. But because the B is in another resource set, it
> does not know that the A on disk has a new reference to it.
No, each resource set has it's own representations of the objects.
>
> My first naive approach would be to re-scan all A's after saving B,
> and loading them to the resource set the B resides in. But this sounds
> like a brute-force approach.
In the end, you can only solve this type of problem by indexing. Xtext
has a good indexer and you could use it to index any resource, not just
Xtext resources. E.g., we index *.ecore and *.genmodel so we can use
them in *.xcore.
>
> Is there a better way of doing this?
Xtext generally deals with this type of issue by indexing the resources
in the workspace. That's likely the best possible approach.
Ed Merks
Professional Support: https://www.macromodeling.com/
|
|
| | |
Goto Forum:
Current Time: Fri Apr 26 11:21:31 GMT 2024
Powered by FUDForum. Page generated in 0.02808 seconds
|