Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » [CDO] Retrieve EstructuralFeature corresponding to InternalCDORevision#getContainingFeatureId()
[CDO] Retrieve EstructuralFeature corresponding to InternalCDORevision#getContainingFeatureId() [message #687581] Wed, 22 June 2011 19:19 Go to next message
kaab  is currently offline kaab Friend
Messages: 43
Registered: July 2009
Member
Hi all,

I need to retrieve the feature corresponding to InternalCDORevision#getContainingFeatureId().
I have tried different methods to retrieve the feature but got unexpected results and so would like to check the correctness of my current approach.

Initially, I was trying to retrieve the feature as shown in the code below, before noticing that the feature returned differed from the expected result, expected result is to retrieve the feature equivalent to calling the eObject.eContainingFeature() with eObject being the EObject representing the CDORevision revision.

final int containingFeatureID = revision.getContainingFeatureID() < 0 ? InternalEObject.EOPPOSITE_FEATURE_BASE - revision.getContainingFeatureID() : revision.getContainingFeatureID();
InternalCDORevision parent = retrieveRevisionById((CDOID)revision.getContainerID());
feature = parent.getEClass().getEStructuralFeature(containingFeatureID);


I noticed that the feature returned would always be the EOpposite of the expected result (when its an EReference with an EOpposite), so my question is whether it would be correct to assume that the expected return value would always be the EOpposite if the feature retrieved is an EReference and has an EOpposite ?
Is there any further conditions that I am not aware of in order to correctly retrieve this feature ?

Thanks a lot,

Abdel

Re: [CDO] Retrieve EstructuralFeature corresponding to InternalCDORevision#getContainingFeatureId() [message #687794 is a reply to message #687581] Thu, 23 June 2011 08:50 Go to previous messageGo to next message
Eike Stepper is currently offline Eike StepperFriend
Messages: 6682
Registered: July 2009
Senior Member
Hi Abdel,

CDORevision.getContainingFeatureID() returns the id of the feature in the containing object that's actually used to point to the contained object. Is that the answer you've expected?

Cheers
/Eike

----
http://www.esc-net.de
http://thegordian.blogspot.com
http://twitter.com/eikestepper



Am 22.06.2011 21:19, schrieb kaab:
> Hi all,
>
> I need to retrieve the feature corresponding to InternalCDORevision#getContainingFeatureId().
> I have tried different methods to retrieve the feature but got unexpected results and so would like to check the correctness of my current approach.
>
> Initially, I was trying to retrieve the feature as shown in the code below, before noticing that the feature returned differed from the expected result, expected result is to retrieve the feature equivalent to calling the eObject.eContainingFeature() with eObject being the EObject representing the CDORevision revision.
>
>
> final int containingFeatureID = revision.getContainingFeatureID() < 0 ? InternalEObject.EOPPOSITE_FEATURE_BASE - revision.getContainingFeatureID() : revision.getContainingFeatureID();
> InternalCDORevision parent = retrieveRevisionById((CDOID)revision.getContainerID());
> feature = parent.getEClass().getEStructuralFeature(containingFeatureID);
>
>
> I noticed that the feature returned would always be the EOpposite of the expected result (when its an EReference with an EOpposite), so my question is whether it would be correct to assume that the expected return value would always be the EOpposite if the feature retrieved is an EReference and has an EOpposite ?
> Is there any further conditions that I am not aware of in order to correctly retrieve this feature ?
>
> Thanks a lot,
>
> Abdel
>
>


Re: [CDO] Retrieve EstructuralFeature corresponding to InternalCDORevision#getContainingFeatureId() [message #688064 is a reply to message #687794] Thu, 23 June 2011 20:02 Go to previous messageGo to next message
kaab  is currently offline kaab Friend
Messages: 43
Registered: July 2009
Member
Hi Eike,

After your response I have tried to write a unit test to show what I meant.

