Eclipse Community Forums - RDF feed
https://www.eclipse.org/forums/
Eclipse Community ForumsSerializing EMF Objects
https://www.eclipse.org/forums/index.php/mv/msg/370086/903983/#msg_903983
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.
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!]]>Ed Merks2012-08-27T14:05:25-00:00Re: Serializing EMF Objects
https://www.eclipse.org/forums/index.php/mv/msg/370086/904029/#msg_904029
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. ]]>Jeff Rose2012-08-27T15:34:15-00:00Re: Serializing EMF Objects
https://www.eclipse.org/forums/index.php/mv/msg/370086/904077/#msg_904077
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...]]>Ed Merks2012-08-27T17:51:34-00:00