Saving/Loading to/from BinaryResourceImpl [message #1383901] |
Tue, 27 May 2014 06:10 |
|
Hey
I have some code to persist a linked/merged/patched/whatever xtext dsl based EMF model to a BinaryResourceImpl, and re-read it from such. This seems to work rather well, however, when re-reading the model from the resource, it seems to disappear suddenly. I have this method:
def load(InputStream binary) {
try {
val bin = resourceSet.createResource(URI.createURI("http://www.wamas.com/dummy.wdlbin"));
bin.load(binary, binaryResourceOptions);
contents = bin.allContents.toIterable.filter(TopLevelElement)
packages = bin.allContents.toIterable.filter(Package)
} finally {
binary.close
}
}
when i set a breakpoint at the end of the method, the contents looks ok. All elements that i'd expect are there. When i step out of this method, contents disappears (is an empty collection then).
What the heck is going on here? what am i missing? any ideas? Thanks!
|
|
|
|
|
|
Re: Saving/Loading to/from BinaryResourceImpl [message #1383942 is a reply to message #1383901] |
Tue, 27 May 2014 10:27 |
Ed Willink Messages: 7670 Registered: July 2009 |
Senior Member |
|
|
Hi
A common problem with persistence is accidentally neglecting to define
the reference as containment, or defining it as transient/volatile.
A common problem while running is child-stealing, adding an object as a
child of a new container removes it from an old container.
For non-trivial models child-stealing can cause such obscure problems
that I add
@Override
protected void eBasicSetContainer(InternalEObject newContainer, int
newContainerFeatureID) {
if (newContainer != null) {
EObject oldContainer = eContainer();
assert ((oldContainer == null) || (newContainer ==
oldContainer) || (oldContainer.eResource() == null));
}
super.eBasicSetContainer(newContainer, newContainerFeatureID);
}
@Override
public NotificationChain eBasicSetContainer(InternalEObject
newContainer, int newContainerFeatureID, NotificationChain msgs) {
if (newContainer != null) {
EObject oldContainer = eContainer();
assert ((oldContainer == null) || (newContainer ==
oldContainer) || (oldContainer.eResource() == null));
}
return super.eBasicSetContainer(newContainer,
newContainerFeatureID, msgs);
}
to my root XXXEObjectImpl.
Minor downside; if you really want to reparent an EObject you must
explicitly set its parent to null in the interim.
Regards
Ed Willink
On 27/05/2014 07:10, Markus Duft wrote:
> Hey
>
> I have some code to persist a linked/merged/patched/whatever xtext dsl
> based EMF model to a BinaryResourceImpl, and re-read it from such.
> This seems to work rather well, however, when re-reading the model
> from the resource, it seems to disappear suddenly. I have this method:
>
>
> def load(InputStream binary) {
> try {
> val bin =
> resourceSet.createResource(URI.createURI("http://www.wamas.com/dummy.wdlbin"));
>
> bin.load(binary, binaryResourceOptions);
>
> contents = bin.allContents.toIterable.filter(TopLevelElement)
> packages = bin.allContents.toIterable.filter(Package)
> } finally {
> binary.close
> }
> }
>
>
> when i set a breakpoint at the end of the method, the contents looks
> ok. All elements that i'd expect are there. When i step out of this
> method, contents disappears (is an empty collection then).
>
> What the heck is going on here? what am i missing? any ideas? Thanks!
|
|
|
Re: Saving/Loading to/from BinaryResourceImpl [message #1383943 is a reply to message #1383942] |
Tue, 27 May 2014 10:38 |
|
thanks for the hints.
@Ed: thanks for the insight, very good to keep that in mind In this case i don't think that i have this kind of problem. I verified that the model is persisted correctly (all elements are in the file), and that it is read correctly (model.contents contains all root elements, and in the debugger i can have a look at them). Just right after "bin.allContents.toIterable.filter(TopLevelElement)" the returned collection is filled, and half a second later it's empty, without any (obvious, in the current thread) code running...
|
|
|
|
Powered by
FUDForum. Page generated in 0.04153 seconds