Bug 159226 - Sample DB Persistence program
Summary: Sample DB Persistence program
Status: NEW
Alias: None
Product: GMF-Runtime
Classification: Modeling
Component: General (show other bugs)
Version: unspecified   Edit
Hardware: PC Windows XP
: P3 enhancement
Target Milestone: 2.0   Edit
Assignee: Sergey CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2006-09-29 01:19 EDT by Vijayan CLA
Modified: 2010-07-19 22:00 EDT (History)
10 users (show)

See Also:


Attachments
Mindmap example persistence + gmf notation fix (for comment #22 by Sergey Armensky) (30.11 KB, application/x-zip-compressed)
2007-06-25 11:07 EDT, Sergey CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Vijayan CLA 2006-09-29 01:19:54 EDT
Hi,

Can we have a sample program for saving & loading the diagram and the complete relationship created using GMF into a database?

Thanks & Regards,
Vijayan
Comment 1 Richard Gronback CLA 2006-10-13 06:31:24 EDT
Adding Martin to the CC list, as yesterday he and I discussed this at ESE.  It seems he also has this on his list of things to do for Teneo.
Comment 2 Martin Taal CLA 2006-11-14 07:58:45 EST
Hi,
I have been looking into this a few times (using Teneo). It does not work right away. My first conclusion is that it is currently difficult for Teneo (because of mapping issues) to store the actual diagram. It should however be possible to read the data from a Teneo relational resource. 
But I have difficulties finding the main hook were to direct that a Teneo resource is read instead of a file based resource.
I have been using the mindmap tutorial. Are there any specific parts of gmf or the generated code which I can extend/adapt to direct the diagram editor to use a certain (emf) resource?

gr. Martin
Comment 3 Richard Gronback CLA 2006-11-14 08:22:36 EST
Perhaps org.eclipse.gmf.runtime.emf.core.resources.GMFResourceFactory will help?  Adding Alex to cc list, as I believe he's had some newsgroup discussions in the past on this subject.
Comment 4 Alex Shatalin CLA 2006-11-14 08:31:15 EST
Rich, you are right! The correct place to hook into EMF is ResourceFactory - we have to register alternative ResourceFactories for both domain and diagram resources and then corresponding factories (provided by Teneo AFAIU) will be responsible for creating actual instances of Resources + EObjects on request from GMF.
Comment 5 Martin Taal CLA 2006-11-14 08:51:14 EST
Thanks for the quick responses, is this possible with the current codebase/release?
Would it be an idea to make this registration available as an extension(point)?

gr. Martin

Comment 6 Alex Shatalin CLA 2006-11-14 11:15:54 EST
It is possible via extension point. Take a look on "org.eclipse.emf.ecore.extension_parser" extension.
Comment 7 Martin Taal CLA 2006-11-15 01:37:59 EST
Yes it works. I tested it based on the mindmap tutorial. In the scenario I tested the data was stored in a HibernateResource in the db and the diagram was stored in a local file.

The steps are very similar to the way the emf editor is initialized, see here:
http://www.elver.org/hibernate/tutorialtwo/tutorial2_intro.html

Is it a problem if the diagram and content are separated (one in a local file and one in a central database)? 
For example if the data in the database is changed by other users/programs is the diagram editor able to reconcile most changes in the local diagram file (I tested a few smaller changes and it worked fine)?
Comment 8 Alex Shatalin CLA 2006-11-15 06:07:08 EST
It should not be a problem. Currently generated implementation should be able to reconcile most of the changes in the domain model and the rest situations considered as bugs and will (should) be fixed.

It actually depends on the requirements – if it is not possible to put diagram into the DB then user can store it locally. Diagram should be stored in the DB if it is required to share diagram elements layout and visual properties across several clients working with same diagram/domain model/DB.
Comment 9 Vijayan CLA 2006-11-15 07:54:21 EST
(In reply to comment #8)
> It should not be a problem. Currently generated implementation should be able
> to reconcile most of the changes in the domain model and the rest situations
> considered as bugs and will (should) be fixed.
> 
> It actually depends on the requirements – if it is not possible to put diagram
> into the DB then user can store it locally. Diagram should be stored in the DB
> if it is required to share diagram elements layout and visual properties across
> several clients working with same diagram/domain model/DB.
> 

Hi,

It would be fine if we are just able to save the complete relationship that we show on the diagram into Database and load it back using GMF. No need of saving the diagram itself into the database. Just like the sample program (using Teneo jars) which we have using EMFT and Hibernate to store/retrieve the library system into database. 

Sorry for the confusion.

Regards,
Vijayan
Comment 10 Martin Taal CLA 2006-11-15 08:36:56 EST
Okay, I will probably do a new build in a few days containing some small changes I was required to do for this.

Let me know if database persistence of the diagram is required for other users. If so then I can look at that also (using Teneo).
However to do that I would need an example of fairly complete diagram content (preferably using the mindmap example), in a xmi/xml file which I can read through the standard EMF xmi/xml resource. This makes it possible for me to test if there are issues related to the mapping to the db.

gr. Martin
Comment 11 Richard Gronback CLA 2006-11-15 08:41:33 EST
I'd say persisting the diagram is a requirement for others.  We also have the option to persist both diagram and domain in a single resource (file).

Let me work on creating a large mindmap instance for you.
Comment 12 Martin Taal CLA 2006-11-20 06:54:02 EST
Hi,
I am looking at persisting the diagram itself. 
I am encountering some difficulties because of the way the persistentChildren efeature of View is handled. 
Although this efeature exists in the ecore model it is renamed at runtime to 'children'. It is this line (1853) in NotationPackageImpl:
initEReference(getView_PersistedChildren(), this.getNode(), null, "children", null, 0, -1, View.class, !IS_TRANSIENT, !IS_VOLATILE, IS_CHANGEABLE, IS_COMPOSITE, !IS_RESOLVE_PROXIES, !IS_UNSETTABLE, IS_UNIQUE, !IS_DERIVED, IS_ORDERED); //$NON-NLS-1$

Is there a specific reason to rename this efeature (just curious here)?
Would it be logical to instead of renaming the efeature persistedchildren to add children as an additional efeature (volatile/transient)?

gr. Martin
Comment 13 Alex Shatalin CLA 2006-11-20 07:51:16 EST
Reply to <a href="show_bug.cgi?id=159226#c12">comment #12</a>: Please, ask corresponding quesrion in newsgroup.
Comment 14 Martin Taal CLA 2006-11-29 01:10:25 EST
Well I did, but I got no response there (at least my news reader does not show an answer).

Anyway, here is a tutorial for at least persisting the data itself in Teneo:
http://www.elver.org/hibernate/gmftutorial/tutorial1.html

If there is interest in trying this out then that would be nice. Please let me know if there are any obstacles/issues.

Regarding persisting the graphical model itself. Currently I am stuck with the issue I mentioned here in this bugzilla (and posted on the gmft newsgroup). I can/will continue looking at this after I get some response on the newsgroup (or here).

gr. Martin
Comment 15 Alex Shatalin CLA 2006-11-29 06:04:13 EST
(In reply to comment #14)
This part of API is in the area of runtime team responsibility, so I can suggest you to ask this question once more and then create corresponding bugzilla entry in case of silence. Please, add CC to me if you submit anything related to it.

Concerning tutorial: m.b. it make sense to put it on GMF wiki page?
Comment 16 Martin Taal CLA 2006-12-01 08:56:50 EST
Okay I have reposted my question. 

I prefer to add a link to the tutorial first because maybe I have to change it based on feedback (prefer not do to that in two locations). 
What would be a logical location for such a link (toc or one of the mindmap tutorials)?

gr. Martin
Comment 17 Vijayan CLA 2006-12-12 01:43:30 EST
Hi,

When i try to run the GMF editor (following all the steps mentioned in the link http://www.elver.org/hibernate/gmftutorial/tutorial1.html), i get an error message saying "Unable to create table map". This is because it tries to create the required tables everytime the editor is run. Please let me know how to set the PersistenceOptions in the properties file to avoid this problem. Also is it necessary to have the database with the name mindmap?

Thanks & Regards,
Vijayan
Comment 18 Martin Taal CLA 2006-12-12 03:15:51 EST
The name of the database can be changed by changing the string mindmap to something else in these two parts of the property file:
dbname=mindmap
dburl=jdbc:mysql://127.0.0.1:3306/mindmap

It should detect that the tables already exists. Although this can depend on the capabilities of the database driver to provide schema information. You can disable db schema creation/updates by passing the following property to the HbDataStore:
PersistenceOptions.UPDATE_SCHEMA

and then set this to false to prevent db schema updates, and true (default) otherwise.

gr. Martin
Comment 19 Sergey CLA 2007-06-01 15:25:32 EDT
(In reply to comment #12)
Model code generator for GMF notation model (dev.eclipse.org, /cvsroot/modeling, org.eclipse.gmf/plugins/org.eclipse.gmf.runtime.notation) uses PackageClass.javajet template that renames "persistedChildren" and "persistedEdges" features to "children" (see model/notation.genmodel, templates/model/PackageClass.javajet). Maybe think about new extension point in org.eclipse.emf.teneo.hibernate plug-in that allows use of custom property handler or at least customization of EListPropertyHandler? It would be useful for models with custom model code generation.
Comment 20 Sergey CLA 2007-06-20 17:55:48 EDT
org.eclipse.emf.ecore.util.ExtendedMetaData may be used in gmf.runtime.notation to avoid renaming persistedChildren->children, persistedEdges->edges in model code. Most likely we'll offer this fix to GMF Runtime team but I doubt they include it GMF 2.0.
Comment 21 Sergey CLA 2007-06-25 11:07:22 EDT
Created attachment 72363 [details]
Mindmap example persistence + gmf notation fix (for comment #22 by Sergey Armensky)

Mindmap example persistence + gmf notation fix (for comment #21 by Sergey Armensky)
Comment 22 Sergey CLA 2007-06-25 11:17:26 EDT
Anyway, there are problems with diagram persistence even using fixed gmf
notation model. I tried mindmap example (persistence code and gmf notation fix
are in attachment #72363 [details]). Mindmap model and diagram persisted to single
database using common SessionController. StaleStateException thrown in
sessionController.getSessionWrapper().commitTransaction() 
(org.hibernate.jdbc.AbstractBatcher#batchUpdate:
com.mysql.jdbc.ServerPreparedStatement - update `style` set
`view_styles_e_id`=1, `view_styles_idx`=0 where e_id=2)

[ERROR] AbstractBatcher - -Exception executing batch: 
<org.hibernate.StaleStateException: Batch update returned unexpected row count
from update [0]; actual row count: 0; expected:
1>org.hibernate.StaleStateException: Batch update returned unexpected row count
from update [0]; actual row count: 0; expected: 1
        at
org.hibernate.jdbc.Expectations$BasicExpectation.checkBatched(Expectations.java:61)
        at
org.hibernate.jdbc.Expectations$BasicExpectation.verifyOutcome(Expectations.java:46)
        at
org.hibernate.jdbc.BatchingBatcher.checkRowCounts(BatchingBatcher.java:68)
        at
org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:48)
        at
org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:246)
        at
org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:237)
        at
org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:145)
        at
org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:298)
        at
org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
        at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1000)
        at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:338)
        at
org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:106)
        at
