Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF "Technology" (Ecore Tools, EMFatic, etc)  » Import Export of XML files in database from GMF or other
Import Export of XML files in database from GMF or other [message #107380] Thu, 17 January 2008 13:53 Go to next message
Eclipse UserFriend
Originally posted by: frederic.ventura.eurogiciel.fr

Hi every body

I've just obtained a working GMF plugin working on a database (using
GMF/teneo/hibernate) and I have to had a new function
I would like to know if it already exists something to do this.
my goal is to import datas from xml files into my database.
for example:
my diagram is composed of a championship
my championship contains several matches
each match is composed of a 2 team
a team is composed of several players

I can create in my GMF diagram instance of championship, match, team and
player.
I can receave xml files (one xml file for each kind of class)
I have to import each file in my GMF diagram.

Such a tool already exist or is it necesary to develop it?

thanks by advance
fred
Re: Import Export of XML files in database from GMF or other [message #107450 is a reply to message #107380] Thu, 17 January 2008 14:15 Go to previous message
Martin Taal is currently offline Martin TaalFriend
Messages: 5468
Registered: July 2009
Senior Member
Hi Fred,
The HbDataStore has a simple method to do this, here is the method body (which is probably too
simple for most uses):
if (importFormat == HbConstants.EXCHANGE_FORMAT_XML) {
importResource = new XMLResourceImpl();
} else {
importResource = new XMIResourceImpl();
}

final HibernateResource hibResource = new HibernateResource(URI.createFileURI("." + name));

try {
importResource.load(is, Collections.EMPTY_MAP);
hibResource.getContents().addAll(importResource.getContents( ));
hibResource.save(Collections.EMPTY_MAP);
} catch (IOException e) {
throw new HbMapperException("Exception when importing " + name, e);
}

When the objects in the xml file update objects in the database then the id and version of the
objects also needs to be present as efeatures in the xml. Otherwise Hibernate will think that the
objects from the xml file are always new and create new records instead of updating the db.
See also here (this is client-server related but also applies here):
http://www.elver.org/hibernate/hibernate_details.html#Client -Server+scenario%3A+requires+explicitly+modelled+id+and+vers ion+properties

gr. Martin

fred wrote:
> Hi every body
>
> I've just obtained a working GMF plugin working on a database (using
> GMF/teneo/hibernate) and I have to had a new function
> I would like to know if it already exists something to do this.
> my goal is to import datas from xml files into my database.
> for example:
> my diagram is composed of a championship
> my championship contains several matches
> each match is composed of a 2 team
> a team is composed of several players
>
> I can create in my GMF diagram instance of championship, match, team and
> player.
> I can receave xml files (one xml file for each kind of class)
> I have to import each file in my GMF diagram.
>
> Such a tool already exist or is it necesary to develop it?
>
> thanks by advance
> fred
>


--

With Regards, Martin Taal

Springsite/Elver.org
Office: Hardwareweg 4, 3821 BV Amersfoort
Postal: Nassaulaan 7, 3941 EC Doorn
The Netherlands
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: Import Export of XML files in database from GMF or other [message #614030 is a reply to message #107380] Thu, 17 January 2008 14:15 Go to previous message
Martin Taal is currently offline Martin TaalFriend
Messages: 5468
Registered: July 2009
Senior Member
Hi Fred,
The HbDataStore has a simple method to do this, here is the method body (which is probably too
simple for most uses):
if (importFormat == HbConstants.EXCHANGE_FORMAT_XML) {
importResource = new XMLResourceImpl();
} else {
importResource = new XMIResourceImpl();
}

final HibernateResource hibResource = new HibernateResource(URI.createFileURI("." + name));

try {
importResource.load(is, Collections.EMPTY_MAP);
hibResource.getContents().addAll(importResource.getContents( ));
hibResource.save(Collections.EMPTY_MAP);
} catch (IOException e) {
throw new HbMapperException("Exception when importing " + name, e);
}

When the objects in the xml file update objects in the database then the id and version of the
objects also needs to be present as efeatures in the xml. Otherwise Hibernate will think that the
objects from the xml file are always new and create new records instead of updating the db.
See also here (this is client-server related but also applies here):
http://www.elver.org/hibernate/hibernate_details.html#Client -Server+scenario%3A+requires+explicitly+modelled+id+and+vers ion+properties

gr. Martin

fred wrote:
> Hi every body
>
> I've just obtained a working GMF plugin working on a database (using
> GMF/teneo/hibernate) and I have to had a new function
> I would like to know if it already exists something to do this.
> my goal is to import datas from xml files into my database.
> for example:
> my diagram is composed of a championship
> my championship contains several matches
> each match is composed of a 2 team
> a team is composed of several players
>
> I can create in my GMF diagram instance of championship, match, team and
> player.
> I can receave xml files (one xml file for each kind of class)
> I have to import each file in my GMF diagram.
>
> Such a tool already exist or is it necesary to develop it?
>
> thanks by advance
> fred
>


--

With Regards, Martin Taal

Springsite/Elver.org
Office: Hardwareweg 4, 3821 BV Amersfoort
Postal: Nassaulaan 7, 3941 EC Doorn
The Netherlands
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
Previous Topic:Import Export of XML files in database from GMF or other
Next Topic:[Ecore Tools] Error by EMFT
Goto Forum:
  


Current Time: Thu Apr 25 14:57:43 GMT 2024

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

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

Back to the top