summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEike Stepper2008-04-21 05:04:53 (EDT)
committerEike Stepper2008-04-21 05:04:53 (EDT)
commit2124fc5183c3cbec4bb37ecac59e65eb82b4a945 (patch)
treedbdbe8557bb72be5e31c936e4f1ecf79b2d0e91e
parentb3854060c2186c4f417137665e424bd60ce8d5e7 (diff)
downloadcdo-2124fc5183c3cbec4bb37ecac59e65eb82b4a945.zip
cdo-2124fc5183c3cbec4bb37ecac59e65eb82b4a945.tar.gz
cdo-2124fc5183c3cbec4bb37ecac59e65eb82b4a945.tar.bz2
[226233] Issues with EPackages having inter-dependencies
https://bugs.eclipse.org/bugs/show_bug.cgi?id=226233
-rw-r--r--plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/PackageRegistryTest.java8
-rw-r--r--plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOPackageRegistryImpl.java22
-rw-r--r--plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOSessionImpl.java11
-rw-r--r--plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/util/ModelUtil.java53
4 files changed, 73 insertions, 21 deletions
diff --git a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/PackageRegistryTest.java b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/PackageRegistryTest.java
index 5c44a51..d8ab83f 100644
--- a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/PackageRegistryTest.java
+++ b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/PackageRegistryTest.java
@@ -150,9 +150,13 @@ public class PackageRegistryTest extends AbstractCDOTest
res.getContents().add(class1);
transaction.commit();
- String nsURI = Model3Package.eINSTANCE.getNsURI();
- CDOPackage model3Package = session.getPackageManager().lookupPackage(nsURI);
+ CDOPackage model3Package = session.getPackageManager().lookupPackage(Model3Package.eINSTANCE.getNsURI());
assertEquals(8, model3Package.getMetaIDRange().size());
+ assertNotNull(model3Package.getEcore());
+
+ CDOPackage subPackage = session.getPackageManager().lookupPackage(SubpackagePackage.eINSTANCE.getNsURI());
+ assertNull(subPackage.getMetaIDRange());
+ assertNull(subPackage.getEcore());
}
public void testCommitCircularPackages() throws Exception
diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOPackageRegistryImpl.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOPackageRegistryImpl.java
index 6ba7a34..96884f3 100644
--- a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOPackageRegistryImpl.java
+++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOPackageRegistryImpl.java
@@ -96,21 +96,25 @@ public class CDOPackageRegistryImpl extends EPackageRegistryImpl implements CDOP
@Override
public Object put(String key, Object value)
{
- if (TRACER.isEnabled())
+ if (value instanceof EPackage)
{
- TRACER.format("Registering package for {0}", key);
- }
+ if (TRACER.isEnabled())
+ {
+ TRACER.format("Registering package for {0}", key);
+ }
- if (value instanceof EPackageImpl)
- {
- EPackageImpl ePackage = (EPackageImpl)value;
- if (EMFUtil.isDynamicEPackage(ePackage))
+ if (value instanceof EPackageImpl)
{
- ModelUtil.prepareEPackage(ePackage);
+ EPackageImpl ePackage = (EPackageImpl)value;
+ if (EMFUtil.isDynamicEPackage(ePackage))
+ {
+ ModelUtil.prepareEPackage(ePackage);
+ }
}
+ EPackage ePackage = (EPackage)value;
CDOPackage cdoPackage = ModelUtil.getCDOPackage(ePackage, session.getPackageManager());
- ((InternalCDOPackage)cdoPackage).setPersistent(!cdoPackage.getMetaIDRange().isTemporary());
+ ((InternalCDOPackage)cdoPackage).setPersistent(!cdoPackage.getTopLevelPackage().getMetaIDRange().isTemporary());
}
return super.put(key, value);
diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOSessionImpl.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOSessionImpl.java
index 5727c8e..578d4c8 100644
--- a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOSessionImpl.java
+++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOSessionImpl.java
@@ -451,8 +451,15 @@ public class CDOSessionImpl extends Container<CDOView> implements CDOSession, CD
TRACER.format("Registering meta instance: {0} <-> {1}", id, metaInstance);
}
- idToMetaInstanceMap.put(id, metaInstance);
- metaInstanceToIDMap.put(metaInstance, id);
+ if (idToMetaInstanceMap.put(id, metaInstance) != null)
+ {
+ throw new IllegalStateException("Duplicate meta ID: " + id + " --> " + metaInstance);
+ }
+
+ if (metaInstanceToIDMap.put(metaInstance, id) != null)
+ {
+ throw new IllegalStateException("Duplicate metaInstance: " + metaInstance + " --> " + id);
+ }
for (EObject content : metaInstance.eContents())
{
diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/util/ModelUtil.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/util/ModelUtil.java
index 2d4caa2..c01db7c 100644
--- a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/util/ModelUtil.java
+++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/util/ModelUtil.java
@@ -30,6 +30,7 @@ import org.eclipse.emf.cdo.util.EMFUtil;
import org.eclipse.emf.internal.cdo.CDOFactoryImpl;
import org.eclipse.emf.internal.cdo.CDOPackageRegistryImpl;
+import org.eclipse.emf.internal.cdo.CDOSessionImpl;
import org.eclipse.emf.internal.cdo.CDOSessionPackageManagerImpl;
import org.eclipse.emf.internal.cdo.bundle.OM;
@@ -64,6 +65,12 @@ public final class ModelUtil
return parentURI;
}
+ public static EPackage getTopLevelPackage(EPackage ePackage)
+ {
+ EPackage superPackage = ePackage.getESuperPackage();
+ return superPackage == null ? ePackage : getTopLevelPackage(superPackage);
+ }
+
public static CDOType getCDOType(EStructuralFeature eFeature)
{
if (eFeature instanceof EReference)
@@ -132,8 +139,16 @@ public final class ModelUtil
CDOPackage cdoPackage = packageManager.lookupPackage(packageURI);
if (cdoPackage == null)
{
- cdoPackage = createCDOPackage(ePackage, packageManager);
- packageManager.addPackage(cdoPackage);
+ EPackage topLevelPackage = getTopLevelPackage(ePackage);
+ if (topLevelPackage != ePackage)
+ {
+ getCDOPackage(topLevelPackage, packageManager);
+ cdoPackage = packageManager.lookupPackage(packageURI);
+ }
+ else
+ {
+ cdoPackage = addCDOPackage(topLevelPackage, packageManager);
+ }
}
return cdoPackage;
@@ -151,22 +166,44 @@ public final class ModelUtil
return cdoClass.lookupFeature(eFeature.getFeatureID());
}
+ private static CDOPackage addCDOPackage(EPackage ePackage, CDOSessionPackageManagerImpl packageManager)
+ {
+ CDOPackage cdoPackage = createCDOPackage(ePackage, packageManager);
+ packageManager.addPackage(cdoPackage);
+
+ for (EPackage subPackage : ePackage.getESubpackages())
+ {
+ addCDOPackage(subPackage, packageManager);
+ }
+
+ return cdoPackage;
+ }
+
/**
* @see EMFUtil#getPersistentFeatures(org.eclipse.emf.common.util.EList)
* @see http://www.eclipse.org/newsportal/article.php?id=26780&group=eclipse.tools.emf#26780
*/
private static CDOPackage createCDOPackage(EPackage ePackage, CDOSessionPackageManagerImpl packageManager)
{
- String packageURI = ePackage.getNsURI();
+ CDOSessionImpl session = packageManager.getSession();
+ String uri = ePackage.getNsURI();
String parentURI = getParentURI(ePackage);
String name = ePackage.getName();
boolean dynamic = EMFUtil.isDynamicEPackage(ePackage);
- String ecore = parentURI == null || EcorePackage.eINSTANCE.getNsURI().equals(packageURI) ? null : EMFUtil
- .ePackageToString(ePackage, packageManager.getSession().getPackageRegistry());
- CDOIDMetaRange idRange = packageManager.getSession().registerEPackage(ePackage);
+ String ecore = null;
+ CDOIDMetaRange idRange = null;
+
+ if (parentURI == null)
+ {
+ if (!EcorePackage.eINSTANCE.getNsURI().equals(uri))
+ {
+ ecore = EMFUtil.ePackageToString(ePackage, session.getPackageRegistry());
+ }
+
+ idRange = session.registerEPackage(ePackage);
+ }
- CDOPackage cdoPackage = CDOModelUtil.createPackage(packageManager, packageURI, name, ecore, dynamic, idRange,
- parentURI);
+ CDOPackage cdoPackage = CDOModelUtil.createPackage(packageManager, uri, name, ecore, dynamic, idRange, parentURI);
initializeCDOPackage(ePackage, cdoPackage);
return cdoPackage;
}