Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF "Technology" (Ecore Tools, EMFatic, etc)  » Teneo proper save & validate
Teneo proper save & validate [message #885251] Tue, 12 June 2012 17:24 Go to next message
C Peter is currently offline C PeterFriend
Messages: 6
Registered: May 2012
Junior Member
Hello community,

I'm using Teneo 1.2, EMF 2.7, HIbernate 3.6 and Eclipse INdigo 3.7.2.

I've started with my own sample ecore model and now after some learning and tries about glueing them all together I've archvied my first success - iam very impressed about all the great stuff, thx^^

Actually I've got two problems where I'm stuck into:

1)

In the documentation wiki.eclipse.org/Teneo/Hibernate/GMF#Initialize_Teneo_when_plugin_starts
the method "doSave" is overwritten:
@Override
// implement a more simple save as there are no save-as dialogs involved
public void doSave(IProgressMonitor progressMonitor) {
	updateState(getEditorInput());
	validateState(getEditorInput());
	performSave(false, progressMonitor);
}


I think my generated Editor class (extends MultiPageEditorPart) must be also adapted in the same manner as described to save to db rather then file, but I do not know how, because there are no methods like updateState,validateState nor performSave in my editor.

The code from emf generation works, but I'm not sure if this is the correct use!!!
(working means: I could add model objects and prerform successfull save agaist hsql db)

The generated code:

	/**
	 * This is for implementing {@link IEditorPart} and simply saves the model file.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public void doSave(IProgressMonitor progressMonitor) {
		// Save only resources that have actually changed.
		//
		final Map<Object, Object> saveOptions = new HashMap<Object, Object>();
		saveOptions.put(Resource.OPTION_SAVE_ONLY_IF_CHANGED, Resource.OPTION_SAVE_ONLY_IF_CHANGED_MEMORY_BUFFER);

		// Do the work within an operation because this is a long running activity that modifies the workbench.
		//
		WorkspaceModifyOperation operation =
			new WorkspaceModifyOperation() {
				// This is the method that gets invoked when the operation runs.
				//
				@Override
				public void execute(IProgressMonitor monitor) {
					// Save the resources to the file system.
					//
					boolean first = true;
					for (Resource resource : editingDomain.getResourceSet().getResources()) {
						if ((first || !resource.getContents().isEmpty() || isPersisted(resource)) && !editingDomain.isReadOnly(resource)) {
							try {
								long timeStamp = resource.getTimeStamp();
								resource.save(saveOptions);
								if (resource.getTimeStamp() != timeStamp) {
									savedResources.add(resource);
								}
							}
							catch (Exception exception) {
								resourceToDiagnosticMap.put(resource, analyzeResourceProblems(resource, exception));
							}
							first = false;
						}
					}
				}
			};

		updateProblemIndication = false;
		try {
			// This runs the options, and shows progress.
			//
			new ProgressMonitorDialog(getSite().getShell()).run(true, false, operation);

			// Refresh the necessary state.
			//
			((BasicCommandStack)editingDomain.getCommandStack()).saveIsDone();
			firePropertyChange(IEditorPart.PROP_DIRTY);
		}
		catch (Exception exception) {
			// Something went wrong that shouldn't.
			//
			M0sfpEditorPlugin.INSTANCE.log(exception);
		}
		updateProblemIndication = true;
		updateProblemIndication();
	}



2)
My second problem is how to enable validation: I've got some OCL constraints in the model which could be successfully validated by menuaction "validate" in the running second eclipse instance, but not when the "save-button" is used.
I've tried via an action(implements IWorkbenchWindowActionDelegate) which calls "StoreController.getInstance().initializeDataStore();" in the "init" method and then:

final Resource resource = new HibernateXMLResource(StoreController.DATABASE_URI);
resource.setTrackingModification(true);

but it does not work - any clues?

Thanx in advance
Claus

[Updated on: Tue, 12 June 2012 17:26]

Report message to a moderator

Re: Teneo proper save &amp; validate [message #885263 is a reply to message #885251] Tue, 12 June 2012 17:40 Go to previous messageGo to next message
Martin Taal is currently offline Martin TaalFriend
Messages: 5468
Registered: July 2009
Senior Member
Hi Claus,
The not very positive answer is that I think you have to find this out alone, GMF and Teneo are not used that often
together and I am quite unfamiliar with it, so I can't help...

Regarding validation, when saving the validation is done in the resource (see StoreResource.validate(..)), maybe you can
extend the hibernate resource and call the validateContents method in the parent class, then you can do the pre-save
validation yourselve.

Btw, I would advice to use Teneo 2.0.0.

On 06/12/2012 07:24 PM, C Peter wrote:
> Hello community,
>
> I'm using Teneo 1.2, EMF 2.7, HIbernate 3.6 and Eclipse INdigo 3.7.2.
>
> I've started with my own sample ecore model and now after some learning and tries about glueing them all together I've
> archvied my first success - iam very impressed about all the great stuff, thx^^
>
> Actually I've got two problems where I'm stuck into:
>
> 1)
>
> In the documentation wiki.eclipse.org/Teneo/Hibernate/GMF#Initialize_Teneo_when_plugin_starts
> the method "doSave" is overwritten:
> @Override
> // implement a more simple save as there are no save-as dialogs involved
> public void doSave(IProgressMonitor progressMonitor) {
> updateState(getEditorInput());
> validateState(getEditorInput());
> performSave(false, progressMonitor);
> }
>
> I think my generated Editor class (extends MultiPageEditorPart) must be also adapted in the same manner as described to
> save to db rather then file, but I do not know how, because there are no methods like updateState,validateState nor
> performSave in my editor.
>
> The code from emf generation works, but I'm not sure if this is the correct use!!!
>
>
> The generated code:
>
> /**
> * This is for implementing {@link IEditorPart} and simply saves the model file.
> * <!-- begin-user-doc -->
> * <!-- end-user-doc -->
> * @generated
> */
> @Override
> public void doSave(IProgressMonitor progressMonitor) {
> // Save only resources that have actually changed.
> //
> final Map<Object, Object> saveOptions = new HashMap<Object, Object>();
> saveOptions.put(Resource.OPTION_SAVE_ONLY_IF_CHANGED, Resource.OPTION_SAVE_ONLY_IF_CHANGED_MEMORY_BUFFER);
>
> // Do the work within an operation because this is a long running activity that modifies the workbench.
> //
> WorkspaceModifyOperation operation =
> new WorkspaceModifyOperation() {
> // This is the method that gets invoked when the operation runs.
> //
> @Override
> public void execute(IProgressMonitor monitor) {
> // Save the resources to the file system.
> //
> boolean first = true;
> for (Resource resource : editingDomain.getResourceSet().getResources()) {
> if ((first || !resource.getContents().isEmpty() || isPersisted(resource)) && !editingDomain.isReadOnly(resource)) {
> try {
> long timeStamp = resource.getTimeStamp();
> resource.save(saveOptions);
> if (resource.getTimeStamp() != timeStamp) {
> savedResources.add(resource);
> }
> }
> catch (Exception exception) {
> resourceToDiagnosticMap.put(resource, analyzeResourceProblems(resource, exception));
> }
> first = false;
> }
> }
> }
> };
>
> updateProblemIndication = false;
> try {
> // This runs the options, and shows progress.
> //
> new ProgressMonitorDialog(getSite().getShell()).run(true, false, operation);
>
> // Refresh the necessary state.
> //
> ((BasicCommandStack)editingDomain.getCommandStack()).saveIsDone();
> firePropertyChange(IEditorPart.PROP_DIRTY);
> }
> catch (Exception exception) {
> // Something went wrong that shouldn't.
> //
> M0sfpEditorPlugin.INSTANCE.log(exception);
> }
> updateProblemIndication = true;
> updateProblemIndication();
> }
>
>
> 2)
> My second problem is how to enable validation: I've got some OCL constraints in the model which could be successfully
> validated by menuaction "validate" in the running second eclipse instance, but not when the "save-button" is used. I've
> tried via an action(implements IWorkbenchWindowActionDelegate) which calls
> "StoreController.getInstance().initializeDataStore();" in the "init" method and then:
>
> final Resource resource = new HibernateXMLResource(StoreController.DATABASE_URI);
> resource.setTrackingModification(true);
>
> but it does not work - any clues?
>
> Thanx in advance
> Claus


