Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » [teneo] drag and drop in resources
[teneo] drag and drop in resources [message #505823] Tue, 05 January 2010 04:43 Go to next message
Allon Moritz is currently offline Allon MoritzFriend
Messages: 38
Registered: July 2009
Member
according to the cut and past article at elver.org there is no way to implement drag and drop when I work with resources?
I tried to set the parameter CASCADE_POLICY_ON_CONTAINMENT
props.setProperty("CASCADE_POLICY_ON_CONTAINMENT",
				"REMOVE,REFRESH,PERSIST,MERGE");

but when I execute the following code
Product product = ShopFactory.eINSTANCE.createProduct();
		product.setName("testProduct");
		product.setNumber(1);

		ProductCategory root = ShopFactory.eINSTANCE.createProductCategory();
		root.setName("root");
		getProductsResource().getContents().add(root);
		saveResources();

		ProductCategory node1 = ShopFactory.eINSTANCE.createProductCategory();
		node1.setName("node1");
		root.getSubCategorys().add(node1);
		node1.getProducts().add(product);
		saveResources();

		ProductCategory node2 = ShopFactory.eINSTANCE.createProductCategory();
		node2.setName("node2");
		root.getSubCategorys().add(node2);
		saveResources();
		product.setProductCategory(node2);
		saveResources();

I get the following exception
Quote:

org.hibernate.ObjectDeletedException: deleted object would be re-saved by cascade (remove deleted object from associations): [Product#32768]
............

Re: [teneo] drag and drop in resources [message #505907 is a reply to message #505823] Tue, 05 January 2010 14:42 Go to previous messageGo to next message
Martin Taal is currently offline Martin TaalFriend
Messages: 5468
Registered: July 2009
Senior Member
Hi Allon,
Yes, correct not with containment relations. One other solution is to copy the object when dropping it.

Regarding your exception, in an email to you on the 13th of December I also discuss this exception and why it occurs.
See below for a snippet. Did my email make sense?

email snippet>>>>

1) object is re-saved exception
The issue is fairly complex....

When an object is saved through hibernate then hibernate creates its own list implementations. Teneo stores these list
implementations in an adapter (when you debug you can see them in the adapters list of the EObject). Teneo uses the
notification framework to keep the hibernate list in sync with the EMF list (see the PersistenceStoreAdapter).
Removing node1 from root results in two notifications which are sent as a chain. The first notification is the set to
null of the parent (so node1.parent), the second is the remove from node1 from root.subCategorys.
You execute the save action in the notify changed. This is done before the hibernate list has been synced with the EMF
list. So when saving the resource, the HibernateResource will remove the node1 explicitly, but the hibernate list is not
yet synced so it will still seem to hibernate that node1 is still being used.
The reason that the save occurs before the hibernate list has been synced is that the save action takes place for the
notification that the parent is set to null and not when the list has already been synced.

I tried a quick solution by checking in your ResourceSaver.notifyChanged method if the efeature is a container
reference. If so nothing is done (as the notification from the container itself will also be received). See the attached
diff.

This prevented the 'object will be re-saved' exception.

However, I am not sure if it is a good idea to do saving inside of the notify changed method. This method is called many
times. I would go for an approach were you set a flag that something has changed and then later in the process you do
the save. For example in the web application world you have so called request filters. These filters are always called
at the end of a request, in a web application that is were the save/commit/rollback can be done. Maybe you have the same
type of main thread handler in your application also.

gr. Martin

Allon Moritz wrote:
> according to the
> http://www.elver.org/hibernate/hibernate_details.html#cutpas te there is
> no way to implement drag and drop when I work with resources?
> I tried to set the parameter CASCADE_POLICY_ON_CONTAINMENT
>
> props.setProperty("CASCADE_POLICY_ON_CONTAINMENT",
> "REMOVE,REFRESH,PERSIST,MERGE");
>
> but when I execute the following code
>
> Product product = ShopFactory.eINSTANCE.createProduct();
> product.setName("testProduct");
> product.setNumber(1);
>
> ProductCategory root =
> ShopFactory.eINSTANCE.createProductCategory();
> root.setName("root");
> getProductsResource().getContents().add(root);
> saveResources();
>
> ProductCategory node1 =
> ShopFactory.eINSTANCE.createProductCategory();
> node1.setName("node1");
> root.getSubCategorys().add(node1);
> node1.getProducts().add(product);
> saveResources();
>
> ProductCategory node2 =
> ShopFactory.eINSTANCE.createProductCategory();
> node2.setName("node2");
> root.getSubCategorys().add(node2);
> saveResources();
> product.setProductCategory(node2);
> saveResources();
>
> I get the following exception
> Quote:
>> org.hibernate.ObjectDeletedException: deleted object would be re-saved
>> by cascade (remove deleted object from associations): [Product#32768]
>> ............
>


--

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
Re: [teneo] drag and drop in resources [message #505913 is a reply to message #505907] Tue, 05 January 2010 14:57 Go to previous messageGo to next message
Allon Moritz is currently offline Allon MoritzFriend
Messages: 38
Registered: July 2009
Member
the problem fro the 13. december is solved with your build M200912130725.

this is a new problem ( I want to implement drag and drop in my RCP app). probably a stupid question but when I copy an element, I need that the references to the old object are pointing to the new one, is teneo/emf supporting this functionality? I assume not. so what is the way to go, to copy an element and update all references to the copied element??

thanks for the help
Re: [teneo] drag and drop in resources [message #505927 is a reply to message #505913] Tue, 05 January 2010 15:05 Go to previous messageGo to next message
Martin Taal is currently offline Martin TaalFriend
Messages: 5468
Registered: July 2009
Senior Member
Hi Allon,
The 13th december build does not solve this issue as it requires changes in your code afaics (correct me if I am wrong),
at least that is what I proposed in my email.

Setting this property:
props.setProperty("CASCADE_POLICY_ON_CONTAINMENT",
"REMOVE,REFRESH,PERSIST,MERGE");

should make it possible to do cut/copy-paste. In combination with resources this works fine as resources take care of
removing objects which are removed from containment relations (so hibernate does not need to do that).

You can check the hibernate mapping to see if the ProductCategory.products association is mapped with delete-orphan (it
should not).

gr. Martin

Allon Moritz wrote:
> the problem fro the 13. december is solved with your build M200912130725.
>
> this is a new problem ( I want to implement drag and drop in my RCP
> app). probably a stupid question but when I copy an element, I need that
> the references to the old object are pointing to the new one, is
> teneo/emf supporting this functionality? I assume not. so what is the
> way to go, to copy an element and update all references to the copied
> element??
>
> thanks for the help


--

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
Re: [teneo] drag and drop in resources [message #505934 is a reply to message #505927] Tue, 05 January 2010 15:26 Go to previous messageGo to next message
Allon Moritz is currently offline Allon MoritzFriend
Messages: 38
Registered: July 2009
Member
Quote:
The 13th december build does not solve this issue as it requires changes in your code afaics (correct me if I am wrong),
at least that is what I proposed in my email.

I did that as well and it works as expected.

how can I check the hibernate mapping of ProductCategory.products??

I wrote you an email with a test case.....I'm looking forward where the problem is..... Laughing
Re: [teneo] drag and drop in resources [message #505943 is a reply to message #505934] Tue, 05 January 2010 15:29 Go to previous messageGo to next message
Martin Taal is currently offline Martin TaalFriend
Messages: 5468
Registered: July 2009
Senior Member
Yes, seen your email! I will check it when I can (maybe today, maybe tomorrow...).

You can call getMappingXML on the datastore (after initialing it) to see the hibernate mapping. Let me know if the
orphan-delete is still there because if so then that's the problem and I don't need to check your testcase :-).

gr. Martin

Allon Moritz wrote:
> Quote:
>> The 13th december build does not solve this issue as it requires
>> changes in your code afaics (correct me if I am wrong),
>> at least that is what I proposed in my email.
>
> I did that as well and it works as expected.
>
> how can I check the hibernate mapping of ProductCategory.products??
>
> I wrote you an email with a test case.....I'm looking forward where the
> problem is..... :lol:


--

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
Re: [teneo] drag and drop in resources [message #505948 is a reply to message #505943] Tue, 05 January 2010 15:45 Go to previous messageGo to next message
Allon Moritz is currently offline Allon MoritzFriend
Messages: 38
Registered: July 2009
Member
I think it's still there
<list name="products" lazy="true" cascade="all,delete-orphan">
			<key update="true">
				<column name="`product_productcategory_e_id`" not-null="false" unique="false"/>
			</key>
			<list-index column="`productcategory_products_idx`"/>
			<one-to-many entity-name="Product"/>
		</list>


how can I change this??
Re: [teneo] drag and drop in resources [message #505959 is a reply to message #505948] Tue, 05 January 2010 16:15 Go to previous messageGo to next message
Martin Taal is currently offline Martin TaalFriend
Messages: 5468
Registered: July 2009
Senior Member
Hi Allon,
It took me a while but it seems that you use the wrong property name, you do:
props.setProperty("CASCADE_POLICY_ON_CONTAINMENT",
"REMOVE,REFRESH,PERSIST,MERGE");

while you should do:
props.setProperty(PersistenceOptions.CASCADE_POLICY_ON_CONTA INMENT,
"REMOVE,REFRESH,PERSIST,MERGE");

It would be nice if Teneo gave a warning but hibernate and teneo options are combined in one property set so that's why
this is not done (cause an option which is not a teneo option can be a hibernate or other driver option).

gr. Martin

Allon Moritz wrote:
> I think it's still there
>
> <list name="products" lazy="true" cascade="all,delete-orphan">
> <key update="true">
> <column name="`product_productcategory_e_id`"
> not-null="false" unique="false"/>
> </key>
> <list-index column="`productcategory_products_idx`"/>
> <one-to-many entity-name="Product"/>
> </list>
>
>
> how can I change this??


--

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
Re: [teneo] drag and drop in resources [message #506022 is a reply to message #505959] Tue, 05 January 2010 19:07 Go to previous messageGo to next message
Allon Moritz is currently offline Allon MoritzFriend
Messages: 38
Registered: July 2009
Member
that was it!!!!!
Re: [teneo] drag and drop in resources [message #506023 is a reply to message #506022] Tue, 05 January 2010 19:11 Go to previous messageGo to next message
Allon Moritz is currently offline Allon MoritzFriend
Messages: 38
Registered: July 2009
Member
if somebody is interested for the jface code here is it
		int ops = DND.DROP_COPY | DND.DROP_MOVE;
		Transfer[] transfers = new Transfer[] { TextTransfer.getInstance() };
		tree.getViewer().addDragSupport(ops, transfers,
				new ViewerDragAdapter(tree.getViewer()) {
					@Override
					public void dragSetData(DragSourceEvent event) {
						event.data = String.class.getName(); //any string!!
					}
				});

		tree.getViewer().addDropSupport(ops, transfers,
				new ViewerDropAdapter(tree.getViewer()) {

					@Override
					public boolean validateDrop(Object target, int operation,
							TransferData transferType) {
						return target instanceof ProductCategory;
					}

					@SuppressWarnings("unchecked")
					@Override
					public boolean performDrop(final Object data) {
						IStructuredSelection selection = (IStructuredSelection) tree
								.getViewer().getSelection();
						List selectedObjects = selection.toList();
								for (Object obj : selectedObjects) {
									if (obj instanceof ProductCategory)
										((ProductCategory) obj)
												.setParent((ProductCategory) getCurrentTarget());
									if (obj instanceof Product)
										((Product) obj)
												.setProductCategory((ProductCategory) getCurrentTarget());
								}
						return true;
					}
				});

[Updated on: Tue, 05 January 2010 19:12]

Report message to a moderator

Re: [teneo] drag and drop in resources [message #506038 is a reply to message #506023] Tue, 05 January 2010 20:07 Go to previous message
Martin Taal is currently offline Martin TaalFriend
Messages: 5468
Registered: July 2009
Senior Member
Thanks Allon!

gr. Martin

Allon Moritz wrote:
> if somebody is interested in the jface code here is it
>
> int ops = DND.DROP_COPY | DND.DROP_MOVE;
> Transfer[] transfers = new Transfer[] {
> TextTransfer.getInstance() };
> tree.getViewer().addDragSupport(ops, transfers,
> new ViewerDragAdapter(tree.getViewer()) {
> @Override
> public void dragSetData(DragSourceEvent event) {
> event.data = String.class.getName(); //any string!!
> }
> });
>
> tree.getViewer().addDropSupport(ops, transfers,
> new ViewerDropAdapter(tree.getViewer()) {
>
> @Override
> public boolean validateDrop(Object target, int
> operation,
> TransferData transferType) {
> return target instanceof ProductCategory;
> }
>
> @SuppressWarnings("unchecked")
> @Override
> public boolean performDrop(final Object data) {
> IStructuredSelection selection =
> (IStructuredSelection) tree
> .getViewer().getSelection();
> List selectedObjects = selection.toList();
> for (Object obj : selectedObjects) {
> if (obj instanceof ProductCategory)
> ((ProductCategory) obj)
>
> .setParent((ProductCategory) getCurrentTarget());
> if (obj instanceof Product)
> ((Product) obj)
>
> .setProductCategory((ProductCategory) getCurrentTarget());
> }
> return true;
> }
> });
>


--

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
Previous Topic:[EMF databinding] Problems with EMFMapProperty
Next Topic:EMF throws an IllegalValueException
Goto Forum:
  


Current Time: Tue Dec 10 13:18:34 GMT 2019

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

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

Back to the top