Resolving references during model creation [message #496717] |
Wed, 11 November 2009 07:10 |
Nirmal Sasidharan Messages: 120 Registered: July 2009 Location: Germany |
Senior Member |
|
|
Hi,
I would like to get some opinion on an approach I have taken to resolve references during model creation.
I have a situation where I have to create parts of my model independently and resolve the references between them after all parts are created (This is somehow the case due to the fact how the input data is persisted and read). In my input data, the references are specified as Strings (something like a Primary key - Foreign key relationship in RDBMS).
In short, the approach I have taken to tackle this is as follows. I adapt each of the EObjects on creation such that, when the key attribute (primary key I mentioned above) is set, it is indexed in a type specific map. Later when a reference needs to be set, I check the type of the EReference and see if it indexed already and sets the required EObject as reference (instead of the String name equivalent of it). I do have a problem in this approach that I cannot get the target reference by simply getting the type of the EReference (as it might be a super type (maybe abstract) and there might be many subtypes that are indexed). So I have to additionally pass the exact type of the reference to be set other then inferring the type from the EReference structural feature.
Could you please let me know if my approach is ok or if I am missing some EMF features which already provides such indexing facilities? The EMFIndex project seems to do something similar at a more generic level. Since I have to use Eclipse 3.4 and EMFIndex is supposed to have major changes due to SAP implementation, I am not preferring it at the moment.
Thanks in advance,
Nirmal
|
|
|
|
Re: Resolving references during model creation [message #496841 is a reply to message #496717] |
Wed, 11 November 2009 14:19 |
Ed Merks Messages: 33216 Registered: July 2009 |
Senior Member |
|
|
Nirmal,
Comments below.
Nirmal Sasidharan wrote:
> Hi,
>
> I would like to get some opinion on an approach I have taken to
> resolve references during model creation.
>
> I have a situation where I have to create parts of my model
> independently and resolve the references between them after all parts
> are created (This is somehow the case due to the fact how the input
> data is persisted and read). In my input data, the references are
> specified as Strings (something like a Primary key - Foreign key
> relationship in RDBMS).
>
> In short, the approach I have taken to tackle this is as follows. I
> adapt each of the EObjects on creation such that, when the key
> attribute (primary key I mentioned above) is set, it is indexed in a
> type specific map. Later when a reference needs to be set, I check
> the type of the EReference and see if it indexed already and sets the
> required EObject as reference (instead of the String name equivalent
> of it). I do have a problem in this approach that I cannot get the
> target reference by simply getting the type of the EReference (as it
> might be a super type (maybe abstract) and there might be many
> subtypes that are indexed). So I have to additionally pass the exact
> type of the reference to be set other then inferring the type from the
> EReference structural feature.
>
> Could you please let me know if my approach is ok or if I am missing
> some EMF features which already provides such indexing facilities? The
> EMFIndex project seems to do something similar at a more generic
> level. Since I have to use Eclipse 3.4 and EMFIndex is supposed to
> have major changes due to SAP implementation, I am not preferring it
> at the moment.
I'm not sure I fully understand your approach, but you might be better
of encoding the "string" information in the form of a URI and use an EMF
proxy. Any instance can act as a proxy by casting to InternalEObject
and using eSetProxyURI. Whenever such an object is fetched, EMF will
first try to resolve the proxy. That involves looking up the resource
for the trimmed URI and then looking up the fragment within that
resource, so you could have a resource that acts as an index on demand.
>
> Thanks in advance,
>
> Nirmal
Ed Merks
Professional Support: https://www.macromodeling.com/
|
|
|
|
|
Re: Resolving references during model creation [message #496949 is a reply to message #496888] |
Wed, 11 November 2009 20:11 |
Ed Merks Messages: 33216 Registered: July 2009 |
Senior Member |
|
|
Nirmal,
Comments below.
Nirmal Sasidharan wrote:
> Thanks Ed. Sorry that the description of my approach was not clear
> enough.
>
> "Resolve" in my earlier statement didn't really mean a resource
> resolution, it only meant resolving a object reference which is
> available in the input as "string" references. All objects will reside
> in the same resource.
It still sounds like the proxy mechanism could be used for that. You'd
just be pointing back at the resource itself and it would have logic to
do efficient indexing of whatever fragment syntax you're using.
>
> As you suggested, I am thinking of using an EMF proxy. Is EMF proxy a
> good idea even when I know that the objects will reside in the same
> resource?
Yes, I think that will work more naturally. In XText for example
they're using this type of approach to lazily look up identifiers...
>
> Thanks and regards,
> Nirmal
Ed Merks
Professional Support: https://www.macromodeling.com/
|
|
|
Powered by
FUDForum. Page generated in 0.04361 seconds