Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » [CDO] Create ecore model with CDOBlob attribute
[CDO] Create ecore model with CDOBlob attribute [message #1573309] Mon, 19 January 2015 17:16 Go to next message
Alexander Klatt is currently offline Alexander KlattFriend
Messages: 59
Registered: April 2014
Member
I am trying to transfer a large file via CDO. From what I read so far, CDOBlob should
be suitable for this purpose?

I am struggling though to understand how to add blob data to the EMF model. From
what I saw on org.eclipse.emf.cdo.tests.LobTest the data needs to be added to a
custom Class within the EMF model?

I tried to add a CDOBlob as an EAttribute to my ecore model. But I get an error that
the attribute cannot be serialized and therefore needs to be transient.

Could you please point me to the right direction for the use of CDOClob?
Re: [CDO] Create ecore model with CDOBlob attribute [message #1573330 is a reply to message #1573309] Mon, 19 January 2015 17:30 Go to previous messageGo to next message
Eike Stepper is currently offline Eike StepperFriend
Messages: 6682
Registered: July 2009
Senior Member
Am 19.01.2015 um 18:16 schrieb Alexander Klatt:
> I am trying to transfer a large file via CDO. From what I read so far, CDOBlob should
> be suitable for this purpose?
Yes, CDOBlob for binary large data and CDOClob for character large data.

> I am struggling though to understand how to add blob data to the EMF model. From
> what I saw on org.eclipse.emf.cdo.tests.LobTest the data needs to be added to a custom Class within the EMF model?
> I tried to add a CDOBlob as an EAttribute to my ecore model. But I get an error that the attribute cannot be
> serialized and therefore needs to be transient.
>
> Could you please point me to the right direction for the use of CDOClob?
CDOBlob/Clob are the runtime classes that your application interacts with. In your model you need to declare attributes
of the EDataTypes "Blob" or "Clob". These EDataTypes are declared in CDO's system model "etypes", which you need to load
into your Ecore file to be able to use them.

Cheers
/Eike

----
http://www.esc-net.de
http://thegordian.blogspot.com
http://twitter.com/eikestepper


Re: [CDO] Create ecore model with CDOBlob attribute [message #1574464 is a reply to message #1573330] Tue, 20 January 2015 08:29 Go to previous messageGo to next message
Alexander Klatt is currently offline Alexander KlattFriend
Messages: 59
Registered: April 2014
Member
Right, this is what I did. I added the etypes.ecore to my own ecore model by right
click -> Load Resource within the model editor.

I am still uncertain about the usage though. My problem is: if I define an
EAttribute with the EType CDOBlob, the model becomes invalid for the property
Transient == false. If I set it to Transient == true, I can create the model code but
the CDOBlob does not seem to be persistent (which Transient == true causes?).


I add the blob as follows:

MyModel myModel = MyModelFactory.eINSTANCE.createMyModel();
File file = new File(location);
 try (DataInputStream dis = new DataInputStream(new FileInputStream(file))) {
     CDOBlob blob = new CDOBlob(dis);
     myModel.setData(blob);
     
     CDOTransaction transaction = null;
     try {
         transaction = cdoSession.openTransaction();
         CDOResource resource = transaction.getOrCreateResource("/home/mymodel");
         resource.getContents().clear(); //clear old data
         resource.getContents().add(myModel);
         transaction.commit();
     } catch (SecurityException e) {
         MessageDialog.openError(Display.getCurrent().getActiveShell(), e.getClass().toString(), "Authentification Failed!");
         System.exit(0);
     } catch (CommitException | CDOException e) {
         //some exception handling
     } finally {
         if (transaction != null) {
             transaction.close();
         }
     }

 } catch (IOException e1) {
   //some exception handling
 }


Afterwards I am trying to access it like this:
CDOView view = null;
try {
    view = cdoSession.openView();
    CDOResource resource = view.getResource("/home/mymodel");
    MyModel test = (MyModel) resource.getContents().get(0);
    try (InputStream in = test.getData().getContents()) { //<--------------------------- test.getData() is null! 
        byte[] data = new byte[in.available()];
        in.read(data);
        System.out.println(data.length);
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
} catch (SecurityException e) {
    MessageDialog.openError(Display.getCurrent().getActiveShell(), e.getClass().toString(), "Authentification Failed!");
    System.exit(0);
} catch (CDOException e) {
    //some exception handling
} finally {
    if (view != null) {
        view.close();
    }
}

[Updated on: Tue, 20 January 2015 09:06]

Report message to a moderator

Re: [CDO] Create ecore model with CDOBlob attribute [message #1574517 is a reply to message #1574464] Tue, 20 January 2015 09:05 Go to previous messageGo to next message
Eike Stepper is currently offline Eike StepperFriend
Messages: 6682
Registered: July 2009
Senior Member
Am 20.01.2015 um 09:29 schrieb Alexander Klatt:
> Right, this is what I did. I added the etypes.ecore to my own ecore model by right click -> Load Resource within the
> model editor.
>
> I am still uncertain about the usage though. My problem is: if I define an EAttribute with the EType CDOBlob, the
> model becomes invalid for the property Transient == false. If I set it to Transient == true, I can create the model
> code but am getting a runtime error:
>
> java.lang.ClassCastException: org.eclipse.emf.cdo.etypes.impl.EtypesFactoryImpl cannot be cast to etypes.EtypesFactory
What's the stack trace?

>
> My code looks like this:
>
>
> MyModel myModel = MyModelFactory.eINSTANCE.createMyModel();
> File file = new File(location);
> try (DataInputStream dis = new DataInputStream(new FileInputStream(file))) {
> CDOBlob blob = new CDOBlob(dis);
> myModel.setData(blob);
> CDOTransaction transaction = null;
> try {
> transaction = cdoSession.openTransaction();
> CDOResource resource = transaction.getOrCreateResource("/home/mymodel");
> resource.getContents().clear(); //clear old data
> resource.getContents().add(myModel);
> transaction.commit();
> } catch (SecurityException e) {
> MessageDialog.openError(Display.getCurrent().getActiveShell(), e.getClass().toString(), "Authentification Failed!");
> System.exit(0);
> } catch (CommitException | CDOException e) {
> //some exception handling
> } finally {
> if (transaction != null) {
> transaction.close();
> }
> }
>
> } catch (IOException e1) {
> //some exception handling
> }
That looks okay (not tried, though). Have you tried to add myModel to the resource first and then set the blob attribute?

Cheers
/Eike

----
http://www.esc-net.de
http://thegordian.blogspot.com
http://twitter.com/eikestepper


Re: [CDO] Create ecore model with CDOBlob attribute [message #1574532 is a reply to message #1574517] Tue, 20 January 2015 09:20 Go to previous messageGo to next message
Alexander Klatt is currently offline Alexander KlattFriend
Messages: 59
Registered: April 2014
Member
> Have you tried to add myModel to the resource first and then set the blob attribute?

I tried this, but the behavior is the same.

> What's the stack trace?
java.lang.ClassCastException: org.eclipse.emf.cdo.etypes.impl.EtypesFactoryImpl cannot be cast to etypes.EtypesFactory
	at etypes.impl.EtypesFactoryImpl.init(EtypesFactoryImpl.java:31)
	at etypes.EtypesFactory.<clinit>(EtypesFactory.java:22)
	at etypes.impl.EtypesPackageImpl.<init>(EtypesPackageImpl.java:102)
	at etypes.impl.EtypesPackageImpl.init(EtypesPackageImpl.java:128)
	at etypes.EtypesPackage.<clinit>(EtypesPackage.java:59)
	at My.impl.MyPackageImpl.init(MyPackageImpl.java:85)
	at My.MyPackage.<clinit>(MyPackage.java:57)
	at My.MyPackage$Literals.<clinit>(MyPackage.java:210)
	at My.impl.MyModelImpl.eStaticClass(MyModelImpl.java:106)
	at org.eclipse.emf.ecore.impl.MinimalEObjectImpl.eClass(MinimalEObjectImpl.java:688)
	at org.eclipse.emf.internal.cdo.object.CDOLegacyWrapper.<init>(CDOLegacyWrapper.java:104)
	at org.eclipse.emf.internal.cdo.object.CDOLegacyAdapter.<init>(CDOLegacyAdapter.java:51)
	at org.eclipse.emf.spi.cdo.FSMUtil.adaptLegacy(FSMUtil.java:117)
	at org.eclipse.emf.spi.cdo.FSMUtil.adapt(FSMUtil.java:101)
	at org.eclipse.emf.cdo.eresource.impl.CDOResourceImpl$ContentsCDOList.inverseAdd(CDOResourceImpl.java:1760)
	at org.eclipse.emf.common.notify.impl.DelegatingNotifyingListImpl.addUnique(DelegatingNotifyingListImpl.java:304)
	at org.eclipse.emf.common.util.AbstractEList.add(AbstractEList.java:303)
	at test.standalone.application.util.MyImporter$ImportThread.run(MyImporter.java:143)
	at org.eclipse.jface.operation.ModalContext$ModalContextThread.run(ModalContext.java:122)

[Updated on: Tue, 20 January 2015 14:19]

Report message to a moderator

Re: [CDO] Create ecore model with CDOBlob attribute [message #1576581 is a reply to message #1574532] Wed, 21 January 2015 11:51 Go to previous messageGo to next message
Alexander Klatt is currently offline Alexander KlattFriend
Messages: 59
Registered: April 2014
Member
I added a discussion on stackoverflow. The explanation to my problem may be better explained in that post:

http://stackoverflow.com/questions/28066455/large-data-transfer-in-cdo-using-data-stream-cdoblob
Re: [CDO] Create ecore model with CDOBlob attribute [message #1576624 is a reply to message #1576581] Wed, 21 January 2015 12:21 Go to previous messageGo to next message
Eike Stepper is currently offline Eike StepperFriend
Messages: 6682
Registered: July 2009
Senior Member
Am 21.01.2015 um 12:51 schrieb Alexander Klatt:
> I added a discussion on stackoverflow. The explanation to my problem may be better explained in that post:
>
> http://stackoverflow.com/questions/28066455/large-data-transfer-in-cdo-using-data-stream-cdoblob
No, you still talk about an exception but don't show the stack trace. It's impossible for me to comment then.

I don't monitor stack overflow very regularly.

Cheers
/Eike

----
http://www.esc-net.de
http://thegordian.blogspot.com
http://twitter.com/eikestepper


Re: [CDO] Create ecore model with CDOBlob attribute [message #1576625 is a reply to message #1576581] Wed, 21 January 2015 12:22 Go to previous messageGo to next message
Eike Stepper is currently offline Eike StepperFriend
Messages: 6682
Registered: July 2009
Senior Member
BTW., don't set the blob attribute to transient.

Cheers
/Eike

----
http://www.esc-net.de
http://thegordian.blogspot.com
http://twitter.com/eikestepper


Am 21.01.2015 um 12:51 schrieb Alexander Klatt:
> I added a discussion on stackoverflow. The explanation to my problem may be better explained in that post:
>
> http://stackoverflow.com/questions/28066455/large-data-transfer-in-cdo-using-data-stream-cdoblob


Re: [CDO] Create ecore model with CDOBlob attribute [message #1576751 is a reply to message #1576625] Wed, 21 January 2015 13:55 Go to previous messageGo to next message
Alexander Klatt is currently offline Alexander KlattFriend
Messages: 59
Registered: April 2014
Member
Unfortunately, in my ecore model I need to set it to transient. Otherwise, I get a validation error: "The attribute 'xxx' is not transient so it must have a data type that is serializable"

> No, you still talk about an exception but don't show the stack trace. It's impossible for me to comment then.

The stack trace is in this thread, 4 answers ago.

[Updated on: Wed, 21 January 2015 13:57]

Report message to a moderator

Re: [CDO] Create ecore model with CDOBlob attribute [message #1576841 is a reply to message #1576751] Wed, 21 January 2015 15:03 Go to previous messageGo to next message
Eike Stepper is currently offline Eike StepperFriend
Messages: 6682
Registered: July 2009
Senior Member
Am 21.01.2015 um 14:55 schrieb Alexander Klatt:
> Unfortunately, in my ecore model I need to set it to transient. Otherwise, I get a validation error: "The attribute
> 'xxx' is not transient so it must have a data type that is serializable"

Sorry, that was my fault. Blob and Clob attributes need to be transient.

Cheers
/Eike

----
http://www.esc-net.de
http://thegordian.blogspot.com
http://twitter.com/eikestepper


Re: [CDO] Create ecore model with CDOBlob attribute [message #1576996 is a reply to message #1576841] Wed, 21 January 2015 16:57 Go to previous messageGo to next message
Alexander Klatt is currently offline Alexander KlattFriend
Messages: 59
Registered: April 2014
Member
Okay, thanks. So I can stop looking for the error at the "transient" property Smile.

But how would I use CDOBlob then to save larger amounts of data? If it is transient then nothing will be stored, I guess.
Re: [CDO] Create ecore model with CDOBlob attribute [message #1577083 is a reply to message #1576996] Wed, 21 January 2015 17:59 Go to previous messageGo to next message
Eike Stepper is currently offline Eike StepperFriend
Messages: 6682
Registered: July 2009
Senior Member
Am 21.01.2015 um 17:57 schrieb Alexander Klatt:
> Okay, thanks. So I can stop looking for the error at the "transient" property :).
>
> But how would I use CDOBlob then to save larger amounts of data? If it is transient then nothing will be stored, I guess.
No, there is special handling for these attributes in CDO. If you follow the code examples in our test suite I don't see
why it should not work.

Cheers
/Eike

----
http://www.esc-net.de
http://thegordian.blogspot.com
http://twitter.com/eikestepper


Re: [CDO] Create ecore model with CDOBlob attribute [message #1577172 is a reply to message #1574532] Wed, 21 January 2015 19:01 Go to previous messageGo to next message
Erdal Karaca is currently offline Erdal KaracaFriend
Messages: 854
Registered: July 2009
Senior Member
Did you "include" or "reference" etypes.ecore?
It seems that you have included etypes.ecore to your own ecore file, so the editor has generated code for etypes.ecore.

Alexander Klatt wrote on Tue, 20 January 2015 10:20
> Have you tried to add myModel to the resource first and then set the blob attribute?

I tried this, but the behavior is the same.

> What's the stack trace?
java.lang.ClassCastException: org.eclipse.emf.cdo.etypes.impl.EtypesFactoryImpl cannot be cast to etypes.EtypesFactory
	at etypes.impl.EtypesFactoryImpl.init(EtypesFactoryImpl.java:31)
	at etypes.EtypesFactory.<clinit>(EtypesFactory.java:22)
	at etypes.impl.EtypesPackageImpl.<init>(EtypesPackageImpl.java:102)
	at etypes.impl.EtypesPackageImpl.init(EtypesPackageImpl.java:128)
	at etypes.EtypesPackage.<clinit>(EtypesPackage.java:59)
	at My.impl.MyPackageImpl.init(MyPackageImpl.java:85)
	at My.MyPackage.<clinit>(MyPackage.java:57)
	at My.MyPackage$Literals.<clinit>(MyPackage.java:210)
	at My.impl.MyModelImpl.eStaticClass(MyModelImpl.java:106)
	at org.eclipse.emf.ecore.impl.MinimalEObjectImpl.eClass(MinimalEObjectImpl.java:688)
	at org.eclipse.emf.internal.cdo.object.CDOLegacyWrapper.<init>(CDOLegacyWrapper.java:104)
	at org.eclipse.emf.internal.cdo.object.CDOLegacyAdapter.<init>(CDOLegacyAdapter.java:51)
	at org.eclipse.emf.spi.cdo.FSMUtil.adaptLegacy(FSMUtil.java:117)
	at org.eclipse.emf.spi.cdo.FSMUtil.adapt(FSMUtil.java:101)
	at org.eclipse.emf.cdo.eresource.impl.CDOResourceImpl$ContentsCDOList.inverseAdd(CDOResourceImpl.java:1760)
	at org.eclipse.emf.common.notify.impl.DelegatingNotifyingListImpl.addUnique(DelegatingNotifyingListImpl.java:304)
	at org.eclipse.emf.common.util.AbstractEList.add(AbstractEList.java:303)
	at test.standalone.application.util.MyImporter$ImportThread.run(MyImporter.java:143)
	at org.eclipse.jface.operation.ModalContext$ModalContextThread.run(ModalContext.java:122)

Re: [CDO] Create ecore model with CDOBlob attribute [message #1661055 is a reply to message #1577172] Mon, 09 March 2015 13:07 Go to previous messageGo to next message
Alexander Klatt is currently offline Alexander KlattFriend
Messages: 59
Registered: April 2014
Member
Erdal Karaca wrote on Wed, 21 January 2015 19:01
Did you "include" or "reference" etypes.ecore?
It seems that you have included etypes.ecore to your own ecore file, so the editor has generated code for etypes.ecore.


Sorry, it took me a while to get back to this Smile.
This was indeed the case.

But now I am back to the problem of the transient property.
Whenever I access the Blob field of a previously committed object, it is null. This is what I would expect if I set the property transient=true.

Within the CDO test project (org.eclipse.emf.cdo.tests.model3), the ecore model
defines a class "Image" with the field "data" of type CDOBlob. It is set to transient=false.
According to my ecore validation, this is not valid.

Do you have any suggestions how I should proceed?
Thanks!


Edit: okay, it works. I was not aware that it is possible to create model code for invalid models. This is kind of ugly though. But I guess there is no way to tell it to be valid?

[Updated on: Mon, 09 March 2015 13:17]

Report message to a moderator

Re: [CDO] Create ecore model with CDOBlob attribute [message #1763462 is a reply to message #1661055] Tue, 16 May 2017 12:02 Go to previous messageGo to next message
Stephan Herrmann is currently offline Stephan HerrmannFriend
Messages: 1853
Registered: July 2009
Senior Member
How to prepare a model for use of Clob/Blob seems to confuse even Eike. Only on third reading of this thread I realized that Eike's first statement was right (and thus his correction was wrong): the lob attribute must be marked as not transient, even though this is illegal in EMF.

=> Please print this in bold letters somewhere very visible in the documentation :)
Re: [CDO] Create ecore model with CDOBlob attribute [message #1763696 is a reply to message #1763462] Thu, 18 May 2017 16:42 Go to previous messageGo to next message
Eike Stepper is currently offline Eike StepperFriend
Messages: 6682
Registered: July 2009
Senior Member
Sometimes I am confused, but in this case it might also be the case that particular statements were made in before the actual etype.ecore model was changed. Since 2016-10-06 the data types Blob and Clob are serializeable and can (and probably should) be used with non-transient attributes. Is that what you concluded, too?

Re: [CDO] Create ecore model with CDOBlob attribute [message #1763698 is a reply to message #1763696] Thu, 18 May 2017 17:31 Go to previous messageGo to next message
Stephan Herrmann is currently offline Stephan HerrmannFriend
Messages: 1853
Registered: July 2009
Senior Member
Eike Stepper wrote on Thu, 18 May 2017 18:42
Sometimes I am confused, but in this case it might also be the case that particular statements were made in before the actual etype.ecore model was changed. Since 2016-10-06 the data types Blob and Clob are serializeable and can (and probably should) be used with non-transient attributes. Is that what you concluded, too?


org.eclipse.emf.cdo.common.lob.CDOClob is the implementation of Clob. right? As of today's HEAD I cannot find Serializable among its supertypes. Am I looking in the wrong location?

Ergo: still today, an illegal EMF model is required to persist a Clob. Or better still: a Blob, which isn't broken by https://bugs.eclipse.org/516680 :)

EDIT: to add to the confusion: I was of course speaking about the latest CDO release (4.5.0), whereas you seem to be saying that with the fix for https://bugs.eclipse.org/498732 all will be fine in Oxygen?

BTW: that bug is marked as "found in version 4.6" and doesn't have a target milestone. Should we assume you meant it's fixed in 4.6?

[Updated on: Thu, 18 May 2017 20:27]

Report message to a moderator

Re: [CDO] Create ecore model with CDOBlob attribute [message #1763722 is a reply to message #1763698] Fri, 19 May 2017 04:03 Go to previous message
Eike Stepper is currently offline Eike StepperFriend
Messages: 6682
Registered: July 2009
Senior Member
Serialization of EDataTypes is implemented in the model's factory class, in this case in these methods (@since 4.6):

org.eclipse.emf.cdo.etypes.impl.EtypesFactoryImpl.createBlobFromString(EDataType, String)
org.eclipse.emf.cdo.etypes.impl.EtypesFactoryImpl.convertBlobToString(EDataType, Object)
org.eclipse.emf.cdo.etypes.impl.EtypesFactoryImpl.createClobFromString(EDataType, String)
org.eclipse.emf.cdo.etypes.impl.EtypesFactoryImpl.convertClobToString(EDataType, Object)


Previous Topic:[TENEO] Save Double list with NaN and Infinity
Next Topic:Loading Xtext Resource Into EMF Editor Breaks on Save?
Goto Forum:
  


Current Time: Fri Apr 19 21:11:41 GMT 2024

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

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

Back to the top