Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEike Stepper2012-01-05 04:32:46 -0500
committerEike Stepper2012-01-05 04:32:46 -0500
commita340df661b0510e48bae72dbbcc23a00e66d6032 (patch)
tree466ab3f6c05fb98ef7d3f022f3a8585492f01a70
parent4902f67af1d5a8eda901024e60a1ce5b7bd04411 (diff)
downloadcdo-a340df661b0510e48bae72dbbcc23a00e66d6032.tar.gz
cdo-a340df661b0510e48bae72dbbcc23a00e66d6032.tar.xz
cdo-a340df661b0510e48bae72dbbcc23a00e66d6032.zip
[367905] [CDO] Allow Adapters to be notified during loading
https://bugs.eclipse.org/bugs/show_bug.cgi?id=367905
-rw-r--r--plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/common/util/PartialCollectionLoadingNotSupportedException.java45
-rw-r--r--plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/internal/common/revision/delta/CDORevisionDeltaImpl.java3
-rw-r--r--plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/ServerCDOView.java10
-rw-r--r--plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/view/CDOView.java110
-rw-r--r--plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/object/CDONotificationBuilder.java9
-rw-r--r--plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/view/CDOStateMachine.java24
-rw-r--r--plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/view/CDOViewImpl.java50
7 files changed, 204 insertions, 47 deletions
diff --git a/plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/common/util/PartialCollectionLoadingNotSupportedException.java b/plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/common/util/PartialCollectionLoadingNotSupportedException.java
new file mode 100644
index 0000000000..f4f3db5926
--- /dev/null
+++ b/plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/common/util/PartialCollectionLoadingNotSupportedException.java
@@ -0,0 +1,45 @@
+/*
+ * Copyright (c) 2004 - 2011 Eike Stepper (Berlin, Germany) and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Eike Stepper - initial API and implementation
+ */
+package org.eclipse.emf.cdo.common.util;
+
+import org.eclipse.emf.cdo.common.revision.CDOElementProxy;
+
+/**
+ * An unchecked exception that indicates that {@link CDOElementProxy list element proxies} have been encountered but
+ * cannot be handled.
+ *
+ * @author Eike Stepper
+ * @noextend This interface is not intended to be extended by clients.
+ * @since 4.1
+ */
+public class PartialCollectionLoadingNotSupportedException extends IllegalStateException
+{
+ private static final long serialVersionUID = 1L;
+
+ public PartialCollectionLoadingNotSupportedException()
+ {
+ }
+
+ public PartialCollectionLoadingNotSupportedException(String message)
+ {
+ super(message);
+ }
+
+ public PartialCollectionLoadingNotSupportedException(String message, Throwable cause)
+ {
+ super(message, cause);
+ }
+
+ public PartialCollectionLoadingNotSupportedException(Throwable cause)
+ {
+ super(cause);
+ }
+}
diff --git a/plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/internal/common/revision/delta/CDORevisionDeltaImpl.java b/plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/internal/common/revision/delta/CDORevisionDeltaImpl.java
index bc6e671bc9..bd5b0ba57e 100644
--- a/plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/internal/common/revision/delta/CDORevisionDeltaImpl.java
+++ b/plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/internal/common/revision/delta/CDORevisionDeltaImpl.java
@@ -30,6 +30,7 @@ import org.eclipse.emf.cdo.common.revision.delta.CDOFeatureDeltaVisitor;
import org.eclipse.emf.cdo.common.revision.delta.CDOListFeatureDelta;
import org.eclipse.emf.cdo.common.revision.delta.CDORevisionDelta;
import org.eclipse.emf.cdo.common.revision.delta.CDOUnsetFeatureDelta;
+import org.eclipse.emf.cdo.common.util.PartialCollectionLoadingNotSupportedException;
import org.eclipse.emf.cdo.spi.common.revision.CDOReferenceAdjuster;
import org.eclipse.emf.cdo.spi.common.revision.InternalCDOFeatureDelta;
import org.eclipse.emf.cdo.spi.common.revision.InternalCDORevision;
@@ -367,7 +368,7 @@ public class CDORevisionDeltaImpl implements InternalCDORevisionDelta
{
if (element instanceof CDOElementProxy)
{
- throw new IllegalStateException("List contains proxy elements");
+ throw new PartialCollectionLoadingNotSupportedException("List contains proxy elements");
}
}
}
diff --git a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/ServerCDOView.java b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/ServerCDOView.java
index 82d24768ab..f8ebfb18a5 100644
--- a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/ServerCDOView.java
+++ b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/ServerCDOView.java
@@ -308,6 +308,16 @@ public class ServerCDOView extends AbstractCDOView implements org.eclipse.emf.cd
throw new UnsupportedOperationException();
}
+ public boolean isLoadNotificationEnabled()
+ {
+ return false;
+ }
+
+ public void setLoadNotificationEnabled(boolean enabled)
+ {
+ throw new UnsupportedOperationException();
+ }
+
public boolean isLockNotificationEnabled()
{
return false;
diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/view/CDOView.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/view/CDOView.java
index 1f421e906b..847dc118a3 100644
--- a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/view/CDOView.java
+++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/view/CDOView.java
@@ -461,31 +461,21 @@ public interface CDOView extends CDOCommonView, CDOUpdatable, INotifier
public static final int NO_REVISION_PREFETCHING = 1;
/**
- * Returns the reference type to be used in the internal object cache.
+ * Returns <code>true</code> if the {@link CDOObject objects} in this view will notify their
+ * {@link org.eclipse.emf.common.notify.Adapter adapters} about the fact that they are <em>loaded</em>,
+ * <code>false</code> otherwise.
*
- * @return Either {@link ReferenceType#STRONG STRONG}, {@link ReferenceType#SOFT SOFT} or {@link ReferenceType#WEAK
- * WEAK}.
- */
- public ReferenceType getCacheReferenceType();
-
- /**
- * Sets the reference type to be used in the internal object cache to either {@link ReferenceType#STRONG STRONG},
- * {@link ReferenceType#SOFT SOFT} or {@link ReferenceType#WEAK WEAK}. If <code>null</code> is passed the default
- * reference type {@link ReferenceType#SOFT SOFT} is set. If the given reference type does not differ from the one
- * being currently set the new value is ignored and <code>false</code> is returned. Otherwise existing object
- * references are converted to the new type and <code>true</code> is returned.
- */
- public boolean setCacheReferenceType(ReferenceType referenceType);
-
- /**
- * @since 3.0
+ * @since 4.1
*/
- public CDOInvalidationPolicy getInvalidationPolicy();
+ public boolean isLoadNotificationEnabled();
/**
- * @since 3.0
+ * Specifies whether the {@link CDOObject objects} in this view will notify their
+ * {@link org.eclipse.emf.common.notify.Adapter adapters} about the fact that they are <em>loaded</em> or not.
+ *
+ * @since 4.1
*/
- public void setInvalidationPolicy(CDOInvalidationPolicy policy);
+ public void setLoadNotificationEnabled(boolean enabled);
/**
* Returns <code>true</code> if the {@link CDOObject objects} in this view will notify their
@@ -506,6 +496,16 @@ public interface CDOView extends CDOCommonView, CDOUpdatable, INotifier
public void setInvalidationNotificationEnabled(boolean enabled);
/**
+ * @since 3.0
+ */
+ public CDOInvalidationPolicy getInvalidationPolicy();
+
+ /**
+ * @since 3.0
+ */
+ public void setInvalidationPolicy(CDOInvalidationPolicy policy);
+
+ /**
* Returns the current set of {@link CDOAdapterPolicy change subscription policies}.
*
* @return The current set of change subscription policies, never <code>null</code>.
@@ -553,6 +553,23 @@ public interface CDOView extends CDOCommonView, CDOUpdatable, INotifier
*/
public void removeChangeSubscriptionPolicy(CDOAdapterPolicy policy);
+ /**
+ * Returns the reference type to be used in the internal object cache.
+ *
+ * @return Either {@link ReferenceType#STRONG STRONG}, {@link ReferenceType#SOFT SOFT} or {@link ReferenceType#WEAK
+ * WEAK}.
+ */
+ public ReferenceType getCacheReferenceType();
+
+ /**
+ * Sets the reference type to be used in the internal object cache to either {@link ReferenceType#STRONG STRONG},
+ * {@link ReferenceType#SOFT SOFT} or {@link ReferenceType#WEAK WEAK}. If <code>null</code> is passed the default
+ * reference type {@link ReferenceType#SOFT SOFT} is set. If the given reference type does not differ from the one
+ * being currently set the new value is ignored and <code>false</code> is returned. Otherwise existing object
+ * references are converted to the new type and <code>true</code> is returned.
+ */
+ public boolean setCacheReferenceType(ReferenceType referenceType);
+
// TODO
public CDOAdapterPolicy getStrongReferencePolicy();
@@ -617,90 +634,103 @@ public interface CDOView extends CDOCommonView, CDOUpdatable, INotifier
/**
* An {@link IOptionsEvent options event} fired from view {@link CDOView#options() options} when the
- * {@link Options#setCacheReferenceType(ReferenceType) cache reference type} option has changed.
+ * {@link Options#setLoadNotificationEnabled(boolean) load notification enabled} option has changed.
*
* @author Eike Stepper
* @noextend This interface is not intended to be extended by clients.
* @noimplement This interface is not intended to be implemented by clients.
+ * @since 4.1
*/
- public interface CacheReferenceTypeEvent extends IOptionsEvent
+ public interface LoadNotificationEvent extends IOptionsEvent
{
}
/**
* An {@link IOptionsEvent options event} fired from view {@link CDOView#options() options} when the
- * {@link Options#setStrongReferencePolicy(CDOAdapterPolicy) strong reference policy} option has changed.
+ * {@link Options#setInvalidationNotificationEnabled(boolean) invalidation notification enabled} option has changed.
*
* @author Eike Stepper
* @noextend This interface is not intended to be extended by clients.
* @noimplement This interface is not intended to be implemented by clients.
- * @since 4.0
*/
- public interface StrongReferencePolicyEvent extends IOptionsEvent
+ public interface InvalidationNotificationEvent extends IOptionsEvent
{
}
/**
* An {@link IOptionsEvent options event} fired from view {@link CDOView#options() options} when the
- * {@link Options#setStrongReferencePolicy(CDOAdapterPolicy) strong reference policy} option has changed.
+ * {@link Options#setInvalidationPolicy(CDOInvalidationPolicy) invalidation policy} option has changed.
*
* @author Eike Stepper
+ * @since 3.0
* @noextend This interface is not intended to be extended by clients.
* @noimplement This interface is not intended to be implemented by clients.
- * @deprecated Use {@link StrongReferencePolicyEvent} instead.
- * @apiviz.exclude
*/
- @Deprecated
- public interface ReferencePolicyEvent extends StrongReferencePolicyEvent
+ public interface InvalidationPolicyEvent extends IOptionsEvent
{
}
/**
* An {@link IOptionsEvent options event} fired from view {@link CDOView#options() options} when the
- * {@link Options#setStaleReferenceBehaviour(CDOStaleReferencePolicy) stale reference type} option has changed.
+ * {@link Options#addChangeSubscriptionPolicy(CDOAdapterPolicy) change subscription policies} option has changed.
*
- * @since 3.0
+ * @author Eike Stepper
* @noextend This interface is not intended to be extended by clients.
* @noimplement This interface is not intended to be implemented by clients.
*/
- public interface StaleReferencePolicyEvent extends IOptionsEvent
+ public interface ChangeSubscriptionPoliciesEvent extends IOptionsEvent
{
}
/**
* An {@link IOptionsEvent options event} fired from view {@link CDOView#options() options} when the
- * {@link Options#addChangeSubscriptionPolicy(CDOAdapterPolicy) change subscription policies} option has changed.
+ * {@link Options#setCacheReferenceType(ReferenceType) cache reference type} option has changed.
*
* @author Eike Stepper
* @noextend This interface is not intended to be extended by clients.
* @noimplement This interface is not intended to be implemented by clients.
*/
- public interface ChangeSubscriptionPoliciesEvent extends IOptionsEvent
+ public interface CacheReferenceTypeEvent extends IOptionsEvent
{
}
/**
* An {@link IOptionsEvent options event} fired from view {@link CDOView#options() options} when the
- * {@link Options#setInvalidationPolicy(CDOInvalidationPolicy) invalidation policy} option has changed.
+ * {@link Options#setStrongReferencePolicy(CDOAdapterPolicy) strong reference policy} option has changed.
*
* @author Eike Stepper
- * @since 3.0
* @noextend This interface is not intended to be extended by clients.
* @noimplement This interface is not intended to be implemented by clients.
+ * @since 4.0
*/
- public interface InvalidationPolicyEvent extends IOptionsEvent
+ public interface StrongReferencePolicyEvent extends IOptionsEvent
{
}
/**
* An {@link IOptionsEvent options event} fired from view {@link CDOView#options() options} when the
- * {@link Options#setInvalidationNotificationEnabled(boolean) invalidation notification enabled} option has changed.
+ * {@link Options#setStrongReferencePolicy(CDOAdapterPolicy) strong reference policy} option has changed.
*
* @author Eike Stepper
* @noextend This interface is not intended to be extended by clients.
* @noimplement This interface is not intended to be implemented by clients.
+ * @deprecated Use {@link StrongReferencePolicyEvent} instead.
+ * @apiviz.exclude
*/
- public interface InvalidationNotificationEvent extends IOptionsEvent
+ @Deprecated
+ public interface ReferencePolicyEvent extends StrongReferencePolicyEvent
+ {
+ }
+
+ /**
+ * An {@link IOptionsEvent options event} fired from view {@link CDOView#options() options} when the
+ * {@link Options#setStaleReferenceBehaviour(CDOStaleReferencePolicy) stale reference type} option has changed.
+ *
+ * @since 3.0
+ * @noextend This interface is not intended to be extended by clients.
+ * @noimplement This interface is not intended to be implemented by clients.
+ */
+ public interface StaleReferencePolicyEvent extends IOptionsEvent
{
}
diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/object/CDONotificationBuilder.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/object/CDONotificationBuilder.java
index 5efff5015a..131e5e0640 100644
--- a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/object/CDONotificationBuilder.java
+++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/object/CDONotificationBuilder.java
@@ -13,6 +13,7 @@ package org.eclipse.emf.internal.cdo.object;
import org.eclipse.emf.cdo.CDOObject;
import org.eclipse.emf.cdo.common.id.CDOID;
+import org.eclipse.emf.cdo.common.revision.CDORevisionFactory;
import org.eclipse.emf.cdo.common.revision.delta.CDOAddFeatureDelta;
import org.eclipse.emf.cdo.common.revision.delta.CDOClearFeatureDelta;
import org.eclipse.emf.cdo.common.revision.delta.CDOContainerFeatureDelta;
@@ -31,6 +32,7 @@ import org.eclipse.emf.common.notify.impl.NotificationChainImpl;
import org.eclipse.emf.ecore.EStructuralFeature;
import org.eclipse.emf.ecore.EcorePackage;
import org.eclipse.emf.ecore.InternalEObject;
+import org.eclipse.emf.spi.cdo.InternalCDOObject;
import java.util.ArrayList;
import java.util.List;
@@ -87,6 +89,13 @@ public class CDONotificationBuilder extends CDOFeatureDeltaVisitorImpl
return notification;
}
+ public synchronized NotificationChain buildNotification(InternalCDOObject object, InternalCDORevision newRevision)
+ {
+ InternalCDORevision oldRevision = (InternalCDORevision)CDORevisionFactory.DEFAULT.createRevision(object.eClass());
+ CDORevisionDelta revisionDelta = newRevision.compare(oldRevision);
+ return buildNotification(object, oldRevision, revisionDelta, null);
+ }
+
@Override
public void visit(CDOMoveFeatureDelta delta)
{
diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/view/CDOStateMachine.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/view/CDOStateMachine.java
index 80ea51a1a4..5ec2d91478 100644
--- a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/view/CDOStateMachine.java
+++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/view/CDOStateMachine.java
@@ -23,6 +23,7 @@ import org.eclipse.emf.cdo.common.revision.CDORevisionKey;
import org.eclipse.emf.cdo.common.revision.CDORevisionUtil;
import org.eclipse.emf.cdo.common.revision.delta.CDOFeatureDelta;
import org.eclipse.emf.cdo.common.revision.delta.CDORevisionDelta;
+import org.eclipse.emf.cdo.common.util.PartialCollectionLoadingNotSupportedException;
import org.eclipse.emf.cdo.spi.common.model.InternalCDOPackageInfo;
import org.eclipse.emf.cdo.spi.common.revision.InternalCDORevision;
import org.eclipse.emf.cdo.spi.common.revision.InternalCDORevisionCache;
@@ -33,12 +34,14 @@ import org.eclipse.emf.cdo.view.CDOView;
import org.eclipse.emf.internal.cdo.CDOObjectImpl;
import org.eclipse.emf.internal.cdo.bundle.OM;
+import org.eclipse.emf.internal.cdo.object.CDONotificationBuilder;
import org.eclipse.net4j.util.collection.Pair;
import org.eclipse.net4j.util.fsm.FiniteStateMachine;
import org.eclipse.net4j.util.fsm.ITransition;
import org.eclipse.net4j.util.om.trace.ContextTracer;
+import org.eclipse.emf.common.notify.NotificationChain;
import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.EPackage;
@@ -962,6 +965,27 @@ public final class CDOStateMachine extends FiniteStateMachine<CDOState, CDOEvent
changeState(object, CDOState.CLEAN);
object.cdoInternalPostLoad();
+ if (view.options().isLoadNotificationEnabled())
+ {
+ try
+ {
+ CDONotificationBuilder builder = new CDONotificationBuilder(view);
+
+ NotificationChain notification = builder.buildNotification(object, revision);
+ if (notification != null)
+ {
+ notification.dispatch();
+ }
+ }
+ catch (PartialCollectionLoadingNotSupportedException ex)
+ {
+ if (TRACER.isEnabled())
+ {
+ TRACER.trace(ex);
+ }
+ }
+ }
+
if (forWrite)
{
INSTANCE.writeWithoutViewLock(object, (CDOFeatureDelta)delta);
diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/view/CDOViewImpl.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/view/CDOViewImpl.java
index 3524857769..4988ba0e5f 100644
--- a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/view/CDOViewImpl.java
+++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/view/CDOViewImpl.java
@@ -1622,6 +1622,8 @@ public class CDOViewImpl extends AbstractCDOView
*/
protected class OptionsImpl extends Notifier implements Options
{
+ private boolean loadNotificationEnabled;
+
private boolean invalidationNotificationEnabled;
private CDOInvalidationPolicy invalidationPolicy = CDOInvalidationPolicy.DEFAULT;
@@ -1647,23 +1649,23 @@ public class CDOViewImpl extends AbstractCDOView
return CDOViewImpl.this;
}
- public CDOInvalidationPolicy getInvalidationPolicy()
+ public boolean isLoadNotificationEnabled()
{
synchronized (CDOViewImpl.this)
{
- return invalidationPolicy;
+ return loadNotificationEnabled;
}
}
- public void setInvalidationPolicy(CDOInvalidationPolicy policy)
+ public void setLoadNotificationEnabled(boolean enabled)
{
IEvent event = null;
synchronized (CDOViewImpl.this)
{
- if (invalidationPolicy != policy)
+ if (loadNotificationEnabled != enabled)
{
- invalidationPolicy = policy;
- event = new InvalidationPolicyEventImpl();
+ loadNotificationEnabled = enabled;
+ event = new LoadNotificationEventImpl();
}
}
@@ -1693,6 +1695,29 @@ public class CDOViewImpl extends AbstractCDOView
fireEvent(event);
}
+ public CDOInvalidationPolicy getInvalidationPolicy()
+ {
+ synchronized (CDOViewImpl.this)
+ {
+ return invalidationPolicy;
+ }
+ }
+
+ public void setInvalidationPolicy(CDOInvalidationPolicy policy)
+ {
+ IEvent event = null;
+ synchronized (CDOViewImpl.this)
+ {
+ if (invalidationPolicy != policy)
+ {
+ invalidationPolicy = policy;
+ event = new InvalidationPolicyEventImpl();
+ }
+ }
+
+ fireEvent(event);
+ }
+
public boolean isLockNotificationEnabled()
{
return lockNotificationsEnabled;
@@ -1987,6 +2012,19 @@ public class CDOViewImpl extends AbstractCDOView
/**
* @author Eike Stepper
*/
+ private final class LoadNotificationEventImpl extends OptionsEvent implements LoadNotificationEvent
+ {
+ private static final long serialVersionUID = 1L;
+
+ public LoadNotificationEventImpl()
+ {
+ super(OptionsImpl.this);
+ }
+ }
+
+ /**
+ * @author Eike Stepper
+ */
private final class InvalidationNotificationEventImpl extends OptionsEvent implements InvalidationNotificationEvent
{
private static final long serialVersionUID = 1L;

Back to the top