org.eclipse.emf.teneo.hibernate.HbSessionWrapper.commitTransaction(HbSessionWrapper.java:82)
        at
org.eclipse.gmf.examples.mindmap.diagram.part.MindmapNewDiagramFileWizard$1.doExecuteWithResult(MindmapNewDiagramFileWizard.java:155)
        at
org.eclipse.gmf.runtime.emf.commands.core.command.AbstractTransactionalCommand.doExecute(AbstractTransactionalCommand.java:246)
        at
org.eclipse.emf.workspace.AbstractEMFOperation.execute(AbstractEMFOperation.java:135)
        at
org.eclipse.core.commands.operations.DefaultOperationHistory.execute(DefaultOperationHistory.java:511)
        at
org.eclipse.gmf.examples.mindmap.diagram.part.MindmapNewDiagramFileWizard.performFinish(MindmapNewDiagramFileWizard.java:172)
        at
org.eclipse.jface.wizard.WizardDialog.finishPressed(WizardDialog.java:742)
        at
org.eclipse.jface.wizard.WizardDialog.buttonPressed(WizardDialog.java:373)
        at org.eclipse.jface.dialogs.Dialog$2.widgetSelected(Dialog.java:616)
        at
org.eclipse.swt.widgets.TypedListener.handleEvent(TypedListener.java:227)
        at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:66)
        at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:938)
        at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:3682)
        at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3293)
        at org.eclipse.jface.window.Window.runEventLoop(Window.java:820)
        at org.eclipse.jface.window.Window.open(Window.java:796)
        at