Given that the definition provided above seem equivalent to the return value of eContainingFeature from EObject interface (Returns the particular feature of the container that actually holds the object or null if there is no container) and is also the expected result I was refering to in my original post, I have written a unit test to compare the returned value for an EObject on client side and for a cdo revision on server side.

After making some more tests on other models, I can see that you definition also corresponds to the behaviour of cdo in most cases, while I was writing the unit test I realized that the issue might be related to the model used, so I tried to trim the model to a minimum in order to show what I meant.

I attached an ecore model to this post and I am providing you with my unit test, in order to reproduce what I now believe is an issue.

The return index for getContainingFeatureID on CDORevision returns the EOppossite of the feature used to refer to the CallableUnit.

So the expected value is the codeElement Structural Feature, but the returned value is module (which is its EOpposite). I have tested this on a new workspace by regenerating the model code for the ecore model provided, we use CDO version 3.0.

Please review and let me know what you think,

I'm also wondering under which conditions the returned value for the call to CDORevision#getContainingFeatureID() will be negative and how to treat it when it's the case.

Thanks a lot,

import org.eclipse.emf.cdo.common.id.CDOID;
import org.eclipse.emf.cdo.common.revision.CDORevision;
import org.eclipse.emf.cdo.common.util.CDOQueryInfo;
import org.eclipse.emf.cdo.eresource.CDOResource;
import org.eclipse.emf.cdo.internal.server.mem.MEMStore;
import org.eclipse.emf.cdo.net4j.CDONet4jUtil;
import org.eclipse.emf.cdo.net4j.CDOSessionConfiguration;
import org.eclipse.emf.cdo.server.CDOServerUtil;
import org.eclipse.emf.cdo.server.IQueryContext;
import org.eclipse.emf.cdo.server.IQueryHandler;
import org.eclipse.emf.cdo.server.IRepository;
import org.eclipse.emf.cdo.server.IStore;
import org.eclipse.emf.cdo.server.net4j.CDONet4jServerUtil;
import org.eclipse.emf.cdo.session.CDOSession;
import org.eclipse.emf.cdo.spi.common.revision.InternalCDORevision;
import org.eclipse.emf.cdo.spi.server.QueryHandlerFactory;
import org.eclipse.emf.cdo.transaction.CDOTransaction;
import org.eclipse.emf.cdo.util.CDOUtil;
import org.eclipse.emf.cdo.util.CommitException;
import org.eclipse.emf.cdo.view.CDOQuery;
import org.eclipse.emf.cdo.view.CDOView;
import org.eclipse.emf.ecore.EStructuralFeature;
import org.eclipse.net4j.Net4jUtil;
import org.eclipse.net4j.connector.IConnector;
import org.eclipse.net4j.internal.util.container.PluginContainer;
import org.eclipse.net4j.jvm.IJVMAcceptor;
import org.eclipse.net4j.jvm.IJVMConnector;
import org.eclipse.net4j.jvm.JVMUtil;
import org.eclipse.net4j.util.container.IManagedContainer;
import org.junit.BeforeClass;
import org.junit.Test;


public class TestContainingEFeatureCDO {
	private static CDOSession session = null;
	
	private static String queryLanguage = "eContainingFeature";
	
	private static final String QUERY_CONTEXT = "context";
	
	private static final String REPOSITORY_NAME = "repo1";

	@BeforeClass
	public static void prepareTest(){
		final IManagedContainer container = PluginContainer.getInstance();
		Net4jUtil.prepareContainer(container); // Prepare the Net4j kernel
		JVMUtil.prepareContainer(container); // Prepare the JVM transport
		CDONet4jServerUtil.prepareContainer(container); // Prepare the CDO
		// server
		CDONet4jUtil.prepareContainer(container); // Prepare the CDO client
		container.activate();
		container.putElement(QueryHandlerFactory.PRODUCT_GROUP,queryLanguage, null, new EContainingFeatureHandler());

		IJVMAcceptor acceptor = JVMUtil.getAcceptor(container, "default"); // Start the
		final IRepository repo = createRepository();

		CDOServerUtil.addRepository(container, repo); // Start a CDO
		IJVMConnector connector = JVMUtil.getConnector(container, "default"); // Open
		session = openSession(connector);// Open a CDO session
	}
	
