Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » CDO: Problem with dynamic model
CDO: Problem with dynamic model [message #422948] Fri, 19 September 2008 13:39 Go to next message
Roger Stocker is currently offline Roger StockerFriend
Messages: 16
Registered: July 2009
Junior Member
Hi

I have a problem when trying to persist dynamic model instances.

Here is my code snippet:

CDOSession session = configuration.openSession();

EClass pClass = EcoreFactory.eINSTANCE.createEClass();
pClass.setName("DynPerson");

EAttribute attribute = EcoreFactory.eINSTANCE.createEAttribute();
attribute.setName("firstName");
attribute.setEType(EcorePackage.eINSTANCE.getEString());
pClass.getEStructuralFeatures().add(attribute);

EPackage package1 = EcoreFactory.eINSTANCE.createEPackage();
package1.setName("DynPeople");
package1.setNsPrefix("ch.mycom");
package1.setNsURI("http://my-com.ch/DynPeople");
package1.getEClassifiers().add(pClass);
EPackage.Registry.INSTANCE.put(package1.getNsURI(), package1);

session.getPackageRegistry().putEPackage(package1);

// Open transaction
CDOTransaction transaction = session.openTransaction();

transaction.setChangeSubscriptionPolicy(CDOChangeSubscriptio nPolicy.ALL);

CDOResource resource = transaction.createResource("/Test");

EObject person = package1.getEFactoryInstance().create(pClass);
EStructuralFeature feature = pClass.getEStructuralFeature("firstName");
person.eSet(feature, "Peter");

try {
resource.getContents().add(person);
} catch(Throwable t) {
t.printStackTrace();
}

transaction.commit();


In the line resource.getContents().add(person); I get this exception:


java.lang.ArrayIndexOutOfBoundsException: -1
at java.util.ArrayList.set(Unknown Source)
at
org.eclipse.emf.cdo.internal.common.model.CDOClassImpl.setIn dex(CDOClassImpl.java:365)
at
org.eclipse.emf.cdo.internal.common.model.CDOClassImpl.getFe atureIndex(CDOClassImpl.java:292)
at
org.eclipse.emf.cdo.internal.common.model.CDOClassImpl.looku pFeature(CDOClassImpl.java:234)
at
org.eclipse.emf.internal.cdo.util.ModelUtil.getCDOFeature(Mo delUtil.java:166)
at
org.eclipse.emf.internal.cdo.CDOObjectImpl.populateRevisionF eature(CDOObjectImpl.java:247)
at
org.eclipse.emf.internal.cdo.CDOObjectImpl.cdoInternalPostAt tach(CDOObjectImpl.java:230)
at
org.eclipse.emf.internal.cdo.CDOStateMachine$AttachTransitio n.execute(CDOStateMachine.java:446)
at
org.eclipse.emf.internal.cdo.CDOStateMachine$AttachTransitio n.execute(CDOStateMachine.java:1)
at
org.eclipse.net4j.util.fsm.FiniteStateMachine.process(Finite StateMachine.java:161)
at
org.eclipse.emf.internal.cdo.CDOStateMachine.attach2(CDOStat eMachine.java:186)
at
org.eclipse.emf.internal.cdo.CDOStateMachine.attach(CDOState Machine.java:159)
at
org.eclipse.emf.cdo.eresource.impl.CDOResourceImpl.attached( CDOResourceImpl.java:434)
at
org.eclipse.emf.cdo.eresource.impl.CDOResourceImpl$Persisten tContents.inverseAdd(CDOResourceImpl.java:559)
at
org.eclipse.emf.common.notify.impl.DelegatingNotifyingListIm pl.addUnique(DelegatingNotifyingListImpl.java:310)
at
org.eclipse.emf.common.util.DelegatingEList.add(DelegatingEL ist.java:499)
at ch.mycom.proto.repository.Activator.start(Activator.java:61)
at
org.eclipse.osgi.framework.internal.core.BundleContextImpl$2 .run(BundleContextImpl.java:1009)
at java.security.AccessController.doPrivileged(Native Method)
at
org.eclipse.osgi.framework.internal.core.BundleContextImpl.s tartActivator(BundleContextImpl.java:1003)
at
org.eclipse.osgi.framework.internal.core.BundleContextImpl.s tart(BundleContextImpl.java:984)
at
org.eclipse.osgi.framework.internal.core.BundleHost.startWor ker(BundleHost.java:346)
at
org.eclipse.osgi.framework.internal.core.AbstractBundle.resu me(AbstractBundle.java:355)
at
org.eclipse.osgi.framework.internal.core.Framework.resumeBun dle(Framework.java:1074)
at
org.eclipse.osgi.framework.internal.core.StartLevelManager.r esumeBundles(StartLevelManager.java:616)
at
org.eclipse.osgi.framework.internal.core.StartLevelManager.i ncFWSL(StartLevelManager.java:508)
at
org.eclipse.osgi.framework.internal.core.StartLevelManager.d oSetStartLevel(StartLevelManager.java:299)
at
org.eclipse.osgi.framework.internal.core.StartLevelManager.d ispatchEvent(StartLevelManager.java:489)
at
org.eclipse.osgi.framework.eventmgr.EventManager.dispatchEve nt(EventManager.java:211)
at
org.eclipse.osgi.framework.eventmgr.EventManager$EventThread .run(EventManager.java:321)


The problem is, that the dynamically created EAttribute has no featureId
(-1).

Start Level Event Dispatcher [debug.model] Created
CDOPackage(URI=http://my-com.ch/DynPeople, name=DynPeople, dynamic=true,
metaIDRange=[mid1:mid4], parentURI=null)
Start Level Event Dispatcher [debug.model] Setting client info:
CDOPackage(URI=http://my-com.ch/DynPeople, name=DynPeople, dynamic=true,
metaIDRange=[mid1:mid4], parentURI=null) -->
org.eclipse.emf.ecore.impl.EPackageImpl@1b258fa (name: DynPeople) (nsURI:
http://my-com.ch/DynPeople, nsPrefix: ch.mycom)
Start Level Event Dispatcher [debug.model] Created CDOClass(ID=0,
name=DynPerson)
Start Level Event Dispatcher [debug.model] Setting client info:
CDOClass(ID=0, name=DynPerson) -->
org.eclipse.emf.ecore.impl.EClassImpl@1efb003 (name: DynPerson)
(instanceClassName: null) (abstract: false, interface: false)
Start Level Event Dispatcher [debug.model] Created CDOFeature(ID=-1,
name=firstName, type=STRING)
Start Level Event Dispatcher [debug.model] Setting client info:
CDOFeature(ID=-1, name=firstName, type=STRING) -->
org.eclipse.emf.ecore.impl.EAttributeImpl@10cc730 (name: firstName)
(ordered: true, unique: true, lowerBound: 0, upperBound: 1) (changeable:
true, volatile: false, transient: false, defaultValueLiteral: null,
unsettable: false, derived: false) (iD: false)
Start Level Event Dispatcher [debug.model] Adding feature:
CDOFeature(ID=-1, name=firstName, type=STRING)
Start Level Event Dispatcher [debug.model] Adding class: CDOClass(ID=0,
name=DynPerson)
Start Level Event Dispatcher [debug.model] Added package:
CDOPackage(URI=http://my-com.ch/DynPeople, name=DynPeople, dynamic=true,
metaIDRange=[mid1:mid4], parentURI=null)


What needs to be done, to get that FeatureId set? I must have missed
something...

Regards
Roger
Re: Problem with dynamic model [message #422952 is a reply to message #422948] Fri, 19 September 2008 14:18 Go to previous messageGo to next message
Simon Mc Duff is currently offline Simon Mc DuffFriend
Messages: 596
Registered: July 2009
Senior Member
I know what is the problem.

I had the same problem.

can you open a bugzilla for that.
Tp fix your problem you need to do the following:
Before opening your session do the following:

pClass.getEAllStructuralFeatures()

It will fix your problem. It seems that the internal structure of EClass
isn't built.



"Roger " <r.stocker@gmx.ch> a
Re: Problem with dynamic model [message #422953 is a reply to message #422952] Fri, 19 September 2008 14:53 Go to previous messageGo to next message
Roger Stocker is currently offline Roger StockerFriend
Messages: 16
Registered: July 2009
Junior Member
Thanks a lot!

I opened a bugzilla.
https://bugs.eclipse.org/bugs/show_bug.cgi?id=247978

Regards
Roger
Re: Problem with dynamic model [message #422965 is a reply to message #422948] Fri, 19 September 2008 16:31 Go to previous messageGo to next message
Simon Mc Duff is currently offline Simon Mc DuffFriend
Messages: 596
Registered: July 2009
Senior Member
Ed,

How EStructuralFeature.getFeatureID is safe ?

I mean we called it for dynamic classes and it returns -1. Is it a bug ?
Should it resolve itself first ?

We fixed our code by calling getALlStructureFeature for each EClass before
using it... but maybe we can do a better job.

Simon

"Roger " <r.stocker@gmx.ch> a
Re: Problem with dynamic model [message #422967 is a reply to message #422965] Fri, 19 September 2008 16:42 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 30813
Registered: July 2009
Senior Member
This is a multi-part message in MIME format.
--------------050602040503020309000000
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 8bit

Simon,

In general, the use of getEFeatureID is a low level thing that clients
don't generally call themselves. We expect clients to use
eClass.getFeatureID(eStructuralFeature) to get the feature ID relative
of a class. This also ensures that all the initialization work in the
class is done first. The performance of these methods are critical to
the performance reflective access so adding guards on them is something
I would do with great reluctance. Most likely it's better that this
issue be added in CDO itself, which is the only place this issue has
ever been noticed. It's certainly best that getEAllStructuralFeatures
is called at most once if possible so perhaps that ought to be done as
part of "registering the package/class" with CDO when first it start to
create or use objects of that class... (I've discussed this with Eike
in the past.)


Simon McDuff wrote:
> Ed,
>
> How EStructuralFeature.getFeatureID is safe ?
>
> I mean we called it for dynamic classes and it returns -1. Is it a bug ?
> Should it resolve itself first ?
>
> We fixed our code by calling getALlStructureFeature for each EClass before
> using it... but maybe we can do a better job.
>
> Simon
>
> "Roger " <r.stocker@gmx.ch> a
Previous Topic:Collections as return types of EOperations
Next Topic:Mapping xmi:type to EMF type
Goto Forum:
  


Current Time: Thu Jan 23 04:21:42 GMT 2020

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

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

Back to the top