Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEike Stepper2012-09-04 08:15:53 +0000
committerEike Stepper2012-09-04 08:15:53 +0000
commit91202b47531461e35fe23d784e15bf6b62345f71 (patch)
tree8620ac675e3cff23f267d4380619af5a31441a41 /plugins
parent612d15a3fb4d5c8d3116ad7500c972f84b4c557b (diff)
downloadcdo-91202b47531461e35fe23d784e15bf6b62345f71.tar.gz
cdo-91202b47531461e35fe23d784e15bf6b62345f71.tar.xz
cdo-91202b47531461e35fe23d784e15bf6b62345f71.zip
[388721] Add CDOResourceImpl.getEObjectByID(String)
https://bugs.eclipse.org/bugs/show_bug.cgi?id=388721
Diffstat (limited to 'plugins')
-rw-r--r--plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/eresource/EresourcePackage.java1
-rw-r--r--plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/eresource/impl/CDOResourceImpl.java107
-rw-r--r--plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/eresource/impl/EresourcePackageImpl.java78
-rw-r--r--plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/util/CDOUtil.java28
4 files changed, 177 insertions, 37 deletions
diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/eresource/EresourcePackage.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/eresource/EresourcePackage.java
index 7455242e95..2d70edacea 100644
--- a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/eresource/EresourcePackage.java
+++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/eresource/EresourcePackage.java
@@ -1045,6 +1045,7 @@ public interface EresourcePackage extends EPackage
/**
* The meta object literal for the '<em><b>Encoding</b></em>' attribute feature.
* <!-- begin-user-doc -->
+ * @since 4.2
* <!-- end-user-doc -->
* @generated
*/
diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/eresource/impl/CDOResourceImpl.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/eresource/impl/CDOResourceImpl.java
index 476ea76a42..ce3ee680ef 100644
--- a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/eresource/impl/CDOResourceImpl.java
+++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/eresource/impl/CDOResourceImpl.java
@@ -55,6 +55,9 @@ import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.emf.ecore.resource.URIConverter;
import org.eclipse.emf.ecore.resource.impl.ExtensibleURIConverterImpl;
import org.eclipse.emf.ecore.resource.impl.ResourceImpl;
+import org.eclipse.emf.ecore.util.EcoreUtil;
+import org.eclipse.emf.ecore.util.EcoreUtil.ContentTreeIterator;
+import org.eclipse.emf.ecore.util.EcoreUtil.ProperContentIterator;
import org.eclipse.emf.ecore.util.InternalEList;
import org.eclipse.emf.ecore.xmi.XMIResource;
import org.eclipse.emf.ecore.xmi.XMLHelper;
@@ -159,6 +162,13 @@ public class CDOResourceImpl extends CDOResourceLeafImpl implements CDOResource,
private transient CDOViewProvider viewProvider;
/**
+ * A map to retrieve the EObject based on the value of its ID feature.
+ * @see #setIntrinsicIDToEObjectMap(Map)
+ * @ADDED
+ */
+ private transient Map<String, EObject> intrinsicIDToEObjectMap;
+
+ /**
* @ADDED
* @since 2.0
*/
@@ -682,7 +692,7 @@ public class CDOResourceImpl extends CDOResourceLeafImpl implements CDOResource,
}
}
- return null;
+ return getEObjectByID(uriFragment);
}
private EObject getEObject(List<String> uriFragmentPath)
@@ -697,6 +707,9 @@ public class CDOResourceImpl extends CDOResourceLeafImpl implements CDOResource,
return eObject;
}
+ /**
+ * @since 4.2
+ */
private EObject getEObjectForURIFragmentRootSegment(String uriFragmentRootSegment)
{
int position = 0;
@@ -722,6 +735,98 @@ public class CDOResourceImpl extends CDOResourceLeafImpl implements CDOResource,
}
/**
+ * Returns the map used to cache the EObject that is identified by the {@link #getEObjectByID(String) value}
+ * of its ID feature.
+ * @return the map used to cache the EObject that is identified by the value of its ID feature.
+ * @see #setIntrinsicIDToEObjectMap
+ * @since 4.2
+ * @ADDED
+ */
+ public Map<String, EObject> getIntrinsicIDToEObjectMap()
+ {
+ return intrinsicIDToEObjectMap;
+ }
+
+ /**
+ * Sets the map used to cache the EObject identified by the value of its ID feature.
+ * This cache is only activated if the map is not <code>null</code>.
+ * The map will be lazily loaded by the {@link #getEObjectByID(String) getEObjectByID} method.
+ * It is up to the client to clear the cache when it becomes invalid,
+ * e.g., when the ID of a previously mapped EObject is changed.
+ * @param intrinsicIDToEObjectMap the new map or <code>null</code>.
+ * @see #getIntrinsicIDToEObjectMap
+ * @since 4.2
+ * @ADDED
+ */
+ public void setIntrinsicIDToEObjectMap(Map<String, EObject> intrinsicIDToEObjectMap)
+ {
+ this.intrinsicIDToEObjectMap = intrinsicIDToEObjectMap;
+ }
+
+ /**
+ * Returns the object based on the fragment as an ID.
+ * @since 4.2
+ * @ADDED
+ */
+ protected EObject getEObjectByID(String id)
+ {
+ Map<String, EObject> map = getIntrinsicIDToEObjectMap();
+ if (map != null)
+ {
+ EObject eObject = map.get(id);
+ if (eObject != null)
+ {
+ return eObject;
+ }
+ }
+
+ EObject result = null;
+ for (TreeIterator<EObject> i = getAllProperContents(getContents()); i.hasNext();)
+ {
+ EObject eObject = i.next();
+ String eObjectId = EcoreUtil.getID(eObject);
+ if (eObjectId != null)
+ {
+ if (map != null)
+ {
+ map.put(eObjectId, eObject);
+ }
+
+ if (eObjectId.equals(id))
+ {
+ result = eObject;
+ if (map == null)
+ {
+ break;
+ }
+ }
+ }
+ }
+
+ return result;
+ }
+
+ /**
+ * @since 4.2
+ * @ADDED
+ */
+ protected TreeIterator<EObject> getAllProperContents(List<EObject> contents)
+ {
+ return new ContentTreeIterator<EObject>(contents, false)
+ {
+ private static final long serialVersionUID = 1L;
+
+ @SuppressWarnings("unchecked")
+ @Override
+ public Iterator<EObject> getChildren(Object object)
+ {
+ return object == this.object ? ((List<EObject>)object).iterator() : new ProperContentIterator<EObject>(
+ (EObject)object);
+ }
+ };
+ }
+
+ /**
* @ADDED
*/
public String getURIFragment(EObject object)
diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/eresource/impl/EresourcePackageImpl.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/eresource/impl/EresourcePackageImpl.java
index 3587bff2cb..83ac5daab3 100644
--- a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/eresource/impl/EresourcePackageImpl.java
+++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/eresource/impl/EresourcePackageImpl.java
@@ -34,7 +34,7 @@ import org.eclipse.emf.ecore.resource.ResourceSet;
/**
* <!-- begin-user-doc --> An implementation of the model <b>Package</b>.
- *
+ *
* @noextend This interface is not intended to be extended by clients. <!-- end-user-doc -->
* @generated
*/
@@ -107,7 +107,7 @@ public class EresourcePackageImpl extends EPackageImpl implements EresourcePacka
* Note: the correct way to create the package is via the static factory method {@link #init init()}, which also
* performs initialization of the package, or returns the registered package, if one already exists. <!--
* begin-user-doc --> <!-- end-user-doc -->
- *
+ *
* @see org.eclipse.emf.ecore.EPackage.Registry
* @see org.eclipse.emf.cdo.eresource.EresourcePackage#eNS_URI
* @see #init()
@@ -126,7 +126,7 @@ public class EresourcePackageImpl extends EPackageImpl implements EresourcePacka
/**
* Creates, registers, and initializes the <b>Package</b> for this model, and for any others upon which it depends.
- *
+ *
* <p>This method is used to initialize {@link EresourcePackage#eINSTANCE} when that field is accessed.
* Clients should not invoke it directly. Instead, they should simply access that field to obtain the package.
* <!-- begin-user-doc
@@ -139,7 +139,9 @@ public class EresourcePackageImpl extends EPackageImpl implements EresourcePacka
public static EresourcePackage init()
{
if (isInited)
+ {
return (EresourcePackage)EPackage.Registry.INSTANCE.getEPackage(EresourcePackage.eNS_URI);
+ }
// Obtain or create and register package
EresourcePackageImpl theEresourcePackage = (EresourcePackageImpl)(EPackage.Registry.INSTANCE.get(eNS_URI) instanceof EresourcePackageImpl ? EPackage.Registry.INSTANCE
@@ -166,7 +168,7 @@ public class EresourcePackageImpl extends EPackageImpl implements EresourcePacka
/**
* <!-- begin-user-doc -->
- *
+ *
* @since 2.0<!-- end-user-doc -->
* @generated
*/
@@ -177,7 +179,7 @@ public class EresourcePackageImpl extends EPackageImpl implements EresourcePacka
/**
* <!-- begin-user-doc -->
- *
+ *
* @since 2.0<!-- end-user-doc -->
* @generated
*/
@@ -188,7 +190,7 @@ public class EresourcePackageImpl extends EPackageImpl implements EresourcePacka
/**
* <!-- begin-user-doc -->
- *
+ *
* @since 2.0<!-- end-user-doc -->
* @generated
*/
@@ -199,7 +201,7 @@ public class EresourcePackageImpl extends EPackageImpl implements EresourcePacka
/**
* <!-- begin-user-doc -->
- *
+ *
* @since 2.0<!-- end-user-doc -->
* @generated
*/
@@ -210,7 +212,7 @@ public class EresourcePackageImpl extends EPackageImpl implements EresourcePacka
/**
* <!-- begin-user-doc -->
- *
+ *
* @since 2.0<!-- end-user-doc -->
* @generated
*/
@@ -221,7 +223,7 @@ public class EresourcePackageImpl extends EPackageImpl implements EresourcePacka
/**
* <!-- begin-user-doc -->
- *
+ *
* @since 2.0<!-- end-user-doc -->
* @generated
*/
@@ -322,7 +324,7 @@ public class EresourcePackageImpl extends EPackageImpl implements EresourcePacka
/**
* <!-- begin-user-doc -->
- *
+ *
* @since 4.1 <!-- end-user-doc -->
* @generated
*/
@@ -333,7 +335,7 @@ public class EresourcePackageImpl extends EPackageImpl implements EresourcePacka
/**
* <!-- begin-user-doc -->
- *
+ *
* @since 4.1 <!-- end-user-doc -->
* @generated
*/
@@ -344,7 +346,7 @@ public class EresourcePackageImpl extends EPackageImpl implements EresourcePacka
/**
* <!-- begin-user-doc -->
- *
+ *
* @since 4.1 <!-- end-user-doc -->
* @generated
*/
@@ -355,7 +357,7 @@ public class EresourcePackageImpl extends EPackageImpl implements EresourcePacka
/**
* <!-- begin-user-doc -->
- *
+ *
* @since 4.1 <!-- end-user-doc -->
* @generated
*/
@@ -366,7 +368,7 @@ public class EresourcePackageImpl extends EPackageImpl implements EresourcePacka
/**
* <!-- begin-user-doc -->
- *
+ *
* @since 4.1 <!-- end-user-doc -->
* @generated
*/
@@ -377,7 +379,7 @@ public class EresourcePackageImpl extends EPackageImpl implements EresourcePacka
/**
* <!-- begin-user-doc -->
- *
+ *
* @since 4.1 <!-- end-user-doc -->
* @generated
*/
@@ -388,6 +390,7 @@ public class EresourcePackageImpl extends EPackageImpl implements EresourcePacka
/**
* <!-- begin-user-doc -->
+ * @since 4.2
* <!-- end-user-doc -->
* @generated
*/
@@ -447,7 +450,9 @@ public class EresourcePackageImpl extends EPackageImpl implements EresourcePacka
public void createPackageContents()
{
if (isCreated)
+ {
return;
+ }
isCreated = true;
// Create classes and their features
@@ -502,7 +507,9 @@ public class EresourcePackageImpl extends EPackageImpl implements EresourcePacka
public void initializePackageContents()
{
if (isInitialized)
+ {
return;
+ }
isInitialized = true;
// Initialize package
@@ -519,20 +526,20 @@ public class EresourcePackageImpl extends EPackageImpl implements EresourcePacka
// Set bounds for type parameters
// Add supertypes to classes
- cdoResourceFolderEClass.getESuperTypes().add(this.getCDOResourceNode());
- cdoResourceEClass.getESuperTypes().add(this.getCDOResourceLeaf());
- cdoResourceLeafEClass.getESuperTypes().add(this.getCDOResourceNode());
- cdoFileResourceEClass.getESuperTypes().add(this.getCDOResourceLeaf());
- cdoBinaryResourceEClass.getESuperTypes().add(this.getCDOFileResource());
- cdoTextResourceEClass.getESuperTypes().add(this.getCDOFileResource());
+ cdoResourceFolderEClass.getESuperTypes().add(getCDOResourceNode());
+ cdoResourceEClass.getESuperTypes().add(getCDOResourceLeaf());
+ cdoResourceLeafEClass.getESuperTypes().add(getCDOResourceNode());
+ cdoFileResourceEClass.getESuperTypes().add(getCDOResourceLeaf());
+ cdoBinaryResourceEClass.getESuperTypes().add(getCDOFileResource());
+ cdoTextResourceEClass.getESuperTypes().add(getCDOFileResource());
// Initialize classes and features; add operations and parameters
initEClass(cdoResourceNodeEClass, CDOResourceNode.class,
"CDOResourceNode", IS_ABSTRACT, !IS_INTERFACE, IS_GENERATED_INSTANCE_CLASS); //$NON-NLS-1$
initEReference(
getCDOResourceNode_Folder(),
- this.getCDOResourceFolder(),
- this.getCDOResourceFolder_Nodes(),
+ getCDOResourceFolder(),
+ getCDOResourceFolder_Nodes(),
"folder", null, 0, 1, CDOResourceNode.class, !IS_TRANSIENT, !IS_VOLATILE, IS_CHANGEABLE, !IS_COMPOSITE, !IS_RESOLVE_PROXIES, !IS_UNSETTABLE, IS_UNIQUE, !IS_DERIVED, IS_ORDERED); //$NON-NLS-1$
initEAttribute(
getCDOResourceNode_Name(),
@@ -547,22 +554,21 @@ public class EresourcePackageImpl extends EPackageImpl implements EresourcePacka
"CDOResourceFolder", !IS_ABSTRACT, !IS_INTERFACE, IS_GENERATED_INSTANCE_CLASS); //$NON-NLS-1$
initEReference(
getCDOResourceFolder_Nodes(),
- this.getCDOResourceNode(),
- this.getCDOResourceNode_Folder(),
+ getCDOResourceNode(),
+ getCDOResourceNode_Folder(),
"nodes", null, 0, -1, CDOResourceFolder.class, !IS_TRANSIENT, !IS_VOLATILE, IS_CHANGEABLE, IS_COMPOSITE, !IS_RESOLVE_PROXIES, !IS_UNSETTABLE, IS_UNIQUE, !IS_DERIVED, IS_ORDERED); //$NON-NLS-1$
- EOperation op = addEOperation(cdoResourceFolderEClass, this.getCDOResourceFolder(),
+ EOperation op = addEOperation(cdoResourceFolderEClass, getCDOResourceFolder(),
"addResourceFolder", 0, 1, IS_UNIQUE, IS_ORDERED); //$NON-NLS-1$
addEParameter(op, theEcorePackage.getEString(), "name", 0, 1, IS_UNIQUE, IS_ORDERED); //$NON-NLS-1$
- op = addEOperation(cdoResourceFolderEClass, this.getCDOResource(), "addResource", 0, 1, IS_UNIQUE, IS_ORDERED); //$NON-NLS-1$
+ op = addEOperation(cdoResourceFolderEClass, getCDOResource(), "addResource", 0, 1, IS_UNIQUE, IS_ORDERED); //$NON-NLS-1$
addEParameter(op, theEcorePackage.getEString(), "name", 0, 1, IS_UNIQUE, IS_ORDERED); //$NON-NLS-1$
- op = addEOperation(cdoResourceFolderEClass, this.getCDOTextResource(),
- "addTextResource", 0, 1, IS_UNIQUE, IS_ORDERED); //$NON-NLS-1$
+ op = addEOperation(cdoResourceFolderEClass, getCDOTextResource(), "addTextResource", 0, 1, IS_UNIQUE, IS_ORDERED); //$NON-NLS-1$
addEParameter(op, theEcorePackage.getEString(), "name", 0, 1, IS_UNIQUE, IS_ORDERED); //$NON-NLS-1$
- op = addEOperation(cdoResourceFolderEClass, this.getCDOBinaryResource(),
+ op = addEOperation(cdoResourceFolderEClass, getCDOBinaryResource(),
"addBinaryResource", 0, 1, IS_UNIQUE, IS_ORDERED); //$NON-NLS-1$
addEParameter(op, theEcorePackage.getEString(), "name", 0, 1, IS_UNIQUE, IS_ORDERED); //$NON-NLS-1$
@@ -570,11 +576,11 @@ public class EresourcePackageImpl extends EPackageImpl implements EresourcePacka
"CDOResource", !IS_ABSTRACT, !IS_INTERFACE, IS_GENERATED_INSTANCE_CLASS); //$NON-NLS-1$
initEAttribute(
getCDOResource_ResourceSet(),
- this.getResourceSet(),
+ getResourceSet(),
"resourceSet", null, 0, 1, CDOResource.class, IS_TRANSIENT, !IS_VOLATILE, IS_CHANGEABLE, !IS_UNSETTABLE, !IS_ID, IS_UNIQUE, !IS_DERIVED, IS_ORDERED); //$NON-NLS-1$
initEAttribute(
getCDOResource_URI(),
- this.getURI(),
+ getURI(),
"uRI", null, 0, 1, CDOResource.class, IS_TRANSIENT, IS_VOLATILE, IS_CHANGEABLE, !IS_UNSETTABLE, !IS_ID, IS_UNIQUE, IS_DERIVED, IS_ORDERED); //$NON-NLS-1$
initEReference(
getCDOResource_Contents(),
@@ -595,11 +601,11 @@ public class EresourcePackageImpl extends EPackageImpl implements EresourcePacka
"trackingModification", null, 0, 1, CDOResource.class, IS_TRANSIENT, !IS_VOLATILE, IS_CHANGEABLE, !IS_UNSETTABLE, !IS_ID, IS_UNIQUE, !IS_DERIVED, IS_ORDERED); //$NON-NLS-1$
initEAttribute(
getCDOResource_Errors(),
- this.getDiagnostic(),
+ getDiagnostic(),
"errors", null, 0, -1, CDOResource.class, IS_TRANSIENT, IS_VOLATILE, !IS_CHANGEABLE, !IS_UNSETTABLE, !IS_ID, IS_UNIQUE, IS_DERIVED, IS_ORDERED); //$NON-NLS-1$
initEAttribute(
getCDOResource_Warnings(),
- this.getDiagnostic(),
+ getDiagnostic(),
"warnings", null, 0, -1, CDOResource.class, IS_TRANSIENT, IS_VOLATILE, !IS_CHANGEABLE, !IS_UNSETTABLE, !IS_ID, IS_UNIQUE, IS_DERIVED, IS_ORDERED); //$NON-NLS-1$
initEAttribute(
getCDOResource_TimeStamp(),
@@ -650,13 +656,13 @@ public class EresourcePackageImpl extends EPackageImpl implements EresourcePacka
/**
* Initializes the annotations for <b>http://www.eclipse.org/CDO/DBStore</b>.
* <!-- begin-user-doc -->
- *
+ *
* @since 4.0 <!-- end-user-doc -->
* @generated
*/
protected void createDBStoreAnnotations()
{
- String source = "http://www.eclipse.org/CDO/DBStore"; //$NON-NLS-1$
+ String source = "http://www.eclipse.org/CDO/DBStore"; //$NON-NLS-1$
addAnnotation(getCDOResourceNode_Name(), source, new String[] { "columnType", "VARCHAR", //$NON-NLS-1$ //$NON-NLS-2$
"columnLength", "255" //$NON-NLS-1$ //$NON-NLS-2$
});
diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/util/CDOUtil.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/util/CDOUtil.java
index ba362b9146..2e187cb81e 100644
--- a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/util/CDOUtil.java
+++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/util/CDOUtil.java
@@ -18,6 +18,7 @@ import org.eclipse.emf.cdo.common.branch.CDOBranchPoint;
import org.eclipse.emf.cdo.common.revision.CDORevision;
import org.eclipse.emf.cdo.eresource.CDOResource;
import org.eclipse.emf.cdo.eresource.CDOResourceFactory;
+import org.eclipse.emf.cdo.eresource.impl.CDOResourceImpl;
import org.eclipse.emf.cdo.session.CDOCollectionLoadingPolicy;
import org.eclipse.emf.cdo.session.CDOSession;
import org.eclipse.emf.cdo.session.remote.CDORemoteSessionManager;
@@ -115,6 +116,33 @@ public final class CDOUtil
}
/**
+ * Returns the map used to cache the EObject that is identified by the {@link CDOResourceImpl#getEObjectByID(String) value}
+ * of its ID feature.
+ * @return the map used to cache the EObject that is identified by the value of its ID feature.
+ * @see #setIntrinsicIDToEObjectMap
+ * @since 4.2
+ */
+ public Map<String, EObject> getIntrinsicIDToEObjectMap(CDOResource resource)
+ {
+ return ((CDOResourceImpl)resource).getIntrinsicIDToEObjectMap();
+ }
+
+ /**
+ * Sets the map used to cache the EObject identified by the value of its ID feature.
+ * This cache is only activated if the map is not <code>null</code>.
+ * The map will be lazily loaded by the {@link CDOResourceImpl#getEObjectByID(String) getEObjectByID} method.
+ * It is up to the client to clear the cache when it becomes invalid,
+ * e.g., when the ID of a previously mapped EObject is changed.
+ * @param intrinsicIDToEObjectMap the new map or <code>null</code>.
+ * @see #getIntrinsicIDToEObjectMap
+ * @since 4.2
+ */
+ public void setIntrinsicIDToEObjectMap(CDOResource resource, Map<String, EObject> intrinsicIDToEObjectMap)
+ {
+ ((CDOResourceImpl)resource).setIntrinsicIDToEObjectMap(intrinsicIDToEObjectMap);
+ }
+
+ /**
* @since 3.0
*/
public static CDOSession getSession(Object object)

Back to the top