Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEike Stepper2013-02-10 00:17:48 -0500
committerEike Stepper2013-02-13 14:58:01 -0500
commitacebc65bb4a2b2279239455c51bf5f094adf8d39 (patch)
tree4504031edeae969b4065ebc2cbfab99ddb692b9d
parent5d8a3a502af57da4c700d80d2134fa3a0da28cc3 (diff)
downloadcdo-acebc65bb4a2b2279239455c51bf5f094adf8d39.tar.gz
cdo-acebc65bb4a2b2279239455c51bf5f094adf8d39.tar.xz
cdo-acebc65bb4a2b2279239455c51bf5f094adf8d39.zip
[400387] Optimize the storage of view, state, id and revision per
CDOObject https://bugs.eclipse.org/bugs/show_bug.cgi?id=400387
-rw-r--r--plugins/org.eclipse.emf.cdo/.settings/.api_filters26
-rw-r--r--plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOObjectImpl.java174
-rw-r--r--plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/object/CDOExternalObject.java21
-rw-r--r--plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/object/CDOLegacyAdapter.java16
-rw-r--r--plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/object/CDOLegacyWrapper.java145
-rw-r--r--plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/object/CDOObjectWrapperBase.java47
-rw-r--r--plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/view/AbstractCDOView.java7
-rw-r--r--plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/view/CDOStateMachine.java3
-rw-r--r--plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/spi/cdo/InternalCDOObject.java4
-rw-r--r--plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/spi/cdo/InternalCDOView.java60
10 files changed, 351 insertions, 152 deletions
diff --git a/plugins/org.eclipse.emf.cdo/.settings/.api_filters b/plugins/org.eclipse.emf.cdo/.settings/.api_filters
index 0df439f080..e5585928e9 100644
--- a/plugins/org.eclipse.emf.cdo/.settings/.api_filters
+++ b/plugins/org.eclipse.emf.cdo/.settings/.api_filters
@@ -162,6 +162,32 @@
</message_arguments>
</filter>
</resource>
+ <resource path="src/org/eclipse/emf/internal/cdo/CDOObjectImpl.java" type="org.eclipse.emf.internal.cdo.CDOObjectImpl">
+ <filter id="421654647">
+ <message_arguments>
+ <message_argument value="org.eclipse.emf.internal.cdo.CDOObjectImpl"/>
+ <message_argument value="cdoID()"/>
+ </message_arguments>
+ </filter>
+ <filter id="421654647">
+ <message_arguments>
+ <message_argument value="org.eclipse.emf.internal.cdo.CDOObjectImpl"/>
+ <message_argument value="cdoRevision()"/>
+ </message_arguments>
+ </filter>
+ <filter id="421654647">
+ <message_arguments>
+ <message_argument value="org.eclipse.emf.internal.cdo.CDOObjectImpl"/>
+ <message_argument value="cdoState()"/>
+ </message_arguments>
+ </filter>
+ <filter id="421654647">
+ <message_arguments>
+ <message_argument value="org.eclipse.emf.internal.cdo.CDOObjectImpl"/>
+ <message_argument value="cdoView()"/>
+ </message_arguments>
+ </filter>
+ </resource>
<resource path="src/org/eclipse/emf/internal/cdo/object/CDOObjectReferenceImpl.java" type="org.eclipse.emf.internal.cdo.object.CDOObjectReferenceImpl">
<filter id="574660632">
<message_arguments>
diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOObjectImpl.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOObjectImpl.java
index a4e2cb1856..660e3d0d86 100644
--- a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOObjectImpl.java
+++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOObjectImpl.java
@@ -66,6 +66,7 @@ import org.eclipse.emf.spi.cdo.FSMUtil;
import org.eclipse.emf.spi.cdo.InternalCDOLoadable;
import org.eclipse.emf.spi.cdo.InternalCDOObject;
import org.eclipse.emf.spi.cdo.InternalCDOView;
+import org.eclipse.emf.spi.cdo.InternalCDOView.ViewAndState;
import java.util.Collection;
import java.util.Collections;
@@ -82,13 +83,18 @@ public class CDOObjectImpl extends EStoreEObjectImpl implements InternalCDOObjec
{
private static final ContextTracer TRACER = new ContextTracer(OM.DEBUG_OBJECT, CDOObjectImpl.class);
- private CDOID id;
-
- private CDOState state;
-
- private InternalCDOView view;
+ /**
+ * Optimized storage of {@link CDOObject#cdoView()} and {@link CDOObject#cdoState()}.
+ *
+ * @see ViewAndState
+ */
+ private ViewAndState viewAndState = ViewAndState.TRANSIENT;
- private InternalCDORevision revision;
+ /**
+ * Optimized storage of {@link CDOObject#cdoID()} and {@link CDOObject#cdoRevision()}.
+ * The idea is that, if a revision is set, the object's ID is equal to the {@link CDORevision revision's} ID.
+ */
+ private Object idOrRevision;
/**
* CDO uses this list instead of eSettings for transient objects. EMF uses eSettings as cache. CDO deactivates the
@@ -100,35 +106,48 @@ public class CDOObjectImpl extends EStoreEObjectImpl implements InternalCDOObjec
public CDOObjectImpl()
{
- state = CDOState.TRANSIENT;
- eContainer = null;
- cdoSettings = null;
+ eContainer = null; // Overwrite base class initialization
}
- public CDOID cdoID()
+ public final CDOState cdoState()
{
- return id;
- }
-
- public CDOState cdoState()
- {
- return state;
+ return viewAndState.state;
}
/**
* @since 2.0
*/
- public InternalCDORevision cdoRevision()
+ public final InternalCDOView cdoView()
{
- return revision;
+ return viewAndState.view;
+ }
+
+ public final CDOID cdoID()
+ {
+ if (idOrRevision == null)
+ {
+ return null;
+ }
+
+ if (idOrRevision instanceof CDOID)
+ {
+ return (CDOID)idOrRevision;
+ }
+
+ return ((InternalCDORevision)idOrRevision).getID();
}
/**
* @since 2.0
*/
- public InternalCDOView cdoView()
+ public final InternalCDORevision cdoRevision()
{
- return view;
+ if (idOrRevision instanceof InternalCDORevision)
+ {
+ return (InternalCDORevision)idOrRevision;
+ }
+
+ return null;
}
public CDOResourceImpl cdoResource()
@@ -161,7 +180,8 @@ public class CDOObjectImpl extends EStoreEObjectImpl implements InternalCDOObjec
*/
public void cdoPrefetch(int depth)
{
- view.prefetchRevisions(id, depth);
+ CDOID id = cdoID();
+ viewAndState.view.prefetchRevisions(id, depth);
}
public void cdoReload()
@@ -174,7 +194,7 @@ public class CDOObjectImpl extends EStoreEObjectImpl implements InternalCDOObjec
*/
public CDOObjectHistory cdoHistory()
{
- return view.getHistory(this);
+ return viewAndState.view.getHistory(this);
}
/**
@@ -225,19 +245,9 @@ public class CDOObjectImpl extends EStoreEObjectImpl implements InternalCDOObjec
return getLockState(this);
}
- public void cdoInternalSetID(CDOID id)
- {
- if (TRACER.isEnabled())
- {
- TRACER.format("Setting ID: {0}", id); //$NON-NLS-1$
- }
-
- this.id = id;
- }
-
public CDOState cdoInternalSetState(CDOState state)
{
- CDOState oldState = this.state;
+ CDOState oldState = viewAndState.state;
if (oldState != state)
{
if (TRACER.isEnabled())
@@ -245,10 +255,10 @@ public class CDOObjectImpl extends EStoreEObjectImpl implements InternalCDOObjec
TRACER.format("Setting state {0} for {1}", state, this); //$NON-NLS-1$
}
- this.state = state;
- if (view != null)
+ viewAndState = viewAndState.getViewAndState(state);
+ if (viewAndState.view != null)
{
- view.handleObjectStateChanged(this, oldState, state);
+ viewAndState.view.handleObjectStateChanged(this, oldState, state);
}
return oldState;
@@ -260,29 +270,58 @@ public class CDOObjectImpl extends EStoreEObjectImpl implements InternalCDOObjec
/**
* @since 2.0
*/
- public void cdoInternalSetRevision(CDORevision revision)
+ public void cdoInternalSetView(CDOView view)
+ {
+ InternalCDOView newView = (InternalCDOView)view;
+ if (newView != null)
+ {
+ viewAndState = newView.getViewAndState(viewAndState.state);
+ }
+ else
+ {
+ viewAndState = ViewAndState.TRANSIENT.getViewAndState(viewAndState.state);
+ }
+
+ if (viewAndState.view != null)
+ {
+ eSetStore(viewAndState.view.getStore());
+ }
+ else
+ {
+ eSetStore(null);
+ }
+ }
+
+ public void cdoInternalSetID(CDOID id)
{
if (TRACER.isEnabled())
{
- TRACER.format("Setting revision: {0}", revision); //$NON-NLS-1$
+ TRACER.format("Setting ID: {0}", id); //$NON-NLS-1$
}
- this.revision = (InternalCDORevision)revision;
+ if (idOrRevision == null || id == null)
+ {
+ idOrRevision = id;
+ }
}
/**
* @since 2.0
*/
- public void cdoInternalSetView(CDOView view)
+ public void cdoInternalSetRevision(CDORevision revision)
{
- this.view = (InternalCDOView)view;
- if (this.view != null)
+ if (TRACER.isEnabled())
+ {
+ TRACER.format("Setting revision: {0}", revision); //$NON-NLS-1$
+ }
+
+ if (revision == null)
{
- eSetStore(this.view.getStore());
+ idOrRevision = cdoID();
}
else
{
- eSetStore(null);
+ idOrRevision = revision;
}
}
@@ -320,9 +359,10 @@ public class CDOObjectImpl extends EStoreEObjectImpl implements InternalCDOObjec
{
// Make sure transient features are kept but persisted values are not cached.
EClass eClass = eClass();
- for (int i = 0; i < eClass.getFeatureCount(); i++)
+ int featureCount = eClass.getFeatureCount();
+ for (int i = 0; i < featureCount; i++)
{
- EStructuralFeature eFeature = cdoInternalDynamicFeature(i);
+ EStructuralFeature eFeature = eClass.getEStructuralFeature(i);
// We need to keep the existing list if possible.
if (EMFUtil.isPersistent(eFeature) && eSettings[i] instanceof InternalCDOLoadable)
@@ -348,7 +388,8 @@ public class CDOObjectImpl extends EStoreEObjectImpl implements InternalCDOObjec
TRACER.format("Populating revision for {0}", this); //$NON-NLS-1$
}
- revision.setContainerID(eContainer == null ? CDOID.NULL : view.convertObjectToID(eContainer, true));
+ InternalCDORevision revision = cdoRevision();
+ revision.setContainerID(eContainer == null ? CDOID.NULL : viewAndState.view.convertObjectToID(eContainer, true));
revision.setContainingFeatureID(eContainerFeatureID);
Resource directResource = eDirectResource();
@@ -361,12 +402,13 @@ public class CDOObjectImpl extends EStoreEObjectImpl implements InternalCDOObjec
if (cdoSettings != null)
{
EClass eClass = eClass();
- for (int i = 0; i < eClass.getFeatureCount(); i++)
+ int featureCount = eClass.getFeatureCount();
+ for (int i = 0; i < featureCount; i++)
{
- EStructuralFeature eFeature = cdoInternalDynamicFeature(i);
+ EStructuralFeature eFeature = eClass.getEStructuralFeature(i);
if (EMFUtil.isPersistent(eFeature))
{
- instanceToRevisionFeature(view, this, eFeature, cdoSettings[i]);
+ instanceToRevisionFeature(viewAndState.view, this, eFeature, cdoSettings[i]);
}
}
@@ -399,13 +441,15 @@ public class CDOObjectImpl extends EStoreEObjectImpl implements InternalCDOObjec
eContainer = store.getContainer(this);
eContainerFeatureID = store.getContainingFeatureID(this);
- // Ensure that the internal eSettings array is initialized;
+ // Ensure that the internal cdoSettings array is initialized;
resetSettings();
+ InternalCDORevision revision = cdoRevision();
EClass eClass = eClass();
- for (int i = 0; i < eClass.getFeatureCount(); i++)
+ int featureCount = eClass.getFeatureCount();
+ for (int i = 0; i < featureCount; i++)
{
- EStructuralFeature eFeature = cdoInternalDynamicFeature(i);
+ EStructuralFeature eFeature = eClass.getEStructuralFeature(i);
if (EMFUtil.isPersistent(eFeature))
{
revisionToInstanceFeature(this, revision, eFeature);
@@ -431,9 +475,10 @@ public class CDOObjectImpl extends EStoreEObjectImpl implements InternalCDOObjec
return this;
}
+ @Deprecated
public EStructuralFeature cdoInternalDynamicFeature(int dynamicFeatureID)
{
- return eDynamicFeature(dynamicFeatureID);
+ throw new UnsupportedOperationException();
}
/**
@@ -452,12 +497,12 @@ public class CDOObjectImpl extends EStoreEObjectImpl implements InternalCDOObjec
@Override
protected void didAdd(int index, Adapter newObject)
{
- if (view == null || view.isActive())
+ if (viewAndState.view == null || viewAndState.view.isActive())
{
super.didAdd(index, newObject);
if (!FSMUtil.isTransient(CDOObjectImpl.this))
{
- view.handleAddAdapter(CDOObjectImpl.this, newObject);
+ viewAndState.view.handleAddAdapter(CDOObjectImpl.this, newObject);
}
}
}
@@ -465,12 +510,12 @@ public class CDOObjectImpl extends EStoreEObjectImpl implements InternalCDOObjec
@Override
protected void didRemove(int index, Adapter oldObject)
{
- if (view == null || view.isActive())
+ if (viewAndState.view == null || viewAndState.view.isActive())
{
super.didRemove(index, oldObject);
if (!FSMUtil.isTransient(CDOObjectImpl.this))
{
- view.handleRemoveAdapter(CDOObjectImpl.this, oldObject);
+ viewAndState.view.handleRemoveAdapter(CDOObjectImpl.this, oldObject);
}
}
}
@@ -676,7 +721,7 @@ public class CDOObjectImpl extends EStoreEObjectImpl implements InternalCDOObjec
}
}
- CDOView oldView = view;
+ CDOView oldView = viewAndState.view;
CDOView newView = newResource != null && newResource instanceof CDOResource ? ((CDOResource)newResource).cdoView()
: null;
@@ -739,11 +784,11 @@ public class CDOObjectImpl extends EStoreEObjectImpl implements InternalCDOObjec
{
Resource.Internal oldResource = eDirectResource();
- CDOView oldView = view;
+ CDOView oldView = viewAndState.view;
CDOView newView = resource != null && resource instanceof CDOResource ? ((CDOResource)resource).cdoView() : null;
boolean isSameView;
- if (state == CDOState.NEW)
+ if (viewAndState.state == CDOState.NEW)
{
isSameView = false;
}
@@ -818,6 +863,7 @@ public class CDOObjectImpl extends EStoreEObjectImpl implements InternalCDOObjec
@Override
public String toString()
{
+ CDOID id = cdoID();
if (id == null)
{
return eClass().getName() + "?"; //$NON-NLS-1$
@@ -953,7 +999,7 @@ public class CDOObjectImpl extends EStoreEObjectImpl implements InternalCDOObjec
private CDOStore cdoStore()
{
- return view.getStore();
+ return viewAndState.view.getStore();
}
private void resetSettings()
@@ -1068,8 +1114,8 @@ public class CDOObjectImpl extends EStoreEObjectImpl implements InternalCDOObjec
TRACER.format("Populating feature {0}", feature); //$NON-NLS-1$
}
- PersistenceFilter filter = ((InternalCDOClassInfo)CDOModelUtil.getClassInfo(feature
- .getEContainingClass())).getPersistenceFilter(feature);
+ PersistenceFilter filter = ((InternalCDOClassInfo)CDOModelUtil.getClassInfo(feature.getEContainingClass()))
+ .getPersistenceFilter(feature);
if (filter != null)
{
if (TRACER.isEnabled())
diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/object/CDOExternalObject.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/object/CDOExternalObject.java
index 1c83dc47cf..4aa46bc7c7 100644
--- a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/object/CDOExternalObject.java
+++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/object/CDOExternalObject.java
@@ -13,8 +13,10 @@ package org.eclipse.emf.internal.cdo.object;
import org.eclipse.emf.cdo.CDOLock;
import org.eclipse.emf.cdo.CDOObjectHistory;
import org.eclipse.emf.cdo.CDOState;
+import org.eclipse.emf.cdo.common.id.CDOID;
import org.eclipse.emf.cdo.common.lock.CDOLockState;
import org.eclipse.emf.cdo.common.revision.CDORevision;
+import org.eclipse.emf.cdo.view.CDOView;
import org.eclipse.emf.ecore.InternalEObject;
import org.eclipse.emf.spi.cdo.InternalCDOView;
@@ -24,6 +26,10 @@ import org.eclipse.emf.spi.cdo.InternalCDOView;
*/
public class CDOExternalObject extends CDOObjectWrapperBase
{
+ private InternalCDOView view;
+
+ private CDOID id;
+
public CDOExternalObject(InternalEObject instance, InternalCDOView view)
{
this.instance = instance;
@@ -31,6 +37,21 @@ public class CDOExternalObject extends CDOObjectWrapperBase
id = view.provideCDOID(instance);
}
+ public CDOID cdoID()
+ {
+ return id;
+ }
+
+ public CDOView cdoView()
+ {
+ return view;
+ }
+
+ @Override
+ public void cdoPrefetch(int depth)
+ {
+ }
+
public CDOState cdoState()
{
return CDOState.CLEAN;
diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/object/CDOLegacyAdapter.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/object/CDOLegacyAdapter.java
index 5fd93bef6f..3e0666137f 100644
--- a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/object/CDOLegacyAdapter.java
+++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/object/CDOLegacyAdapter.java
@@ -84,7 +84,7 @@ public class CDOLegacyAdapter extends CDOLegacyWrapper implements Adapter.Intern
}
EStructuralFeature feature = (EStructuralFeature)msg.getFeature();
- if (view == null || feature == null || !(view instanceof CDOTransaction))
+ if (viewAndState.view == null || feature == null || !(viewAndState.view instanceof CDOTransaction))
{
return;
}
@@ -141,7 +141,7 @@ public class CDOLegacyAdapter extends CDOLegacyWrapper implements Adapter.Intern
protected void notifySet(EStructuralFeature feature, int position, Object oldValue, Object newValue)
{
- CDOStore store = view.getStore();
+ CDOStore store = viewAndState.view.getStore();
store.set(instance, feature, position, newValue);
if (feature instanceof EReference)
{
@@ -165,7 +165,7 @@ public class CDOLegacyAdapter extends CDOLegacyWrapper implements Adapter.Intern
protected void notifyUnset(EStructuralFeature feature, Object oldValue)
{
- CDOStore store = view.getStore();
+ CDOStore store = viewAndState.view.getStore();
if (feature instanceof EReference)
{
EReference reference = (EReference)feature;
@@ -188,13 +188,13 @@ public class CDOLegacyAdapter extends CDOLegacyWrapper implements Adapter.Intern
protected void notifyMove(EStructuralFeature feature, int position, Object oldValue)
{
- CDOStore store = view.getStore();
+ CDOStore store = viewAndState.view.getStore();
store.move(instance, feature, position, (Integer)oldValue);
}
protected void notifyAdd(EStructuralFeature feature, int position, Object newValue)
{
- CDOStore store = view.getStore();
+ CDOStore store = viewAndState.view.getStore();
store.add(instance, feature, position, newValue);
if (newValue != null && feature instanceof EReference)
{
@@ -209,7 +209,7 @@ public class CDOLegacyAdapter extends CDOLegacyWrapper implements Adapter.Intern
protected void notifyAddMany(EStructuralFeature feature, int position, Object newValue)
{
- CDOStore store = view.getStore();
+ CDOStore store = viewAndState.view.getStore();
int pos = position;
@SuppressWarnings("unchecked")
List<Object> list = (List<Object>)newValue;
@@ -230,7 +230,7 @@ public class CDOLegacyAdapter extends CDOLegacyWrapper implements Adapter.Intern
protected void notifyRemove(EStructuralFeature feature, int position)
{
- CDOStore store = view.getStore();
+ CDOStore store = viewAndState.view.getStore();
Object oldChild = store.remove(instance, feature, position);
if (oldChild instanceof InternalEObject)
@@ -249,7 +249,7 @@ public class CDOLegacyAdapter extends CDOLegacyWrapper implements Adapter.Intern
protected void notifyRemoveMany(EStructuralFeature feature, int[] positions)
{
- CDOStore store = view.getStore();
+ CDOStore store = viewAndState.view.getStore();
if (positions == null)
{
diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/object/CDOLegacyWrapper.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/object/CDOLegacyWrapper.java
index 6ef309baba..1b55487234 100644
--- a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/object/CDOLegacyWrapper.java
+++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/object/CDOLegacyWrapper.java
@@ -29,6 +29,7 @@ import org.eclipse.emf.cdo.eresource.CDOResource;
import org.eclipse.emf.cdo.eresource.impl.CDOResourceImpl;
import org.eclipse.emf.cdo.spi.common.revision.InternalCDORevision;
import org.eclipse.emf.cdo.util.CDOUtil;
+import org.eclipse.emf.cdo.view.CDOView;
import org.eclipse.emf.internal.cdo.CDOObjectImpl;
import org.eclipse.emf.internal.cdo.bundle.OM;
@@ -55,6 +56,7 @@ import org.eclipse.emf.spi.cdo.FSMUtil;
import org.eclipse.emf.spi.cdo.InternalCDOObject;
import org.eclipse.emf.spi.cdo.InternalCDOResource;
import org.eclipse.emf.spi.cdo.InternalCDOView;
+import org.eclipse.emf.spi.cdo.InternalCDOView.ViewAndState;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationHandler;
@@ -94,9 +96,9 @@ public abstract class CDOLegacyWrapper extends CDOObjectWrapper
}
};
- protected CDOState state;
+ protected ViewAndState viewAndState;
- protected InternalCDORevision revision;
+ protected Object idOrRevision;
/**
* It could happen that while <i>revisionToInstance()</i> is executed externally the <i>internalPostLoad()</i> method
@@ -111,17 +113,73 @@ public abstract class CDOLegacyWrapper extends CDOObjectWrapper
public CDOLegacyWrapper(InternalEObject instance)
{
this.instance = instance;
- state = CDOState.TRANSIENT;
+ viewAndState = ViewAndState.TRANSIENT;
+ }
+
+ public CDOID cdoID()
+ {
+ if (idOrRevision == null)
+ {
+ return null;
+ }
+
+ if (idOrRevision instanceof CDOID)
+ {
+ return (CDOID)idOrRevision;
+ }
+
+ return ((InternalCDORevision)idOrRevision).getID();
+ }
+
+ public InternalCDOView cdoView()
+ {
+ return viewAndState.view;
+ }
+
+ public void cdoInternalSetID(CDOID id)
+ {
+ if (TRACER.isEnabled())
+ {
+ TRACER.format("Setting ID: {0} for {1}", id, instance); //$NON-NLS-1$
+ }
+
+ if (idOrRevision == null || id == null)
+ {
+ idOrRevision = id;
+ }
+ }
+
+ public void cdoInternalSetView(CDOView view)
+ {
+ if (TRACER.isEnabled())
+ {
+ TRACER.format("Setting view: {0} for {1}", view, instance); //$NON-NLS-1$
+ }
+
+ InternalCDOView newView = (InternalCDOView)view;
+ if (newView != null)
+ {
+ viewAndState = newView.getViewAndState(viewAndState.state);
+ }
+ else
+ {
+ viewAndState = ViewAndState.TRANSIENT.getViewAndState(viewAndState.state);
+ }
}
public CDOState cdoState()
{
- return state;
+ return viewAndState.state;
}
public InternalCDORevision cdoRevision()
{
- return revision;
+ if (idOrRevision instanceof InternalCDORevision)
+ {
+ return (InternalCDORevision)idOrRevision;
+ }
+
+ return null;
}
@Override
@@ -138,25 +196,25 @@ public abstract class CDOLegacyWrapper extends CDOObjectWrapper
public CDOObjectHistory cdoHistory()
{
- return view.getHistory(this);
+ return viewAndState.view.getHistory(this);
}
public CDOState cdoInternalSetState(CDOState state)
{
- if (this.state != state)
+ CDOState oldState = viewAndState.state;
+ if (oldState != state)
{
if (TRACER.isEnabled())
{
TRACER.format("Setting state {0} for {1}", state, this); //$NON-NLS-1$
}
- CDOState oldState = this.state;
- this.state = state;
+ viewAndState = viewAndState.getViewAndState(state);
adjustEProxy();
- if (view != null)
+ if (viewAndState.view != null)
{
- view.handleObjectStateChanged(this, oldState, state);
+ viewAndState.view.handleObjectStateChanged(this, oldState, state);
}
return oldState;
@@ -172,7 +230,14 @@ public abstract class CDOLegacyWrapper extends CDOObjectWrapper
TRACER.trace("Setting revision: " + revision); //$NON-NLS-1$
}
- this.revision = (InternalCDORevision)revision;
+ if (revision == null)
+ {
+ idOrRevision = cdoID();
+ }
+ else
+ {
+ idOrRevision = revision;
+ }
}
public void cdoInternalPostAttach()
@@ -183,8 +248,8 @@ public abstract class CDOLegacyWrapper extends CDOObjectWrapper
{
if (!(adapter instanceof CDOObjectWrapper))
{
- view.handleAddAdapter(this, adapter);
- view.subscribe(this, adapter);
+ viewAndState.view.handleAddAdapter(this, adapter);
+ viewAndState.view.subscribe(this, adapter);
}
}
}
@@ -198,6 +263,7 @@ public abstract class CDOLegacyWrapper extends CDOObjectWrapper
}
// This loop adjusts the opposite wrapper objects to support dangling references. See Bugzilla_251263_Test
+ InternalCDORevision revision = cdoRevision();
EClass eClass = revision.getEClass();
EStructuralFeature[] allPersistentFeatures = CDOModelUtil.getAllPersistentFeatures(eClass);
for (EStructuralFeature feature : allPersistentFeatures)
@@ -248,6 +314,7 @@ public abstract class CDOLegacyWrapper extends CDOObjectWrapper
// If the container is not an legacy Object the system will get no information
instanceToRevisionContainment();
+ InternalCDORevision revision = cdoRevision();
EClass eClass = revision.getEClass();
EStructuralFeature[] allPersistentFeatures = CDOModelUtil.getAllPersistentFeatures(eClass);
for (EStructuralFeature feature : allPersistentFeatures)
@@ -301,6 +368,7 @@ public abstract class CDOLegacyWrapper extends CDOObjectWrapper
protected void instanceToRevision()
{
+ InternalCDORevision revision = cdoRevision();
if (TRACER.isEnabled())
{
TRACER.format("Transfering instance to revision: {0} --> {1}", instance, revision); //$NON-NLS-1$
@@ -322,6 +390,8 @@ public abstract class CDOLegacyWrapper extends CDOObjectWrapper
protected void instanceToRevisionContainment()
{
+ InternalCDORevision revision = cdoRevision();
+
CDOResource resource = (CDOResource)getInstanceResource(instance);
revision.setResourceID(resource == null ? CDOID.NULL : resource.cdoID());
@@ -333,7 +403,7 @@ public abstract class CDOLegacyWrapper extends CDOObjectWrapper
}
else
{
- CDOObject cdoContainer = FSMUtil.adapt(eContainer, view);
+ CDOObject cdoContainer = FSMUtil.adapt(eContainer, viewAndState.view);
revision.setContainerID(cdoContainer);
revision.setContainingFeatureID(getInstanceContainerFeatureID(instance));
}
@@ -344,7 +414,7 @@ public abstract class CDOLegacyWrapper extends CDOObjectWrapper
if (isSetInstanceValue(instance, feature))
{
Object instanceValue = getInstanceValue(instance, feature);
- CDOObjectImpl.instanceToRevisionFeature(view, this, feature, instanceValue);
+ CDOObjectImpl.instanceToRevisionFeature(viewAndState.view, this, feature, instanceValue);
}
}
@@ -357,6 +427,7 @@ public abstract class CDOLegacyWrapper extends CDOObjectWrapper
}
underConstruction = true;
+ InternalCDORevision revision = cdoRevision();
if (TRACER.isEnabled())
{
@@ -376,7 +447,7 @@ public abstract class CDOLegacyWrapper extends CDOObjectWrapper
{
registerWrapper(this);
counter.increment();
- view.registerObject(this);
+ viewAndState.view.registerObject(this);
revisionToInstanceResource();
revisionToInstanceContainer();
@@ -428,6 +499,7 @@ public abstract class CDOLegacyWrapper extends CDOObjectWrapper
*/
protected void revisionToInstanceContainer()
{
+ InternalCDORevision revision = cdoRevision();
CDOPermission permission = revision.getPermission();
if (permission != CDOPermission.WRITE)
{
@@ -437,7 +509,7 @@ public abstract class CDOLegacyWrapper extends CDOObjectWrapper
try
{
Object containerID = revision.getContainerID();
- InternalEObject container = getEObjectFromPotentialID(view, null, containerID);
+ InternalEObject container = getEObjectFromPotentialID(viewAndState.view, null, containerID);
EObject oldContainer = instance.eContainer();
if (oldContainer != container)
{
@@ -458,14 +530,15 @@ public abstract class CDOLegacyWrapper extends CDOObjectWrapper
*/
protected void revisionToInstanceResource()
{
+ InternalCDORevision revision = cdoRevision();
if (revision != null)
{
CDOID resourceID = revision.getResourceID();
- InternalEObject resource = getEObjectFromPotentialID(view, null, resourceID);
+ InternalEObject resource = getEObjectFromPotentialID(viewAndState.view, null, resourceID);
setInstanceResource((Resource.Internal)resource);
if (resource != null)
{
- view.registerObject((InternalCDOObject)resource);
+ viewAndState.view.registerObject((InternalCDOObject)resource);
}
}
}
@@ -475,7 +548,7 @@ public abstract class CDOLegacyWrapper extends CDOObjectWrapper
*/
protected void revisionToInstanceFeature(EStructuralFeature feature)
{
- if (feature.isUnsettable() && !view.getStore().isSet(this, feature))
+ if (feature.isUnsettable() && !viewAndState.view.getStore().isSet(this, feature))
{
// Clarify if this is sufficient for bidirectional references
instance.eUnset(feature);
@@ -486,11 +559,13 @@ public abstract class CDOLegacyWrapper extends CDOObjectWrapper
{
if (TRACER.isEnabled())
{
- TRACER.format("State of Object (" + this + "/" + instance + ") is : " + state); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ TRACER.format("State of Object (" + this + "/" + instance + ") is : " + viewAndState.state); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
}
- if (state == CDOState.CLEAN || state == CDOState.PROXY || state == CDOState.NEW || state == CDOState.DIRTY)
+ if (viewAndState.state == CDOState.CLEAN || viewAndState.state == CDOState.PROXY
+ || viewAndState.state == CDOState.NEW || viewAndState.state == CDOState.DIRTY)
{
+ InternalCDORevision revision = cdoRevision();
int size = revision.size(feature);
@SuppressWarnings("unchecked")
@@ -625,6 +700,7 @@ public abstract class CDOLegacyWrapper extends CDOObjectWrapper
*/
private Object getValueFromRevision(EStructuralFeature feature, int index)
{
+ InternalCDORevision revision = cdoRevision();
Object object = revision.get(feature, index);
if (object == null)
{
@@ -635,7 +711,7 @@ public abstract class CDOLegacyWrapper extends CDOObjectWrapper
{
// Resolve proxy
CDOElementProxy proxy = (CDOElementProxy)object;
- object = view.getSession().resolveElementProxy(revision, feature, index, proxy.getIndex());
+ object = viewAndState.view.getSession().resolveElementProxy(revision, feature, index, proxy.getIndex());
}
if (object instanceof CDOLegacyWrapper)
@@ -644,7 +720,7 @@ public abstract class CDOLegacyWrapper extends CDOObjectWrapper
}
CDOType type = CDOModelUtil.getType(feature.getEType());
- object = view.getStore().convertToEMF(instance, revision, feature, index, object);
+ object = viewAndState.view.getStore().convertToEMF(instance, revision, feature, index, object);
if (type == CDOType.OBJECT)
{
@@ -664,11 +740,11 @@ public abstract class CDOLegacyWrapper extends CDOObjectWrapper
if (id.isExternal())
{
- object = view.getResourceSet().getEObject(URI.createURI(id.toURIFragment()), true);
+ object = viewAndState.view.getResourceSet().getEObject(URI.createURI(id.toURIFragment()), true);
}
else
{
- object = view.getObject(id);
+ object = viewAndState.view.getObject(id);
}
if (object instanceof CDOObjectWrapper)
@@ -713,12 +789,12 @@ public abstract class CDOLegacyWrapper extends CDOObjectWrapper
if (id.isExternal())
{
URI uri = URI.createURI(id.toURIFragment());
- InternalEObject eObject = (InternalEObject)view.getResourceSet().getEObject(uri, true);
+ InternalEObject eObject = (InternalEObject)viewAndState.view.getResourceSet().getEObject(uri, true);
return eObject;
}
boolean loadOnDemand = feature == null;
- potentialID = view.getObject(id, loadOnDemand);
+ potentialID = viewAndState.view.getObject(id, loadOnDemand);
if (potentialID == null && !loadOnDemand)
{
return createProxy(view, feature, id);
@@ -774,6 +850,7 @@ public abstract class CDOLegacyWrapper extends CDOObjectWrapper
*/
protected void resolveAllProxies()
{
+ InternalCDORevision revision = cdoRevision();
EClass eClass = revision.getEClass();
EStructuralFeature[] allPersistentFeatures = CDOModelUtil.getAllPersistentFeatures(eClass);
for (EStructuralFeature feature : allPersistentFeatures)
@@ -812,7 +889,7 @@ public abstract class CDOLegacyWrapper extends CDOObjectWrapper
if (element instanceof LegacyProxy)
{
CDOID id = ((LegacyProxy)element).getID();
- InternalCDOObject resolved = (InternalCDOObject)view.getObject(id);
+ InternalCDOObject resolved = (InternalCDOObject)viewAndState.view.getObject(id);
InternalEObject instance = resolved.cdoInternalInstance();
// TODO LEGACY
@@ -845,7 +922,7 @@ public abstract class CDOLegacyWrapper extends CDOObjectWrapper
if (value instanceof LegacyProxy)
{
CDOID id = ((LegacyProxy)value).getID();
- InternalCDOObject resolved = (InternalCDOObject)view.getObject(id);
+ InternalCDOObject resolved = (InternalCDOObject)viewAndState.view.getObject(id);
InternalEObject instance = resolved.cdoInternalInstance();
setInstanceValue(instance, feature, instance);
}
@@ -858,11 +935,11 @@ public abstract class CDOLegacyWrapper extends CDOObjectWrapper
// Setting eProxyURI is necessary to prevent content adapters from
// loading the whole content tree.
// TODO Does not have the desired effect ;-( see CDOEditor.createModel()
- if (state == CDOState.PROXY)
+ if (viewAndState.state == CDOState.PROXY)
{
if (!instance.eIsProxy())
{
- URI uri = URI.createURI(CDOProtocolConstants.PROTOCOL_NAME + ":proxy#" + id); //$NON-NLS-1$
+ URI uri = URI.createURI(CDOProtocolConstants.PROTOCOL_NAME + ":proxy#" + cdoID()); //$NON-NLS-1$
if (TRACER.isEnabled())
{
TRACER.format("Setting proxyURI {0} for {1}", uri, instance); //$NON-NLS-1$
@@ -989,7 +1066,7 @@ public abstract class CDOLegacyWrapper extends CDOObjectWrapper
InternalCDOView view = oppositeCDOObject.cdoView();
if (view != null)
{
- CDOStore store = view.getStore();
+ CDOStore store = viewAndState.view.getStore();
if (store != null)
{
if (oppositeReference.isMany())
diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/object/CDOObjectWrapperBase.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/object/CDOObjectWrapperBase.java
index 40258814be..ae02451a9b 100644
--- a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/object/CDOObjectWrapperBase.java
+++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/object/CDOObjectWrapperBase.java
@@ -11,15 +11,10 @@
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.model.EMFUtil;
import org.eclipse.emf.cdo.eresource.impl.CDOResourceImpl;
-import org.eclipse.emf.cdo.view.CDOView;
-
-import org.eclipse.emf.internal.cdo.bundle.OM;
import org.eclipse.net4j.util.ReflectUtil;
-import org.eclipse.net4j.util.om.trace.ContextTracer;
import org.eclipse.emf.common.notify.Adapter;
import org.eclipse.emf.common.notify.Notification;
@@ -49,28 +44,12 @@ import java.util.List;
*/
public abstract class CDOObjectWrapperBase implements CDOObject, InternalEObject
{
- private static final ContextTracer TRACER = new ContextTracer(OM.DEBUG_OBJECT, CDOObjectWrapperBase.class);
-
- protected CDOID id;
-
- protected InternalCDOView view;
-
protected InternalEObject instance;
public CDOObjectWrapperBase()
{
}
- public CDOID cdoID()
- {
- return id;
- }
-
- public InternalCDOView cdoView()
- {
- return view;
- }
-
public CDOResourceImpl cdoResource()
{
Resource resource = eResource();
@@ -96,26 +75,6 @@ public abstract class CDOObjectWrapperBase implements CDOObject, InternalEObject
return null;
}
- public void cdoInternalSetID(CDOID id)
- {
- if (TRACER.isEnabled())
- {
- TRACER.format("Setting ID: {0} for {1}", id, instance); //$NON-NLS-1$
- }
-
- this.id = id;
- }
-
- public void cdoInternalSetView(CDOView view)
- {
- if (TRACER.isEnabled())
- {
- TRACER.format("Setting view: {0} for {1}", view, instance); //$NON-NLS-1$
- }
-
- this.view = (InternalCDOView)view;
- }
-
public InternalEObject cdoInternalInstance()
{
return instance;
@@ -142,7 +101,8 @@ public abstract class CDOObjectWrapperBase implements CDOObject, InternalEObject
*/
public void cdoPrefetch(int depth)
{
- view.prefetchRevisions(id, depth);
+ InternalCDOView view = (InternalCDOView)cdoView();
+ view.prefetchRevisions(cdoID(), depth);
}
public EStructuralFeature cdoInternalDynamicFeature(int dynamicFeatureID)
@@ -499,7 +459,6 @@ public abstract class CDOObjectWrapperBase implements CDOObject, InternalEObject
@Override
public String toString()
{
- return getClass().getSimpleName() + "[" + instance.getClass().getSimpleName() + "@" + id + "]"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ return getClass().getSimpleName() + "[" + instance.getClass().getSimpleName() + "@" + cdoID() + "]"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
}
-
}
diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/view/AbstractCDOView.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/view/AbstractCDOView.java
index c9a7840a00..58a6bc13ba 100644
--- a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/view/AbstractCDOView.java
+++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/view/AbstractCDOView.java
@@ -120,6 +120,8 @@ public abstract class AbstractCDOView extends CDOCommitHistoryProviderImpl<CDOOb
{
private static final ContextTracer TRACER = new ContextTracer(OM.DEBUG_VIEW, AbstractCDOView.class);
+ private final ViewAndState[] viewAndStates = ViewAndState.create(this);
+
private final boolean legacyModeEnabled;
private CDOBranchPoint branchPoint;
@@ -193,6 +195,11 @@ public abstract class AbstractCDOView extends CDOCommitHistoryProviderImpl<CDOOb
this.objects = objects;
}
+ public ViewAndState getViewAndState(CDOState state)
+ {
+ return viewAndStates[state.ordinal()];
+ }
+
public CDOStore getStore()
{
checkActive();
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 05d822db32..730330c2d4 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
@@ -886,9 +886,8 @@ public final class CDOStateMachine extends FiniteStateMachine<CDOState, CDOEvent
CDOID newID = idMappings.get(oldID);
if (newID != null)
{
- object.cdoInternalSetID(newID);
- transaction.remapObject(oldID);
revision.setID(newID);
+ transaction.remapObject(oldID);
}
// Adjust revision
diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/spi/cdo/InternalCDOObject.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/spi/cdo/InternalCDOObject.java
index d6260cfffc..b7ca2d3d67 100644
--- a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/spi/cdo/InternalCDOObject.java
+++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/spi/cdo/InternalCDOObject.java
@@ -59,5 +59,9 @@ public interface InternalCDOObject extends CDOObject, InternalEObject, InternalC
public InternalEObject cdoInternalInstance();
+ /**
+ * @deprecated As of 4.2 no longer supported.
+ */
+ @Deprecated
public EStructuralFeature cdoInternalDynamicFeature(int dynamicFeatureID);
}
diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/spi/cdo/InternalCDOView.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/spi/cdo/InternalCDOView.java
index 479f1d4597..93bcfe9aad 100644
--- a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/spi/cdo/InternalCDOView.java
+++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/spi/cdo/InternalCDOView.java
@@ -163,4 +163,64 @@ public interface InternalCDOView extends CDOView, CDOIDProvider, ILifecycle
* @since 4.1
*/
public CDOLockState[] getLockStates(Collection<CDOID> ids);
+
+ /**
+ * @since 4.2
+ */
+ public ViewAndState getViewAndState(CDOState state);
+
+ /**
+ * Optimizes the storage of {@link CDOObject#cdoView()} and {@link CDOObject#cdoState()}. All objects of a view
+ * share a small number of {@link CDOState} literals, so they are moved into a final AbstractCDOView.viewAndStates array.
+ * For the {@link CDOState#TRANSIENT TRANSIENT} state, where there is no view associated with a {@link CDOObject}, this class
+ * maintains a static {@link #VIEW_AND_STATES} array.
+ *
+ * @author Eike Stepper
+ * @since 4.2
+ */
+ public static final class ViewAndState
+ {
+ private static final CDOState[] STATE_VALUES = CDOState.values();
+
+ private static final ViewAndState[] VIEW_AND_STATES = create(null);
+
+ public static final ViewAndState TRANSIENT = VIEW_AND_STATES[CDOState.TRANSIENT.ordinal()];
+
+ public final InternalCDOView view;
+
+ public final CDOState state;
+
+ public ViewAndState(InternalCDOView view, CDOState state)
+ {
+ this.view = view;
+ this.state = state;
+ }
+
+ public ViewAndState getViewAndState(CDOState state)
+ {
+ if (view != null)
+ {
+ return view.getViewAndState(state);
+ }
+
+ return VIEW_AND_STATES[state.ordinal()];
+ }
+
+ @Override
+ public String toString()
+ {
+ return "ViewAndState[view=" + view + ", state=" + state + "]";
+ }
+
+ public static ViewAndState[] create(InternalCDOView view)
+ {
+ ViewAndState[] viewAndStates = new ViewAndState[STATE_VALUES.length];
+ for (CDOState state : STATE_VALUES)
+ {
+ viewAndStates[state.ordinal()] = new ViewAndState(view, state);
+ }
+
+ return viewAndStates;
+ }
+ }
}

Back to the top