|
Re: [CDO] Create ecore model with CDOBlob attribute [message #1573330 is a reply to message #1573309] |
Mon, 19 January 2015 17:30 |
|
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
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 |
Alexander Klatt 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 |
|
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
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 |
Alexander Klatt 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 #1763698 is a reply to message #1763696] |
Thu, 18 May 2017 17:31 |
Stephan Herrmann Messages: 1853 Registered: July 2009 |
Senior Member |
|
|
Eike Stepper wrote on Thu, 18 May 2017 18:42Sometimes 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
|
|
|
|
Powered by
FUDForum. Page generated in 0.05614 seconds