	private static CDOSession openSession(IConnector connector2) {
		final CDOSessionConfiguration configuration = CDONet4jUtil.createSessionConfiguration();
		configuration.setConnector(connector2);
		configuration.setRepositoryName(REPOSITORY_NAME);
		return configuration.openSession();
	}

	private static IRepository createRepository() {
		final Map<String, String> props = new HashMap<String, String>();
		IRepository repository = CDOServerUtil.createRepository(REPOSITORY_NAME, createMemStore(), props);
		return repository;
	}
	
	private static IStore createMemStore() {
		return new MEMStore();
	}
	
	static class EContainingFeatureHandler implements IQueryHandler{

		@Override
		public void executeQuery(CDOQueryInfo info, IQueryContext context) {
			final IStore store = context.getView().getRepository().getStore();
			final Map<String, Object> params = info.getParameters();

			final CDOID queryContext = (CDOID)params.get(QUERY_CONTEXT);
			final InternalCDORevision revision = (InternalCDORevision)store.getRepository().getRevisionManager()
					.getRevision(queryContext, context, CDORevision.UNCHUNKED, CDORevision.DEPTH_NONE, true);
			int containingFeatureId = revision.getContainingFeatureID();
			CDOID containerID = (CDOID)revision.getContainerID();
			final InternalCDORevision container = (InternalCDORevision)store.getRepository().getRevisionManager()
					.getRevision(containerID, context, CDORevision.UNCHUNKED, CDORevision.DEPTH_NONE, true);
			EStructuralFeature feature = container.getEClass().getEStructuralFeature(containingFeatureId);
			System.out.println(feature.getName());
			context.addResult(feature.getName());
		}
	}

	@Test
	public void testContainingFeature() throws CommitException {
		CompilationUnit compUnit = CodeFactory.eINSTANCE.createCompilationUnit();
		CallableUnit cu = CodeFactory.eINSTANCE.createCallableUnit();
		compUnit.getCodeElement().add(cu);
		CDOTransaction trans = session.openTransaction(); 
		CDOResource resource = trans.getOrCreateResource("testRez");
		resource.getContents().add(compUnit);
		trans.commit();
		EStructuralFeature feature = cu.eContainingFeature();
		CDOView view = session.openView(); 
		CDOQuery query = view.createQuery(queryLanguage, "");
		query.setParameter(QUERY_CONTEXT, CDOUtil.getCDOObject(cu).cdoID());
		List<String> results = query.getResult(String.class);
		assertEquals(1, results.size());
		assertEquals(feature.getName(), results.get(0));
	}
}

Re: [CDO] Retrieve EstructuralFeature corresponding to InternalCDORevision#getContainingFeatureId() [message #688178 is a reply to message #688064] Fri, 24 June 2011 05:08 Go to previous messageGo to next message
Eike Stepper is currently offline Eike StepperFriend
Messages: 6682
Registered: July 2009
Senior Member
Hi Kaab,

I want to use the test code you've provided but I can't do it right now. Can you please open a proper bugzilla for your problem and attach all relevant files?

Cheers
/Eike

----
http://www.esc-net.de
http://thegordian.blogspot.com
http://twitter.com/eikestepper