org.eclipse.gmf.examples.mindmap.diagram.part.MindmapDiagramEditorUtil.runWizard(MindmapDiagramEditorUtil.java:176)
        at
org.eclipse.gmf.examples.mindmap.diagram.part.MindmapInitDiagramFileAction$1.doExecute(MindmapInitDiagramFileAction.java:159)
        at
org.eclipse.emf.transaction.RecordingCommand.execute(RecordingCommand.java:129)
        at
org.eclipse.emf.workspace.EMFCommandOperation.doExecute(EMFCommandOperation.java:116)
        at
org.eclipse.emf.workspace.AbstractEMFOperation.execute(AbstractEMFOperation.java:135)
        at
org.eclipse.core.commands.operations.DefaultOperationHistory.execute(DefaultOperationHistory.java:511)
        at
org.eclipse.emf.workspace.impl.WorkspaceCommandStackImpl.doExecute(WorkspaceCommandStackImpl.java:144)
        at
org.eclipse.emf.transaction.impl.AbstractTransactionalCommandStack.execute(AbstractTransactionalCommandStack.java:164)
        at
org.eclipse.emf.transaction.impl.AbstractTransactionalCommandStack.execute(AbstractTransactionalCommandStack.java:217)
        at
org.eclipse.gmf.examples.mindmap.diagram.part.MindmapInitDiagramFileAction.run(MindmapInitDiagramFileAction.java:122)
        at
