summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEike Stepper2007-08-03 10:38:12 (EDT)
committerEike Stepper2007-08-03 10:38:12 (EDT)
commit8c08eb7718d34fd08507e971c2a6821d84d2a445 (patch)
tree00865194dd0c543207ecbb86e40a88d9fd7bf991
parent391ac25300365b78ecb7609a802ca529dc9c0a0a (diff)
downloadcdo-8c08eb7718d34fd08507e971c2a6821d84d2a445.zip
cdo-8c08eb7718d34fd08507e971c2a6821d84d2a445.tar.gz
cdo-8c08eb7718d34fd08507e971c2a6821d84d2a445.tar.bz2
*** empty log message ***
-rw-r--r--plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/Session.java24
-rw-r--r--plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/protocol/CDOServerProtocol.java4
-rw-r--r--plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/protocol/LoadRevisionIndication.java (renamed from plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/protocol/LoadObjectIndication.java)10
-rw-r--r--plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/util/EMFUtil.java40
-rw-r--r--plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOAdapterImpl.java13
-rw-r--r--plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOCallbackImpl.java9
-rw-r--r--plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOLegacyImpl.java85
-rw-r--r--plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDORevisionManagerImpl.java6
-rw-r--r--plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/protocol/LoadRevisionRequest.java (renamed from plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/protocol/LoadObjectRequest.java)10
-rw-r--r--plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/io/ExtendedDataInputStream.java20
-rw-r--r--plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/io/ExtendedDataOutputStream.java20
-rw-r--r--plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/io/IOUtil.java1
12 files changed, 187 insertions, 55 deletions
diff --git a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/Session.java b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/Session.java
index daa9449..d4ca206 100644
--- a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/Session.java
+++ b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/Session.java
@@ -10,16 +10,23 @@
**************************************************************************/
package org.eclipse.emf.cdo.internal.server;
+import org.eclipse.emf.cdo.internal.protocol.CDOIDImpl;
+import org.eclipse.emf.cdo.internal.protocol.revision.CDOIDProvider;
import org.eclipse.emf.cdo.internal.protocol.revision.CDORevisionImpl;
import org.eclipse.emf.cdo.internal.server.bundle.OM;
import org.eclipse.emf.cdo.internal.server.protocol.CDOServerProtocol;
import org.eclipse.emf.cdo.internal.server.protocol.InvalidationRequest;
+import org.eclipse.emf.cdo.protocol.CDOID;
+import org.eclipse.emf.cdo.protocol.model.CDOClassRef;
import org.eclipse.emf.cdo.server.ISession;
+import java.util.HashSet;
+import java.util.Set;
+
/**
* @author Eike Stepper
*/
-public class Session implements ISession
+public class Session implements ISession, CDOIDProvider
{
private SessionManager sessionManager;
@@ -27,6 +34,8 @@ public class Session implements ISession
private int sessionID;
+ private Set<CDOID> knownObjects = new HashSet();
+
public Session(SessionManager sessionManager, CDOServerProtocol protocol, int sessionID)
{
this.sessionManager = sessionManager;
@@ -60,4 +69,17 @@ public class Session implements ISession
OM.LOG.error(ex);
}
}
+
+ public CDOID provideCDOID(Object idObject)
+ {
+ CDOID id = (CDOID)idObject;
+ if (knownObjects.contains(id))
+ {
+ return id;
+ }
+
+ knownObjects.add(id);
+ CDOClassRef type = null;
+ return CDOIDImpl.create(id.getValue(), type);
+ }
}
diff --git a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/protocol/CDOServerProtocol.java b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/protocol/CDOServerProtocol.java
index 9a84dd2..44f3033 100644
--- a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/protocol/CDOServerProtocol.java
+++ b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/protocol/CDOServerProtocol.java
@@ -59,8 +59,8 @@ public class CDOServerProtocol extends SignalProtocol
case CDOProtocolConstants.SIGNAL_LOAD_PACKAGE:
return new LoadPackageIndication();
- case CDOProtocolConstants.SIGNAL_LOAD_OBJECT:
- return new LoadObjectIndication();
+ case CDOProtocolConstants.SIGNAL_LOAD_REVISION:
+ return new LoadRevisionIndication();
case CDOProtocolConstants.SIGNAL_COMMIT_TRANSACTION:
return new CommitTransactionIndication();
diff --git a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/protocol/LoadObjectIndication.java b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/protocol/LoadRevisionIndication.java
index a0dffe0..d6da2a0 100644
--- a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/protocol/LoadObjectIndication.java
+++ b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/protocol/LoadRevisionIndication.java
@@ -26,17 +26,17 @@ import java.io.IOException;
/**
* @author Eike Stepper
*/
-public class LoadObjectIndication extends CDOServerIndication
+public class LoadRevisionIndication extends CDOServerIndication
{
- private static final ContextTracer PROTOCOL = new ContextTracer(OM.DEBUG_PROTOCOL, LoadObjectIndication.class);
+ private static final ContextTracer PROTOCOL = new ContextTracer(OM.DEBUG_PROTOCOL, LoadRevisionIndication.class);
private CDOID id;
private Long timeStamp;
- public LoadObjectIndication()
+ public LoadRevisionIndication()
{
- super(CDOProtocolConstants.SIGNAL_LOAD_OBJECT);
+ super(CDOProtocolConstants.SIGNAL_LOAD_REVISION);
}
@Override
@@ -72,6 +72,6 @@ public class LoadObjectIndication extends CDOServerIndication
}
});
- revision[0].write(out, null);
+ revision[0].write(out, getSession());
}
}
diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/util/EMFUtil.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/util/EMFUtil.java
index 45c5895..1e5ad62 100644
--- a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/util/EMFUtil.java
+++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/util/EMFUtil.java
@@ -14,6 +14,7 @@ import org.eclipse.net4j.util.io.IORuntimeException;
import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.common.util.TreeIterator;
+import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.EClassifier;
import org.eclipse.emf.ecore.EDataType;
@@ -24,8 +25,14 @@ import org.eclipse.emf.ecore.EReference;
import org.eclipse.emf.ecore.EStructuralFeature;
import org.eclipse.emf.ecore.impl.EClassifierImpl;
import org.eclipse.emf.ecore.impl.EPackageImpl;
+import org.eclipse.emf.ecore.resource.Resource;
+import org.eclipse.emf.ecore.resource.ResourceSet;
+import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
+import org.eclipse.emf.ecore.util.EcoreUtil;
import org.eclipse.emf.ecore.xmi.XMIResource;
+import org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl;
import org.eclipse.emf.ecore.xmi.impl.XMIResourceImpl;
+
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
@@ -44,6 +51,39 @@ public final class EMFUtil
{
}
+ public static EObject loadXMI(String fileName)
+ {
+ return loadXMI(fileName, EPackage.Registry.INSTANCE);
+ }
+
+ public static EObject loadXMI(String fileName, EPackage.Registry packageRegistry)
+ {
+ ResourceSet resourceSet = new ResourceSetImpl();
+ resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put("*", new XMIResourceFactoryImpl());
+ resourceSet.setPackageRegistry(packageRegistry);
+
+ Resource resource = resourceSet.getResource(URI.createFileURI(fileName), true);
+ return resource.getContents().get(0);
+ }
+
+ public static void saveXMI(String fileName, EObject root)
+ {
+ ResourceSet resourceSet = new ResourceSetImpl();
+ resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put("*", new XMIResourceFactoryImpl());
+ Resource resource = resourceSet.createResource(URI.createFileURI(fileName));
+
+ EObject copy = EcoreUtil.copy(root);
+ resource.getContents().add(copy);
+ try
+ {
+ resource.save(null);
+ }
+ catch (IOException ex)
+ {
+ throw new IORuntimeException(ex);
+ }
+ }
+
public static int countAllContents(EObject eObject)
{
int count = 0;
diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOAdapterImpl.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOAdapterImpl.java
index 13bf223..9667f0b 100644
--- a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOAdapterImpl.java
+++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOAdapterImpl.java
@@ -124,4 +124,17 @@ public class CDOAdapterImpl extends CDOLegacyImpl implements Adapter.Internal
return oldState;
}
+
+ /**
+ * This implementation simply asks the view to convert the ID which can result
+ * in a LoadObjectRequest being sent. Basically this leads to loading the
+ * whole subtree (i.e. resource). TODO Investigate the use of proxies here
+ *
+ * @see CDOCallbackImpl
+ */
+ @Override
+ protected Object convertPotentialID(CDOViewImpl view, Object potentialID)
+ {
+ return view.convertIDToObject(potentialID);
+ }
}
diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOCallbackImpl.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOCallbackImpl.java
index df55561..a7b228e 100644
--- a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOCallbackImpl.java
+++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOCallbackImpl.java
@@ -15,8 +15,6 @@ import org.eclipse.emf.ecore.impl.CDOCallback;
import org.eclipse.emf.ecore.impl.EObjectImpl;
/**
- * TODO Check if deriving from CDOAdapterImpl is necessary
- *
* @author Eike Stepper
*/
public class CDOCallbackImpl extends CDOLegacyImpl implements CDOCallback
@@ -35,4 +33,11 @@ public class CDOCallbackImpl extends CDOLegacyImpl implements CDOCallback
{
CDOStateMachine.INSTANCE.write(this);
}
+
+ @Override
+ protected Object convertPotentialID(CDOViewImpl view, Object potentialID)
+ {
+ // XXX
+ return view.convertIDToObject(potentialID);
+ }
}
diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOLegacyImpl.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOLegacyImpl.java
index 7cde124..a5a3980 100644
--- a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOLegacyImpl.java
+++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOLegacyImpl.java
@@ -190,6 +190,7 @@ public abstract class CDOLegacyImpl extends CDOWrapperImpl
else
{
revision.setResourceID(CDOID.NULL);
+ // XXX is as CDOIDProvider call ok here?
CDOID containerID = view.provideCDOID(container);
if (containerID.isNull())
{
@@ -260,6 +261,19 @@ public abstract class CDOLegacyImpl extends CDOWrapperImpl
}
// Handle containment
+ transferContainmentToInstance(view);
+
+ // Handle values
+ CDOClassImpl cdoClass = revision.getCDOClass();
+ CDOFeatureImpl[] features = cdoClass.getAllFeatures();
+ for (CDOFeatureImpl feature : features)
+ {
+ transferFeatureToInstance(view, feature);
+ }
+ }
+
+ protected void transferContainmentToInstance(CDOViewImpl view)
+ {
CDOID containerID = revision.getContainerID();
if (containerID.isNull())
{
@@ -270,45 +284,10 @@ public abstract class CDOLegacyImpl extends CDOWrapperImpl
else
{
int containingFeatureID = revision.getContainingFeatureID();
+ // XXX Maybe convertPotentialID() better here?
InternalCDOObject container = view.lookupObject(containerID);
((BasicEObjectImpl)instance).eBasicSetContainer(container, containingFeatureID, null);
}
-
- // Handle values
- CDOClassImpl cdoClass = revision.getCDOClass();
- CDOFeatureImpl[] features = cdoClass.getAllFeatures();
- for (int i = 0; i < features.length; i++)
- {
- CDOFeatureImpl feature = features[i];
- Object value = revision.getValue(feature);
- if (feature.isMany())
- {
- InternalEList instanceList = (InternalEList)getInstanceValue(instance, feature);
- if (instanceList != null)
- {
- clearEList(instanceList);
- List revisionList = (List)value;
- for (Object toBeAdded : revisionList)
- {
- if (feature.isReference())
- {
- toBeAdded = view.convertIDToObject(toBeAdded);
- }
-
- instanceList.basicAdd(toBeAdded, null);
- }
- }
- }
- else
- {
- if (feature.isReference())
- {
- value = view.convertIDToObject(value);
- }
-
- setInstanceValue(instance, feature, value);
- }
- }
}
protected void transferResourceToInstance(BasicEObjectImpl instance, Resource.Internal resource)
@@ -325,6 +304,40 @@ public abstract class CDOLegacyImpl extends CDOWrapperImpl
}
}
+ protected void transferFeatureToInstance(CDOViewImpl view, CDOFeatureImpl feature)
+ {
+ Object value = revision.getValue(feature);
+ if (feature.isMany())
+ {
+ InternalEList instanceList = (InternalEList)getInstanceValue(instance, feature);
+ if (instanceList != null)
+ {
+ clearEList(instanceList);
+ List revisionList = (List)value;
+ for (Object element : revisionList)
+ {
+ if (feature.isReference())
+ {
+ element = convertPotentialID(view, element);
+ }
+
+ instanceList.basicAdd(element, null);
+ }
+ }
+ }
+ else
+ {
+ if (feature.isReference())
+ {
+ value = convertPotentialID(view, value);
+ }
+
+ setInstanceValue(instance, feature, value);
+ }
+ }
+
+ protected abstract Object convertPotentialID(CDOViewImpl view, Object potentialID);
+
protected Object getInstanceValue(InternalEObject instance, CDOFeatureImpl feature)
{
// Class<?> targetClass = target.getClass();
diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDORevisionManagerImpl.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDORevisionManagerImpl.java
index 14b2070..98fb387 100644
--- a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDORevisionManagerImpl.java
+++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDORevisionManagerImpl.java
@@ -16,7 +16,7 @@ import org.eclipse.emf.cdo.internal.protocol.revision.CDORevisionResolverImpl;
import org.eclipse.emf.cdo.protocol.CDOID;
import org.eclipse.emf.cdo.protocol.util.TransportException;
-import org.eclipse.emf.internal.cdo.protocol.LoadObjectRequest;
+import org.eclipse.emf.internal.cdo.protocol.LoadRevisionRequest;
/**
* @author Eike Stepper
@@ -40,7 +40,7 @@ public class CDORevisionManagerImpl extends CDORevisionResolverImpl implements C
{
try
{
- return new LoadObjectRequest(session.getChannel(), id).send();
+ return new LoadRevisionRequest(session.getChannel(), id).send();
}
catch (RuntimeException ex)
{
@@ -57,7 +57,7 @@ public class CDORevisionManagerImpl extends CDORevisionResolverImpl implements C
{
try
{
- LoadObjectRequest signal = new LoadObjectRequest(session.getChannel(), id, timeStamp);
+ LoadRevisionRequest signal = new LoadRevisionRequest(session.getChannel(), id, timeStamp);
return signal.send();
}
catch (RuntimeException ex)
diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/protocol/LoadObjectRequest.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/protocol/LoadRevisionRequest.java
index ad665b0..eeb070a 100644
--- a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/protocol/LoadObjectRequest.java
+++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/protocol/LoadRevisionRequest.java
@@ -27,21 +27,21 @@ import java.io.IOException;
/**
* @author Eike Stepper
*/
-public class LoadObjectRequest extends CDOClientRequest<CDORevisionImpl>
+public class LoadRevisionRequest extends CDOClientRequest<CDORevisionImpl>
{
- private static final ContextTracer PROTOCOL = new ContextTracer(OM.DEBUG_PROTOCOL, LoadObjectRequest.class);
+ private static final ContextTracer PROTOCOL = new ContextTracer(OM.DEBUG_PROTOCOL, LoadRevisionRequest.class);
private CDOID id;
private Long timeStamp;
- public LoadObjectRequest(IChannel channel, CDOID id)
+ public LoadRevisionRequest(IChannel channel, CDOID id)
{
- super(channel, CDOProtocolConstants.SIGNAL_LOAD_OBJECT);
+ super(channel, CDOProtocolConstants.SIGNAL_LOAD_REVISION);
this.id = id;
}
- public LoadObjectRequest(IChannel channel, CDOID id, long timeStamp)
+ public LoadRevisionRequest(IChannel channel, CDOID id, long timeStamp)
{
this(channel, id);
this.timeStamp = timeStamp;
diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/io/ExtendedDataInputStream.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/io/ExtendedDataInputStream.java
index 16ee7d3..e8d7df8 100644
--- a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/io/ExtendedDataInputStream.java
+++ b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/io/ExtendedDataInputStream.java
@@ -68,4 +68,24 @@ public class ExtendedDataInputStream extends DataInputStream implements Extended
ObjectInputStream wrapper = new ObjectInputStream(this);
return wrapper.readObject();
}
+
+ public static ExtendedDataInputStream wrap(InputStream stream)
+ {
+ if (stream instanceof ExtendedDataInputStream)
+ {
+ return (ExtendedDataInputStream)stream;
+ }
+
+ return new ExtendedDataInputStream(stream);
+ }
+
+ public static InputStream unwrap(InputStream stream)
+ {
+ if (stream instanceof ExtendedDataInputStream)
+ {
+ return ((ExtendedDataInputStream)stream).in;
+ }
+
+ return stream;
+ }
}
diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/io/ExtendedDataOutputStream.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/io/ExtendedDataOutputStream.java
index 5ea1abc..633c60c 100644
--- a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/io/ExtendedDataOutputStream.java
+++ b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/io/ExtendedDataOutputStream.java
@@ -55,4 +55,24 @@ public class ExtendedDataOutputStream extends DataOutputStream implements Extend
ObjectOutputStream wrapper = new ObjectOutputStream(this);
wrapper.writeObject(object);
}
+
+ public static ExtendedDataOutputStream wrap(OutputStream stream)
+ {
+ if (stream instanceof ExtendedDataOutputStream)
+ {
+ return (ExtendedDataOutputStream)stream;
+ }
+
+ return new ExtendedDataOutputStream(stream);
+ }
+
+ public static OutputStream unwrap(OutputStream stream)
+ {
+ if (stream instanceof ExtendedDataOutputStream)
+ {
+ return ((ExtendedDataOutputStream)stream).out;
+ }
+
+ return stream;
+ }
}
diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/io/IOUtil.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/io/IOUtil.java
index b86f9d6..2959eb9 100644
--- a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/io/IOUtil.java
+++ b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/io/IOUtil.java
@@ -450,7 +450,6 @@ public final class IOUtil
{
stream1 = new FileInputStream(file1);
stream2 = new FileInputStream(file2);
-
return equals(stream1, stream2);
}
catch (IOException ex)