Am 23.06.2011 22:02, schrieb kaab:
> Hi Eike,
>
> After your response I have tried to write a unit test to show what I meant.
>
> Given that the definition provided above seem equivalent to the return value of eContainingFeature from EObject interface (Returns the particular feature of the container that actually holds the object or null if there is no container) and is also the expected result I was refering to in my original post, I have written a unit test to compare the returned value for an EObject on client side and for a cdo revision on server side.
>
> After making some more tests on other models, I can see that you definition also corresponds to the behaviour of cdo in most cases, while I was writing the unit test I realized that the issue might be related to the model used, so I tried to trim the model to a minimum in order to show what I meant.
>
> I attached an ecore model to this post and I am providing you with my unit test, in order to reproduce what I now believe is an issue.
>
> The return index for getContainingFeatureID on CDORevision returns the EOppossite of the feature used to refer to the CallableUnit.
>
> So the expected value is the codeElement Structural Feature, but the returned value is module (which is its EOpposite). I have tested this on a new workspace by regenerating the model code for the ecore model provided, we use CDO version 3.0.
>
> Please review and let me know what you think,
>
> I'm also wondering under which conditions the returned value for the call to CDORevision#getContainingFeatureID() will be negative and how to treat it when it's the case.
>
> Thanks a lot,
>
>
> import org.eclipse.emf.cdo.common.id.CDOID;
> import org.eclipse.emf.cdo.common.revision.CDORevision;
> import org.eclipse.emf.cdo.common.util.CDOQueryInfo;
> import org.eclipse.emf.cdo.eresource.CDOResource;
> import org.eclipse.emf.cdo.internal.server.mem.MEMStore;
> import org.eclipse.emf.cdo.net4j.CDONet4jUtil;
> import org.eclipse.emf.cdo.net4j.CDOSessionConfiguration;
> import org.eclipse.emf.cdo.server.CDOServerUtil;
> import org.eclipse.emf.cdo.server.IQueryContext;
> import org.eclipse.emf.cdo.server.IQueryHandler;
> import org.eclipse.emf.cdo.server.IRepository;
> import org.eclipse.emf.cdo.server.IStore;
> import org.eclipse.emf.cdo.server.net4j.CDONet4jServerUtil;
> import org.eclipse.emf.cdo.session.CDOSession;
> import org.eclipse.emf.cdo.spi.common.revision.InternalCDORevision;
> import org.eclipse.emf.cdo.spi.server.QueryHandlerFactory;
> import org.eclipse.emf.cdo.transaction.CDOTransaction;
> import org.eclipse.emf.cdo.util.CDOUtil;
> import org.eclipse.emf.cdo.util.CommitException;
> import org.eclipse.emf.cdo.view.CDOQuery;
> import org.eclipse.emf.cdo.view.CDOView;
> import org.eclipse.emf.ecore.EStructuralFeature;
> import org.eclipse.net4j.Net4jUtil;
> import org.eclipse.net4j.connector.IConnector;
> import org.eclipse.net4j.internal.util.container.PluginContainer;
> import org.eclipse.net4j.jvm.IJVMAcceptor;
> import org.eclipse.net4j.jvm.IJVMConnector;
> import org.eclipse.net4j.jvm.JVMUtil;
> import org.eclipse.net4j.util.container.IManagedContainer;
> import org.junit.BeforeClass;
> import org.junit.Test;
>
>
> public class TestContainingEFeatureCDO {
> private static CDOSession session = null;
>
> private static String queryLanguage = "eContainingFeature";
>
> private static final String QUERY_CONTEXT = "context";
>
> private static final String REPOSITORY_NAME = "repo1";
>
> @BeforeClass
> public static void prepareTest(){
> final IManagedContainer container = PluginContainer.getInstance();
> Net4jUtil.prepareContainer(container); // Prepare the Net4j kernel
> JVMUtil.prepareContainer(container); // Prepare the JVM transport
> CDONet4jServerUtil.prepareContainer(container); // Prepare the CDO
> // server
> CDONet4jUtil.prepareContainer(container); // Prepare the CDO client
> container.activate();
> container.putElement(QueryHandlerFactory.PRODUCT_GROUP,queryLanguage, null, new EContainingFeatureHandler());
>
> IJVMAcceptor acceptor = JVMUtil.getAcceptor(container, "default"); // Start the
> final IRepository repo = createRepository();
>
> CDOServerUtil.addRepository(container, repo); // Start a CDO
> IJVMConnector connector = JVMUtil.getConnector(container, "default"); // Open
> session = openSession(connector);// Open a CDO session
> }
>
> private static CDOSession openSession(IConnector connector2) {
> final CDOSessionConfiguration configuration = CDONet4jUtil.createSessionConfiguration();
> configuration.setConnector(connector2);
> configuration.setRepositoryName(REPOSITORY_NAME);
> return configuration.openSession();
> }
>
> private static IRepository createRepository() {
> final Map<String, String> props = new HashMap<String, String>();
> IRepository repository = CDOServerUtil.createRepository(REPOSITORY_NAME, createMemStore(), props);
> return repository;
> }
>
> private static IStore createMemStore() {
> return new MEMStore();
> }
>
> static class EContainingFeatureHandler implements IQueryHandler{
>
> @Override
> public void executeQuery(CDOQueryInfo info, IQueryContext context) {
> final IStore store = context.getView().getRepository().getStore();
> final Map<String, Object> params = info.getParameters();
>
> final CDOID queryContext = (CDOID)params.get(QUERY_CONTEXT);
> final InternalCDORevision revision = (InternalCDORevision)store.getRepository().getRevisionManager()
> .getRevision(queryContext, context, CDORevision.UNCHUNKED, CDORevision.DEPTH_NONE, true);
> int containingFeatureId = revision.getContainingFeatureID();
> CDOID containerID = (CDOID)revision.getContainerID();
> final InternalCDORevision container = (InternalCDORevision)store.getRepository().getRevisionManager()
> .getRevision(containerID, context, CDORevision.UNCHUNKED, CDORevision.DEPTH_NONE, true);
> EStructuralFeature feature = container.getEClass().getEStructuralFeature(containingFeatureId);
> System.out.println(feature.getName());
> context.addResult(feature.getName());
> }
> }
>
> @Test
> public void testContainingFeature() throws CommitException {
> CompilationUnit compUnit = CodeFactory.eINSTANCE.createCompilationUnit();
> CallableUnit cu = CodeFactory.eINSTANCE.createCallableUnit();
> compUnit.getCodeElement().add(cu);
> CDOTransaction trans = session.openTransaction();
> CDOResource resource = trans.getOrCreateResource("testRez");
> resource.getContents().add(compUnit);
> trans.commit();
> EStructuralFeature feature = cu.eContainingFeature();
> CDOView view = session.openView();
> CDOQuery query = view.createQuery(queryLanguage, "");
> query.setParameter(QUERY_CONTEXT, CDOUtil.getCDOObject(cu).cdoID());
> List<String> results = query.getResult(String.class);
> assertEquals(1, results.size());
> assertEquals(feature.getName(), results.get(0));
> }
> }
>
>


