Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF "Technology" (Ecore Tools, EMFatic, etc)  » [Texo] Example for creating orm.xml from ecore model programmatically
[Texo] Example for creating orm.xml from ecore model programmatically [message #870594] Tue, 08 May 2012 21:12 Go to next message
Shahim Essaid is currently offline Shahim EssaidFriend
Messages: 40
Registered: July 2009
Member
Hi all,

Can someone please show me an example for creating a JPA mapping file (orm.xml) programmatically from an ecore metamodel by using the Texo API?

Also, can I load the metamodel into a ResourceSet, programatically create an annotation model with few overrides in the same set, and have the generated orm be based on the additional annotations?

What about generating the JPA annotated code, can that also be done programatically?

I tried to look for examples in the Wiki but it mostly shows how to do this from the UI, not from the API. Any examples or hints will be appreciated.

Thank you,
Shahim
Re: [Texo] Example for creating orm.xml from ecore model programmatically [message #870599 is a reply to message #870594] Tue, 08 May 2012 21:58 Go to previous messageGo to next message
Martin Taal is currently offline Martin TaalFriend
Messages: 5468
Registered: July 2009
Senior Member
Hi Shahim,
For the first question you are the first to ask so therefore there is no wiki entry about it.. :-). For generating the
in-memory orm model from an ecore metamodel, check out this method:
http://git.eclipse.org/c/texo/org.eclipse.emf.texo.git/tree/generator/org.eclipse.emf.texo.orm/src/org/eclipse/emf/texo/orm/annotator/ORMGenerator.java#n128

the generateStoreORM method, so it takes less than 10 lines of code to generate orms and have them represented
in-memory, if you use an annotation model then it is important to read the epackages in the correct way (the annotations
model are searched in the same place as where the ecore is read from).
This test method gives a good feel for how to do that:
http://git.eclipse.org/c/texo/org.eclipse.emf.texo.git/tree/tests/org.eclipse.emf.texo.orm.test/src/org/eclipse/emf/texo/orm/test/ORMGeneratorTest.java#n91

See the launch configs here for what Texo uses in its test runs (to generate orms):
http://git.eclipse.org/c/texo/org.eclipse.emf.texo.git/tree/tests/org.eclipse.emf.texo.orm.test

For generating java code, Texo needs an eclipse running, possibly in headless mode, Texo also needs a workspace with a
dev project to generate the source code, but other than that you can call a generator for that:
http://git.eclipse.org/c/texo/org.eclipse.emf.texo.git/tree/tests/org.eclipse.emf.texo.modelgenerator.test/src/org/eclipse/emf/texo/modelgenerator/test/EclipseModelGeneratorTest.java

Note that the generator must run in an eclipse instance (headless is possible) with a workspace which contains a java
development project, see the launch configs here as an example:
http://git.eclipse.org/c/texo/org.eclipse.emf.texo.git/tree/tests/org.eclipse.emf.texo.modelgenerator.test/

There is a ModelAnnotatorRegistry which you can use to override the default annotators implemented by Texo, so in that
way you create/add custom annotations. But this is quite deep into the Texo code...

Let me know if you have any more questions/remarks;

gr. Martin

On 05/08/2012 11:13 PM, Shahim Essaid wrote:
> Hi all,
>
> Can someone please show me an example for creating a JPA mapping file (orm.xml) programmatically from an ecore metamodel
> by using the Texo API?
> Also, can I load the metamodel into a ResourceSet, programatically create an annotation model with few overrides in the
> same set, and have the generated orm be based on the additional annotations?
>
> What about generating the JPA annotated code, can that also be done programatically?
>
> I tried to look for examples in the Wiki but it mostly shows how to do this from the UI, not from the API. Any examples
> or hints will be appreciated.
>
> Thank you,
> Shahim


--

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@xxxxxxxx - mtaal@xxxxxxxx
Web: www.springsite.com - www.elver.org
Re: [Texo] Example for creating orm.xml from ecore model programmatically [message #870601 is a reply to message #870599] Tue, 08 May 2012 22:40 Go to previous messageGo to next message
Martin Taal is currently offline Martin TaalFriend
Messages: 5468
Registered: July 2009
Senior Member
Hi Shahim,
I noticed this plugin:
http://www.ant4eclipse.org/userguide-executors

which seems to make it possible to run launch configs, maybe this can be combined with the current code of Texo
generation to programmatically generate stuff.

gr. Martin

On 05/08/2012 11:58 PM, Martin Taal wrote:
> Hi Shahim,
> For the first question you are the first to ask so therefore there is no wiki entry about it.. :-). For generating the
> in-memory orm model from an ecore metamodel, check out this method:
> http://git.eclipse.org/c/texo/org.eclipse.emf.texo.git/tree/generator/org.eclipse.emf.texo.orm/src/org/eclipse/emf/texo/orm/annotator/ORMGenerator.java#n128
>
>
> the generateStoreORM method, so it takes less than 10 lines of code to generate orms and have them represented
> in-memory, if you use an annotation model then it is important to read the epackages in the correct way (the annotations
> model are searched in the same place as where the ecore is read from).
> This test method gives a good feel for how to do that:
> http://git.eclipse.org/c/texo/org.eclipse.emf.texo.git/tree/tests/org.eclipse.emf.texo.orm.test/src/org/eclipse/emf/texo/orm/test/ORMGeneratorTest.java#n91
>
>
> See the launch configs here for what Texo uses in its test runs (to generate orms):
> http://git.eclipse.org/c/texo/org.eclipse.emf.texo.git/tree/tests/org.eclipse.emf.texo.orm.test
>
> For generating java code, Texo needs an eclipse running, possibly in headless mode, Texo also needs a workspace with a
> dev project to generate the source code, but other than that you can call a generator for that:
> http://git.eclipse.org/c/texo/org.eclipse.emf.texo.git/tree/tests/org.eclipse.emf.texo.modelgenerator.test/src/org/eclipse/emf/texo/modelgenerator/test/EclipseModelGeneratorTest.java
>
>
> Note that the generator must run in an eclipse instance (headless is possible) with a workspace which contains a java
> development project, see the launch configs here as an example:
> http://git.eclipse.org/c/texo/org.eclipse.emf.texo.git/tree/tests/org.eclipse.emf.texo.modelgenerator.test/
>
> There is a ModelAnnotatorRegistry which you can use to override the default annotators implemented by Texo, so in that
> way you create/add custom annotations. But this is quite deep into the Texo code...
>
> Let me know if you have any more questions/remarks;
>
> gr. Martin
>
> On 05/08/2012 11:13 PM, Shahim Essaid wrote:
>> Hi all,
>>
>> Can someone please show me an example for creating a JPA mapping file (orm.xml) programmatically from an ecore metamodel
>> by using the Texo API?
>> Also, can I load the metamodel into a ResourceSet, programatically create an annotation model with few overrides in the
>> same set, and have the generated orm be based on the additional annotations?
>>
>> What about generating the JPA annotated code, can that also be done programatically?
>>
>> I tried to look for examples in the Wiki but it mostly shows how to do this from the UI, not from the API. Any examples
>> or hints will be appreciated.
>>
>> Thank you,
>> Shahim
>
>


--

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@xxxxxxxx - mtaal@xxxxxxxx
Web: www.springsite.com - www.elver.org
Re: [Texo] Example for creating orm.xml from ecore model programmatically [message #870614 is a reply to message #870601] Wed, 09 May 2012 02:24 Go to previous messageGo to next message
Shahim Essaid is currently offline Shahim EssaidFriend
Messages: 40
Registered: July 2009
Member
Thank you very much Martin! I will look at your suggestions and come back with any questions. I thought it would be a little more straightforward than this Smile

It would be nice if Texo is able to generate some of these artifacts (especially the ORM part) without having to run in an Eclipse instance. I was planning on using Texo in a plain Java SE environment. I can add few plugin dependencies but I can't run an instance of Eclipse just to do this. I'll look at your launch configuration a little closer to see if it does not start an Eclipse instance.

Best,
Shahim
Re: [Texo] Example for creating orm.xml from ecore model programmatically [message #870618 is a reply to message #870614] Wed, 09 May 2012 05:32 Go to previous messageGo to next message
Martin Taal is currently offline Martin TaalFriend
Messages: 5468
Registered: July 2009
Senior Member
Hi Shahim,
Generating the orm.xml should be possible outside of an eclipse instance. I can probably easily change that if currently
somehow the ide is required. It is generating code where the ide is used as the code generation uses several features
from the jdt to do import resolving and code formatting, even then, you can run eclipse in headless mode, which is
basically the same as any java program (afaiu). In fact that's what the test cases of Texo do, run eclipse headless, the
Texo build is an ant script which runs eclipe in headless mode and generates code and everything else.

Note that at runtime you don't need to have Eclipse ide running at all, you just need a few jar files. Here is an
example tomcat web project with Texo:
http://wiki.eclipse.org/Texo/Download_and_Install#Texo_Example_Project.28s.29

gr. Martin

On 05/09/2012 04:25 AM, Shahim Essaid wrote:
> Thank you very much Martin! I will look at your suggestions and come back with any questions. I thought it would be a
> little more straightforward than this :)
>
> It would be nice if Texo is able to generate some of these artifacts (especially the ORM part) without having to run in
> an Eclipse instance. I was planning on using Texo in a plain Java SE environment. I can add few plugin dependencies but
> I can't run an instance of Eclipse just to do this. I'll look at your launch configuration a little closer to see if it
> does not start an Eclipse instance.
>
> Best,
> Shahim


--

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@xxxxxxxx - mtaal@xxxxxxxx
Web: www.springsite.com - www.elver.org
Re: [Texo] Example for creating orm.xml from ecore model programmatically [message #870796 is a reply to message #870618] Wed, 09 May 2012 17:33 Go to previous messageGo to next message
Shahim Essaid is currently offline Shahim EssaidFriend
Messages: 40
Registered: July 2009
Member
Martin, thank you for your quick and detailed responses. I really appreciate it.

I have not tried to run Eclipse in headless mode or in any unit tests before. I'll do some reading and then look at the examples you were referring to.

I think the current ORMGenerator does require an instance of Eclipse. I was trying to understand a null pointer exception when I tried it yesterday. It appears the exception is due to not finding needed plugins or other resources in the Eclipse registry, or something like that. I assumed this means that the Eclipse runtime has to be available to generate the ORM.

Again, thank you!

All the best,
Shahim

[Updated on: Wed, 09 May 2012 17:34]

Report message to a moderator

Re: [Texo] Example for creating orm.xml from ecore model programmatically [message #870830 is a reply to message #870796] Wed, 09 May 2012 19:40 Go to previous messageGo to next message
Martin Taal is currently offline Martin TaalFriend
Messages: 5468
Registered: July 2009
Senior Member
Okay, let me know if you know more if it is a missing plugin/jar or indeed that it expects a workspace being there. For
the in-memory orm generation it should officially not be needed to have eclipse. But I did not explicitly thought about
it when doing the code...

Texo uses launch configs for starting eclipse, maybe these can be somehow packaged in a runnable product. I don't know
much/anything about this though...

gr. Martin

On 05/09/2012 07:34 PM, Shahim Essaid wrote:
> Martin, thank you for your quick and detailed responses. I really appreciate it.
>
> I have not tried to run Eclipse in headless mode or in any unit tests before. I'll do some reading and then look at the
> examples you were referring to.
>
> I think the current ORMGenerator does require an instance of Eclipse. I was trying to understand a null point exception
> when I tried it yesterday. It appears the exception is due to not finding needed plugins or other resources in the
> Eclipse registry, or something like that. I assumed this means that the Eclipse runtime has to be available to generate
> the ORM.
>
> Again, thank you!
>
> All the best,
> Shahim


--

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@xxxxxxxx - mtaal@xxxxxxxx
Web: www.springsite.com - www.elver.org
Re: [Texo] Example for creating orm.xml from ecore model programmatically [message #991853 is a reply to message #870830] Thu, 20 December 2012 11:03 Go to previous messageGo to next message
Pradeep Badiger is currently offline Pradeep BadigerFriend
Messages: 53
Registered: November 2012
Member
Hi Martin,

I was trying to execute the JPA code generator test (EclipseModelGeneratorTest) with my own model project. But for "project.getLocation()", I get null and ultimately test fails with exception. I get the same exception even when I place my project in the workspace created during junit plugin-test run. Are there any settings that i am missing?

thanks,
Pradeep V.B.
Re: [Texo] Example for creating orm.xml from ecore model programmatically [message #991873 is a reply to message #991853] Thu, 20 December 2012 11:40 Go to previous messageGo to next message
Martin Taal is currently offline Martin TaalFriend
Messages: 5468
Registered: July 2009
Senior Member
Hi Pradeep,
Hmm, is the workspace cleared at each testrun? (a checkbox below the workspace location in the launch config)
It should not be cleared.

Can you put a breakpoint where it fails and then go into a file explorer and check that the project exists at the
location your expecting?

How do you place the project in the workspace? You need to open the workspace in the IDE and add the project there and
then close the IDE. So copying the project in the workspace through a file explorer won't work (if you are doing that
ofcourse).

gr. Martin


On 12/20/2012 12:03 PM, Pradeep Badiger wrote:
> Hi Martin,
>
> I was trying to execute the JPA code generator test (EclipseModelGeneratorTest) with my own model project. But for
> "project.getLocation()", I get null and ultimately test fails with exception. I get the same exception even when I place
> my project in the workspace created during junit plugin-test run. Are there any settings that i am missing?
>
> thanks,
> Pradeep V.B.


--

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@xxxxxxxx - mtaal@xxxxxxxx
Web: www.springsite.com - www.elver.org
Re: [Texo] Example for creating orm.xml from ecore model programmatically [message #991897 is a reply to message #991873] Thu, 20 December 2012 12:53 Go to previous message
Pradeep Badiger is currently offline Pradeep BadigerFriend
Messages: 53
Registered: November 2012
Member
Hi Martin,

Thanks for the guidance. I did not import the project. On import its able to locate the project and create the entities.

thanks,
Pradeep V.B.
Previous Topic:EMF + Texo + Xpand2
Next Topic:[Texo] Entity Listener annotation not generated correctly
Goto Forum:
  


Current Time: Fri Apr 19 03:37:08 GMT 2024

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

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

Back to the top