Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » Serializing EMF Objects
Serializing EMF Objects [message #903983] Mon, 27 August 2012 13:47 Go to next message
Jeff Rose is currently offline Jeff Rose
Messages: 2
Registered: August 2012
Junior Member
I have an EMF model object that is created while my application is running and is intended to not be persisted. This object can be cached, which behaves normally in-memory, but when flushed to disk I get errors that the object is not Serializable. This EObject has containment over other objects that I cannot modify, so I can't just re-write everything to be Serializable.

I know EMF has ways to persist these objects through Resources, since we do this in other areas of our application. I'm wondering if there's a way EMF can flatten this object down and handle the serialization for me without creating a Resource to back it. Currently our plan is to create a Resource for the object, even when we don't intend to persist it, and clean it up when we're done, but this seems somewhat sloppy.

I'd appreciate any feedback about Serializing EObjects and/or other suggestions forward.

Thanks!
Re: Serializing EMF Objects [message #903993 is a reply to message #903983] Mon, 27 August 2012 14:05 Go to previous messageGo to next message
Ed Merks is currently offline Ed Merks
Messages: 26141
Registered: July 2009
Senior Member
Jeff,

Comments below.

On 27/08/2012 3:47 PM, Jeff Rose wrote:
> I have an EMF model object that is created while my application is
> running and is intended to not be persisted. This object can be
> cached, which behaves normally in-memory, but when flushed to disk I
> get errors that the object is not Serializable. This EObject has
> containment over other objects that I cannot modify, so I can't just
> re-write everything to be Serializable.
>
> I know EMF has ways to persist these objects through Resources, since
> we do this in other areas of our application. I'm wondering if there's
> a way EMF can flatten this object down and handle the serialization
> for me without creating a Resource to back it.
Not generally no. But BinaryResourceImpl contains infrastructure that
you can reuse to serialize/deserialize an object to/from bytes, i.e.,
EObjectOutputStream and EObjectOutputStream.
> Currently our plan is to create a Resource for the object, even when
> we don't intend to persist it, and clean it up when we're done, but
> this seems somewhat sloppy.
Why can't it just always be contained by a resource?
> I'd appreciate any feedback about Serializing EObjects and/or other
> suggestions forward.
> Thanks!
Re: Serializing EMF Objects [message #904029 is a reply to message #903993] Mon, 27 August 2012 15:34 Go to previous messageGo to next message
Jeff Rose is currently offline Jeff Rose
Messages: 2
Registered: August 2012
Junior Member
Ed,

Thanks for the quick response. Few questions:

Quote:
> I know EMF has ways to persist these objects through Resources, since
> we do this in other areas of our application. I'm wondering if there's
> a way EMF can flatten this object down and handle the serialization
> for me without creating a Resource to back it.
Not generally no. But BinaryResourceImpl contains infrastructure that
you can reuse to serialize/deserialize an object to/from bytes, i.e.,
EObjectOutputStream and EObjectOutputStream.

Do you think this type of resource is capable of handling EObjects whose attributes are not themselves Serializable?

Quote:
> Currently our plan is to create a Resource for the object, even when
> we don't intend to persist it, and clean it up when we're done, but
> this seems somewhat sloppy.
Why can't it just always be contained by a resource?

We're trying to avoid Resources for a few reasons. We create these objects at runtime, and we could potentially create a lot of them. They may not need to be written to disk at all, and that will be managed by our cache. It is my understanding that creating a Resource also creates a file to back the object. If that is correct, we'd be using a lot of time writing to disk we create these Resources, which would really add up. We also don't want them persisted in the model indefinitely, so we'd want to clean all of them up.
Re: Serializing EMF Objects [message #904077 is a reply to message #904029] Mon, 27 August 2012 17:51 Go to previous message
Ed Merks is currently offline Ed Merks
Messages: 26141
Registered: July 2009
Senior Member
Jeff,

Comments below.

On 27/08/2012 5:34 PM, Jeff Rose wrote:
> Ed,
>
> Thanks for the quick response. Few questions:
>
> Quote:
>> > I know EMF has ways to persist these objects through Resources,
>> since > we do this in other areas of our application. I'm wondering
>> if there's > a way EMF can flatten this object down and handle the
>> serialization > for me without creating a Resource to back it. Not
>> generally no. But BinaryResourceImpl contains infrastructure that you
>> can reuse to serialize/deserialize an object to/from bytes, i.e.,
>> EObjectOutputStream and EObjectOutputStream.
>
> Do you think this type of resource is capable of handling EObjects
> whose attributes are not themselves Serializable?
It handles any EObjects.
> Quote:
>> > Currently our plan is to create a Resource for the object, even
>> when > we don't intend to persist it, and clean it up when we're
>> done, but > this seems somewhat sloppy.
>> Why can't it just always be contained by a resource?
>
> We're trying to avoid Resources for a few reasons. We create these
> objects at runtime, and we could potentially create a lot of them.
> They may not need to be written to disk at all, and that will be
> managed by our cache. It is my understanding that creating a Resource
> also creates a file to back the object.
No, a resource need not correspond to something any any backing store.
> If that is correct, we'd be using a lot of time writing to disk we
> create these Resources, which would really add up.
Yes, but that's not the case.
> We also don't want them persisted in the model indefinitely, so we'd
> want to clean all of them up.
ResourceSet.createResource creates a new resource that's not backed in
any way. Until you call save, no attempt will be made to persist them
to a backing store. The URI of the resource might not even allow it to
be saved...
Previous Topic:Doxygen documentation
Next Topic:[EMF Compare] Hide Nodes
Goto Forum:
  


Current Time: Fri Oct 24 21:27:26 GMT 2014

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

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