Re: [CDO] Retrieve EstructuralFeature corresponding to InternalCDORevision#getContainingFeatureId() [message #689360 is a reply to message #688178] Mon, 27 June 2011 13:52 Go to previous messageGo to next message
kaab  is currently offline kaab Friend
Messages: 43
Registered: July 2009
Member
Bugzilla opened at :
https://bugs.eclipse.org/bugs/show_bug.cgi?id=350447

Waiting for your feedback,

Thanks
Re: [CDO] Retrieve EstructuralFeature corresponding to InternalCDORevision#getContainingFeatureId() [message #689387 is a reply to message #689360] Mon, 27 June 2011 14:44 Go to previous message
Eike Stepper is currently offline Eike StepperFriend
Messages: 6682
Registered: July 2009
Senior Member
Am 27.06.2011 15:52, schrieb kaab:
> Bugzilla opened at :
> https://bugs.eclipse.org/bugs/show_bug.cgi?id=350447
>
> Waiting for your feedback,
Due to the release and follow-up work I have a backlog of 108 Bugzillas now ;-(

Cheers
/Eike

----
http://www.esc-net.de
http://thegordian.blogspot.com
http://twitter.com/eikestepper


Previous Topic:(no subject)
Next Topic:EcoreUtil.copy and String attributes
Goto Forum:
  


Current Time: Thu Apr 25 19:50:50 GMT 2024

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

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

Back to the top