|
|
Re: [TENEO] Problem to generate mapping when using multiple ecore models [message #517834 is a reply to message #517769] |
Tue, 02 March 2010 10:02 |
Torsten Link Messages: 51 Registered: July 2009 |
Member |
|
|
Hi Martin,
when I select both ecore Models and then generate it is working.
So the model itself seems to be OK.
Here is my code:
public class TestTeneo {
* @throws IOException
*/
public static void main(String[] args) throws IOException {
TestTeneo tt = new TestTeneo();
tt.run();
}
private void run() throws IOException{
final Properties props = new Properties();
props.setProperty(Environment.DRIVER, "com.mysql.jdbc.Driver");
props.setProperty(Environment.URL, "jdbc:mysql://localhost:3306/Abilit");
props.setProperty(Environment.USER, "root");
props.setProperty(Environment.PASS, "");
props.setProperty(Environment.DIALECT, "org.hibernate.dialect.MySQLInnoDBDialect");
props.setProperty(Environment.SHOW_SQL, "true");
props.setProperty(PersistenceOptions.INHERITANCE_MAPPING, "SINGLE_TABLE");
HbDataStore hbds = (HbDataStore)HbHelper.INSTANCE.createRegisterDataStore("Abilit ");
hbds.setProperties(props);
List<String> packageFiles = new ArrayList<String>();
packageFiles.add(" /Users/torstenlink/Documents/workspace_abilit_java/gumbo/mod el/structure.ecore ");
packageFiles.add(" /Users/torstenlink/Documents/workspace_abilit_java/gumbo/mod el/testModel.ecore ");
EPackage[] packages = readFromEcore(packageFiles);
// at this point the array conmtains two packages as I expect
hbds.setEPackages(packages);
hbds.initialize();
}
// this reeds the ecore File and returns all packages in this file
// Is it necessary to get all Packages of the model file or just
// the top level Packages?
private EPackage[] readFromEcore(List<String> ecoreFiles) {
final ResourceSet resourceSet = new ResourceSetImpl();
resourceSet.getResourceFactoryRegistry().getExtensionToFacto ryMap().put( "*", new EcoreResourceFactoryImpl());
final ArrayList<EPackage> epackages = new ArrayList<EPackage>();
for (String ecoreFile : ecoreFiles) {
try {
final Resource res = resourceSet.getResource(URI.createURI(ecoreFile), true);
TreeIterator<EObject> treeIter = res.getAllContents();
while(treeIter.hasNext()){
EObject obj = treeIter.next();
if (obj instanceof EPackage) {
epackages.add((EPackage) obj);
}
}
} catch (Exception e) {
throw new IllegalStateException(e);
}
}
EPackage[] packArray = new EPackage[epackages.size()];
for(int i=0; i<epackages.size();i++){
packArray[i] = epackages.get(i);
}
return packArray;
}
}
Thanks for the fast Help
Torsten Link
|
|
|
Re: [TENEO] Problem to generate mapping when using multiple ecore models [message #517854 is a reply to message #517834] |
Tue, 02 March 2010 10:40 |
Martin Taal Messages: 5468 Registered: July 2009 |
Senior Member |
|
|
Hi Torsten,
Can you check that the read of epackages correctly creates the relations between the epackages. So is the testModel
refering to the structure epackage read first or to a new instance of the structure epackage?
gr. Martin
Torsten Link wrote:
> Hi Martin,
>
> when I select both ecore Models and then generate it is working. :)
> So the model itself seems to be OK.
>
>
> Here is my code:
>
>
> public class TestTeneo {
> * @throws IOException */
> public static void main(String[] args) throws IOException {
> TestTeneo tt = new TestTeneo();
> tt.run();
> }
>
> private void run() throws IOException{
>
> final Properties props = new Properties();
> props.setProperty(Environment.DRIVER, "com.mysql.jdbc.Driver");
> props.setProperty(Environment.URL,
> "jdbc:mysql://localhost:3306/Abilit");
> props.setProperty(Environment.USER, "root");
> props.setProperty(Environment.PASS, "");
> props.setProperty(Environment.DIALECT,
> "org.hibernate.dialect.MySQLInnoDBDialect");
> props.setProperty(Environment.SHOW_SQL, "true");
> props.setProperty(PersistenceOptions.INHERITANCE_MAPPING,
> "SINGLE_TABLE");
>
> HbDataStore hbds =
> (HbDataStore)HbHelper.INSTANCE.createRegisterDataStore("Abilit ");
> hbds.setProperties(props);
>
> List<String> packageFiles = new ArrayList<String>();
> packageFiles.add("
> /Users/torstenlink/Documents/workspace_abilit_java/gumbo/mod
> el/structure.ecore ");
> packageFiles.add("
> /Users/torstenlink/Documents/workspace_abilit_java/gumbo/mod
> el/testModel.ecore ");
>
> EPackage[] packages = readFromEcore(packageFiles);
>
> // at this point the array conmtains two packages as I expect
> hbds.setEPackages(packages);
>
> hbds.initialize();
> }
>
> // this reeds the ecore File and returns all packages in this file
> // Is it necessary to get all Packages of the model file or just
> // the top level Packages?
> private EPackage[] readFromEcore(List<String> ecoreFiles) {
> final ResourceSet resourceSet = new ResourceSetImpl();
> resourceSet.getResourceFactoryRegistry().getExtensionToFacto
> ryMap().put( "*", new EcoreResourceFactoryImpl());
> final ArrayList<EPackage> epackages = new ArrayList<EPackage>();
> for (String ecoreFile : ecoreFiles) {
> try {
> final Resource res =
> resourceSet.getResource(URI.createURI(ecoreFile), true);
>
> TreeIterator<EObject> treeIter = res.getAllContents();
> while(treeIter.hasNext()){
> EObject obj = treeIter.next();
> if (obj instanceof EPackage) {
> epackages.add((EPackage) obj);
> }
> }
> } catch (Exception e) {
> throw new IllegalStateException(e);
> }
> }
>
> EPackage[] packArray = new EPackage[epackages.size()];
> for(int i=0; i<epackages.size();i++){
> packArray[i] = epackages.get(i);
> }
>
> return packArray;
> }
> }
>
>
>
> Thanks for the fast Help
>
>
> Torsten Link
>
>
--
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
|
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.07797 seconds