Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » Automatically loading "child" resources when "parent" resource is loaded
Automatically loading "child" resources when "parent" resource is loaded [message #422898] Thu, 18 September 2008 10:54 Go to next message
Eclipse UserFriend
Originally posted by: twominutehate.joinpoint.org

Hello,

in my Metamodel Class A has a transient, multi-valued, containment
reference "children" to Class B.
"A" and each instance of "B" are saved in seperate Resources. When A's
resource is loaded, I want to transparently load all "B" resources
aswell. How many children "A" has is determined by the application by
looking for "B"-resources in the corresponding directory.
As the reference to B is transient, I can't take advantage of EMF proxy
resolving/demand-loading facility.

My first idea was to implement a ResourceSetListener, that returns a
Trigger when the TransactionalEditingDomain notifies me about resource
state chages. The trigger would have been responsible for loading all
related "B"-resources and add their contents to "A.children".

But I've noticed, that the ResourceChangeListener is not always called.
When the resource for an "A" instance is demand-loaded in a read-only
transaction for example, the ResourceSetListener doesn't receive the
corresponding notification.
Is this expected behavior?


Another way would be to add an Adapter to A's resources. When it
detects, that A's "loaded" feature has been set, it schedules an Eclipse
Job, that does essentially the same as the aforementioned trigger.

Could anybody tell me whether there's another, perhaps more preferable
way to do what I want?

Cheers!
Re: Automatically loading "child" resources when "parent" resource is loaded [message #422906 is a reply to message #422898] Thu, 18 September 2008 13:32 Go to previous message
Eclipse UserFriend
Originally posted by: cdamus.zeligsoft.com

Hi, Ömer,

See some replies in-line, below.

HTH,

Christian


Ömer Yildiz wrote:
> Hello,
>
> in my Metamodel Class A has a transient, multi-valued, containment
> reference "children" to Class B.
> "A" and each instance of "B" are saved in seperate Resources. When A's
> resource is loaded, I want to transparently load all "B" resources
> aswell. How many children "A" has is determined by the application by
> looking for "B"-resources in the corresponding directory.
> As the reference to B is transient, I can't take advantage of EMF proxy
> resolving/demand-loading facility.

Why should it be transient? It sounds like your application depends on
these associations of As to Bs, so perhaps it should be persistent.
Transient containment sounds to me like asking for trouble ...


> My first idea was to implement a ResourceSetListener, that returns a
> Trigger when the TransactionalEditingDomain notifies me about resource
> state chages. The trigger would have been responsible for loading all
> related "B"-resources and add their contents to "A.children".
>
> But I've noticed, that the ResourceChangeListener is not always called.
> When the resource for an "A" instance is demand-loaded in a read-only
> transaction for example, the ResourceSetListener doesn't receive the
> corresponding notification.
> Is this expected behavior?

Yes, it is. The transaction's data-integrity mechanisms (triggers and
validation) are only invoked by read/write transactions, as their
purpose is to safeguard the resource set when changes are performed. In
this regard, the loading of resources in a read-only context (by proxy
resolution or otherwise) is not considered as a change to the state of
the data. It is only revealing more data that, conceptually, already
exists.


> Another way would be to add an Adapter to A's resources. When it
> detects, that A's "loaded" feature has been set, it schedules an Eclipse
> Job, that does essentially the same as the aforementioned trigger.

Except that, in the case of a read-only transaction, your modification
of the As associated with the Bs that the adapter loads would bomb with
an IllegalStateException on the absence of a read/write transaction.


> Could anybody tell me whether there's another, perhaps more preferable
> way to do what I want?

Why not use cross-resource containment? This is what it's for. It just
seems like make-work to externally implement a lazy-loading mechanism
that EMF already provides.


>
> Cheers!
Previous Topic:Model instance transformation framework
Next Topic:Forcing EMF code generation for EPackage that contain sub-EPackage only
Goto Forum:
  


Current Time: Mon Jan 20 15:55:49 GMT 2020

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

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

Back to the top