org.eclipse.ui.internal.PluginAction.runWithEvent(PluginAction.java:256)
        at
org.eclipse.jface.action.ActionContributionItem.handleWidgetSelection(ActionContributionItem.java:545)
        at
org.eclipse.jface.action.ActionContributionItem.access$2(ActionContributionItem.java:490)
        at
org.eclipse.jface.action.ActionContributionItem$5.handleEvent(ActionContributionItem.java:402)
        at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:66)
        at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:938)
        at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:3682)
        at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3293)
        at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.java:2389)
        at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:2353)
        at org.eclipse.ui.internal.Workbench.access$4(Workbench.java:2219)
        at org.eclipse.ui.internal.Workbench$4.run(Workbench.java:466)
        at
org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:289)
        at
org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:461)
        at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:149)
        at
org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.java:106)
        at
org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:153)
        at
org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:106)
        at
org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:76)
        at
org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:363)
        at
org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:176)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
        at java.lang.reflect.Method.invoke(Unknown Source)
        at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:504)
        at org.eclipse.equinox.launcher.Main.basicRun(Main.java:443)
        at org.eclipse.equinox.launcher.Main.run(Main.java:1169)
        at org.eclipse.equinox.launcher.Main.main(Main.java:1144)
Comment 23 Robert Moloney CLA 2007-10-22 06:38:49 EDT
Hi,
What is the status of this issue? Will the EclipseLink intergation solve these problems? We have tried a solution that stores the notational data as a bytearray in the database. But as we no longer use an IFile, decorations, markers, link helper and possibly other functionality is disabled! 
Cheers
Rob
Comment 24 Martin Taal CLA 2008-03-08 08:34:02 EST
I am currently solving some issues related to the Teneo GMF integration. The following two threads can be of interest:
http://www.eclipse.org/newsportal/article.php?id=4809&group=eclipse.technology.emft#4809
http://www.eclipse.org/newsportal/article.php?id=4823&group=eclipse.technology.emft#4823

We still have the issue that the persistedChildren efeature is renamed to children (as mentioned in the bugzilla from comment 12 and further). My impression is that the proposed patch was not yet applied. Just for my information is it still the idea to apply the patch or what can I do to promote this patch to be applied?

The reason I ask is because the last few weeks there have been several users on the Teneo newsgroup working on persisting diagrams and their related data.

gr. Martin
Comment 25 Richard Gronback CLA 2008-03-08 11:20:37 EST
Adding Anthony to cc for comment on notation model question, and switching component to runtime for the time being.
Comment 26 Martin Taal CLA 2008-03-17 22:01:17 EDT
Hi,
I have made a number of changes in Teneo to accomodate for also persisting the diagram. I have a good workaround for both comment 12 and 22. This is included in the latest Teneo build of today. So with the newest Teneo build the model and the diagram are stored in the same database. 

The gmf tutorial for teneo has been updated and describes in detail how to make use of Teneo resources within GMF:
http://www.elver.org/hibernate/gmftutorial/tutorial1.html

Overall I think that with the newest approach it is fairly easy to integrate Teneo and GMF (basically overriding 2 methods in the generated editor class).

Feel free to comment on the tutorial.

gr. Martin
Comment 27 Anthony Hunter CLA 2008-03-18 12:03:21 EDT
(In reply to comment #20)
> org.eclipse.emf.ecore.util.ExtendedMetaData may be used in gmf.runtime.notation
> to avoid renaming persistedChildren->children, persistedEdges->edges in model
> code. Most likely we'll offer this fix to GMF Runtime team but I doubt they
> include it GMF 2.0.

I was trying to find out why we made this change, but it has been there before we open sourced GMF. This is a breaking API change for existing clients, so we would need to look at having both persistedChildren and children, rather than the rename. Correct?
Comment 28 Martin Taal CLA 2008-03-18 12:15:10 EDT
Yes, if both are present whereby one internally just calls the other then that would work fine to.

gr. Martin
Comment 29 Eclipse Webmaster CLA 2010-07-19 22:00:11 EDT
[GMF Restructure] Bug 319140 : product GMF and component
Runtime was the original product and component for this bug