--

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: Teneo proper save &amp; validate [message #885514 is a reply to message #885263] Wed, 13 June 2012 06:52 Go to previous messageGo to next message
C Peter is currently offline C PeterFriend
Messages: 6
Registered: May 2012
Junior Member
Hi Martin,

I'll take a look at StoreResource and try to use it,
thanks for your comments.

Best regards,
Claus

Re: Teneo proper save &amp; validate [message #885838 is a reply to message #885263] Wed, 13 June 2012 17:35 Go to previous messageGo to next message
C Peter is currently offline C PeterFriend
Messages: 6
Registered: May 2012
Junior Member
Hello Martin,

I debugged the code when method "doSave" has been preformed in the Editor.
Since I'm using HibernateXMLResource which extends from StoreResource the "save(Map<?, ?> options)" method get called and therefore "validateContents" also, but the OCL contraints are not validated correctly (even if new obejct is created, rather then modified.)

But anyhow, I'll upgrade the next days to Teneo 2.0 and dig deeper into the code.

For now I'm going to watch football "EM2012 NL-DE" and I hope that the netherlands stay further in the tournament^^

Groetjes uit Aken
Claus

[Updated on: Wed, 13 June 2012 17:39]

Report message to a moderator

Re: Teneo proper save &amp; validate [message #889798 is a reply to message #885263] Tue, 19 June 2012 16:55 Go to previous messageGo to next message
C Peter is currently offline C PeterFriend
Messages: 6
Registered: May 2012
Junior Member
Hi Martin,

I switched to Teneo 2.0 as promised but that doesn't resolve my problem.

The clue was to install EMF Validation Framework Very Happy .

I wondering why there are no dependencies from my OCL Plugins to EMF Validation Confused , but anyhow that is not my question.


Now validation takes place on insertion of new objects when

public void doSave(IProgressMonitor progressMonitor)

gets called (in my Editor).

Actually the validation of modified object is still missing.
The method:
org.eclipse.emf.teneo.resource.StoreResource.validate
seems not to add the loaded objects to list of objects to be validated.

	protected void validateContents() throws StoreValidationException {
		// get the changed or new eobjects
		final ArrayList<EObject> newOrChangedObjects = new ArrayList<EObject>(
				newEObjects);
		newOrChangedObjects.addAll(modifiedEObjects);

		log.debug("Validating contents of resource " + uri + " approx. "
				+ newOrChangedObjects.size() + " will be checked");
...


My suggestion is to add the following line:

newOrChangedObjects.addAll(loadedEObjects);



What do you think about it?


Best regards,
Claus



Re: Teneo proper save &amp;amp; validate [message #889821 is a reply to message #889798] Tue, 19 June 2012 19:14 Go to previous messageGo to next message
Martin Taal is currently offline Martin TaalFriend
Messages: 5468
Registered: July 2009
Senior Member
Hi Peter,
The loaded objects are not validated as they are assumed to be correct already, only modified or new objects are validated.

gr. Martin

On 06/19/2012 06:55 PM, C Peter wrote:
> Hi Martin,
>
> I switched to Teneo 2.0 as promised but that doesn't resolve my problem.
>
> The clue was to install EMF Validation Framework :d .
>
> I wondering why there are no dependencies from my OCL Plugins to EMF Validation :? , but anyhow that is not my question.
>
> Now validation takes place on insertion of new objects when
> public void doSave(IProgressMonitor progressMonitor)
>
> gets called (in my Editor).
>
> Actually the validation of modified object is still missing. The method:
> org.eclipse.emf.teneo.resource.StoreResource.validate
> seems not to add the loaded objects to list of objects to be validated.
>
> protected void validateContents() throws StoreValidationException {
> // get the changed or new eobjects
> final ArrayList<EObject> newOrChangedObjects = new ArrayList<EObject>(
> newEObjects);
> newOrChangedObjects.addAll(modifiedEObjects);
>
> log.debug("Validating contents of resource " + uri + " approx. "
> + newOrChangedObjects.size() + " will be checked");
> ...
>
>
> My suggestion is to add the following line:
>
> newOrChangedObjects.addAll(loadedEObjects);
>
>
>
> What do you think about it?
>
>
> Best regards,
> Claus
>
>
>
>


--

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: Teneo proper save &amp;amp; validate [message #889828 is a reply to message #889821] Tue, 19 June 2012 20:12 Go to previous messageGo to next message
C Peter is currently offline C PeterFriend
Messages: 6
Registered: May 2012
Junior Member
Hi Martin,

I've debugged into
StoreResource.validateContents() throws StoreValidationException
.
If I modify an object in the model and fire store - the list
modifiedEObjects
is empty in StoreResource.

The list
loadedEObjects
contains the modified object...

Thx in advance,
Claus
Re: Teneo proper save &amp;amp;amp; validate [message #889835 is a reply to message #889828] Tue, 19 June 2012 20:59 Go to previous messageGo to next message
Martin Taal is currently offline Martin TaalFriend
Messages: 5468
Registered: July 2009
Senior Member
Hi Claus,
Hmm, can you debug somewhere in the change tracking code in the store resource? The object should have been added to the
modifiedobjects list.

gr. Martin

On 06/19/2012 10:12 PM, C Peter wrote:
> Hi Martin,
>
> I've debugged into StoreResource.validateContents() throws StoreValidationException.
> If I modify an object in the model and fire store - the list modifiedEObjects is empty in StoreResource.
>
> The list loadedEObjects contains the modified object...
>
> Thx in advance,
> Claus


--

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: Teneo proper save &amp;amp;amp; validate [message #889870 is a reply to message #889835] Wed, 20 June 2012 05:42 Go to previous message
C Peter is currently offline C PeterFriend
Messages: 6
Registered: May 2012
Junior Member
Hi Martin,

I assumed that
Quote:
The object should have been added to the
modifiedobjects list.


It seems that the call
setTrackingModification(true)
on the HibernateXMLResource has no effect.
I call it right after creation of the HibernateXMLResource.
When save I get another instance of resource and calling "resource.isTrackingModification()" returns false?!
Therefore maybe the list of modifiedObjects is still empty.

I'll take a deeper look at my code at the weekend and report what's going on.


Thanks,
Claus
Previous Topic:[EOL] Delete the default group: Objects ??
Next Topic:[EMFT] Getting started
Goto Forum:
  


Current Time: Fri Mar 29 00:15:57 GMT 2024

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

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

Back to the top