summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSimon McDuff2008-05-22 15:14:56 (EDT)
committerSimon McDuff2008-05-22 15:14:56 (EDT)
commitc881310e1104decf5183fa79e8a68b23a33b3c53 (patch)
treecf90c550a4e2516762aacec1e94133b893d0f6cf
parent53d0c607a4045128f3728866dfcbec2048accff5 (diff)
downloadcdo-c881310e1104decf5183fa79e8a68b23a33b3c53.zip
cdo-c881310e1104decf5183fa79e8a68b23a33b3c53.tar.gz
cdo-c881310e1104decf5183fa79e8a68b23a33b3c53.tar.bz2
[226778] Implement getURIFragment and getEObject
https://bugs.eclipse.org/bugs/show_bug.cgi?id=226778
-rw-r--r--plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/InitialTest.java50
-rw-r--r--plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/eresource/impl/CDOResourceImpl.java36
-rw-r--r--plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOSessionImpl.java9
3 files changed, 90 insertions, 5 deletions
diff --git a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/InitialTest.java b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/InitialTest.java
index ce16758..81d50ca 100644
--- a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/InitialTest.java
+++ b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/InitialTest.java
@@ -30,6 +30,7 @@ import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
+import org.eclipse.emf.ecore.util.EcoreUtil;
import java.util.Date;
@@ -733,4 +734,53 @@ public class InitialTest extends AbstractCDOTest
msg("Verifying product");
assertEquals(null, orderDetail.getProduct());
}
+
+ public void testResourceAccessor() throws Exception
+ {
+ msg("Opening session");
+ CDOSession session = openModel1Session();
+
+ msg("Opening transaction");
+ CDOTransaction transaction = session.openTransaction();
+
+ msg("Creating resource");
+ CDOResource resource = transaction.createResource("/test1");
+
+ msg("Creating supplier");
+ Supplier supplier = Model1Factory.eINSTANCE.createSupplier();
+
+ msg("Setting name");
+ supplier.setName("Stepper");
+
+ msg("Adding supplier");
+ resource.getContents().add(supplier);
+
+ URI supplierTempURI = EcoreUtil.getURI(supplier);
+
+ msg("Retrieving supplier from URI before commit");
+ EObject supplier1 = transaction.getResourceSet().getEObject(supplierTempURI, true);
+
+ assertEquals(supplier, supplier1);
+
+ msg("Committing");
+ transaction.commit();
+
+ URI supplierURI = EcoreUtil.getURI(supplier);
+
+ msg("Retrieving supplier from URI after commit");
+ EObject supplierFromURI = transaction.getResourceSet().getEObject(supplierURI, true);
+
+ assertEquals(supplier, supplierFromURI);
+
+ try
+ {
+ EObject supplierAfterCommit2 = transaction.getResourceSet().getEObject(supplierTempURI, true);
+ assertEquals(null, supplierAfterCommit2);
+ }
+ catch(IllegalStateException excep)
+ {
+
+ }
+
+ }
}
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 915c7c2..aef3dd4 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
@@ -7,6 +7,7 @@
*
* Contributors:
* Eike Stepper - initial API and implementation
+ * Simon McDuff - https://bugs.eclipse.org/bugs/show_bug.cgi?id=226778
**************************************************************************/
package org.eclipse.emf.cdo.eresource.impl;
@@ -14,6 +15,10 @@ import org.eclipse.emf.cdo.CDOState;
import org.eclipse.emf.cdo.CDOTransaction;
import org.eclipse.emf.cdo.eresource.CDOResource;
import org.eclipse.emf.cdo.eresource.EresourcePackage;
+import org.eclipse.emf.cdo.internal.protocol.id.CDOIDLongImpl;
+import org.eclipse.emf.cdo.internal.protocol.id.CDOIDTempObjectImpl;
+import org.eclipse.emf.cdo.protocol.id.CDOID;
+import org.eclipse.emf.cdo.protocol.id.CDOIDUtil;
import org.eclipse.emf.cdo.util.CDOUtil;
import org.eclipse.emf.internal.cdo.CDOLegacyImpl;
@@ -26,6 +31,7 @@ import org.eclipse.emf.internal.cdo.util.FSMUtil;
import org.eclipse.net4j.internal.util.om.trace.ContextTracer;
import org.eclipse.net4j.util.ImplementationError;
+import org.eclipse.net4j.util.io.ExtendedDataOutputStream;
import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.common.notify.NotificationChain;
@@ -43,7 +49,9 @@ import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.emf.ecore.resource.impl.ResourceImpl;
import org.eclipse.emf.ecore.util.InternalEList;
+import org.eclipse.emf.ecore.xmi.UnresolvedReferenceException;
+import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
@@ -332,17 +340,37 @@ public class CDOResourceImpl extends CDOObjectImpl implements CDOResource
*/
public EObject getEObject(String uriFragment)
{
- // TODO Implement method CDOResourceImpl.getEObject()
- throw new UnsupportedOperationException("Not yet implemented");
+ if (uriFragment == null)
+ return null;
+
+ CDOID cdoID = CDOIDUtil.read(uriFragment, cdoView().getSession().getPackageManager().getCDOIDObjectFactory());
+
+ if (cdoID.isNull())
+ return null;
+
+ if (cdoID.isTemporary() && !cdoView().isObjectRegistered(cdoID))
+ throw new IllegalStateException("Temporary object : " + uriFragment + " is not available anymore.");
+
+ if (cdoID.isObject())
+ return cdoView().getObject(cdoID,true);
+
+ // If it doesn`t match to anything we return null like ResourceImpl.getEObject
+ return null;
}
/**
+ *
* @ADDED
*/
public String getURIFragment(EObject object)
{
- // TODO Implement method CDOResourceImpl.getURIFragment()
- throw new UnsupportedOperationException("Not yet implemented");
+ InternalCDOObject internalCDOObject = FSMUtil.adapt(object, this.cdoView());
+
+ StringBuffer idBuffer = new StringBuffer();
+
+ CDOIDUtil.write(idBuffer, internalCDOObject.cdoID());
+
+ return idBuffer.toString();
}
/**
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 552aaa4..91047c7 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
@@ -7,6 +7,7 @@
*
* Contributors:
* Eike Stepper - initial API and implementation
+ * Simon McDuff - https://bugs.eclipse.org/bugs/show_bug.cgi?id=226778
**************************************************************************/
package org.eclipse.emf.internal.cdo;
@@ -164,7 +165,12 @@ public class CDOSessionImpl extends Container<CDOView> implements CDOSession, CD
{
return cdoidObjectFactory.createCDOIDObject(in);
}
-
+
+ public CDOIDObject createCDOIDObject(String in)
+ {
+ return cdoidObjectFactory.createCDOIDObject(in);
+ }
+
public boolean isDisableLegacyObjects()
{
return disableLegacyObjects;
@@ -833,4 +839,5 @@ public class CDOSessionImpl extends Container<CDOView> implements CDOSession, CD
return "CDOSessionInvalidationEvent" + dirtyOIDs;
}
}
+
}