Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF "Technology" (Ecore Tools, EMFatic, etc)  » [Teneo] How to store an existing model from XMI to MySQL database(About basic funcionallity and concepts of teneo.)
[Teneo] How to store an existing model from XMI to MySQL database [message #758530] Wed, 23 November 2011 15:23 Go to next message
CarlosM  is currently offline CarlosM Friend
Messages: 5
Registered: November 2011
Junior Member
Hi.

I would like to store some models that I have built according to my ecore metamodel to a MySQL database.
I have downloaded and installed Teneo and its dependencies, and I have seen how Teneo may be used to persist the information. However, the examples I have seen, build some objects according to the metamodel, and then persist de information in the database using Teneo within a session transaction or something like that.
What I would like to do, is to persist an existing model directly, not to create the objects programatically and at the end, persist the session. When I say "persist an existing model" I mean "to create the DDL in the database and afterwards, populate the data on that DDL". What I don't know is whether is there any procedure inside teneo that allows the editor to save the whole model without visiting the nodes of the tree...
Could you please tell me wether that is possible or not?
Otherwise, do I need to visit all the nodes of my tree model and persist the object for each one?
Have you got any other suggestion?

Thank you very much in advance.
Best regards.
Carlos.
Re: [Teneo] How to store an existing model from XMI to MySQL database [message #758541 is a reply to message #758530] Wed, 23 November 2011 15:44 Go to previous messageGo to next message
Martin Taal is currently offline Martin TaalFriend
Messages: 5468
Registered: July 2009
Senior Member
Hi Carlos,
The datastore has an importDataStore method. You can try that.Or create a hibernateResource load from an input stream
and then save the resource.'

If you want to insert always then this should work fine. If you are updating then sometimes it makes sense to be more
precise, so reading objects from the database and then apply the data from the xml.

If you work server side only, so no rcp then the following project might be interesting to:
http://wiki.eclipse.org/Texo

It provides many of the same server side functionality as EMF but gives easier/simpler code which can be persisted in
any standard ORM without a runtime layer.

gr. Martin

On 11/23/2011 04:23 PM, CarlosM wrote:
> Hi.
>
> I would like to store some models that I have built according to my ecore metamodel to a MySQL database.
> I have downloaded and installed Teneo and its dependencies, and I have seen how Teneo may be used to persist the
> information. However, the examples I have seen, build some objects according to the metamodel, and then persist de
> information in the database using Teneo within a session transaction or something like that.
> What I would like to do, is to persist an existing model directly, not to create the objects programatically and at the
> end, persist the session. When I say "persist an existing model" I mean "to create the DDL in the database and
> afterwards, populate the data on that DDL". What I don't know is whether is there any procedure inside teneo that allows
> the editor to save the whole model without visiting the nodes of the tree...
> Could you please tell me wether that is possible or not?
> Otherwise, do I need to visit all the nodes of my tree model and persist the object for each one?
> Have you got any other suggestion?
>
> Thank you very much in advance.
> Best regards.
> Carlos.


--

With Regards, Martin Taal

Springsite/Elver.org
Office: Hardwareweg 4, 3821 BV Amersfoort
Postal: Nassaulaan 7, 3941 EC Doorn
The Netherlands
Cell: +31 (0)6 288 48 943
Tel: +31 (0)84 420 2397
Fax: +31 (0)84 225 9307
Mail: mtaal@springsite.com - mtaal@elver.org
Web: www.springsite.com - www.elver.org
Re: [Teneo] How to store an existing model from XMI to MySQL database [message #758916 is a reply to message #758541] Fri, 25 November 2011 09:17 Go to previous messageGo to next message
CarlosM  is currently offline CarlosM Friend
Messages: 5
Registered: November 2011
Junior Member
Hi Martin.

I have been doing some tests and it works fine.
However, I have concerns about the cross references among distinct resources, at the time they're going to be persisted.

When I say "cross reference" I mean one object in one particular resource which references other object in other resource. The second one is placed in only one resource but it may be referenced by other locations...

I'm using for each object of my model an universal UUID stored in the XMI ID attribute.
I have just tried to save first the resource where the referenced entity is, and then the resource where the entity which references to, is.

I get in the log something like this:
The feature 'xxx' of 'org.xxx.impl.Entity@20e54a{.dbName#Entyty|id=_HY5j0Ba4EeGQTJDX4_KHmg}' contains an unresolved proxy 'org.xxx.ReferencedEntity@1ad637e{theother.entity#_8NL5cBa3EeGQTJDX4_KHmg}'

I would like to know how to resolve this kind of references if possible... because my model resources are very interconnnected in this way.

Have voy got any suggestion?

Thank you very much in advance, one again.
Kind regards.
Carlos.
Re: [Teneo] How to store an existing model from XMI to MySQL database [message #758919 is a reply to message #758916] Fri, 25 November 2011 09:31 Go to previous messageGo to next message
Martin Taal is currently offline Martin TaalFriend
Messages: 5468
Registered: July 2009
Senior Member
Is feature xxx a containment reference? If so you have to explicitly set its properties to resolve proxies. Also if
multiple resources should be saved together then they should use one session:
http://wiki.eclipse.org/Teneo/Hibernate/EMF_Resource#Sharing_one_Session_between_Resources.2C_One_transaction_when_saving_multiple_resources

gr. Martin

On 11/25/2011 10:17 AM, CarlosM wrote:
> Hi Martin.
>
> I have been doing some tests and it works fine.
> However, I have concerns about the cross references among distinct resources, at the time they're going to be persisted.
>
> When I say "cross reference" I mean one object in one particular resource which references other object in other
> resource. The second one is placed in only one resource but it may be referenced by other locations...
>
> I'm using for each object of my model an universal UUID stored in the XMI ID attribute.
> I have just tried to save first the resource where the referenced entity is, and then the resource where the entity
> which references to, is.
>
> I get in the log something like this:
> The feature 'xxx' of mailto:'org.xxx.impl.Entity@20e54a{.dbName#Entyty|id=_HY5j0Ba4EeGQTJDX4_KHmg}' contains an
> unresolved proxy mailto:'org.xxx.ReferencedEntity@1ad637e{theother.entity#_8NL5cBa3EeGQTJDX4_KHmg}'
>
> I would like to know how to resolve this kind of references if possible... because my model resources are very
> interconnnected in this way.
>
> Have voy got any suggestion?
>
> Thank you very much in advance, one again.
> Kind regards.
> Carlos.


--

With Regards, Martin Taal

Springsite/Elver.org
Office: Hardwareweg 4, 3821 BV Amersfoort
Postal: Nassaulaan 7, 3941 EC Doorn
The Netherlands
Cell: +31 (0)6 288 48 943
Tel: +31 (0)84 420 2397
Fax: +31 (0)84 225 9307
Mail: mtaal@springsite.com - mtaal@elver.org
Web: www.springsite.com - www.elver.org
Re: [Teneo] How to store an existing model from XMI to MySQL database [message #758959 is a reply to message #758919] Fri, 25 November 2011 11:51 Go to previous messageGo to next message
CarlosM  is currently offline CarlosM Friend
Messages: 5
Registered: November 2011
Junior Member
The properties to resolve proxies are set to true.

What I'm trying to do is to persist the resources that are already loaded into my editor to the mysql database. I was doing something like this:

Iterator<Resource> it = resourceSet.getResources().iterator();
while (it.hasNext()){
Resource resource = it.next();
InputStream is = editor.getEditingDomain()
.getResourceSet().getURIConverter().createInputStream(resource.getURI());
hbds.importDataStore(is, HbConstants.EXCHANGE_FORMAT_XMI);
}

If I do this inside one session controller also fails.

If I try to follow the sample I see that my URI's are based on files, I wouldn't know how to transfer the data from the resources based on files to the based on "hibernate protocol" ones.

Thanks!
Re: [Teneo] How to store an existing model from XMI to MySQL database [message #758996 is a reply to message #758959] Fri, 25 November 2011 14:34 Go to previous messageGo to next message
Martin Taal is currently offline Martin TaalFriend
Messages: 5468
Registered: July 2009
Senior Member
Hi Carlos,
Hmm, the following is probably must simpler:

Iterator<Resource> it = resourceSet.getResources().iterator();
final Session session = hbds.getSessionFactory().openSession();
session.getTransaction().begin();
while (it.hasNext()){
Resource resource = it.next();
for (Object o : resource.getContents()) {
session.saveOrUpdate(o);
}
}
session.getTransaction().commit();

gr. Martin

On 11/25/2011 12:51 PM, CarlosM wrote:
> The properties to resolve proxies are set to true.
>
> What I'm trying to do is to persist the resources that are already loaded into my editor to the mysql database. I was
> doing something like this:
>
> Iterator<Resource> it = resourceSet.getResources().iterator();
> while (it.hasNext()){
> Resource resource = it.next();
> InputStream is = editor.getEditingDomain()
> .getResourceSet().getURIConverter().createInputStream(resource.getURI());
> hbds.importDataStore(is, HbConstants.EXCHANGE_FORMAT_XMI);
> }
>
> If I do this inside one session controller also fails.
>
> If I try to follow the sample I see that my URI's are based on files, I wouldn't know how to transfer the data from the
> resources based on files to the based on "hibernate protocol" ones.
>
> Thanks!


--

With Regards, Martin Taal

Springsite/Elver.org
Office: Hardwareweg 4, 3821 BV Amersfoort
Postal: Nassaulaan 7, 3941 EC Doorn
The Netherlands
Cell: +31 (0)6 288 48 943
Tel: +31 (0)84 420 2397
Fax: +31 (0)84 225 9307
Mail: mtaal@springsite.com - mtaal@elver.org
Web: www.springsite.com - www.elver.org
Re: [Teneo] How to store an existing model from XMI to MySQL database [message #759002 is a reply to message #758996] Fri, 25 November 2011 14:46 Go to previous message
CarlosM  is currently offline CarlosM Friend
Messages: 5
Registered: November 2011
Junior Member
That's just what I was looking for!

Thank you very much.
Carlos.
Previous Topic:[EMF CP] TreeView and linkWithEditor feature
Next Topic:Generating ecore diagram image file programmatically
Goto Forum:
  


Current Time: Fri Mar 29 07:36:02 GMT 2024

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

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

Back to the top