Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Xtext Dsl Persistency in database(Xtext Dsl Persistency in database)
Xtext Dsl Persistency in database [message #1080651] Tue, 06 August 2013 08:04 Go to next message
Paul Brillant is currently offline Paul BrillantFriend
Messages: 7
Registered: August 2013
Junior Member
Hi all,
How can I save model instances created in my DSL editor directly in database rather than flat files ?
I guess this will constitute to customize the method resource.save() or somehow to modify the Xtext implementation of the Xtext resources

I tried to find out in different posts without success. I saw how to persist EMF models in database using Teneo and hibernate. Can you give me some hints for Xtext models ?
Thanks in advance,
Regards,
Paul
Re: Xtext Dsl Persistency in database [message #1082362 is a reply to message #1080651] Thu, 08 August 2013 13:13 Go to previous messageGo to next message
Jaime Chavarriaga is currently offline Jaime ChavarriagaFriend
Messages: 5
Registered: June 2013
Junior Member
Storing Models into databases

In EMF, you can store models into databases using Texo or Teneo
- Texo, wiki.eclipse.org/Texo, use plain Java objects
- Teneo, wiki.eclipse.org/Teneo/Hibernate, use Ecore-based objects

In any case, you must include annotations in the metamodel to define the mapping between classes and attributes in the Model and the tables and columns in the databases. Once you have persisted your models, you can use SQL o JPQL to query data on your set of models.

Other option is to store models into a Model repository such as CDO o EMFStore.
- CDO, www.eclipse.org/cdo/
- EMFStore, eclipse.org/emfstore/

Using Xtext

If you are using a predefined EMF meta-model (using import in your grammar), you can set the annotations in each meta-class without any interference to Xtext (www.softwareagility.gr/index.php?q=node/26)

If you are generating the EMF metamodel based on your grammar (using generate instead of import), I think you can use a Xtext PostProcessor to add the annotations to the generated metamodels, or create an IGeneratorFragment to use in your MWE2 workflow (just like the existing EcoreGeneratorFragment)

Additionally, if you grammar is very stable, you can generate the meta-model using your grammar, then modify your metamodel and use the modified metamodel instead of generate it in the MWE2 workflow. This trick was used in the LWC11 submission of Xtext (lwc11-xtext.eclipselabs.org.codespot.com/files/LWC11-XtextSubmission-v1.2.pdf) in the Chapter 7.
Re: Xtext Dsl Persistency in database [message #1082895 is a reply to message #1082362] Fri, 09 August 2013 07:02 Go to previous messageGo to next message
Jan Koehnlein is currently offline Jan KoehnleinFriend
Messages: 760
Registered: July 2009
Location: Hamburg
Senior Member
Some additional notes:
- If you only store the EMF model in the database you will loose all
concrete syntax information (whitespaces, comments etc.)

- Database repositories usually have a different notion of object
identity than file based ones. E.g. Xtext replaces entire subtrees of
the model when you type in the editor with the reparsed elements. Object
identity is *not* preserved. The semantic model is transient artifact
derived from the authoritative text model.


Am 08.08.13 15:13, schrieb Jaime Chavarriaga:
> Storing Models into databases
>
> In EMF, you can store models into databases using Texo or Teneo
> - Texo, wiki.eclipse.org/Texo, use plain Java objects
> - Teneo, wiki.eclipse.org/Teneo/Hibernate, use Ecore-based objects
>
> In any case, you must include annotations in the metamodel to define the
> mapping between classes and attributes in the Model and the tables and
> columns in the databases. Once you have persisted your models, you can
> use SQL o JPQL to query data on your set of models.
>
> Other option is to store models into a Model repository such as CDO o
> EMFStore.
> - CDO, www.eclipse.org/cdo/
> - EMFStore, eclipse.org/emfstore/
>
> Using Xtext
>
> If you are using a predefined EMF meta-model (using import in your
> grammar), you can set the annotations in each meta-class without any
> interference to Xtext (www.softwareagility.gr/index.php?q=node/26)
>
> If you are generating the EMF metamodel based on your grammar (using
> generate instead of import), I think you can use a Xtext PostProcessor
> to add the annotations to the generated metamodels, or create an
> IGeneratorFragment to use in your MWE2 workflow (just like the existing
> EcoreGeneratorFragment)
> Additionally, if you grammar is very stable, you can generate the
> meta-model using your grammar, then modify your metamodel and use the
> modified metamodel instead of generate it in the MWE2 workflow. This
> trick was used in the LWC11 submission of Xtext
> (lwc11-xtext.eclipselabs.org.codespot.com/files/LWC11-XtextSubmission-v1.2.pdf)
> in the Chapter 7.


--
Need professional support for Eclipse Modeling?
Go visit: http://xtext.itemis.com


---
Get professional support from the Xtext committers at www.typefox.io
Re: Xtext Dsl Persistency in database [message #1083187 is a reply to message #1082895] Fri, 09 August 2013 15:51 Go to previous messageGo to next message
Paul Brillant is currently offline Paul BrillantFriend
Messages: 7
Registered: August 2013
Junior Member
Jaime,

Thanks for your detailed answer.
Actually, the first link* in the "Using Xtext" paragraph of your answer is really what I am looking for. Because I want also that elements of content assist editor come from database. However, I followed this post so far but it did not work for me. Maybe as you mentioned, I will first set the annotations in each meta-class. But there is not mention in the post about that. It seems like the author did not get more in details in some aspects. Do I necessary need to set annotations in order to have the example of this post works ?

PS. for my project, I am using a predefined EMF meta-model.

Jan,
Thanks for the additional infos.


* Sorry, I cannot put this link because the site reported an error telling that I have fewer than 5 messages

Regards,
Paul
Re: Xtext Dsl Persistency in database [message #1140531 is a reply to message #1083187] Wed, 16 October 2013 12:25 Go to previous message
louy koko is currently offline louy kokoFriend
Messages: 20
Registered: October 2013
Junior Member
If you know answer.
my email. louykoko@yahoo.com

I was trying to open database, then this error appeared.

3004: Unexpected error occurred.
org.eclipse.e4.core.di.InjectionException: java.lang.NullPointerException
at org.eclipse.e4.core.internal.di.MethodRequestor.execute(MethodRequestor.java:63)
at org.eclipse.e4.core.internal.di.InjectorImpl.invokeUsingClass(InjectorImpl.java:231)
at org.eclipse.e4.core.internal.di.InjectorImpl.invoke(InjectorImpl.java:212)
at org.eclipse.e4.core.contexts.ContextInjectionFactory.invoke(ContextInjectionFactory.java:131)
at org.eclipse.e4.core.commands.internal.HandlerServiceImpl.executeHandler(HandlerServiceImpl.java:171)
at org.eclipse.e4.ui.workbench.renderers.swt.HandledContributionItem.executeItem(HandledContributionItem.java:831)
at org.eclipse.e4.ui.workbench.renderers.swt.HandledContributionItem.handleWidgetSelection(HandledContributionItem.java:724)
at org.eclipse.e4.ui.workbench.renderers.swt.HandledContributionItem.access$7(HandledContributionItem.java:708)
at org.eclipse.e4.ui.workbench.renderers.swt.HandledContributionItem$4.handleEvent(HandledContributionItem.java:647)
at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1053)
at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:4169)
at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3758)
at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine$9.run(PartRenderingEngine.java:1053)
at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332)
at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.run(PartRenderingEngine.java:942)
at org.eclipse.e4.ui.internal.workbench.E4Workbench.createAndRunUI(E4Workbench.java:86)
at org.eclipse.ui.internal.Workbench$5.run(Workbench.java:588)
at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332)
at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:543)
at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:149)
at org.eclipse.jubula.app.Launcher.start(Launcher.java:242)
at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:196)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:110)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:79)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:353)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:180)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:629)
at org.eclipse.equinox.launcher.Main.basicRun(Main.java:584)
at org.eclipse.equinox.launcher.Main.run(Main.java:1438)
at org.eclipse.equinox.launcher.Main.main(Main.java:1414)
Caused by: java.lang.NullPointerException
at java.util.TreeMap.getEntry(TreeMap.java:324)
at java.util.TreeMap.containsKey(TreeMap.java:209)
at org.eclipse.jubula.client.ui.rcp.handlers.project.OpenProjectHandler.checkAllAvailableProjects(OpenProjectHandler.java:397)
at org.eclipse.jubula.client.ui.rcp.handlers.project.OpenProjectHandler.executeImpl(OpenProjectHandler.java:534)
at org.eclipse.jubula.client.ui.handlers.AbstractHandler.execute(AbstractHandler.java:46)
at org.eclipse.jubula.client.ui.handlers.project.AbstractProjectHandler.execute(AbstractProjectHandler.java:38)
at org.eclipse.ui.internal.handlers.HandlerProxy.execute(HandlerProxy.java:290)
at org.eclipse.ui.internal.handlers.E4HandlerProxy.execute(E4HandlerProxy.java:76)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.eclipse.e4.core.internal.di.MethodRequestor.execute(MethodRequestor.java:56)
... 34 more
Previous Topic:using UUIDs in FragmentProvider
Next Topic:Migrating from Xtext 1.0.2 to Xtext 2.0
Goto Forum:
  


Current Time: Thu Dec 03 23:15:41 GMT 2020

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

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

Back to the top