diff options
Diffstat (limited to 'plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo')
52 files changed, 8824 insertions, 8824 deletions
diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/analyzer/CDOAbstractFeatureRuleAnalyzer.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/analyzer/CDOAbstractFeatureRuleAnalyzer.java index 9671d547a9..9f206aa915 100644 --- a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/analyzer/CDOAbstractFeatureRuleAnalyzer.java +++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/analyzer/CDOAbstractFeatureRuleAnalyzer.java @@ -1,119 +1,119 @@ -/*
- * Copyright (c) 2004 - 2012 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:
- * Simon McDuff - initial API and implementation
- * Eike Stepper - maintenance
- */
-package org.eclipse.emf.internal.cdo.analyzer;
-
-import org.eclipse.emf.cdo.CDOObject;
-import org.eclipse.emf.cdo.session.CDOCollectionLoadingPolicy;
-import org.eclipse.emf.cdo.view.CDOFeatureAnalyzer;
-import org.eclipse.emf.cdo.view.CDOFetchRuleManager;
-
-import org.eclipse.emf.internal.cdo.bundle.OM;
-
-import org.eclipse.net4j.util.om.trace.ContextTracer;
-
-import org.eclipse.emf.ecore.EStructuralFeature;
-
-/**
- * @author Simon McDuff
- */
-public abstract class CDOAbstractFeatureRuleAnalyzer implements CDOFeatureAnalyzer, CDOFetchRuleManager
-{
- private static final ContextTracer TRACER = new ContextTracer(OM.DEBUG, CDOAbstractFeatureRuleAnalyzer.class);
-
- protected EStructuralFeature lastTraverseFeature;
-
- protected int lastTraverseIndex;
-
- protected long lastAccessTime;
-
- protected long lastElapseTimeBetweenOperations;
-
- protected CDOObject lastTraverseCDOObject;
-
- protected long lastLatencyTime;
-
- protected CDOCollectionLoadingPolicy loadCollectionPolicy;
-
- private boolean didFetch;
-
- private int fetchCount;
-
- public CDOAbstractFeatureRuleAnalyzer()
- {
- }
-
- public int getFetchCount()
- {
- return fetchCount;
- }
-
- public CDOCollectionLoadingPolicy getCollectionLoadingPolicy()
- {
- return loadCollectionPolicy;
- }
-
- public void preTraverseFeature(CDOObject cdoObject, EStructuralFeature feature, int index)
- {
- if (TRACER.isEnabled())
- {
- TRACER.format("preTraverseFeature : {0}.{1}", cdoObject.eClass(), feature.getName()); //$NON-NLS-1$
- }
-
- loadCollectionPolicy = cdoObject.cdoView().getSession().options().getCollectionLoadingPolicy();
- lastTraverseFeature = feature;
- lastTraverseCDOObject = cdoObject;
- lastTraverseIndex = index;
- lastElapseTimeBetweenOperations = System.currentTimeMillis() - lastAccessTime;
- lastAccessTime = System.currentTimeMillis();
- didFetch = false;
-
- CDOFetchRuleManagerThreadLocal.join(this);
- doPreTraverseFeature(cdoObject, feature, index);
- }
-
- public void postTraverseFeature(CDOObject cdoObject, EStructuralFeature feature, int index, Object value)
- {
- if (TRACER.isEnabled())
- {
- TRACER.format("postTraverseFeature : {0}.{1}", cdoObject.eClass(), feature.getName()); //$NON-NLS-1$
- }
-
- try
- {
- doPostTraverseFeature(cdoObject, feature, index, value);
- }
- finally
- {
- CDOFetchRuleManagerThreadLocal.leave();
- lastAccessTime = System.currentTimeMillis();
- }
- }
-
- protected void doPreTraverseFeature(CDOObject cdoObject, EStructuralFeature feature, int index)
- {
- }
-
- protected void doPostTraverseFeature(CDOObject cdoObject, EStructuralFeature feature, int index, Object value)
- {
- }
-
- protected void fetchData()
- {
- didFetch = true;
- fetchCount++;
- }
-
- protected boolean didFetch()
- {
- return didFetch;
- }
-}
+/* + * Copyright (c) 2004 - 2012 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: + * Simon McDuff - initial API and implementation + * Eike Stepper - maintenance + */ +package org.eclipse.emf.internal.cdo.analyzer; + +import org.eclipse.emf.cdo.CDOObject; +import org.eclipse.emf.cdo.session.CDOCollectionLoadingPolicy; +import org.eclipse.emf.cdo.view.CDOFeatureAnalyzer; +import org.eclipse.emf.cdo.view.CDOFetchRuleManager; + +import org.eclipse.emf.internal.cdo.bundle.OM; + +import org.eclipse.net4j.util.om.trace.ContextTracer; + +import org.eclipse.emf.ecore.EStructuralFeature; + +/** + * @author Simon McDuff + */ +public abstract class CDOAbstractFeatureRuleAnalyzer implements CDOFeatureAnalyzer, CDOFetchRuleManager +{ + private static final ContextTracer TRACER = new ContextTracer(OM.DEBUG, CDOAbstractFeatureRuleAnalyzer.class); + + protected EStructuralFeature lastTraverseFeature; + + protected int lastTraverseIndex; + + protected long lastAccessTime; + + protected long lastElapseTimeBetweenOperations; + + protected CDOObject lastTraverseCDOObject; + + protected long lastLatencyTime; + + protected CDOCollectionLoadingPolicy loadCollectionPolicy; + + private boolean didFetch; + + private int fetchCount; + + public CDOAbstractFeatureRuleAnalyzer() + { + } + + public int getFetchCount() + { + return fetchCount; + } + + public CDOCollectionLoadingPolicy getCollectionLoadingPolicy() + { + return loadCollectionPolicy; + } + + public void preTraverseFeature(CDOObject cdoObject, EStructuralFeature feature, int index) + { + if (TRACER.isEnabled()) + { + TRACER.format("preTraverseFeature : {0}.{1}", cdoObject.eClass(), feature.getName()); //$NON-NLS-1$ + } + + loadCollectionPolicy = cdoObject.cdoView().getSession().options().getCollectionLoadingPolicy(); + lastTraverseFeature = feature; + lastTraverseCDOObject = cdoObject; + lastTraverseIndex = index; + lastElapseTimeBetweenOperations = System.currentTimeMillis() - lastAccessTime; + lastAccessTime = System.currentTimeMillis(); + didFetch = false; + + CDOFetchRuleManagerThreadLocal.join(this); + doPreTraverseFeature(cdoObject, feature, index); + } + + public void postTraverseFeature(CDOObject cdoObject, EStructuralFeature feature, int index, Object value) + { + if (TRACER.isEnabled()) + { + TRACER.format("postTraverseFeature : {0}.{1}", cdoObject.eClass(), feature.getName()); //$NON-NLS-1$ + } + + try + { + doPostTraverseFeature(cdoObject, feature, index, value); + } + finally + { + CDOFetchRuleManagerThreadLocal.leave(); + lastAccessTime = System.currentTimeMillis(); + } + } + + protected void doPreTraverseFeature(CDOObject cdoObject, EStructuralFeature feature, int index) + { + } + + protected void doPostTraverseFeature(CDOObject cdoObject, EStructuralFeature feature, int index, Object value) + { + } + + protected void fetchData() + { + didFetch = true; + fetchCount++; + } + + protected boolean didFetch() + { + return didFetch; + } +} diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/analyzer/CDOAnalyzerFeatureInfo.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/analyzer/CDOAnalyzerFeatureInfo.java index f75690d187..5aa8787ce5 100644 --- a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/analyzer/CDOAnalyzerFeatureInfo.java +++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/analyzer/CDOAnalyzerFeatureInfo.java @@ -1,119 +1,119 @@ -/*
- * Copyright (c) 2004 - 2012 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:
- * Simon McDuff - initial API and implementation
- * Eike Stepper - maintenance
- */
-package org.eclipse.emf.internal.cdo.analyzer;
-
-import org.eclipse.emf.cdo.common.util.CDOFetchRule;
-
-import org.eclipse.emf.internal.cdo.bundle.OM;
-
-import org.eclipse.net4j.util.om.trace.ContextTracer;
-
-import org.eclipse.emf.ecore.EClass;
-import org.eclipse.emf.ecore.EStructuralFeature;
-
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.Map;
-
-/**
- * @author Simon McDuff
- */
-public class CDOAnalyzerFeatureInfo
-{
- private static final ContextTracer TRACER = new ContextTracer(OM.DEBUG, CDOAnalyzerFeatureInfo.class);
-
- private Map<CDOFetchFeatureInfo, CDOFetchFeatureInfo> featureStats = new HashMap<CDOFetchFeatureInfo, CDOFetchFeatureInfo>();
-
- private Map<EClass, CDOFetchRule> fetchRules = new HashMap<EClass, CDOFetchRule>();
-
- public CDOAnalyzerFeatureInfo()
- {
- }
-
- public Collection<CDOFetchRule> getRules(EClass eClass, EStructuralFeature feature)
- {
- return fetchRules.values();
- }
-
- public synchronized CDOFetchFeatureInfo getFeatureStat(EClass eClass, EStructuralFeature feature)
- {
- CDOFetchFeatureInfo search = new CDOFetchFeatureInfo(eClass, feature);
- CDOFetchFeatureInfo featureRule = featureStats.get(search);
- if (featureRule == null)
- {
- featureRule = search;
- featureStats.put(search, featureRule);
- }
-
- return featureRule;
- }
-
- public boolean isActive(EClass eClass, EStructuralFeature feature)
- {
- CDOFetchFeatureInfo search = new CDOFetchFeatureInfo(eClass, feature);
- CDOFetchFeatureInfo featureRule = featureStats.get(search);
- return featureRule != null && featureRule.isActive();
- }
-
- public void activate(EClass eClass, EStructuralFeature feature)
- {
- CDOFetchFeatureInfo info = getFeatureStat(eClass, feature);
- if (!info.isActive())
- {
- info.setActive(true);
- addRule(eClass, feature);
- }
- }
-
- public void deactivate(EClass eClass, EStructuralFeature feature)
- {
- CDOFetchFeatureInfo info = getFeatureStat(eClass, feature);
- if (info.isActive())
- {
- info.setActive(false);
- removeRule(eClass, feature);
- }
- }
-
- private void addRule(EClass eClass, EStructuralFeature feature)
- {
- if (TRACER.isEnabled())
- {
- TRACER.format("Adding rule : {0}.{1}", eClass.getName(), feature.getName()); //$NON-NLS-1$
- }
-
- CDOFetchRule fetchRule = fetchRules.get(eClass);
- if (fetchRule == null)
- {
- fetchRule = new CDOFetchRule(eClass);
- fetchRules.put(eClass, fetchRule);
- }
-
- fetchRule.addFeature(feature);
- }
-
- private void removeRule(EClass eClass, EStructuralFeature feature)
- {
- if (TRACER.isEnabled())
- {
- TRACER.format("Removing rule : {0}.{1}", eClass.getName(), feature.getName()); //$NON-NLS-1$
- }
-
- CDOFetchRule fetchRule = fetchRules.get(eClass);
- if (fetchRule == null)
- {
- return;
- }
-
- fetchRule.removeFeature(feature);
- }
-}
+/* + * Copyright (c) 2004 - 2012 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: + * Simon McDuff - initial API and implementation + * Eike Stepper - maintenance + */ +package org.eclipse.emf.internal.cdo.analyzer; + +import org.eclipse.emf.cdo.common.util.CDOFetchRule; + +import org.eclipse.emf.internal.cdo.bundle.OM; + +import org.eclipse.net4j.util.om.trace.ContextTracer; + +import org.eclipse.emf.ecore.EClass; +import org.eclipse.emf.ecore.EStructuralFeature; + +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; + +/** + * @author Simon McDuff + */ +public class CDOAnalyzerFeatureInfo +{ + private static final ContextTracer TRACER = new ContextTracer(OM.DEBUG, CDOAnalyzerFeatureInfo.class); + + private Map<CDOFetchFeatureInfo, CDOFetchFeatureInfo> featureStats = new HashMap<CDOFetchFeatureInfo, CDOFetchFeatureInfo>(); + + private Map<EClass, CDOFetchRule> fetchRules = new HashMap<EClass, CDOFetchRule>(); + + public CDOAnalyzerFeatureInfo() + { + } + + public Collection<CDOFetchRule> getRules(EClass eClass, EStructuralFeature feature) + { + return fetchRules.values(); + } + + public synchronized CDOFetchFeatureInfo getFeatureStat(EClass eClass, EStructuralFeature feature) + { + CDOFetchFeatureInfo search = new CDOFetchFeatureInfo(eClass, feature); + CDOFetchFeatureInfo featureRule = featureStats.get(search); + if (featureRule == null) + { + featureRule = search; + featureStats.put(search, featureRule); + } + + return featureRule; + } + + public boolean isActive(EClass eClass, EStructuralFeature feature) + { + CDOFetchFeatureInfo search = new CDOFetchFeatureInfo(eClass, feature); + CDOFetchFeatureInfo featureRule = featureStats.get(search); + return featureRule != null && featureRule.isActive(); + } + + public void activate(EClass eClass, EStructuralFeature feature) + { + CDOFetchFeatureInfo info = getFeatureStat(eClass, feature); + if (!info.isActive()) + { + info.setActive(true); + addRule(eClass, feature); + } + } + + public void deactivate(EClass eClass, EStructuralFeature feature) + { + CDOFetchFeatureInfo info = getFeatureStat(eClass, feature); + if (info.isActive()) + { + info.setActive(false); + removeRule(eClass, feature); + } + } + + private void addRule(EClass eClass, EStructuralFeature feature) + { + if (TRACER.isEnabled()) + { + TRACER.format("Adding rule : {0}.{1}", eClass.getName(), feature.getName()); //$NON-NLS-1$ + } + + CDOFetchRule fetchRule = fetchRules.get(eClass); + if (fetchRule == null) + { + fetchRule = new CDOFetchRule(eClass); + fetchRules.put(eClass, fetchRule); + } + + fetchRule.addFeature(feature); + } + + private void removeRule(EClass eClass, EStructuralFeature feature) + { + if (TRACER.isEnabled()) + { + TRACER.format("Removing rule : {0}.{1}", eClass.getName(), feature.getName()); //$NON-NLS-1$ + } + + CDOFetchRule fetchRule = fetchRules.get(eClass); + if (fetchRule == null) + { + return; + } + + fetchRule.removeFeature(feature); + } +} diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/analyzer/CDOClusterOfFetchRule.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/analyzer/CDOClusterOfFetchRule.java index f9ada50df0..685cfd7047 100644 --- a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/analyzer/CDOClusterOfFetchRule.java +++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/analyzer/CDOClusterOfFetchRule.java @@ -1,74 +1,74 @@ -/*
- * Copyright (c) 2004 - 2012 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:
- * Simon McDuff - initial API and implementation
- * Eike Stepper - maintenance
- */
-package org.eclipse.emf.internal.cdo.analyzer;
-
-import org.eclipse.emf.ecore.EClass;
-import org.eclipse.emf.ecore.EStructuralFeature;
-
-/**
- * @author Simon McDuff
- */
-public class CDOClusterOfFetchRule
-{
- private CDOAnalyzerFeatureInfo featureInfo = new CDOAnalyzerFeatureInfo();
-
- private EStructuralFeature rootFeature;
-
- private EClass rootClass;
-
- private long lastUpdate;
-
- public CDOClusterOfFetchRule(EClass rootClass, EStructuralFeature rootFeature)
- {
- this.rootFeature = rootFeature;
- this.rootClass = rootClass;
- lastUpdate = System.currentTimeMillis();
- }
-
- public EStructuralFeature getRootFeature()
- {
- return rootFeature;
- }
-
- public CDOAnalyzerFeatureInfo getFeatureInfo()
- {
- return featureInfo;
- }
-
- public long getLastUpdate()
- {
- return lastUpdate;
- }
-
- @Override
- public int hashCode()
- {
- return rootClass.hashCode() ^ rootFeature.hashCode();
- }
-
- @Override
- public boolean equals(Object obj)
- {
- if (obj == this)
- {
- return true;
- }
-
- if (obj instanceof CDOClusterOfFetchRule)
- {
- CDOClusterOfFetchRule featureInfo = (CDOClusterOfFetchRule)obj;
- return featureInfo.rootClass == rootClass && featureInfo.rootFeature == rootFeature;
- }
-
- return false;
- }
-}
+/* + * Copyright (c) 2004 - 2012 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: + * Simon McDuff - initial API and implementation + * Eike Stepper - maintenance + */ +package org.eclipse.emf.internal.cdo.analyzer; + +import org.eclipse.emf.ecore.EClass; +import org.eclipse.emf.ecore.EStructuralFeature; + +/** + * @author Simon McDuff + */ +public class CDOClusterOfFetchRule +{ + private CDOAnalyzerFeatureInfo featureInfo = new CDOAnalyzerFeatureInfo(); + + private EStructuralFeature rootFeature; + + private EClass rootClass; + + private long lastUpdate; + + public CDOClusterOfFetchRule(EClass rootClass, EStructuralFeature rootFeature) + { + this.rootFeature = rootFeature; + this.rootClass = rootClass; + lastUpdate = System.currentTimeMillis(); + } + + public EStructuralFeature getRootFeature() + { + return rootFeature; + } + + public CDOAnalyzerFeatureInfo getFeatureInfo() + { + return featureInfo; + } + + public long getLastUpdate() + { + return lastUpdate; + } + + @Override + public int hashCode() + { + return rootClass.hashCode() ^ rootFeature.hashCode(); + } + + @Override + public boolean equals(Object obj) + { + if (obj == this) + { + return true; + } + + if (obj instanceof CDOClusterOfFetchRule) + { + CDOClusterOfFetchRule featureInfo = (CDOClusterOfFetchRule)obj; + return featureInfo.rootClass == rootClass && featureInfo.rootFeature == rootFeature; + } + + return false; + } +} diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/analyzer/CDOFeatureAnalyzerModelBased.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/analyzer/CDOFeatureAnalyzerModelBased.java index 6b9fe0e65f..7ed7eba3ae 100644 --- a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/analyzer/CDOFeatureAnalyzerModelBased.java +++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/analyzer/CDOFeatureAnalyzerModelBased.java @@ -1,61 +1,61 @@ -/*
- * Copyright (c) 2004 - 2012 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:
- * Simon McDuff - initial API and implementation
- * Eike Stepper - maintenance
- */
-package org.eclipse.emf.internal.cdo.analyzer;
-
-import org.eclipse.emf.cdo.CDOObject;
-import org.eclipse.emf.cdo.common.id.CDOID;
-import org.eclipse.emf.cdo.common.util.CDOFetchRule;
-
-import org.eclipse.emf.ecore.EStructuralFeature;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.List;
-
-/**
- * @author Simon McDuff
- */
-public class CDOFeatureAnalyzerModelBased extends CDOAbstractFeatureRuleAnalyzer
-{
- CDOAnalyzerFeatureInfo featureInfos = new CDOAnalyzerFeatureInfo();
-
- public CDOFeatureAnalyzerModelBased()
- {
- }
-
- @Override
- public void doPreTraverseFeature(CDOObject cdoObject, EStructuralFeature feature, int index)
- {
- }
-
- @Override
- public void doPostTraverseFeature(CDOObject cdoObject, EStructuralFeature feature, int index, Object value)
- {
- if (didFetch())
- {
- featureInfos.activate(cdoObject.eClass(), feature);
- }
- }
-
- public CDOID getContext()
- {
- return CDOID.NULL;
- }
-
- public List<CDOFetchRule> getFetchRules(Collection<CDOID> ids)
- {
- fetchData();
- List<CDOFetchRule> rules = new ArrayList<CDOFetchRule>();
- rules.addAll(featureInfos.getRules(lastTraverseCDOObject.eClass(), lastTraverseFeature));
- return rules;
- }
-}
+/* + * Copyright (c) 2004 - 2012 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: + * Simon McDuff - initial API and implementation + * Eike Stepper - maintenance + */ +package org.eclipse.emf.internal.cdo.analyzer; + +import org.eclipse.emf.cdo.CDOObject; +import org.eclipse.emf.cdo.common.id.CDOID; +import org.eclipse.emf.cdo.common.util.CDOFetchRule; + +import org.eclipse.emf.ecore.EStructuralFeature; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; + +/** + * @author Simon McDuff + */ +public class CDOFeatureAnalyzerModelBased extends CDOAbstractFeatureRuleAnalyzer +{ + CDOAnalyzerFeatureInfo featureInfos = new CDOAnalyzerFeatureInfo(); + + public CDOFeatureAnalyzerModelBased() + { + } + + @Override + public void doPreTraverseFeature(CDOObject cdoObject, EStructuralFeature feature, int index) + { + } + + @Override + public void doPostTraverseFeature(CDOObject cdoObject, EStructuralFeature feature, int index, Object value) + { + if (didFetch()) + { + featureInfos.activate(cdoObject.eClass(), feature); + } + } + + public CDOID getContext() + { + return CDOID.NULL; + } + + public List<CDOFetchRule> getFetchRules(Collection<CDOID> ids) + { + fetchData(); + List<CDOFetchRule> rules = new ArrayList<CDOFetchRule>(); + rules.addAll(featureInfos.getRules(lastTraverseCDOObject.eClass(), lastTraverseFeature)); + return rules; + } +} diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/analyzer/CDOFeatureAnalyzerUI.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/analyzer/CDOFeatureAnalyzerUI.java index 8d1fd03156..e1a4af6bd7 100644 --- a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/analyzer/CDOFeatureAnalyzerUI.java +++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/analyzer/CDOFeatureAnalyzerUI.java @@ -1,128 +1,128 @@ -/*
- * Copyright (c) 2004 - 2012 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:
- * Simon McDuff - initial API and implementation
- * Eike Stepper - maintenance
- */
-package org.eclipse.emf.internal.cdo.analyzer;
-
-import org.eclipse.emf.cdo.CDOObject;
-import org.eclipse.emf.cdo.common.id.CDOID;
-import org.eclipse.emf.cdo.common.util.CDOFetchRule;
-
-import org.eclipse.emf.ecore.EClass;
-import org.eclipse.emf.ecore.EReference;
-import org.eclipse.emf.ecore.EStructuralFeature;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-/**
- * @author Simon McDuff
- */
-public class CDOFeatureAnalyzerUI extends CDOAbstractFeatureRuleAnalyzer
-{
- private static final long ELAPSE_TIME = 400L;
-
- private Map<CDOClusterOfFetchRule, CDOClusterOfFetchRule> featureRules = new HashMap<CDOClusterOfFetchRule, CDOClusterOfFetchRule>();
-
- private CDOClusterOfFetchRule currentClusterOfFetchRule;
-
- private long maxTimeBetweenOperation;
-
- public CDOFeatureAnalyzerUI()
- {
- this(ELAPSE_TIME);
- }
-
- public CDOFeatureAnalyzerUI(long maxTimeBetweenOperation)
- {
- this.maxTimeBetweenOperation = maxTimeBetweenOperation;
- }
-
- public CDOID getContext()
- {
- if (lastTraverseFeature.isMany())
- {
- return CDOID.NULL;
- }
-
- return lastTraverseCDOObject.cdoID();
- }
-
- public synchronized CDOClusterOfFetchRule getFeatureRule(EClass eClass, EStructuralFeature feature)
- {
- CDOClusterOfFetchRule search = new CDOClusterOfFetchRule(eClass, feature);
- CDOClusterOfFetchRule featureRule = featureRules.get(search);
- if (featureRule == null)
- {
- featureRule = search;
- featureRules.put(search, featureRule);
- }
-
- return featureRule;
- }
-
- public List<CDOFetchRule> getFetchRules(Collection<CDOID> ids)
- {
- boolean addRootFeature = true;
- fetchData();
-
- if (lastTraverseFeature.isMany())
- {
- addRootFeature = false;
- }
-
- CDOClusterOfFetchRule search = new CDOClusterOfFetchRule(lastTraverseCDOObject.eClass(), lastTraverseFeature);
- CDOClusterOfFetchRule fetchOfRule = featureRules.get(search);
- if (fetchOfRule == null)
- {
- return null;
- }
-
- Collection<CDOFetchRule> fetchRules = fetchOfRule.getFeatureInfo().getRules(null, null);
- List<CDOFetchRule> list = new ArrayList<CDOFetchRule>();
- for (CDOFetchRule fetchRule : fetchRules)
- {
- if (addRootFeature == true || lastTraverseCDOObject.eClass() != fetchRule.getEClass())
- {
- list.add(fetchRule);
- }
- }
-
- return list;
- }
-
- @Override
- protected void doPreTraverseFeature(CDOObject cdoObject, EStructuralFeature feature, int index)
- {
- // Don`t handle containment relationship
- // TODO Simon: Do you really mean containment here? The check is different...
- // TODO Clarify feature maps
- if (feature instanceof EReference)
- {
- if (lastElapseTimeBetweenOperations > maxTimeBetweenOperation || currentClusterOfFetchRule == null)
- {
- // The user interacted with the UI. Restart a new ClusterOfFetchRule
- currentClusterOfFetchRule = getFeatureRule(cdoObject.eClass(), feature);
- }
- }
- }
-
- @Override
- protected void doPostTraverseFeature(CDOObject cdoObject, EStructuralFeature feature, int index, Object object)
- {
- if (didFetch())
- {
- currentClusterOfFetchRule.getFeatureInfo().activate(cdoObject.eClass(), feature);
- }
- }
-}
+/* + * Copyright (c) 2004 - 2012 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: + * Simon McDuff - initial API and implementation + * Eike Stepper - maintenance + */ +package org.eclipse.emf.internal.cdo.analyzer; + +import org.eclipse.emf.cdo.CDOObject; +import org.eclipse.emf.cdo.common.id.CDOID; +import org.eclipse.emf.cdo.common.util.CDOFetchRule; + +import org.eclipse.emf.ecore.EClass; +import org.eclipse.emf.ecore.EReference; +import org.eclipse.emf.ecore.EStructuralFeature; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +/** + * @author Simon McDuff + */ +public class CDOFeatureAnalyzerUI extends CDOAbstractFeatureRuleAnalyzer +{ + private static final long ELAPSE_TIME = 400L; + + private Map<CDOClusterOfFetchRule, CDOClusterOfFetchRule> featureRules = new HashMap<CDOClusterOfFetchRule, CDOClusterOfFetchRule>(); + + private CDOClusterOfFetchRule currentClusterOfFetchRule; + + private long maxTimeBetweenOperation; + + public CDOFeatureAnalyzerUI() + { + this(ELAPSE_TIME); + } + + public CDOFeatureAnalyzerUI(long maxTimeBetweenOperation) + { + this.maxTimeBetweenOperation = maxTimeBetweenOperation; + } + + public CDOID getContext() + { + if (lastTraverseFeature.isMany()) + { + return CDOID.NULL; + } + + return lastTraverseCDOObject.cdoID(); + } + + public synchronized CDOClusterOfFetchRule getFeatureRule(EClass eClass, EStructuralFeature feature) + { + CDOClusterOfFetchRule search = new CDOClusterOfFetchRule(eClass, feature); + CDOClusterOfFetchRule featureRule = featureRules.get(search); + if (featureRule == null) + { + featureRule = search; + featureRules.put(search, featureRule); + } + + return featureRule; + } + + public List<CDOFetchRule> getFetchRules(Collection<CDOID> ids) + { + boolean addRootFeature = true; + fetchData(); + + if (lastTraverseFeature.isMany()) + { + addRootFeature = false; + } + + CDOClusterOfFetchRule search = new CDOClusterOfFetchRule(lastTraverseCDOObject.eClass(), lastTraverseFeature); + CDOClusterOfFetchRule fetchOfRule = featureRules.get(search); + if (fetchOfRule == null) + { + return null; + } + + Collection<CDOFetchRule> fetchRules = fetchOfRule.getFeatureInfo().getRules(null, null); + List<CDOFetchRule> list = new ArrayList<CDOFetchRule>(); + for (CDOFetchRule fetchRule : fetchRules) + { + if (addRootFeature == true || lastTraverseCDOObject.eClass() != fetchRule.getEClass()) + { + list.add(fetchRule); + } + } + + return list; + } + + @Override + protected void doPreTraverseFeature(CDOObject cdoObject, EStructuralFeature feature, int index) + { + // Don`t handle containment relationship + // TODO Simon: Do you really mean containment here? The check is different... + // TODO Clarify feature maps + if (feature instanceof EReference) + { + if (lastElapseTimeBetweenOperations > maxTimeBetweenOperation || currentClusterOfFetchRule == null) + { + // The user interacted with the UI. Restart a new ClusterOfFetchRule + currentClusterOfFetchRule = getFeatureRule(cdoObject.eClass(), feature); + } + } + } + + @Override + protected void doPostTraverseFeature(CDOObject cdoObject, EStructuralFeature feature, int index, Object object) + { + if (didFetch()) + { + currentClusterOfFetchRule.getFeatureInfo().activate(cdoObject.eClass(), feature); + } + } +} diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/analyzer/CDOFetchFeatureInfo.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/analyzer/CDOFetchFeatureInfo.java index e70b7ce7f3..dfd2eca391 100644 --- a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/analyzer/CDOFetchFeatureInfo.java +++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/analyzer/CDOFetchFeatureInfo.java @@ -1,126 +1,126 @@ -/*
- * Copyright (c) 2004 - 2012 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:
- * Simon McDuff - initial API and implementation
- * Eike Stepper - maintenance
- */
-package org.eclipse.emf.internal.cdo.analyzer;
-
-import org.eclipse.emf.ecore.EClass;
-import org.eclipse.emf.ecore.EStructuralFeature;
-
-/**
- * @author Simon McDuff
- */
-public class CDOFetchFeatureInfo
-{
- private long timeBeforeUsed;
-
- private long latencyTime;
-
- private boolean active;
-
- private EClass eClass;
-
- private EStructuralFeature feature;
-
- public CDOFetchFeatureInfo(EClass eClass, EStructuralFeature feature)
- {
- this.eClass = eClass;
- this.feature = feature;
- active = false;
- latencyTime = -1;
- }
-
- public EClass getEClass()
- {
- return eClass;
- }
-
- public EStructuralFeature getEStructuralFeature()
- {
- return feature;
- }
-
- public boolean isActive()
- {
- return active;
- }
-
- public void setActive(boolean active)
- {
- this.active = active;
- }
-
- public long getTimeBeforeUsed()
- {
- return timeBeforeUsed;
- }
-
- public void setTimeBeforeUsed(long timeBeforeUsed)
- {
- this.timeBeforeUsed = timeBeforeUsed;
- }
-
- public long getLatencyTime()
- {
- return latencyTime;
- }
-
- public void setLatencyTime(long latencyTime)
- {
- this.latencyTime = latencyTime;
- }
-
- public void updateLatencyTime(long latencyTime)
- {
- if (getLatencyTime() == -1)
- {
- setLatencyTime(latencyTime);
- }
- else
- {
- setLatencyTime((latencyTime + getLatencyTime()) / 2);
- }
- }
-
- public void updateTimeInfo(long elapseTimeBeforeLastRequest)
- {
- if (getTimeBeforeUsed() == 0)
- {
- setTimeBeforeUsed(elapseTimeBeforeLastRequest);
- }
- else
- {
- setTimeBeforeUsed((getTimeBeforeUsed() + elapseTimeBeforeLastRequest) / 2);
- }
- }
-
- @Override
- public int hashCode()
- {
- return eClass.hashCode() ^ feature.hashCode();
- }
-
- @Override
- public boolean equals(Object obj)
- {
- if (obj == this)
- {
- return true;
- }
-
- if (obj instanceof CDOFetchFeatureInfo)
- {
- CDOFetchFeatureInfo featureInfo = (CDOFetchFeatureInfo)obj;
- return featureInfo.eClass == eClass && featureInfo.feature == feature;
- }
-
- return false;
- }
-}
+/* + * Copyright (c) 2004 - 2012 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: + * Simon McDuff - initial API and implementation + * Eike Stepper - maintenance + */ +package org.eclipse.emf.internal.cdo.analyzer; + +import org.eclipse.emf.ecore.EClass; +import org.eclipse.emf.ecore.EStructuralFeature; + +/** + * @author Simon McDuff + */ +public class CDOFetchFeatureInfo +{ + private long timeBeforeUsed; + + private long latencyTime; + + private boolean active; + + private EClass eClass; + + private EStructuralFeature feature; + + public CDOFetchFeatureInfo(EClass eClass, EStructuralFeature feature) + { + this.eClass = eClass; + this.feature = feature; + active = false; + latencyTime = -1; + } + + public EClass getEClass() + { + return eClass; + } + + public EStructuralFeature getEStructuralFeature() + { + return feature; + } + + public boolean isActive() + { + return active; + } + + public void setActive(boolean active) + { + this.active = active; + } + + public long getTimeBeforeUsed() + { + return timeBeforeUsed; + } + + public void setTimeBeforeUsed(long timeBeforeUsed) + { + this.timeBeforeUsed = timeBeforeUsed; + } + + public long getLatencyTime() + { + return latencyTime; + } + + public void setLatencyTime(long latencyTime) + { + this.latencyTime = latencyTime; + } + + public void updateLatencyTime(long latencyTime) + { + if (getLatencyTime() == -1) + { + setLatencyTime(latencyTime); + } + else + { + setLatencyTime((latencyTime + getLatencyTime()) / 2); + } + } + + public void updateTimeInfo(long elapseTimeBeforeLastRequest) + { + if (getTimeBeforeUsed() == 0) + { + setTimeBeforeUsed(elapseTimeBeforeLastRequest); + } + else + { + setTimeBeforeUsed((getTimeBeforeUsed() + elapseTimeBeforeLastRequest) / 2); + } + } + + @Override + public int hashCode() + { + return eClass.hashCode() ^ feature.hashCode(); + } + + @Override + public boolean equals(Object obj) + { + if (obj == this) + { + return true; + } + + if (obj instanceof CDOFetchFeatureInfo) + { + CDOFetchFeatureInfo featureInfo = (CDOFetchFeatureInfo)obj; + return featureInfo.eClass == eClass && featureInfo.feature == feature; + } + + return false; + } +} diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/analyzer/CDOFetchRuleManagerThreadLocal.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/analyzer/CDOFetchRuleManagerThreadLocal.java index 59f1e938d1..5a2af21f9b 100644 --- a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/analyzer/CDOFetchRuleManagerThreadLocal.java +++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/analyzer/CDOFetchRuleManagerThreadLocal.java @@ -1,65 +1,65 @@ -/*
- * Copyright (c) 2004 - 2012 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:
- * Simon McDuff - initial API and implementation
- * Eike Stepper - maintenance
- */
-package org.eclipse.emf.internal.cdo.analyzer;
-
-import org.eclipse.emf.cdo.common.id.CDOID;
-import org.eclipse.emf.cdo.common.util.CDOFetchRule;
-import org.eclipse.emf.cdo.session.CDOCollectionLoadingPolicy;
-import org.eclipse.emf.cdo.view.CDOFetchRuleManager;
-
-import java.util.Collection;
-import java.util.List;
-
-/**
- * @author Simon McDuff
- */
-public class CDOFetchRuleManagerThreadLocal implements CDOFetchRuleManager
-{
- private static final ThreadLocal<CDOFetchRuleManager> threadLocal = new ThreadLocal<CDOFetchRuleManager>();
-
- public CDOFetchRuleManagerThreadLocal()
- {
- }
-
- public static CDOFetchRuleManager getCurrent()
- {
- return threadLocal.get();
- }
-
- public static void join(CDOFetchRuleManager fetchRulemanager)
- {
- threadLocal.set(fetchRulemanager);
- }
-
- public static void leave()
- {
- threadLocal.set(null);
- }
-
- public CDOID getContext()
- {
- CDOFetchRuleManager analyzer = CDOFetchRuleManagerThreadLocal.getCurrent();
- return analyzer != null ? analyzer.getContext() : null;
- }
-
- public List<CDOFetchRule> getFetchRules(Collection<CDOID> ids)
- {
- CDOFetchRuleManager analyzer = CDOFetchRuleManagerThreadLocal.getCurrent();
- return analyzer != null ? analyzer.getFetchRules(ids) : null;
- }
-
- public CDOCollectionLoadingPolicy getCollectionLoadingPolicy()
- {
- CDOFetchRuleManager analyzer = CDOFetchRuleManagerThreadLocal.getCurrent();
- return analyzer != null ? analyzer.getCollectionLoadingPolicy() : null;
- }
-}
+/* + * Copyright (c) 2004 - 2012 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: + * Simon McDuff - initial API and implementation + * Eike Stepper - maintenance + */ +package org.eclipse.emf.internal.cdo.analyzer; + +import org.eclipse.emf.cdo.common.id.CDOID; +import org.eclipse.emf.cdo.common.util.CDOFetchRule; +import org.eclipse.emf.cdo.session.CDOCollectionLoadingPolicy; +import org.eclipse.emf.cdo.view.CDOFetchRuleManager; + +import java.util.Collection; +import java.util.List; + +/** + * @author Simon McDuff + */ +public class CDOFetchRuleManagerThreadLocal implements CDOFetchRuleManager +{ + private static final ThreadLocal<CDOFetchRuleManager> threadLocal = new ThreadLocal<CDOFetchRuleManager>(); + + public CDOFetchRuleManagerThreadLocal() + { + } + + public static CDOFetchRuleManager getCurrent() + { + return threadLocal.get(); + } + + public static void join(CDOFetchRuleManager fetchRulemanager) + { + threadLocal.set(fetchRulemanager); + } + + public static void leave() + { + threadLocal.set(null); + } + + public CDOID getContext() + { + CDOFetchRuleManager analyzer = CDOFetchRuleManagerThreadLocal.getCurrent(); + return analyzer != null ? analyzer.getContext() : null; + } + + public List<CDOFetchRule> getFetchRules(Collection<CDOID> ids) + { + CDOFetchRuleManager analyzer = CDOFetchRuleManagerThreadLocal.getCurrent(); + return analyzer != null ? analyzer.getFetchRules(ids) : null; + } + + public CDOCollectionLoadingPolicy getCollectionLoadingPolicy() + { + CDOFetchRuleManager analyzer = CDOFetchRuleManagerThreadLocal.getCurrent(); + return analyzer != null ? analyzer.getCollectionLoadingPolicy() : null; + } +} diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/analyzer/NOOPFeatureAnalyzer.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/analyzer/NOOPFeatureAnalyzer.java index c1b8bd19a7..aa493288d3 100644 --- a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/analyzer/NOOPFeatureAnalyzer.java +++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/analyzer/NOOPFeatureAnalyzer.java @@ -1,35 +1,35 @@ -/*
- * Copyright (c) 2004 - 2012 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:
- * Simon McDuff - initial API and implementation
- * Eike Stepper - maintenance
- */
-package org.eclipse.emf.internal.cdo.analyzer;
-
-import org.eclipse.emf.cdo.CDOObject;
-import org.eclipse.emf.cdo.view.CDOFeatureAnalyzer;
-
-import org.eclipse.emf.ecore.EStructuralFeature;
-
-/**
- * @author Simon McDuff
- */
-public class NOOPFeatureAnalyzer implements CDOFeatureAnalyzer
-{
- public NOOPFeatureAnalyzer()
- {
- }
-
- public void preTraverseFeature(CDOObject eClass, EStructuralFeature feature, int index)
- {
- }
-
- public void postTraverseFeature(CDOObject eClass, EStructuralFeature feature, int index, Object value)
- {
- }
-}
+/* + * Copyright (c) 2004 - 2012 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: + * Simon McDuff - initial API and implementation + * Eike Stepper - maintenance + */ +package org.eclipse.emf.internal.cdo.analyzer; + +import org.eclipse.emf.cdo.CDOObject; +import org.eclipse.emf.cdo.view.CDOFeatureAnalyzer; + +import org.eclipse.emf.ecore.EStructuralFeature; + +/** + * @author Simon McDuff + */ +public class NOOPFeatureAnalyzer implements CDOFeatureAnalyzer +{ + public NOOPFeatureAnalyzer() + { + } + + public void preTraverseFeature(CDOObject eClass, EStructuralFeature feature, int index) + { + } + + public void postTraverseFeature(CDOObject eClass, EStructuralFeature feature, int index, Object value) + { + } +} diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/analyzer/NOOPFetchRuleManager.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/analyzer/NOOPFetchRuleManager.java index fe4e84b68a..c890dc55a4 100644 --- a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/analyzer/NOOPFetchRuleManager.java +++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/analyzer/NOOPFetchRuleManager.java @@ -1,45 +1,45 @@ -/*
- * Copyright (c) 2004 - 2012 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:
- * Simon McDuff - initial API and implementation
- * Eike Stepper - maintenance
- */
-package org.eclipse.emf.internal.cdo.analyzer;
-
-import org.eclipse.emf.cdo.common.id.CDOID;
-import org.eclipse.emf.cdo.common.util.CDOFetchRule;
-import org.eclipse.emf.cdo.view.CDOFetchRuleManager;
-
-import java.util.Collection;
-import java.util.List;
-
-/**
- * @author Simon McDuff
- */
-public abstract class NOOPFetchRuleManager implements CDOFetchRuleManager
-{
- public NOOPFetchRuleManager()
- {
- }
-
- public CDOID getContext()
- {
- return CDOID.NULL;
- }
-
- public List<CDOFetchRule> getFetchRules(Collection<CDOID> ids)
- {
- return null;
- }
-
- @Override
- public String toString()
- {
- return "NOOP"; //$NON-NLS-1$
- }
-}
+/* + * Copyright (c) 2004 - 2012 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: + * Simon McDuff - initial API and implementation + * Eike Stepper - maintenance + */ +package org.eclipse.emf.internal.cdo.analyzer; + +import org.eclipse.emf.cdo.common.id.CDOID; +import org.eclipse.emf.cdo.common.util.CDOFetchRule; +import org.eclipse.emf.cdo.view.CDOFetchRuleManager; + +import java.util.Collection; +import java.util.List; + +/** + * @author Simon McDuff + */ +public abstract class NOOPFetchRuleManager implements CDOFetchRuleManager +{ + public NOOPFetchRuleManager() + { + } + + public CDOID getContext() + { + return CDOID.NULL; + } + + public List<CDOFetchRule> getFetchRules(Collection<CDOID> ids) + { + return null; + } + + @Override + public String toString() + { + return "NOOP"; //$NON-NLS-1$ + } +} diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/bundle/Activator.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/bundle/Activator.java index b869c28066..fa01e4d3a1 100644 --- a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/bundle/Activator.java +++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/bundle/Activator.java @@ -1,137 +1,137 @@ -/*
- * Copyright (c) 2004 - 2012 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.internal.cdo.bundle;
-
-import org.eclipse.emf.internal.cdo.view.CDOViewProviderRegistryImpl;
-
-import org.eclipse.net4j.util.lifecycle.LifecycleUtil;
-import org.eclipse.net4j.util.om.OSGiActivator;
-import org.eclipse.net4j.util.om.log.OMLogger;
-
-import org.eclipse.emf.common.EMFPlugin;
-import org.eclipse.emf.common.util.ResourceLocator;
-
-import org.osgi.framework.BundleContext;
-
-/**
- * @author Eike Stepper
- */
-public final class Activator extends EMFPlugin
-{
- // @Singleton
- public static final Activator INSTANCE = new Activator();
-
- private static Implementation plugin;
-
- public Activator()
- {
- super(new ResourceLocator[] {});
- }
-
- @Override
- public ResourceLocator getPluginResourceLocator()
- {
- return plugin;
- }
-
- public static Implementation getPlugin()
- {
- return plugin;
- }
-
- /**
- * @author Eike Stepper
- */
- public static class Implementation extends EclipsePlugin
- {
- public Implementation()
- {
- plugin = this;
- }
-
- @Override
- public void start(BundleContext context) throws Exception
- {
- OSGiActivator.traceStart(context);
- if (OM.BUNDLE == null)
- {
- throw new IllegalStateException("bundle == null"); //$NON-NLS-1$
- }
-
- try
- {
- super.start(context);
- setBundleContext(context);
- doStart();
- }
- catch (Error error)
- {
- OM.BUNDLE.logger().error(error);
- throw error;
- }
- catch (Exception ex)
- {
- OM.BUNDLE.logger().error(ex);
- throw ex;
- }
- }
-
- @Override
- public void stop(BundleContext context) throws Exception
- {
- plugin = null;
- OSGiActivator.traceStop(context);
- if (OM.BUNDLE == null)
- {
- throw new IllegalStateException("bundle == null"); //$NON-NLS-1$
- }
-
- try
- {
- doStop();
- setBundleContext(null);
- super.stop(context);
- }
- catch (Error error)
- {
- OM.BUNDLE.logger().error(error);
- throw error;
- }
- catch (Exception ex)
- {
- OM.BUNDLE.logger().error(ex);
- throw ex;
- }
- }
-
- /**
- * @since 2.0
- */
- protected void doStart() throws Exception
- {
- CDOViewProviderRegistryImpl.INSTANCE.activate();
- }
-
- /**
- * @since 2.0
- */
- protected void doStop() throws Exception
- {
- LifecycleUtil.deactivate(CDOViewProviderRegistryImpl.INSTANCE, OMLogger.Level.WARN);
- }
-
- @SuppressWarnings("deprecation")
- private void setBundleContext(BundleContext context)
- {
- OM.BUNDLE.setBundleContext(context);
- }
- }
-}
+/* + * Copyright (c) 2004 - 2012 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.internal.cdo.bundle; + +import org.eclipse.emf.internal.cdo.view.CDOViewProviderRegistryImpl; + +import org.eclipse.net4j.util.lifecycle.LifecycleUtil; +import org.eclipse.net4j.util.om.OSGiActivator; +import org.eclipse.net4j.util.om.log.OMLogger; + +import org.eclipse.emf.common.EMFPlugin; +import org.eclipse.emf.common.util.ResourceLocator; + +import org.osgi.framework.BundleContext; + +/** + * @author Eike Stepper + */ +public final class Activator extends EMFPlugin +{ + // @Singleton + public static final Activator INSTANCE = new Activator(); + + private static Implementation plugin; + + public Activator() + { + super(new ResourceLocator[] {}); + } + + @Override + public ResourceLocator getPluginResourceLocator() + { + return plugin; + } + + public static Implementation getPlugin() + { + return plugin; + } + + /** + * @author Eike Stepper + */ + public static class Implementation extends EclipsePlugin + { + public Implementation() + { + plugin = this; + } + + @Override + public void start(BundleContext context) throws Exception + { + OSGiActivator.traceStart(context); + if (OM.BUNDLE == null) + { + throw new IllegalStateException("bundle == null"); //$NON-NLS-1$ + } + + try + { + super.start(context); + setBundleContext(context); + doStart(); + } + catch (Error error) + { + OM.BUNDLE.logger().error(error); + throw error; + } + catch (Exception ex) + { + OM.BUNDLE.logger().error(ex); + throw ex; + } + } + + @Override + public void stop(BundleContext context) throws Exception + { + plugin = null; + OSGiActivator.traceStop(context); + if (OM.BUNDLE == null) + { + throw new IllegalStateException("bundle == null"); //$NON-NLS-1$ + } + + try + { + doStop(); + setBundleContext(null); + super.stop(context); + } + catch (Error error) + { + OM.BUNDLE.logger().error(error); + throw error; + } + catch (Exception ex) + { + OM.BUNDLE.logger().error(ex); + throw ex; + } + } + + /** + * @since 2.0 + */ + protected void doStart() throws Exception + { + CDOViewProviderRegistryImpl.INSTANCE.activate(); + } + + /** + * @since 2.0 + */ + protected void doStop() throws Exception + { + LifecycleUtil.deactivate(CDOViewProviderRegistryImpl.INSTANCE, OMLogger.Level.WARN); + } + + @SuppressWarnings("deprecation") + private void setBundleContext(BundleContext context) + { + OM.BUNDLE.setBundleContext(context); + } + } +} diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/bundle/OM.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/bundle/OM.java index a48b7c138e..08561ac5ba 100644 --- a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/bundle/OM.java +++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/bundle/OM.java @@ -1,75 +1,75 @@ -/*
- * Copyright (c) 2004 - 2012 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.internal.cdo.bundle;
-
-import org.eclipse.emf.cdo.common.revision.CDORevision;
-import org.eclipse.emf.cdo.view.CDOView;
-
-import org.eclipse.net4j.util.om.OMBundle;
-import org.eclipse.net4j.util.om.OMPlatform;
-import org.eclipse.net4j.util.om.log.OMLogger;
-import org.eclipse.net4j.util.om.pref.OMPreference;
-import org.eclipse.net4j.util.om.pref.OMPreferences;
-import org.eclipse.net4j.util.om.trace.OMTracer;
-
-/**
- * The <em>Operations & Maintenance</em> class of this bundle.
- *
- * @author Eike Stepper
- */
-public abstract class OM
-{
- public static final String BUNDLE_ID = "org.eclipse.emf.cdo"; //$NON-NLS-1$
-
- public static final OMBundle BUNDLE = OMPlatform.INSTANCE.bundle(BUNDLE_ID, OM.class);
-
- public static final OMTracer DEBUG = BUNDLE.tracer("debug"); //$NON-NLS-1$
-
- public static final OMTracer DEBUG_SESSION = DEBUG.tracer("session"); //$NON-NLS-1$
-
- public static final OMTracer DEBUG_MODEL = DEBUG_SESSION.tracer("model"); //$NON-NLS-1$
-
- public static final OMTracer DEBUG_REVISION = DEBUG_SESSION.tracer("revision"); //$NON-NLS-1$
-
- public static final OMTracer DEBUG_VIEW = DEBUG.tracer("view"); //$NON-NLS-1$
-
- public static final OMTracer DEBUG_TRANSACTION = DEBUG_VIEW.tracer("transaction"); //$NON-NLS-1$
-
- public static final OMTracer DEBUG_AUDIT = DEBUG_VIEW.tracer("audit"); //$NON-NLS-1$
-
- public static final OMTracer DEBUG_OBJECT = DEBUG.tracer("object"); //$NON-NLS-1$
-
- public static final OMTracer DEBUG_STATEMACHINE = DEBUG_OBJECT.tracer("statemachine"); //$NON-NLS-1$
-
- public static final OMTracer DEBUG_STORE = DEBUG_OBJECT.tracer("store"); //$NON-NLS-1$
-
- public static final OMLogger LOG = BUNDLE.logger();
-
- public static final OMPreferences PREFS = BUNDLE.preferences();
-
- public static final OMPreference<String> PREF_REPOSITORY_NAME = //
- PREFS.initString("PREF_REPOSITORY_NAME"); //$NON-NLS-1$
-
- public static final OMPreference<String> PREF_USER_NAME = //
- PREFS.initString("PREF_USER_NAME"); //$NON-NLS-1$
-
- public static final OMPreference<String> PREF_CONNECTOR_DESCRIPTION = //
- PREFS.initString("PREF_CONNECTOR_DESCRIPTION"); //$NON-NLS-1$
-
- public static final OMPreference<Integer> PREF_COLLECTION_LOADING_CHUNK_SIZE = //
- PREFS.init("PREF_COLLECTION_LOADING_CHUNK_SIZE", CDORevision.UNCHUNKED); //$NON-NLS-1$
-
- public static final OMPreference<Boolean> PREF_ENABLE_INVALIDATION_NOTIFICATION = //
- PREFS.init("PREF_ENABLE_INVALIDATION_NOTIFICATION", false); //$NON-NLS-1$
-
- public static final OMPreference<Integer> PREF_REVISION_LOADING_CHUNK_SIZE = //
- PREFS.init("PREF_REVISION_LOADING_CHUNK_SIZE", CDOView.Options.NO_REVISION_PREFETCHING); //$NON-NLS-1$
-}
+/* + * Copyright (c) 2004 - 2012 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.internal.cdo.bundle; + +import org.eclipse.emf.cdo.common.revision.CDORevision; +import org.eclipse.emf.cdo.view.CDOView; + +import org.eclipse.net4j.util.om.OMBundle; +import org.eclipse.net4j.util.om.OMPlatform; +import org.eclipse.net4j.util.om.log.OMLogger; +import org.eclipse.net4j.util.om.pref.OMPreference; +import org.eclipse.net4j.util.om.pref.OMPreferences; +import org.eclipse.net4j.util.om.trace.OMTracer; + +/** + * The <em>Operations & Maintenance</em> class of this bundle. + * + * @author Eike Stepper + */ +public abstract class OM +{ + public static final String BUNDLE_ID = "org.eclipse.emf.cdo"; //$NON-NLS-1$ + + public static final OMBundle BUNDLE = OMPlatform.INSTANCE.bundle(BUNDLE_ID, OM.class); + + public static final OMTracer DEBUG = BUNDLE.tracer("debug"); //$NON-NLS-1$ + + public static final OMTracer DEBUG_SESSION = DEBUG.tracer("session"); //$NON-NLS-1$ + + public static final OMTracer DEBUG_MODEL = DEBUG_SESSION.tracer("model"); //$NON-NLS-1$ + + public static final OMTracer DEBUG_REVISION = DEBUG_SESSION.tracer("revision"); //$NON-NLS-1$ + + public static final OMTracer DEBUG_VIEW = DEBUG.tracer("view"); //$NON-NLS-1$ + + public static final OMTracer DEBUG_TRANSACTION = DEBUG_VIEW.tracer("transaction"); //$NON-NLS-1$ + + public static final OMTracer DEBUG_AUDIT = DEBUG_VIEW.tracer("audit"); //$NON-NLS-1$ + + public static final OMTracer DEBUG_OBJECT = DEBUG.tracer("object"); //$NON-NLS-1$ + + public static final OMTracer DEBUG_STATEMACHINE = DEBUG_OBJECT.tracer("statemachine"); //$NON-NLS-1$ + + public static final OMTracer DEBUG_STORE = DEBUG_OBJECT.tracer("store"); //$NON-NLS-1$ + + public static final OMLogger LOG = BUNDLE.logger(); + + public static final OMPreferences PREFS = BUNDLE.preferences(); + + public static final OMPreference<String> PREF_REPOSITORY_NAME = // + PREFS.initString("PREF_REPOSITORY_NAME"); //$NON-NLS-1$ + + public static final OMPreference<String> PREF_USER_NAME = // + PREFS.initString("PREF_USER_NAME"); //$NON-NLS-1$ + + public static final OMPreference<String> PREF_CONNECTOR_DESCRIPTION = // + PREFS.initString("PREF_CONNECTOR_DESCRIPTION"); //$NON-NLS-1$ + + public static final OMPreference<Integer> PREF_COLLECTION_LOADING_CHUNK_SIZE = // + PREFS.init("PREF_COLLECTION_LOADING_CHUNK_SIZE", CDORevision.UNCHUNKED); //$NON-NLS-1$ + + public static final OMPreference<Boolean> PREF_ENABLE_INVALIDATION_NOTIFICATION = // + PREFS.init("PREF_ENABLE_INVALIDATION_NOTIFICATION", false); //$NON-NLS-1$ + + public static final OMPreference<Integer> PREF_REVISION_LOADING_CHUNK_SIZE = // + PREFS.init("PREF_REVISION_LOADING_CHUNK_SIZE", CDOView.Options.NO_REVISION_PREFETCHING); //$NON-NLS-1$ +} diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/messages/Messages.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/messages/Messages.java index b795852464..e2c005aad4 100644 --- a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/messages/Messages.java +++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/messages/Messages.java @@ -1,41 +1,41 @@ -/*
- * Copyright (c) 2004 - 2012 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:
- * Victor Roldan Betancort - initial API and implementation
- * Eike Stepper - maintenance
- */
-package org.eclipse.emf.internal.cdo.messages;
-
-import java.util.MissingResourceException;
-import java.util.ResourceBundle;
-
-/**
- * @author Victor Roldan Betancort
- */
-public class Messages
-{
- private static final String BUNDLE_NAME = "org.eclipse.emf.internal.cdo.messages.messages"; //$NON-NLS-1$
-
- private static final ResourceBundle RESOURCE_BUNDLE = ResourceBundle.getBundle(BUNDLE_NAME);
-
- private Messages()
- {
- }
-
- public static String getString(String key)
- {
- try
- {
- return RESOURCE_BUNDLE.getString(key);
- }
- catch (MissingResourceException e)
- {
- return '!' + key + '!';
- }
- }
-}
+/* + * Copyright (c) 2004 - 2012 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: + * Victor Roldan Betancort - initial API and implementation + * Eike Stepper - maintenance + */ +package org.eclipse.emf.internal.cdo.messages; + +import java.util.MissingResourceException; +import java.util.ResourceBundle; + +/** + * @author Victor Roldan Betancort + */ +public class Messages +{ + private static final String BUNDLE_NAME = "org.eclipse.emf.internal.cdo.messages.messages"; //$NON-NLS-1$ + + private static final ResourceBundle RESOURCE_BUNDLE = ResourceBundle.getBundle(BUNDLE_NAME); + + private Messages() + { + } + + public static String getString(String key) + { + try + { + return RESOURCE_BUNDLE.getString(key); + } + catch (MissingResourceException e) + { + return '!' + key + '!'; + } + } +} diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/messages/messages.properties b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/messages/messages.properties index 66e118303b..e5d4e6574e 100644 --- a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/messages/messages.properties +++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/messages/messages.properties @@ -1,128 +1,128 @@ -# Copyright (c) 2004 - 2012 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:
-# Victor Roldan Betancort - initial API and implementation
-# Eike Stepper - maintenance
-
-AbstractObjectConflictResolver.0=Object has feature-level conflicts
-CDOAdapterPolicy.0=CDO
-CDOAdapterPolicy.1=NONE
-CDOAdapterPolicy.2=ALL
-CDOClientProtocol.0=No session
-CDOObjectImpl.8=Resource needs to be an instanceof CDOResourceImpl
-CDOQueryImpl.0=Object not persisted
-CDOResourceNodeImpl.3=Null path is not allowed
-CDOResourceNodeImpl.4=Root path is not allowed
-CDOResourceNodeImpl.5=Duplicate path: {0}
-CDOSessionConfigurationImpl.0=Session is already open
-CDOSessionConfigurationImpl.1=Session is not open
-CDOSessionFactory.1=Query is empty: {0}
-CDOSessionImpl.0=Generated packages locally not available: {0}
-CDOSessionImpl.1=Commit notification arrived while view is inactive
-CDOSessionImpl.2=Commit notification arrived while session is inactive
-CDOStaleReferencePolicy.0=EXCEPTION
-CDOStaleReferencePolicy.1=PROXY
-CDOTransactionImpl.0=Not a ResourceFolder: {0}
-CDOTransactionImpl.1=Top-level resource node {0} does not exist
-CDOTransactionImpl.10=Duplicate ID: {0}
-CDOTransactionImpl.11=No package unit for {0}
-CDOTransactionImpl.17=New conflict resolver is already associated with a transaction
-CDOTransactionImpl.2=This transaction has conflicts
-CDOTransactionImpl.3=Save point is null
-CDOTransactionImpl.4=Save point does not belong to this transaction: {0}
-CDOTransactionImpl.6=Save point is invalid: {0}
-CDOUtil.0=Auditing not supported by repository
-CDOViewImpl.0=CDO view is read-only: {0}
-CDOViewImpl.1=path is empty
-CDOViewImpl.11=Object is contained in a different repository: {0}
-CDOViewImpl.14=Not a ResourceFolder: {0}
-CDOViewImpl.16=Unable to provideCDOID: {0}
-CDOViewImpl.17=ID not registered: {0}
-CDOViewImpl.18=CDO view is read-only: {0}
-CDOViewImpl.2=Can not find {0}
-CDOViewImpl.20=Object was already registered: {0}
-CDOViewImpl.26=Invalid view type: {0}
-CDOViewImpl.27=Object {0} does not belong to this view
-CDOViewImpl.29=Unknown referenceType
-CDOViewImpl.30=Different object was registered for {0}
-CDOViewImpl.3=name == null
-CDOViewImpl.4=Expected folder for id = {0}
-CDOViewImpl.5=Node {0} not found
-CDOViewImpl.6=No root ResourceNode
-CDOViewImpl.7=No top level ResourceNode with the name {0}
-CDOViewImpl.8=Duplicate top-level ResourceNodes
-CDOViewImpl.9=Cannot find revision with ID {0}
-CDOViewProviderRegistryImpl.4=class not defined for extension {0}
-CDOViewProviderRegistryImpl.6=regex not defined for extension {0}
-CDOViewSetImpl.0=Cannot find associated CDOView for repository {0}
-CDOViewSetImpl.1=Do not know which CDOView to take since no authority has been specified
-CDOViewSetImpl.2=Only one view per repository can be open for the same resource set
-CDOViewSetImpl.3=Unsupported target: {0}
-CDOViewSetImpl.4=Cannot associate more than 1 resource set with this view set
-CDOXACommitContextImpl.0=Object should be an EObject: {0}
-CDOXATransactionImpl.0=ViewSet is already attached to this XATransaction
-CDOXATransactionImpl.1=ViewSet is not attached to this XATransaction
-CDOXATransactionImpl.4=Committing XA transaction
-CDOXATransactionImpl.7=Save point is invalid: {0}
-CDOXATransactionImpl.8=Commit from CDOTransaction is not allowed
-CommitTransactionPhase2Request.1=Missing informations. {0} is not involved in the commit
-CommitTransactionPhase2Request.2=Missing informations. {0} is not mapped in the commit
-CompletePackageClosure.0=Package == null for {0}
-DanglingReferenceException.0=The object "{0}({1})" is not contained in a resource
-EresourceFactoryImpl.1=The datatype "{0}" is not a valid classifier
-EresourceFactoryImpl.3=The class "{0}" is not a valid classifier
-FailOverStrategyInjector.0=Malformed URI, could not find scheme separator ://
-FailOverStrategyInjector.1=factoryType not defined
-FailOverStrategyInjector.2=connectorDescription not defined
-FSMUtil.0=View closed
-FSMUtil.1=object == null
-FSMUtil.2=view == null
-FSMUtil.3=Legacy models not supported
-FSMUtil.4=Use CDOFactory to create dynamic object:
-ObjectNotFoundException.0=Object {0} not found
-ObjectNotFoundException.1=Object {0} not found in branch {1} at {2}
-InvalidObjectException.0=Object {0} is invalid in branch {1} at {2}
-InvalidURIException.0=Invalid URI "{0}": {1}
-OpenSessionRequest.0=Repository {0} not found
-OpenSessionRequest.3=Failed to open session for repository {0}
-SyncRevisionsRequest.2=Did not expect to receive object with id {0}
-SessionPropertyTester_0=ID
-SessionPropertyTester_10=Name
-SessionPropertyTester_11=The name of the repository of this session.
-SessionPropertyTester_12=UUID
-SessionPropertyTester_13=The UUID of the repository of this session.
-SessionPropertyTester_14=Type
-SessionPropertyTester_15=The type of the repository of this session. One of MASTER, BACKUP, CLONE.
-SessionPropertyTester_16=State
-SessionPropertyTester_17=The state of the repository of this session. One of OFFLINE, SYNCING, ONLINE.
-SessionPropertyTester_18=Creation Time
-SessionPropertyTester_19=The creation time of the repository of this session.
-SessionPropertyTester_20=Supporting Audits
-SessionPropertyTester_21=Whether the repository of this session is supporting auditing.
-SessionPropertyTester_22=Supporting Branches
-SessionPropertyTester_23=Whether the repository of this session is supporting branching.
-SessionPropertyTester_24=Store Type
-SessionPropertyTester_25=The type of the store that backs the repository of this session.
-SessionPropertyTester_26=Object ID Types
-SessionPropertyTester_27=The types of object IDs created by the store that backs the repository of this session.
-SessionPropertyTester_28=Supporting Ecore
-SessionPropertyTester_29=Whether the repository of this session is supporting Ecore instances.
-SessionPropertyTester_30=Ensure Referential Integrity
-SessionPropertyTester_31=Whether the repository of this session is ensuring referential integrity.
-SessionPropertyTester_32=ID Generation Location
-SessionPropertyTester_33=One of STORE, CLIENT.
-SessionPropertyTester_34=Open
-SessionPropertyTester_35=Whether this session is open or not.
-SessionPropertyTester_36=Last Update
-SessionPropertyTester_37=The time stamp of the last passive update.
-SessionPropertyTester_3=The ID of this session.
-SessionPropertyTester_4=User
-SessionPropertyTester_5=The ID of the authenticated user of this session.
-SessionPropertyTester_6=Passive Updates Enabled
-SessionPropertyTester_7=Whether this session is receiving passive updates from the repository.
-SessionPropertyTester_8=Passive Updates Mode
-SessionPropertyTester_9=One of INVALIDATIONS, CHANGES, ADDITIONS.
+# Copyright (c) 2004 - 2012 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: +# Victor Roldan Betancort - initial API and implementation +# Eike Stepper - maintenance + +AbstractObjectConflictResolver.0=Object has feature-level conflicts +CDOAdapterPolicy.0=CDO +CDOAdapterPolicy.1=NONE +CDOAdapterPolicy.2=ALL +CDOClientProtocol.0=No session +CDOObjectImpl.8=Resource needs to be an instanceof CDOResourceImpl +CDOQueryImpl.0=Object not persisted +CDOResourceNodeImpl.3=Null path is not allowed +CDOResourceNodeImpl.4=Root path is not allowed +CDOResourceNodeImpl.5=Duplicate path: {0} +CDOSessionConfigurationImpl.0=Session is already open +CDOSessionConfigurationImpl.1=Session is not open +CDOSessionFactory.1=Query is empty: {0} +CDOSessionImpl.0=Generated packages locally not available: {0} +CDOSessionImpl.1=Commit notification arrived while view is inactive +CDOSessionImpl.2=Commit notification arrived while session is inactive +CDOStaleReferencePolicy.0=EXCEPTION +CDOStaleReferencePolicy.1=PROXY +CDOTransactionImpl.0=Not a ResourceFolder: {0} +CDOTransactionImpl.1=Top-level resource node {0} does not exist +CDOTransactionImpl.10=Duplicate ID: {0} +CDOTransactionImpl.11=No package unit for {0} +CDOTransactionImpl.17=New conflict resolver is already associated with a transaction +CDOTransactionImpl.2=This transaction has conflicts +CDOTransactionImpl.3=Save point is null +CDOTransactionImpl.4=Save point does not belong to this transaction: {0} +CDOTransactionImpl.6=Save point is invalid: {0} +CDOUtil.0=Auditing not supported by repository +CDOViewImpl.0=CDO view is read-only: {0} +CDOViewImpl.1=path is empty +CDOViewImpl.11=Object is contained in a different repository: {0} +CDOViewImpl.14=Not a ResourceFolder: {0} +CDOViewImpl.16=Unable to provideCDOID: {0} +CDOViewImpl.17=ID not registered: {0} +CDOViewImpl.18=CDO view is read-only: {0} +CDOViewImpl.2=Can not find {0} +CDOViewImpl.20=Object was already registered: {0} +CDOViewImpl.26=Invalid view type: {0} +CDOViewImpl.27=Object {0} does not belong to this view +CDOViewImpl.29=Unknown referenceType +CDOViewImpl.30=Different object was registered for {0} +CDOViewImpl.3=name == null +CDOViewImpl.4=Expected folder for id = {0} +CDOViewImpl.5=Node {0} not found +CDOViewImpl.6=No root ResourceNode +CDOViewImpl.7=No top level ResourceNode with the name {0} +CDOViewImpl.8=Duplicate top-level ResourceNodes +CDOViewImpl.9=Cannot find revision with ID {0} +CDOViewProviderRegistryImpl.4=class not defined for extension {0} +CDOViewProviderRegistryImpl.6=regex not defined for extension {0} +CDOViewSetImpl.0=Cannot find associated CDOView for repository {0} +CDOViewSetImpl.1=Do not know which CDOView to take since no authority has been specified +CDOViewSetImpl.2=Only one view per repository can be open for the same resource set +CDOViewSetImpl.3=Unsupported target: {0} +CDOViewSetImpl.4=Cannot associate more than 1 resource set with this view set +CDOXACommitContextImpl.0=Object should be an EObject: {0} +CDOXATransactionImpl.0=ViewSet is already attached to this XATransaction +CDOXATransactionImpl.1=ViewSet is not attached to this XATransaction +CDOXATransactionImpl.4=Committing XA transaction +CDOXATransactionImpl.7=Save point is invalid: {0} +CDOXATransactionImpl.8=Commit from CDOTransaction is not allowed +CommitTransactionPhase2Request.1=Missing informations. {0} is not involved in the commit +CommitTransactionPhase2Request.2=Missing informations. {0} is not mapped in the commit +CompletePackageClosure.0=Package == null for {0} +DanglingReferenceException.0=The object "{0}({1})" is not contained in a resource +EresourceFactoryImpl.1=The datatype "{0}" is not a valid classifier +EresourceFactoryImpl.3=The class "{0}" is not a valid classifier +FailOverStrategyInjector.0=Malformed URI, could not find scheme separator :// +FailOverStrategyInjector.1=factoryType not defined +FailOverStrategyInjector.2=connectorDescription not defined +FSMUtil.0=View closed +FSMUtil.1=object == null +FSMUtil.2=view == null +FSMUtil.3=Legacy models not supported +FSMUtil.4=Use CDOFactory to create dynamic object: +ObjectNotFoundException.0=Object {0} not found +ObjectNotFoundException.1=Object {0} not found in branch {1} at {2} +InvalidObjectException.0=Object {0} is invalid in branch {1} at {2} +InvalidURIException.0=Invalid URI "{0}": {1} +OpenSessionRequest.0=Repository {0} not found +OpenSessionRequest.3=Failed to open session for repository {0} +SyncRevisionsRequest.2=Did not expect to receive object with id {0} +SessionPropertyTester_0=ID +SessionPropertyTester_10=Name +SessionPropertyTester_11=The name of the repository of this session. +SessionPropertyTester_12=UUID +SessionPropertyTester_13=The UUID of the repository of this session. +SessionPropertyTester_14=Type +SessionPropertyTester_15=The type of the repository of this session. One of MASTER, BACKUP, CLONE. +SessionPropertyTester_16=State +SessionPropertyTester_17=The state of the repository of this session. One of OFFLINE, SYNCING, ONLINE. +SessionPropertyTester_18=Creation Time +SessionPropertyTester_19=The creation time of the repository of this session. +SessionPropertyTester_20=Supporting Audits +SessionPropertyTester_21=Whether the repository of this session is supporting auditing. +SessionPropertyTester_22=Supporting Branches +SessionPropertyTester_23=Whether the repository of this session is supporting branching. +SessionPropertyTester_24=Store Type +SessionPropertyTester_25=The type of the store that backs the repository of this session. +SessionPropertyTester_26=Object ID Types +SessionPropertyTester_27=The types of object IDs created by the store that backs the repository of this session. +SessionPropertyTester_28=Supporting Ecore +SessionPropertyTester_29=Whether the repository of this session is supporting Ecore instances. +SessionPropertyTester_30=Ensure Referential Integrity +SessionPropertyTester_31=Whether the repository of this session is ensuring referential integrity. +SessionPropertyTester_32=ID Generation Location +SessionPropertyTester_33=One of STORE, CLIENT. +SessionPropertyTester_34=Open +SessionPropertyTester_35=Whether this session is open or not. +SessionPropertyTester_36=Last Update +SessionPropertyTester_37=The time stamp of the last passive update. +SessionPropertyTester_3=The ID of this session. +SessionPropertyTester_4=User +SessionPropertyTester_5=The ID of the authenticated user of this session. +SessionPropertyTester_6=Passive Updates Enabled +SessionPropertyTester_7=Whether this session is receiving passive updates from the repository. +SessionPropertyTester_8=Passive Updates Mode +SessionPropertyTester_9=One of INVALIDATIONS, CHANGES, ADDITIONS. diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/object/CDODeltaNotificationImpl.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/object/CDODeltaNotificationImpl.java index f3530462c5..6f6bd18c0e 100644 --- a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/object/CDODeltaNotificationImpl.java +++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/object/CDODeltaNotificationImpl.java @@ -1,139 +1,139 @@ -/*
- * Copyright (c) 2004 - 2012 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:
- * Simon McDuff - initial API and implementation
- * Eike Stepper - maintenance
- */
-package org.eclipse.emf.internal.cdo.object;
-
-import org.eclipse.emf.cdo.CDODeltaNotification;
-import org.eclipse.emf.cdo.CDOObject;
-import org.eclipse.emf.cdo.common.id.CDOID;
-import org.eclipse.emf.cdo.common.revision.delta.CDORevisionDelta;
-import org.eclipse.emf.cdo.util.CDOUtil;
-import org.eclipse.emf.cdo.util.ObjectNotFoundException;
-
-import org.eclipse.emf.common.notify.Notification;
-import org.eclipse.emf.common.util.ECollections;
-import org.eclipse.emf.ecore.EObject;
-import org.eclipse.emf.ecore.EStructuralFeature;
-import org.eclipse.emf.ecore.InternalEObject;
-import org.eclipse.emf.ecore.impl.ENotificationImpl;
-import org.eclipse.emf.spi.cdo.InternalCDOObject;
-import org.eclipse.emf.spi.cdo.InternalCDOView;
-
-/**
- * @author Simon McDuff
- * @since 2.0
- */
-public class CDODeltaNotificationImpl extends ENotificationImpl implements CDODeltaNotification
-{
- private CDORevisionDelta revisionDelta;
-
- public CDODeltaNotificationImpl(InternalEObject notifier, int eventType, EStructuralFeature feature, Object oldValue,
- Object newValue)
- {
- super(getEObject(notifier), eventType, feature, oldValue, newValue);
- }
-
- public CDODeltaNotificationImpl(InternalEObject notifier, int eventType, int featureID, Object oldValue,
- Object newValue, int position)
- {
- super(getEObject(notifier), eventType, featureID, oldValue, newValue, position);
- }
-
- public CDODeltaNotificationImpl(InternalEObject notifier, int eventType, int featureID, Object oldValue,
- Object newValue)
- {
- super(getEObject(notifier), eventType, featureID, oldValue, newValue);
- }
-
- @Override
- public Object getNewValue()
- {
- Object object = super.getNewValue();
- return adapt(object);
- }
-
- @Override
- public Object getOldValue()
- {
- Object oldValue = super.getOldValue();
- if (oldValue == null && getEventType() == Notification.REMOVE_MANY)
- {
- Object feature = getFeature();
- if (feature instanceof EStructuralFeature)
- {
- EStructuralFeature structuralFeature = (EStructuralFeature)feature;
- if (structuralFeature.isMany())
- {
- return ECollections.emptyEList();
- }
- }
- }
-
- return adapt(oldValue);
- }
-
- public Object adapt(Object object)
- {
- if (object instanceof CDOID)
- {
- CDOID id = (CDOID)object;
-
- try
- {
- InternalCDOView view = getCDOObject().cdoView();
- object = view.getObject(id, true);
- }
- catch (ObjectNotFoundException ex)
- {
- object = null;
- }
- }
-
- if (object instanceof CDOObject)
- {
- object = CDOUtil.getEObject((EObject)object);
- }
-
- return object;
- }
-
- public boolean hasNext()
- {
- return next != null;
- }
-
- public CDORevisionDelta getRevisionDelta()
- {
- return revisionDelta;
- }
-
- public void setRevisionDelta(CDORevisionDelta revisionDelta)
- {
- this.revisionDelta = revisionDelta;
- }
-
- @Override
- public boolean merge(Notification notification)
- {
- // Do not merge at all. See bug 317144.
- return false;
- }
-
- private InternalCDOObject getCDOObject()
- {
- return (InternalCDOObject)CDOUtil.getCDOObject((EObject)getNotifier());
- }
-
- private static InternalEObject getEObject(InternalEObject notifier)
- {
- return (InternalEObject)CDOUtil.getEObject(notifier);
- }
-}
+/* + * Copyright (c) 2004 - 2012 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: + * Simon McDuff - initial API and implementation + * Eike Stepper - maintenance + */ +package org.eclipse.emf.internal.cdo.object; + +import org.eclipse.emf.cdo.CDODeltaNotification; +import org.eclipse.emf.cdo.CDOObject; +import org.eclipse.emf.cdo.common.id.CDOID; +import org.eclipse.emf.cdo.common.revision.delta.CDORevisionDelta; +import org.eclipse.emf.cdo.util.CDOUtil; +import org.eclipse.emf.cdo.util.ObjectNotFoundException; + +import org.eclipse.emf.common.notify.Notification; +import org.eclipse.emf.common.util.ECollections; +import org.eclipse.emf.ecore.EObject; +import org.eclipse.emf.ecore.EStructuralFeature; +import org.eclipse.emf.ecore.InternalEObject; +import org.eclipse.emf.ecore.impl.ENotificationImpl; +import org.eclipse.emf.spi.cdo.InternalCDOObject; +import org.eclipse.emf.spi.cdo.InternalCDOView; + +/** + * @author Simon McDuff + * @since 2.0 + */ +public class CDODeltaNotificationImpl extends ENotificationImpl implements CDODeltaNotification +{ + private CDORevisionDelta revisionDelta; + + public CDODeltaNotificationImpl(InternalEObject notifier, int eventType, EStructuralFeature feature, Object oldValue, + Object newValue) + { + super(getEObject(notifier), eventType, feature, oldValue, newValue); + } + + public CDODeltaNotificationImpl(InternalEObject notifier, int eventType, int featureID, Object oldValue, + Object newValue, int position) + { + super(getEObject(notifier), eventType, featureID, oldValue, newValue, position); + } + + public CDODeltaNotificationImpl(InternalEObject notifier, int eventType, int featureID, Object oldValue, + Object newValue) + { + super(getEObject(notifier), eventType, featureID, oldValue, newValue); + } + + @Override + public Object getNewValue() + { + Object object = super.getNewValue(); + return adapt(object); + } + + @Override + public Object getOldValue() + { + Object oldValue = super.getOldValue(); + if (oldValue == null && getEventType() == Notification.REMOVE_MANY) + { + Object feature = getFeature(); + if (feature instanceof EStructuralFeature) + { + EStructuralFeature structuralFeature = (EStructuralFeature)feature; + if (structuralFeature.isMany()) + { + return ECollections.emptyEList(); + } + } + } + + return adapt(oldValue); + } + + public Object adapt(Object object) + { + if (object instanceof CDOID) + { + CDOID id = (CDOID)object; + + try + { + InternalCDOView view = getCDOObject().cdoView(); + object = view.getObject(id, true); + } + catch (ObjectNotFoundException ex) + { + object = null; + } + } + + if (object instanceof CDOObject) + { + object = CDOUtil.getEObject((EObject)object); + } + + return object; + } + + public boolean hasNext() + { + return next != null; + } + + public CDORevisionDelta getRevisionDelta() + { + return revisionDelta; + } + + public void setRevisionDelta(CDORevisionDelta revisionDelta) + { + this.revisionDelta = revisionDelta; + } + + @Override + public boolean merge(Notification notification) + { + // Do not merge at all. See bug 317144. + return false; + } + + private InternalCDOObject getCDOObject() + { + return (InternalCDOObject)CDOUtil.getCDOObject((EObject)getNotifier()); + } + + private static InternalEObject getEObject(InternalEObject notifier) + { + return (InternalEObject)CDOUtil.getEObject(notifier); + } +} diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/object/CDOFactoryImpl.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/object/CDOFactoryImpl.java index 98f80b7d7d..2efde3744f 100644 --- a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/object/CDOFactoryImpl.java +++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/object/CDOFactoryImpl.java @@ -1,59 +1,59 @@ -/*
- * Copyright (c) 2004 - 2012 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.internal.cdo.object;
-
-import org.eclipse.emf.cdo.common.model.EMFUtil;
-import org.eclipse.emf.cdo.util.CDOFactory;
-
-import org.eclipse.emf.ecore.EClass;
-import org.eclipse.emf.ecore.EObject;
-import org.eclipse.emf.ecore.EPackage;
-import org.eclipse.emf.ecore.impl.EFactoryImpl;
-
-/**
- * @author Eike Stepper
- */
-public class CDOFactoryImpl extends EFactoryImpl implements CDOFactory
-{
- public CDOFactoryImpl(EPackage ePackage)
- {
- this.ePackage = ePackage;
- }
-
- @Override
- protected EObject basicCreate(EClass eClass)
- {
- if (eClass.getInstanceClassName() == "java.util.Map$Entry") //$NON-NLS-1$
- {
- return new DynamicCDOObjectImpl.BasicEMapEntry<String, String>(eClass);
- }
-
- return new DynamicCDOObjectImpl(eClass);
- }
-
- /**
- * @since 2.0
- */
- public static boolean prepareDynamicEPackage(Object value)
- {
- if (EMFUtil.isDynamicEPackage(value))
- {
- EPackage ePackage = (EPackage)value;
- if (!(ePackage.getEFactoryInstance() instanceof CDOFactory))
- {
- ePackage.setEFactoryInstance(new CDOFactoryImpl(ePackage));
- return true;
- }
- }
-
- return false;
- }
-}
+/* + * Copyright (c) 2004 - 2012 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.internal.cdo.object; + +import org.eclipse.emf.cdo.common.model.EMFUtil; +import org.eclipse.emf.cdo.util.CDOFactory; + +import org.eclipse.emf.ecore.EClass; +import org.eclipse.emf.ecore.EObject; +import org.eclipse.emf.ecore.EPackage; +import org.eclipse.emf.ecore.impl.EFactoryImpl; + +/** + * @author Eike Stepper + */ +public class CDOFactoryImpl extends EFactoryImpl implements CDOFactory +{ + public CDOFactoryImpl(EPackage ePackage) + { + this.ePackage = ePackage; + } + + @Override + protected EObject basicCreate(EClass eClass) + { + if (eClass.getInstanceClassName() == "java.util.Map$Entry") //$NON-NLS-1$ + { + return new DynamicCDOObjectImpl.BasicEMapEntry<String, String>(eClass); + } + + return new DynamicCDOObjectImpl(eClass); + } + + /** + * @since 2.0 + */ + public static boolean prepareDynamicEPackage(Object value) + { + if (EMFUtil.isDynamicEPackage(value)) + { + EPackage ePackage = (EPackage)value; + if (!(ePackage.getEFactoryInstance() instanceof CDOFactory)) + { + ePackage.setEFactoryInstance(new CDOFactoryImpl(ePackage)); + return true; + } + } + + return false; + } +} diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/object/CDOInvalidationNotificationImpl.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/object/CDOInvalidationNotificationImpl.java index 03f1c7b6bd..67ffcb3545 100644 --- a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/object/CDOInvalidationNotificationImpl.java +++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/object/CDOInvalidationNotificationImpl.java @@ -1,176 +1,176 @@ -/*
- * Copyright (c) 2004 - 2012 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:
- * Simon McDuff - initial API and implementation
- * Eike Stepper - maintenance
- */
-package org.eclipse.emf.internal.cdo.object;
-
-import org.eclipse.emf.cdo.CDOInvalidationNotification;
-import org.eclipse.emf.cdo.util.CDOUtil;
-
-import org.eclipse.emf.common.notify.Notification;
-import org.eclipse.emf.ecore.EObject;
-
-/**
- * @author Simon McDuff
- */
-public class CDOInvalidationNotificationImpl implements CDOInvalidationNotification
-{
- private EObject eObject;
-
- public CDOInvalidationNotificationImpl(EObject eObject)
- {
- this.eObject = CDOUtil.getEObject(eObject);
- }
-
- public Object getNotifier()
- {
- return eObject;
- }
-
- public int getEventType()
- {
- return INVALIDATE;
- }
-
- public Object getFeature()
- {
- return null;
- }
-
- public int getFeatureID(Class<?> expectedClass)
- {
- return NO_FEATURE_ID;
- }
-
- public int getPosition()
- {
- return NO_INDEX;
- }
-
- public boolean wasSet()
- {
- throw new UnsupportedOperationException();
- }
-
- public boolean isReset()
- {
- throw new UnsupportedOperationException();
- }
-
- public boolean isTouch()
- {
- return false;
- }
-
- public boolean merge(Notification notification)
- {
- throw new UnsupportedOperationException();
- }
-
- public boolean getNewBooleanValue()
- {
- throw new UnsupportedOperationException();
- }
-
- public byte getNewByteValue()
- {
- throw new UnsupportedOperationException();
- }
-
- public char getNewCharValue()
- {
- throw new UnsupportedOperationException();
- }
-
- public double getNewDoubleValue()
- {
- throw new UnsupportedOperationException();
- }
-
- public float getNewFloatValue()
- {
- throw new UnsupportedOperationException();
- }
-
- public int getNewIntValue()
- {
- throw new UnsupportedOperationException();
- }
-
- public long getNewLongValue()
- {
- throw new UnsupportedOperationException();
- }
-
- public short getNewShortValue()
- {
- throw new UnsupportedOperationException();
- }
-
- public String getNewStringValue()
- {
- throw new UnsupportedOperationException();
- }
-
- public Object getNewValue()
- {
- throw new UnsupportedOperationException();
- }
-
- public boolean getOldBooleanValue()
- {
- throw new UnsupportedOperationException();
- }
-
- public byte getOldByteValue()
- {
- throw new UnsupportedOperationException();
- }
-
- public char getOldCharValue()
- {
- throw new UnsupportedOperationException();
- }
-
- public double getOldDoubleValue()
- {
- throw new UnsupportedOperationException();
- }
-
- public float getOldFloatValue()
- {
- throw new UnsupportedOperationException();
- }
-
- public int getOldIntValue()
- {
- throw new UnsupportedOperationException();
- }
-
- public long getOldLongValue()
- {
- throw new UnsupportedOperationException();
- }
-
- public short getOldShortValue()
- {
- throw new UnsupportedOperationException();
- }
-
- public String getOldStringValue()
- {
- throw new UnsupportedOperationException();
- }
-
- public Object getOldValue()
- {
- throw new UnsupportedOperationException();
- }
-}
+/* + * Copyright (c) 2004 - 2012 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: + * Simon McDuff - initial API and implementation + * Eike Stepper - maintenance + */ +package org.eclipse.emf.internal.cdo.object; + +import org.eclipse.emf.cdo.CDOInvalidationNotification; +import org.eclipse.emf.cdo.util.CDOUtil; + +import org.eclipse.emf.common.notify.Notification; +import org.eclipse.emf.ecore.EObject; + +/** + * @author Simon McDuff + */ +public class CDOInvalidationNotificationImpl implements CDOInvalidationNotification +{ + private EObject eObject; + + public CDOInvalidationNotificationImpl(EObject eObject) + { + this.eObject = CDOUtil.getEObject(eObject); + } + + public Object getNotifier() + { + return eObject; + } + + public int getEventType() + { + return INVALIDATE; + } + + public Object getFeature() + { + return null; + } + + public int getFeatureID(Class<?> expectedClass) + { + return NO_FEATURE_ID; + } + + public int getPosition() + { + return NO_INDEX; + } + + public boolean wasSet() + { + throw new UnsupportedOperationException(); + } + + public boolean isReset() + { + throw new UnsupportedOperationException(); + } + + public boolean isTouch() + { + return false; + } + + public boolean merge(Notification notification) + { + throw new UnsupportedOperationException(); + } + + public boolean getNewBooleanValue() + { + throw new UnsupportedOperationException(); + } + + public byte getNewByteValue() + { + throw new UnsupportedOperationException(); + } + + public char getNewCharValue() + { + throw new UnsupportedOperationException(); + } + + public double getNewDoubleValue() + { + throw new UnsupportedOperationException(); + } + + public float getNewFloatValue() + { + throw new UnsupportedOperationException(); + } + + public int getNewIntValue() + { + throw new UnsupportedOperationException(); + } + + public long getNewLongValue() + { + throw new UnsupportedOperationException(); + } + + public short getNewShortValue() + { + throw new UnsupportedOperationException(); + } + + public String getNewStringValue() + { + throw new UnsupportedOperationException(); + } + + public Object getNewValue() + { + throw new UnsupportedOperationException(); + } + + public boolean getOldBooleanValue() + { + throw new UnsupportedOperationException(); + } + + public byte getOldByteValue() + { + throw new UnsupportedOperationException(); + } + + public char getOldCharValue() + { + throw new UnsupportedOperationException(); + } + + public double getOldDoubleValue() + { + throw new UnsupportedOperationException(); + } + + public float getOldFloatValue() + { + throw new UnsupportedOperationException(); + } + + public int getOldIntValue() + { + throw new UnsupportedOperationException(); + } + + public long getOldLongValue() + { + throw new UnsupportedOperationException(); + } + + public short getOldShortValue() + { + throw new UnsupportedOperationException(); + } + + public String getOldStringValue() + { + throw new UnsupportedOperationException(); + } + + public Object getOldValue() + { + throw new UnsupportedOperationException(); + } +} diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/object/CDOLegacyListener.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/object/CDOLegacyListener.java index 52c819c6aa..b74a7aa8c8 100644 --- a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/object/CDOLegacyListener.java +++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/object/CDOLegacyListener.java @@ -1,109 +1,109 @@ -/*
- * Copyright (c) 2004 - 2012 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.internal.cdo.object;
-
-import org.eclipse.emf.internal.cdo.view.CDOStateMachine;
-
-import org.eclipse.emf.ecore.InternalEObject;
-
-/**
- * @author Eike Stepper
- * @since 2.0
- */
-/*
- * IMPORTANT: Compile errors in this class might indicate an old version of EMF. Legacy support is only enabled for EMF
- * with fixed bug #247130. These compile errors do not affect native models!
- */
-public final class CDOLegacyListener extends CDOLegacyWrapper
-// TODO LEGACY
-// implements InternalEObject.EReadListener, InternalEObject.EWriteListener
-{
- private boolean handlingCallback;
-
- public CDOLegacyListener(InternalEObject instance)
- {
- super(instance);
- }
-
- public void eFireRead(int featureID)
- {
- // Do nothing
- }
-
- public void eFireWrite(int featureID)
- {
- // Do nothing
- }
-
- // TODO LEGACY
- // /**
- // * @since 2.0
- // */
- // /*
- // * IMPORTANT: Compile errors in this method might indicate an old version of EMF. Legacy support is only enabled for
- // * EMF with fixed bug #247130. These compile errors do not affect native models!
- // */
- // public EList<InternalEObject.EReadListener> eReadListeners()
- // {
- // return instance.eReadListeners();
- // }
-
- // TODO LEGACY
- // /**
- // * @since 2.0
- // */
- // /*
- // * IMPORTANT: Compile errors in this method might indicate an old version of EMF. Legacy support is only enabled for
- // * EMF with fixed bug #247130. These compile errors do not affect native models!
- // */
- // public EList<InternalEObject.EWriteListener> eWriteListeners()
- // {
- // return instance.eWriteListeners();
- // }
-
- public synchronized void handleRead(InternalEObject object, int featureID)
- {
- if (!handlingCallback)
- {
- try
- {
- handlingCallback = true;
- CDOStateMachine.INSTANCE.read(this);
-
- // TODO Optimize this when the list position index is added to the new callbacks
- resolveAllProxies();
- }
- finally
- {
- handlingCallback = false;
- }
- }
- }
-
- public synchronized void handleWrite(InternalEObject object, int featureID)
- {
- if (!handlingCallback)
- {
- try
- {
- handlingCallback = true;
- CDOStateMachine.INSTANCE.write(this);
-
- // TODO Optimize this when the list position index is added to the new callbacks
- resolveAllProxies();
- }
- finally
- {
- handlingCallback = false;
- }
- }
- }
-}
+/* + * Copyright (c) 2004 - 2012 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.internal.cdo.object; + +import org.eclipse.emf.internal.cdo.view.CDOStateMachine; + +import org.eclipse.emf.ecore.InternalEObject; + +/** + * @author Eike Stepper + * @since 2.0 + */ +/* + * IMPORTANT: Compile errors in this class might indicate an old version of EMF. Legacy support is only enabled for EMF + * with fixed bug #247130. These compile errors do not affect native models! + */ +public final class CDOLegacyListener extends CDOLegacyWrapper +// TODO LEGACY +// implements InternalEObject.EReadListener, InternalEObject.EWriteListener +{ + private boolean handlingCallback; + + public CDOLegacyListener(InternalEObject instance) + { + super(instance); + } + + public void eFireRead(int featureID) + { + // Do nothing + } + + public void eFireWrite(int featureID) + { + // Do nothing + } + + // TODO LEGACY + // /** + // * @since 2.0 + // */ + // /* + // * IMPORTANT: Compile errors in this method might indicate an old version of EMF. Legacy support is only enabled for + // * EMF with fixed bug #247130. These compile errors do not affect native models! + // */ + // public EList<InternalEObject.EReadListener> eReadListeners() + // { + // return instance.eReadListeners(); + // } + + // TODO LEGACY + // /** + // * @since 2.0 + // */ + // /* + // * IMPORTANT: Compile errors in this method might indicate an old version of EMF. Legacy support is only enabled for + // * EMF with fixed bug #247130. These compile errors do not affect native models! + // */ + // public EList<InternalEObject.EWriteListener> eWriteListeners() + // { + // return instance.eWriteListeners(); + // } + + public synchronized void handleRead(InternalEObject object, int featureID) + { + if (!handlingCallback) + { + try + { + handlingCallback = true; + CDOStateMachine.INSTANCE.read(this); + + // TODO Optimize this when the list position index is added to the new callbacks + resolveAllProxies(); + } + finally + { + handlingCallback = false; + } + } + } + + public synchronized void handleWrite(InternalEObject object, int featureID) + { + if (!handlingCallback) + { + try + { + handlingCallback = true; + CDOStateMachine.INSTANCE.write(this); + + // TODO Optimize this when the list position index is added to the new callbacks + resolveAllProxies(); + } + finally + { + handlingCallback = false; + } + } + } +} diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/object/CDOLockImpl.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/object/CDOLockImpl.java index 9aaa2bec84..085f04398d 100644 --- a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/object/CDOLockImpl.java +++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/object/CDOLockImpl.java @@ -1,229 +1,229 @@ -/*
- * Copyright (c) 2004 - 2012 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:
- * Simon McDuff - initial API and implementation
- * Eike Stepper - maintenance
- */
-package org.eclipse.emf.internal.cdo.object;
-
-import org.eclipse.emf.cdo.CDOLock;
-import org.eclipse.emf.cdo.common.lock.CDOLockOwner;
-import org.eclipse.emf.cdo.common.lock.CDOLockUtil;
-import org.eclipse.emf.cdo.util.LockTimeoutException;
-
-import org.eclipse.net4j.util.WrappedException;
-import org.eclipse.net4j.util.concurrent.IRWLockManager.LockType;
-
-import org.eclipse.emf.spi.cdo.InternalCDOObject;
-
-import java.text.MessageFormat;
-import java.util.Collections;
-import java.util.concurrent.TimeUnit;
-import java.util.concurrent.TimeoutException;
-import java.util.concurrent.locks.Condition;
-
-/**
- * @author Simon McDuff
- * @since 4.0
- */
-public class CDOLockImpl implements CDOLock
-{
- public static final CDOLock NOOP = new NOOPLockImpl();
-
- private final InternalCDOObject object;
-
- private final LockType type;
-
- private final CDOLockOwner owner;
-
- public CDOLockImpl(InternalCDOObject object, LockType type)
- {
- this.object = object;
- this.type = type;
- owner = CDOLockUtil.createLockOwner(object.cdoView());
- }
-
- public LockType getType()
- {
- return type;
- }
-
- public boolean isLocked()
- {
- return object.cdoLockState().isLocked(type, owner, false);
- }
-
- /**
- * @see org.eclipse.emf.cdo.CDOLock#isLockedByOthers()
- */
- public boolean isLockedByOthers()
- {
- return object.cdoLockState().isLocked(type, owner, true);
- }
-
- public void lock()
- {
- try
- {
- object.cdoView().lockObjects(Collections.singletonList(object), type, WAIT);
- }
- catch (InterruptedException ex)
- {
- throw WrappedException.wrap(ex);
- }
- }
-
- public void lock(long time, TimeUnit unit) throws TimeoutException
- {
- try
- {
- if (!tryLock(time, unit))
- {
- throw new TimeoutException();
- }
- }
- catch (InterruptedException ex)
- {
- throw WrappedException.wrap(ex);
- }
- }
-
- public void lock(long millis) throws TimeoutException
- {
- lock(millis, TimeUnit.MILLISECONDS);
- }
-
- public boolean tryLock(long millis) throws InterruptedException
- {
- return tryLock(millis, TimeUnit.MILLISECONDS);
- }
-
- public void lockInterruptibly() throws InterruptedException
- {
- lock();
- }
-
- public Condition newCondition()
- {
- throw new UnsupportedOperationException();
- }
-
- public boolean tryLock()
- {
- try
- {
- object.cdoView().lockObjects(Collections.singletonList(object), type, NO_WAIT);
- return true;
- }
- catch (LockTimeoutException ex)
- {
- return false;
- }
- catch (InterruptedException ex)
- {
- throw WrappedException.wrap(ex);
- }
- }
-
- public boolean tryLock(long time, TimeUnit unit) throws InterruptedException
- {
- try
- {
- object.cdoView().lockObjects(Collections.singletonList(object), type, unit.toMillis(time));
- return true;
- }
- catch (LockTimeoutException ex)
- {
- return false;
- }
- }
-
- public void unlock()
- {
- object.cdoView().unlockObjects(Collections.singletonList(object), type);
- }
-
- @Override
- public String toString()
- {
- return MessageFormat.format("CDOLock[object={0}, type={1}]", object, type);
- }
-
- /**
- * @author Simon McDuff
- */
- public static final class NOOPLockImpl implements CDOLock
- {
- private NOOPLockImpl()
- {
- }
-
- public boolean isLocked()
- {
- return false;
- }
-
- /**
- * @see org.eclipse.emf.cdo.CDOLock#isLockedByOthers()
- */
- public boolean isLockedByOthers()
- {
- return false;
- }
-
- public void lock()
- {
- throw new UnsupportedOperationException();
- }
-
- public void lockInterruptibly() throws InterruptedException
- {
- throw new UnsupportedOperationException();
- }
-
- public Condition newCondition()
- {
- return null;
- }
-
- public void lock(long time, TimeUnit unit) throws TimeoutException
- {
- throw new UnsupportedOperationException();
- }
-
- public void lock(long millis) throws TimeoutException
- {
- throw new UnsupportedOperationException();
- }
-
- public boolean tryLock(long millis) throws InterruptedException
- {
- return false;
- }
-
- public boolean tryLock()
- {
- return false;
- }
-
- public boolean tryLock(long time, TimeUnit unit) throws InterruptedException
- {
- return false;
- }
-
- public void unlock()
- {
- throw new UnsupportedOperationException();
- }
-
- public LockType getType()
- {
- return null;
- }
- }
-}
+/* + * Copyright (c) 2004 - 2012 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: + * Simon McDuff - initial API and implementation + * Eike Stepper - maintenance + */ +package org.eclipse.emf.internal.cdo.object; + +import org.eclipse.emf.cdo.CDOLock; +import org.eclipse.emf.cdo.common.lock.CDOLockOwner; +import org.eclipse.emf.cdo.common.lock.CDOLockUtil; +import org.eclipse.emf.cdo.util.LockTimeoutException; + +import org.eclipse.net4j.util.WrappedException; +import org.eclipse.net4j.util.concurrent.IRWLockManager.LockType; + +import org.eclipse.emf.spi.cdo.InternalCDOObject; + +import java.text.MessageFormat; +import java.util.Collections; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.TimeoutException; +import java.util.concurrent.locks.Condition; + +/** + * @author Simon McDuff + * @since 4.0 + */ +public class CDOLockImpl implements CDOLock +{ + public static final CDOLock NOOP = new NOOPLockImpl(); + + private final InternalCDOObject object; + + private final LockType type; + + private final CDOLockOwner owner; + + public CDOLockImpl(InternalCDOObject object, LockType type) + { + this.object = object; + this.type = type; + owner = CDOLockUtil.createLockOwner(object.cdoView()); + } + + public LockType getType() + { + return type; + } + + public boolean isLocked() + { + return object.cdoLockState().isLocked(type, owner, false); + } + + /** + * @see org.eclipse.emf.cdo.CDOLock#isLockedByOthers() + */ + public boolean isLockedByOthers() + { + return object.cdoLockState().isLocked(type, owner, true); + } + + public void lock() + { + try + { + object.cdoView().lockObjects(Collections.singletonList(object), type, WAIT); + } + catch (InterruptedException ex) + { + throw WrappedException.wrap(ex); + } + } + + public void lock(long time, TimeUnit unit) throws TimeoutException + { + try + { + if (!tryLock(time, unit)) + { + throw new TimeoutException(); + } + } + catch (InterruptedException ex) + { + throw WrappedException.wrap(ex); + } + } + + public void lock(long millis) throws TimeoutException + { + lock(millis, TimeUnit.MILLISECONDS); + } + + public boolean tryLock(long millis) throws InterruptedException + { + return tryLock(millis, TimeUnit.MILLISECONDS); + } + + public void lockInterruptibly() throws InterruptedException + { + lock(); + } + + public Condition newCondition() + { + throw new UnsupportedOperationException(); + } + + public boolean tryLock() + { + try + { + object.cdoView().lockObjects(Collections.singletonList(object), type, NO_WAIT); + return true; + } + catch (LockTimeoutException ex) + { + return false; + } + catch (InterruptedException ex) + { + throw WrappedException.wrap(ex); + } + } + + public boolean tryLock(long time, TimeUnit unit) throws InterruptedException + { + try + { + object.cdoView().lockObjects(Collections.singletonList(object), type, unit.toMillis(time)); + return true; + } + catch (LockTimeoutException ex) + { + return false; + } + } + + public void unlock() + { + object.cdoView().unlockObjects(Collections.singletonList(object), type); + } + + @Override + public String toString() + { + return MessageFormat.format("CDOLock[object={0}, type={1}]", object, type); + } + + /** + * @author Simon McDuff + */ + public static final class NOOPLockImpl implements CDOLock + { + private NOOPLockImpl() + { + } + + public boolean isLocked() + { + return false; + } + + /** + * @see org.eclipse.emf.cdo.CDOLock#isLockedByOthers() + */ + public boolean isLockedByOthers() + { + return false; + } + + public void lock() + { + throw new UnsupportedOperationException(); + } + + public void lockInterruptibly() throws InterruptedException + { + throw new UnsupportedOperationException(); + } + + public Condition newCondition() + { + return null; + } + + public void lock(long time, TimeUnit unit) throws TimeoutException + { + throw new UnsupportedOperationException(); + } + + public void lock(long millis) throws TimeoutException + { + throw new UnsupportedOperationException(); + } + + public boolean tryLock(long millis) throws InterruptedException + { + return false; + } + + public boolean tryLock() + { + return false; + } + + public boolean tryLock(long time, TimeUnit unit) throws InterruptedException + { + return false; + } + + public void unlock() + { + throw new UnsupportedOperationException(); + } + + public LockType getType() + { + return null; + } + } +} diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/object/CDOObjectMerger.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/object/CDOObjectMerger.java index 700203c286..4c321f0c24 100644 --- a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/object/CDOObjectMerger.java +++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/object/CDOObjectMerger.java @@ -1,48 +1,48 @@ -/*
- * Copyright (c) 2004 - 2012 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:
- * Simon McDuff - initial API and implementation
- * Eike Stepper - maintenance
- */
-package org.eclipse.emf.internal.cdo.object;
-
-import org.eclipse.emf.cdo.CDOState;
-import org.eclipse.emf.cdo.common.revision.delta.CDORevisionDelta;
-import org.eclipse.emf.cdo.spi.common.revision.CDORevisionMerger;
-import org.eclipse.emf.cdo.spi.common.revision.InternalCDORevision;
-
-import org.eclipse.emf.spi.cdo.InternalCDOObject;
-
-/**
- * @author Simon McDuff
- */
-public class CDOObjectMerger extends CDORevisionMerger
-{
- public CDOObjectMerger()
- {
- }
-
- /**
- * @since 2.0
- */
- public synchronized void merge(InternalCDOObject object, CDORevisionDelta delta)
- {
- InternalCDORevision oldRevision = object.cdoRevision();
- InternalCDORevision revision = oldRevision.copy();
- object.cdoInternalSetRevision(revision);
-
- // NEW object should stay that state.
- if (object.cdoState() != CDOState.NEW)
- {
- object.cdoInternalSetState(CDOState.DIRTY);
- }
-
- merge(revision, delta);
- object.cdoInternalPostLoad();
- }
-}
+/* + * Copyright (c) 2004 - 2012 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: + * Simon McDuff - initial API and implementation + * Eike Stepper - maintenance + */ +package org.eclipse.emf.internal.cdo.object; + +import org.eclipse.emf.cdo.CDOState; +import org.eclipse.emf.cdo.common.revision.delta.CDORevisionDelta; +import org.eclipse.emf.cdo.spi.common.revision.CDORevisionMerger; +import org.eclipse.emf.cdo.spi.common.revision.InternalCDORevision; + +import org.eclipse.emf.spi.cdo.InternalCDOObject; + +/** + * @author Simon McDuff + */ +public class CDOObjectMerger extends CDORevisionMerger +{ + public CDOObjectMerger() + { + } + + /** + * @since 2.0 + */ + public synchronized void merge(InternalCDOObject object, CDORevisionDelta delta) + { + InternalCDORevision oldRevision = object.cdoRevision(); + InternalCDORevision revision = oldRevision.copy(); + object.cdoInternalSetRevision(revision); + + // NEW object should stay that state. + if (object.cdoState() != CDOState.NEW) + { + object.cdoInternalSetState(CDOState.DIRTY); + } + + merge(revision, delta); + object.cdoInternalPostLoad(); + } +} diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/object/CDOObjectReferenceImpl.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/object/CDOObjectReferenceImpl.java index 9883ac66d0..4538eb6899 100644 --- a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/object/CDOObjectReferenceImpl.java +++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/object/CDOObjectReferenceImpl.java @@ -1,76 +1,76 @@ -/*
- * Copyright (c) 2004 - 2012 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.internal.cdo.object;
-
-import org.eclipse.emf.cdo.CDOObject;
-import org.eclipse.emf.cdo.CDOObjectReference;
-import org.eclipse.emf.cdo.common.id.CDOIDReference;
-import org.eclipse.emf.cdo.view.CDOView;
-
-import org.eclipse.emf.ecore.EStructuralFeature;
-
-/**
- * @author Eike Stepper
- * @since 4.0
- */
-public class CDOObjectReferenceImpl implements CDOObjectReference
-{
- private CDOView view;
-
- private CDOIDReference delegate;
-
- public CDOObjectReferenceImpl(CDOView view, CDOIDReference delegate)
- {
- this.view = view;
- this.delegate = delegate;
- }
-
- public CDOObject getTargetObject()
- {
- return view.getObject(delegate.getTargetObject());
- }
-
- public CDOObject getSourceObject()
- {
- return view.getObject(delegate.getSourceObject());
- }
-
- public EStructuralFeature getSourceFeature()
- {
- return delegate.getSourceFeature();
- }
-
- public int getSourceIndex()
- {
- return delegate.getSourceIndex();
- }
-
- @Override
- public String toString()
- {
- StringBuilder builder = new StringBuilder();
- builder.append(getSourceObject());
- builder.append(".");
- builder.append(getSourceFeature().getName());
- int sourceIndex = getSourceIndex();
- if (sourceIndex != NO_INDEX)
- {
- builder.append("[");
- builder.append(sourceIndex);
- builder.append("]");
- }
-
- builder.append(" --> ");
- builder.append(getTargetObject());
- return builder.toString();
- }
-
-}
+/* + * Copyright (c) 2004 - 2012 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.internal.cdo.object; + +import org.eclipse.emf.cdo.CDOObject; +import org.eclipse.emf.cdo.CDOObjectReference; +import org.eclipse.emf.cdo.common.id.CDOIDReference; +import org.eclipse.emf.cdo.view.CDOView; + +import org.eclipse.emf.ecore.EStructuralFeature; + +/** + * @author Eike Stepper + * @since 4.0 + */ +public class CDOObjectReferenceImpl implements CDOObjectReference +{ + private CDOView view; + + private CDOIDReference delegate; + + public CDOObjectReferenceImpl(CDOView view, CDOIDReference delegate) + { + this.view = view; + this.delegate = delegate; + } + + public CDOObject getTargetObject() + { + return view.getObject(delegate.getTargetObject()); + } + + public CDOObject getSourceObject() + { + return view.getObject(delegate.getSourceObject()); + } + + public EStructuralFeature getSourceFeature() + { + return delegate.getSourceFeature(); + } + + public int getSourceIndex() + { + return delegate.getSourceIndex(); + } + + @Override + public String toString() + { + StringBuilder builder = new StringBuilder(); + builder.append(getSourceObject()); + builder.append("."); + builder.append(getSourceFeature().getName()); + int sourceIndex = getSourceIndex(); + if (sourceIndex != NO_INDEX) + { + builder.append("["); + builder.append(sourceIndex); + builder.append("]"); + } + + builder.append(" --> "); + builder.append(getTargetObject()); + return builder.toString(); + } + +} diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/object/DynamicCDOObjectImpl.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/object/DynamicCDOObjectImpl.java index ef7e46ea67..388becd11f 100644 --- a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/object/DynamicCDOObjectImpl.java +++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/object/DynamicCDOObjectImpl.java @@ -1,119 +1,119 @@ -/*
- * Copyright (c) 2004 - 2012 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
- * Martin Fluegge - EMap support
- */
-package org.eclipse.emf.internal.cdo.object;
-
-import org.eclipse.emf.internal.cdo.CDOObjectImpl;
-
-import org.eclipse.emf.common.util.BasicEMap;
-import org.eclipse.emf.ecore.EClass;
-import org.eclipse.emf.ecore.EStructuralFeature;
-
-/**
- * @author Eike Stepper
- */
-public class DynamicCDOObjectImpl extends CDOObjectImpl
-{
- private EClass eClass;
-
- public DynamicCDOObjectImpl(EClass eClass)
- {
- eSetClass(eClass);
- }
-
- @Override
- public EClass eClass()
- {
- return eClass;
- }
-
- @Override
- public void eSetClass(EClass eClass)
- {
- this.eClass = eClass;
- }
-
- @Override
- protected EClass eDynamicClass()
- {
- return eClass;
- }
-
- /**
- * @author Martin Fluegge
- * @since 3.0
- */
- public static final class BasicEMapEntry<K, V> extends DynamicCDOObjectImpl implements BasicEMap.Entry<K, V>
- {
- protected int hash = -1;
-
- protected EStructuralFeature keyFeature;
-
- protected EStructuralFeature valueFeature;
-
- /**
- * Creates a dynamic EObject.
- */
- public BasicEMapEntry(EClass eClass)
- {
- super(eClass);
- }
-
- @SuppressWarnings("unchecked")
- public K getKey()
- {
- return (K)eGet(keyFeature);
- }
-
- public void setKey(Object key)
- {
- eSet(keyFeature, key);
- }
-
- public int getHash()
- {
- if (hash == -1)
- {
- Object theKey = getKey();
- hash = theKey == null ? 0 : theKey.hashCode();
- }
-
- return hash;
- }
-
- public void setHash(int hash)
- {
- this.hash = hash;
- }
-
- @SuppressWarnings("unchecked")
- public V getValue()
- {
- return (V)eGet(valueFeature);
- }
-
- public V setValue(V value)
- {
- @SuppressWarnings("unchecked")
- V result = (V)eGet(valueFeature);
- eSet(valueFeature, value);
- return result;
- }
-
- @Override
- public void eSetClass(EClass eClass)
- {
- super.eSetClass(eClass);
- keyFeature = eClass.getEStructuralFeature("key");
- valueFeature = eClass.getEStructuralFeature("value");
- }
- }
-}
+/* + * Copyright (c) 2004 - 2012 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 + * Martin Fluegge - EMap support + */ +package org.eclipse.emf.internal.cdo.object; + +import org.eclipse.emf.internal.cdo.CDOObjectImpl; + +import org.eclipse.emf.common.util.BasicEMap; +import org.eclipse.emf.ecore.EClass; +import org.eclipse.emf.ecore.EStructuralFeature; + +/** + * @author Eike Stepper + */ +public class DynamicCDOObjectImpl extends CDOObjectImpl +{ + private EClass eClass; + + public DynamicCDOObjectImpl(EClass eClass) + { + eSetClass(eClass); + } + + @Override + public EClass eClass() + { + return eClass; + } + + @Override + public void eSetClass(EClass eClass) + { + this.eClass = eClass; + } + + @Override + protected EClass eDynamicClass() + { + return eClass; + } + + /** + * @author Martin Fluegge + * @since 3.0 + */ + public static final class BasicEMapEntry<K, V> extends DynamicCDOObjectImpl implements BasicEMap.Entry<K, V> + { + protected int hash = -1; + + protected EStructuralFeature keyFeature; + + protected EStructuralFeature valueFeature; + + /** + * Creates a dynamic EObject. + */ + public BasicEMapEntry(EClass eClass) + { + super(eClass); + } + + @SuppressWarnings("unchecked") + public K getKey() + { + return (K)eGet(keyFeature); + } + + public void setKey(Object key) + { + eSet(keyFeature, key); + } + + public int getHash() + { + if (hash == -1) + { + Object theKey = getKey(); + hash = theKey == null ? 0 : theKey.hashCode(); + } + + return hash; + } + + public void setHash(int hash) + { + this.hash = hash; + } + + @SuppressWarnings("unchecked") + public V getValue() + { + return (V)eGet(valueFeature); + } + + public V setValue(V value) + { + @SuppressWarnings("unchecked") + V result = (V)eGet(valueFeature); + eSet(valueFeature, value); + return result; + } + + @Override + public void eSetClass(EClass eClass) + { + super.eSetClass(eClass); + keyFeature = eClass.getEStructuralFeature("key"); + valueFeature = eClass.getEStructuralFeature("value"); + } + } +} diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/package-info.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/package-info.java index 6c66c5b477..88d6b26d33 100644 --- a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/package-info.java +++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/package-info.java @@ -1,16 +1,16 @@ -/*
- * Copyright (c) 2004 - 2012 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
- */
-
-/**
- * Exposes {@link org.eclipse.emf.internal.cdo.CDOObjectImpl} for extension in generated EMF models.
- */
-package org.eclipse.emf.internal.cdo;
-
+/* + * Copyright (c) 2004 - 2012 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 + */ + +/** + * Exposes {@link org.eclipse.emf.internal.cdo.CDOObjectImpl} for extension in generated EMF models. + */ +package org.eclipse.emf.internal.cdo; + diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/query/CDOQueryCDOIDIteratorImpl.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/query/CDOQueryCDOIDIteratorImpl.java index bf0fbe37ba..2ba395d734 100644 --- a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/query/CDOQueryCDOIDIteratorImpl.java +++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/query/CDOQueryCDOIDIteratorImpl.java @@ -1,43 +1,43 @@ -/*
- * Copyright (c) 2004 - 2012 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:
- * Simon McDuff - initial API and implementation
- * Eike Stepper - maintenance
- */
-package org.eclipse.emf.internal.cdo.query;
-
-import org.eclipse.emf.cdo.common.util.CDOQueryInfo;
-import org.eclipse.emf.cdo.view.CDOView;
-
-import org.eclipse.emf.spi.cdo.AbstractQueryIterator;
-
-import java.util.ArrayList;
-import java.util.List;
-
-/**
- * @author Simon McDuff
- */
-public class CDOQueryCDOIDIteratorImpl<CDOID> extends AbstractQueryIterator<CDOID>
-{
- public CDOQueryCDOIDIteratorImpl(CDOView view, CDOQueryInfo queryInfo)
- {
- super(view, queryInfo);
- }
-
- @Override
- public List<CDOID> asList()
- {
- ArrayList<CDOID> result = new ArrayList<CDOID>();
- while (hasNext())
- {
- result.add(next());
- }
-
- return result;
- }
-}
+/* + * Copyright (c) 2004 - 2012 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: + * Simon McDuff - initial API and implementation + * Eike Stepper - maintenance + */ +package org.eclipse.emf.internal.cdo.query; + +import org.eclipse.emf.cdo.common.util.CDOQueryInfo; +import org.eclipse.emf.cdo.view.CDOView; + +import org.eclipse.emf.spi.cdo.AbstractQueryIterator; + +import java.util.ArrayList; +import java.util.List; + +/** + * @author Simon McDuff + */ +public class CDOQueryCDOIDIteratorImpl<CDOID> extends AbstractQueryIterator<CDOID> +{ + public CDOQueryCDOIDIteratorImpl(CDOView view, CDOQueryInfo queryInfo) + { + super(view, queryInfo); + } + + @Override + public List<CDOID> asList() + { + ArrayList<CDOID> result = new ArrayList<CDOID>(); + while (hasNext()) + { + result.add(next()); + } + + return result; + } +} diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/query/CDOQueryImpl.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/query/CDOQueryImpl.java index 73d513caee..6297113821 100644 --- a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/query/CDOQueryImpl.java +++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/query/CDOQueryImpl.java @@ -1,190 +1,190 @@ -/*
- * Copyright (c) 2004 - 2012 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:
- * Simon McDuff - initial API and implementation
- * Eike Stepper - maintenance
- */
-package org.eclipse.emf.internal.cdo.query;
-
-import org.eclipse.emf.cdo.common.id.CDOID;
-import org.eclipse.emf.cdo.common.util.BlockingCloseableIterator;
-import org.eclipse.emf.cdo.internal.common.CDOQueryInfoImpl;
-import org.eclipse.emf.cdo.view.CDOQuery;
-
-import org.eclipse.emf.internal.cdo.messages.Messages;
-
-import org.eclipse.net4j.util.WrappedException;
-
-import org.eclipse.emf.spi.cdo.AbstractQueryIterator;
-import org.eclipse.emf.spi.cdo.FSMUtil;
-import org.eclipse.emf.spi.cdo.InternalCDOObject;
-import org.eclipse.emf.spi.cdo.InternalCDOView;
-
-import java.util.List;
-import java.util.Map.Entry;
-
-/**
- * @author Simon McDuff
- */
-public class CDOQueryImpl extends CDOQueryInfoImpl implements CDOQuery
-{
- private static final String OBJECT_NOT_PERSISTED_MESSAGE = Messages.getString("CDOQueryImpl.0"); //$NON-NLS-1$
-
- private InternalCDOView view;
-
- public CDOQueryImpl(InternalCDOView view, String queryLanguage, String queryString, Object context)
- {
- super(queryLanguage, queryString, context);
- this.view = view;
- setLegacyModeEnabled(view.isLegacyModeEnabled());
- }
-
- public InternalCDOView getView()
- {
- return view;
- }
-
- @Override
- public CDOQueryImpl setContext(Object context)
- {
- this.context = context;
- return this;
- }
-
- public CDOQueryImpl setParameter(String name, Object value)
- {
- parameters.put(name, value);
- return this;
- }
-
- @Override
- public CDOQueryImpl setMaxResults(int maxResults)
- {
- this.maxResults = maxResults;
- return this;
- }
-
- protected <T> AbstractQueryIterator<T> createQueryResult(Class<T> classObject)
- {
- CDOQueryInfoImpl queryInfo = createQueryInfo();
- if (CDOID.class.equals(classObject))
- {
- return new CDOQueryCDOIDIteratorImpl<T>(view, queryInfo);
- }
-
- return new CDOQueryResultIteratorImpl<T>(view, queryInfo);
- }
-
- public <T> List<T> getResult(Class<T> classObject)
- {
- AbstractQueryIterator<T> queryResult = null;
-
- try
- {
- queryResult = createQueryResult(classObject);
- view.getSession().getSessionProtocol().query(view, queryResult);
- return queryResult.asList();
- }
- finally
- {
- if (queryResult != null)
- {
- queryResult.close();
- }
- }
- }
-
- public <T> List<T> getResult()
- {
- return getResult(null);
- }
-
- public <T> BlockingCloseableIterator<T> getResultAsync(Class<T> classObject)
- {
- final AbstractQueryIterator<T> queryResult = createQueryResult(classObject);
- final Exception exception[] = new Exception[1];
- Runnable runnable = new Runnable()
- {
- public void run()
- {
- try
- {
- view.getSession().getSessionProtocol().query(view, queryResult);
- }
- catch (Exception ex)
- {
- queryResult.close();
- exception[0] = ex;
- }
- }
- };
-
- // TODO Simon: Can we leverage a thread pool?
- new Thread(runnable).start();
-
- try
- {
- queryResult.waitForInitialization();
- }
- catch (Exception ex)
- {
- exception[0] = ex;
- }
-
- if (exception[0] != null)
- {
- throw WrappedException.wrap(exception[0]);
- }
-
- return queryResult;
- }
-
- public <T> BlockingCloseableIterator<T> getResultAsync()
- {
- return getResultAsync(null);
- }
-
- protected CDOQueryInfoImpl createQueryInfo()
- {
- CDOQueryInfoImpl queryInfo = new CDOQueryInfoImpl(getQueryLanguage(), getQueryString(), getContext());
- queryInfo.setMaxResults(getMaxResults());
- queryInfo.setLegacyModeEnabled(isLegacyModeEnabled());
- queryInfo.setChangeSetData(getChangeSetData());
-
- for (Entry<String, Object> entry : getParameters().entrySet())
- {
- Object value = entry.getValue();
- value = adapt(value);
- queryInfo.addParameter(entry.getKey(), value);
- }
-
- return queryInfo;
- }
-
- protected Object adapt(Object object)
- {
- if (object instanceof InternalCDOObject)
- {
- InternalCDOObject internalCDOObject = FSMUtil.adapt(object, view);
- CDOID id = internalCDOObject.cdoID();
- if (id == null)
- {
- throw new UnsupportedOperationException(OBJECT_NOT_PERSISTED_MESSAGE);
- }
-
- if (view.isObjectNew(id))
- {
- throw new UnsupportedOperationException(OBJECT_NOT_PERSISTED_MESSAGE);
- }
-
- return id;
- }
-
- return object;
- }
-}
+/* + * Copyright (c) 2004 - 2012 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: + * Simon McDuff - initial API and implementation + * Eike Stepper - maintenance + */ +package org.eclipse.emf.internal.cdo.query; + +import org.eclipse.emf.cdo.common.id.CDOID; +import org.eclipse.emf.cdo.common.util.BlockingCloseableIterator; +import org.eclipse.emf.cdo.internal.common.CDOQueryInfoImpl; +import org.eclipse.emf.cdo.view.CDOQuery; + +import org.eclipse.emf.internal.cdo.messages.Messages; + +import org.eclipse.net4j.util.WrappedException; + +import org.eclipse.emf.spi.cdo.AbstractQueryIterator; +import org.eclipse.emf.spi.cdo.FSMUtil; +import org.eclipse.emf.spi.cdo.InternalCDOObject; +import org.eclipse.emf.spi.cdo.InternalCDOView; + +import java.util.List; +import java.util.Map.Entry; + +/** + * @author Simon McDuff + */ +public class CDOQueryImpl extends CDOQueryInfoImpl implements CDOQuery +{ + private static final String OBJECT_NOT_PERSISTED_MESSAGE = Messages.getString("CDOQueryImpl.0"); //$NON-NLS-1$ + + private InternalCDOView view; + + public CDOQueryImpl(InternalCDOView view, String queryLanguage, String queryString, Object context) + { + super(queryLanguage, queryString, context); + this.view = view; + setLegacyModeEnabled(view.isLegacyModeEnabled()); + } + + public InternalCDOView getView() + { + return view; + } + + @Override + public CDOQueryImpl setContext(Object context) + { + this.context = context; + return this; + } + + public CDOQueryImpl setParameter(String name, Object value) + { + parameters.put(name, value); + return this; + } + + @Override + public CDOQueryImpl setMaxResults(int maxResults) + { + this.maxResults = maxResults; + return this; + } + + protected <T> AbstractQueryIterator<T> createQueryResult(Class<T> classObject) + { + CDOQueryInfoImpl queryInfo = createQueryInfo(); + if (CDOID.class.equals(classObject)) + { + return new CDOQueryCDOIDIteratorImpl<T>(view, queryInfo); + } + + return new CDOQueryResultIteratorImpl<T>(view, queryInfo); + } + + public <T> List<T> getResult(Class<T> classObject) + { + AbstractQueryIterator<T> queryResult = null; + + try + { + queryResult = createQueryResult(classObject); + view.getSession().getSessionProtocol().query(view, queryResult); + return queryResult.asList(); + } + finally + { + if (queryResult != null) + { + queryResult.close(); + } + } + } + + public <T> List<T> getResult() + { + return getResult(null); + } + + public <T> BlockingCloseableIterator<T> getResultAsync(Class<T> classObject) + { + final AbstractQueryIterator<T> queryResult = createQueryResult(classObject); + final Exception exception[] = new Exception[1]; + Runnable runnable = new Runnable() + { + public void run() + { + try + { + view.getSession().getSessionProtocol().query(view, queryResult); + } + catch (Exception ex) + { + queryResult.close(); + exception[0] = ex; + } + } + }; + + // TODO Simon: Can we leverage a thread pool? + new Thread(runnable).start(); + + try + { + queryResult.waitForInitialization(); + } + catch (Exception ex) + { + exception[0] = ex; + } + + if (exception[0] != null) + { + throw WrappedException.wrap(exception[0]); + } + + return queryResult; + } + + public <T> BlockingCloseableIterator<T> getResultAsync() + { + return getResultAsync(null); + } + + protected CDOQueryInfoImpl createQueryInfo() + { + CDOQueryInfoImpl queryInfo = new CDOQueryInfoImpl(getQueryLanguage(), getQueryString(), getContext()); + queryInfo.setMaxResults(getMaxResults()); + queryInfo.setLegacyModeEnabled(isLegacyModeEnabled()); + queryInfo.setChangeSetData(getChangeSetData()); + + for (Entry<String, Object> entry : getParameters().entrySet()) + { + Object value = entry.getValue(); + value = adapt(value); + queryInfo.addParameter(entry.getKey(), value); + } + + return queryInfo; + } + + protected Object adapt(Object object) + { + if (object instanceof InternalCDOObject) + { + InternalCDOObject internalCDOObject = FSMUtil.adapt(object, view); + CDOID id = internalCDOObject.cdoID(); + if (id == null) + { + throw new UnsupportedOperationException(OBJECT_NOT_PERSISTED_MESSAGE); + } + + if (view.isObjectNew(id)) + { + throw new UnsupportedOperationException(OBJECT_NOT_PERSISTED_MESSAGE); + } + + return id; + } + + return object; + } +} diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/session/CDOCollectionLoadingPolicyImpl.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/session/CDOCollectionLoadingPolicyImpl.java index e4a682c2d2..072f2c561c 100644 --- a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/session/CDOCollectionLoadingPolicyImpl.java +++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/session/CDOCollectionLoadingPolicyImpl.java @@ -1,139 +1,139 @@ -/*
- * Copyright (c) 2004 - 2012 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:
- * Simon McDuff - initial API and implementation
- * Eike Stepper - maintenance
- */
-package org.eclipse.emf.internal.cdo.session;
-
-import org.eclipse.emf.cdo.common.revision.CDOElementProxy;
-import org.eclipse.emf.cdo.common.revision.CDORevision;
-import org.eclipse.emf.cdo.session.CDOCollectionLoadingPolicy;
-import org.eclipse.emf.cdo.session.CDOSession;
-import org.eclipse.emf.cdo.spi.common.revision.InternalCDORevision;
-
-import org.eclipse.net4j.util.collection.MoveableList;
-
-import org.eclipse.emf.ecore.EStructuralFeature;
-import org.eclipse.emf.spi.cdo.CDOSessionProtocol;
-import org.eclipse.emf.spi.cdo.InternalCDOSession;
-
-/**
- * @author Simon McDuff
- * @since 2.0
- */
-public class CDOCollectionLoadingPolicyImpl implements CDOCollectionLoadingPolicy
-{
- private CDOSession session;
-
- private int initialChunkSize;
-
- private int resolveChunkSize;
-
- public CDOCollectionLoadingPolicyImpl(int initialChunkSize, int resolveChunkSize)
- {
- this.resolveChunkSize = resolveChunkSize <= 0 ? CDORevision.UNCHUNKED : resolveChunkSize;
- this.initialChunkSize = initialChunkSize < 0 ? resolveChunkSize : initialChunkSize;
- }
-
- public CDOSession getSession()
- {
- return session;
- }
-
- public void setSession(CDOSession session)
- {
- this.session = session;
- }
-
- public int getInitialChunkSize()
- {
- return initialChunkSize;
- }
-
- public int getResolveChunkSize()
- {
- return resolveChunkSize;
- }
-
- public void resolveAllProxies(CDORevision revision, EStructuralFeature feature)
- {
- doResolveProxy(revision, feature, 0, 0, Integer.MAX_VALUE);
- }
-
- public Object resolveProxy(CDORevision rev, EStructuralFeature feature, int accessIndex, int serverIndex)
- {
- int chunkSize = resolveChunkSize;
- if (chunkSize == CDORevision.UNCHUNKED)
- {
- // Can happen if CDOSession.setReferenceChunkSize() was called meanwhile
- chunkSize = Integer.MAX_VALUE;
- }
-
- return doResolveProxy(rev, feature, accessIndex, serverIndex, chunkSize);
- }
-
- private Object doResolveProxy(CDORevision rev, EStructuralFeature feature, int accessIndex, int serverIndex,
- int chunkSize)
- {
- // Get proxy values
- InternalCDORevision revision = (InternalCDORevision)rev;
- int fetchIndex = serverIndex;
-
- MoveableList<Object> list = revision.getList(feature);
- int size = list.size();
- int fromIndex = accessIndex;
- int toIndex = accessIndex;
- boolean minReached = false;
- boolean maxReached = false;
- boolean alternation = false;
- for (int i = 0; i < chunkSize; i++)
- {
- if (alternation)
- {
- if (!maxReached && toIndex < size - 1 && list.get(toIndex + 1) instanceof CDOElementProxy)
- {
- ++toIndex;
- }
- else
- {
- maxReached = true;
- }
-
- if (!minReached)
- {
- alternation = false;
- }
- }
- else
- {
- if (!minReached && fromIndex > 0 && list.get(fromIndex - 1) instanceof CDOElementProxy)
- {
- --fromIndex;
- }
- else
- {
- minReached = true;
- }
-
- if (!maxReached)
- {
- alternation = true;
- }
- }
-
- if (minReached && maxReached)
- {
- break;
- }
- }
-
- CDOSessionProtocol protocol = ((InternalCDOSession)session).getSessionProtocol();
- return protocol.loadChunk(revision, feature, accessIndex, fetchIndex, fromIndex, toIndex);
- }
-}
+/* + * Copyright (c) 2004 - 2012 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: + * Simon McDuff - initial API and implementation + * Eike Stepper - maintenance + */ +package org.eclipse.emf.internal.cdo.session; + +import org.eclipse.emf.cdo.common.revision.CDOElementProxy; +import org.eclipse.emf.cdo.common.revision.CDORevision; +import org.eclipse.emf.cdo.session.CDOCollectionLoadingPolicy; +import org.eclipse.emf.cdo.session.CDOSession; +import org.eclipse.emf.cdo.spi.common.revision.InternalCDORevision; + +import org.eclipse.net4j.util.collection.MoveableList; + +import org.eclipse.emf.ecore.EStructuralFeature; +import org.eclipse.emf.spi.cdo.CDOSessionProtocol; +import org.eclipse.emf.spi.cdo.InternalCDOSession; + +/** + * @author Simon McDuff + * @since 2.0 + */ +public class CDOCollectionLoadingPolicyImpl implements CDOCollectionLoadingPolicy +{ + private CDOSession session; + + private int initialChunkSize; + + private int resolveChunkSize; + + public CDOCollectionLoadingPolicyImpl(int initialChunkSize, int resolveChunkSize) + { + this.resolveChunkSize = resolveChunkSize <= 0 ? CDORevision.UNCHUNKED : resolveChunkSize; + this.initialChunkSize = initialChunkSize < 0 ? resolveChunkSize : initialChunkSize; + } + + public CDOSession getSession() + { + return session; + } + + public void setSession(CDOSession session) + { + this.session = session; + } + + public int getInitialChunkSize() + { + return initialChunkSize; + } + + public int getResolveChunkSize() + { + return resolveChunkSize; + } + + public void resolveAllProxies(CDORevision revision, EStructuralFeature feature) + { + doResolveProxy(revision, feature, 0, 0, Integer.MAX_VALUE); + } + + public Object resolveProxy(CDORevision rev, EStructuralFeature feature, int accessIndex, int serverIndex) + { + int chunkSize = resolveChunkSize; + if (chunkSize == CDORevision.UNCHUNKED) + { + // Can happen if CDOSession.setReferenceChunkSize() was called meanwhile + chunkSize = Integer.MAX_VALUE; + } + + return doResolveProxy(rev, feature, accessIndex, serverIndex, chunkSize); + } + + private Object doResolveProxy(CDORevision rev, EStructuralFeature feature, int accessIndex, int serverIndex, + int chunkSize) + { + // Get proxy values + InternalCDORevision revision = (InternalCDORevision)rev; + int fetchIndex = serverIndex; + + MoveableList<Object> list = revision.getList(feature); + int size = list.size(); + int fromIndex = accessIndex; + int toIndex = accessIndex; + boolean minReached = false; + boolean maxReached = false; + boolean alternation = false; + for (int i = 0; i < chunkSize; i++) + { + if (alternation) + { + if (!maxReached && toIndex < size - 1 && list.get(toIndex + 1) instanceof CDOElementProxy) + { + ++toIndex; + } + else + { + maxReached = true; + } + + if (!minReached) + { + alternation = false; + } + } + else + { + if (!minReached && fromIndex > 0 && list.get(fromIndex - 1) instanceof CDOElementProxy) + { + --fromIndex; + } + else + { + minReached = true; + } + + if (!maxReached) + { + alternation = true; + } + } + + if (minReached && maxReached) + { + break; + } + } + + CDOSessionProtocol protocol = ((InternalCDOSession)session).getSessionProtocol(); + return protocol.loadChunk(revision, feature, accessIndex, fetchIndex, fromIndex, toIndex); + } +} diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/session/CDOSessionConfigurationImpl.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/session/CDOSessionConfigurationImpl.java index 06656f969b..99952d6e6e 100644 --- a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/session/CDOSessionConfigurationImpl.java +++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/session/CDOSessionConfigurationImpl.java @@ -1,347 +1,347 @@ -/*
- * Copyright (c) 2004 - 2012 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.internal.cdo.session;
-
-import org.eclipse.emf.cdo.common.CDOCommonSession.Options.LockNotificationMode;
-import org.eclipse.emf.cdo.common.CDOCommonSession.Options.PassiveUpdateMode;
-import org.eclipse.emf.cdo.common.branch.CDOBranchManager;
-import org.eclipse.emf.cdo.common.commit.CDOCommitInfoManager;
-import org.eclipse.emf.cdo.common.id.CDOIDGenerator;
-import org.eclipse.emf.cdo.common.model.CDOPackageRegistry;
-import org.eclipse.emf.cdo.common.protocol.CDOAuthenticator;
-import org.eclipse.emf.cdo.common.revision.CDORevisionManager;
-import org.eclipse.emf.cdo.session.CDOSession;
-import org.eclipse.emf.cdo.session.CDOSessionConfiguration;
-import org.eclipse.emf.cdo.spi.common.branch.InternalCDOBranchManager;
-import org.eclipse.emf.cdo.spi.common.commit.InternalCDOCommitInfoManager;
-import org.eclipse.emf.cdo.spi.common.model.InternalCDOPackageRegistry;
-import org.eclipse.emf.cdo.spi.common.revision.InternalCDORevisionManager;
-import org.eclipse.emf.cdo.view.CDOFetchRuleManager;
-
-import org.eclipse.emf.internal.cdo.messages.Messages;
-
-import org.eclipse.net4j.util.event.IListener;
-import org.eclipse.net4j.util.event.Notifier;
-import org.eclipse.net4j.util.lifecycle.ILifecycle;
-import org.eclipse.net4j.util.lifecycle.LifecycleEventAdapter;
-
-import org.eclipse.emf.spi.cdo.InternalCDOSession;
-import org.eclipse.emf.spi.cdo.InternalCDOSessionConfiguration;
-
-/**
- * @author Eike Stepper
- */
-public abstract class CDOSessionConfigurationImpl extends Notifier implements InternalCDOSessionConfiguration
-{
- private boolean passiveUpdateEnabled = true;
-
- private PassiveUpdateMode passiveUpdateMode = PassiveUpdateMode.INVALIDATIONS;
-
- private LockNotificationMode lockNotificationMode = LockNotificationMode.IF_REQUIRED_BY_VIEWS;
-
- private CDOAuthenticator authenticator = new CDOAuthenticatorImpl();
-
- private CDOSession.ExceptionHandler exceptionHandler;
-
- private CDOIDGenerator idGenerator;
-
- private CDOFetchRuleManager fetchRuleManager;
-
- private InternalCDOBranchManager branchManager;
-
- private InternalCDOPackageRegistry packageRegistry;
-
- private InternalCDORevisionManager revisionManager;
-
- private InternalCDOCommitInfoManager commitInfoManager;
-
- private boolean mainBranchLocal;
-
- private boolean activateOnOpen = true;
-
- private InternalCDOSession session;
-
- private final IListener lifecycleEventAdapter = new LifecycleEventAdapter()
- {
- @Override
- protected void onActivated(final ILifecycle newSession)
- {
- newSession.removeListener(lifecycleEventAdapter);
- fireEvent(new SessionOpenedEvent()
- {
- public CDOSessionConfiguration getSource()
- {
- return CDOSessionConfigurationImpl.this;
- }
-
- public CDOSession getOpenedSession()
- {
- return (CDOSession)newSession;
- }
- });
- }
- };
-
- public CDOSessionConfigurationImpl()
- {
- }
-
- public boolean isPassiveUpdateEnabled()
- {
- return passiveUpdateEnabled;
- }
-
- public void setPassiveUpdateEnabled(boolean passiveUpdateEnabled)
- {
- checkNotOpen();
- uncheckedSetPassiveUpdateEnabled(passiveUpdateEnabled);
- }
-
- protected void uncheckedSetPassiveUpdateEnabled(boolean passiveUpdateEnabled)
- {
- this.passiveUpdateEnabled = passiveUpdateEnabled;
- }
-
- public PassiveUpdateMode getPassiveUpdateMode()
- {
- return passiveUpdateMode;
- }
-
- public void setPassiveUpdateMode(PassiveUpdateMode passiveUpdateMode)
- {
- checkNotOpen();
- uncheckedSetPassiveUpdateMode(passiveUpdateMode);
- }
-
- protected void uncheckedSetPassiveUpdateMode(PassiveUpdateMode passiveUpdateMode)
- {
- this.passiveUpdateMode = passiveUpdateMode;
- }
-
- public LockNotificationMode getLockNotificationMode()
- {
- return lockNotificationMode;
- }
-
- public void setLockNotificationMode(LockNotificationMode lockNotificationMode)
- {
- checkNotOpen();
- uncheckedSetLockNotificationMode(lockNotificationMode);
- }
-
- protected void uncheckedSetLockNotificationMode(LockNotificationMode lockNotificationMode)
- {
- this.lockNotificationMode = lockNotificationMode;
- }
-
- public CDOAuthenticator getAuthenticator()
- {
- return authenticator;
- }
-
- public void setAuthenticator(CDOAuthenticator authenticator)
- {
- checkNotOpen();
- this.authenticator = authenticator;
- }
-
- public CDOSession.ExceptionHandler getExceptionHandler()
- {
- return exceptionHandler;
- }
-
- public void setExceptionHandler(CDOSession.ExceptionHandler exceptionHandler)
- {
- checkNotOpen();
- this.exceptionHandler = exceptionHandler;
- }
-
- public CDOIDGenerator getIDGenerator()
- {
- return idGenerator;
- }
-
- public void setIDGenerator(CDOIDGenerator idGenerator)
- {
- checkNotOpen();
- this.idGenerator = idGenerator;
- }
-
- public CDOFetchRuleManager getFetchRuleManager()
- {
- return fetchRuleManager;
- }
-
- public void setFetchRuleManager(CDOFetchRuleManager fetchRuleManager)
- {
- checkNotOpen();
- this.fetchRuleManager = fetchRuleManager;
- }
-
- public InternalCDOBranchManager getBranchManager()
- {
- return branchManager;
- }
-
- public void setBranchManager(CDOBranchManager branchManager)
- {
- checkNotOpen();
- this.branchManager = (InternalCDOBranchManager)branchManager;
- }
-
- public InternalCDOPackageRegistry getPackageRegistry()
- {
- return packageRegistry;
- }
-
- public void setPackageRegistry(CDOPackageRegistry packageRegistry)
- {
- checkNotOpen();
- this.packageRegistry = (InternalCDOPackageRegistry)packageRegistry;
- }
-
- public InternalCDORevisionManager getRevisionManager()
- {
- return revisionManager;
- }
-
- public void setRevisionManager(CDORevisionManager revisionManager)
- {
- checkNotOpen();
- this.revisionManager = (InternalCDORevisionManager)revisionManager;
- }
-
- /**
- * Returns the commit info manager. The commit info manager may be used to query commit infos.
- *
- * @return the commit info manager
- * @see CDOCommitInfoManager
- */
- public InternalCDOCommitInfoManager getCommitInfoManager()
- {
- return commitInfoManager;
- }
-
- /**
- * Sets the commit info manager. The commit info manager may be used to query commit infos. May only be called as long
- * as the session's not opened yet
- *
- * @param commitInfoManager
- * the new commit info manager
- * @see CDOCommitInfoManager
- */
- public void setCommitInfoManager(CDOCommitInfoManager commitInfoManager)
- {
- checkNotOpen();
- this.commitInfoManager = (InternalCDOCommitInfoManager)commitInfoManager;
- }
-
- public boolean isMainBranchLocal()
- {
- return mainBranchLocal;
- }
-
- public void setMainBranchLocal(boolean mainBranchLocal)
- {
- this.mainBranchLocal = mainBranchLocal;
- }
-
- public boolean isActivateOnOpen()
- {
- return activateOnOpen;
- }
-
- public void setActivateOnOpen(boolean activateOnOpen)
- {
- checkNotOpen();
- this.activateOnOpen = activateOnOpen;
- }
-
- public boolean isSessionOpen()
- {
- if (session == null)
- {
- return false;
- }
-
- if (!session.isClosed())
- {
- return true;
- }
-
- session = null;
- return false;
- }
-
- /**
- * @since 2.0
- */
- public CDOSession openSession()
- {
- if (!isSessionOpen())
- {
- session = createSession();
- session.addListener(lifecycleEventAdapter);
- configureSession(session);
-
- if (activateOnOpen)
- {
- session.activate();
- }
- }
-
- return session;
- }
-
- protected void configureSession(InternalCDOSession session)
- {
- session.options().setPassiveUpdateEnabled(passiveUpdateEnabled);
- session.options().setPassiveUpdateMode(passiveUpdateMode);
- session.options().setLockNotificationMode(lockNotificationMode);
-
- session.setMainBranchLocal(mainBranchLocal);
- session.setExceptionHandler(exceptionHandler);
- session.setFetchRuleManager(fetchRuleManager);
- session.setIDGenerator(idGenerator);
- session.setAuthenticator(authenticator);
- session.setRevisionManager(revisionManager);
- session.setBranchManager(branchManager);
- session.setCommitInfoManager(commitInfoManager);
- session.setPackageRegistry(packageRegistry);
- }
-
- public InternalCDOSession getSession()
- {
- checkOpen();
- return session;
- }
-
- protected void setSession(InternalCDOSession session)
- {
- this.session = session;
- }
-
- protected void checkOpen()
- {
- if (!isSessionOpen())
- {
- throw new IllegalStateException(Messages.getString("CDOSessionConfigurationImpl.1")); //$NON-NLS-1$
- }
- }
-
- protected void checkNotOpen()
- {
- if (isSessionOpen())
- {
- throw new IllegalStateException(Messages.getString("CDOSessionConfigurationImpl.0")); //$NON-NLS-1$
- }
- }
-}
+/* + * Copyright (c) 2004 - 2012 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.internal.cdo.session; + +import org.eclipse.emf.cdo.common.CDOCommonSession.Options.LockNotificationMode; +import org.eclipse.emf.cdo.common.CDOCommonSession.Options.PassiveUpdateMode; +import org.eclipse.emf.cdo.common.branch.CDOBranchManager; +import org.eclipse.emf.cdo.common.commit.CDOCommitInfoManager; +import org.eclipse.emf.cdo.common.id.CDOIDGenerator; +import org.eclipse.emf.cdo.common.model.CDOPackageRegistry; +import org.eclipse.emf.cdo.common.protocol.CDOAuthenticator; +import org.eclipse.emf.cdo.common.revision.CDORevisionManager; +import org.eclipse.emf.cdo.session.CDOSession; +import org.eclipse.emf.cdo.session.CDOSessionConfiguration; +import org.eclipse.emf.cdo.spi.common.branch.InternalCDOBranchManager; +import org.eclipse.emf.cdo.spi.common.commit.InternalCDOCommitInfoManager; +import org.eclipse.emf.cdo.spi.common.model.InternalCDOPackageRegistry; +import org.eclipse.emf.cdo.spi.common.revision.InternalCDORevisionManager; +import org.eclipse.emf.cdo.view.CDOFetchRuleManager; + +import org.eclipse.emf.internal.cdo.messages.Messages; + +import org.eclipse.net4j.util.event.IListener; +import org.eclipse.net4j.util.event.Notifier; +import org.eclipse.net4j.util.lifecycle.ILifecycle; +import org.eclipse.net4j.util.lifecycle.LifecycleEventAdapter; + +import org.eclipse.emf.spi.cdo.InternalCDOSession; +import org.eclipse.emf.spi.cdo.InternalCDOSessionConfiguration; + +/** + * @author Eike Stepper + */ +public abstract class CDOSessionConfigurationImpl extends Notifier implements InternalCDOSessionConfiguration +{ + private boolean passiveUpdateEnabled = true; + + private PassiveUpdateMode passiveUpdateMode = PassiveUpdateMode.INVALIDATIONS; + + private LockNotificationMode lockNotificationMode = LockNotificationMode.IF_REQUIRED_BY_VIEWS; + + private CDOAuthenticator authenticator = new CDOAuthenticatorImpl(); + + private CDOSession.ExceptionHandler exceptionHandler; + + private CDOIDGenerator idGenerator; + + private CDOFetchRuleManager fetchRuleManager; + + private InternalCDOBranchManager branchManager; + + private InternalCDOPackageRegistry packageRegistry; + + private InternalCDORevisionManager revisionManager; + + private InternalCDOCommitInfoManager commitInfoManager; + + private boolean mainBranchLocal; + + private boolean activateOnOpen = true; + + private InternalCDOSession session; + + private final IListener lifecycleEventAdapter = new LifecycleEventAdapter() + { + @Override + protected void onActivated(final ILifecycle newSession) + { + newSession.removeListener(lifecycleEventAdapter); + fireEvent(new SessionOpenedEvent() + { + public CDOSessionConfiguration getSource() + { + return CDOSessionConfigurationImpl.this; + } + + public CDOSession getOpenedSession() + { + return (CDOSession)newSession; + } + }); + } + }; + + public CDOSessionConfigurationImpl() + { + } + + public boolean isPassiveUpdateEnabled() + { + return passiveUpdateEnabled; + } + + public void setPassiveUpdateEnabled(boolean passiveUpdateEnabled) + { + checkNotOpen(); + uncheckedSetPassiveUpdateEnabled(passiveUpdateEnabled); + } + + protected void uncheckedSetPassiveUpdateEnabled(boolean passiveUpdateEnabled) + { + this.passiveUpdateEnabled = passiveUpdateEnabled; + } + + public PassiveUpdateMode getPassiveUpdateMode() + { + return passiveUpdateMode; + } + + public void setPassiveUpdateMode(PassiveUpdateMode passiveUpdateMode) + { + checkNotOpen(); + uncheckedSetPassiveUpdateMode(passiveUpdateMode); + } + + protected void uncheckedSetPassiveUpdateMode(PassiveUpdateMode passiveUpdateMode) + { + this.passiveUpdateMode = passiveUpdateMode; + } + + public LockNotificationMode getLockNotificationMode() + { + return lockNotificationMode; + } + + public void setLockNotificationMode(LockNotificationMode lockNotificationMode) + { + checkNotOpen(); + uncheckedSetLockNotificationMode(lockNotificationMode); + } + + protected void uncheckedSetLockNotificationMode(LockNotificationMode lockNotificationMode) + { + this.lockNotificationMode = lockNotificationMode; + } + + public CDOAuthenticator getAuthenticator() + { + return authenticator; + } + + public void setAuthenticator(CDOAuthenticator authenticator) + { + checkNotOpen(); + this.authenticator = authenticator; + } + + public CDOSession.ExceptionHandler getExceptionHandler() + { + return exceptionHandler; + } + + public void setExceptionHandler(CDOSession.ExceptionHandler exceptionHandler) + { + checkNotOpen(); + this.exceptionHandler = exceptionHandler; + } + + public CDOIDGenerator getIDGenerator() + { + return idGenerator; + } + + public void setIDGenerator(CDOIDGenerator idGenerator) + { + checkNotOpen(); + this.idGenerator = idGenerator; + } + + public CDOFetchRuleManager getFetchRuleManager() + { + return fetchRuleManager; + } + + public void setFetchRuleManager(CDOFetchRuleManager fetchRuleManager) + { + checkNotOpen(); + this.fetchRuleManager = fetchRuleManager; + } + + public InternalCDOBranchManager getBranchManager() + { + return branchManager; + } + + public void setBranchManager(CDOBranchManager branchManager) + { + checkNotOpen(); + this.branchManager = (InternalCDOBranchManager)branchManager; + } + + public InternalCDOPackageRegistry getPackageRegistry() + { + return packageRegistry; + } + + public void setPackageRegistry(CDOPackageRegistry packageRegistry) + { + checkNotOpen(); + this.packageRegistry = (InternalCDOPackageRegistry)packageRegistry; + } + + public InternalCDORevisionManager getRevisionManager() + { + return revisionManager; + } + + public void setRevisionManager(CDORevisionManager revisionManager) + { + checkNotOpen(); + this.revisionManager = (InternalCDORevisionManager)revisionManager; + } + + /** + * Returns the commit info manager. The commit info manager may be used to query commit infos. + * + * @return the commit info manager + * @see CDOCommitInfoManager + */ + public InternalCDOCommitInfoManager getCommitInfoManager() + { + return commitInfoManager; + } + + /** + * Sets the commit info manager. The commit info manager may be used to query commit infos. May only be called as long + * as the session's not opened yet + * + * @param commitInfoManager + * the new commit info manager + * @see CDOCommitInfoManager + */ + public void setCommitInfoManager(CDOCommitInfoManager commitInfoManager) + { + checkNotOpen(); + this.commitInfoManager = (InternalCDOCommitInfoManager)commitInfoManager; + } + + public boolean isMainBranchLocal() + { + return mainBranchLocal; + } + + public void setMainBranchLocal(boolean mainBranchLocal) + { + this.mainBranchLocal = mainBranchLocal; + } + + public boolean isActivateOnOpen() + { + return activateOnOpen; + } + + public void setActivateOnOpen(boolean activateOnOpen) + { + checkNotOpen(); + this.activateOnOpen = activateOnOpen; + } + + public boolean isSessionOpen() + { + if (session == null) + { + return false; + } + + if (!session.isClosed()) + { + return true; + } + + session = null; + return false; + } + + /** + * @since 2.0 + */ + public CDOSession openSession() + { + if (!isSessionOpen()) + { + session = createSession(); + session.addListener(lifecycleEventAdapter); + configureSession(session); + + if (activateOnOpen) + { + session.activate(); + } + } + + return session; + } + + protected void configureSession(InternalCDOSession session) + { + session.options().setPassiveUpdateEnabled(passiveUpdateEnabled); + session.options().setPassiveUpdateMode(passiveUpdateMode); + session.options().setLockNotificationMode(lockNotificationMode); + + session.setMainBranchLocal(mainBranchLocal); + session.setExceptionHandler(exceptionHandler); + session.setFetchRuleManager(fetchRuleManager); + session.setIDGenerator(idGenerator); + session.setAuthenticator(authenticator); + session.setRevisionManager(revisionManager); + session.setBranchManager(branchManager); + session.setCommitInfoManager(commitInfoManager); + session.setPackageRegistry(packageRegistry); + } + + public InternalCDOSession getSession() + { + checkOpen(); + return session; + } + + protected void setSession(InternalCDOSession session) + { + this.session = session; + } + + protected void checkOpen() + { + if (!isSessionOpen()) + { + throw new IllegalStateException(Messages.getString("CDOSessionConfigurationImpl.1")); //$NON-NLS-1$ + } + } + + protected void checkNotOpen() + { + if (isSessionOpen()) + { + throw new IllegalStateException(Messages.getString("CDOSessionConfigurationImpl.0")); //$NON-NLS-1$ + } + } +} diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/session/CDOSessionFactory.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/session/CDOSessionFactory.java index adafc476e6..219b0c968e 100644 --- a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/session/CDOSessionFactory.java +++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/session/CDOSessionFactory.java @@ -1,73 +1,73 @@ -/*
- * Copyright (c) 2004 - 2012 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.internal.cdo.session;
-
-import org.eclipse.emf.cdo.session.CDOSession;
-import org.eclipse.emf.cdo.util.CDOURIUtil;
-
-import org.eclipse.emf.internal.cdo.messages.Messages;
-
-import org.eclipse.net4j.util.StringUtil;
-import org.eclipse.net4j.util.factory.Factory;
-
-import org.eclipse.emf.spi.cdo.InternalCDOSession;
-
-import java.net.URI;
-import java.net.URISyntaxException;
-import java.text.MessageFormat;
-import java.util.Map;
-
-/**
- * @author Eike Stepper
- */
-public abstract class CDOSessionFactory extends Factory
-{
- public static final String PRODUCT_GROUP = "org.eclipse.emf.cdo.sessions"; //$NON-NLS-1$
-
- private static final String TRUE = Boolean.TRUE.toString();
-
- public CDOSessionFactory(String type)
- {
- super(PRODUCT_GROUP, type);
- }
-
- public CDOSession create(String description)
- {
- try
- {
- URI uri = new URI(description);
- String query = uri.getQuery();
- if (StringUtil.isEmpty(query))
- {
- throw new IllegalArgumentException(MessageFormat.format(Messages.getString("CDOSessionFactory.1"), description)); //$NON-NLS-1$
- }
-
- Map<String, String> result = CDOURIUtil.getParameters(query);
- String repositoryName = result.get("repositoryName"); //$NON-NLS-1$
- if (repositoryName == null)
- {
- throw new IllegalArgumentException("Repository name is missing: " + description);
- }
-
- boolean automaticPackageRegistry = TRUE.equals(result.get("automaticPackageRegistry")); //$NON-NLS-1$
- return createSession(repositoryName, automaticPackageRegistry);
- }
- catch (URISyntaxException ex)
- {
- throw new IllegalArgumentException(ex);
- }
- }
-
- /**
- * @since 2.0
- */
- protected abstract InternalCDOSession createSession(String repositoryName, boolean automaticPackageRegistry);
-}
+/* + * Copyright (c) 2004 - 2012 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.internal.cdo.session; + +import org.eclipse.emf.cdo.session.CDOSession; +import org.eclipse.emf.cdo.util.CDOURIUtil; + +import org.eclipse.emf.internal.cdo.messages.Messages; + +import org.eclipse.net4j.util.StringUtil; +import org.eclipse.net4j.util.factory.Factory; + +import org.eclipse.emf.spi.cdo.InternalCDOSession; + +import java.net.URI; +import java.net.URISyntaxException; +import java.text.MessageFormat; +import java.util.Map; + +/** + * @author Eike Stepper + */ +public abstract class CDOSessionFactory extends Factory +{ + public static final String PRODUCT_GROUP = "org.eclipse.emf.cdo.sessions"; //$NON-NLS-1$ + + private static final String TRUE = Boolean.TRUE.toString(); + + public CDOSessionFactory(String type) + { + super(PRODUCT_GROUP, type); + } + + public CDOSession create(String description) + { + try + { + URI uri = new URI(description); + String query = uri.getQuery(); + if (StringUtil.isEmpty(query)) + { + throw new IllegalArgumentException(MessageFormat.format(Messages.getString("CDOSessionFactory.1"), description)); //$NON-NLS-1$ + } + + Map<String, String> result = CDOURIUtil.getParameters(query); + String repositoryName = result.get("repositoryName"); //$NON-NLS-1$ + if (repositoryName == null) + { + throw new IllegalArgumentException("Repository name is missing: " + description); + } + + boolean automaticPackageRegistry = TRUE.equals(result.get("automaticPackageRegistry")); //$NON-NLS-1$ + return createSession(repositoryName, automaticPackageRegistry); + } + catch (URISyntaxException ex) + { + throw new IllegalArgumentException(ex); + } + } + + /** + * @since 2.0 + */ + protected abstract InternalCDOSession createSession(String repositoryName, boolean automaticPackageRegistry); +} diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/session/CDOTransactionContainerImpl.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/session/CDOTransactionContainerImpl.java index aff56e9a41..65a39a1800 100644 --- a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/session/CDOTransactionContainerImpl.java +++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/session/CDOTransactionContainerImpl.java @@ -1,134 +1,134 @@ -/*
- * Copyright (c) 2004 - 2012 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
- * Simon McDuff - bug 226778
- * Simon McDuff - bug 230832
- * Simon McDuff - bug 233490
- * Simon McDuff - bug 213402
- * Victor Roldan Betancort - maintenance
- */
-package org.eclipse.emf.internal.cdo.session;
-
-import org.eclipse.emf.cdo.common.branch.CDOBranch;
-import org.eclipse.emf.cdo.common.branch.CDOBranchPoint;
-import org.eclipse.emf.cdo.transaction.CDOTransaction;
-import org.eclipse.emf.cdo.transaction.CDOTransactionContainer;
-import org.eclipse.emf.cdo.view.CDOView;
-
-import org.eclipse.emf.internal.cdo.transaction.CDOTransactionImpl;
-
-import org.eclipse.emf.ecore.resource.ResourceSet;
-import org.eclipse.emf.spi.cdo.InternalCDOTransaction;
-import org.eclipse.emf.spi.cdo.InternalCDOView;
-
-import java.util.ArrayList;
-import java.util.List;
-
-/**
- * @author Eike Stepper
- */
-public abstract class CDOTransactionContainerImpl extends CDOViewContainerImpl implements CDOTransactionContainer
-{
- public CDOTransactionContainerImpl()
- {
- }
-
- public InternalCDOTransaction getTransaction(int viewID)
- {
- CDOView view = getView(viewID);
- if (view instanceof InternalCDOTransaction)
- {
- return (InternalCDOTransaction)view;
- }
-
- return null;
- }
-
- public InternalCDOTransaction[] getTransactions()
- {
- checkActive();
- List<InternalCDOTransaction> result = new ArrayList<InternalCDOTransaction>();
-
- for (InternalCDOView view : getViews())
- {
- if (view instanceof InternalCDOTransaction)
- {
- result.add((InternalCDOTransaction)view);
- }
- }
-
- return result.toArray(new InternalCDOTransaction[result.size()]);
- }
-
- public CDOTransaction openTransaction(CDOBranchPoint target, ResourceSet resourceSet)
- {
- checkArg(target.getTimeStamp() == CDOBranchPoint.UNSPECIFIED_DATE, "Target is not head of a branch: " + target);
- return null;
- }
-
- public CDOTransaction openTransaction(CDOBranchPoint target)
- {
- return openTransaction(target, createResourceSet());
- }
-
- public InternalCDOTransaction openTransaction(CDOBranch branch, ResourceSet resourceSet)
- {
- checkActive();
- InternalCDOTransaction transaction = createTransaction(branch);
- initView(transaction, resourceSet);
- return transaction;
- }
-
- public InternalCDOTransaction openTransaction(ResourceSet resourceSet)
- {
- return openTransaction(getMainBranch(), resourceSet);
- }
-
- public InternalCDOTransaction openTransaction(CDOBranch branch)
- {
- return openTransaction(branch, createResourceSet());
- }
-
- /**
- * @since 2.0
- */
- public InternalCDOTransaction openTransaction()
- {
- return openTransaction(getMainBranch());
- }
-
- public CDOTransaction openTransaction(String durableLockingID)
- {
- return openTransaction(durableLockingID, createResourceSet());
- }
-
- public CDOTransaction openTransaction(String durableLockingID, ResourceSet resourceSet)
- {
- checkActive();
- InternalCDOTransaction transaction = createTransaction(durableLockingID);
- initView(transaction, resourceSet);
- return transaction;
- }
-
- /**
- * @since 2.0
- */
- protected InternalCDOTransaction createTransaction(CDOBranch branch)
- {
- return new CDOTransactionImpl(branch);
- }
-
- /**
- * @since 4.0
- */
- protected InternalCDOTransaction createTransaction(String durableLockingID)
- {
- return new CDOTransactionImpl(durableLockingID);
- }
-}
+/* + * Copyright (c) 2004 - 2012 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 + * Simon McDuff - bug 226778 + * Simon McDuff - bug 230832 + * Simon McDuff - bug 233490 + * Simon McDuff - bug 213402 + * Victor Roldan Betancort - maintenance + */ +package org.eclipse.emf.internal.cdo.session; + +import org.eclipse.emf.cdo.common.branch.CDOBranch; +import org.eclipse.emf.cdo.common.branch.CDOBranchPoint; +import org.eclipse.emf.cdo.transaction.CDOTransaction; +import org.eclipse.emf.cdo.transaction.CDOTransactionContainer; +import org.eclipse.emf.cdo.view.CDOView; + +import org.eclipse.emf.internal.cdo.transaction.CDOTransactionImpl; + +import org.eclipse.emf.ecore.resource.ResourceSet; +import org.eclipse.emf.spi.cdo.InternalCDOTransaction; +import org.eclipse.emf.spi.cdo.InternalCDOView; + +import java.util.ArrayList; +import java.util.List; + +/** + * @author Eike Stepper + */ +public abstract class CDOTransactionContainerImpl extends CDOViewContainerImpl implements CDOTransactionContainer +{ + public CDOTransactionContainerImpl() + { + } + + public InternalCDOTransaction getTransaction(int viewID) + { + CDOView view = getView(viewID); + if (view instanceof InternalCDOTransaction) + { + return (InternalCDOTransaction)view; + } + + return null; + } + + public InternalCDOTransaction[] getTransactions() + { + checkActive(); + List<InternalCDOTransaction> result = new ArrayList<InternalCDOTransaction>(); + + for (InternalCDOView view : getViews()) + { + if (view instanceof InternalCDOTransaction) + { + result.add((InternalCDOTransaction)view); + } + } + + return result.toArray(new InternalCDOTransaction[result.size()]); + } + + public CDOTransaction openTransaction(CDOBranchPoint target, ResourceSet resourceSet) + { + checkArg(target.getTimeStamp() == CDOBranchPoint.UNSPECIFIED_DATE, "Target is not head of a branch: " + target); + return null; + } + + public CDOTransaction openTransaction(CDOBranchPoint target) + { + return openTransaction(target, createResourceSet()); + } + + public InternalCDOTransaction openTransaction(CDOBranch branch, ResourceSet resourceSet) + { + checkActive(); + InternalCDOTransaction transaction = createTransaction(branch); + initView(transaction, resourceSet); + return transaction; + } + + public InternalCDOTransaction openTransaction(ResourceSet resourceSet) + { + return openTransaction(getMainBranch(), resourceSet); + } + + public InternalCDOTransaction openTransaction(CDOBranch branch) + { + return openTransaction(branch, createResourceSet()); + } + + /** + * @since 2.0 + */ + public InternalCDOTransaction openTransaction() + { + return openTransaction(getMainBranch()); + } + + public CDOTransaction openTransaction(String durableLockingID) + { + return openTransaction(durableLockingID, createResourceSet()); + } + + public CDOTransaction openTransaction(String durableLockingID, ResourceSet resourceSet) + { + checkActive(); + InternalCDOTransaction transaction = createTransaction(durableLockingID); + initView(transaction, resourceSet); + return transaction; + } + + /** + * @since 2.0 + */ + protected InternalCDOTransaction createTransaction(CDOBranch branch) + { + return new CDOTransactionImpl(branch); + } + + /** + * @since 4.0 + */ + protected InternalCDOTransaction createTransaction(String durableLockingID) + { + return new CDOTransactionImpl(durableLockingID); + } +} diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/session/CDOViewContainerImpl.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/session/CDOViewContainerImpl.java index 182060ebd8..6d8cb6165d 100644 --- a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/session/CDOViewContainerImpl.java +++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/session/CDOViewContainerImpl.java @@ -1,257 +1,257 @@ -/*
- * Copyright (c) 2004 - 2012 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
- * Simon McDuff - bug 226778
- * Simon McDuff - bug 230832
- * Simon McDuff - bug 233490
- * Simon McDuff - bug 213402
- * Victor Roldan Betancort - maintenance
- */
-package org.eclipse.emf.internal.cdo.session;
-
-import org.eclipse.emf.cdo.common.branch.CDOBranch;
-import org.eclipse.emf.cdo.common.branch.CDOBranchPoint;
-import org.eclipse.emf.cdo.view.CDOView;
-import org.eclipse.emf.cdo.view.CDOViewContainer;
-
-import org.eclipse.emf.internal.cdo.view.CDOViewImpl;
-
-import org.eclipse.net4j.util.ReflectUtil.ExcludeFromDump;
-import org.eclipse.net4j.util.WrappedException;
-import org.eclipse.net4j.util.container.Container;
-import org.eclipse.net4j.util.lifecycle.LifecycleUtil;
-
-import org.eclipse.emf.ecore.resource.ResourceSet;
-import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
-import org.eclipse.emf.spi.cdo.InternalCDOView;
-import org.eclipse.emf.spi.cdo.InternalCDOViewSet;
-
-import java.util.HashSet;
-import java.util.Set;
-
-/**
- * @author Eike Stepper
- */
-public abstract class CDOViewContainerImpl extends Container<CDOView> implements CDOViewContainer
-{
- private Set<InternalCDOView> views = new HashSet<InternalCDOView>();
-
- @ExcludeFromDump
- private int lastViewID;
-
- public CDOViewContainerImpl()
- {
- }
-
- public CDOView getView(int viewID)
- {
- checkActive();
- for (InternalCDOView view : getViews())
- {
- if (view.getViewID() == viewID)
- {
- return view;
- }
- }
-
- return null;
- }
-
- /**
- * @since 2.0
- */
- public InternalCDOView[] getViews()
- {
- checkActive();
- synchronized (views)
- {
- return views.toArray(new InternalCDOView[views.size()]);
- }
- }
-
- public CDOView[] getElements()
- {
- return getViews();
- }
-
- @Override
- public boolean isEmpty()
- {
- checkActive();
- return views.isEmpty();
- }
-
- public CDOView openView(CDOBranchPoint target, ResourceSet resourceSet)
- {
- return openView(target.getBranch(), target.getTimeStamp(), resourceSet);
- }
-
- public CDOView openView(CDOBranchPoint target)
- {
- return openView(target, createResourceSet());
- }
-
- public InternalCDOView openView(CDOBranch branch, long timeStamp, ResourceSet resourceSet)
- {
- checkActive();
- InternalCDOView view = createView(branch, timeStamp);
- initView(view, resourceSet);
- return view;
- }
-
- public InternalCDOView openView(CDOBranch branch, long timeStamp)
- {
- return openView(branch, timeStamp, createResourceSet());
- }
-
- public InternalCDOView openView(CDOBranch branch)
- {
- return openView(branch, CDOBranchPoint.UNSPECIFIED_DATE);
- }
-
- public InternalCDOView openView(long timeStamp)
- {
- return openView(getMainBranch(), timeStamp);
- }
-
- public InternalCDOView openView(ResourceSet resourceSet)
- {
- return openView(getMainBranch(), CDOBranchPoint.UNSPECIFIED_DATE, resourceSet);
- }
-
- /**
- * @since 2.0
- */
- public InternalCDOView openView()
- {
- return openView(CDOBranchPoint.UNSPECIFIED_DATE);
- }
-
- public CDOView openView(String durableLockingID)
- {
- return openView(durableLockingID, createResourceSet());
- }
-
- public CDOView openView(String durableLockingID, ResourceSet resourceSet)
- {
- checkActive();
- InternalCDOView view = createView(durableLockingID);
- initView(view, resourceSet);
- return view;
- }
-
- /**
- * @since 2.0
- */
- public void viewDetached(InternalCDOView view)
- {
- // Detach viewset from the view
- view.getViewSet().remove(view);
- synchronized (views)
- {
- if (!views.remove(view))
- {
- return;
- }
- }
-
- if (isActive())
- {
- try
- {
- LifecycleUtil.deactivate(view);
- }
- catch (Exception ex)
- {
- throw WrappedException.wrap(ex);
- }
- }
-
- fireElementRemovedEvent(view);
- }
-
- /**
- * @since 2.0
- */
- protected InternalCDOView createView(CDOBranch branch, long timeStamp)
- {
- return new CDOViewImpl(branch, timeStamp);
- }
-
- /**
- * @since 4.0
- */
- protected InternalCDOView createView(String durableLockingID)
- {
- return new CDOViewImpl(durableLockingID);
- }
-
- protected ResourceSet createResourceSet()
- {
- return new ResourceSetImpl();
- }
-
- @Override
- protected void doDeactivate() throws Exception
- {
- for (InternalCDOView view : views.toArray(new InternalCDOView[views.size()]))
- {
- try
- {
- view.close();
- }
- catch (RuntimeException ignore)
- {
- }
- }
-
- views.clear();
- super.doDeactivate();
- }
-
- /**
- * @since 2.0
- */
- protected void initView(InternalCDOView view, ResourceSet resourceSet)
- {
- InternalCDOViewSet viewSet = SessionUtil.prepareResourceSet(resourceSet);
- synchronized (views)
- {
- view.setViewID(++lastViewID);
- initViewSynced(view);
- views.add(view);
- }
-
- // Link ViewSet with View
- view.setViewSet(viewSet);
- viewSet.add(view);
-
- try
- {
- view.activate();
- fireElementAddedEvent(view);
- }
- catch (RuntimeException ex)
- {
- synchronized (views)
- {
- views.remove(view);
- }
-
- viewSet.remove(view);
- throw ex;
- }
- }
-
- protected void initViewSynced(InternalCDOView view)
- {
- }
-
- protected abstract CDOBranch getMainBranch();
-}
+/* + * Copyright (c) 2004 - 2012 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 + * Simon McDuff - bug 226778 + * Simon McDuff - bug 230832 + * Simon McDuff - bug 233490 + * Simon McDuff - bug 213402 + * Victor Roldan Betancort - maintenance + */ +package org.eclipse.emf.internal.cdo.session; + +import org.eclipse.emf.cdo.common.branch.CDOBranch; +import org.eclipse.emf.cdo.common.branch.CDOBranchPoint; +import org.eclipse.emf.cdo.view.CDOView; +import org.eclipse.emf.cdo.view.CDOViewContainer; + +import org.eclipse.emf.internal.cdo.view.CDOViewImpl; + +import org.eclipse.net4j.util.ReflectUtil.ExcludeFromDump; +import org.eclipse.net4j.util.WrappedException; +import org.eclipse.net4j.util.container.Container; +import org.eclipse.net4j.util.lifecycle.LifecycleUtil; + +import org.eclipse.emf.ecore.resource.ResourceSet; +import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl; +import org.eclipse.emf.spi.cdo.InternalCDOView; +import org.eclipse.emf.spi.cdo.InternalCDOViewSet; + +import java.util.HashSet; +import java.util.Set; + +/** + * @author Eike Stepper + */ +public abstract class CDOViewContainerImpl extends Container<CDOView> implements CDOViewContainer +{ + private Set<InternalCDOView> views = new HashSet<InternalCDOView>(); + + @ExcludeFromDump + private int lastViewID; + + public CDOViewContainerImpl() + { + } + + public CDOView getView(int viewID) + { + checkActive(); + for (InternalCDOView view : getViews()) + { + if (view.getViewID() == viewID) + { + return view; + } + } + + return null; + } + + /** + * @since 2.0 + */ + public InternalCDOView[] getViews() + { + checkActive(); + synchronized (views) + { + return views.toArray(new InternalCDOView[views.size()]); + } + } + + public CDOView[] getElements() + { + return getViews(); + } + + @Override + public boolean isEmpty() + { + checkActive(); + return views.isEmpty(); + } + + public CDOView openView(CDOBranchPoint target, ResourceSet resourceSet) + { + return openView(target.getBranch(), target.getTimeStamp(), resourceSet); + } + + public CDOView openView(CDOBranchPoint target) + { + return openView(target, createResourceSet()); + } + + public InternalCDOView openView(CDOBranch branch, long timeStamp, ResourceSet resourceSet) + { + checkActive(); + InternalCDOView view = createView(branch, timeStamp); + initView(view, resourceSet); + return view; + } + + public InternalCDOView openView(CDOBranch branch, long timeStamp) + { + return openView(branch, timeStamp, createResourceSet()); + } + + public InternalCDOView openView(CDOBranch branch) + { + return openView(branch, CDOBranchPoint.UNSPECIFIED_DATE); + } + + public InternalCDOView openView(long timeStamp) + { + return openView(getMainBranch(), timeStamp); + } + + public InternalCDOView openView(ResourceSet resourceSet) + { + return openView(getMainBranch(), CDOBranchPoint.UNSPECIFIED_DATE, resourceSet); + } + + /** + * @since 2.0 + */ + public InternalCDOView openView() + { + return openView(CDOBranchPoint.UNSPECIFIED_DATE); + } + + public CDOView openView(String durableLockingID) + { + return openView(durableLockingID, createResourceSet()); + } + + public CDOView openView(String durableLockingID, ResourceSet resourceSet) + { + checkActive(); + InternalCDOView view = createView(durableLockingID); + initView(view, resourceSet); + return view; + } + + /** + * @since 2.0 + */ + public void viewDetached(InternalCDOView view) + { + // Detach viewset from the view + view.getViewSet().remove(view); + synchronized (views) + { + if (!views.remove(view)) + { + return; + } + } + + if (isActive()) + { + try + { + LifecycleUtil.deactivate(view); + } + catch (Exception ex) + { + throw WrappedException.wrap(ex); + } + } + + fireElementRemovedEvent(view); + } + + /** + * @since 2.0 + */ + protected InternalCDOView createView(CDOBranch branch, long timeStamp) + { + return new CDOViewImpl(branch, timeStamp); + } + + /** + * @since 4.0 + */ + protected InternalCDOView createView(String durableLockingID) + { + return new CDOViewImpl(durableLockingID); + } + + protected ResourceSet createResourceSet() + { + return new ResourceSetImpl(); + } + + @Override + protected void doDeactivate() throws Exception + { + for (InternalCDOView view : views.toArray(new InternalCDOView[views.size()])) + { + try + { + view.close(); + } + catch (RuntimeException ignore) + { + } + } + + views.clear(); + super.doDeactivate(); + } + + /** + * @since 2.0 + */ + protected void initView(InternalCDOView view, ResourceSet resourceSet) + { + InternalCDOViewSet viewSet = SessionUtil.prepareResourceSet(resourceSet); + synchronized (views) + { + view.setViewID(++lastViewID); + initViewSynced(view); + views.add(view); + } + + // Link ViewSet with View + view.setViewSet(viewSet); + viewSet.add(view); + + try + { + view.activate(); + fireElementAddedEvent(view); + } + catch (RuntimeException ex) + { + synchronized (views) + { + views.remove(view); + } + + viewSet.remove(view); + throw ex; + } + } + + protected void initViewSynced(InternalCDOView view) + { + } + + protected abstract CDOBranch getMainBranch(); +} diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/session/DelegatingSessionProtocol.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/session/DelegatingSessionProtocol.java index cd0dcc09d2..603499b8c3 100644 --- a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/session/DelegatingSessionProtocol.java +++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/session/DelegatingSessionProtocol.java @@ -1,955 +1,955 @@ -/*
- * Copyright (c) 2004 - 2012 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.internal.cdo.session;
-
-import org.eclipse.emf.cdo.CDOObject;
-import org.eclipse.emf.cdo.common.CDOCommonSession.Options.LockNotificationMode;
-import org.eclipse.emf.cdo.common.CDOCommonSession.Options.PassiveUpdateMode;
-import org.eclipse.emf.cdo.common.branch.CDOBranch;
-import org.eclipse.emf.cdo.common.branch.CDOBranchHandler;
-import org.eclipse.emf.cdo.common.branch.CDOBranchPoint;
-import org.eclipse.emf.cdo.common.branch.CDOBranchPointRange;
-import org.eclipse.emf.cdo.common.branch.CDOBranchVersion;
-import org.eclipse.emf.cdo.common.commit.CDOChangeSetData;
-import org.eclipse.emf.cdo.common.commit.CDOCommitData;
-import org.eclipse.emf.cdo.common.commit.CDOCommitInfoHandler;
-import org.eclipse.emf.cdo.common.id.CDOID;
-import org.eclipse.emf.cdo.common.id.CDOIDProvider;
-import org.eclipse.emf.cdo.common.lob.CDOLob;
-import org.eclipse.emf.cdo.common.lob.CDOLobInfo;
-import org.eclipse.emf.cdo.common.lock.CDOLockState;
-import org.eclipse.emf.cdo.common.model.CDOPackageUnit;
-import org.eclipse.emf.cdo.common.revision.CDOIDAndVersion;
-import org.eclipse.emf.cdo.common.revision.CDORevisionHandler;
-import org.eclipse.emf.cdo.common.revision.CDORevisionKey;
-import org.eclipse.emf.cdo.session.CDOSession;
-import org.eclipse.emf.cdo.session.CDOSession.ExceptionHandler;
-import org.eclipse.emf.cdo.session.remote.CDORemoteSession;
-import org.eclipse.emf.cdo.session.remote.CDORemoteSessionMessage;
-import org.eclipse.emf.cdo.spi.common.CDORawReplicationContext;
-import org.eclipse.emf.cdo.spi.common.CDOReplicationContext;
-import org.eclipse.emf.cdo.spi.common.commit.CDORevisionAvailabilityInfo;
-import org.eclipse.emf.cdo.spi.common.revision.InternalCDORevision;
-import org.eclipse.emf.cdo.spi.common.revision.RevisionInfo;
-import org.eclipse.emf.cdo.view.CDOView;
-
-import org.eclipse.net4j.util.ReflectUtil.ExcludeFromDump;
-import org.eclipse.net4j.util.WrappedException;
-import org.eclipse.net4j.util.collection.Pair;
-import org.eclipse.net4j.util.concurrent.IRWLockManager.LockType;
-import org.eclipse.net4j.util.event.EventUtil;
-import org.eclipse.net4j.util.event.IListener;
-import org.eclipse.net4j.util.lifecycle.ILifecycle;
-import org.eclipse.net4j.util.lifecycle.Lifecycle;
-import org.eclipse.net4j.util.lifecycle.LifecycleEventAdapter;
-import org.eclipse.net4j.util.lifecycle.LifecycleUtil;
-import org.eclipse.net4j.util.om.monitor.OMMonitor;
-
-import org.eclipse.emf.ecore.EClass;
-import org.eclipse.emf.ecore.EPackage;
-import org.eclipse.emf.ecore.EStructuralFeature;
-import org.eclipse.emf.spi.cdo.AbstractQueryIterator;
-import org.eclipse.emf.spi.cdo.CDOSessionProtocol;
-import org.eclipse.emf.spi.cdo.InternalCDOObject;
-import org.eclipse.emf.spi.cdo.InternalCDORemoteSessionManager;
-import org.eclipse.emf.spi.cdo.InternalCDOTransaction.InternalCDOCommitContext;
-import org.eclipse.emf.spi.cdo.InternalCDOXATransaction.InternalCDOXACommitContext;
-
-import java.util.Collection;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
-/**
- * @author Eike Stepper
- */
-public class DelegatingSessionProtocol extends Lifecycle implements CDOSessionProtocol
-{
- private CDOSessionProtocol delegate;
-
- private ExceptionHandler exceptionHandler;
-
- @ExcludeFromDump
- private IListener delegateListener = new LifecycleEventAdapter()
- {
- @Override
- protected void onDeactivated(ILifecycle lifecycle)
- {
- DelegatingSessionProtocol.this.deactivate();
- }
- };
-
- public DelegatingSessionProtocol(CDOSessionProtocol delegate, ExceptionHandler handler)
- {
- this.delegate = delegate;
- exceptionHandler = handler;
- activate();
- }
-
- public CDOSessionProtocol getDelegate()
- {
- return delegate;
- }
-
- public void setDelegate(CDOSessionProtocol delegate)
- {
- if (delegate != null)
- {
- unhookDelegate();
- if (LifecycleUtil.isActive(this.delegate))
- {
- LifecycleUtil.deactivate(this.delegate);
- }
- }
-
- this.delegate = delegate;
- hookDelegate();
- }
-
- public CDOSession getSession()
- {
- return (CDOSession)delegate.getSession();
- }
-
- public boolean cancelQuery(int queryId)
- {
- int attempt = 0;
- for (;;)
- {
- try
- {
- return delegate.cancelQuery(queryId);
- }
- catch (Exception ex)
- {
- handleException(++attempt, ex);
- }
- }
- }
-
- public void changeSubscription(int viewID, List<CDOID> ids, boolean subscribeMode, boolean clear)
- {
- int attempt = 0;
- for (;;)
- {
- try
- {
- delegate.changeSubscription(viewID, ids, subscribeMode, clear);
- return;
- }
- catch (Exception ex)
- {
- handleException(++attempt, ex);
- }
- }
- }
-
- public void openView(int viewID, boolean readOnly, CDOBranchPoint branchPoint)
- {
- int attempt = 0;
- for (;;)
- {
- try
- {
- delegate.openView(viewID, readOnly, branchPoint);
- return;
- }
- catch (Exception ex)
- {
- handleException(++attempt, ex);
- }
- }
- }
-
- public CDOBranchPoint openView(int viewID, boolean readOnly, String durableLockingID)
- {
- int attempt = 0;
- for (;;)
- {
- try
- {
- return delegate.openView(viewID, readOnly, durableLockingID);
- }
- catch (Exception ex)
- {
- handleException(++attempt, ex);
- }
- }
- }
-
- public void switchTarget(int viewID, CDOBranchPoint branchPoint, List<InternalCDOObject> invalidObjects,
- List<CDORevisionKey> allChangedObjects, List<CDOIDAndVersion> allDetachedObjects, OMMonitor monitor)
- {
- int attempt = 0;
- for (;;)
- {
- try
- {
- delegate.switchTarget(viewID, branchPoint, invalidObjects, allChangedObjects, allDetachedObjects, monitor);
- return;
- }
- catch (Exception ex)
- {
- handleException(++attempt, ex);
- }
- }
- }
-
- public void closeView(int viewID)
- {
- int attempt = 0;
- for (;;)
- {
- try
- {
- if (delegate != null)
- {
- delegate.closeView(viewID);
- }
-
- return;
- }
- catch (Exception ex)
- {
- handleException(++attempt, ex);
- }
- }
- }
-
- public List<byte[]> queryLobs(Set<byte[]> ids)
- {
- int attempt = 0;
- for (;;)
- {
- try
- {
- return delegate.queryLobs(ids);
- }
- catch (Exception ex)
- {
- handleException(++attempt, ex);
- }
- }
- }
-
- public void loadLob(CDOLobInfo info, Object outputStreamOrWriter)
- {
- int attempt = 0;
- for (;;)
- {
- try
- {
- delegate.loadLob(info, outputStreamOrWriter);
- return;
- }
- catch (Exception ex)
- {
- handleException(++attempt, ex);
- }
- }
- }
-
- public void handleRevisions(EClass eClass, CDOBranch branch, boolean exactBranch, long timeStamp, boolean exactTime,
- CDORevisionHandler handler)
- {
- int attempt = 0;
- for (;;)
- {
- try
- {
- delegate.handleRevisions(eClass, branch, exactBranch, timeStamp, exactTime, handler);
- return;
- }
- catch (Exception ex)
- {
- handleException(++attempt, ex);
- }
- }
- }
-
- @Deprecated
- public CommitTransactionResult commitTransaction(int transactionID, String comment, boolean releaseLocks,
- CDOIDProvider idProvider, CDOCommitData commitData, Collection<CDOLob<?>> lobs, OMMonitor monitor)
- {
- throw new UnsupportedOperationException();
- }
-
- public CommitTransactionResult commitTransaction(InternalCDOCommitContext context, OMMonitor monitor)
- {
- int attempt = 0;
- for (;;)
- {
- try
- {
- return delegate.commitTransaction(context, monitor);
- }
- catch (Exception ex)
- {
- handleException(++attempt, ex);
- }
- }
- }
-
- @Deprecated
- public CommitTransactionResult commitDelegation(CDOBranch branch, String userID, String comment,
- CDOCommitData commitData, Map<CDOID, EClass> detachedObjectTypes, Collection<CDOLob<?>> lobs, OMMonitor monitor)
- {
- throw new UnsupportedOperationException();
- }
-
- public CommitTransactionResult commitDelegation(InternalCDOCommitContext context, OMMonitor monitor)
- {
- int attempt = 0;
- for (;;)
- {
- try
- {
- return delegate.commitDelegation(context, monitor);
- }
- catch (Exception ex)
- {
- handleException(++attempt, ex);
- }
- }
- }
-
- public CommitTransactionResult commitXATransactionCancel(InternalCDOXACommitContext xaContext, OMMonitor monitor)
- {
- int attempt = 0;
- for (;;)
- {
- try
- {
- return delegate.commitXATransactionCancel(xaContext, monitor);
- }
- catch (Exception ex)
- {
- handleException(++attempt, ex);
- }
- }
- }
-
- public CommitTransactionResult commitXATransactionPhase1(InternalCDOXACommitContext xaContext, OMMonitor monitor)
- {
- int attempt = 0;
- for (;;)
- {
- try
- {
- return delegate.commitXATransactionPhase1(xaContext, monitor);
- }
- catch (Exception ex)
- {
- handleException(++attempt, ex);
- }
- }
- }
-
- public CommitTransactionResult commitXATransactionPhase2(InternalCDOXACommitContext xaContext, OMMonitor monitor)
- {
- int attempt = 0;
- for (;;)
- {
- try
- {
- return delegate.commitXATransactionPhase2(xaContext, monitor);
- }
- catch (Exception ex)
- {
- handleException(++attempt, ex);
- }
- }
- }
-
- public CommitTransactionResult commitXATransactionPhase3(InternalCDOXACommitContext xaContext, OMMonitor monitor)
- {
- int attempt = 0;
- for (;;)
- {
- try
- {
- return delegate.commitXATransactionPhase3(xaContext, monitor);
- }
- catch (Exception ex)
- {
- handleException(++attempt, ex);
- }
- }
- }
-
- public RepositoryTimeResult getRepositoryTime()
- {
- int attempt = 0;
- for (;;)
- {
- try
- {
- return delegate.getRepositoryTime();
- }
- catch (Exception ex)
- {
- handleException(++attempt, ex);
- }
- }
- }
-
- public CDOLockState[] getLockStates(int viewID, Collection<CDOID> ids)
- {
- int attempt = 0;
- for (;;)
- {
- try
- {
- return delegate.getLockStates(viewID, ids);
- }
- catch (Exception ex)
- {
- handleException(++attempt, ex);
- }
- }
- }
-
- public void enableLockNotifications(int viewID, boolean enable)
- {
- int attempt = 0;
- for (;;)
- {
- try
- {
- delegate.enableLockNotifications(viewID, enable);
- return;
- }
- catch (Exception ex)
- {
- handleException(++attempt, ex);
- }
- }
- }
-
- public boolean isObjectLocked(CDOView view, CDOObject object, LockType lockType, boolean byOthers)
- {
- int attempt = 0;
- for (;;)
- {
- try
- {
- return delegate.isObjectLocked(view, object, lockType, byOthers);
- }
- catch (Exception ex)
- {
- handleException(++attempt, ex);
- }
- }
- }
-
- public String changeLockArea(CDOView view, boolean create)
- {
- int attempt = 0;
- for (;;)
- {
- try
- {
- return delegate.changeLockArea(view, create);
- }
- catch (Exception ex)
- {
- handleException(++attempt, ex);
- }
- }
- }
-
- public EPackage[] loadPackages(CDOPackageUnit packageUnit)
- {
- int attempt = 0;
- for (;;)
- {
- try
- {
- return delegate.loadPackages(packageUnit);
- }
- catch (Exception ex)
- {
- handleException(++attempt, ex);
- }
- }
- }
-
- public Pair<Integer, Long> createBranch(int branchID, BranchInfo branchInfo)
- {
- int attempt = 0;
- for (;;)
- {
- try
- {
- return delegate.createBranch(branchID, branchInfo);
- }
- catch (Exception ex)
- {
- handleException(++attempt, ex);
- }
- }
- }
-
- public BranchInfo loadBranch(int branchID)
- {
- int attempt = 0;
- for (;;)
- {
- try
- {
- return delegate.loadBranch(branchID);
- }
- catch (Exception ex)
- {
- handleException(++attempt, ex);
- }
- }
- }
-
- public SubBranchInfo[] loadSubBranches(int branchID)
- {
- int attempt = 0;
- for (;;)
- {
- try
- {
- return delegate.loadSubBranches(branchID);
- }
- catch (Exception ex)
- {
- handleException(++attempt, ex);
- }
- }
- }
-
- public int loadBranches(int startID, int endID, CDOBranchHandler branchHandler)
- {
- int attempt = 0;
- for (;;)
- {
- try
- {
- return delegate.loadBranches(startID, endID, branchHandler);
- }
- catch (Exception ex)
- {
- handleException(++attempt, ex);
- }
- }
- }
-
- public void loadCommitInfos(CDOBranch branch, long startTime, long endTime, CDOCommitInfoHandler handler)
- {
- int attempt = 0;
- for (;;)
- {
- try
- {
- delegate.loadCommitInfos(branch, startTime, endTime, handler);
- return;
- }
- catch (Exception ex)
- {
- handleException(++attempt, ex);
- }
- }
- }
-
- public CDOCommitData loadCommitData(long timeStamp)
- {
- int attempt = 0;
- for (;;)
- {
- try
- {
- return delegate.loadCommitData(timeStamp);
- }
- catch (Exception ex)
- {
- handleException(++attempt, ex);
- }
- }
- }
-
- public Object loadChunk(InternalCDORevision revision, EStructuralFeature feature, int accessIndex, int fetchIndex,
- int fromIndex, int toIndex)
- {
- int attempt = 0;
- for (;;)
- {
- try
- {
- return delegate.loadChunk(revision, feature, accessIndex, fetchIndex, fromIndex, toIndex);
- }
- catch (Exception ex)
- {
- handleException(++attempt, ex);
- }
- }
- }
-
- public List<InternalCDORevision> loadRevisions(List<RevisionInfo> infos, CDOBranchPoint branchPoint,
- int referenceChunk, int prefetchDepth)
- {
- int attempt = 0;
- for (;;)
- {
- try
- {
- return delegate.loadRevisions(infos, branchPoint, referenceChunk, prefetchDepth);
- }
- catch (Exception ex)
- {
- handleException(++attempt, ex);
- }
- }
- }
-
- public InternalCDORevision loadRevisionByVersion(CDOID id, CDOBranchVersion branchVersion, int referenceChunk)
- {
- int attempt = 0;
- for (;;)
- {
- try
- {
- return delegate.loadRevisionByVersion(id, branchVersion, referenceChunk);
- }
- catch (Exception ex)
- {
- handleException(++attempt, ex);
- }
- }
- }
-
- @Deprecated
- public LockObjectsResult lockObjects(List<InternalCDORevision> viewedRevisions, int viewID, CDOBranch viewedBranch,
- LockType lockType, long timeout) throws InterruptedException
- {
- throw new UnsupportedOperationException();
- }
-
- /**
- * @since 4.1
- */
- public LockObjectsResult lockObjects2(List<CDORevisionKey> revisionKeys, int viewID, CDOBranch viewedBranch,
- LockType lockType, boolean recursive, long timeout) throws InterruptedException
-
- {
- int attempt = 0;
- for (;;)
- {
- try
- {
- return delegate.lockObjects2(revisionKeys, viewID, viewedBranch, lockType, recursive, timeout);
- }
- catch (Exception ex)
- {
- handleException(++attempt, ex);
- }
- }
- }
-
- public LockObjectsResult delegateLockObjects(String lockAreaID, List<CDORevisionKey> revisionKeys,
- CDOBranch viewedBranch, LockType lockType, boolean recursive, long timeout) throws InterruptedException
- {
- int attempt = 0;
- for (;;)
- {
- try
- {
- return delegate.delegateLockObjects(lockAreaID, revisionKeys, viewedBranch, lockType, recursive, timeout);
- }
- catch (Exception ex)
- {
- handleException(++attempt, ex);
- }
- }
- }
-
- public UnlockObjectsResult delegateUnlockObjects(String lockAreaID, Collection<CDOID> objectIDs, LockType lockType,
- boolean recursive)
- {
- int attempt = 0;
- for (;;)
- {
- try
- {
- return delegate.delegateUnlockObjects(lockAreaID, objectIDs, lockType, recursive);
- }
- catch (Exception ex)
- {
- handleException(++attempt, ex);
- }
- }
- }
-
- public void query(CDOView view, AbstractQueryIterator<?> queryResult)
- {
- int attempt = 0;
- for (;;)
- {
- try
- {
- delegate.query(view, queryResult);
- return;
- }
- catch (Exception ex)
- {
- handleException(++attempt, ex);
- }
- }
- }
-
- public void disablePassiveUpdate()
- {
- int attempt = 0;
- for (;;)
- {
- try
- {
- delegate.disablePassiveUpdate();
- return;
- }
- catch (Exception ex)
- {
- handleException(++attempt, ex);
- }
- }
- }
-
- public void setPassiveUpdateMode(PassiveUpdateMode mode)
- {
- int attempt = 0;
- for (;;)
- {
- try
- {
- delegate.setPassiveUpdateMode(mode);
- return;
- }
- catch (Exception ex)
- {
- handleException(++attempt, ex);
- }
- }
- }
-
- public void setLockNotificationMode(LockNotificationMode mode)
- {
- int attempt = 0;
- for (;;)
- {
- try
- {
- delegate.setLockNotificationMode(mode);
- return;
- }
- catch (Exception ex)
- {
- handleException(++attempt, ex);
- }
- }
- }
-
- public RefreshSessionResult refresh(long lastUpdateTime,
- Map<CDOBranch, Map<CDOID, InternalCDORevision>> viewedRevisions, int initialChunkSize,
- boolean enablePassiveUpdates)
- {
- int attempt = 0;
- for (;;)
- {
- try
- {
- return delegate.refresh(lastUpdateTime, viewedRevisions, initialChunkSize, enablePassiveUpdates);
- }
- catch (Exception ex)
- {
- handleException(++attempt, ex);
- }
- }
- }
-
- @Deprecated
- public void unlockObjects(CDOView view, Collection<CDOID> objectIDs, LockType lockType)
- {
- throw new UnsupportedOperationException();
- }
-
- public UnlockObjectsResult unlockObjects2(CDOView view, Collection<CDOID> objectIDs, LockType lockType,
- boolean recursive)
- {
- int attempt = 0;
- for (;;)
- {
- try
- {
- return delegate.unlockObjects2(view, objectIDs, lockType, recursive);
- }
- catch (Exception ex)
- {
- handleException(++attempt, ex);
- }
- }
- }
-
- public List<CDORemoteSession> getRemoteSessions(InternalCDORemoteSessionManager manager, boolean subscribe)
- {
- int attempt = 0;
- for (;;)
- {
- try
- {
- return delegate.getRemoteSessions(manager, subscribe);
- }
- catch (Exception ex)
- {
- handleException(++attempt, ex);
- }
- }
- }
-
- public Set<Integer> sendRemoteMessage(CDORemoteSessionMessage message, List<CDORemoteSession> recipients)
- {
- int attempt = 0;
- for (;;)
- {
- try
- {
- return delegate.sendRemoteMessage(message, recipients);
- }
- catch (Exception ex)
- {
- handleException(++attempt, ex);
- }
- }
- }
-
- public boolean unsubscribeRemoteSessions()
- {
- int attempt = 0;
- for (;;)
- {
- try
- {
- return delegate.unsubscribeRemoteSessions();
- }
- catch (Exception ex)
- {
- handleException(++attempt, ex);
- }
- }
- }
-
- public void replicateRepository(CDOReplicationContext context, OMMonitor monitor)
- {
- int attempt = 0;
- for (;;)
- {
- try
- {
- delegate.replicateRepository(context, monitor);
- return;
- }
- catch (Exception ex)
- {
- handleException(++attempt, ex);
- }
- }
- }
-
- public void replicateRepositoryRaw(CDORawReplicationContext context, OMMonitor monitor)
- {
- int attempt = 0;
- for (;;)
- {
- try
- {
- delegate.replicateRepositoryRaw(context, monitor);
- return;
- }
- catch (Exception ex)
- {
- handleException(++attempt, ex);
- }
- }
- }
-
- public CDOChangeSetData[] loadChangeSets(CDOBranchPointRange... ranges)
- {
- int attempt = 0;
- for (;;)
- {
- try
- {
- return delegate.loadChangeSets(ranges);
- }
- catch (Exception ex)
- {
- handleException(++attempt, ex);
- }
- }
- }
-
- public Set<CDOID> loadMergeData(CDORevisionAvailabilityInfo targetInfo, CDORevisionAvailabilityInfo sourceInfo,
- CDORevisionAvailabilityInfo targetBaseInfo, CDORevisionAvailabilityInfo sourceBaseInfo)
- {
- int attempt = 0;
- for (;;)
- {
- try
- {
- return delegate.loadMergeData(targetInfo, sourceInfo, targetBaseInfo, sourceBaseInfo);
- }
- catch (Exception ex)
- {
- handleException(++attempt, ex);
- }
- }
- }
-
- @Override
- protected void doActivate() throws Exception
- {
- super.doActivate();
- hookDelegate();
- }
-
- private void hookDelegate()
- {
- EventUtil.addListener(delegate, delegateListener);
- }
-
- @Override
- protected void doDeactivate() throws Exception
- {
- unhookDelegate();
- LifecycleUtil.deactivate(delegate);
- delegate = null;
- super.doDeactivate();
- }
-
- private void unhookDelegate()
- {
- EventUtil.removeListener(delegate, delegateListener);
- }
-
- private void handleException(int attempt, Exception exception)
- {
- try
- {
- exceptionHandler.handleException(getSession(), attempt, exception);
- }
- catch (Exception ex)
- {
- throw WrappedException.wrap(ex);
- }
- }
-}
+/* + * Copyright (c) 2004 - 2012 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.internal.cdo.session; + +import org.eclipse.emf.cdo.CDOObject; +import org.eclipse.emf.cdo.common.CDOCommonSession.Options.LockNotificationMode; +import org.eclipse.emf.cdo.common.CDOCommonSession.Options.PassiveUpdateMode; +import org.eclipse.emf.cdo.common.branch.CDOBranch; +import org.eclipse.emf.cdo.common.branch.CDOBranchHandler; +import org.eclipse.emf.cdo.common.branch.CDOBranchPoint; +import org.eclipse.emf.cdo.common.branch.CDOBranchPointRange; +import org.eclipse.emf.cdo.common.branch.CDOBranchVersion; +import org.eclipse.emf.cdo.common.commit.CDOChangeSetData; +import org.eclipse.emf.cdo.common.commit.CDOCommitData; +import org.eclipse.emf.cdo.common.commit.CDOCommitInfoHandler; +import org.eclipse.emf.cdo.common.id.CDOID; +import org.eclipse.emf.cdo.common.id.CDOIDProvider; +import org.eclipse.emf.cdo.common.lob.CDOLob; +import org.eclipse.emf.cdo.common.lob.CDOLobInfo; +import org.eclipse.emf.cdo.common.lock.CDOLockState; +import org.eclipse.emf.cdo.common.model.CDOPackageUnit; +import org.eclipse.emf.cdo.common.revision.CDOIDAndVersion; +import org.eclipse.emf.cdo.common.revision.CDORevisionHandler; +import org.eclipse.emf.cdo.common.revision.CDORevisionKey; +import org.eclipse.emf.cdo.session.CDOSession; +import org.eclipse.emf.cdo.session.CDOSession.ExceptionHandler; +import org.eclipse.emf.cdo.session.remote.CDORemoteSession; +import org.eclipse.emf.cdo.session.remote.CDORemoteSessionMessage; +import org.eclipse.emf.cdo.spi.common.CDORawReplicationContext; +import org.eclipse.emf.cdo.spi.common.CDOReplicationContext; +import org.eclipse.emf.cdo.spi.common.commit.CDORevisionAvailabilityInfo; +import org.eclipse.emf.cdo.spi.common.revision.InternalCDORevision; +import org.eclipse.emf.cdo.spi.common.revision.RevisionInfo; +import org.eclipse.emf.cdo.view.CDOView; + +import org.eclipse.net4j.util.ReflectUtil.ExcludeFromDump; +import org.eclipse.net4j.util.WrappedException; +import org.eclipse.net4j.util.collection.Pair; +import org.eclipse.net4j.util.concurrent.IRWLockManager.LockType; +import org.eclipse.net4j.util.event.EventUtil; +import org.eclipse.net4j.util.event.IListener; +import org.eclipse.net4j.util.lifecycle.ILifecycle; +import org.eclipse.net4j.util.lifecycle.Lifecycle; +import org.eclipse.net4j.util.lifecycle.LifecycleEventAdapter; +import org.eclipse.net4j.util.lifecycle.LifecycleUtil; +import org.eclipse.net4j.util.om.monitor.OMMonitor; + +import org.eclipse.emf.ecore.EClass; +import org.eclipse.emf.ecore.EPackage; +import org.eclipse.emf.ecore.EStructuralFeature; +import org.eclipse.emf.spi.cdo.AbstractQueryIterator; +import org.eclipse.emf.spi.cdo.CDOSessionProtocol; +import org.eclipse.emf.spi.cdo.InternalCDOObject; +import org.eclipse.emf.spi.cdo.InternalCDORemoteSessionManager; +import org.eclipse.emf.spi.cdo.InternalCDOTransaction.InternalCDOCommitContext; +import org.eclipse.emf.spi.cdo.InternalCDOXATransaction.InternalCDOXACommitContext; + +import java.util.Collection; +import java.util.List; +import java.util.Map; +import java.util.Set; + +/** + * @author Eike Stepper + */ +public class DelegatingSessionProtocol extends Lifecycle implements CDOSessionProtocol +{ + private CDOSessionProtocol delegate; + + private ExceptionHandler exceptionHandler; + + @ExcludeFromDump + private IListener delegateListener = new LifecycleEventAdapter() + { + @Override + protected void onDeactivated(ILifecycle lifecycle) + { + DelegatingSessionProtocol.this.deactivate(); + } + }; + + public DelegatingSessionProtocol(CDOSessionProtocol delegate, ExceptionHandler handler) + { + this.delegate = delegate; + exceptionHandler = handler; + activate(); + } + + public CDOSessionProtocol getDelegate() + { + return delegate; + } + + public void setDelegate(CDOSessionProtocol delegate) + { + if (delegate != null) + { + unhookDelegate(); + if (LifecycleUtil.isActive(this.delegate)) + { + LifecycleUtil.deactivate(this.delegate); + } + } + + this.delegate = delegate; + hookDelegate(); + } + + public CDOSession getSession() + { + return (CDOSession)delegate.getSession(); + } + + public boolean cancelQuery(int queryId) + { + int attempt = 0; + for (;;) + { + try + { + return delegate.cancelQuery(queryId); + } + catch (Exception ex) + { + handleException(++attempt, ex); + } + } + } + + public void changeSubscription(int viewID, List<CDOID> ids, boolean subscribeMode, boolean clear) + { + int attempt = 0; + for (;;) + { + try + { + delegate.changeSubscription(viewID, ids, subscribeMode, clear); + return; + } + catch (Exception ex) + { + handleException(++attempt, ex); + } + } + } + + public void openView(int viewID, boolean readOnly, CDOBranchPoint branchPoint) + { + int attempt = 0; + for (;;) + { + try + { + delegate.openView(viewID, readOnly, branchPoint); + return; + } + catch (Exception ex) + { + handleException(++attempt, ex); + } + } + } + + public CDOBranchPoint openView(int viewID, boolean readOnly, String durableLockingID) + { + int attempt = 0; + for (;;) + { + try + { + return delegate.openView(viewID, readOnly, durableLockingID); + } + catch (Exception ex) + { + handleException(++attempt, ex); + } + } + } + + public void switchTarget(int viewID, CDOBranchPoint branchPoint, List<InternalCDOObject> invalidObjects, + List<CDORevisionKey> allChangedObjects, List<CDOIDAndVersion> allDetachedObjects, OMMonitor monitor) + { + int attempt = 0; + for (;;) + { + try + { + delegate.switchTarget(viewID, branchPoint, invalidObjects, allChangedObjects, allDetachedObjects, monitor); + return; + } + catch (Exception ex) + { + handleException(++attempt, ex); + } + } + } + + public void closeView(int viewID) + { + int attempt = 0; + for (;;) + { + try + { + if (delegate != null) + { + delegate.closeView(viewID); + } + + return; + } + catch (Exception ex) + { + handleException(++attempt, ex); + } + } + } + + public List<byte[]> queryLobs(Set<byte[]> ids) + { + int attempt = 0; + for (;;) + { + try + { + return delegate.queryLobs(ids); + } + catch (Exception ex) + { + handleException(++attempt, ex); + } + } + } + + public void loadLob(CDOLobInfo info, Object outputStreamOrWriter) + { + int attempt = 0; + for (;;) + { + try + { + delegate.loadLob(info, outputStreamOrWriter); + return; + } + catch (Exception ex) + { + handleException(++attempt, ex); + } + } + } + + public void handleRevisions(EClass eClass, CDOBranch branch, boolean exactBranch, long timeStamp, boolean exactTime, + CDORevisionHandler handler) + { + int attempt = 0; + for (;;) + { + try + { + delegate.handleRevisions(eClass, branch, exactBranch, timeStamp, exactTime, handler); + return; + } + catch (Exception ex) + { + handleException(++attempt, ex); + } + } + } + + @Deprecated + public CommitTransactionResult commitTransaction(int transactionID, String comment, boolean releaseLocks, + CDOIDProvider idProvider, CDOCommitData commitData, Collection<CDOLob<?>> lobs, OMMonitor monitor) + { + throw new UnsupportedOperationException(); + } + + public CommitTransactionResult commitTransaction(InternalCDOCommitContext context, OMMonitor monitor) + { + int attempt = 0; + for (;;) + { + try + { + return delegate.commitTransaction(context, monitor); + } + catch (Exception ex) + { + handleException(++attempt, ex); + } + } + } + + @Deprecated + public CommitTransactionResult commitDelegation(CDOBranch branch, String userID, String comment, + CDOCommitData commitData, Map<CDOID, EClass> detachedObjectTypes, Collection<CDOLob<?>> lobs, OMMonitor monitor) + { + throw new UnsupportedOperationException(); + } + + public CommitTransactionResult commitDelegation(InternalCDOCommitContext context, OMMonitor monitor) + { + int attempt = 0; + for (;;) + { + try + { + return delegate.commitDelegation(context, monitor); + } + catch (Exception ex) + { + handleException(++attempt, ex); + } + } + } + + public CommitTransactionResult commitXATransactionCancel(InternalCDOXACommitContext xaContext, OMMonitor monitor) + { + int attempt = 0; + for (;;) + { + try + { + return delegate.commitXATransactionCancel(xaContext, monitor); + } + catch (Exception ex) + { + handleException(++attempt, ex); + } + } + } + + public CommitTransactionResult commitXATransactionPhase1(InternalCDOXACommitContext xaContext, OMMonitor monitor) + { + int attempt = 0; + for (;;) + { + try + { + return delegate.commitXATransactionPhase1(xaContext, monitor); + } + catch (Exception ex) + { + handleException(++attempt, ex); + } + } + } + + public CommitTransactionResult commitXATransactionPhase2(InternalCDOXACommitContext xaContext, OMMonitor monitor) + { + int attempt = 0; + for (;;) + { + try + { + return delegate.commitXATransactionPhase2(xaContext, monitor); + } + catch (Exception ex) + { + handleException(++attempt, ex); + } + } + } + + public CommitTransactionResult commitXATransactionPhase3(InternalCDOXACommitContext xaContext, OMMonitor monitor) + { + int attempt = 0; + for (;;) + { + try + { + return delegate.commitXATransactionPhase3(xaContext, monitor); + } + catch (Exception ex) + { + handleException(++attempt, ex); + } + } + } + + public RepositoryTimeResult getRepositoryTime() + { + int attempt = 0; + for (;;) + { + try + { + return delegate.getRepositoryTime(); + } + catch (Exception ex) + { + handleException(++attempt, ex); + } + } + } + + public CDOLockState[] getLockStates(int viewID, Collection<CDOID> ids) + { + int attempt = 0; + for (;;) + { + try + { + return delegate.getLockStates(viewID, ids); + } + catch (Exception ex) + { + handleException(++attempt, ex); + } + } + } + + public void enableLockNotifications(int viewID, boolean enable) + { + int attempt = 0; + for (;;) + { + try + { + delegate.enableLockNotifications(viewID, enable); + return; + } + catch (Exception ex) + { + handleException(++attempt, ex); + } + } + } + + public boolean isObjectLocked(CDOView view, CDOObject object, LockType lockType, boolean byOthers) + { + int attempt = 0; + for (;;) + { + try + { + return delegate.isObjectLocked(view, object, lockType, byOthers); + } + catch (Exception ex) + { + handleException(++attempt, ex); + } + } + } + + public String changeLockArea(CDOView view, boolean create) + { + int attempt = 0; + for (;;) + { + try + { + return delegate.changeLockArea(view, create); + } + catch (Exception ex) + { + handleException(++attempt, ex); + } + } + } + + public EPackage[] loadPackages(CDOPackageUnit packageUnit) + { + int attempt = 0; + for (;;) + { + try + { + return delegate.loadPackages(packageUnit); + } + catch (Exception ex) + { + handleException(++attempt, ex); + } + } + } + + public Pair<Integer, Long> createBranch(int branchID, BranchInfo branchInfo) + { + int attempt = 0; + for (;;) + { + try + { + return delegate.createBranch(branchID, branchInfo); + } + catch (Exception ex) + { + handleException(++attempt, ex); + } + } + } + + public BranchInfo loadBranch(int branchID) + { + int attempt = 0; + for (;;) + { + try + { + return delegate.loadBranch(branchID); + } + catch (Exception ex) + { + handleException(++attempt, ex); + } + } + } + + public SubBranchInfo[] loadSubBranches(int branchID) + { + int attempt = 0; + for (;;) + { + try + { + return delegate.loadSubBranches(branchID); + } + catch (Exception ex) + { + handleException(++attempt, ex); + } + } + } + + public int loadBranches(int startID, int endID, CDOBranchHandler branchHandler) + { + int attempt = 0; + for (;;) + { + try + { + return delegate.loadBranches(startID, endID, branchHandler); + } + catch (Exception ex) + { + handleException(++attempt, ex); + } + } + } + + public void loadCommitInfos(CDOBranch branch, long startTime, long endTime, CDOCommitInfoHandler handler) + { + int attempt = 0; + for (;;) + { + try + { + delegate.loadCommitInfos(branch, startTime, endTime, handler); + return; + } + catch (Exception ex) + { + handleException(++attempt, ex); + } + } + } + + public CDOCommitData loadCommitData(long timeStamp) + { + int attempt = 0; + for (;;) + { + try + { + return delegate.loadCommitData(timeStamp); + } + catch (Exception ex) + { + handleException(++attempt, ex); + } + } + } + + public Object loadChunk(InternalCDORevision revision, EStructuralFeature feature, int accessIndex, int fetchIndex, + int fromIndex, int toIndex) + { + int attempt = 0; + for (;;) + { + try + { + return delegate.loadChunk(revision, feature, accessIndex, fetchIndex, fromIndex, toIndex); + } + catch (Exception ex) + { + handleException(++attempt, ex); + } + } + } + + public List<InternalCDORevision> loadRevisions(List<RevisionInfo> infos, CDOBranchPoint branchPoint, + int referenceChunk, int prefetchDepth) + { + int attempt = 0; + for (;;) + { + try + { + return delegate.loadRevisions(infos, branchPoint, referenceChunk, prefetchDepth); + } + catch (Exception ex) + { + handleException(++attempt, ex); + } + } + } + + public InternalCDORevision loadRevisionByVersion(CDOID id, CDOBranchVersion branchVersion, int referenceChunk) + { + int attempt = 0; + for (;;) + { + try + { + return delegate.loadRevisionByVersion(id, branchVersion, referenceChunk); + } + catch (Exception ex) + { + handleException(++attempt, ex); + } + } + } + + @Deprecated + public LockObjectsResult lockObjects(List<InternalCDORevision> viewedRevisions, int viewID, CDOBranch viewedBranch, + LockType lockType, long timeout) throws InterruptedException + { + throw new UnsupportedOperationException(); + } + + /** + * @since 4.1 + */ + public LockObjectsResult lockObjects2(List<CDORevisionKey> revisionKeys, int viewID, CDOBranch viewedBranch, + LockType lockType, boolean recursive, long timeout) throws InterruptedException + + { + int attempt = 0; + for (;;) + { + try + { + return delegate.lockObjects2(revisionKeys, viewID, viewedBranch, lockType, recursive, timeout); + } + catch (Exception ex) + { + handleException(++attempt, ex); + } + } + } + + public LockObjectsResult delegateLockObjects(String lockAreaID, List<CDORevisionKey> revisionKeys, + CDOBranch viewedBranch, LockType lockType, boolean recursive, long timeout) throws InterruptedException + { + int attempt = 0; + for (;;) + { + try + { + return delegate.delegateLockObjects(lockAreaID, revisionKeys, viewedBranch, lockType, recursive, timeout); + } + catch (Exception ex) + { + handleException(++attempt, ex); + } + } + } + + public UnlockObjectsResult delegateUnlockObjects(String lockAreaID, Collection<CDOID> objectIDs, LockType lockType, + boolean recursive) + { + int attempt = 0; + for (;;) + { + try + { + return delegate.delegateUnlockObjects(lockAreaID, objectIDs, lockType, recursive); + } + catch (Exception ex) + { + handleException(++attempt, ex); + } + } + } + + public void query(CDOView view, AbstractQueryIterator<?> queryResult) + { + int attempt = 0; + for (;;) + { + try + { + delegate.query(view, queryResult); + return; + } + catch (Exception ex) + { + handleException(++attempt, ex); + } + } + } + + public void disablePassiveUpdate() + { + int attempt = 0; + for (;;) + { + try + { + delegate.disablePassiveUpdate(); + return; + } + catch (Exception ex) + { + handleException(++attempt, ex); + } + } + } + + public void setPassiveUpdateMode(PassiveUpdateMode mode) + { + int attempt = 0; + for (;;) + { + try + { + delegate.setPassiveUpdateMode(mode); + return; + } + catch (Exception ex) + { + handleException(++attempt, ex); + } + } + } + + public void setLockNotificationMode(LockNotificationMode mode) + { + int attempt = 0; + for (;;) + { + try + { + delegate.setLockNotificationMode(mode); + return; + } + catch (Exception ex) + { + handleException(++attempt, ex); + } + } + } + + public RefreshSessionResult refresh(long lastUpdateTime, + Map<CDOBranch, Map<CDOID, InternalCDORevision>> viewedRevisions, int initialChunkSize, + boolean enablePassiveUpdates) + { + int attempt = 0; + for (;;) + { + try + { + return delegate.refresh(lastUpdateTime, viewedRevisions, initialChunkSize, enablePassiveUpdates); + } + catch (Exception ex) + { + handleException(++attempt, ex); + } + } + } + + @Deprecated + public void unlockObjects(CDOView view, Collection<CDOID> objectIDs, LockType lockType) + { + throw new UnsupportedOperationException(); + } + + public UnlockObjectsResult unlockObjects2(CDOView view, Collection<CDOID> objectIDs, LockType lockType, + boolean recursive) + { + int attempt = 0; + for (;;) + { + try + { + return delegate.unlockObjects2(view, objectIDs, lockType, recursive); + } + catch (Exception ex) + { + handleException(++attempt, ex); + } + } + } + + public List<CDORemoteSession> getRemoteSessions(InternalCDORemoteSessionManager manager, boolean subscribe) + { + int attempt = 0; + for (;;) + { + try + { + return delegate.getRemoteSessions(manager, subscribe); + } + catch (Exception ex) + { + handleException(++attempt, ex); + } + } + } + + public Set<Integer> sendRemoteMessage(CDORemoteSessionMessage message, List<CDORemoteSession> recipients) + { + int attempt = 0; + for (;;) + { + try + { + return delegate.sendRemoteMessage(message, recipients); + } + catch (Exception ex) + { + handleException(++attempt, ex); + } + } + } + + public boolean unsubscribeRemoteSessions() + { + int attempt = 0; + for (;;) + { + try + { + return delegate.unsubscribeRemoteSessions(); + } + catch (Exception ex) + { + handleException(++attempt, ex); + } + } + } + + public void replicateRepository(CDOReplicationContext context, OMMonitor monitor) + { + int attempt = 0; + for (;;) + { + try + { + delegate.replicateRepository(context, monitor); + return; + } + catch (Exception ex) + { + handleException(++attempt, ex); + } + } + } + + public void replicateRepositoryRaw(CDORawReplicationContext context, OMMonitor monitor) + { + int attempt = 0; + for (;;) + { + try + { + delegate.replicateRepositoryRaw(context, monitor); + return; + } + catch (Exception ex) + { + handleException(++attempt, ex); + } + } + } + + public CDOChangeSetData[] loadChangeSets(CDOBranchPointRange... ranges) + { + int attempt = 0; + for (;;) + { + try + { + return delegate.loadChangeSets(ranges); + } + catch (Exception ex) + { + handleException(++attempt, ex); + } + } + } + + public Set<CDOID> loadMergeData(CDORevisionAvailabilityInfo targetInfo, CDORevisionAvailabilityInfo sourceInfo, + CDORevisionAvailabilityInfo targetBaseInfo, CDORevisionAvailabilityInfo sourceBaseInfo) + { + int attempt = 0; + for (;;) + { + try + { + return delegate.loadMergeData(targetInfo, sourceInfo, targetBaseInfo, sourceBaseInfo); + } + catch (Exception ex) + { + handleException(++attempt, ex); + } + } + } + + @Override + protected void doActivate() throws Exception + { + super.doActivate(); + hookDelegate(); + } + + private void hookDelegate() + { + EventUtil.addListener(delegate, delegateListener); + } + + @Override + protected void doDeactivate() throws Exception + { + unhookDelegate(); + LifecycleUtil.deactivate(delegate); + delegate = null; + super.doDeactivate(); + } + + private void unhookDelegate() + { + EventUtil.removeListener(delegate, delegateListener); + } + + private void handleException(int attempt, Exception exception) + { + try + { + exceptionHandler.handleException(getSession(), attempt, exception); + } + catch (Exception ex) + { + throw WrappedException.wrap(ex); + } + } +} diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/session/SessionProperties.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/session/SessionProperties.java index f643a28271..8dce79a8e4 100644 --- a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/session/SessionProperties.java +++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/session/SessionProperties.java @@ -1,266 +1,266 @@ -/*
- * Copyright (c) 2004 - 2012 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.internal.cdo.session;
-
-import org.eclipse.emf.cdo.common.id.CDOID;
-import org.eclipse.emf.cdo.common.util.CDOCommonUtil;
-import org.eclipse.emf.cdo.session.CDOSession;
-
-import org.eclipse.emf.internal.cdo.messages.Messages;
-
-import org.eclipse.net4j.util.properties.DefaultPropertyTester;
-import org.eclipse.net4j.util.properties.IProperties;
-import org.eclipse.net4j.util.properties.Properties;
-import org.eclipse.net4j.util.properties.Property;
-
-/**
- * @author Eike Stepper
- */
-public class SessionProperties extends Properties<CDOSession>
-{
- public static final IProperties<CDOSession> INSTANCE = new SessionProperties();
-
- private static final String CATEGORY_SESSION = "Session"; //$NON-NLS-1$
-
- private static final String CATEGORY_REPOSITORY = "Repository"; //$NON-NLS-1$
-
- private SessionProperties()
- {
- super(CDOSession.class);
-
- add(new Property<CDOSession>("open", Messages.getString("SessionPropertyTester_34"),//
- Messages.getString("SessionPropertyTester_35"), //$NON-NLS-1$
- CATEGORY_SESSION)
- {
- @Override
- protected Object eval(CDOSession session)
- {
- return !session.isClosed();
- }
- });
-
- add(new Property<CDOSession>("sessionID", Messages.getString("SessionPropertyTester_0"),//
- Messages.getString("SessionPropertyTester_3"), //$NON-NLS-1$
- CATEGORY_SESSION)
- {
- @Override
- protected Object eval(CDOSession session)
- {
- return session.getSessionID();
- }
- });
-
- add(new Property<CDOSession>("userID", Messages.getString("SessionPropertyTester_4"), //
- Messages.getString("SessionPropertyTester_5"), //$NON-NLS-1$
- CATEGORY_SESSION)
- {
- @Override
- protected Object eval(CDOSession session)
- {
- return session.getUserID();
- }
- });
-
- add(new Property<CDOSession>("passiveUpdateEnabled", Messages.getString("SessionPropertyTester_6"), //
- Messages.getString("SessionPropertyTester_7"), //$NON-NLS-1$
- CATEGORY_SESSION)
- {
- @Override
- protected Object eval(CDOSession session)
- {
- return session.options().isPassiveUpdateEnabled();
- }
- });
-
- add(new Property<CDOSession>("lastUpdateTime", Messages.getString("SessionPropertyTester_36"), //
- Messages.getString("SessionPropertyTester_37"), //$NON-NLS-1$
- CATEGORY_SESSION)
- {
- @Override
- protected Object eval(CDOSession session)
- {
- return CDOCommonUtil.formatTimeStamp(session.getLastUpdateTime());
- }
- });
-
- add(new Property<CDOSession>("passiveUpdateMode", Messages.getString("SessionPropertyTester_8"), //
- Messages.getString("SessionPropertyTester_9"), //$NON-NLS-1$
- CATEGORY_SESSION)
- {
- @Override
- protected Object eval(CDOSession session)
- {
- return session.options().getPassiveUpdateMode();
- }
- });
-
- add(new Property<CDOSession>("repositoryName", Messages.getString("SessionPropertyTester_10"), //
- Messages.getString("SessionPropertyTester_11"), //$NON-NLS-1$
- CATEGORY_REPOSITORY)
- {
- @Override
- protected Object eval(CDOSession session)
- {
- return session.getRepositoryInfo().getName();
- }
- });
-
- add(new Property<CDOSession>("repositoryUUID", Messages.getString("SessionPropertyTester_12"), //
- Messages.getString("SessionPropertyTester_13"), //$NON-NLS-1$
- CATEGORY_REPOSITORY)
- {
- @Override
- protected Object eval(CDOSession session)
- {
- return session.getRepositoryInfo().getUUID();
- }
- });
-
- add(new Property<CDOSession>("repositoryType", Messages.getString("SessionPropertyTester_14"), //
- Messages.getString("SessionPropertyTester_15"), //$NON-NLS-1$
- CATEGORY_REPOSITORY)
- {
- @Override
- protected Object eval(CDOSession session)
- {
- return session.getRepositoryInfo().getType();
- }
- });
-
- add(new Property<CDOSession>("repositoryState", Messages.getString("SessionPropertyTester_16"), //
- Messages.getString("SessionPropertyTester_17"), //$NON-NLS-1$
- CATEGORY_REPOSITORY)
- {
- @Override
- protected Object eval(CDOSession session)
- {
- return session.getRepositoryInfo().getState();
- }
- });
-
- add(new Property<CDOSession>("repositoryCreationTime", Messages.getString("SessionPropertyTester_18"), //
- Messages.getString("SessionPropertyTester_19"), //$NON-NLS-1$
- CATEGORY_REPOSITORY)
- {
- @Override
- protected Object eval(CDOSession session)
- {
- return CDOCommonUtil.formatTimeStamp(session.getRepositoryInfo().getCreationTime());
- }
- });
-
- add(new Property<CDOSession>("supportingAudits", Messages.getString("SessionPropertyTester_20"), //
- Messages.getString("SessionPropertyTester_21"), //$NON-NLS-1$
- CATEGORY_REPOSITORY)
- {
- @Override
- protected Object eval(CDOSession session)
- {
- return session.getRepositoryInfo().isSupportingAudits();
- }
- });
-
- add(new Property<CDOSession>("supportingBranches", Messages.getString("SessionPropertyTester_22"), //
- Messages.getString("SessionPropertyTester_23"), //$NON-NLS-1$
- CATEGORY_REPOSITORY)
- {
- @Override
- protected Object eval(CDOSession session)
- {
- return session.getRepositoryInfo().isSupportingBranches();
- }
- });
-
- add(new Property<CDOSession>("supportingEcore", Messages.getString("SessionPropertyTester_28"), //
- Messages.getString("SessionPropertyTester_29"), //$NON-NLS-1$
- CATEGORY_REPOSITORY)
- {
- @Override
- protected Object eval(CDOSession session)
- {
- return session.getRepositoryInfo().isSupportingEcore();
- }
- });
-
- add(new Property<CDOSession>("ensureReferentialIntegrity", Messages.getString("SessionPropertyTester_30"), //
- Messages.getString("SessionPropertyTester_31"), //$NON-NLS-1$
- CATEGORY_REPOSITORY)
- {
- @Override
- protected Object eval(CDOSession session)
- {
- return session.getRepositoryInfo().isEnsuringReferentialIntegrity();
- }
- });
-
- add(new Property<CDOSession>("idGenerationLocation", Messages.getString("SessionPropertyTester_32"), //
- Messages.getString("SessionPropertyTester_33"), //$NON-NLS-1$
- CATEGORY_REPOSITORY)
- {
- @Override
- protected Object eval(CDOSession session)
- {
- return session.getRepositoryInfo().getIDGenerationLocation();
- }
- });
-
- add(new Property<CDOSession>("storeType", Messages.getString("SessionPropertyTester_24"), //
- Messages.getString("SessionPropertyTester_25"), //$NON-NLS-1$
- CATEGORY_REPOSITORY)
- {
- @Override
- protected Object eval(CDOSession session)
- {
- return session.getRepositoryInfo().getStoreType();
- }
- });
-
- add(new Property<CDOSession>("objectIDTypes", Messages.getString("SessionPropertyTester_26"), //
- Messages.getString("SessionPropertyTester_27"), //$NON-NLS-1$
- CATEGORY_REPOSITORY)
- {
- @Override
- protected Object eval(CDOSession session)
- {
- StringBuilder builder = new StringBuilder();
- for (CDOID.ObjectType objectIDType : session.getRepositoryInfo().getObjectIDTypes())
- {
- if (builder.length() != 0)
- {
- builder.append(", "); //$NON-NLS-1$
- }
-
- builder.append(objectIDType);
- }
-
- return builder;
- }
- });
- }
-
- public static void main(String[] args)
- {
- new Tester().dumpContributionMarkup();
- }
-
- /**
- * @author Eike Stepper
- */
- public static final class Tester extends DefaultPropertyTester<CDOSession>
- {
- public static final String NAMESPACE = "org.eclipse.emf.cdo.session";
-
- public Tester()
- {
- super(NAMESPACE, INSTANCE);
- }
- }
-}
+/* + * Copyright (c) 2004 - 2012 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.internal.cdo.session; + +import org.eclipse.emf.cdo.common.id.CDOID; +import org.eclipse.emf.cdo.common.util.CDOCommonUtil; +import org.eclipse.emf.cdo.session.CDOSession; + +import org.eclipse.emf.internal.cdo.messages.Messages; + +import org.eclipse.net4j.util.properties.DefaultPropertyTester; +import org.eclipse.net4j.util.properties.IProperties; +import org.eclipse.net4j.util.properties.Properties; +import org.eclipse.net4j.util.properties.Property; + +/** + * @author Eike Stepper + */ +public class SessionProperties extends Properties<CDOSession> +{ + public static final IProperties<CDOSession> INSTANCE = new SessionProperties(); + + private static final String CATEGORY_SESSION = "Session"; //$NON-NLS-1$ + + private static final String CATEGORY_REPOSITORY = "Repository"; //$NON-NLS-1$ + + private SessionProperties() + { + super(CDOSession.class); + + add(new Property<CDOSession>("open", Messages.getString("SessionPropertyTester_34"),// + Messages.getString("SessionPropertyTester_35"), //$NON-NLS-1$ + CATEGORY_SESSION) + { + @Override + protected Object eval(CDOSession session) + { + return !session.isClosed(); + } + }); + + add(new Property<CDOSession>("sessionID", Messages.getString("SessionPropertyTester_0"),// + Messages.getString("SessionPropertyTester_3"), //$NON-NLS-1$ + CATEGORY_SESSION) + { + @Override + protected Object eval(CDOSession session) + { + return session.getSessionID(); + } + }); + + add(new Property<CDOSession>("userID", Messages.getString("SessionPropertyTester_4"), // + Messages.getString("SessionPropertyTester_5"), //$NON-NLS-1$ + CATEGORY_SESSION) + { + @Override + protected Object eval(CDOSession session) + { + return session.getUserID(); + } + }); + + add(new Property<CDOSession>("passiveUpdateEnabled", Messages.getString("SessionPropertyTester_6"), // + Messages.getString("SessionPropertyTester_7"), //$NON-NLS-1$ + CATEGORY_SESSION) + { + @Override + protected Object eval(CDOSession session) + { + return session.options().isPassiveUpdateEnabled(); + } + }); + + add(new Property<CDOSession>("lastUpdateTime", Messages.getString("SessionPropertyTester_36"), // + Messages.getString("SessionPropertyTester_37"), //$NON-NLS-1$ + CATEGORY_SESSION) + { + @Override + protected Object eval(CDOSession session) + { + return CDOCommonUtil.formatTimeStamp(session.getLastUpdateTime()); + } + }); + + add(new Property<CDOSession>("passiveUpdateMode", Messages.getString("SessionPropertyTester_8"), // + Messages.getString("SessionPropertyTester_9"), //$NON-NLS-1$ + CATEGORY_SESSION) + { + @Override + protected Object eval(CDOSession session) + { + return session.options().getPassiveUpdateMode(); + } + }); + + add(new Property<CDOSession>("repositoryName", Messages.getString("SessionPropertyTester_10"), // + Messages.getString("SessionPropertyTester_11"), //$NON-NLS-1$ + CATEGORY_REPOSITORY) + { + @Override + protected Object eval(CDOSession session) + { + return session.getRepositoryInfo().getName(); + } + }); + + add(new Property<CDOSession>("repositoryUUID", Messages.getString("SessionPropertyTester_12"), // + Messages.getString("SessionPropertyTester_13"), //$NON-NLS-1$ + CATEGORY_REPOSITORY) + { + @Override + protected Object eval(CDOSession session) + { + return session.getRepositoryInfo().getUUID(); + } + }); + + add(new Property<CDOSession>("repositoryType", Messages.getString("SessionPropertyTester_14"), // + Messages.getString("SessionPropertyTester_15"), //$NON-NLS-1$ + CATEGORY_REPOSITORY) + { + @Override + protected Object eval(CDOSession session) + { + return session.getRepositoryInfo().getType(); + } + }); + + add(new Property<CDOSession>("repositoryState", Messages.getString("SessionPropertyTester_16"), // + Messages.getString("SessionPropertyTester_17"), //$NON-NLS-1$ + CATEGORY_REPOSITORY) + { + @Override + protected Object eval(CDOSession session) + { + return session.getRepositoryInfo().getState(); + } + }); + + add(new Property<CDOSession>("repositoryCreationTime", Messages.getString("SessionPropertyTester_18"), // + Messages.getString("SessionPropertyTester_19"), //$NON-NLS-1$ + CATEGORY_REPOSITORY) + { + @Override + protected Object eval(CDOSession session) + { + return CDOCommonUtil.formatTimeStamp(session.getRepositoryInfo().getCreationTime()); + } + }); + + add(new Property<CDOSession>("supportingAudits", Messages.getString("SessionPropertyTester_20"), // + Messages.getString("SessionPropertyTester_21"), //$NON-NLS-1$ + CATEGORY_REPOSITORY) + { + @Override + protected Object eval(CDOSession session) + { + return session.getRepositoryInfo().isSupportingAudits(); + } + }); + + add(new Property<CDOSession>("supportingBranches", Messages.getString("SessionPropertyTester_22"), // + Messages.getString("SessionPropertyTester_23"), //$NON-NLS-1$ + CATEGORY_REPOSITORY) + { + @Override + protected Object eval(CDOSession session) + { + return session.getRepositoryInfo().isSupportingBranches(); + } + }); + + add(new Property<CDOSession>("supportingEcore", Messages.getString("SessionPropertyTester_28"), // + Messages.getString("SessionPropertyTester_29"), //$NON-NLS-1$ + CATEGORY_REPOSITORY) + { + @Override + protected Object eval(CDOSession session) + { + return session.getRepositoryInfo().isSupportingEcore(); + } + }); + + add(new Property<CDOSession>("ensureReferentialIntegrity", Messages.getString("SessionPropertyTester_30"), // + Messages.getString("SessionPropertyTester_31"), //$NON-NLS-1$ + CATEGORY_REPOSITORY) + { + @Override + protected Object eval(CDOSession session) + { + return session.getRepositoryInfo().isEnsuringReferentialIntegrity(); + } + }); + + add(new Property<CDOSession>("idGenerationLocation", Messages.getString("SessionPropertyTester_32"), // + Messages.getString("SessionPropertyTester_33"), //$NON-NLS-1$ + CATEGORY_REPOSITORY) + { + @Override + protected Object eval(CDOSession session) + { + return session.getRepositoryInfo().getIDGenerationLocation(); + } + }); + + add(new Property<CDOSession>("storeType", Messages.getString("SessionPropertyTester_24"), // + Messages.getString("SessionPropertyTester_25"), //$NON-NLS-1$ + CATEGORY_REPOSITORY) + { + @Override + protected Object eval(CDOSession session) + { + return session.getRepositoryInfo().getStoreType(); + } + }); + + add(new Property<CDOSession>("objectIDTypes", Messages.getString("SessionPropertyTester_26"), // + Messages.getString("SessionPropertyTester_27"), //$NON-NLS-1$ + CATEGORY_REPOSITORY) + { + @Override + protected Object eval(CDOSession session) + { + StringBuilder builder = new StringBuilder(); + for (CDOID.ObjectType objectIDType : session.getRepositoryInfo().getObjectIDTypes()) + { + if (builder.length() != 0) + { + builder.append(", "); //$NON-NLS-1$ + } + + builder.append(objectIDType); + } + + return builder; + } + }); + } + + public static void main(String[] args) + { + new Tester().dumpContributionMarkup(); + } + + /** + * @author Eike Stepper + */ + public static final class Tester extends DefaultPropertyTester<CDOSession> + { + public static final String NAMESPACE = "org.eclipse.emf.cdo.session"; + + public Tester() + { + super(NAMESPACE, INSTANCE); + } + } +} diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/session/SessionUtil.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/session/SessionUtil.java index 24c701321f..9ccc568463 100644 --- a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/session/SessionUtil.java +++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/session/SessionUtil.java @@ -1,90 +1,90 @@ -/*
- * Copyright (c) 2004 - 2012 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.internal.cdo.session;
-
-import org.eclipse.emf.cdo.eresource.CDOResource;
-import org.eclipse.emf.cdo.util.CDOUtil;
-
-import org.eclipse.emf.internal.cdo.view.CDOViewSetImpl;
-
-import org.eclipse.emf.common.notify.Notification;
-import org.eclipse.emf.common.notify.Notifier;
-import org.eclipse.emf.common.notify.impl.AdapterImpl;
-import org.eclipse.emf.ecore.resource.ResourceSet;
-import org.eclipse.emf.spi.cdo.InternalCDOViewSet;
-
-/**
- * @author Eike Stepper
- */
-public final class SessionUtil
-{
- private static final boolean ROOT_RESOURCE_EXCLUSION_CHECK = false;
-
- private SessionUtil()
- {
- }
-
- /**
- * @since 2.0
- */
- public static InternalCDOViewSet prepareResourceSet(ResourceSet resourceSet)
- {
- InternalCDOViewSet viewSet = null;
- synchronized (resourceSet)
- {
- if (ROOT_RESOURCE_EXCLUSION_CHECK)
- {
- addRootResourceExclusionCheckAdapter(resourceSet);
- }
-
- viewSet = (InternalCDOViewSet)CDOUtil.getViewSet(resourceSet);
- if (viewSet == null)
- {
- viewSet = new CDOViewSetImpl();
- resourceSet.eAdapters().add(viewSet);
- }
- }
-
- return viewSet;
- }
-
- private static void addRootResourceExclusionCheckAdapter(ResourceSet resourceSet)
- {
- class RootResourceExclusionCheckAdapter extends AdapterImpl
- {
- @Override
- public void notifyChanged(Notification msg)
- {
- if (msg.getEventType() == Notification.ADD || msg.getEventType() == Notification.ADD_MANY)
- {
- Object newValue = msg.getNewValue();
- check(newValue);
- }
- }
-
- @Override
- public void setTarget(Notifier newTarget)
- {
- check(newTarget);
- }
-
- private void check(Object object)
- {
- if (object instanceof CDOResource && ((CDOResource)object).isRoot())
- {
- throw new AssertionError("Root resource in resource set not allowed");
- }
- }
- }
-
- resourceSet.eAdapters().add(new RootResourceExclusionCheckAdapter());
- }
-}
+/* + * Copyright (c) 2004 - 2012 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.internal.cdo.session; + +import org.eclipse.emf.cdo.eresource.CDOResource; +import org.eclipse.emf.cdo.util.CDOUtil; + +import org.eclipse.emf.internal.cdo.view.CDOViewSetImpl; + +import org.eclipse.emf.common.notify.Notification; +import org.eclipse.emf.common.notify.Notifier; +import org.eclipse.emf.common.notify.impl.AdapterImpl; +import org.eclipse.emf.ecore.resource.ResourceSet; +import org.eclipse.emf.spi.cdo.InternalCDOViewSet; + +/** + * @author Eike Stepper + */ +public final class SessionUtil +{ + private static final boolean ROOT_RESOURCE_EXCLUSION_CHECK = false; + + private SessionUtil() + { + } + + /** + * @since 2.0 + */ + public static InternalCDOViewSet prepareResourceSet(ResourceSet resourceSet) + { + InternalCDOViewSet viewSet = null; + synchronized (resourceSet) + { + if (ROOT_RESOURCE_EXCLUSION_CHECK) + { + addRootResourceExclusionCheckAdapter(resourceSet); + } + + viewSet = (InternalCDOViewSet)CDOUtil.getViewSet(resourceSet); + if (viewSet == null) + { + viewSet = new CDOViewSetImpl(); + resourceSet.eAdapters().add(viewSet); + } + } + + return viewSet; + } + + private static void addRootResourceExclusionCheckAdapter(ResourceSet resourceSet) + { + class RootResourceExclusionCheckAdapter extends AdapterImpl + { + @Override + public void notifyChanged(Notification msg) + { + if (msg.getEventType() == Notification.ADD || msg.getEventType() == Notification.ADD_MANY) + { + Object newValue = msg.getNewValue(); + check(newValue); + } + } + + @Override + public void setTarget(Notifier newTarget) + { + check(newTarget); + } + + private void check(Object object) + { + if (object instanceof CDOResource && ((CDOResource)object).isRoot()) + { + throw new AssertionError("Root resource in resource set not allowed"); + } + } + } + + resourceSet.eAdapters().add(new RootResourceExclusionCheckAdapter()); + } +} diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/session/remote/CDORemoteSessionImpl.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/session/remote/CDORemoteSessionImpl.java index 6e4071835c..8843decce7 100644 --- a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/session/remote/CDORemoteSessionImpl.java +++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/session/remote/CDORemoteSessionImpl.java @@ -1,117 +1,117 @@ -/*
- * Copyright (c) 2004 - 2012 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.internal.cdo.session.remote;
-
-import org.eclipse.emf.cdo.session.remote.CDORemoteSession;
-import org.eclipse.emf.cdo.session.remote.CDORemoteSessionMessage;
-
-import org.eclipse.emf.spi.cdo.InternalCDORemoteSession;
-import org.eclipse.emf.spi.cdo.InternalCDORemoteSessionManager;
-
-import java.text.MessageFormat;
-
-/**
- * @author Eike Stepper
- */
-public class CDORemoteSessionImpl implements InternalCDORemoteSession
-{
- private InternalCDORemoteSessionManager manager;
-
- private int sessionID;
-
- private String userID;
-
- private boolean subscribed;
-
- public CDORemoteSessionImpl(InternalCDORemoteSessionManager manager, int sessionID, String userID)
- {
- this.manager = manager;
- this.sessionID = sessionID;
- this.userID = userID;
- }
-
- public InternalCDORemoteSessionManager getManager()
- {
- return manager;
- }
-
- public int getSessionID()
- {
- return sessionID;
- }
-
- public String getUserID()
- {
- return userID;
- }
-
- public boolean isSubscribed()
- {
- return subscribed;
- }
-
- public void setSubscribed(boolean subscribed)
- {
- this.subscribed = subscribed;
- }
-
- public boolean sendMessage(CDORemoteSessionMessage message)
- {
- if (!isSubscribed())
- {
- return false;
- }
-
- return manager.sendMessage(message, this).size() == 1;
- }
-
- public int compareTo(CDORemoteSession obj)
- {
- int result = userID.compareTo(obj.getUserID());
- if (result == 0)
- {
- result = Integer.valueOf(sessionID).compareTo(obj.getSessionID());
- }
-
- return result;
- }
-
- @Override
- public boolean equals(Object obj)
- {
- if (obj == this)
- {
- return true;
- }
-
- if (obj instanceof CDORemoteSession)
- {
- CDORemoteSession that = (CDORemoteSession)obj;
- return manager == that.getManager() && sessionID == that.getSessionID();
- }
-
- return false;
- }
-
- @Override
- public int hashCode()
- {
- return manager.hashCode() ^ sessionID;
- }
-
- @Override
- public String toString()
- {
- String repo = manager.getLocalSession().getRepositoryInfo().getName();
- String user = userID == null ? repo : userID + "@" + repo;
- return MessageFormat.format("{0} ({1})", user, sessionID); //$NON-NLS-1$
- }
-}
+/* + * Copyright (c) 2004 - 2012 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.internal.cdo.session.remote; + +import org.eclipse.emf.cdo.session.remote.CDORemoteSession; +import org.eclipse.emf.cdo.session.remote.CDORemoteSessionMessage; + +import org.eclipse.emf.spi.cdo.InternalCDORemoteSession; +import org.eclipse.emf.spi.cdo.InternalCDORemoteSessionManager; + +import java.text.MessageFormat; + +/** + * @author Eike Stepper + */ +public class CDORemoteSessionImpl implements InternalCDORemoteSession +{ + private InternalCDORemoteSessionManager manager; + + private int sessionID; + + private String userID; + + private boolean subscribed; + + public CDORemoteSessionImpl(InternalCDORemoteSessionManager manager, int sessionID, String userID) + { + this.manager = manager; + this.sessionID = sessionID; + this.userID = userID; + } + + public InternalCDORemoteSessionManager getManager() + { + return manager; + } + + public int getSessionID() + { + return sessionID; + } + + public String getUserID() + { + return userID; + } + + public boolean isSubscribed() + { + return subscribed; + } + + public void setSubscribed(boolean subscribed) + { + this.subscribed = subscribed; + } + + public boolean sendMessage(CDORemoteSessionMessage message) + { + if (!isSubscribed()) + { + return false; + } + + return manager.sendMessage(message, this).size() == 1; + } + + public int compareTo(CDORemoteSession obj) + { + int result = userID.compareTo(obj.getUserID()); + if (result == 0) + { + result = Integer.valueOf(sessionID).compareTo(obj.getSessionID()); + } + + return result; + } + + @Override + public boolean equals(Object obj) + { + if (obj == this) + { + return true; + } + + if (obj instanceof CDORemoteSession) + { + CDORemoteSession that = (CDORemoteSession)obj; + return manager == that.getManager() && sessionID == that.getSessionID(); + } + + return false; + } + + @Override + public int hashCode() + { + return manager.hashCode() ^ sessionID; + } + + @Override + public String toString() + { + String repo = manager.getLocalSession().getRepositoryInfo().getName(); + String user = userID == null ? repo : userID + "@" + repo; + return MessageFormat.format("{0} ({1})", user, sessionID); //$NON-NLS-1$ + } +} diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/session/remote/CDORemoteSessionManagerImpl.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/session/remote/CDORemoteSessionManagerImpl.java index f5ec88118c..5848c7a507 100644 --- a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/session/remote/CDORemoteSessionManagerImpl.java +++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/session/remote/CDORemoteSessionManagerImpl.java @@ -1,398 +1,398 @@ -/*
- * Copyright (c) 2004 - 2012 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.internal.cdo.session.remote;
-
-import org.eclipse.emf.cdo.session.remote.CDORemoteSession;
-import org.eclipse.emf.cdo.session.remote.CDORemoteSessionEvent;
-import org.eclipse.emf.cdo.session.remote.CDORemoteSessionManager;
-import org.eclipse.emf.cdo.session.remote.CDORemoteSessionMessage;
-
-import org.eclipse.net4j.util.collection.ArrayIterator;
-import org.eclipse.net4j.util.container.Container;
-import org.eclipse.net4j.util.container.ContainerEvent;
-import org.eclipse.net4j.util.container.IContainerDelta;
-import org.eclipse.net4j.util.event.Event;
-import org.eclipse.net4j.util.event.IEvent;
-
-import org.eclipse.emf.spi.cdo.InternalCDORemoteSession;
-import org.eclipse.emf.spi.cdo.InternalCDORemoteSessionManager;
-import org.eclipse.emf.spi.cdo.InternalCDOSession;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
-/**
- * @author Eike Stepper
- */
-public class CDORemoteSessionManagerImpl extends Container<CDORemoteSession> implements InternalCDORemoteSessionManager
-{
- private InternalCDOSession localSession;
-
- private boolean forceSubscription;
-
- private boolean subscribed;
-
- private Map<Integer, CDORemoteSession> remoteSessions = new HashMap<Integer, CDORemoteSession>();
-
- public CDORemoteSessionManagerImpl()
- {
- }
-
- public InternalCDOSession getLocalSession()
- {
- return localSession;
- }
-
- public void setLocalSession(InternalCDOSession localSession)
- {
- this.localSession = localSession;
- }
-
- public CDORemoteSession[] getRemoteSessions()
- {
- Collection<CDORemoteSession> remoteSessions;
- synchronized (this)
- {
- if (subscribed)
- {
- remoteSessions = this.remoteSessions.values();
- }
- else
- {
- remoteSessions = localSession.getSessionProtocol().getRemoteSessions(this, false);
- }
- }
-
- return remoteSessions.toArray(new CDORemoteSession[remoteSessions.size()]);
- }
-
- public CDORemoteSession[] getElements()
- {
- return getRemoteSessions();
- }
-
- public boolean isSubscribed()
- {
- synchronized (this)
- {
- return subscribed;
- }
- }
-
- public boolean isForceSubscription()
- {
- synchronized (this)
- {
- return forceSubscription;
- }
- }
-
- public void setForceSubscription(boolean forceSubscription)
- {
- IEvent[] events = null;
- synchronized (this)
- {
- this.forceSubscription = forceSubscription;
- if (forceSubscription)
- {
- if (!subscribed)
- {
- events = subscribe();
- }
- }
- else
- {
- if (!hasListeners())
- {
- events = unsubscribe();
- }
- }
- }
-
- fireEvents(events);
- }
-
- public Set<CDORemoteSession> sendMessage(CDORemoteSessionMessage message, CDORemoteSession... recipients)
- {
- return sendMessage(message, new ArrayIterator<CDORemoteSession>(recipients));
- }
-
- public Set<CDORemoteSession> sendMessage(CDORemoteSessionMessage message, Collection<CDORemoteSession> recipients)
- {
- return sendMessage(message, recipients.iterator());
- }
-
- private Set<CDORemoteSession> sendMessage(CDORemoteSessionMessage message, Iterator<CDORemoteSession> recipients)
- {
- List<CDORemoteSession> subscribed = new ArrayList<CDORemoteSession>();
- while (recipients.hasNext())
- {
- CDORemoteSession recipient = recipients.next();
- if (recipient.isSubscribed())
- {
- subscribed.add(recipient);
- }
- }
-
- if (subscribed.isEmpty())
- {
- return Collections.emptySet();
- }
-
- Set<Integer> sessionIDs = localSession.getSessionProtocol().sendRemoteMessage(message, subscribed);
- Set<CDORemoteSession> result = new HashSet<CDORemoteSession>();
- for (CDORemoteSession recipient : subscribed)
- {
- if (sessionIDs.contains(recipient.getSessionID()))
- {
- result.add(recipient);
- }
- }
-
- return result;
- }
-
- public InternalCDORemoteSession createRemoteSession(int sessionID, String userID, boolean subscribed)
- {
- InternalCDORemoteSession remoteSession = new CDORemoteSessionImpl(this, sessionID, userID);
- remoteSession.setSubscribed(subscribed);
- return remoteSession;
- }
-
- public void handleRemoteSessionOpened(int sessionID, String userID)
- {
- CDORemoteSession remoteSession = createRemoteSession(sessionID, userID, false);
- synchronized (this)
- {
- remoteSessions.put(sessionID, remoteSession);
- }
-
- fireElementAddedEvent(remoteSession);
- }
-
- public void handleRemoteSessionClosed(int sessionID)
- {
- CDORemoteSession remoteSession = null;
- synchronized (this)
- {
- remoteSession = remoteSessions.remove(sessionID);
- }
-
- if (remoteSession != null)
- {
- fireElementRemovedEvent(remoteSession);
- }
- }
-
- public void handleRemoteSessionSubscribed(int sessionID, boolean subscribed)
- {
- IEvent event = null;
- synchronized (this)
- {
- InternalCDORemoteSession remoteSession = (InternalCDORemoteSession)remoteSessions.get(sessionID);
- if (remoteSession != null)
- {
- remoteSession.setSubscribed(subscribed);
- event = new SubscriptionChangedEventImpl(remoteSession, subscribed);
- }
- }
-
- if (event != null)
- {
- fireEvent(event);
- }
- }
-
- public void handleRemoteSessionMessage(int sessionID, final CDORemoteSessionMessage message)
- {
- IEvent event = null;
- synchronized (this)
- {
- final CDORemoteSessionManager source = this;
- final InternalCDORemoteSession remoteSession = (InternalCDORemoteSession)remoteSessions.get(sessionID);
- if (remoteSession != null)
- {
- event = new CDORemoteSessionEvent.MessageReceived()
- {
- public CDORemoteSessionManager getSource()
- {
- return source;
- }
-
- public CDORemoteSession getRemoteSession()
- {
- return remoteSession;
- }
-
- public CDORemoteSessionMessage getMessage()
- {
- return message;
- }
- };
- }
- }
-
- if (event != null)
- {
- fireEvent(event);
- }
- }
-
- @Override
- protected void firstListenerAdded()
- {
- IEvent[] events = null;
- synchronized (this)
- {
- if (!subscribed)
- {
- events = subscribe();
- }
- }
-
- fireEvents(events);
- }
-
- @Override
- protected void lastListenerRemoved()
- {
- IEvent[] events = null;
- synchronized (this)
- {
- if (!forceSubscription)
- {
- events = unsubscribe();
- }
- }
-
- fireEvents(events);
- }
-
- /**
- * Needs to be synchronized externally.
- */
- private IEvent[] subscribe()
- {
- List<CDORemoteSession> result = localSession.getSessionProtocol().getRemoteSessions(this, true);
- ContainerEvent<CDORemoteSession> event = new ContainerEvent<CDORemoteSession>(this);
- for (CDORemoteSession remoteSession : result)
- {
- remoteSessions.put(remoteSession.getSessionID(), remoteSession);
- event.addDelta(remoteSession, IContainerDelta.Kind.ADDED);
- }
-
- subscribed = true;
- IEvent[] events = { new LocalSubscriptionChangedEventImpl(true), event.isEmpty() ? null : event };
- return events;
- }
-
- /**
- * Needs to be synchronized externally.
- */
- private IEvent[] unsubscribe()
- {
- localSession.getSessionProtocol().unsubscribeRemoteSessions();
- ContainerEvent<CDORemoteSession> event = new ContainerEvent<CDORemoteSession>(this);
- for (CDORemoteSession remoteSession : remoteSessions.values())
- {
- event.addDelta(remoteSession, IContainerDelta.Kind.REMOVED);
- }
-
- remoteSessions.clear();
- subscribed = false;
- IEvent[] events = { new LocalSubscriptionChangedEventImpl(false), event.isEmpty() ? null : event };
- return events;
- }
-
- private void fireEvents(IEvent[] events)
- {
- if (events != null)
- {
- for (int i = 0; i < events.length; i++)
- {
- IEvent event = events[i];
- if (event != null)
- {
- fireEvent(event);
- }
- }
- }
- }
-
- /**
- * @author Eike Stepper
- */
- private final class LocalSubscriptionChangedEventImpl extends Event implements LocalSubscriptionChangedEvent
- {
- private static final long serialVersionUID = 1L;
-
- private boolean subscribed;
-
- public LocalSubscriptionChangedEventImpl(boolean subscribed)
- {
- super(CDORemoteSessionManagerImpl.this);
- this.subscribed = subscribed;
- }
-
- @Override
- public CDORemoteSessionManager getSource()
- {
- return (CDORemoteSessionManager)super.getSource();
- }
-
- public boolean isSubscribed()
- {
- return subscribed;
- }
- }
-
- /**
- * @author Eike Stepper
- */
- private final class SubscriptionChangedEventImpl extends Event implements CDORemoteSessionEvent.SubscriptionChanged
- {
- private static final long serialVersionUID = 1L;
-
- private InternalCDORemoteSession remoteSession;
-
- private boolean subscribed;
-
- public SubscriptionChangedEventImpl(InternalCDORemoteSession remoteSession, boolean subscribed)
- {
- super(CDORemoteSessionManagerImpl.this);
- this.remoteSession = remoteSession;
- this.subscribed = subscribed;
- }
-
- @Override
- public CDORemoteSessionManager getSource()
- {
- return (CDORemoteSessionManager)super.getSource();
- }
-
- public CDORemoteSession getRemoteSession()
- {
- return remoteSession;
- }
-
- public boolean isSubscribed()
- {
- return subscribed;
- }
- }
-}
+/* + * Copyright (c) 2004 - 2012 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.internal.cdo.session.remote; + +import org.eclipse.emf.cdo.session.remote.CDORemoteSession; +import org.eclipse.emf.cdo.session.remote.CDORemoteSessionEvent; +import org.eclipse.emf.cdo.session.remote.CDORemoteSessionManager; +import org.eclipse.emf.cdo.session.remote.CDORemoteSessionMessage; + +import org.eclipse.net4j.util.collection.ArrayIterator; +import org.eclipse.net4j.util.container.Container; +import org.eclipse.net4j.util.container.ContainerEvent; +import org.eclipse.net4j.util.container.IContainerDelta; +import org.eclipse.net4j.util.event.Event; +import org.eclipse.net4j.util.event.IEvent; + +import org.eclipse.emf.spi.cdo.InternalCDORemoteSession; +import org.eclipse.emf.spi.cdo.InternalCDORemoteSessionManager; +import org.eclipse.emf.spi.cdo.InternalCDOSession; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Set; + +/** + * @author Eike Stepper + */ +public class CDORemoteSessionManagerImpl extends Container<CDORemoteSession> implements InternalCDORemoteSessionManager +{ + private InternalCDOSession localSession; + + private boolean forceSubscription; + + private boolean subscribed; + + private Map<Integer, CDORemoteSession> remoteSessions = new HashMap<Integer, CDORemoteSession>(); + + public CDORemoteSessionManagerImpl() + { + } + + public InternalCDOSession getLocalSession() + { + return localSession; + } + + public void setLocalSession(InternalCDOSession localSession) + { + this.localSession = localSession; + } + + public CDORemoteSession[] getRemoteSessions() + { + Collection<CDORemoteSession> remoteSessions; + synchronized (this) + { + if (subscribed) + { + remoteSessions = this.remoteSessions.values(); + } + else + { + remoteSessions = localSession.getSessionProtocol().getRemoteSessions(this, false); + } + } + + return remoteSessions.toArray(new CDORemoteSession[remoteSessions.size()]); + } + + public CDORemoteSession[] getElements() + { + return getRemoteSessions(); + } + + public boolean isSubscribed() + { + synchronized (this) + { + return subscribed; + } + } + + public boolean isForceSubscription() + { + synchronized (this) + { + return forceSubscription; + } + } + + public void setForceSubscription(boolean forceSubscription) + { + IEvent[] events = null; + synchronized (this) + { + this.forceSubscription = forceSubscription; + if (forceSubscription) + { + if (!subscribed) + { + events = subscribe(); + } + } + else + { + if (!hasListeners()) + { + events = unsubscribe(); + } + } + } + + fireEvents(events); + } + + public Set<CDORemoteSession> sendMessage(CDORemoteSessionMessage message, CDORemoteSession... recipients) + { + return sendMessage(message, new ArrayIterator<CDORemoteSession>(recipients)); + } + + public Set<CDORemoteSession> sendMessage(CDORemoteSessionMessage message, Collection<CDORemoteSession> recipients) + { + return sendMessage(message, recipients.iterator()); + } + + private Set<CDORemoteSession> sendMessage(CDORemoteSessionMessage message, Iterator<CDORemoteSession> recipients) + { + List<CDORemoteSession> subscribed = new ArrayList<CDORemoteSession>(); + while (recipients.hasNext()) + { + CDORemoteSession recipient = recipients.next(); + if (recipient.isSubscribed()) + { + subscribed.add(recipient); + } + } + + if (subscribed.isEmpty()) + { + return Collections.emptySet(); + } + + Set<Integer> sessionIDs = localSession.getSessionProtocol().sendRemoteMessage(message, subscribed); + Set<CDORemoteSession> result = new HashSet<CDORemoteSession>(); + for (CDORemoteSession recipient : subscribed) + { + if (sessionIDs.contains(recipient.getSessionID())) + { + result.add(recipient); + } + } + + return result; + } + + public InternalCDORemoteSession createRemoteSession(int sessionID, String userID, boolean subscribed) + { + InternalCDORemoteSession remoteSession = new CDORemoteSessionImpl(this, sessionID, userID); + remoteSession.setSubscribed(subscribed); + return remoteSession; + } + + public void handleRemoteSessionOpened(int sessionID, String userID) + { + CDORemoteSession remoteSession = createRemoteSession(sessionID, userID, false); + synchronized (this) + { + remoteSessions.put(sessionID, remoteSession); + } + + fireElementAddedEvent(remoteSession); + } + + public void handleRemoteSessionClosed(int sessionID) + { + CDORemoteSession remoteSession = null; + synchronized (this) + { + remoteSession = remoteSessions.remove(sessionID); + } + + if (remoteSession != null) + { + fireElementRemovedEvent(remoteSession); + } + } + + public void handleRemoteSessionSubscribed(int sessionID, boolean subscribed) + { + IEvent event = null; + synchronized (this) + { + InternalCDORemoteSession remoteSession = (InternalCDORemoteSession)remoteSessions.get(sessionID); + if (remoteSession != null) + { + remoteSession.setSubscribed(subscribed); + event = new SubscriptionChangedEventImpl(remoteSession, subscribed); + } + } + + if (event != null) + { + fireEvent(event); + } + } + + public void handleRemoteSessionMessage(int sessionID, final CDORemoteSessionMessage message) + { + IEvent event = null; + synchronized (this) + { + final CDORemoteSessionManager source = this; + final InternalCDORemoteSession remoteSession = (InternalCDORemoteSession)remoteSessions.get(sessionID); + if (remoteSession != null) + { + event = new CDORemoteSessionEvent.MessageReceived() + { + public CDORemoteSessionManager getSource() + { + return source; + } + + public CDORemoteSession getRemoteSession() + { + return remoteSession; + } + + public CDORemoteSessionMessage getMessage() + { + return message; + } + }; + } + } + + if (event != null) + { + fireEvent(event); + } + } + + @Override + protected void firstListenerAdded() + { + IEvent[] events = null; + synchronized (this) + { + if (!subscribed) + { + events = subscribe(); + } + } + + fireEvents(events); + } + + @Override + protected void lastListenerRemoved() + { + IEvent[] events = null; + synchronized (this) + { + if (!forceSubscription) + { + events = unsubscribe(); + } + } + + fireEvents(events); + } + + /** + * Needs to be synchronized externally. + */ + private IEvent[] subscribe() + { + List<CDORemoteSession> result = localSession.getSessionProtocol().getRemoteSessions(this, true); + ContainerEvent<CDORemoteSession> event = new ContainerEvent<CDORemoteSession>(this); + for (CDORemoteSession remoteSession : result) + { + remoteSessions.put(remoteSession.getSessionID(), remoteSession); + event.addDelta(remoteSession, IContainerDelta.Kind.ADDED); + } + + subscribed = true; + IEvent[] events = { new LocalSubscriptionChangedEventImpl(true), event.isEmpty() ? null : event }; + return events; + } + + /** + * Needs to be synchronized externally. + */ + private IEvent[] unsubscribe() + { + localSession.getSessionProtocol().unsubscribeRemoteSessions(); + ContainerEvent<CDORemoteSession> event = new ContainerEvent<CDORemoteSession>(this); + for (CDORemoteSession remoteSession : remoteSessions.values()) + { + event.addDelta(remoteSession, IContainerDelta.Kind.REMOVED); + } + + remoteSessions.clear(); + subscribed = false; + IEvent[] events = { new LocalSubscriptionChangedEventImpl(false), event.isEmpty() ? null : event }; + return events; + } + + private void fireEvents(IEvent[] events) + { + if (events != null) + { + for (int i = 0; i < events.length; i++) + { + IEvent event = events[i]; + if (event != null) + { + fireEvent(event); + } + } + } + } + + /** + * @author Eike Stepper + */ + private final class LocalSubscriptionChangedEventImpl extends Event implements LocalSubscriptionChangedEvent + { + private static final long serialVersionUID = 1L; + + private boolean subscribed; + + public LocalSubscriptionChangedEventImpl(boolean subscribed) + { + super(CDORemoteSessionManagerImpl.this); + this.subscribed = subscribed; + } + + @Override + public CDORemoteSessionManager getSource() + { + return (CDORemoteSessionManager)super.getSource(); + } + + public boolean isSubscribed() + { + return subscribed; + } + } + + /** + * @author Eike Stepper + */ + private final class SubscriptionChangedEventImpl extends Event implements CDORemoteSessionEvent.SubscriptionChanged + { + private static final long serialVersionUID = 1L; + + private InternalCDORemoteSession remoteSession; + + private boolean subscribed; + + public SubscriptionChangedEventImpl(InternalCDORemoteSession remoteSession, boolean subscribed) + { + super(CDORemoteSessionManagerImpl.this); + this.remoteSession = remoteSession; + this.subscribed = subscribed; + } + + @Override + public CDORemoteSessionManager getSource() + { + return (CDORemoteSessionManager)super.getSource(); + } + + public CDORemoteSession getRemoteSession() + { + return remoteSession; + } + + public boolean isSubscribed() + { + return subscribed; + } + } +} diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/transaction/CDOSavepointImpl.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/transaction/CDOSavepointImpl.java index 315a5d2991..09bbba6f3e 100644 --- a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/transaction/CDOSavepointImpl.java +++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/transaction/CDOSavepointImpl.java @@ -1,449 +1,449 @@ -/*
- * Copyright (c) 2004 - 2012 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:
- * Simon McDuff - initial API and implementation
- * Eike Stepper - maintenance
- * Simon McDuff - bug 204890
- */
-package org.eclipse.emf.internal.cdo.transaction;
-
-import org.eclipse.emf.cdo.CDOObject;
-import org.eclipse.emf.cdo.common.branch.CDOBranchVersion;
-import org.eclipse.emf.cdo.common.commit.CDOChangeSetData;
-import org.eclipse.emf.cdo.common.id.CDOID;
-import org.eclipse.emf.cdo.common.id.CDOIDUtil;
-import org.eclipse.emf.cdo.common.revision.CDOIDAndVersion;
-import org.eclipse.emf.cdo.common.revision.CDORevision;
-import org.eclipse.emf.cdo.common.revision.CDORevisionKey;
-import org.eclipse.emf.cdo.common.revision.delta.CDOFeatureDelta;
-import org.eclipse.emf.cdo.common.revision.delta.CDORevisionDelta;
-import org.eclipse.emf.cdo.internal.common.commit.CDOChangeSetDataImpl;
-import org.eclipse.emf.cdo.internal.common.revision.delta.CDORevisionDeltaImpl;
-import org.eclipse.emf.cdo.spi.common.revision.InternalCDOFeatureDelta;
-
-import org.eclipse.net4j.util.collection.MultiMap;
-import org.eclipse.net4j.util.lifecycle.LifecycleUtil;
-
-import org.eclipse.emf.spi.cdo.CDOTransactionStrategy;
-import org.eclipse.emf.spi.cdo.InternalCDOSavepoint;
-import org.eclipse.emf.spi.cdo.InternalCDOTransaction;
-
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Map.Entry;
-import java.util.Set;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.concurrent.ConcurrentMap;
-
-/**
- * @author Simon McDuff
- * @since 2.0
- */
-public class CDOSavepointImpl extends CDOUserSavepointImpl implements InternalCDOSavepoint
-{
- private final InternalCDOTransaction transaction;
-
- private Map<CDOID, CDORevision> baseNewObjects = new HashMap<CDOID, CDORevision>();
-
- private Map<CDOID, CDOObject> newObjects = new HashMap<CDOID, CDOObject>();
-
- // Bug 283985 (Re-attachment)
- private Map<CDOID, CDOObject> reattachedObjects = new HashMap<CDOID, CDOObject>();
-
- private Map<CDOID, CDOObject> detachedObjects = new HashMap<CDOID, CDOObject>()
- {
- private static final long serialVersionUID = 1L;
-
- @Override
- public CDOObject put(CDOID key, CDOObject object)
- {
- synchronized (transaction)
- {
- baseNewObjects.remove(key);
- newObjects.remove(key);
- reattachedObjects.remove(key);
- dirtyObjects.remove(key);
- revisionDeltas.remove(key);
- return super.put(key, object);
- }
- }
- };
-
- private Map<CDOID, CDOObject> dirtyObjects = new HashMap<CDOID, CDOObject>();
-
- private ConcurrentMap<CDOID, CDORevisionDelta> revisionDeltas = new ConcurrentHashMap<CDOID, CDORevisionDelta>();
-
- private boolean wasDirty;
-
- public CDOSavepointImpl(InternalCDOTransaction transaction, InternalCDOSavepoint lastSavepoint)
- {
- super(transaction, lastSavepoint);
- this.transaction = transaction;
- wasDirty = transaction.isDirty();
- }
-
- @Override
- public InternalCDOTransaction getTransaction()
- {
- return (InternalCDOTransaction)super.getTransaction();
- }
-
- @Override
- public InternalCDOSavepoint getFirstSavePoint()
- {
- synchronized (transaction)
- {
- return (InternalCDOSavepoint)super.getFirstSavePoint();
- }
- }
-
- @Override
- public InternalCDOSavepoint getPreviousSavepoint()
- {
- synchronized (transaction)
- {
- return (InternalCDOSavepoint)super.getPreviousSavepoint();
- }
- }
-
- @Override
- public InternalCDOSavepoint getNextSavepoint()
- {
- synchronized (transaction)
- {
- return (InternalCDOSavepoint)super.getNextSavepoint();
- }
- }
-
- public void clear()
- {
- synchronized (transaction)
- {
- newObjects.clear();
- dirtyObjects.clear();
- revisionDeltas.clear();
- baseNewObjects.clear();
- detachedObjects.clear();
- reattachedObjects.clear();
- }
- }
-
- public boolean wasDirty()
- {
- return wasDirty;
- }
-
- public Map<CDOID, CDOObject> getNewObjects()
- {
- return newObjects;
- }
-
- public Map<CDOID, CDOObject> getDetachedObjects()
- {
- return detachedObjects;
- }
-
- // Bug 283985 (Re-attachment)
- public Map<CDOID, CDOObject> getReattachedObjects()
- {
- return reattachedObjects;
- }
-
- public Map<CDOID, CDOObject> getDirtyObjects()
- {
- return dirtyObjects;
- }
-
- @Deprecated
- public Set<CDOID> getSharedDetachedObjects()
- {
- throw new UnsupportedOperationException();
- }
-
- @Deprecated
- public void recalculateSharedDetachedObjects()
- {
- throw new UnsupportedOperationException();
- }
-
- public ConcurrentMap<CDOID, CDORevisionDelta> getRevisionDeltas()
- {
- return revisionDeltas;
- }
-
- public CDOChangeSetData getChangeSetData()
- {
- synchronized (transaction)
- {
- return createChangeSetData(newObjects, revisionDeltas, detachedObjects);
- }
- }
-
- public CDOChangeSetData getAllChangeSetData()
- {
- synchronized (transaction)
- {
- return createChangeSetData(getAllNewObjects(), getAllRevisionDeltas(), getAllDetachedObjects());
- }
- }
-
- private CDOChangeSetData createChangeSetData(Map<CDOID, CDOObject> newObjects,
- Map<CDOID, CDORevisionDelta> revisionDeltas, Map<CDOID, CDOObject> detachedObjects)
- {
- List<CDOIDAndVersion> newList = new ArrayList<CDOIDAndVersion>(newObjects.size());
- for (CDOObject object : newObjects.values())
- {
- newList.add(object.cdoRevision());
- }
-
- List<CDORevisionKey> changedList = new ArrayList<CDORevisionKey>(revisionDeltas.size());
- for (CDORevisionDelta delta : revisionDeltas.values())
- {
- changedList.add(delta);
- }
-
- List<CDOIDAndVersion> detachedList = new ArrayList<CDOIDAndVersion>(detachedObjects.size());
- for (CDOID id : detachedObjects.keySet())
- {
- detachedList.add(CDOIDUtil.createIDAndVersion(id, CDOBranchVersion.UNSPECIFIED_VERSION));
- }
-
- return new CDOChangeSetDataImpl(newList, changedList, detachedList);
- }
-
- public Map<CDOID, CDORevision> getBaseNewObjects()
- {
- return baseNewObjects;
- }
-
- /**
- * Return the list of new objects from this point.
- */
- public Map<CDOID, CDOObject> getAllDirtyObjects()
- {
- synchronized (transaction)
- {
- if (getPreviousSavepoint() == null)
- {
- return Collections.unmodifiableMap(getDirtyObjects());
- }
-
- MultiMap.ListBased<CDOID, CDOObject> dirtyObjects = new MultiMap.ListBased<CDOID, CDOObject>();
- for (InternalCDOSavepoint savepoint = this; savepoint != null; savepoint = savepoint.getPreviousSavepoint())
- {
- dirtyObjects.getDelegates().add(savepoint.getDirtyObjects());
- }
-
- return dirtyObjects;
- }
- }
-
- /**
- * Return the list of new objects from this point without objects that are removed.
- */
- public Map<CDOID, CDOObject> getAllNewObjects()
- {
- synchronized (transaction)
- {
- if (getPreviousSavepoint() == null)
- {
- return Collections.unmodifiableMap(getNewObjects());
- }
-
- Map<CDOID, CDOObject> newObjects = new HashMap<CDOID, CDOObject>();
- for (InternalCDOSavepoint savepoint = getFirstSavePoint(); savepoint != null; savepoint = savepoint
- .getNextSavepoint())
- {
- newObjects.putAll(savepoint.getNewObjects());
- for (CDOID removedID : savepoint.getDetachedObjects().keySet())
- {
- newObjects.remove(removedID);
- }
- }
-
- return newObjects;
- }
- }
-
- /**
- * @since 2.0
- */
- public Map<CDOID, CDORevision> getAllBaseNewObjects()
- {
- synchronized (transaction)
- {
- if (getPreviousSavepoint() == null)
- {
- return Collections.unmodifiableMap(getBaseNewObjects());
- }
-
- MultiMap.ListBased<CDOID, CDORevision> newObjects = new MultiMap.ListBased<CDOID, CDORevision>();
- for (InternalCDOSavepoint savepoint = this; savepoint != null; savepoint = savepoint.getPreviousSavepoint())
- {
- newObjects.getDelegates().add(savepoint.getBaseNewObjects());
- }
-
- return newObjects;
- }
- }
-
- /**
- * Return the list of all deltas without objects that are removed.
- */
- public Map<CDOID, CDORevisionDelta> getAllRevisionDeltas()
- {
- synchronized (transaction)
- {
- if (getPreviousSavepoint() == null)
- {
- return Collections.unmodifiableMap(getRevisionDeltas());
- }
-
- // We need to combined the result for all delta in different Savepoint
- Map<CDOID, CDORevisionDelta> allRevisionDeltas = new HashMap<CDOID, CDORevisionDelta>();
- for (InternalCDOSavepoint savepoint = getFirstSavePoint(); savepoint != null; savepoint = savepoint
- .getNextSavepoint())
- {
- for (CDORevisionDelta revisionDelta : savepoint.getRevisionDeltas().values())
- {
- CDOID id = revisionDelta.getID();
- if (!isNewObject(id))
- {
- CDORevisionDeltaImpl oldRevisionDelta = (CDORevisionDeltaImpl)allRevisionDeltas.get(id);
- if (oldRevisionDelta == null)
- {
- allRevisionDeltas.put(id, revisionDelta.copy());
- }
- else
- {
- for (CDOFeatureDelta delta : revisionDelta.getFeatureDeltas())
- {
- oldRevisionDelta.addFeatureDelta(((InternalCDOFeatureDelta)delta).copy());
- }
- }
- }
- }
-
- Set<CDOID> reattachedObjects = savepoint.getReattachedObjects().keySet();
- for (CDOID detachedID : savepoint.getDetachedObjects().keySet())
- {
- if (!reattachedObjects.contains(detachedID))
- {
- allRevisionDeltas.remove(detachedID);
- }
- }
- }
-
- return Collections.unmodifiableMap(allRevisionDeltas);
- }
- }
-
- public Map<CDOID, CDOObject> getAllDetachedObjects()
- {
- synchronized (transaction)
- {
- if (getPreviousSavepoint() == null && reattachedObjects.isEmpty())
- {
- return Collections.unmodifiableMap(getDetachedObjects());
- }
-
- Map<CDOID, CDOObject> detachedObjects = new HashMap<CDOID, CDOObject>();
- for (InternalCDOSavepoint savepoint = getFirstSavePoint(); savepoint != null; savepoint = savepoint
- .getNextSavepoint())
- {
- for (Entry<CDOID, CDOObject> entry : savepoint.getDetachedObjects().entrySet())
- {
- CDOID detachedID = entry.getKey();
- if (!isNewObject(detachedID))
- {
- CDOObject detachedObject = entry.getValue();
- detachedObjects.put(detachedID, detachedObject);
- }
- }
-
- for (CDOID reattachedID : savepoint.getReattachedObjects().keySet())
- {
- detachedObjects.remove(reattachedID);
- }
- }
-
- return detachedObjects;
- }
- }
-
- public boolean isNewObject(CDOID id)
- {
- if (id.isTemporary())
- {
- return true;
- }
-
- synchronized (transaction)
- {
- for (InternalCDOSavepoint savepoint = this; savepoint != null; savepoint = savepoint.getPreviousSavepoint())
- {
- if (savepoint.getNewObjects().containsKey(id))
- {
- return true;
- }
- }
- }
-
- return false;
- }
-
- // TODO Not sure if this new implementation is needed. The existing one passes all tests.
- // public boolean isNewObject(CDOID id)
- // {
- // if (id.isTemporary())
- // {
- // return true;
- // }
- //
- // boolean isNew = false;
- // boolean wasNew = false;
- // synchronized (transaction)
- // {
- // for (InternalCDOSavepoint savepoint = this; savepoint != null; savepoint = savepoint.getPreviousSavepoint())
- // {
- // if (savepoint.getNewObjects().containsKey(id))
- // {
- // isNew = true;
- // wasNew = true;
- // }
- //
- // if (isNew && savepoint.getDetachedObjects().containsKey(id))
- // {
- // isNew = false;
- // }
- //
- // if (!isNew && wasNew && savepoint.getReattachedObjects().containsKey(id))
- // {
- // isNew = true;
- // }
- // }
- // }
- //
- // return isNew;
- // }
-
- public void rollback()
- {
- synchronized (transaction)
- {
- InternalCDOTransaction transaction = getTransaction();
- LifecycleUtil.checkActive(transaction);
-
- CDOTransactionStrategy transactionStrategy = transaction.getTransactionStrategy();
- transactionStrategy.rollback(transaction, this);
- }
- }
-}
+/* + * Copyright (c) 2004 - 2012 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: + * Simon McDuff - initial API and implementation + * Eike Stepper - maintenance + * Simon McDuff - bug 204890 + */ +package org.eclipse.emf.internal.cdo.transaction; + +import org.eclipse.emf.cdo.CDOObject; +import org.eclipse.emf.cdo.common.branch.CDOBranchVersion; +import org.eclipse.emf.cdo.common.commit.CDOChangeSetData; +import org.eclipse.emf.cdo.common.id.CDOID; +import org.eclipse.emf.cdo.common.id.CDOIDUtil; +import org.eclipse.emf.cdo.common.revision.CDOIDAndVersion; +import org.eclipse.emf.cdo.common.revision.CDORevision; +import org.eclipse.emf.cdo.common.revision.CDORevisionKey; +import org.eclipse.emf.cdo.common.revision.delta.CDOFeatureDelta; +import org.eclipse.emf.cdo.common.revision.delta.CDORevisionDelta; +import org.eclipse.emf.cdo.internal.common.commit.CDOChangeSetDataImpl; +import org.eclipse.emf.cdo.internal.common.revision.delta.CDORevisionDeltaImpl; +import org.eclipse.emf.cdo.spi.common.revision.InternalCDOFeatureDelta; + +import org.eclipse.net4j.util.collection.MultiMap; +import org.eclipse.net4j.util.lifecycle.LifecycleUtil; + +import org.eclipse.emf.spi.cdo.CDOTransactionStrategy; +import org.eclipse.emf.spi.cdo.InternalCDOSavepoint; +import org.eclipse.emf.spi.cdo.InternalCDOTransaction; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; +import java.util.Set; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.ConcurrentMap; + +/** + * @author Simon McDuff + * @since 2.0 + */ +public class CDOSavepointImpl extends CDOUserSavepointImpl implements InternalCDOSavepoint +{ + private final InternalCDOTransaction transaction; + + private Map<CDOID, CDORevision> baseNewObjects = new HashMap<CDOID, CDORevision>(); + + private Map<CDOID, CDOObject> newObjects = new HashMap<CDOID, CDOObject>(); + + // Bug 283985 (Re-attachment) + private Map<CDOID, CDOObject> reattachedObjects = new HashMap<CDOID, CDOObject>(); + + private Map<CDOID, CDOObject> detachedObjects = new HashMap<CDOID, CDOObject>() + { + private static final long serialVersionUID = 1L; + + @Override + public CDOObject put(CDOID key, CDOObject object) + { + synchronized (transaction) + { + baseNewObjects.remove(key); + newObjects.remove(key); + reattachedObjects.remove(key); + dirtyObjects.remove(key); + revisionDeltas.remove(key); + return super.put(key, object); + } + } + }; + + private Map<CDOID, CDOObject> dirtyObjects = new HashMap<CDOID, CDOObject>(); + + private ConcurrentMap<CDOID, CDORevisionDelta> revisionDeltas = new ConcurrentHashMap<CDOID, CDORevisionDelta>(); + + private boolean wasDirty; + + public CDOSavepointImpl(InternalCDOTransaction transaction, InternalCDOSavepoint lastSavepoint) + { + super(transaction, lastSavepoint); + this.transaction = transaction; + wasDirty = transaction.isDirty(); + } + + @Override + public InternalCDOTransaction getTransaction() + { + return (InternalCDOTransaction)super.getTransaction(); + } + + @Override + public InternalCDOSavepoint getFirstSavePoint() + { + synchronized (transaction) + { + return (InternalCDOSavepoint)super.getFirstSavePoint(); + } + } + + @Override + public InternalCDOSavepoint getPreviousSavepoint() + { + synchronized (transaction) + { + return (InternalCDOSavepoint)super.getPreviousSavepoint(); + } + } + + @Override + public InternalCDOSavepoint getNextSavepoint() + { + synchronized (transaction) + { + return (InternalCDOSavepoint)super.getNextSavepoint(); + } + } + + public void clear() + { + synchronized (transaction) + { + newObjects.clear(); + dirtyObjects.clear(); + revisionDeltas.clear(); + baseNewObjects.clear(); + detachedObjects.clear(); + reattachedObjects.clear(); + } + } + + public boolean wasDirty() + { + return wasDirty; + } + + public Map<CDOID, CDOObject> getNewObjects() + { + return newObjects; + } + + public Map<CDOID, CDOObject> getDetachedObjects() + { + return detachedObjects; + } + + // Bug 283985 (Re-attachment) + public Map<CDOID, CDOObject> getReattachedObjects() + { + return reattachedObjects; + } + + public Map<CDOID, CDOObject> getDirtyObjects() + { + return dirtyObjects; + } + + @Deprecated + public Set<CDOID> getSharedDetachedObjects() + { + throw new UnsupportedOperationException(); + } + + @Deprecated + public void recalculateSharedDetachedObjects() + { + throw new UnsupportedOperationException(); + } + + public ConcurrentMap<CDOID, CDORevisionDelta> getRevisionDeltas() + { + return revisionDeltas; + } + + public CDOChangeSetData getChangeSetData() + { + synchronized (transaction) + { + return createChangeSetData(newObjects, revisionDeltas, detachedObjects); + } + } + + public CDOChangeSetData getAllChangeSetData() + { + synchronized (transaction) + { + return createChangeSetData(getAllNewObjects(), getAllRevisionDeltas(), getAllDetachedObjects()); + } + } + + private CDOChangeSetData createChangeSetData(Map<CDOID, CDOObject> newObjects, + Map<CDOID, CDORevisionDelta> revisionDeltas, Map<CDOID, CDOObject> detachedObjects) + { + List<CDOIDAndVersion> newList = new ArrayList<CDOIDAndVersion>(newObjects.size()); + for (CDOObject object : newObjects.values()) + { + newList.add(object.cdoRevision()); + } + + List<CDORevisionKey> changedList = new ArrayList<CDORevisionKey>(revisionDeltas.size()); + for (CDORevisionDelta delta : revisionDeltas.values()) + { + changedList.add(delta); + } + + List<CDOIDAndVersion> detachedList = new ArrayList<CDOIDAndVersion>(detachedObjects.size()); + for (CDOID id : detachedObjects.keySet()) + { + detachedList.add(CDOIDUtil.createIDAndVersion(id, CDOBranchVersion.UNSPECIFIED_VERSION)); + } + + return new CDOChangeSetDataImpl(newList, changedList, detachedList); + } + + public Map<CDOID, CDORevision> getBaseNewObjects() + { + return baseNewObjects; + } + + /** + * Return the list of new objects from this point. + */ + public Map<CDOID, CDOObject> getAllDirtyObjects() + { + synchronized (transaction) + { + if (getPreviousSavepoint() == null) + { + return Collections.unmodifiableMap(getDirtyObjects()); + } + + MultiMap.ListBased<CDOID, CDOObject> dirtyObjects = new MultiMap.ListBased<CDOID, CDOObject>(); + for (InternalCDOSavepoint savepoint = this; savepoint != null; savepoint = savepoint.getPreviousSavepoint()) + { + dirtyObjects.getDelegates().add(savepoint.getDirtyObjects()); + } + + return dirtyObjects; + } + } + + /** + * Return the list of new objects from this point without objects that are removed. + */ + public Map<CDOID, CDOObject> getAllNewObjects() + { + synchronized (transaction) + { + if (getPreviousSavepoint() == null) + { + return Collections.unmodifiableMap(getNewObjects()); + } + + Map<CDOID, CDOObject> newObjects = new HashMap<CDOID, CDOObject>(); + for (InternalCDOSavepoint savepoint = getFirstSavePoint(); savepoint != null; savepoint = savepoint + .getNextSavepoint()) + { + newObjects.putAll(savepoint.getNewObjects()); + for (CDOID removedID : savepoint.getDetachedObjects().keySet()) + { + newObjects.remove(removedID); + } + } + + return newObjects; + } + } + + /** + * @since 2.0 + */ + public Map<CDOID, CDORevision> getAllBaseNewObjects() + { + synchronized (transaction) + { + if (getPreviousSavepoint() == null) + { + return Collections.unmodifiableMap(getBaseNewObjects()); + } + + MultiMap.ListBased<CDOID, CDORevision> newObjects = new MultiMap.ListBased<CDOID, CDORevision>(); + for (InternalCDOSavepoint savepoint = this; savepoint != null; savepoint = savepoint.getPreviousSavepoint()) + { + newObjects.getDelegates().add(savepoint.getBaseNewObjects()); + } + + return newObjects; + } + } + + /** + * Return the list of all deltas without objects that are removed. + */ + public Map<CDOID, CDORevisionDelta> getAllRevisionDeltas() + { + synchronized (transaction) + { + if (getPreviousSavepoint() == null) + { + return Collections.unmodifiableMap(getRevisionDeltas()); + } + + // We need to combined the result for all delta in different Savepoint + Map<CDOID, CDORevisionDelta> allRevisionDeltas = new HashMap<CDOID, CDORevisionDelta>(); + for (InternalCDOSavepoint savepoint = getFirstSavePoint(); savepoint != null; savepoint = savepoint + .getNextSavepoint()) + { + for (CDORevisionDelta revisionDelta : savepoint.getRevisionDeltas().values()) + { + CDOID id = revisionDelta.getID(); + if (!isNewObject(id)) + { + CDORevisionDeltaImpl oldRevisionDelta = (CDORevisionDeltaImpl)allRevisionDeltas.get(id); + if (oldRevisionDelta == null) + { + allRevisionDeltas.put(id, revisionDelta.copy()); + } + else + { + for (CDOFeatureDelta delta : revisionDelta.getFeatureDeltas()) + { + oldRevisionDelta.addFeatureDelta(((InternalCDOFeatureDelta)delta).copy()); + } + } + } + } + + Set<CDOID> reattachedObjects = savepoint.getReattachedObjects().keySet(); + for (CDOID detachedID : savepoint.getDetachedObjects().keySet()) + { + if (!reattachedObjects.contains(detachedID)) + { + allRevisionDeltas.remove(detachedID); + } + } + } + + return Collections.unmodifiableMap(allRevisionDeltas); + } + } + + public Map<CDOID, CDOObject> getAllDetachedObjects() + { + synchronized (transaction) + { + if (getPreviousSavepoint() == null && reattachedObjects.isEmpty()) + { + return Collections.unmodifiableMap(getDetachedObjects()); + } + + Map<CDOID, CDOObject> detachedObjects = new HashMap<CDOID, CDOObject>(); + for (InternalCDOSavepoint savepoint = getFirstSavePoint(); savepoint != null; savepoint = savepoint + .getNextSavepoint()) + { + for (Entry<CDOID, CDOObject> entry : savepoint.getDetachedObjects().entrySet()) + { + CDOID detachedID = entry.getKey(); + if (!isNewObject(detachedID)) + { + CDOObject detachedObject = entry.getValue(); + detachedObjects.put(detachedID, detachedObject); + } + } + + for (CDOID reattachedID : savepoint.getReattachedObjects().keySet()) + { + detachedObjects.remove(reattachedID); + } + } + + return detachedObjects; + } + } + + public boolean isNewObject(CDOID id) + { + if (id.isTemporary()) + { + return true; + } + + synchronized (transaction) + { + for (InternalCDOSavepoint savepoint = this; savepoint != null; savepoint = savepoint.getPreviousSavepoint()) + { + if (savepoint.getNewObjects().containsKey(id)) + { + return true; + } + } + } + + return false; + } + + // TODO Not sure if this new implementation is needed. The existing one passes all tests. + // public boolean isNewObject(CDOID id) + // { + // if (id.isTemporary()) + // { + // return true; + // } + // + // boolean isNew = false; + // boolean wasNew = false; + // synchronized (transaction) + // { + // for (InternalCDOSavepoint savepoint = this; savepoint != null; savepoint = savepoint.getPreviousSavepoint()) + // { + // if (savepoint.getNewObjects().containsKey(id)) + // { + // isNew = true; + // wasNew = true; + // } + // + // if (isNew && savepoint.getDetachedObjects().containsKey(id)) + // { + // isNew = false; + // } + // + // if (!isNew && wasNew && savepoint.getReattachedObjects().containsKey(id)) + // { + // isNew = true; + // } + // } + // } + // + // return isNew; + // } + + public void rollback() + { + synchronized (transaction) + { + InternalCDOTransaction transaction = getTransaction(); + LifecycleUtil.checkActive(transaction); + + CDOTransactionStrategy transactionStrategy = transaction.getTransactionStrategy(); + transactionStrategy.rollback(transaction, this); + } + } +} diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/transaction/CDOSingleTransactionStrategyImpl.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/transaction/CDOSingleTransactionStrategyImpl.java index 8d402ceab9..7f9227ef96 100644 --- a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/transaction/CDOSingleTransactionStrategyImpl.java +++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/transaction/CDOSingleTransactionStrategyImpl.java @@ -1,118 +1,118 @@ -/*
- * Copyright (c) 2004 - 2012 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:
- * Simon McDuff - initial API and implementation
- */
-package org.eclipse.emf.internal.cdo.transaction;
-
-import org.eclipse.emf.cdo.CDOObjectReference;
-import org.eclipse.emf.cdo.common.branch.CDOBranch;
-import org.eclipse.emf.cdo.common.commit.CDOCommitData;
-import org.eclipse.emf.cdo.common.commit.CDOCommitInfo;
-import org.eclipse.emf.cdo.spi.common.commit.InternalCDOCommitInfoManager;
-import org.eclipse.emf.cdo.util.CommitException;
-import org.eclipse.emf.cdo.util.ReferentialIntegrityException;
-
-import org.eclipse.emf.internal.cdo.bundle.OM;
-
-import org.eclipse.net4j.util.om.monitor.EclipseMonitor;
-import org.eclipse.net4j.util.om.monitor.OMMonitor;
-import org.eclipse.net4j.util.om.trace.ContextTracer;
-
-import org.eclipse.emf.spi.cdo.CDOSessionProtocol;
-import org.eclipse.emf.spi.cdo.CDOSessionProtocol.CommitTransactionResult;
-import org.eclipse.emf.spi.cdo.CDOTransactionStrategy;
-import org.eclipse.emf.spi.cdo.InternalCDOSavepoint;
-import org.eclipse.emf.spi.cdo.InternalCDOSession;
-import org.eclipse.emf.spi.cdo.InternalCDOTransaction;
-import org.eclipse.emf.spi.cdo.InternalCDOTransaction.InternalCDOCommitContext;
-import org.eclipse.emf.spi.cdo.InternalCDOUserSavepoint;
-
-import org.eclipse.core.runtime.IProgressMonitor;
-
-import java.util.List;
-
-/**
- * @author Simon McDuff
- * @since 2.0
- */
-public class CDOSingleTransactionStrategyImpl implements CDOTransactionStrategy
-{
- public static final CDOSingleTransactionStrategyImpl INSTANCE = new CDOSingleTransactionStrategyImpl();
-
- private static final ContextTracer TRACER = new ContextTracer(OM.DEBUG_TRANSACTION,
- CDOSingleTransactionStrategyImpl.class);
-
- public CDOSingleTransactionStrategyImpl()
- {
- }
-
- public CDOCommitInfo commit(InternalCDOTransaction transaction, IProgressMonitor progressMonitor) throws Exception
- {
- String comment = transaction.getCommitComment();
- InternalCDOCommitContext commitContext = transaction.createCommitContext();
- if (TRACER.isEnabled())
- {
- TRACER.format("CDOCommitContext.preCommit"); //$NON-NLS-1$
- }
-
- commitContext.preCommit();
-
- CDOCommitData commitData = commitContext.getCommitData();
- InternalCDOSession session = transaction.getSession();
- CommitTransactionResult result = null;
-
- OMMonitor monitor = new EclipseMonitor(progressMonitor);
- CDOSessionProtocol sessionProtocol = session.getSessionProtocol();
- result = sessionProtocol.commitTransaction(commitContext, monitor);
-
- commitContext.postCommit(result);
-
- String rollbackMessage = result.getRollbackMessage();
- if (rollbackMessage != null)
- {
- List<CDOObjectReference> xRefs = result.getXRefs();
- if (xRefs != null)
- {
- throw new ReferentialIntegrityException(rollbackMessage, xRefs);
- }
-
- throw new CommitException(rollbackMessage);
- }
-
- transaction.setCommitComment(null);
-
- long previousTimeStamp = result.getPreviousTimeStamp();
- CDOBranch branch = transaction.getBranch();
- long timeStamp = result.getTimeStamp();
- String userID = session.getUserID();
-
- InternalCDOCommitInfoManager commitInfoManager = session.getCommitInfoManager();
- return commitInfoManager.createCommitInfo(branch, timeStamp, previousTimeStamp, userID, comment, commitData);
- }
-
- public void rollback(InternalCDOTransaction transaction, InternalCDOUserSavepoint savepoint)
- {
- transaction.handleRollback((InternalCDOSavepoint)savepoint);
- }
-
- public InternalCDOUserSavepoint setSavepoint(InternalCDOTransaction transaction)
- {
- return transaction.handleSetSavepoint();
- }
-
- public void setTarget(InternalCDOTransaction transaction)
- {
- // Do nothing
- }
-
- public void unsetTarget(InternalCDOTransaction transaction)
- {
- // Do nothing
- }
-}
+/* + * Copyright (c) 2004 - 2012 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: + * Simon McDuff - initial API and implementation + */ +package org.eclipse.emf.internal.cdo.transaction; + +import org.eclipse.emf.cdo.CDOObjectReference; +import org.eclipse.emf.cdo.common.branch.CDOBranch; +import org.eclipse.emf.cdo.common.commit.CDOCommitData; +import org.eclipse.emf.cdo.common.commit.CDOCommitInfo; +import org.eclipse.emf.cdo.spi.common.commit.InternalCDOCommitInfoManager; +import org.eclipse.emf.cdo.util.CommitException; +import org.eclipse.emf.cdo.util.ReferentialIntegrityException; + +import org.eclipse.emf.internal.cdo.bundle.OM; + +import org.eclipse.net4j.util.om.monitor.EclipseMonitor; +import org.eclipse.net4j.util.om.monitor.OMMonitor; +import org.eclipse.net4j.util.om.trace.ContextTracer; + +import org.eclipse.emf.spi.cdo.CDOSessionProtocol; +import org.eclipse.emf.spi.cdo.CDOSessionProtocol.CommitTransactionResult; +import org.eclipse.emf.spi.cdo.CDOTransactionStrategy; +import org.eclipse.emf.spi.cdo.InternalCDOSavepoint; +import org.eclipse.emf.spi.cdo.InternalCDOSession; +import org.eclipse.emf.spi.cdo.InternalCDOTransaction; +import org.eclipse.emf.spi.cdo.InternalCDOTransaction.InternalCDOCommitContext; +import org.eclipse.emf.spi.cdo.InternalCDOUserSavepoint; + +import org.eclipse.core.runtime.IProgressMonitor; + +import java.util.List; + +/** + * @author Simon McDuff + * @since 2.0 + */ +public class CDOSingleTransactionStrategyImpl implements CDOTransactionStrategy +{ + public static final CDOSingleTransactionStrategyImpl INSTANCE = new CDOSingleTransactionStrategyImpl(); + + private static final ContextTracer TRACER = new ContextTracer(OM.DEBUG_TRANSACTION, + CDOSingleTransactionStrategyImpl.class); + + public CDOSingleTransactionStrategyImpl() + { + } + + public CDOCommitInfo commit(InternalCDOTransaction transaction, IProgressMonitor progressMonitor) throws Exception + { + String comment = transaction.getCommitComment(); + InternalCDOCommitContext commitContext = transaction.createCommitContext(); + if (TRACER.isEnabled()) + { + TRACER.format("CDOCommitContext.preCommit"); //$NON-NLS-1$ + } + + commitContext.preCommit(); + + CDOCommitData commitData = commitContext.getCommitData(); + InternalCDOSession session = transaction.getSession(); + CommitTransactionResult result = null; + + OMMonitor monitor = new EclipseMonitor(progressMonitor); + CDOSessionProtocol sessionProtocol = session.getSessionProtocol(); + result = sessionProtocol.commitTransaction(commitContext, monitor); + + commitContext.postCommit(result); + + String rollbackMessage = result.getRollbackMessage(); + if (rollbackMessage != null) + { + List<CDOObjectReference> xRefs = result.getXRefs(); + if (xRefs != null) + { + throw new ReferentialIntegrityException(rollbackMessage, xRefs); + } + + throw new CommitException(rollbackMessage); + } + + transaction.setCommitComment(null); + + long previousTimeStamp = result.getPreviousTimeStamp(); + CDOBranch branch = transaction.getBranch(); + long timeStamp = result.getTimeStamp(); + String userID = session.getUserID(); + + InternalCDOCommitInfoManager commitInfoManager = session.getCommitInfoManager(); + return commitInfoManager.createCommitInfo(branch, timeStamp, previousTimeStamp, userID, comment, commitData); + } + + public void rollback(InternalCDOTransaction transaction, InternalCDOUserSavepoint savepoint) + { + transaction.handleRollback((InternalCDOSavepoint)savepoint); + } + + public InternalCDOUserSavepoint setSavepoint(InternalCDOTransaction transaction) + { + return transaction.handleSetSavepoint(); + } + + public void setTarget(InternalCDOTransaction transaction) + { + // Do nothing + } + + public void unsetTarget(InternalCDOTransaction transaction) + { + // Do nothing + } +} diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/transaction/CDOUserSavepointImpl.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/transaction/CDOUserSavepointImpl.java index 7a6196d03c..96406ebbae 100644 --- a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/transaction/CDOUserSavepointImpl.java +++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/transaction/CDOUserSavepointImpl.java @@ -1,103 +1,103 @@ -/*
- * Copyright (c) 2004 - 2012 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:
- * Simon McDuff - initial API and implementation
- * Eike Stepper - maintenance
- */
-package org.eclipse.emf.internal.cdo.transaction;
-
-import org.eclipse.emf.cdo.transaction.CDOUserSavepoint;
-
-import org.eclipse.emf.spi.cdo.InternalCDOUserSavepoint;
-import org.eclipse.emf.spi.cdo.InternalCDOUserTransaction;
-
-/**
- * @author Simon McDuff
- * @since 2.0
- */
-public abstract class CDOUserSavepointImpl implements InternalCDOUserSavepoint
-{
- private InternalCDOUserTransaction transaction;
-
- private InternalCDOUserSavepoint previousSavepoint;
-
- private InternalCDOUserSavepoint nextSavepoint;
-
- public CDOUserSavepointImpl(InternalCDOUserTransaction transaction, InternalCDOUserSavepoint lastSavepoint)
- {
- this.transaction = transaction;
- previousSavepoint = lastSavepoint;
- if (previousSavepoint != null)
- {
- previousSavepoint.setNextSavepoint(this);
- }
- }
-
- public InternalCDOUserTransaction getTransaction()
- {
- return transaction;
- }
-
- public InternalCDOUserSavepoint getPreviousSavepoint()
- {
- return previousSavepoint;
- }
-
- public void setPreviousSavepoint(InternalCDOUserSavepoint previousSavepoint)
- {
- this.previousSavepoint = previousSavepoint;
- }
-
- public InternalCDOUserSavepoint getNextSavepoint()
- {
- return nextSavepoint;
- }
-
- public void setNextSavepoint(InternalCDOUserSavepoint nextSavepoint)
- {
- this.nextSavepoint = nextSavepoint;
- }
-
- public InternalCDOUserSavepoint getFirstSavePoint()
- {
- return previousSavepoint != null ? previousSavepoint.getFirstSavePoint() : this;
- }
-
- public boolean isValid()
- {
- InternalCDOUserSavepoint lastSavepoint = getTransaction().getLastSavepoint();
- for (InternalCDOUserSavepoint savepoint = lastSavepoint; savepoint != null; savepoint = savepoint
- .getPreviousSavepoint())
- {
- if (savepoint == this)
- {
- return true;
- }
- }
-
- return false;
- }
-
- public int getNumber()
- {
- int number = 1;
- CDOUserSavepoint savepoint = this;
- while ((savepoint = savepoint.getPreviousSavepoint()) != null)
- {
- ++number;
- }
-
- return number;
- }
-
- @Override
- public String toString()
- {
- return "Savepoint #" + getNumber();
- }
-}
+/* + * Copyright (c) 2004 - 2012 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: + * Simon McDuff - initial API and implementation + * Eike Stepper - maintenance + */ +package org.eclipse.emf.internal.cdo.transaction; + +import org.eclipse.emf.cdo.transaction.CDOUserSavepoint; + +import org.eclipse.emf.spi.cdo.InternalCDOUserSavepoint; +import org.eclipse.emf.spi.cdo.InternalCDOUserTransaction; + +/** + * @author Simon McDuff + * @since 2.0 + */ +public abstract class CDOUserSavepointImpl implements InternalCDOUserSavepoint +{ + private InternalCDOUserTransaction transaction; + + private InternalCDOUserSavepoint previousSavepoint; + + private InternalCDOUserSavepoint nextSavepoint; + + public CDOUserSavepointImpl(InternalCDOUserTransaction transaction, InternalCDOUserSavepoint lastSavepoint) + { + this.transaction = transaction; + previousSavepoint = lastSavepoint; + if (previousSavepoint != null) + { + previousSavepoint.setNextSavepoint(this); + } + } + + public InternalCDOUserTransaction getTransaction() + { + return transaction; + } + + public InternalCDOUserSavepoint getPreviousSavepoint() + { + return previousSavepoint; + } + + public void setPreviousSavepoint(InternalCDOUserSavepoint previousSavepoint) + { + this.previousSavepoint = previousSavepoint; + } + + public InternalCDOUserSavepoint getNextSavepoint() + { + return nextSavepoint; + } + + public void setNextSavepoint(InternalCDOUserSavepoint nextSavepoint) + { + this.nextSavepoint = nextSavepoint; + } + + public InternalCDOUserSavepoint getFirstSavePoint() + { + return previousSavepoint != null ? previousSavepoint.getFirstSavePoint() : this; + } + + public boolean isValid() + { + InternalCDOUserSavepoint lastSavepoint = getTransaction().getLastSavepoint(); + for (InternalCDOUserSavepoint savepoint = lastSavepoint; savepoint != null; savepoint = savepoint + .getPreviousSavepoint()) + { + if (savepoint == this) + { + return true; + } + } + + return false; + } + + public int getNumber() + { + int number = 1; + CDOUserSavepoint savepoint = this; + while ((savepoint = savepoint.getPreviousSavepoint()) != null) + { + ++number; + } + + return number; + } + + @Override + public String toString() + { + return "Savepoint #" + getNumber(); + } +} diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/transaction/CDOXACommitContextImpl.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/transaction/CDOXACommitContextImpl.java index c8306bfd67..3edc469f75 100644 --- a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/transaction/CDOXACommitContextImpl.java +++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/transaction/CDOXACommitContextImpl.java @@ -1,250 +1,250 @@ -/*
- * Copyright (c) 2004 - 2012 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:
- * Simon McDuff - initial API and implementation
- */
-package org.eclipse.emf.internal.cdo.transaction;
-
-import org.eclipse.emf.cdo.CDOObject;
-import org.eclipse.emf.cdo.common.branch.CDOBranch;
-import org.eclipse.emf.cdo.common.commit.CDOCommitData;
-import org.eclipse.emf.cdo.common.id.CDOID;
-import org.eclipse.emf.cdo.common.lob.CDOLob;
-import org.eclipse.emf.cdo.common.lock.CDOLockState;
-import org.eclipse.emf.cdo.common.model.CDOPackageUnit;
-import org.eclipse.emf.cdo.common.revision.delta.CDORevisionDelta;
-import org.eclipse.emf.cdo.internal.common.id.CDOIDTempObjectExternalImpl;
-import org.eclipse.emf.cdo.spi.common.revision.CDOReferenceAdjuster;
-import org.eclipse.emf.cdo.util.CDOUtil;
-
-import org.eclipse.emf.internal.cdo.messages.Messages;
-
-import org.eclipse.net4j.util.ImplementationError;
-
-import org.eclipse.emf.ecore.EStructuralFeature;
-import org.eclipse.emf.ecore.InternalEObject;
-import org.eclipse.emf.spi.cdo.CDOSessionProtocol.CommitTransactionResult;
-import org.eclipse.emf.spi.cdo.InternalCDOObject;
-import org.eclipse.emf.spi.cdo.InternalCDOTransaction;
-import org.eclipse.emf.spi.cdo.InternalCDOTransaction.InternalCDOCommitContext;
-import org.eclipse.emf.spi.cdo.InternalCDOXATransaction;
-import org.eclipse.emf.spi.cdo.InternalCDOXATransaction.InternalCDOXACommitContext;
-
-import org.eclipse.core.runtime.IProgressMonitor;
-
-import java.text.MessageFormat;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-/**
- * @author Simon McDuff
- * @since 2.0
- */
-public class CDOXACommitContextImpl implements InternalCDOXACommitContext
-{
- private InternalCDOXATransaction transactionManager;
-
- private IProgressMonitor progressMonitor;
-
- private CDOXAState state;
-
- private CommitTransactionResult result;
-
- private InternalCDOCommitContext delegateCommitContext;
-
- private Map<CDOIDTempObjectExternalImpl, InternalCDOTransaction> requestedIDs = new HashMap<CDOIDTempObjectExternalImpl, InternalCDOTransaction>();
-
- private Map<InternalCDOObject, CDOIDTempObjectExternalImpl> objectToID = new HashMap<InternalCDOObject, CDOIDTempObjectExternalImpl>();
-
- public CDOXACommitContextImpl(InternalCDOXATransaction manager, InternalCDOCommitContext commitContext)
- {
- transactionManager = manager;
- delegateCommitContext = commitContext;
- }
-
- public InternalCDOXATransaction getTransactionManager()
- {
- return transactionManager;
- }
-
- public void setProgressMonitor(IProgressMonitor progressMonitor)
- {
- this.progressMonitor = progressMonitor;
- }
-
- public CDOXAState getState()
- {
- return state;
- }
-
- public void setState(CDOXAState state)
- {
- this.state = state;
- }
-
- public CommitTransactionResult getResult()
- {
- return result;
- }
-
- public void setResult(CommitTransactionResult result)
- {
- this.result = result;
- }
-
- public int getViewID()
- {
- return delegateCommitContext.getViewID();
- }
-
- public String getUserID()
- {
- return delegateCommitContext.getUserID();
- }
-
- public CDOBranch getBranch()
- {
- return delegateCommitContext.getBranch();
- }
-
- public InternalCDOTransaction getTransaction()
- {
- return delegateCommitContext.getTransaction();
- }
-
- public boolean isAutoReleaseLocks()
- {
- return delegateCommitContext.isAutoReleaseLocks();
- }
-
- public boolean isPartialCommit()
- {
- return delegateCommitContext.isPartialCommit();
- }
-
- public CDOCommitData getCommitData()
- {
- return delegateCommitContext.getCommitData();
- }
-
- public String getCommitComment()
- {
- return delegateCommitContext.getCommitComment();
- }
-
- public Map<CDOIDTempObjectExternalImpl, InternalCDOTransaction> getRequestedIDs()
- {
- return requestedIDs;
- }
-
- public Map<CDOID, CDOObject> getDirtyObjects()
- {
- return delegateCommitContext.getDirtyObjects();
- }
-
- public Map<CDOID, CDOObject> getNewObjects()
- {
- return delegateCommitContext.getNewObjects();
- }
-
- public List<CDOPackageUnit> getNewPackageUnits()
- {
- return delegateCommitContext.getNewPackageUnits();
- }
-
- public Collection<CDOLockState> getLocksOnNewObjects()
- {
- return delegateCommitContext.getLocksOnNewObjects();
- }
-
- public Map<CDOID, CDOObject> getDetachedObjects()
- {
- return delegateCommitContext.getDetachedObjects();
- }
-
- public Map<CDOID, CDORevisionDelta> getRevisionDeltas()
- {
- return delegateCommitContext.getRevisionDeltas();
- }
-
- public Collection<CDOLob<?>> getLobs()
- {
- return delegateCommitContext.getLobs();
- }
-
- public Object call() throws Exception
- {
- state.handle(this, progressMonitor);
- return true;
- }
-
- public CDOID provideCDOID(Object idOrObject)
- {
- CDOID id = getTransaction().provideCDOID(idOrObject);
- if (id instanceof CDOIDTempObjectExternalImpl)
- {
- if (idOrObject instanceof InternalEObject)
- {
- CDOIDTempObjectExternalImpl proxyTemp = (CDOIDTempObjectExternalImpl)id;
- if (!requestedIDs.containsKey(proxyTemp))
- {
- InternalCDOObject cdoObject = (InternalCDOObject)CDOUtil.getCDOObject((InternalEObject)idOrObject);
- InternalCDOTransaction cdoTransaction = (InternalCDOTransaction)cdoObject.cdoView();
- getTransactionManager().add(cdoTransaction, proxyTemp);
- requestedIDs.put(proxyTemp, cdoTransaction);
- objectToID.put(cdoObject, proxyTemp);
- }
- }
- else
- {
- throw new ImplementationError(MessageFormat.format(Messages.getString("CDOXACommitContextImpl.0"), idOrObject)); //$NON-NLS-1$
- }
- }
-
- return id;
- }
-
- public void preCommit()
- {
- delegateCommitContext.preCommit();
- }
-
- public void postCommit(CommitTransactionResult result)
- {
- if (result != null)
- {
- if (result.getRollbackMessage() != null)
- {
- final CDOReferenceAdjuster defaultReferenceAdjuster = result.getReferenceAdjuster();
- result.setReferenceAdjuster(new CDOReferenceAdjuster()
- {
- public Object adjustReference(Object id, EStructuralFeature feature, int index)
- {
- CDOIDTempObjectExternalImpl externalID = objectToID.get(id);
- if (externalID != null)
- {
- id = externalID;
- }
-
- return defaultReferenceAdjuster.adjustReference(id, feature, index);
- }
- });
- }
-
- delegateCommitContext.postCommit(result);
- }
- }
-
- @Override
- public String toString()
- {
- return MessageFormat.format("CDOXACommitContext[{0}, {1}]", transactionManager, state);
- }
-}
+/* + * Copyright (c) 2004 - 2012 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: + * Simon McDuff - initial API and implementation + */ +package org.eclipse.emf.internal.cdo.transaction; + +import org.eclipse.emf.cdo.CDOObject; +import org.eclipse.emf.cdo.common.branch.CDOBranch; +import org.eclipse.emf.cdo.common.commit.CDOCommitData; +import org.eclipse.emf.cdo.common.id.CDOID; +import org.eclipse.emf.cdo.common.lob.CDOLob; +import org.eclipse.emf.cdo.common.lock.CDOLockState; +import org.eclipse.emf.cdo.common.model.CDOPackageUnit; +import org.eclipse.emf.cdo.common.revision.delta.CDORevisionDelta; +import org.eclipse.emf.cdo.internal.common.id.CDOIDTempObjectExternalImpl; +import org.eclipse.emf.cdo.spi.common.revision.CDOReferenceAdjuster; +import org.eclipse.emf.cdo.util.CDOUtil; + +import org.eclipse.emf.internal.cdo.messages.Messages; + +import org.eclipse.net4j.util.ImplementationError; + +import org.eclipse.emf.ecore.EStructuralFeature; +import org.eclipse.emf.ecore.InternalEObject; +import org.eclipse.emf.spi.cdo.CDOSessionProtocol.CommitTransactionResult; +import org.eclipse.emf.spi.cdo.InternalCDOObject; +import org.eclipse.emf.spi.cdo.InternalCDOTransaction; +import org.eclipse.emf.spi.cdo.InternalCDOTransaction.InternalCDOCommitContext; +import org.eclipse.emf.spi.cdo.InternalCDOXATransaction; +import org.eclipse.emf.spi.cdo.InternalCDOXATransaction.InternalCDOXACommitContext; + +import org.eclipse.core.runtime.IProgressMonitor; + +import java.text.MessageFormat; +import java.util.Collection; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +/** + * @author Simon McDuff + * @since 2.0 + */ +public class CDOXACommitContextImpl implements InternalCDOXACommitContext +{ + private InternalCDOXATransaction transactionManager; + + private IProgressMonitor progressMonitor; + + private CDOXAState state; + + private CommitTransactionResult result; + + private InternalCDOCommitContext delegateCommitContext; + + private Map<CDOIDTempObjectExternalImpl, InternalCDOTransaction> requestedIDs = new HashMap<CDOIDTempObjectExternalImpl, InternalCDOTransaction>(); + + private Map<InternalCDOObject, CDOIDTempObjectExternalImpl> objectToID = new HashMap<InternalCDOObject, CDOIDTempObjectExternalImpl>(); + + public CDOXACommitContextImpl(InternalCDOXATransaction manager, InternalCDOCommitContext commitContext) + { + transactionManager = manager; + delegateCommitContext = commitContext; + } + + public InternalCDOXATransaction getTransactionManager() + { + return transactionManager; + } + + public void setProgressMonitor(IProgressMonitor progressMonitor) + { + this.progressMonitor = progressMonitor; + } + + public CDOXAState getState() + { + return state; + } + + public void setState(CDOXAState state) + { + this.state = state; + } + + public CommitTransactionResult getResult() + { + return result; + } + + public void setResult(CommitTransactionResult result) + { + this.result = result; + } + + public int getViewID() + { + return delegateCommitContext.getViewID(); + } + + public String getUserID() + { + return delegateCommitContext.getUserID(); + } + + public CDOBranch getBranch() + { + return delegateCommitContext.getBranch(); + } + + public InternalCDOTransaction getTransaction() + { + return delegateCommitContext.getTransaction(); + } + + public boolean isAutoReleaseLocks() + { + return delegateCommitContext.isAutoReleaseLocks(); + } + + public boolean isPartialCommit() + { + return delegateCommitContext.isPartialCommit(); + } + + public CDOCommitData getCommitData() + { + return delegateCommitContext.getCommitData(); + } + + public String getCommitComment() + { + return delegateCommitContext.getCommitComment(); + } + + public Map<CDOIDTempObjectExternalImpl, InternalCDOTransaction> getRequestedIDs() + { + return requestedIDs; + } + + public Map<CDOID, CDOObject> getDirtyObjects() + { + return delegateCommitContext.getDirtyObjects(); + } + + public Map<CDOID, CDOObject> getNewObjects() + { + return delegateCommitContext.getNewObjects(); + } + + public List<CDOPackageUnit> getNewPackageUnits() + { + return delegateCommitContext.getNewPackageUnits(); + } + + public Collection<CDOLockState> getLocksOnNewObjects() + { + return delegateCommitContext.getLocksOnNewObjects(); + } + + public Map<CDOID, CDOObject> getDetachedObjects() + { + return delegateCommitContext.getDetachedObjects(); + } + + public Map<CDOID, CDORevisionDelta> getRevisionDeltas() + { + return delegateCommitContext.getRevisionDeltas(); + } + + public Collection<CDOLob<?>> getLobs() + { + return delegateCommitContext.getLobs(); + } + + public Object call() throws Exception + { + state.handle(this, progressMonitor); + return true; + } + + public CDOID provideCDOID(Object idOrObject) + { + CDOID id = getTransaction().provideCDOID(idOrObject); + if (id instanceof CDOIDTempObjectExternalImpl) + { + if (idOrObject instanceof InternalEObject) + { + CDOIDTempObjectExternalImpl proxyTemp = (CDOIDTempObjectExternalImpl)id; + if (!requestedIDs.containsKey(proxyTemp)) + { + InternalCDOObject cdoObject = (InternalCDOObject)CDOUtil.getCDOObject((InternalEObject)idOrObject); + InternalCDOTransaction cdoTransaction = (InternalCDOTransaction)cdoObject.cdoView(); + getTransactionManager().add(cdoTransaction, proxyTemp); + requestedIDs.put(proxyTemp, cdoTransaction); + objectToID.put(cdoObject, proxyTemp); + } + } + else + { + throw new ImplementationError(MessageFormat.format(Messages.getString("CDOXACommitContextImpl.0"), idOrObject)); //$NON-NLS-1$ + } + } + + return id; + } + + public void preCommit() + { + delegateCommitContext.preCommit(); + } + + public void postCommit(CommitTransactionResult result) + { + if (result != null) + { + if (result.getRollbackMessage() != null) + { + final CDOReferenceAdjuster defaultReferenceAdjuster = result.getReferenceAdjuster(); + result.setReferenceAdjuster(new CDOReferenceAdjuster() + { + public Object adjustReference(Object id, EStructuralFeature feature, int index) + { + CDOIDTempObjectExternalImpl externalID = objectToID.get(id); + if (externalID != null) + { + id = externalID; + } + + return defaultReferenceAdjuster.adjustReference(id, feature, index); + } + }); + } + + delegateCommitContext.postCommit(result); + } + } + + @Override + public String toString() + { + return MessageFormat.format("CDOXACommitContext[{0}, {1}]", transactionManager, state); + } +} diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/transaction/CDOXASavepointImpl.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/transaction/CDOXASavepointImpl.java index c12e6d54e1..a1c6d192dc 100644 --- a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/transaction/CDOXASavepointImpl.java +++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/transaction/CDOXASavepointImpl.java @@ -1,71 +1,71 @@ -/*
- * Copyright (c) 2004 - 2012 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:
- * Simon McDuff - initial API and implementation
- */
-package org.eclipse.emf.internal.cdo.transaction;
-
-import org.eclipse.emf.cdo.transaction.CDOSavepoint;
-
-import org.eclipse.emf.spi.cdo.InternalCDOXASavepoint;
-import org.eclipse.emf.spi.cdo.InternalCDOXATransaction;
-
-import java.util.List;
-
-/**
- * @author Simon McDuff
- * @since 2.0
- */
-public class CDOXASavepointImpl extends CDOUserSavepointImpl implements InternalCDOXASavepoint
-{
- private List<CDOSavepoint> savepoints;
-
- public CDOXASavepointImpl(InternalCDOXATransaction transaction, InternalCDOXASavepoint lastSavepoint)
- {
- super(transaction, lastSavepoint);
- }
-
- @Override
- public InternalCDOXATransaction getTransaction()
- {
- return (InternalCDOXATransaction)super.getTransaction();
- }
-
- @Override
- public InternalCDOXASavepoint getFirstSavePoint()
- {
- return (InternalCDOXASavepoint)super.getFirstSavePoint();
- }
-
- @Override
- public InternalCDOXASavepoint getNextSavepoint()
- {
- return (InternalCDOXASavepoint)super.getNextSavepoint();
- }
-
- @Override
- public InternalCDOXASavepoint getPreviousSavepoint()
- {
- return (InternalCDOXASavepoint)super.getPreviousSavepoint();
- }
-
- public List<CDOSavepoint> getSavepoints()
- {
- return savepoints;
- }
-
- public void setSavepoints(List<CDOSavepoint> savepoints)
- {
- this.savepoints = savepoints;
- }
-
- public void rollback()
- {
- getTransaction().rollback(this);
- }
-}
+/* + * Copyright (c) 2004 - 2012 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: + * Simon McDuff - initial API and implementation + */ +package org.eclipse.emf.internal.cdo.transaction; + +import org.eclipse.emf.cdo.transaction.CDOSavepoint; + +import org.eclipse.emf.spi.cdo.InternalCDOXASavepoint; +import org.eclipse.emf.spi.cdo.InternalCDOXATransaction; + +import java.util.List; + +/** + * @author Simon McDuff + * @since 2.0 + */ +public class CDOXASavepointImpl extends CDOUserSavepointImpl implements InternalCDOXASavepoint +{ + private List<CDOSavepoint> savepoints; + + public CDOXASavepointImpl(InternalCDOXATransaction transaction, InternalCDOXASavepoint lastSavepoint) + { + super(transaction, lastSavepoint); + } + + @Override + public InternalCDOXATransaction getTransaction() + { + return (InternalCDOXATransaction)super.getTransaction(); + } + + @Override + public InternalCDOXASavepoint getFirstSavePoint() + { + return (InternalCDOXASavepoint)super.getFirstSavePoint(); + } + + @Override + public InternalCDOXASavepoint getNextSavepoint() + { + return (InternalCDOXASavepoint)super.getNextSavepoint(); + } + + @Override + public InternalCDOXASavepoint getPreviousSavepoint() + { + return (InternalCDOXASavepoint)super.getPreviousSavepoint(); + } + + public List<CDOSavepoint> getSavepoints() + { + return savepoints; + } + + public void setSavepoints(List<CDOSavepoint> savepoints) + { + this.savepoints = savepoints; + } + + public void rollback() + { + getTransaction().rollback(this); + } +} diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/transaction/CDOXATransactionImpl.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/transaction/CDOXATransactionImpl.java index 71727089b0..42c1803f6c 100644 --- a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/transaction/CDOXATransactionImpl.java +++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/transaction/CDOXATransactionImpl.java @@ -1,713 +1,713 @@ -/*
- * Copyright (c) 2004 - 2012 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:
- * Simon McDuff - initial API and implementation
- * Eike Stepper - maintenance
- */
-package org.eclipse.emf.internal.cdo.transaction;
-
-import org.eclipse.emf.cdo.common.commit.CDOCommitInfo;
-import org.eclipse.emf.cdo.common.id.CDOID;
-import org.eclipse.emf.cdo.transaction.CDOSavepoint;
-import org.eclipse.emf.cdo.transaction.CDOTransaction;
-import org.eclipse.emf.cdo.transaction.CDOXATransaction;
-import org.eclipse.emf.cdo.util.CDOUtil;
-import org.eclipse.emf.cdo.util.CommitException;
-import org.eclipse.emf.cdo.view.CDOView;
-import org.eclipse.emf.cdo.view.CDOViewSet;
-
-import org.eclipse.emf.internal.cdo.bundle.OM;
-import org.eclipse.emf.internal.cdo.messages.Messages;
-
-import org.eclipse.net4j.util.CheckUtil;
-import org.eclipse.net4j.util.WrappedException;
-import org.eclipse.net4j.util.om.monitor.EclipseMonitor;
-import org.eclipse.net4j.util.om.monitor.EclipseMonitor.SynchronizedSubProgressMonitor;
-import org.eclipse.net4j.util.om.monitor.OMMonitor;
-import org.eclipse.net4j.util.om.trace.ContextTracer;
-
-import org.eclipse.emf.common.notify.Adapter;
-import org.eclipse.emf.common.notify.Notification;
-import org.eclipse.emf.common.notify.Notifier;
-import org.eclipse.emf.spi.cdo.CDOSessionProtocol;
-import org.eclipse.emf.spi.cdo.CDOSessionProtocol.CommitTransactionResult;
-import org.eclipse.emf.spi.cdo.CDOTransactionStrategy;
-import org.eclipse.emf.spi.cdo.InternalCDOTransaction;
-import org.eclipse.emf.spi.cdo.InternalCDOTransaction.InternalCDOCommitContext;
-import org.eclipse.emf.spi.cdo.InternalCDOUserSavepoint;
-import org.eclipse.emf.spi.cdo.InternalCDOXASavepoint;
-import org.eclipse.emf.spi.cdo.InternalCDOXATransaction;
-import org.eclipse.emf.spi.cdo.InternalCDOXATransaction.InternalCDOXACommitContext.CDOXAState;
-
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.core.runtime.NullProgressMonitor;
-import org.eclipse.core.runtime.SubProgressMonitor;
-
-import java.text.MessageFormat;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.Map.Entry;
-import java.util.Set;
-import java.util.concurrent.AbstractExecutorService;
-import java.util.concurrent.ExecutionException;
-import java.util.concurrent.ExecutorService;
-import java.util.concurrent.Executors;
-import java.util.concurrent.Future;
-import java.util.concurrent.TimeUnit;
-import java.util.concurrent.TimeoutException;
-
-/**
- * Three-phase commit.
- * <p>
- * Phase 1 does the following for each CDOTransaction:<br>
- * - preCommit <br>
- * - Accumulate external temporary ID.<br>
- * - request the commit to the server.<br>
- * - The server registers the commit context and returns the final ID for each temporary ID.
- * <p>
- * Phase 2 does the following for each CDOTransaction:<br>
- * - Transfer to the server a list of mapping of temporary externalID and final external ID that we accumulate
- * previously<br>
- * - Returns to the client only when commit process is ready to flush to disk (commit). <br>
- * <p>
- * Phase 3 does the following for each CDOTransaction:<br>
- * - Make modifications permanent.<br>
- * - PostCommit.
- * <p>
- * If an exception occurred during phase 1 or phase 2, the commit will be cancelled for all {@link CDOTransaction}
- * include in the XA transaction. If an exception occurred during phase 3, the commit will be cancelled only for the
- * {@link CDOTransaction} where the error happened.
- * <p>
- * All {@link CDOTransaction} includes in the commit process need to have finish their phase before moving to the next
- * phase. For one phase, every {@link CDOTransaction} could have their own thread. It depends of the ExecutorService.
- * <p>
- *
- * @author Simon McDuff
- * @since 2.0
- */
-public class CDOXATransactionImpl implements InternalCDOXATransaction
-{
- private static final ContextTracer TRACER = new ContextTracer(OM.DEBUG_TRANSACTION, CDOXATransactionImpl.class);
-
- /**
- * Parallel execution leads to deadlocks because the view lock is being held by the scheduler.
- * <p>
- * Contact the authors if you want to have this executed in parallel.
- */
- private static boolean SEQUENTIAL_EXECUTION = true;
-
- private List<InternalCDOTransaction> transactions = new ArrayList<InternalCDOTransaction>();
-
- private boolean allowRequestFromTransactionEnabled = true;
-
- private ExecutorService executorService = createExecutorService();
-
- private Map<InternalCDOTransaction, InternalCDOXACommitContext> activeContexts = new HashMap<InternalCDOTransaction, InternalCDOXACommitContext>();
-
- private Map<InternalCDOTransaction, Set<CDOID>> requestedCDOIDs = new HashMap<InternalCDOTransaction, Set<CDOID>>();
-
- private InternalCDOXASavepoint lastSavepoint = createSavepoint(null);
-
- private InternalCDOXASavepoint firstSavepoint = lastSavepoint;
-
- private CDOTransactionStrategy transactionStrategy = createTransactionStrategy();
-
- private CDOXAInternalAdapter internalAdapter = createInternalAdapter();
-
- public CDOXATransactionImpl()
- {
- }
-
- public boolean isAllowRequestFromTransactionEnabled()
- {
- return allowRequestFromTransactionEnabled;
- }
-
- public void setAllowRequestFromTransactionEnabled(boolean on)
- {
- allowRequestFromTransactionEnabled = on;
- }
-
- public void add(InternalCDOTransaction transaction)
- {
- transaction.setTransactionStrategy(transactionStrategy);
- }
-
- public void remove(InternalCDOTransaction transaction)
- {
- if (transaction != null)
- {
- transaction.setTransactionStrategy(null);
- }
- }
-
- public synchronized void add(CDOViewSet viewSet)
- {
- CDOXATransaction transSet = CDOUtil.getXATransaction(viewSet);
- if (transSet != null)
- {
- throw new IllegalArgumentException(Messages.getString("CDOXATransactionImpl.0")); //$NON-NLS-1$
- }
-
- viewSet.eAdapters().add(internalAdapter);
-
- for (InternalCDOTransaction transaction : getTransactions(viewSet))
- {
- add(transaction);
- }
- }
-
- public synchronized void remove(CDOViewSet viewSet)
- {
- CDOXATransaction transSet = CDOUtil.getXATransaction(viewSet);
- if (transSet != this)
- {
- throw new IllegalArgumentException(Messages.getString("CDOXATransactionImpl.1")); //$NON-NLS-1$
- }
-
- for (InternalCDOTransaction transaction : getTransactions(viewSet))
- {
- remove(transaction);
- }
-
- viewSet.eAdapters().remove(internalAdapter);
- }
-
- public void add(InternalCDOTransaction transaction, CDOID object)
- {
- synchronized (requestedCDOIDs)
- {
- Set<CDOID> ids = requestedCDOIDs.get(transaction);
- if (ids == null)
- {
- ids = new HashSet<CDOID>();
- requestedCDOIDs.put(transaction, ids);
- }
-
- ids.add(object);
- }
- }
-
- public CDOID[] get(InternalCDOTransaction transaction)
- {
- Set<CDOID> ids = requestedCDOIDs.get(transaction);
- return ids.toArray(new CDOID[ids.size()]);
- }
-
- public InternalCDOXACommitContext getCommitContext(CDOTransaction transaction)
- {
- return activeContexts.get(transaction);
- }
-
- private void send(Collection<InternalCDOXACommitContext> xaContexts, final IProgressMonitor progressMonitor)
- throws InterruptedException, ExecutionException
- {
- int xaContextSize = xaContexts.size();
- progressMonitor.beginTask("", xaContextSize); //$NON-NLS-1$
-
- try
- {
- Map<Future<Object>, InternalCDOXACommitContext> futures = new HashMap<Future<Object>, InternalCDOXACommitContext>();
- for (InternalCDOXACommitContext xaContext : xaContexts)
- {
- xaContext.setProgressMonitor(new SynchronizedSubProgressMonitor(progressMonitor, 1));
- Future<Object> future = executorService.submit(xaContext);
- futures.put(future, xaContext);
- }
-
- int nbProcessDone = 0;
-
- do
- {
- for (Iterator<Entry<Future<Object>, InternalCDOXACommitContext>> it = futures.entrySet().iterator(); it
- .hasNext();)
- {
- Entry<Future<Object>, InternalCDOXACommitContext> entry = it.next();
- Future<Object> future = entry.getKey();
- InternalCDOXACommitContext xaContext = entry.getValue();
-
- try
- {
- future.get(1000, TimeUnit.MILLISECONDS);
- nbProcessDone++;
- it.remove();
- if (TRACER.isEnabled())
- {
- TRACER.format("Got {0}", xaContext);
- }
- }
- catch (TimeoutException ex)
- {
- // Just retry
- if (TRACER.isEnabled())
- {
- TRACER.format("Waiting for {0}", xaContext);
- }
- }
- }
- } while (xaContextSize != nbProcessDone);
- }
- finally
- {
- progressMonitor.done();
- for (InternalCDOXACommitContext xaContext : xaContexts)
- {
- xaContext.setProgressMonitor(null);
- }
- }
- }
-
- private void cleanUp()
- {
- activeContexts.clear();
- requestedCDOIDs.clear();
- }
-
- private List<InternalCDOTransaction> getTransactions(CDOViewSet viewSet)
- {
- List<InternalCDOTransaction> transactions = new ArrayList<InternalCDOTransaction>();
- for (CDOView view : viewSet.getViews())
- {
- if (view instanceof InternalCDOTransaction)
- {
- transactions.add((InternalCDOTransaction)view);
- }
- }
-
- return transactions;
- }
-
- public CDOCommitInfo commit() throws CommitException
- {
- return commit(new NullProgressMonitor());
- }
-
- public CDOCommitInfo commit(IProgressMonitor progressMonitor) throws CommitException
- {
- CheckUtil.checkArg(progressMonitor, "progressMonitor"); //$NON-NLS-1$
- progressMonitor.beginTask(Messages.getString("CDOXATransactionImpl.4"), 3); //$NON-NLS-1$
- int phase = 0;
-
- for (InternalCDOTransaction transaction : transactions)
- {
- InternalCDOCommitContext context = transaction.createCommitContext();
- InternalCDOXACommitContext xaContext = createXACommitContext(context);
- xaContext.setState(CDOXAPhase1State.INSTANCE);
- activeContexts.put(transaction, xaContext);
- }
-
- try
- {
- // We need to complete 3 phases
- while (phase < 3)
- {
- send(activeContexts.values(), new SubProgressMonitor(progressMonitor, 1));
- ++phase;
- }
-
- return null;
- }
- catch (Exception ex)
- {
- if (phase < 2)
- {
- // Phase 0 and 1 are the only two phases we can cancel.
- for (InternalCDOXACommitContext xaContext : activeContexts.values())
- {
- xaContext.setState(CDOXACancel.INSTANCE);
- }
-
- try
- {
- send(activeContexts.values(), new SubProgressMonitor(progressMonitor, 2 - phase));
- }
- catch (InterruptedException ex1)
- {
- throw WrappedException.wrap(ex1);
- }
- catch (ExecutionException ex1)
- {
- OM.LOG.warn(ex1);
- }
- }
-
- throw new CommitException(ex);
- }
- finally
- {
- cleanUp();
- progressMonitor.done();
- }
- }
-
- public InternalCDOXASavepoint getLastSavepoint()
- {
- return lastSavepoint;
- }
-
- public void rollback()
- {
- rollback(firstSavepoint);
- }
-
- public void rollback(InternalCDOXASavepoint savepoint)
- {
- if (!savepoint.isValid())
- {
- throw new IllegalArgumentException(Messages.getString("CDOXATransactionImpl.7") + savepoint); //$NON-NLS-1$
- }
-
- List<CDOSavepoint> savepoints = savepoint.getSavepoints();
- if (savepoints == null)
- {
- savepoints = getListSavepoints();
- }
-
- for (CDOSavepoint indexSavePoint : savepoints)
- {
- InternalCDOTransaction transaction = (InternalCDOTransaction)indexSavePoint.getTransaction();
- CDOSingleTransactionStrategyImpl.INSTANCE.rollback(transaction, (InternalCDOUserSavepoint)indexSavePoint);
- }
-
- lastSavepoint = savepoint;
- lastSavepoint.setNextSavepoint(null);
- lastSavepoint.setSavepoints(null);
- }
-
- public InternalCDOXASavepoint setSavepoint()
- {
- List<CDOSavepoint> savepoints = getListSavepoints();
- for (CDOSavepoint savepoint : savepoints)
- {
- InternalCDOTransaction transaction = (InternalCDOTransaction)savepoint.getTransaction();
- CDOSingleTransactionStrategyImpl.INSTANCE.setSavepoint(transaction);
- }
-
- getLastSavepoint().setSavepoints(savepoints);
- lastSavepoint = createSavepoint(getLastSavepoint());
- return lastSavepoint;
- }
-
- @Override
- public String toString()
- {
- return MessageFormat.format("CDOXATransaction[size={0}]", transactions.size());
- }
-
- protected CDOXACommitContextImpl createXACommitContext(InternalCDOCommitContext context)
- {
- return new CDOXACommitContextImpl(this, context);
- }
-
- protected CDOXATransactionStrategyImpl createTransactionStrategy()
- {
- return new CDOXATransactionStrategyImpl(this);
- }
-
- protected CDOXAInternalAdapter createInternalAdapter()
- {
- return new CDOXAInternalAdapter(this);
- }
-
- protected CDOXASavepointImpl createSavepoint(InternalCDOXASavepoint lastSavepoint)
- {
- return new CDOXASavepointImpl(this, lastSavepoint);
- }
-
- protected final ExecutorService createExecutorService()
- {
- if (SEQUENTIAL_EXECUTION)
- {
- return new AbstractExecutorService()
- {
- public void execute(Runnable command)
- {
- command.run();
- }
-
- public List<Runnable> shutdownNow()
- {
- return null;
- }
-
- public void shutdown()
- {
- }
-
- public boolean isTerminated()
- {
- return false;
- }
-
- public boolean isShutdown()
- {
- return false;
- }
-
- public boolean awaitTermination(long timeout, TimeUnit unit) throws InterruptedException
- {
- return false;
- }
- };
- }
-
- return Executors.newFixedThreadPool(10);
- }
-
- private List<CDOSavepoint> getListSavepoints()
- {
- synchronized (transactions)
- {
- List<CDOSavepoint> savepoints = new ArrayList<CDOSavepoint>();
- for (InternalCDOTransaction transaction : transactions)
- {
- savepoints.add(transaction.getLastSavepoint());
- }
-
- return savepoints;
- }
- }
-
- /**
- * @author Simon McDuff
- */
- public static class CDOXAInternalAdapter implements Adapter
- {
- private InternalCDOXATransaction xaTransaction;
-
- public CDOXAInternalAdapter(InternalCDOXATransaction xaTransaction)
- {
- this.xaTransaction = xaTransaction;
- }
-
- public InternalCDOXATransaction getXATransaction()
- {
- return xaTransaction;
- }
-
- public Notifier getTarget()
- {
- return null;
- }
-
- public boolean isAdapterForType(Object type)
- {
- return false;
- }
-
- public void notifyChanged(Notification notification)
- {
- switch (notification.getEventType())
- {
- case Notification.ADD:
- if (notification.getNewValue() instanceof InternalCDOTransaction)
- {
- getXATransaction().add((InternalCDOTransaction)notification.getNewValue());
- }
-
- break;
-
- case Notification.REMOVE:
- if (notification.getOldValue() instanceof InternalCDOTransaction)
- {
- getXATransaction().remove((InternalCDOTransaction)notification.getNewValue());
- }
-
- break;
- }
- }
-
- public void setTarget(Notifier newTarget)
- {
- }
- }
-
- /**
- * @author Simon McDuff
- */
- private final class CDOXATransactionStrategyImpl implements CDOTransactionStrategy
- {
- private InternalCDOXATransaction xaTransaction;
-
- public CDOXATransactionStrategyImpl(InternalCDOXATransaction xaTransaction)
- {
- this.xaTransaction = xaTransaction;
- }
-
- public void setTarget(InternalCDOTransaction transaction)
- {
- synchronized (transactions)
- {
- transactions.add(transaction);
- }
- }
-
- public void unsetTarget(InternalCDOTransaction transaction)
- {
- synchronized (transactions)
- {
- transactions.remove(transaction);
- }
- }
-
- private void checkAccess()
- {
- if (!allowRequestFromTransactionEnabled)
- {
- throw new IllegalStateException(Messages.getString("CDOXATransactionImpl.8")); //$NON-NLS-1$
- }
- }
-
- public CDOCommitInfo commit(InternalCDOTransaction transactionCommit, IProgressMonitor progressMonitor)
- throws Exception
- {
- checkAccess();
- return xaTransaction.commit(progressMonitor);
- }
-
- public void rollback(InternalCDOTransaction transaction, InternalCDOUserSavepoint savepoint)
- {
- checkAccess();
- xaTransaction.rollback((InternalCDOXASavepoint)savepoint);
- }
-
- public InternalCDOUserSavepoint setSavepoint(InternalCDOTransaction transaction)
- {
- checkAccess();
- return xaTransaction.setSavepoint();
- }
- }
-
- /**
- * @author Simon McDuff
- */
- public static class CDOXAPhase1State extends CDOXAState
- {
- public static final CDOXAPhase1State INSTANCE = new CDOXAPhase1State();
-
- @Override
- public void handle(InternalCDOXACommitContext xaContext, IProgressMonitor progressMonitor) throws Exception
- {
- xaContext.preCommit();
- CommitTransactionResult result = null;
- if (xaContext.getTransaction().isDirty())
- {
- CDOSessionProtocol sessionProtocol = xaContext.getTransaction().getSession().getSessionProtocol();
- OMMonitor monitor = new EclipseMonitor(progressMonitor);
- result = sessionProtocol.commitXATransactionPhase1(xaContext, monitor);
- check_result(result);
- }
-
- xaContext.setResult(result);
- xaContext.setState(CDOXAPhase2State.INSTANCE);
- }
-
- @Override
- public String toString()
- {
- return "PHASE1";
- }
- }
-
- /**
- * @author Simon McDuff
- */
- public static class CDOXAPhase2State extends CDOXAState
- {
- public static final CDOXAPhase2State INSTANCE = new CDOXAPhase2State();
-
- public CDOXAPhase2State()
- {
- }
-
- @Override
- public void handle(InternalCDOXACommitContext xaContext, IProgressMonitor progressMonitor) throws Exception
- {
- if (xaContext.getTransaction().isDirty())
- {
- CDOSessionProtocol sessionProtocol = xaContext.getTransaction().getSession().getSessionProtocol();
- OMMonitor monitor = new EclipseMonitor(progressMonitor);
- CommitTransactionResult result = sessionProtocol.commitXATransactionPhase2(xaContext, monitor);
- check_result(result);
- }
-
- xaContext.setState(CDOXAPhase3State.INSTANCE);
- }
-
- @Override
- public String toString()
- {
- return "PHASE2";
- }
- }
-
- /**
- * @author Simon McDuff
- */
- public static class CDOXAPhase3State extends CDOXAState
- {
- public static final CDOXAPhase3State INSTANCE = new CDOXAPhase3State();
-
- public CDOXAPhase3State()
- {
- }
-
- @Override
- public void handle(InternalCDOXACommitContext xaContext, IProgressMonitor progressMonitor) throws Exception
- {
- if (xaContext.getTransaction().isDirty())
- {
- CDOSessionProtocol sessionProtocol = xaContext.getTransaction().getSession().getSessionProtocol();
- OMMonitor monitor = new EclipseMonitor(progressMonitor);
- CommitTransactionResult result = sessionProtocol.commitXATransactionPhase3(xaContext, monitor);
- check_result(result);
- }
-
- xaContext.postCommit(xaContext.getResult());
- xaContext.setState(null);
- }
-
- @Override
- public String toString()
- {
- return "PHASE3";
- }
- }
-
- /**
- * @author Simon McDuff
- */
- public static class CDOXACancel extends CDOXAState
- {
- public static final CDOXACancel INSTANCE = new CDOXACancel();
-
- public CDOXACancel()
- {
- }
-
- @Override
- public void handle(InternalCDOXACommitContext xaContext, IProgressMonitor progressMonitor) throws Exception
- {
- CDOSessionProtocol sessionProtocol = xaContext.getTransaction().getSession().getSessionProtocol();
- OMMonitor monitor = new EclipseMonitor(progressMonitor);
- CommitTransactionResult result = sessionProtocol.commitXATransactionCancel(xaContext, monitor);
- check_result(result);
- }
-
- @Override
- public String toString()
- {
- return "CANCEL";
- }
- }
-}
+/* + * Copyright (c) 2004 - 2012 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: + * Simon McDuff - initial API and implementation + * Eike Stepper - maintenance + */ +package org.eclipse.emf.internal.cdo.transaction; + +import org.eclipse.emf.cdo.common.commit.CDOCommitInfo; +import org.eclipse.emf.cdo.common.id.CDOID; +import org.eclipse.emf.cdo.transaction.CDOSavepoint; +import org.eclipse.emf.cdo.transaction.CDOTransaction; +import org.eclipse.emf.cdo.transaction.CDOXATransaction; +import org.eclipse.emf.cdo.util.CDOUtil; +import org.eclipse.emf.cdo.util.CommitException; +import org.eclipse.emf.cdo.view.CDOView; +import org.eclipse.emf.cdo.view.CDOViewSet; + +import org.eclipse.emf.internal.cdo.bundle.OM; +import org.eclipse.emf.internal.cdo.messages.Messages; + +import org.eclipse.net4j.util.CheckUtil; +import org.eclipse.net4j.util.WrappedException; +import org.eclipse.net4j.util.om.monitor.EclipseMonitor; +import org.eclipse.net4j.util.om.monitor.EclipseMonitor.SynchronizedSubProgressMonitor; +import org.eclipse.net4j.util.om.monitor.OMMonitor; +import org.eclipse.net4j.util.om.trace.ContextTracer; + +import org.eclipse.emf.common.notify.Adapter; +import org.eclipse.emf.common.notify.Notification; +import org.eclipse.emf.common.notify.Notifier; +import org.eclipse.emf.spi.cdo.CDOSessionProtocol; +import org.eclipse.emf.spi.cdo.CDOSessionProtocol.CommitTransactionResult; +import org.eclipse.emf.spi.cdo.CDOTransactionStrategy; +import org.eclipse.emf.spi.cdo.InternalCDOTransaction; +import org.eclipse.emf.spi.cdo.InternalCDOTransaction.InternalCDOCommitContext; +import org.eclipse.emf.spi.cdo.InternalCDOUserSavepoint; +import org.eclipse.emf.spi.cdo.InternalCDOXASavepoint; +import org.eclipse.emf.spi.cdo.InternalCDOXATransaction; +import org.eclipse.emf.spi.cdo.InternalCDOXATransaction.InternalCDOXACommitContext.CDOXAState; + +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.NullProgressMonitor; +import org.eclipse.core.runtime.SubProgressMonitor; + +import java.text.MessageFormat; +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; +import java.util.Set; +import java.util.concurrent.AbstractExecutorService; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.Future; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.TimeoutException; + +/** + * Three-phase commit. + * <p> + * Phase 1 does the following for each CDOTransaction:<br> + * - preCommit <br> + * - Accumulate external temporary ID.<br> + * - request the commit to the server.<br> + * - The server registers the commit context and returns the final ID for each temporary ID. + * <p> + * Phase 2 does the following for each CDOTransaction:<br> + * - Transfer to the server a list of mapping of temporary externalID and final external ID that we accumulate + * previously<br> + * - Returns to the client only when commit process is ready to flush to disk (commit). <br> + * <p> + * Phase 3 does the following for each CDOTransaction:<br> + * - Make modifications permanent.<br> + * - PostCommit. + * <p> + * If an exception occurred during phase 1 or phase 2, the commit will be cancelled for all {@link CDOTransaction} + * include in the XA transaction. If an exception occurred during phase 3, the commit will be cancelled only for the + * {@link CDOTransaction} where the error happened. + * <p> + * All {@link CDOTransaction} includes in the commit process need to have finish their phase before moving to the next + * phase. For one phase, every {@link CDOTransaction} could have their own thread. It depends of the ExecutorService. + * <p> + * + * @author Simon McDuff + * @since 2.0 + */ +public class CDOXATransactionImpl implements InternalCDOXATransaction +{ + private static final ContextTracer TRACER = new ContextTracer(OM.DEBUG_TRANSACTION, CDOXATransactionImpl.class); + + /** + * Parallel execution leads to deadlocks because the view lock is being held by the scheduler. + * <p> + * Contact the authors if you want to have this executed in parallel. + */ + private static boolean SEQUENTIAL_EXECUTION = true; + + private List<InternalCDOTransaction> transactions = new ArrayList<InternalCDOTransaction>(); + + private boolean allowRequestFromTransactionEnabled = true; + + private ExecutorService executorService = createExecutorService(); + + private Map<InternalCDOTransaction, InternalCDOXACommitContext> activeContexts = new HashMap<InternalCDOTransaction, InternalCDOXACommitContext>(); + + private Map<InternalCDOTransaction, Set<CDOID>> requestedCDOIDs = new HashMap<InternalCDOTransaction, Set<CDOID>>(); + + private InternalCDOXASavepoint lastSavepoint = createSavepoint(null); + + private InternalCDOXASavepoint firstSavepoint = lastSavepoint; + + private CDOTransactionStrategy transactionStrategy = createTransactionStrategy(); + + private CDOXAInternalAdapter internalAdapter = createInternalAdapter(); + + public CDOXATransactionImpl() + { + } + + public boolean isAllowRequestFromTransactionEnabled() + { + return allowRequestFromTransactionEnabled; + } + + public void setAllowRequestFromTransactionEnabled(boolean on) + { + allowRequestFromTransactionEnabled = on; + } + + public void add(InternalCDOTransaction transaction) + { + transaction.setTransactionStrategy(transactionStrategy); + } + + public void remove(InternalCDOTransaction transaction) + { + if (transaction != null) + { + transaction.setTransactionStrategy(null); + } + } + + public synchronized void add(CDOViewSet viewSet) + { + CDOXATransaction transSet = CDOUtil.getXATransaction(viewSet); + if (transSet != null) + { + throw new IllegalArgumentException(Messages.getString("CDOXATransactionImpl.0")); //$NON-NLS-1$ + } + + viewSet.eAdapters().add(internalAdapter); + + for (InternalCDOTransaction transaction : getTransactions(viewSet)) + { + add(transaction); + } + } + + public synchronized void remove(CDOViewSet viewSet) + { + CDOXATransaction transSet = CDOUtil.getXATransaction(viewSet); + if (transSet != this) + { + throw new IllegalArgumentException(Messages.getString("CDOXATransactionImpl.1")); //$NON-NLS-1$ + } + + for (InternalCDOTransaction transaction : getTransactions(viewSet)) + { + remove(transaction); + } + + viewSet.eAdapters().remove(internalAdapter); + } + + public void add(InternalCDOTransaction transaction, CDOID object) + { + synchronized (requestedCDOIDs) + { + Set<CDOID> ids = requestedCDOIDs.get(transaction); + if (ids == null) + { + ids = new HashSet<CDOID>(); + requestedCDOIDs.put(transaction, ids); + } + + ids.add(object); + } + } + + public CDOID[] get(InternalCDOTransaction transaction) + { + Set<CDOID> ids = requestedCDOIDs.get(transaction); + return ids.toArray(new CDOID[ids.size()]); + } + + public InternalCDOXACommitContext getCommitContext(CDOTransaction transaction) + { + return activeContexts.get(transaction); + } + + private void send(Collection<InternalCDOXACommitContext> xaContexts, final IProgressMonitor progressMonitor) + throws InterruptedException, ExecutionException + { + int xaContextSize = xaContexts.size(); + progressMonitor.beginTask("", xaContextSize); //$NON-NLS-1$ + + try + { + Map<Future<Object>, InternalCDOXACommitContext> futures = new HashMap<Future<Object>, InternalCDOXACommitContext>(); + for (InternalCDOXACommitContext xaContext : xaContexts) + { + xaContext.setProgressMonitor(new SynchronizedSubProgressMonitor(progressMonitor, 1)); + Future<Object> future = executorService.submit(xaContext); + futures.put(future, xaContext); + } + + int nbProcessDone = 0; + + do + { + for (Iterator<Entry<Future<Object>, InternalCDOXACommitContext>> it = futures.entrySet().iterator(); it + .hasNext();) + { + Entry<Future<Object>, InternalCDOXACommitContext> entry = it.next(); + Future<Object> future = entry.getKey(); + InternalCDOXACommitContext xaContext = entry.getValue(); + + try + { + future.get(1000, TimeUnit.MILLISECONDS); + nbProcessDone++; + it.remove(); + if (TRACER.isEnabled()) + { + TRACER.format("Got {0}", xaContext); + } + } + catch (TimeoutException ex) + { + // Just retry + if (TRACER.isEnabled()) + { + TRACER.format("Waiting for {0}", xaContext); + } + } + } + } while (xaContextSize != nbProcessDone); + } + finally + { + progressMonitor.done(); + for (InternalCDOXACommitContext xaContext : xaContexts) + { + xaContext.setProgressMonitor(null); + } + } + } + + private void cleanUp() + { + activeContexts.clear(); + requestedCDOIDs.clear(); + } + + private List<InternalCDOTransaction> getTransactions(CDOViewSet viewSet) + { + List<InternalCDOTransaction> transactions = new ArrayList<InternalCDOTransaction>(); + for (CDOView view : viewSet.getViews()) + { + if (view instanceof InternalCDOTransaction) + { + transactions.add((InternalCDOTransaction)view); + } + } + + return transactions; + } + + public CDOCommitInfo commit() throws CommitException + { + return commit(new NullProgressMonitor()); + } + + public CDOCommitInfo commit(IProgressMonitor progressMonitor) throws CommitException + { + CheckUtil.checkArg(progressMonitor, "progressMonitor"); //$NON-NLS-1$ + progressMonitor.beginTask(Messages.getString("CDOXATransactionImpl.4"), 3); //$NON-NLS-1$ + int phase = 0; + + for (InternalCDOTransaction transaction : transactions) + { + InternalCDOCommitContext context = transaction.createCommitContext(); + InternalCDOXACommitContext xaContext = createXACommitContext(context); + xaContext.setState(CDOXAPhase1State.INSTANCE); + activeContexts.put(transaction, xaContext); + } + + try + { + // We need to complete 3 phases + while (phase < 3) + { + send(activeContexts.values(), new SubProgressMonitor(progressMonitor, 1)); + ++phase; + } + + return null; + } + catch (Exception ex) + { + if (phase < 2) + { + // Phase 0 and 1 are the only two phases we can cancel. + for (InternalCDOXACommitContext xaContext : activeContexts.values()) + { + xaContext.setState(CDOXACancel.INSTANCE); + } + + try + { + send(activeContexts.values(), new SubProgressMonitor(progressMonitor, 2 - phase)); + } + catch (InterruptedException ex1) + { + throw WrappedException.wrap(ex1); + } + catch (ExecutionException ex1) + { + OM.LOG.warn(ex1); + } + } + + throw new CommitException(ex); + } + finally + { + cleanUp(); + progressMonitor.done(); + } + } + + public InternalCDOXASavepoint getLastSavepoint() + { + return lastSavepoint; + } + + public void rollback() + { + rollback(firstSavepoint); + } + + public void rollback(InternalCDOXASavepoint savepoint) + { + if (!savepoint.isValid()) + { + throw new IllegalArgumentException(Messages.getString("CDOXATransactionImpl.7") + savepoint); //$NON-NLS-1$ + } + + List<CDOSavepoint> savepoints = savepoint.getSavepoints(); + if (savepoints == null) + { + savepoints = getListSavepoints(); + } + + for (CDOSavepoint indexSavePoint : savepoints) + { + InternalCDOTransaction transaction = (InternalCDOTransaction)indexSavePoint.getTransaction(); + CDOSingleTransactionStrategyImpl.INSTANCE.rollback(transaction, (InternalCDOUserSavepoint)indexSavePoint); + } + + lastSavepoint = savepoint; + lastSavepoint.setNextSavepoint(null); + lastSavepoint.setSavepoints(null); + } + + public InternalCDOXASavepoint setSavepoint() + { + List<CDOSavepoint> savepoints = getListSavepoints(); + for (CDOSavepoint savepoint : savepoints) + { + InternalCDOTransaction transaction = (InternalCDOTransaction)savepoint.getTransaction(); + CDOSingleTransactionStrategyImpl.INSTANCE.setSavepoint(transaction); + } + + getLastSavepoint().setSavepoints(savepoints); + lastSavepoint = createSavepoint(getLastSavepoint()); + return lastSavepoint; + } + + @Override + public String toString() + { + return MessageFormat.format("CDOXATransaction[size={0}]", transactions.size()); + } + + protected CDOXACommitContextImpl createXACommitContext(InternalCDOCommitContext context) + { + return new CDOXACommitContextImpl(this, context); + } + + protected CDOXATransactionStrategyImpl createTransactionStrategy() + { + return new CDOXATransactionStrategyImpl(this); + } + + protected CDOXAInternalAdapter createInternalAdapter() + { + return new CDOXAInternalAdapter(this); + } + + protected CDOXASavepointImpl createSavepoint(InternalCDOXASavepoint lastSavepoint) + { + return new CDOXASavepointImpl(this, lastSavepoint); + } + + protected final ExecutorService createExecutorService() + { + if (SEQUENTIAL_EXECUTION) + { + return new AbstractExecutorService() + { + public void execute(Runnable command) + { + command.run(); + } + + public List<Runnable> shutdownNow() + { + return null; + } + + public void shutdown() + { + } + + public boolean isTerminated() + { + return false; + } + + public boolean isShutdown() + { + return false; + } + + public boolean awaitTermination(long timeout, TimeUnit unit) throws InterruptedException + { + return false; + } + }; + } + + return Executors.newFixedThreadPool(10); + } + + private List<CDOSavepoint> getListSavepoints() + { + synchronized (transactions) + { + List<CDOSavepoint> savepoints = new ArrayList<CDOSavepoint>(); + for (InternalCDOTransaction transaction : transactions) + { + savepoints.add(transaction.getLastSavepoint()); + } + + return savepoints; + } + } + + /** + * @author Simon McDuff + */ + public static class CDOXAInternalAdapter implements Adapter + { + private InternalCDOXATransaction xaTransaction; + + public CDOXAInternalAdapter(InternalCDOXATransaction xaTransaction) + { + this.xaTransaction = xaTransaction; + } + + public InternalCDOXATransaction getXATransaction() + { + return xaTransaction; + } + + public Notifier getTarget() + { + return null; + } + + public boolean isAdapterForType(Object type) + { + return false; + } + + public void notifyChanged(Notification notification) + { + switch (notification.getEventType()) + { + case Notification.ADD: + if (notification.getNewValue() instanceof InternalCDOTransaction) + { + getXATransaction().add((InternalCDOTransaction)notification.getNewValue()); + } + + break; + + case Notification.REMOVE: + if (notification.getOldValue() instanceof InternalCDOTransaction) + { + getXATransaction().remove((InternalCDOTransaction)notification.getNewValue()); + } + + break; + } + } + + public void setTarget(Notifier newTarget) + { + } + } + + /** + * @author Simon McDuff + */ + private final class CDOXATransactionStrategyImpl implements CDOTransactionStrategy + { + private InternalCDOXATransaction xaTransaction; + + public CDOXATransactionStrategyImpl(InternalCDOXATransaction xaTransaction) + { + this.xaTransaction = xaTransaction; + } + + public void setTarget(InternalCDOTransaction transaction) + { + synchronized (transactions) + { + transactions.add(transaction); + } + } + + public void unsetTarget(InternalCDOTransaction transaction) + { + synchronized (transactions) + { + transactions.remove(transaction); + } + } + + private void checkAccess() + { + if (!allowRequestFromTransactionEnabled) + { + throw new IllegalStateException(Messages.getString("CDOXATransactionImpl.8")); //$NON-NLS-1$ + } + } + + public CDOCommitInfo commit(InternalCDOTransaction transactionCommit, IProgressMonitor progressMonitor) + throws Exception + { + checkAccess(); + return xaTransaction.commit(progressMonitor); + } + + public void rollback(InternalCDOTransaction transaction, InternalCDOUserSavepoint savepoint) + { + checkAccess(); + xaTransaction.rollback((InternalCDOXASavepoint)savepoint); + } + + public InternalCDOUserSavepoint setSavepoint(InternalCDOTransaction transaction) + { + checkAccess(); + return xaTransaction.setSavepoint(); + } + } + + /** + * @author Simon McDuff + */ + public static class CDOXAPhase1State extends CDOXAState + { + public static final CDOXAPhase1State INSTANCE = new CDOXAPhase1State(); + + @Override + public void handle(InternalCDOXACommitContext xaContext, IProgressMonitor progressMonitor) throws Exception + { + xaContext.preCommit(); + CommitTransactionResult result = null; + if (xaContext.getTransaction().isDirty()) + { + CDOSessionProtocol sessionProtocol = xaContext.getTransaction().getSession().getSessionProtocol(); + OMMonitor monitor = new EclipseMonitor(progressMonitor); + result = sessionProtocol.commitXATransactionPhase1(xaContext, monitor); + check_result(result); + } + + xaContext.setResult(result); + xaContext.setState(CDOXAPhase2State.INSTANCE); + } + + @Override + public String toString() + { + return "PHASE1"; + } + } + + /** + * @author Simon McDuff + */ + public static class CDOXAPhase2State extends CDOXAState + { + public static final CDOXAPhase2State INSTANCE = new CDOXAPhase2State(); + + public CDOXAPhase2State() + { + } + + @Override + public void handle(InternalCDOXACommitContext xaContext, IProgressMonitor progressMonitor) throws Exception + { + if (xaContext.getTransaction().isDirty()) + { + CDOSessionProtocol sessionProtocol = xaContext.getTransaction().getSession().getSessionProtocol(); + OMMonitor monitor = new EclipseMonitor(progressMonitor); + CommitTransactionResult result = sessionProtocol.commitXATransactionPhase2(xaContext, monitor); + check_result(result); + } + + xaContext.setState(CDOXAPhase3State.INSTANCE); + } + + @Override + public String toString() + { + return "PHASE2"; + } + } + + /** + * @author Simon McDuff + */ + public static class CDOXAPhase3State extends CDOXAState + { + public static final CDOXAPhase3State INSTANCE = new CDOXAPhase3State(); + + public CDOXAPhase3State() + { + } + + @Override + public void handle(InternalCDOXACommitContext xaContext, IProgressMonitor progressMonitor) throws Exception + { + if (xaContext.getTransaction().isDirty()) + { + CDOSessionProtocol sessionProtocol = xaContext.getTransaction().getSession().getSessionProtocol(); + OMMonitor monitor = new EclipseMonitor(progressMonitor); + CommitTransactionResult result = sessionProtocol.commitXATransactionPhase3(xaContext, monitor); + check_result(result); + } + + xaContext.postCommit(xaContext.getResult()); + xaContext.setState(null); + } + + @Override + public String toString() + { + return "PHASE3"; + } + } + + /** + * @author Simon McDuff + */ + public static class CDOXACancel extends CDOXAState + { + public static final CDOXACancel INSTANCE = new CDOXACancel(); + + public CDOXACancel() + { + } + + @Override + public void handle(InternalCDOXACommitContext xaContext, IProgressMonitor progressMonitor) throws Exception + { + CDOSessionProtocol sessionProtocol = xaContext.getTransaction().getSession().getSessionProtocol(); + OMMonitor monitor = new EclipseMonitor(progressMonitor); + CommitTransactionResult result = sessionProtocol.commitXATransactionCancel(xaContext, monitor); + check_result(result); + } + + @Override + public String toString() + { + return "CANCEL"; + } + } +} diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/util/CommitIntegrityCheck.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/util/CommitIntegrityCheck.java index 0802b4b8be..93e02a670f 100644 --- a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/util/CommitIntegrityCheck.java +++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/util/CommitIntegrityCheck.java @@ -1,523 +1,523 @@ -/*
- * Copyright (c) 2004 - 2012 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:
- * Caspar De Groot - initial API and implementation
- */
-package org.eclipse.emf.internal.cdo.util;
-
-import org.eclipse.emf.cdo.CDOObject;
-import org.eclipse.emf.cdo.CDOState;
-import org.eclipse.emf.cdo.common.id.CDOID;
-import org.eclipse.emf.cdo.common.id.CDOIDUtil;
-import org.eclipse.emf.cdo.common.model.EMFUtil;
-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;
-import org.eclipse.emf.cdo.common.revision.delta.CDOFeatureDelta;
-import org.eclipse.emf.cdo.common.revision.delta.CDOListFeatureDelta;
-import org.eclipse.emf.cdo.common.revision.delta.CDOMoveFeatureDelta;
-import org.eclipse.emf.cdo.common.revision.delta.CDORemoveFeatureDelta;
-import org.eclipse.emf.cdo.common.revision.delta.CDORevisionDelta;
-import org.eclipse.emf.cdo.common.revision.delta.CDOSetFeatureDelta;
-import org.eclipse.emf.cdo.common.revision.delta.CDOUnsetFeatureDelta;
-import org.eclipse.emf.cdo.eresource.CDOResource;
-import org.eclipse.emf.cdo.spi.common.revision.InternalCDORevision;
-import org.eclipse.emf.cdo.util.CDOUtil;
-import org.eclipse.emf.cdo.util.CommitIntegrityException;
-
-import org.eclipse.net4j.util.CheckUtil;
-
-import org.eclipse.emf.common.util.EList;
-import org.eclipse.emf.ecore.EObject;
-import org.eclipse.emf.ecore.EReference;
-import org.eclipse.emf.ecore.EStructuralFeature;
-import org.eclipse.emf.ecore.InternalEObject.EStore;
-import org.eclipse.emf.spi.cdo.InternalCDOObject;
-import org.eclipse.emf.spi.cdo.InternalCDOTransaction;
-import org.eclipse.emf.spi.cdo.InternalCDOTransaction.InternalCDOCommitContext;
-
-import java.util.HashSet;
-import java.util.Set;
-
-/**
- * @author Caspar De Groot
- * @since 4.0
- */
-public class CommitIntegrityCheck
-{
- private InternalCDOTransaction transaction;
-
- private Style style;
-
- private Set<CDOID> newIDs, dirtyIDs, detachedIDs;
-
- private Set<CDOObject> missingObjects = new HashSet<CDOObject>();
-
- private StringBuilder exceptionMessage = new StringBuilder();
-
- public CommitIntegrityCheck(InternalCDOCommitContext commitContext)
- {
- this(commitContext, Style.EXCEPTION_FAST);
- }
-
- public CommitIntegrityCheck(InternalCDOCommitContext commitContext, Style style)
- {
- transaction = commitContext.getTransaction();
-
- CheckUtil.checkArg(style, "style");
- this.style = style;
-
- newIDs = commitContext.getNewObjects().keySet();
- dirtyIDs = commitContext.getDirtyObjects().keySet();
- detachedIDs = commitContext.getDetachedObjects().keySet();
- }
-
- public void check() throws CommitIntegrityException
- {
- // For new objects: ensure that their container is included,
- // as well as the targets of the new object's bidi references
- for (CDOID newID : newIDs)
- {
- CDOObject newObject = transaction.getObject(newID);
- checkContainerIncluded(newObject, "new");
- checkCurrentRefTargetsIncluded(newObject, "new");
- }
-
- // For detached objects: ensure that their former container is included,
- // as well as the targets of the detached object's bidi references
- for (CDOID detachedID : detachedIDs)
- {
- CDOObject detachedObject = transaction.getObject(detachedID);
- checkFormerContainerIncluded(detachedObject);
- checkFormerBidiRefTargetsIncluded(detachedObject, "detached");
- }
-
- // For dirty objects: if any of the deltas for the object, affect containment (i.e. object was moved)
- // or a bi-di reference, ensure that for containment, both the old and new containers are included,
- // (or that the child is included if we are considering the dirty parent),
- // and that for a bi-di reference, the object holding the other end of the bi-di is included,
- // as well as possibly the *former* object holding the other end.
- for (CDOID dirtyID : dirtyIDs)
- {
- CDOObject dirtyObject = transaction.getObject(dirtyID);
- analyzeRevisionDelta((InternalCDOObject)dirtyObject);
- }
-
- if (!missingObjects.isEmpty() && style == Style.EXCEPTION)
- {
- throw createException();
- }
- }
-
- public Set<? extends EObject> getMissingObjects()
- {
- return missingObjects;
- }
-
- private CDOID getContainerOrResourceID(InternalCDORevision revision)
- {
- CDOID containerOrResourceID = null;
- Object idOrObject = revision.getContainerID();
- if (idOrObject != null)
- {
- containerOrResourceID = (CDOID)transaction.convertObjectToID(idOrObject);
- }
-
- if (CDOIDUtil.isNull(containerOrResourceID))
- {
- idOrObject = revision.getResourceID();
- if (idOrObject != null)
- {
- containerOrResourceID = (CDOID)transaction.convertObjectToID(idOrObject);
- }
- }
-
- return containerOrResourceID;
- }
-
- private void analyzeRevisionDelta(InternalCDOObject dirtyObject) throws CommitIntegrityException
- {
- // Getting the deltas from the TX is not a good idea...
- // We better recompute a fresh delta:
- InternalCDORevision cleanRev = transaction.getCleanRevisions().get(dirtyObject);
- CheckUtil.checkNull(cleanRev, "Could not obtain clean revision for dirty object " + dirtyObject);
-
- InternalCDORevision dirtyRev = dirtyObject.cdoRevision();
- CDORevisionDelta rDelta = dirtyRev.compare(cleanRev);
-
- for (CDOFeatureDelta featureDelta : rDelta.getFeatureDeltas())
- {
- EStructuralFeature feat = featureDelta.getFeature();
- if (feat == CDOContainerFeatureDelta.CONTAINER_FEATURE)
- {
- // Three possibilities here:
- // 1. Object's container has changed
- // 2. Object's containment feature has changed
- // 3. Object's resource has changed
- // (or several of the above)
-
- // @1
- CDOID currentContainerID = (CDOID)transaction.convertObjectToID(dirtyRev.getContainerID());
- CDOID cleanContainerID = (CDOID)transaction.convertObjectToID(cleanRev.getContainerID());
- if (!CDOIDUtil.equals(currentContainerID, cleanContainerID))
- {
- if (currentContainerID != CDOID.NULL)
- {
- checkIncluded(currentContainerID, "container of moved", dirtyObject);
- }
-
- if (cleanContainerID != CDOID.NULL)
- {
- checkIncluded(cleanContainerID, "former container of moved", dirtyObject);
- }
- }
-
- // @2
- // Nothing to be done. (I think...)
-
- // @3
- CDOID currentResourceID = (CDOID)transaction.convertObjectToID(dirtyRev.getResourceID());
- CDOID cleanResourceID = (CDOID)transaction.convertObjectToID(cleanRev.getResourceID());
- if (!CDOIDUtil.equals(currentResourceID, cleanResourceID))
- {
- if (currentResourceID != CDOID.NULL)
- {
- checkIncluded(currentResourceID, "resource of moved", dirtyObject);
- }
-
- if (cleanResourceID != CDOID.NULL)
- {
- checkIncluded(cleanResourceID, "former resource of moved", dirtyObject);
- }
- }
- }
- else if (feat instanceof EReference)
- {
- if (featureDelta instanceof CDOListFeatureDelta)
- {
- for (CDOFeatureDelta innerFeatDelta : ((CDOListFeatureDelta)featureDelta).getListChanges())
- {
- checkFeatureDelta(innerFeatDelta, dirtyObject);
- }
- }
- else
- {
- checkFeatureDelta(featureDelta, dirtyObject);
- }
- }
- }
- }
-
- private void checkIncluded(Object idOrObject, String msg, CDOObject o) throws CommitIntegrityException
- {
- idOrObject = transaction.convertObjectToID(idOrObject);
- if (idOrObject instanceof CDOID)
- {
- CDOID id = (CDOID)idOrObject;
- if (!id.isNull())
- {
- checkIncluded(id, msg, o);
- }
- }
-
- // else: Transient object -- ignore
- }
-
- private void checkFeatureDelta(CDOFeatureDelta featureDelta, CDOObject dirtyObject) throws CommitIntegrityException
- {
- EReference ref = (EReference)featureDelta.getFeature();
- boolean containmentOrWithOpposite = ref.isContainment() || hasPersistentOpposite(ref);
-
- if (featureDelta instanceof CDOAddFeatureDelta)
- {
- Object idOrObject = ((CDOAddFeatureDelta)featureDelta).getValue();
- if (containmentOrWithOpposite || isNew(idOrObject))
- {
- checkIncluded(idOrObject, "added child / refTarget of", dirtyObject);
- }
- }
- else if (featureDelta instanceof CDOSetFeatureDelta)
- {
- Object oldIDOrObject = ((CDOSetFeatureDelta)featureDelta).getOldValue();
- CDOID oldID = (CDOID)transaction.convertObjectToID(oldIDOrObject);
- if (!CDOIDUtil.isNull(oldID))
- {
- // Old child must be included if it's the container or has an eOpposite
- if (containmentOrWithOpposite)
- {
- checkIncluded(oldID, "removed / former child / refTarget of", dirtyObject);
- }
- }
-
- Object newIDOrObject = ((CDOSetFeatureDelta)featureDelta).getValue();
- if (newIDOrObject != null)
- {
- // New child must be included
- newIDOrObject = transaction.convertObjectToID(newIDOrObject);
- if (containmentOrWithOpposite || isNew(newIDOrObject))
- {
- checkIncluded(newIDOrObject, "new child / refTarget of", dirtyObject);
- }
- }
- }
- else if (containmentOrWithOpposite)
- {
- if (featureDelta instanceof CDORemoveFeatureDelta)
- {
- Object idOrObject = ((CDORemoveFeatureDelta)featureDelta).getValue();
- CDOID id = (CDOID)transaction.convertObjectToID(idOrObject);
- checkIncluded(id, "removed child / refTarget of", dirtyObject);
- }
- else if (featureDelta instanceof CDOClearFeatureDelta)
- {
- EStructuralFeature feat = ((CDOClearFeatureDelta)featureDelta).getFeature();
- InternalCDORevision cleanRev = transaction.getCleanRevisions().get(dirtyObject);
- int n = cleanRev.size(feat);
- for (int i = 0; i < n; i++)
- {
- Object idOrObject = cleanRev.get(feat, i);
- CDOID id = (CDOID)transaction.convertObjectToID(idOrObject);
- checkIncluded(id, "removed child / refTarget of", dirtyObject);
- }
- }
- else if (featureDelta instanceof CDOUnsetFeatureDelta)
- {
- EStructuralFeature feat = ((CDOUnsetFeatureDelta)featureDelta).getFeature();
- InternalCDORevision cleanRev = transaction.getCleanRevisions().get(dirtyObject);
- Object idOrObject = cleanRev.getValue(feat);
- CDOID id = (CDOID)transaction.convertObjectToID(idOrObject);
- checkIncluded(id, "removed child / refTarget of", dirtyObject);
- }
- else if (featureDelta instanceof CDOMoveFeatureDelta)
- {
- // Nothing to do: a move doesn't affect the child being moved
- // so that child does not need to be included
- }
- else
- {
- throw new IllegalArgumentException("Unexpected delta type: " + featureDelta.getClass().getSimpleName());
- }
- }
- }
-
- private boolean isNew(Object idOrObject)
- {
- CDOObject object = null;
- if (idOrObject instanceof CDOObject)
- {
- object = (CDOObject)idOrObject;
- }
- else if (idOrObject instanceof EObject)
- {
- object = CDOUtil.getCDOObject((EObject)idOrObject);
- }
- else if (idOrObject instanceof CDOID)
- {
- object = transaction.getObject((CDOID)idOrObject);
- }
-
- if (object != null)
- {
- return object.cdoState() == CDOState.NEW;
- }
-
- return false;
- }
-
- private void checkIncluded(CDOID id, String msg, CDOObject o) throws CommitIntegrityException
- {
- if (id.isNull())
- {
- throw new IllegalArgumentException("CDOID must not be NULL");
- }
-
- if (!dirtyIDs.contains(id) && !detachedIDs.contains(id) && !newIDs.contains(id))
- {
- CDOObject missingObject = transaction.getObject(id);
- if (missingObject == null)
- {
- throw new IllegalStateException("Could not find object for CDOID " + id);
- }
-
- missingObjects.add(missingObject);
-
- if (exceptionMessage.length() > 0)
- {
- exceptionMessage.append('\n');
- }
-
- String m = String.format("The %s object %s needs to be included in the commit but isn't", msg, o);
- exceptionMessage.append(m);
-
- if (style == Style.EXCEPTION_FAST)
- {
- throw createException();
- }
- }
- }
-
- private CommitIntegrityException createException()
- {
- return new CommitIntegrityException(exceptionMessage.toString(), missingObjects);
- }
-
- /**
- * Checks whether the container of a given object is included in the commit
- */
- private void checkContainerIncluded(CDOObject object, String msgFrag) throws CommitIntegrityException
- {
- EObject eContainer = object.eContainer();
- if (eContainer == null)
- {
- // It's a top-level object
- CDOResource resource = object.cdoDirectResource();
- checkIncluded(resource.cdoID(), "resource of " + msgFrag, object);
- }
- else
- {
- CDOObject container = CDOUtil.getCDOObject(eContainer);
- checkIncluded(container.cdoID(), "container of " + msgFrag, object);
- }
- }
-
- private void checkCurrentRefTargetsIncluded(CDOObject referencer, String msgFrag) throws CommitIntegrityException
- {
- for (EReference eRef : referencer.eClass().getEAllReferences())
- {
- if (EMFUtil.isPersistent(eRef))
- {
- if (eRef.isMany())
- {
- EList<?> list = (EList<?>)referencer.eGet(eRef);
- for (Object refTarget : list)
- {
- checkBidiRefTargetOrNewNonBidiTargetIncluded(referencer, eRef, refTarget, msgFrag);
- }
- }
- else
- {
- Object refTarget = referencer.eGet(eRef);
- if (refTarget != null)
- {
- checkBidiRefTargetOrNewNonBidiTargetIncluded(referencer, eRef, refTarget, msgFrag);
- }
- }
- }
- }
- }
-
- private void checkBidiRefTargetOrNewNonBidiTargetIncluded(CDOObject referencer, EReference eRef, Object refTarget,
- String msgFrag) throws CommitIntegrityException
- {
- if (hasPersistentOpposite(eRef))
- {
- // It's a bi-di ref; the target must definitely be included
- checkBidiRefTargetIncluded(refTarget, referencer, eRef.getName(), msgFrag);
- }
- else if (isNew(refTarget))
- {
- // It's a non-bidi ref; the target doesn't have to be included unless it's NEW
- checkIncluded(refTarget, "target of reference '" + eRef.getName() + "' of " + msgFrag, referencer);
- }
- }
-
- private void checkFormerBidiRefTargetsIncluded(CDOObject referencer, String msgFrag) throws CommitIntegrityException
- {
- // The referencer argument should really be a detached object, and so we know
- // that we can find the pre-detach revision in tx.getFormerRevisions(). However,
- // the object may have already been dirty prior to detachment, so we check the
- // clean revisions first.
- InternalCDORevision cleanRev = transaction.getCleanRevisions().get(referencer);
- CheckUtil.checkState(cleanRev, "cleanRev");
-
- for (EReference eRef : referencer.eClass().getEAllReferences())
- {
- if (EMFUtil.isPersistent(eRef) && hasPersistentOpposite(eRef))
- {
- Object value = cleanRev.get(eRef, EStore.NO_INDEX);
- if (value != null)
- {
- if (eRef.isMany())
- {
- EList<?> list = (EList<?>)value;
- for (Object element : list)
- {
- checkBidiRefTargetIncluded(element, referencer, eRef.getName(), msgFrag);
- }
- }
- else
- {
- checkBidiRefTargetIncluded(value, referencer, eRef.getName(), msgFrag);
- }
- }
- }
- }
- }
-
- private void checkBidiRefTargetIncluded(Object refTarget, CDOObject referencer, String refName, String msgFrag)
- throws CommitIntegrityException
- {
- CheckUtil.checkArg(refTarget, "refTarget");
- CDOID refTargetID = null;
- if (refTarget instanceof EObject)
- {
- refTargetID = CDOUtil.getCDOObject((EObject)refTarget).cdoID();
- if (refTargetID == null)
- {
- // No ID, means object is TRANSIENT; ignore.
- return;
- }
- }
- else if (refTarget instanceof CDOID)
- {
- refTargetID = (CDOID)refTarget;
- }
-
- checkIncluded(refTargetID, "target of reference '" + refName + "' of " + msgFrag, referencer);
- }
-
- private void checkFormerContainerIncluded(CDOObject detachedObject) throws CommitIntegrityException
- {
- InternalCDORevision rev = transaction.getCleanRevisions().get(detachedObject);
- CheckUtil.checkNull(rev, "Could not obtain clean revision for detached object " + detachedObject);
-
- CDOID id = getContainerOrResourceID(rev);
- checkIncluded(id, "former container (or resource) of detached", detachedObject);
- }
-
- private static boolean hasPersistentOpposite(EReference ref)
- {
- EReference eOpposite = ref.getEOpposite();
- return eOpposite != null && EMFUtil.isPersistent(eOpposite);
- }
-
- /**
- * Designates an exception style for a {@link CommitIntegrityCheck}
- *
- * @author Caspar De Groot
- */
- public static enum Style
- {
- /**
- * Throw an exception as soon as this {@link CommitIntegrityCheck} encounters the first problem
- */
- EXCEPTION_FAST,
-
- /**
- * Throw an exception when this {@link CommitIntegrityCheck} finishes performing all possible checks, in case any
- * problems were found
- */
- EXCEPTION,
-
- /**
- * Do not throw an exception. Caller must invoke {@link CommitIntegrityCheck#getMissingObjects()} to find out if the
- * check discovered any problems.
- */
- NO_EXCEPTION
- }
-}
+/* + * Copyright (c) 2004 - 2012 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: + * Caspar De Groot - initial API and implementation + */ +package org.eclipse.emf.internal.cdo.util; + +import org.eclipse.emf.cdo.CDOObject; +import org.eclipse.emf.cdo.CDOState; +import org.eclipse.emf.cdo.common.id.CDOID; +import org.eclipse.emf.cdo.common.id.CDOIDUtil; +import org.eclipse.emf.cdo.common.model.EMFUtil; +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; +import org.eclipse.emf.cdo.common.revision.delta.CDOFeatureDelta; +import org.eclipse.emf.cdo.common.revision.delta.CDOListFeatureDelta; +import org.eclipse.emf.cdo.common.revision.delta.CDOMoveFeatureDelta; +import org.eclipse.emf.cdo.common.revision.delta.CDORemoveFeatureDelta; +import org.eclipse.emf.cdo.common.revision.delta.CDORevisionDelta; +import org.eclipse.emf.cdo.common.revision.delta.CDOSetFeatureDelta; +import org.eclipse.emf.cdo.common.revision.delta.CDOUnsetFeatureDelta; +import org.eclipse.emf.cdo.eresource.CDOResource; +import org.eclipse.emf.cdo.spi.common.revision.InternalCDORevision; +import org.eclipse.emf.cdo.util.CDOUtil; +import org.eclipse.emf.cdo.util.CommitIntegrityException; + +import org.eclipse.net4j.util.CheckUtil; + +import org.eclipse.emf.common.util.EList; +import org.eclipse.emf.ecore.EObject; +import org.eclipse.emf.ecore.EReference; +import org.eclipse.emf.ecore.EStructuralFeature; +import org.eclipse.emf.ecore.InternalEObject.EStore; +import org.eclipse.emf.spi.cdo.InternalCDOObject; +import org.eclipse.emf.spi.cdo.InternalCDOTransaction; +import org.eclipse.emf.spi.cdo.InternalCDOTransaction.InternalCDOCommitContext; + +import java.util.HashSet; +import java.util.Set; + +/** + * @author Caspar De Groot + * @since 4.0 + */ +public class CommitIntegrityCheck +{ + private InternalCDOTransaction transaction; + + private Style style; + + private Set<CDOID> newIDs, dirtyIDs, detachedIDs; + + private Set<CDOObject> missingObjects = new HashSet<CDOObject>(); + + private StringBuilder exceptionMessage = new StringBuilder(); + + public CommitIntegrityCheck(InternalCDOCommitContext commitContext) + { + this(commitContext, Style.EXCEPTION_FAST); + } + + public CommitIntegrityCheck(InternalCDOCommitContext commitContext, Style style) + { + transaction = commitContext.getTransaction(); + + CheckUtil.checkArg(style, "style"); + this.style = style; + + newIDs = commitContext.getNewObjects().keySet(); + dirtyIDs = commitContext.getDirtyObjects().keySet(); + detachedIDs = commitContext.getDetachedObjects().keySet(); + } + + public void check() throws CommitIntegrityException + { + // For new objects: ensure that their container is included, + // as well as the targets of the new object's bidi references + for (CDOID newID : newIDs) + { + CDOObject newObject = transaction.getObject(newID); + checkContainerIncluded(newObject, "new"); + checkCurrentRefTargetsIncluded(newObject, "new"); + } + + // For detached objects: ensure that their former container is included, + // as well as the targets of the detached object's bidi references + for (CDOID detachedID : detachedIDs) + { + CDOObject detachedObject = transaction.getObject(detachedID); + checkFormerContainerIncluded(detachedObject); + checkFormerBidiRefTargetsIncluded(detachedObject, "detached"); + } + + // For dirty objects: if any of the deltas for the object, affect containment (i.e. object was moved) + // or a bi-di reference, ensure that for containment, both the old and new containers are included, + // (or that the child is included if we are considering the dirty parent), + // and that for a bi-di reference, the object holding the other end of the bi-di is included, + // as well as possibly the *former* object holding the other end. + for (CDOID dirtyID : dirtyIDs) + { + CDOObject dirtyObject = transaction.getObject(dirtyID); + analyzeRevisionDelta((InternalCDOObject)dirtyObject); + } + + if (!missingObjects.isEmpty() && style == Style.EXCEPTION) + { + throw createException(); + } + } + + public Set<? extends EObject> getMissingObjects() + { + return missingObjects; + } + + private CDOID getContainerOrResourceID(InternalCDORevision revision) + { + CDOID containerOrResourceID = null; + Object idOrObject = revision.getContainerID(); + if (idOrObject != null) + { + containerOrResourceID = (CDOID)transaction.convertObjectToID(idOrObject); + } + + if (CDOIDUtil.isNull(containerOrResourceID)) + { + idOrObject = revision.getResourceID(); + if (idOrObject != null) + { + containerOrResourceID = (CDOID)transaction.convertObjectToID(idOrObject); + } + } + + return containerOrResourceID; + } + + private void analyzeRevisionDelta(InternalCDOObject dirtyObject) throws CommitIntegrityException + { + // Getting the deltas from the TX is not a good idea... + // We better recompute a fresh delta: + InternalCDORevision cleanRev = transaction.getCleanRevisions().get(dirtyObject); + CheckUtil.checkNull(cleanRev, "Could not obtain clean revision for dirty object " + dirtyObject); + + InternalCDORevision dirtyRev = dirtyObject.cdoRevision(); + CDORevisionDelta rDelta = dirtyRev.compare(cleanRev); + + for (CDOFeatureDelta featureDelta : rDelta.getFeatureDeltas()) + { + EStructuralFeature feat = featureDelta.getFeature(); + if (feat == CDOContainerFeatureDelta.CONTAINER_FEATURE) + { + // Three possibilities here: + // 1. Object's container has changed + // 2. Object's containment feature has changed + // 3. Object's resource has changed + // (or several of the above) + + // @1 + CDOID currentContainerID = (CDOID)transaction.convertObjectToID(dirtyRev.getContainerID()); + CDOID cleanContainerID = (CDOID)transaction.convertObjectToID(cleanRev.getContainerID()); + if (!CDOIDUtil.equals(currentContainerID, cleanContainerID)) + { + if (currentContainerID != CDOID.NULL) + { + checkIncluded(currentContainerID, "container of moved", dirtyObject); + } + + if (cleanContainerID != CDOID.NULL) + { + checkIncluded(cleanContainerID, "former container of moved", dirtyObject); + } + } + + // @2 + // Nothing to be done. (I think...) + + // @3 + CDOID currentResourceID = (CDOID)transaction.convertObjectToID(dirtyRev.getResourceID()); + CDOID cleanResourceID = (CDOID)transaction.convertObjectToID(cleanRev.getResourceID()); + if (!CDOIDUtil.equals(currentResourceID, cleanResourceID)) + { + if (currentResourceID != CDOID.NULL) + { + checkIncluded(currentResourceID, "resource of moved", dirtyObject); + } + + if (cleanResourceID != CDOID.NULL) + { + checkIncluded(cleanResourceID, "former resource of moved", dirtyObject); + } + } + } + else if (feat instanceof EReference) + { + if (featureDelta instanceof CDOListFeatureDelta) + { + for (CDOFeatureDelta innerFeatDelta : ((CDOListFeatureDelta)featureDelta).getListChanges()) + { + checkFeatureDelta(innerFeatDelta, dirtyObject); + } + } + else + { + checkFeatureDelta(featureDelta, dirtyObject); + } + } + } + } + + private void checkIncluded(Object idOrObject, String msg, CDOObject o) throws CommitIntegrityException + { + idOrObject = transaction.convertObjectToID(idOrObject); + if (idOrObject instanceof CDOID) + { + CDOID id = (CDOID)idOrObject; + if (!id.isNull()) + { + checkIncluded(id, msg, o); + } + } + + // else: Transient object -- ignore + } + + private void checkFeatureDelta(CDOFeatureDelta featureDelta, CDOObject dirtyObject) throws CommitIntegrityException + { + EReference ref = (EReference)featureDelta.getFeature(); + boolean containmentOrWithOpposite = ref.isContainment() || hasPersistentOpposite(ref); + + if (featureDelta instanceof CDOAddFeatureDelta) + { + Object idOrObject = ((CDOAddFeatureDelta)featureDelta).getValue(); + if (containmentOrWithOpposite || isNew(idOrObject)) + { + checkIncluded(idOrObject, "added child / refTarget of", dirtyObject); + } + } + else if (featureDelta instanceof CDOSetFeatureDelta) + { + Object oldIDOrObject = ((CDOSetFeatureDelta)featureDelta).getOldValue(); + CDOID oldID = (CDOID)transaction.convertObjectToID(oldIDOrObject); + if (!CDOIDUtil.isNull(oldID)) + { + // Old child must be included if it's the container or has an eOpposite + if (containmentOrWithOpposite) + { + checkIncluded(oldID, "removed / former child / refTarget of", dirtyObject); + } + } + + Object newIDOrObject = ((CDOSetFeatureDelta)featureDelta).getValue(); + if (newIDOrObject != null) + { + // New child must be included + newIDOrObject = transaction.convertObjectToID(newIDOrObject); + if (containmentOrWithOpposite || isNew(newIDOrObject)) + { + checkIncluded(newIDOrObject, "new child / refTarget of", dirtyObject); + } + } + } + else if (containmentOrWithOpposite) + { + if (featureDelta instanceof CDORemoveFeatureDelta) + { + Object idOrObject = ((CDORemoveFeatureDelta)featureDelta).getValue(); + CDOID id = (CDOID)transaction.convertObjectToID(idOrObject); + checkIncluded(id, "removed child / refTarget of", dirtyObject); + } + else if (featureDelta instanceof CDOClearFeatureDelta) + { + EStructuralFeature feat = ((CDOClearFeatureDelta)featureDelta).getFeature(); + InternalCDORevision cleanRev = transaction.getCleanRevisions().get(dirtyObject); + int n = cleanRev.size(feat); + for (int i = 0; i < n; i++) + { + Object idOrObject = cleanRev.get(feat, i); + CDOID id = (CDOID)transaction.convertObjectToID(idOrObject); + checkIncluded(id, "removed child / refTarget of", dirtyObject); + } + } + else if (featureDelta instanceof CDOUnsetFeatureDelta) + { + EStructuralFeature feat = ((CDOUnsetFeatureDelta)featureDelta).getFeature(); + InternalCDORevision cleanRev = transaction.getCleanRevisions().get(dirtyObject); + Object idOrObject = cleanRev.getValue(feat); + CDOID id = (CDOID)transaction.convertObjectToID(idOrObject); + checkIncluded(id, "removed child / refTarget of", dirtyObject); + } + else if (featureDelta instanceof CDOMoveFeatureDelta) + { + // Nothing to do: a move doesn't affect the child being moved + // so that child does not need to be included + } + else + { + throw new IllegalArgumentException("Unexpected delta type: " + featureDelta.getClass().getSimpleName()); + } + } + } + + private boolean isNew(Object idOrObject) + { + CDOObject object = null; + if (idOrObject instanceof CDOObject) + { + object = (CDOObject)idOrObject; + } + else if (idOrObject instanceof EObject) + { + object = CDOUtil.getCDOObject((EObject)idOrObject); + } + else if (idOrObject instanceof CDOID) + { + object = transaction.getObject((CDOID)idOrObject); + } + + if (object != null) + { + return object.cdoState() == CDOState.NEW; + } + + return false; + } + + private void checkIncluded(CDOID id, String msg, CDOObject o) throws CommitIntegrityException + { + if (id.isNull()) + { + throw new IllegalArgumentException("CDOID must not be NULL"); + } + + if (!dirtyIDs.contains(id) && !detachedIDs.contains(id) && !newIDs.contains(id)) + { + CDOObject missingObject = transaction.getObject(id); + if (missingObject == null) + { + throw new IllegalStateException("Could not find object for CDOID " + id); + } + + missingObjects.add(missingObject); + + if (exceptionMessage.length() > 0) + { + exceptionMessage.append('\n'); + } + + String m = String.format("The %s object %s needs to be included in the commit but isn't", msg, o); + exceptionMessage.append(m); + + if (style == Style.EXCEPTION_FAST) + { + throw createException(); + } + } + } + + private CommitIntegrityException createException() + { + return new CommitIntegrityException(exceptionMessage.toString(), missingObjects); + } + + /** + * Checks whether the container of a given object is included in the commit + */ + private void checkContainerIncluded(CDOObject object, String msgFrag) throws CommitIntegrityException + { + EObject eContainer = object.eContainer(); + if (eContainer == null) + { + // It's a top-level object + CDOResource resource = object.cdoDirectResource(); + checkIncluded(resource.cdoID(), "resource of " + msgFrag, object); + } + else + { + CDOObject container = CDOUtil.getCDOObject(eContainer); + checkIncluded(container.cdoID(), "container of " + msgFrag, object); + } + } + + private void checkCurrentRefTargetsIncluded(CDOObject referencer, String msgFrag) throws CommitIntegrityException + { + for (EReference eRef : referencer.eClass().getEAllReferences()) + { + if (EMFUtil.isPersistent(eRef)) + { + if (eRef.isMany()) + { + EList<?> list = (EList<?>)referencer.eGet(eRef); + for (Object refTarget : list) + { + checkBidiRefTargetOrNewNonBidiTargetIncluded(referencer, eRef, refTarget, msgFrag); + } + } + else + { + Object refTarget = referencer.eGet(eRef); + if (refTarget != null) + { + checkBidiRefTargetOrNewNonBidiTargetIncluded(referencer, eRef, refTarget, msgFrag); + } + } + } + } + } + + private void checkBidiRefTargetOrNewNonBidiTargetIncluded(CDOObject referencer, EReference eRef, Object refTarget, + String msgFrag) throws CommitIntegrityException + { + if (hasPersistentOpposite(eRef)) + { + // It's a bi-di ref; the target must definitely be included + checkBidiRefTargetIncluded(refTarget, referencer, eRef.getName(), msgFrag); + } + else if (isNew(refTarget)) + { + // It's a non-bidi ref; the target doesn't have to be included unless it's NEW + checkIncluded(refTarget, "target of reference '" + eRef.getName() + "' of " + msgFrag, referencer); + } + } + + private void checkFormerBidiRefTargetsIncluded(CDOObject referencer, String msgFrag) throws CommitIntegrityException + { + // The referencer argument should really be a detached object, and so we know + // that we can find the pre-detach revision in tx.getFormerRevisions(). However, + // the object may have already been dirty prior to detachment, so we check the + // clean revisions first. + InternalCDORevision cleanRev = transaction.getCleanRevisions().get(referencer); + CheckUtil.checkState(cleanRev, "cleanRev"); + + for (EReference eRef : referencer.eClass().getEAllReferences()) + { + if (EMFUtil.isPersistent(eRef) && hasPersistentOpposite(eRef)) + { + Object value = cleanRev.get(eRef, EStore.NO_INDEX); + if (value != null) + { + if (eRef.isMany()) + { + EList<?> list = (EList<?>)value; + for (Object element : list) + { + checkBidiRefTargetIncluded(element, referencer, eRef.getName(), msgFrag); + } + } + else + { + checkBidiRefTargetIncluded(value, referencer, eRef.getName(), msgFrag); + } + } + } + } + } + + private void checkBidiRefTargetIncluded(Object refTarget, CDOObject referencer, String refName, String msgFrag) + throws CommitIntegrityException + { + CheckUtil.checkArg(refTarget, "refTarget"); + CDOID refTargetID = null; + if (refTarget instanceof EObject) + { + refTargetID = CDOUtil.getCDOObject((EObject)refTarget).cdoID(); + if (refTargetID == null) + { + // No ID, means object is TRANSIENT; ignore. + return; + } + } + else if (refTarget instanceof CDOID) + { + refTargetID = (CDOID)refTarget; + } + + checkIncluded(refTargetID, "target of reference '" + refName + "' of " + msgFrag, referencer); + } + + private void checkFormerContainerIncluded(CDOObject detachedObject) throws CommitIntegrityException + { + InternalCDORevision rev = transaction.getCleanRevisions().get(detachedObject); + CheckUtil.checkNull(rev, "Could not obtain clean revision for detached object " + detachedObject); + + CDOID id = getContainerOrResourceID(rev); + checkIncluded(id, "former container (or resource) of detached", detachedObject); + } + + private static boolean hasPersistentOpposite(EReference ref) + { + EReference eOpposite = ref.getEOpposite(); + return eOpposite != null && EMFUtil.isPersistent(eOpposite); + } + + /** + * Designates an exception style for a {@link CommitIntegrityCheck} + * + * @author Caspar De Groot + */ + public static enum Style + { + /** + * Throw an exception as soon as this {@link CommitIntegrityCheck} encounters the first problem + */ + EXCEPTION_FAST, + + /** + * Throw an exception when this {@link CommitIntegrityCheck} finishes performing all possible checks, in case any + * problems were found + */ + EXCEPTION, + + /** + * Do not throw an exception. Caller must invoke {@link CommitIntegrityCheck#getMissingObjects()} to find out if the + * check discovered any problems. + */ + NO_EXCEPTION + } +} diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/util/CompletePackageClosure.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/util/CompletePackageClosure.java index c59f5f7971..b17adde7b3 100644 --- a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/util/CompletePackageClosure.java +++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/util/CompletePackageClosure.java @@ -1,189 +1,189 @@ -/*
- * Copyright (c) 2004 - 2012 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
- * Simon McDuff - bug 246442
- */
-package org.eclipse.emf.internal.cdo.util;
-
-import org.eclipse.emf.internal.cdo.bundle.OM;
-import org.eclipse.emf.internal.cdo.messages.Messages;
-
-import org.eclipse.net4j.util.om.trace.ContextTracer;
-
-import org.eclipse.emf.common.util.EList;
-import org.eclipse.emf.ecore.EClass;
-import org.eclipse.emf.ecore.EClassifier;
-import org.eclipse.emf.ecore.EGenericType;
-import org.eclipse.emf.ecore.EOperation;
-import org.eclipse.emf.ecore.EPackage;
-import org.eclipse.emf.ecore.EParameter;
-import org.eclipse.emf.ecore.EStructuralFeature;
-import org.eclipse.emf.ecore.ETypeParameter;
-import org.eclipse.emf.ecore.EcorePackage;
-
-import java.text.MessageFormat;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Set;
-
-/**
- * @author Eike Stepper
- */
-public class CompletePackageClosure extends PackageClosure
-{
- private static final ContextTracer TRACER = new ContextTracer(OM.DEBUG_MODEL, CompletePackageClosure.class);
-
- private boolean excludeEcore;
-
- private Set<EPackage> visitedPackages;
-
- public CompletePackageClosure()
- {
- }
-
- public CompletePackageClosure(boolean excludeEcore)
- {
- this.excludeEcore = excludeEcore;
- }
-
- @Override
- protected void handleEPackage(EPackage ePackage, Set<EPackage> visitedPackages)
- {
- if (ePackage != null && visitedPackages.add(ePackage))
- {
- if (excludeEcore && // Optimize EPackage comparison
- (EcorePackage.eINSTANCE == ePackage || EcorePackage.eNS_URI.equals(ePackage.getNsURI())))
- {
- return;
- }
-
- this.visitedPackages = visitedPackages;
- Set<EClassifier> visitedClassifiers = new HashSet<EClassifier>();
- for (EClassifier classifier : ePackage.getEClassifiers())
- {
- handleEClassifier(classifier, visitedClassifiers);
- }
-
- for (EClassifier classifier : visitedClassifiers)
- {
- final EPackage p = classifier.getEPackage();
- if (p != null)
- {
- if (visitedPackages.add(p))
- {
- if (TRACER.isEnabled())
- {
- TRACER.trace("Found package " + p.getNsURI()); //$NON-NLS-1$
- }
- }
- }
- else
- {
- OM.LOG.warn(MessageFormat.format(Messages.getString("CompletePackageClosure.0"), classifier.getName())); //$NON-NLS-1$
- }
- }
- }
- }
-
- protected void handleEClassifier(EClassifier classifier, Set<EClassifier> visited)
- {
- if (classifier != null && visited.add(classifier))
- {
- handleEPackage(classifier.getEPackage(), visitedPackages);
- handleETypeParameters(classifier.getETypeParameters(), visited);
- if (classifier instanceof EClass)
- {
- EClass eClass = (EClass)classifier;
- handleEStructuralFeatures(eClass.getEStructuralFeatures(), visited);
- handleEOperations(eClass.getEOperations(), visited);
- handleEGenericTypes(eClass.getEGenericSuperTypes(), visited);
- }
- }
- }
-
- protected void handleEStructuralFeatures(List<EStructuralFeature> structuralFeatures, Set<EClassifier> visited)
- {
- if (structuralFeatures != null)
- {
- for (EStructuralFeature structuralFeature : structuralFeatures)
- {
- handleEGenericType(structuralFeature.getEGenericType(), visited);
- }
- }
- }
-
- protected void handleEOperations(List<EOperation> operations, Set<EClassifier> visited)
- {
- if (operations != null)
- {
- for (EOperation operation : operations)
- {
- handleEGenericType(operation.getEGenericType(), visited);
- handleETypeParameters(operation.getETypeParameters(), visited);
- handleEParameters(operation.getEParameters(), visited);
- handleEGenericTypes(operation.getEGenericExceptions(), visited);
- }
- }
- }
-
- protected void handleEParameters(List<EParameter> parameters, Set<EClassifier> visited)
- {
- if (parameters != null)
- {
- for (EParameter parameter : parameters)
- {
- handleEClassifier(parameter.getEType(), visited);
- handleEGenericType(parameter.getEGenericType(), visited);
- }
- }
- }
-
- protected void handleEGenericTypes(EList<EGenericType> genericTypes, Set<EClassifier> visited)
- {
- if (genericTypes != null)
- {
- for (EGenericType genericType : genericTypes)
- {
- handleEGenericType(genericType, visited);
- }
- }
- }
-
- protected void handleEGenericType(EGenericType genericType, Set<EClassifier> visited)
- {
- if (genericType != null)
- {
- handleEClassifier(genericType.getEClassifier(), visited);
- handleEClassifier(genericType.getERawType(), visited);
- handleEGenericType(genericType.getELowerBound(), visited);
- handleEGenericType(genericType.getEUpperBound(), visited);
- handleEGenericTypes(genericType.getETypeArguments(), visited);
- handleETypeParameter(genericType.getETypeParameter(), visited);
- }
- }
-
- protected void handleETypeParameters(EList<ETypeParameter> typeParameters, Set<EClassifier> visited)
- {
- if (typeParameters != null)
- {
- for (ETypeParameter typeParameter : typeParameters)
- {
- handleETypeParameter(typeParameter, visited);
- }
- }
- }
-
- protected void handleETypeParameter(ETypeParameter typeParameter, Set<EClassifier> visited)
- {
- if (typeParameter != null)
- {
- handleEGenericTypes(typeParameter.getEBounds(), visited);
- }
- }
-}
+/* + * Copyright (c) 2004 - 2012 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 + * Simon McDuff - bug 246442 + */ +package org.eclipse.emf.internal.cdo.util; + +import org.eclipse.emf.internal.cdo.bundle.OM; +import org.eclipse.emf.internal.cdo.messages.Messages; + +import org.eclipse.net4j.util.om.trace.ContextTracer; + +import org.eclipse.emf.common.util.EList; +import org.eclipse.emf.ecore.EClass; +import org.eclipse.emf.ecore.EClassifier; +import org.eclipse.emf.ecore.EGenericType; +import org.eclipse.emf.ecore.EOperation; +import org.eclipse.emf.ecore.EPackage; +import org.eclipse.emf.ecore.EParameter; +import org.eclipse.emf.ecore.EStructuralFeature; +import org.eclipse.emf.ecore.ETypeParameter; +import org.eclipse.emf.ecore.EcorePackage; + +import java.text.MessageFormat; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +/** + * @author Eike Stepper + */ +public class CompletePackageClosure extends PackageClosure +{ + private static final ContextTracer TRACER = new ContextTracer(OM.DEBUG_MODEL, CompletePackageClosure.class); + + private boolean excludeEcore; + + private Set<EPackage> visitedPackages; + + public CompletePackageClosure() + { + } + + public CompletePackageClosure(boolean excludeEcore) + { + this.excludeEcore = excludeEcore; + } + + @Override + protected void handleEPackage(EPackage ePackage, Set<EPackage> visitedPackages) + { + if (ePackage != null && visitedPackages.add(ePackage)) + { + if (excludeEcore && // Optimize EPackage comparison + (EcorePackage.eINSTANCE == ePackage || EcorePackage.eNS_URI.equals(ePackage.getNsURI()))) + { + return; + } + + this.visitedPackages = visitedPackages; + Set<EClassifier> visitedClassifiers = new HashSet<EClassifier>(); + for (EClassifier classifier : ePackage.getEClassifiers()) + { + handleEClassifier(classifier, visitedClassifiers); + } + + for (EClassifier classifier : visitedClassifiers) + { + final EPackage p = classifier.getEPackage(); + if (p != null) + { + if (visitedPackages.add(p)) + { + if (TRACER.isEnabled()) + { + TRACER.trace("Found package " + p.getNsURI()); //$NON-NLS-1$ + } + } + } + else + { + OM.LOG.warn(MessageFormat.format(Messages.getString("CompletePackageClosure.0"), classifier.getName())); //$NON-NLS-1$ + } + } + } + } + + protected void handleEClassifier(EClassifier classifier, Set<EClassifier> visited) + { + if (classifier != null && visited.add(classifier)) + { + handleEPackage(classifier.getEPackage(), visitedPackages); + handleETypeParameters(classifier.getETypeParameters(), visited); + if (classifier instanceof EClass) + { + EClass eClass = (EClass)classifier; + handleEStructuralFeatures(eClass.getEStructuralFeatures(), visited); + handleEOperations(eClass.getEOperations(), visited); + handleEGenericTypes(eClass.getEGenericSuperTypes(), visited); + } + } + } + + protected void handleEStructuralFeatures(List<EStructuralFeature> structuralFeatures, Set<EClassifier> visited) + { + if (structuralFeatures != null) + { + for (EStructuralFeature structuralFeature : structuralFeatures) + { + handleEGenericType(structuralFeature.getEGenericType(), visited); + } + } + } + + protected void handleEOperations(List<EOperation> operations, Set<EClassifier> visited) + { + if (operations != null) + { + for (EOperation operation : operations) + { + handleEGenericType(operation.getEGenericType(), visited); + handleETypeParameters(operation.getETypeParameters(), visited); + handleEParameters(operation.getEParameters(), visited); + handleEGenericTypes(operation.getEGenericExceptions(), visited); + } + } + } + + protected void handleEParameters(List<EParameter> parameters, Set<EClassifier> visited) + { + if (parameters != null) + { + for (EParameter parameter : parameters) + { + handleEClassifier(parameter.getEType(), visited); + handleEGenericType(parameter.getEGenericType(), visited); + } + } + } + + protected void handleEGenericTypes(EList<EGenericType> genericTypes, Set<EClassifier> visited) + { + if (genericTypes != null) + { + for (EGenericType genericType : genericTypes) + { + handleEGenericType(genericType, visited); + } + } + } + + protected void handleEGenericType(EGenericType genericType, Set<EClassifier> visited) + { + if (genericType != null) + { + handleEClassifier(genericType.getEClassifier(), visited); + handleEClassifier(genericType.getERawType(), visited); + handleEGenericType(genericType.getELowerBound(), visited); + handleEGenericType(genericType.getEUpperBound(), visited); + handleEGenericTypes(genericType.getETypeArguments(), visited); + handleETypeParameter(genericType.getETypeParameter(), visited); + } + } + + protected void handleETypeParameters(EList<ETypeParameter> typeParameters, Set<EClassifier> visited) + { + if (typeParameters != null) + { + for (ETypeParameter typeParameter : typeParameters) + { + handleETypeParameter(typeParameter, visited); + } + } + } + + protected void handleETypeParameter(ETypeParameter typeParameter, Set<EClassifier> visited) + { + if (typeParameter != null) + { + handleEGenericTypes(typeParameter.getEBounds(), visited); + } + } +} diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/util/CrossReferencesPackageClosure.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/util/CrossReferencesPackageClosure.java index 579505e188..9753823a92 100644 --- a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/util/CrossReferencesPackageClosure.java +++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/util/CrossReferencesPackageClosure.java @@ -1,61 +1,61 @@ -/*
- * Copyright (c) 2004 - 2012 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.internal.cdo.util;
-
-import org.eclipse.emf.common.util.EList;
-import org.eclipse.emf.ecore.EObject;
-import org.eclipse.emf.ecore.EPackage;
-
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.Set;
-
-/**
- * @author Eike Stepper
- */
-public class CrossReferencesPackageClosure extends PackageClosure
-{
- public CrossReferencesPackageClosure()
- {
- }
-
- @Override
- public Set<EPackage> calculate(EPackage ePackage)
- {
- Set<EPackage> visited = new HashSet<EPackage>();
- handleEPackage(ePackage, visited);
- return visited;
- }
-
- @Override
- protected void handleEPackage(EPackage ePackage, Set<EPackage> visited)
- {
- visited.add(ePackage);
- for (Iterator<EObject> it = ePackage.eAllContents(); it.hasNext();)
- {
- EObject content = it.next();
- collectCrossReferences(content, visited);
- }
- }
-
- protected void collectCrossReferences(EObject content, Set<EPackage> visited)
- {
- EList<EObject> crossReferences = content.eCrossReferences();
- for (EObject crossReference : crossReferences)
- {
- EPackage crossReferencePackage = crossReference.eClass().getEPackage();
- if (!visited.contains(crossReferencePackage))
- {
- handleEPackage(crossReferencePackage, visited);
- }
- }
- }
-}
+/* + * Copyright (c) 2004 - 2012 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.internal.cdo.util; + +import org.eclipse.emf.common.util.EList; +import org.eclipse.emf.ecore.EObject; +import org.eclipse.emf.ecore.EPackage; + +import java.util.HashSet; +import java.util.Iterator; +import java.util.Set; + +/** + * @author Eike Stepper + */ +public class CrossReferencesPackageClosure extends PackageClosure +{ + public CrossReferencesPackageClosure() + { + } + + @Override + public Set<EPackage> calculate(EPackage ePackage) + { + Set<EPackage> visited = new HashSet<EPackage>(); + handleEPackage(ePackage, visited); + return visited; + } + + @Override + protected void handleEPackage(EPackage ePackage, Set<EPackage> visited) + { + visited.add(ePackage); + for (Iterator<EObject> it = ePackage.eAllContents(); it.hasNext();) + { + EObject content = it.next(); + collectCrossReferences(content, visited); + } + } + + protected void collectCrossReferences(EObject content, Set<EPackage> visited) + { + EList<EObject> crossReferences = content.eCrossReferences(); + for (EObject crossReference : crossReferences) + { + EPackage crossReferencePackage = crossReference.eClass().getEPackage(); + if (!visited.contains(crossReferencePackage)) + { + handleEPackage(crossReferencePackage, visited); + } + } + } +} diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/util/DefaultLocksChangedEvent.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/util/DefaultLocksChangedEvent.java index fd354ccf3c..3059929057 100644 --- a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/util/DefaultLocksChangedEvent.java +++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/util/DefaultLocksChangedEvent.java @@ -1,82 +1,82 @@ -/*
- * Copyright (c) 2004 - 2012 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.internal.cdo.util;
-
-import org.eclipse.emf.cdo.common.branch.CDOBranch;
-import org.eclipse.emf.cdo.common.lock.CDOLockChangeInfo;
-import org.eclipse.emf.cdo.common.lock.CDOLockOwner;
-import org.eclipse.emf.cdo.common.lock.CDOLockState;
-
-import org.eclipse.net4j.util.concurrent.IRWLockManager.LockType;
-import org.eclipse.net4j.util.event.Event;
-import org.eclipse.net4j.util.event.INotifier;
-
-import org.eclipse.emf.spi.cdo.InternalCDOView;
-
-/**
- * @author Caspar De Groot
- * @since 4.1
- */
-public class DefaultLocksChangedEvent extends Event implements CDOLockChangeInfo
-{
- private static final long serialVersionUID = 1L;
-
- private final InternalCDOView sender;
-
- private final CDOLockChangeInfo lockChangeInfo;
-
- public DefaultLocksChangedEvent(INotifier notifier, InternalCDOView sender, CDOLockChangeInfo lockChangeInfo)
- {
- super(notifier);
- this.sender = sender;
- this.lockChangeInfo = lockChangeInfo;
- }
-
- public InternalCDOView getSender()
- {
- return sender;
- }
-
- public CDOBranch getBranch()
- {
- return lockChangeInfo.getBranch();
- }
-
- public long getTimeStamp()
- {
- return lockChangeInfo.getTimeStamp();
- }
-
- public CDOLockOwner getLockOwner()
- {
- return lockChangeInfo.getLockOwner();
- }
-
- public CDOLockState[] getLockStates()
- {
- return lockChangeInfo.getLockStates();
- }
-
- public Operation getOperation()
- {
- return lockChangeInfo.getOperation();
- }
-
- public LockType getLockType()
- {
- return lockChangeInfo.getLockType();
- }
-
- public boolean isInvalidateAll()
- {
- return lockChangeInfo.isInvalidateAll();
- }
-}
+/* + * Copyright (c) 2004 - 2012 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.internal.cdo.util; + +import org.eclipse.emf.cdo.common.branch.CDOBranch; +import org.eclipse.emf.cdo.common.lock.CDOLockChangeInfo; +import org.eclipse.emf.cdo.common.lock.CDOLockOwner; +import org.eclipse.emf.cdo.common.lock.CDOLockState; + +import org.eclipse.net4j.util.concurrent.IRWLockManager.LockType; +import org.eclipse.net4j.util.event.Event; +import org.eclipse.net4j.util.event.INotifier; + +import org.eclipse.emf.spi.cdo.InternalCDOView; + +/** + * @author Caspar De Groot + * @since 4.1 + */ +public class DefaultLocksChangedEvent extends Event implements CDOLockChangeInfo +{ + private static final long serialVersionUID = 1L; + + private final InternalCDOView sender; + + private final CDOLockChangeInfo lockChangeInfo; + + public DefaultLocksChangedEvent(INotifier notifier, InternalCDOView sender, CDOLockChangeInfo lockChangeInfo) + { + super(notifier); + this.sender = sender; + this.lockChangeInfo = lockChangeInfo; + } + + public InternalCDOView getSender() + { + return sender; + } + + public CDOBranch getBranch() + { + return lockChangeInfo.getBranch(); + } + + public long getTimeStamp() + { + return lockChangeInfo.getTimeStamp(); + } + + public CDOLockOwner getLockOwner() + { + return lockChangeInfo.getLockOwner(); + } + + public CDOLockState[] getLockStates() + { + return lockChangeInfo.getLockStates(); + } + + public Operation getOperation() + { + return lockChangeInfo.getOperation(); + } + + public LockType getLockType() + { + return lockChangeInfo.getLockType(); + } + + public boolean isInvalidateAll() + { + return lockChangeInfo.isInvalidateAll(); + } +} diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/util/IPackageClosure.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/util/IPackageClosure.java index 3591bc989f..a2459884ef 100644 --- a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/util/IPackageClosure.java +++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/util/IPackageClosure.java @@ -1,29 +1,29 @@ -/*
- * Copyright (c) 2004 - 2012 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.internal.cdo.util;
-
-import org.eclipse.emf.ecore.EPackage;
-
-import java.util.Collection;
-import java.util.Collections;
-import java.util.Set;
-
-/**
- * @author Eike Stepper
- */
-public interface IPackageClosure
-{
- public static final Set<EPackage> EMPTY_CLOSURE = Collections.emptySet();
-
- public Set<EPackage> calculate(Collection<EPackage> ePackages);
-
- public Set<EPackage> calculate(EPackage ePackage);
-}
+/* + * Copyright (c) 2004 - 2012 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.internal.cdo.util; + +import org.eclipse.emf.ecore.EPackage; + +import java.util.Collection; +import java.util.Collections; +import java.util.Set; + +/** + * @author Eike Stepper + */ +public interface IPackageClosure +{ + public static final Set<EPackage> EMPTY_CLOSURE = Collections.emptySet(); + + public Set<EPackage> calculate(Collection<EPackage> ePackages); + + public Set<EPackage> calculate(EPackage ePackage); +} diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/util/PackageClosure.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/util/PackageClosure.java index 20dbfe0c84..bfcdffb04a 100644 --- a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/util/PackageClosure.java +++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/util/PackageClosure.java @@ -1,73 +1,73 @@ -/*
- * Copyright (c) 2004 - 2012 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
- * Simon McDuff - maintenance
- */
-package org.eclipse.emf.internal.cdo.util;
-
-import org.eclipse.emf.internal.cdo.bundle.OM;
-
-import org.eclipse.net4j.util.om.trace.ContextTracer;
-
-import org.eclipse.emf.ecore.EPackage;
-
-import java.util.Collection;
-import java.util.Collections;
-import java.util.HashSet;
-import java.util.Set;
-
-/**
- * @author Eike Stepper
- */
-public abstract class PackageClosure implements IPackageClosure
-{
- private static final ContextTracer TRACER = new ContextTracer(OM.DEBUG_MODEL, PackageClosure.class);
-
- protected PackageClosure()
- {
- }
-
- public Set<EPackage> calculate(EPackage ePackage)
- {
- return calculate(Collections.singletonList(ePackage));
- }
-
- public Set<EPackage> calculate(Collection<EPackage> ePackages)
- {
- // Optimize no packages
- if (ePackages.isEmpty())
- {
- return EMPTY_CLOSURE;
- }
-
- Set<EPackage> visited = new HashSet<EPackage>();
- for (EPackage ePackage : ePackages)
- {
- doCollectContents(ePackage, visited);
- }
-
- return visited;
- }
-
- private void doCollectContents(EPackage ePackage, Set<EPackage> visited)
- {
- if (TRACER.isEnabled())
- {
- TRACER.trace("Package closure for " + ePackage.getNsURI()); //$NON-NLS-1$
- }
-
- handleEPackage(ePackage, visited);
- for (EPackage subPackage : ePackage.getESubpackages())
- {
- doCollectContents(subPackage, visited);
- }
- }
-
- protected abstract void handleEPackage(EPackage ePackage, Set<EPackage> visited);
-}
+/* + * Copyright (c) 2004 - 2012 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 + * Simon McDuff - maintenance + */ +package org.eclipse.emf.internal.cdo.util; + +import org.eclipse.emf.internal.cdo.bundle.OM; + +import org.eclipse.net4j.util.om.trace.ContextTracer; + +import org.eclipse.emf.ecore.EPackage; + +import java.util.Collection; +import java.util.Collections; +import java.util.HashSet; +import java.util.Set; + +/** + * @author Eike Stepper + */ +public abstract class PackageClosure implements IPackageClosure +{ + private static final ContextTracer TRACER = new ContextTracer(OM.DEBUG_MODEL, PackageClosure.class); + + protected PackageClosure() + { + } + + public Set<EPackage> calculate(EPackage ePackage) + { + return calculate(Collections.singletonList(ePackage)); + } + + public Set<EPackage> calculate(Collection<EPackage> ePackages) + { + // Optimize no packages + if (ePackages.isEmpty()) + { + return EMPTY_CLOSURE; + } + + Set<EPackage> visited = new HashSet<EPackage>(); + for (EPackage ePackage : ePackages) + { + doCollectContents(ePackage, visited); + } + + return visited; + } + + private void doCollectContents(EPackage ePackage, Set<EPackage> visited) + { + if (TRACER.isEnabled()) + { + TRACER.trace("Package closure for " + ePackage.getNsURI()); //$NON-NLS-1$ + } + + handleEPackage(ePackage, visited); + for (EPackage subPackage : ePackage.getESubpackages()) + { + doCollectContents(subPackage, visited); + } + } + + protected abstract void handleEPackage(EPackage ePackage, Set<EPackage> visited); +} diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/view/CDORevisionPrefetchingPolicyImpl.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/view/CDORevisionPrefetchingPolicyImpl.java index d4c7bca03f..1dc1751e3d 100644 --- a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/view/CDORevisionPrefetchingPolicyImpl.java +++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/view/CDORevisionPrefetchingPolicyImpl.java @@ -1,75 +1,75 @@ -/*
- * Copyright (c) 2004 - 2012 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:
- * Simon McDuff - initial API and implementation
- * Eike Stepper - maintenance
- */
-package org.eclipse.emf.internal.cdo.view;
-
-import org.eclipse.emf.cdo.common.branch.CDOBranchPoint;
-import org.eclipse.emf.cdo.common.id.CDOID;
-import org.eclipse.emf.cdo.common.revision.CDOList;
-import org.eclipse.emf.cdo.common.revision.CDORevisionManager;
-import org.eclipse.emf.cdo.view.CDORevisionPrefetchingPolicy;
-
-import org.eclipse.emf.ecore.EObject;
-import org.eclipse.emf.ecore.EStructuralFeature;
-
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Set;
-
-/**
- * @author Simon McDuff
- * @since 2.0
- */
-public class CDORevisionPrefetchingPolicyImpl implements CDORevisionPrefetchingPolicy
-{
- private int chunkSize;
-
- public CDORevisionPrefetchingPolicyImpl(int chunkSize)
- {
- this.chunkSize = chunkSize;
- }
-
- public List<CDOID> loadAhead(CDORevisionManager revisionManager, CDOBranchPoint branchPoint, EObject eObject,
- EStructuralFeature feature, CDOList list, int accessIndex, CDOID accessID)
- {
- if (chunkSize > 1 && !revisionManager.containsRevision(accessID, branchPoint))
- {
- int fromIndex = accessIndex;
- int toIndex = Math.min(accessIndex + chunkSize, list.size()) - 1;
-
- Set<CDOID> notRegistered = new HashSet<CDOID>();
- for (int i = fromIndex; i <= toIndex; i++)
- {
- Object element = list.get(i);
- if (element instanceof CDOID)
- {
- CDOID idElement = (CDOID)element;
- if (!idElement.isTemporary() && !idElement.isExternal())
- {
- if (!revisionManager.containsRevision(idElement, branchPoint))
- {
- if (!notRegistered.contains(idElement))
- {
- notRegistered.add(idElement);
- }
- }
- }
- }
- }
-
- return new ArrayList<CDOID>(notRegistered);
- }
-
- return Collections.emptyList();
- }
-}
+/* + * Copyright (c) 2004 - 2012 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: + * Simon McDuff - initial API and implementation + * Eike Stepper - maintenance + */ +package org.eclipse.emf.internal.cdo.view; + +import org.eclipse.emf.cdo.common.branch.CDOBranchPoint; +import org.eclipse.emf.cdo.common.id.CDOID; +import org.eclipse.emf.cdo.common.revision.CDOList; +import org.eclipse.emf.cdo.common.revision.CDORevisionManager; +import org.eclipse.emf.cdo.view.CDORevisionPrefetchingPolicy; + +import org.eclipse.emf.ecore.EObject; +import org.eclipse.emf.ecore.EStructuralFeature; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +/** + * @author Simon McDuff + * @since 2.0 + */ +public class CDORevisionPrefetchingPolicyImpl implements CDORevisionPrefetchingPolicy +{ + private int chunkSize; + + public CDORevisionPrefetchingPolicyImpl(int chunkSize) + { + this.chunkSize = chunkSize; + } + + public List<CDOID> loadAhead(CDORevisionManager revisionManager, CDOBranchPoint branchPoint, EObject eObject, + EStructuralFeature feature, CDOList list, int accessIndex, CDOID accessID) + { + if (chunkSize > 1 && !revisionManager.containsRevision(accessID, branchPoint)) + { + int fromIndex = accessIndex; + int toIndex = Math.min(accessIndex + chunkSize, list.size()) - 1; + + Set<CDOID> notRegistered = new HashSet<CDOID>(); + for (int i = fromIndex; i <= toIndex; i++) + { + Object element = list.get(i); + if (element instanceof CDOID) + { + CDOID idElement = (CDOID)element; + if (!idElement.isTemporary() && !idElement.isExternal()) + { + if (!revisionManager.containsRevision(idElement, branchPoint)) + { + if (!notRegistered.contains(idElement)) + { + notRegistered.add(idElement); + } + } + } + } + } + + return new ArrayList<CDOID>(notRegistered); + } + + return Collections.emptyList(); + } +} diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/view/CDOViewProviderRegistryImpl.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/view/CDOViewProviderRegistryImpl.java index 36498e5789..38580f4f9e 100644 --- a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/view/CDOViewProviderRegistryImpl.java +++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/view/CDOViewProviderRegistryImpl.java @@ -1,271 +1,271 @@ -/*
- * Copyright (c) 2004 - 2012 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:
- * Victor Roldan Betancort - initial API and implementation
- * Eike Stepper - maintenance
- */
-package org.eclipse.emf.internal.cdo.view;
-
-import org.eclipse.emf.cdo.util.CDOURIUtil;
-import org.eclipse.emf.cdo.util.CDOUtil;
-import org.eclipse.emf.cdo.view.AbstractCDOViewProvider;
-import org.eclipse.emf.cdo.view.CDOView;
-import org.eclipse.emf.cdo.view.CDOViewProvider;
-import org.eclipse.emf.cdo.view.CDOViewProviderRegistry;
-import org.eclipse.emf.cdo.view.CDOViewSet;
-
-import org.eclipse.emf.internal.cdo.bundle.OM;
-import org.eclipse.emf.internal.cdo.messages.Messages;
-
-import org.eclipse.net4j.util.StringUtil;
-import org.eclipse.net4j.util.WrappedException;
-import org.eclipse.net4j.util.collection.Pair;
-import org.eclipse.net4j.util.container.Container;
-import org.eclipse.net4j.util.om.OMPlatform;
-
-import org.eclipse.emf.common.util.URI;
-import org.eclipse.emf.ecore.resource.ResourceSet;
-
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.IConfigurationElement;
-import org.eclipse.core.runtime.IExtensionRegistry;
-import org.eclipse.core.runtime.Platform;
-
-import java.text.MessageFormat;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.Comparator;
-import java.util.List;
-
-/**
- * When instanced in Eclipse, it's populated with contributions from the viewProvider Extension Point. A default
- * CDOViewProvider implementation is registered, regardless of the execution environment.
- *
- * @author Victor Roldan Betancort
- * @since 2.0
- * @see CDOViewProvider
- */
-public class CDOViewProviderRegistryImpl extends Container<CDOViewProvider> implements CDOViewProviderRegistry
-{
- public static final CDOViewProviderRegistryImpl INSTANCE = new CDOViewProviderRegistryImpl();
-
- private static final String EXT_POINT = "viewProviders"; //$NON-NLS-1$
-
- private List<CDOViewProvider> viewProviders = new ArrayList<CDOViewProvider>();
-
- public CDOViewProviderRegistryImpl()
- {
- addViewProvider(PluginContainerViewProvider.INSTANCE);
- }
-
- public CDOView provideView(URI uri, ResourceSet resourceSet)
- {
- Pair<CDOView, CDOViewProvider> pair = provideViewWithInfo(uri, resourceSet);
- if (pair == null)
- {
- return null;
- }
-
- return pair.getElement1();
- }
-
- public Pair<CDOView, CDOViewProvider> provideViewWithInfo(URI uri, ResourceSet resourceSet)
- {
- if (uri == null)
- {
- return null;
- }
-
- CDOViewSet viewSet = CDOUtil.getViewSet(resourceSet);
- if (viewSet != null)
- {
- try
- {
- String uuid = CDOURIUtil.extractRepositoryUUID(uri);
- CDOView view = viewSet.resolveView(uuid);
- if (view != null)
- {
- return new Pair<CDOView, CDOViewProvider>(view, null);
- }
- }
- catch (Exception ignore)
- {
- // Do nothing
- }
- }
-
- for (CDOViewProvider viewProvider : getViewProviders(uri))
- {
- CDOView view = viewProvider.getView(uri, resourceSet);
- if (view != null)
- {
- return new Pair<CDOView, CDOViewProvider>(view, viewProvider);
- }
- }
-
- return null;
- }
-
- public CDOViewProvider[] getViewProviders(URI uri)
- {
- List<CDOViewProvider> result = new ArrayList<CDOViewProvider>();
- for (CDOViewProvider viewProvider : viewProviders)
- {
- if (viewProvider.matchesRegex(uri))
- {
- result.add(viewProvider);
- }
- }
-
- // Sort highest priority first
- Collections.sort(result, new Comparator<CDOViewProvider>()
- {
- public int compare(CDOViewProvider o1, CDOViewProvider o2)
- {
- return -Integer.valueOf(o1.getPriority()).compareTo(o2.getPriority());
- }
- });
-
- return result.toArray(new CDOViewProvider[result.size()]);
- }
-
- public boolean hasViewProvider(CDOViewProvider viewProvider)
- {
- synchronized (viewProviders)
- {
- return viewProviders.contains(viewProvider);
- }
- }
-
- public void addViewProvider(CDOViewProvider viewProvider)
- {
- boolean added;
- synchronized (viewProviders)
- {
- added = !viewProviders.contains(viewProvider);
- if (added)
- {
- viewProviders.add(viewProvider);
- }
- }
-
- if (added)
- {
- fireElementAddedEvent(viewProvider);
- }
- }
-
- public void removeViewProvider(CDOViewProvider viewProvider)
- {
- boolean removed;
- synchronized (viewProviders)
- {
- removed = viewProviders.remove(viewProvider);
- }
-
- if (removed)
- {
- fireElementRemovedEvent(viewProvider);
- }
- }
-
- public CDOViewProvider[] getElements()
- {
- synchronized (viewProviders)
- {
- return viewProviders.toArray(new CDOViewProvider[viewProviders.size()]);
- }
- }
-
- @Override
- public boolean isEmpty()
- {
- synchronized (viewProviders)
- {
- return viewProviders.isEmpty();
- }
- }
-
- @Override
- protected void doActivate() throws Exception
- {
- super.doActivate();
- if (OMPlatform.INSTANCE.isOSGiRunning())
- {
- try
- {
- readExtensions();
- }
- catch (Throwable t)
- {
- OM.LOG.error(t);
- }
- }
- }
-
- public void readExtensions()
- {
- IExtensionRegistry registry = Platform.getExtensionRegistry();
- IConfigurationElement[] configurationElements = registry.getConfigurationElementsFor(OM.BUNDLE_ID, EXT_POINT);
- for (IConfigurationElement element : configurationElements)
- {
- try
- {
- CDOViewProviderDescriptor descriptor = new CDOViewProviderDescriptor(element);
- addViewProvider(descriptor);
- }
- catch (Exception ex)
- {
- OM.LOG.error(ex);
- }
- }
- }
-
- /**
- * @author Eike Stepper
- */
- public static final class CDOViewProviderDescriptor extends AbstractCDOViewProvider
- {
- private IConfigurationElement element;
-
- public CDOViewProviderDescriptor(IConfigurationElement element)
- {
- super(element.getAttribute("regex"), Integer.parseInt(element.getAttribute("priority"))); //$NON-NLS-1$ //$NON-NLS-2$
- this.element = element;
-
- if (StringUtil.isEmpty(element.getAttribute("class"))) //$NON-NLS-1$
- {
- throw new IllegalArgumentException(MessageFormat.format(
- Messages.getString("CDOViewProviderRegistryImpl.4"), element)); //$NON-NLS-1$
- }
-
- if (StringUtil.isEmpty(element.getAttribute("regex"))) //$NON-NLS-1$
- {
- throw new IllegalArgumentException(MessageFormat.format(
- Messages.getString("CDOViewProviderRegistryImpl.6"), element)); //$NON-NLS-1$
- }
- }
-
- public CDOView getView(URI uri, ResourceSet resourceSet)
- {
- return getViewProvider().getView(uri, resourceSet);
- }
-
- private CDOViewProvider getViewProvider()
- {
- try
- {
- return (CDOViewProvider)element.createExecutableExtension("class"); //$NON-NLS-1$
- }
- catch (CoreException ex)
- {
- throw WrappedException.wrap(ex);
- }
- }
- }
-}
+/* + * Copyright (c) 2004 - 2012 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: + * Victor Roldan Betancort - initial API and implementation + * Eike Stepper - maintenance + */ +package org.eclipse.emf.internal.cdo.view; + +import org.eclipse.emf.cdo.util.CDOURIUtil; +import org.eclipse.emf.cdo.util.CDOUtil; +import org.eclipse.emf.cdo.view.AbstractCDOViewProvider; +import org.eclipse.emf.cdo.view.CDOView; +import org.eclipse.emf.cdo.view.CDOViewProvider; +import org.eclipse.emf.cdo.view.CDOViewProviderRegistry; +import org.eclipse.emf.cdo.view.CDOViewSet; + +import org.eclipse.emf.internal.cdo.bundle.OM; +import org.eclipse.emf.internal.cdo.messages.Messages; + +import org.eclipse.net4j.util.StringUtil; +import org.eclipse.net4j.util.WrappedException; +import org.eclipse.net4j.util.collection.Pair; +import org.eclipse.net4j.util.container.Container; +import org.eclipse.net4j.util.om.OMPlatform; + +import org.eclipse.emf.common.util.URI; +import org.eclipse.emf.ecore.resource.ResourceSet; + +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IConfigurationElement; +import org.eclipse.core.runtime.IExtensionRegistry; +import org.eclipse.core.runtime.Platform; + +import java.text.MessageFormat; +import java.util.ArrayList; +import java.util.Collections; +import java.util.Comparator; +import java.util.List; + +/** + * When instanced in Eclipse, it's populated with contributions from the viewProvider Extension Point. A default + * CDOViewProvider implementation is registered, regardless of the execution environment. + * + * @author Victor Roldan Betancort + * @since 2.0 + * @see CDOViewProvider + */ +public class CDOViewProviderRegistryImpl extends Container<CDOViewProvider> implements CDOViewProviderRegistry +{ + public static final CDOViewProviderRegistryImpl INSTANCE = new CDOViewProviderRegistryImpl(); + + private static final String EXT_POINT = "viewProviders"; //$NON-NLS-1$ + + private List<CDOViewProvider> viewProviders = new ArrayList<CDOViewProvider>(); + + public CDOViewProviderRegistryImpl() + { + addViewProvider(PluginContainerViewProvider.INSTANCE); + } + + public CDOView provideView(URI uri, ResourceSet resourceSet) + { + Pair<CDOView, CDOViewProvider> pair = provideViewWithInfo(uri, resourceSet); + if (pair == null) + { + return null; + } + + return pair.getElement1(); + } + + public Pair<CDOView, CDOViewProvider> provideViewWithInfo(URI uri, ResourceSet resourceSet) + { + if (uri == null) + { + return null; + } + + CDOViewSet viewSet = CDOUtil.getViewSet(resourceSet); + if (viewSet != null) + { + try + { + String uuid = CDOURIUtil.extractRepositoryUUID(uri); + CDOView view = viewSet.resolveView(uuid); + if (view != null) + { + return new Pair<CDOView, CDOViewProvider>(view, null); + } + } + catch (Exception ignore) + { + // Do nothing + } + } + + for (CDOViewProvider viewProvider : getViewProviders(uri)) + { + CDOView view = viewProvider.getView(uri, resourceSet); + if (view != null) + { + return new Pair<CDOView, CDOViewProvider>(view, viewProvider); + } + } + + return null; + } + + public CDOViewProvider[] getViewProviders(URI uri) + { + List<CDOViewProvider> result = new ArrayList<CDOViewProvider>(); + for (CDOViewProvider viewProvider : viewProviders) + { + if (viewProvider.matchesRegex(uri)) + { + result.add(viewProvider); + } + } + + // Sort highest priority first + Collections.sort(result, new Comparator<CDOViewProvider>() + { + public int compare(CDOViewProvider o1, CDOViewProvider o2) + { + return -Integer.valueOf(o1.getPriority()).compareTo(o2.getPriority()); + } + }); + + return result.toArray(new CDOViewProvider[result.size()]); + } + + public boolean hasViewProvider(CDOViewProvider viewProvider) + { + synchronized (viewProviders) + { + return viewProviders.contains(viewProvider); + } + } + + public void addViewProvider(CDOViewProvider viewProvider) + { + boolean added; + synchronized (viewProviders) + { + added = !viewProviders.contains(viewProvider); + if (added) + { + viewProviders.add(viewProvider); + } + } + + if (added) + { + fireElementAddedEvent(viewProvider); + } + } + + public void removeViewProvider(CDOViewProvider viewProvider) + { + boolean removed; + synchronized (viewProviders) + { + removed = viewProviders.remove(viewProvider); + } + + if (removed) + { + fireElementRemovedEvent(viewProvider); + } + } + + public CDOViewProvider[] getElements() + { + synchronized (viewProviders) + { + return viewProviders.toArray(new CDOViewProvider[viewProviders.size()]); + } + } + + @Override + public boolean isEmpty() + { + synchronized (viewProviders) + { + return viewProviders.isEmpty(); + } + } + + @Override + protected void doActivate() throws Exception + { + super.doActivate(); + if (OMPlatform.INSTANCE.isOSGiRunning()) + { + try + { + readExtensions(); + } + catch (Throwable t) + { + OM.LOG.error(t); + } + } + } + + public void readExtensions() + { + IExtensionRegistry registry = Platform.getExtensionRegistry(); + IConfigurationElement[] configurationElements = registry.getConfigurationElementsFor(OM.BUNDLE_ID, EXT_POINT); + for (IConfigurationElement element : configurationElements) + { + try + { + CDOViewProviderDescriptor descriptor = new CDOViewProviderDescriptor(element); + addViewProvider(descriptor); + } + catch (Exception ex) + { + OM.LOG.error(ex); + } + } + } + + /** + * @author Eike Stepper + */ + public static final class CDOViewProviderDescriptor extends AbstractCDOViewProvider + { + private IConfigurationElement element; + + public CDOViewProviderDescriptor(IConfigurationElement element) + { + super(element.getAttribute("regex"), Integer.parseInt(element.getAttribute("priority"))); //$NON-NLS-1$ //$NON-NLS-2$ + this.element = element; + + if (StringUtil.isEmpty(element.getAttribute("class"))) //$NON-NLS-1$ + { + throw new IllegalArgumentException(MessageFormat.format( + Messages.getString("CDOViewProviderRegistryImpl.4"), element)); //$NON-NLS-1$ + } + + if (StringUtil.isEmpty(element.getAttribute("regex"))) //$NON-NLS-1$ + { + throw new IllegalArgumentException(MessageFormat.format( + Messages.getString("CDOViewProviderRegistryImpl.6"), element)); //$NON-NLS-1$ + } + } + + public CDOView getView(URI uri, ResourceSet resourceSet) + { + return getViewProvider().getView(uri, resourceSet); + } + + private CDOViewProvider getViewProvider() + { + try + { + return (CDOViewProvider)element.createExecutableExtension("class"); //$NON-NLS-1$ + } + catch (CoreException ex) + { + throw WrappedException.wrap(ex); + } + } + } +} diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/view/CDOViewSetImpl.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/view/CDOViewSetImpl.java index b5495f481f..3c64a57c96 100644 --- a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/view/CDOViewSetImpl.java +++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/view/CDOViewSetImpl.java @@ -1,356 +1,356 @@ -/*
- * Copyright (c) 2004 - 2012 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:
- * Simon McDuff - initial API and implementation
- * Eike Stepper - maintenance
- * Victor Roldan Betancort - bug 338921
- */
-package org.eclipse.emf.internal.cdo.view;
-
-import org.eclipse.emf.cdo.CDOState;
-import org.eclipse.emf.cdo.common.protocol.CDOProtocolConstants;
-import org.eclipse.emf.cdo.common.util.CDOException;
-import org.eclipse.emf.cdo.eresource.CDOResource;
-import org.eclipse.emf.cdo.eresource.CDOResourceFactory;
-import org.eclipse.emf.cdo.view.CDOView;
-
-import org.eclipse.emf.internal.cdo.messages.Messages;
-
-import org.eclipse.net4j.util.WrappedException;
-
-import org.eclipse.emf.common.notify.Notification;
-import org.eclipse.emf.common.notify.Notifier;
-import org.eclipse.emf.common.notify.impl.NotificationImpl;
-import org.eclipse.emf.common.notify.impl.NotifierImpl;
-import org.eclipse.emf.ecore.EPackage;
-import org.eclipse.emf.ecore.resource.Resource;
-import org.eclipse.emf.ecore.resource.Resource.Factory.Registry;
-import org.eclipse.emf.ecore.resource.ResourceSet;
-import org.eclipse.emf.spi.cdo.InternalCDOObject;
-import org.eclipse.emf.spi.cdo.InternalCDOView;
-import org.eclipse.emf.spi.cdo.InternalCDOViewSet;
-
-import java.text.MessageFormat;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Map.Entry;
-import java.util.Set;
-import java.util.concurrent.Callable;
-
-/**
- * @author Simon McDuff
- * @since 2.0
- */
-public class CDOViewSetImpl extends NotifierImpl implements InternalCDOViewSet
-{
- private Set<InternalCDOView> views = new HashSet<InternalCDOView>();
-
- private Map<String, InternalCDOView> mapOfViews = new HashMap<String, InternalCDOView>();
-
- private CDOResourceFactory resourceFactory = CDOResourceFactory.INSTANCE;
-
- private CDOViewSetPackageRegistryImpl packageRegistry;
-
- private ResourceSet resourceSet;
-
- private ThreadLocal<Boolean> ignoreNotifications = new InheritableThreadLocal<Boolean>();
-
- public CDOViewSetImpl()
- {
- }
-
- public ResourceSet getResourceSet()
- {
- return resourceSet;
- }
-
- public EPackage.Registry getPackageRegistry()
- {
- return packageRegistry;
- }
-
- public CDOResourceFactory getResourceFactory()
- {
- return resourceFactory;
- }
-
- public CDOView[] getViews()
- {
- synchronized (views)
- {
- return views.toArray(new CDOView[views.size()]);
- }
- }
-
- /**
- * @throws IllegalArgumentException
- * if repositoryUUID doesn't match any CDOView.
- */
- public InternalCDOView resolveView(String repositoryUUID)
- {
- InternalCDOView view = null;
- synchronized (views)
- {
- view = mapOfViews.get(repositoryUUID);
- if (view == null)
- {
- if (repositoryUUID != null)
- {
- throw new IllegalArgumentException(MessageFormat.format(
- Messages.getString("CDOViewSetImpl.0"), repositoryUUID)); //$NON-NLS-1$
- }
-
- if (mapOfViews.size() == 1)
- {
- return views.iterator().next();
- }
-
- if (mapOfViews.size() == 0)
- {
- return null;
- }
-
- throw new IllegalStateException(Messages.getString("CDOViewSetImpl.1")); //$NON-NLS-1$
- }
- }
-
- return view;
- }
-
- public InternalCDOView getView(String repositoryUUID)
- {
- synchronized (views)
- {
- return mapOfViews.get(repositoryUUID);
- }
- }
-
- public void add(InternalCDOView view)
- {
- String repositoryUUID = view.getSession().getRepositoryInfo().getUUID();
- synchronized (views)
- {
- CDOView lookupView = mapOfViews.get(repositoryUUID);
- if (lookupView != null)
- {
- throw new RuntimeException(Messages.getString("CDOViewSetImpl.2")); //$NON-NLS-1$
- }
-
- views.add(view);
- mapOfViews.put(repositoryUUID, view);
- }
-
- if (eNotificationRequired())
- {
- NotificationImpl notification = new NotificationImpl(NotificationImpl.ADD, null, view);
- eNotify(notification);
- }
- }
-
- public void remove(InternalCDOView view)
- {
- String repositoryUUID = view.getSession().getRepositoryInfo().getUUID();
- List<Resource> resToRemove = new ArrayList<Resource>();
- synchronized (views)
- {
- // It is important to remove view from the list first. It is the way we can differentiate close and detach.
- views.remove(view);
- mapOfViews.remove(repositoryUUID);
-
- for (Resource resource : getResourceSet().getResources())
- {
- if (resource instanceof CDOResource)
- {
- CDOResource cdoRes = (CDOResource)resource;
- if (cdoRes.cdoView() == view)
- {
- resToRemove.add(resource);
- }
- }
- }
- }
-
- getResourceSet().getResources().removeAll(resToRemove);
- if (eNotificationRequired())
- {
- NotificationImpl notification = new NotificationImpl(NotificationImpl.REMOVE, view, null);
- eNotify(notification);
- }
- }
-
- public Notifier getTarget()
- {
- return resourceSet;
- }
-
- public void setTarget(Notifier newTarget)
- {
- if (!isAdapterForType(newTarget))
- {
- throw new IllegalArgumentException(MessageFormat.format(Messages.getString("CDOViewSetImpl.3"), newTarget)); //$NON-NLS-1$
- }
-
- if (resourceSet != null)
- {
- throw new IllegalStateException(Messages.getString("CDOViewSetImpl.4")); //$NON-NLS-1$
- }
-
- resourceSet = (ResourceSet)newTarget;
- EPackage.Registry oldPackageRegistry = resourceSet.getPackageRegistry();
- packageRegistry = new CDOViewSetPackageRegistryImpl(this, oldPackageRegistry);
- resourceSet.setPackageRegistry(packageRegistry);
-
- Registry registry = resourceSet.getResourceFactoryRegistry();
- Map<String, Object> map = registry.getProtocolToFactoryMap();
- map.put(CDOProtocolConstants.PROTOCOL_NAME, getResourceFactory());
- }
-
- public boolean isAdapterForType(Object type)
- {
- return type instanceof ResourceSet;
- }
-
- public synchronized <V> V executeWithoutNotificationHandling(Callable<V> callable)
- {
- Boolean wasIgnore = ignoreNotifications.get();
-
- try
- {
- ignoreNotifications.set(true);
- return callable.call();
- }
- catch (Exception ex)
- {
- throw WrappedException.wrap(ex);
- }
- finally
- {
- if (wasIgnore == null)
- {
- ignoreNotifications.remove();
- }
- }
- }
-
- public void notifyChanged(Notification notification)
- {
- // The resource <-> view association is done in CDOResourceImpl.basicSetResourceSet()
-
- if (ignoreNotifications.get() == null)
- {
- // We need to deregister CDOResources from CDOView if removed from the ResourceSet, see bug 338921
- switch (notification.getEventType())
- {
- case Notification.REMOVE_MANY:
- deregisterResources((List<?>)notification.getOldValue());
- break;
-
- case Notification.REMOVE:
- deregisterResources(Collections.singleton(notification.getOldValue()));
- break;
- }
- }
- }
-
- private void deregisterResources(Collection<?> potentialResources)
- {
- List<CDOResource> allDirtyResources = new ArrayList<CDOResource>();
-
- try
- {
- Map<CDOView, List<CDOResource>> resourcesPerView = getResourcesPerView(potentialResources);
-
- for (Entry<CDOView, List<CDOResource>> entry : resourcesPerView.entrySet())
- {
- InternalCDOView view = (InternalCDOView)entry.getKey();
- List<CDOResource> resources = entry.getValue();
-
- if (view.isDirty())
- {
- List<CDOResource> dirtyResources = getDirtyResources(resources);
- if (!dirtyResources.isEmpty())
- {
- allDirtyResources.addAll(dirtyResources);
- resourceSet.getResources().addAll(resources);
- continue;
- }
- }
-
- for (CDOResource resource : resources)
- {
- InternalCDOObject internalResource = (InternalCDOObject)resource;
- view.deregisterObject(internalResource);
- internalResource.cdoInternalSetState(CDOState.INVALID);
- }
- }
- }
- finally
- {
- int size = allDirtyResources.size();
- if (size == 1)
- {
- throw new CDOException("Attempt to remove a dirty resource from a resource set: " + allDirtyResources.get(0));
- }
- else if (size > 1)
- {
- throw new CDOException("Attempt to remove dirty resources from a resource set: " + allDirtyResources);
- }
- }
- }
-
- private List<CDOResource> getDirtyResources(List<CDOResource> resources)
- {
- List<CDOResource> dirtyResources = new ArrayList<CDOResource>();
- for (CDOResource resource : resources)
- {
- switch (resource.cdoState())
- {
- case NEW:
- case DIRTY:
- case CONFLICT:
- case INVALID_CONFLICT:
- dirtyResources.addAll(resources);
- }
- }
-
- return dirtyResources;
- }
-
- private Map<CDOView, List<CDOResource>> getResourcesPerView(Collection<?> potentialResources)
- {
- Map<CDOView, List<CDOResource>> resourcesPerView = new HashMap<CDOView, List<CDOResource>>();
-
- for (Object potentialResource : potentialResources)
- {
- if (potentialResource instanceof CDOResource)
- {
- CDOResource resource = (CDOResource)potentialResource;
- CDOView view = resource.cdoView();
-
- if (views.contains(view))
- {
- List<CDOResource> resources = resourcesPerView.get(view);
- if (resources == null)
- {
- resources = new ArrayList<CDOResource>();
- resourcesPerView.put(view, resources);
- }
-
- resources.add(resource);
- }
- }
- }
-
- return resourcesPerView;
- }
-}
+/* + * Copyright (c) 2004 - 2012 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: + * Simon McDuff - initial API and implementation + * Eike Stepper - maintenance + * Victor Roldan Betancort - bug 338921 + */ +package org.eclipse.emf.internal.cdo.view; + +import org.eclipse.emf.cdo.CDOState; +import org.eclipse.emf.cdo.common.protocol.CDOProtocolConstants; +import org.eclipse.emf.cdo.common.util.CDOException; +import org.eclipse.emf.cdo.eresource.CDOResource; +import org.eclipse.emf.cdo.eresource.CDOResourceFactory; +import org.eclipse.emf.cdo.view.CDOView; + +import org.eclipse.emf.internal.cdo.messages.Messages; + +import org.eclipse.net4j.util.WrappedException; + +import org.eclipse.emf.common.notify.Notification; +import org.eclipse.emf.common.notify.Notifier; +import org.eclipse.emf.common.notify.impl.NotificationImpl; +import org.eclipse.emf.common.notify.impl.NotifierImpl; +import org.eclipse.emf.ecore.EPackage; +import org.eclipse.emf.ecore.resource.Resource; +import org.eclipse.emf.ecore.resource.Resource.Factory.Registry; +import org.eclipse.emf.ecore.resource.ResourceSet; +import org.eclipse.emf.spi.cdo.InternalCDOObject; +import org.eclipse.emf.spi.cdo.InternalCDOView; +import org.eclipse.emf.spi.cdo.InternalCDOViewSet; + +import java.text.MessageFormat; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; +import java.util.Set; +import java.util.concurrent.Callable; + +/** + * @author Simon McDuff + * @since 2.0 + */ +public class CDOViewSetImpl extends NotifierImpl implements InternalCDOViewSet +{ + private Set<InternalCDOView> views = new HashSet<InternalCDOView>(); + + private Map<String, InternalCDOView> mapOfViews = new HashMap<String, InternalCDOView>(); + + private CDOResourceFactory resourceFactory = CDOResourceFactory.INSTANCE; + + private CDOViewSetPackageRegistryImpl packageRegistry; + + private ResourceSet resourceSet; + + private ThreadLocal<Boolean> ignoreNotifications = new InheritableThreadLocal<Boolean>(); + + public CDOViewSetImpl() + { + } + + public ResourceSet getResourceSet() + { + return resourceSet; + } + + public EPackage.Registry getPackageRegistry() + { + return packageRegistry; + } + + public CDOResourceFactory getResourceFactory() + { + return resourceFactory; + } + + public CDOView[] getViews() + { + synchronized (views) + { + return views.toArray(new CDOView[views.size()]); + } + } + + /** + * @throws IllegalArgumentException + * if repositoryUUID doesn't match any CDOView. + */ + public InternalCDOView resolveView(String repositoryUUID) + { + InternalCDOView view = null; + synchronized (views) + { + view = mapOfViews.get(repositoryUUID); + if (view == null) + { + if (repositoryUUID != null) + { + throw new IllegalArgumentException(MessageFormat.format( + Messages.getString("CDOViewSetImpl.0"), repositoryUUID)); //$NON-NLS-1$ + } + + if (mapOfViews.size() == 1) + { + return views.iterator().next(); + } + + if (mapOfViews.size() == 0) + { + return null; + } + + throw new IllegalStateException(Messages.getString("CDOViewSetImpl.1")); //$NON-NLS-1$ + } + } + + return view; + } + + public InternalCDOView getView(String repositoryUUID) + { + synchronized (views) + { + return mapOfViews.get(repositoryUUID); + } + } + + public void add(InternalCDOView view) + { + String repositoryUUID = view.getSession().getRepositoryInfo().getUUID(); + synchronized (views) + { + CDOView lookupView = mapOfViews.get(repositoryUUID); + if (lookupView != null) + { + throw new RuntimeException(Messages.getString("CDOViewSetImpl.2")); //$NON-NLS-1$ + } + + views.add(view); + mapOfViews.put(repositoryUUID, view); + } + + if (eNotificationRequired()) + { + NotificationImpl notification = new NotificationImpl(NotificationImpl.ADD, null, view); + eNotify(notification); + } + } + + public void remove(InternalCDOView view) + { + String repositoryUUID = view.getSession().getRepositoryInfo().getUUID(); + List<Resource> resToRemove = new ArrayList<Resource>(); + synchronized (views) + { + // It is important to remove view from the list first. It is the way we can differentiate close and detach. + views.remove(view); + mapOfViews.remove(repositoryUUID); + + for (Resource resource : getResourceSet().getResources()) + { + if (resource instanceof CDOResource) + { + CDOResource cdoRes = (CDOResource)resource; + if (cdoRes.cdoView() == view) + { + resToRemove.add(resource); + } + } + } + } + + getResourceSet().getResources().removeAll(resToRemove); + if (eNotificationRequired()) + { + NotificationImpl notification = new NotificationImpl(NotificationImpl.REMOVE, view, null); + eNotify(notification); + } + } + + public Notifier getTarget() + { + return resourceSet; + } + + public void setTarget(Notifier newTarget) + { + if (!isAdapterForType(newTarget)) + { + throw new IllegalArgumentException(MessageFormat.format(Messages.getString("CDOViewSetImpl.3"), newTarget)); //$NON-NLS-1$ + } + + if (resourceSet != null) + { + throw new IllegalStateException(Messages.getString("CDOViewSetImpl.4")); //$NON-NLS-1$ + } + + resourceSet = (ResourceSet)newTarget; + EPackage.Registry oldPackageRegistry = resourceSet.getPackageRegistry(); + packageRegistry = new CDOViewSetPackageRegistryImpl(this, oldPackageRegistry); + resourceSet.setPackageRegistry(packageRegistry); + + Registry registry = resourceSet.getResourceFactoryRegistry(); + Map<String, Object> map = registry.getProtocolToFactoryMap(); + map.put(CDOProtocolConstants.PROTOCOL_NAME, getResourceFactory()); + } + + public boolean isAdapterForType(Object type) + { + return type instanceof ResourceSet; + } + + public synchronized <V> V executeWithoutNotificationHandling(Callable<V> callable) + { + Boolean wasIgnore = ignoreNotifications.get(); + + try + { + ignoreNotifications.set(true); + return callable.call(); + } + catch (Exception ex) + { + throw WrappedException.wrap(ex); + } + finally + { + if (wasIgnore == null) + { + ignoreNotifications.remove(); + } + } + } + + public void notifyChanged(Notification notification) + { + // The resource <-> view association is done in CDOResourceImpl.basicSetResourceSet() + + if (ignoreNotifications.get() == null) + { + // We need to deregister CDOResources from CDOView if removed from the ResourceSet, see bug 338921 + switch (notification.getEventType()) + { + case Notification.REMOVE_MANY: + deregisterResources((List<?>)notification.getOldValue()); + break; + + case Notification.REMOVE: + deregisterResources(Collections.singleton(notification.getOldValue())); + break; + } + } + } + + private void deregisterResources(Collection<?> potentialResources) + { + List<CDOResource> allDirtyResources = new ArrayList<CDOResource>(); + + try + { + Map<CDOView, List<CDOResource>> resourcesPerView = getResourcesPerView(potentialResources); + + for (Entry<CDOView, List<CDOResource>> entry : resourcesPerView.entrySet()) + { + InternalCDOView view = (InternalCDOView)entry.getKey(); + List<CDOResource> resources = entry.getValue(); + + if (view.isDirty()) + { + List<CDOResource> dirtyResources = getDirtyResources(resources); + if (!dirtyResources.isEmpty()) + { + allDirtyResources.addAll(dirtyResources); + resourceSet.getResources().addAll(resources); + continue; + } + } + + for (CDOResource resource : resources) + { + InternalCDOObject internalResource = (InternalCDOObject)resource; + view.deregisterObject(internalResource); + internalResource.cdoInternalSetState(CDOState.INVALID); + } + } + } + finally + { + int size = allDirtyResources.size(); + if (size == 1) + { + throw new CDOException("Attempt to remove a dirty resource from a resource set: " + allDirtyResources.get(0)); + } + else if (size > 1) + { + throw new CDOException("Attempt to remove dirty resources from a resource set: " + allDirtyResources); + } + } + } + + private List<CDOResource> getDirtyResources(List<CDOResource> resources) + { + List<CDOResource> dirtyResources = new ArrayList<CDOResource>(); + for (CDOResource resource : resources) + { + switch (resource.cdoState()) + { + case NEW: + case DIRTY: + case CONFLICT: + case INVALID_CONFLICT: + dirtyResources.addAll(resources); + } + } + + return dirtyResources; + } + + private Map<CDOView, List<CDOResource>> getResourcesPerView(Collection<?> potentialResources) + { + Map<CDOView, List<CDOResource>> resourcesPerView = new HashMap<CDOView, List<CDOResource>>(); + + for (Object potentialResource : potentialResources) + { + if (potentialResource instanceof CDOResource) + { + CDOResource resource = (CDOResource)potentialResource; + CDOView view = resource.cdoView(); + + if (views.contains(view)) + { + List<CDOResource> resources = resourcesPerView.get(view); + if (resources == null) + { + resources = new ArrayList<CDOResource>(); + resourcesPerView.put(view, resources); + } + + resources.add(resource); + } + } + } + + return resourcesPerView; + } +} diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/view/CDOViewSetPackageRegistryImpl.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/view/CDOViewSetPackageRegistryImpl.java index 3447d58047..739db3f5b5 100644 --- a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/view/CDOViewSetPackageRegistryImpl.java +++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/view/CDOViewSetPackageRegistryImpl.java @@ -1,80 +1,80 @@ -/*
- * Copyright (c) 2004 - 2012 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:
- * Simon McDuff - initial API and implementation
- * Eike Stepper - maintenance
- */
-package org.eclipse.emf.internal.cdo.view;
-
-import org.eclipse.emf.cdo.view.CDOView;
-import org.eclipse.emf.cdo.view.CDOViewSet;
-
-import org.eclipse.emf.ecore.EPackage;
-import org.eclipse.emf.ecore.impl.EPackageRegistryImpl;
-
-/**
- * @author Simon McDuff
- */
-public class CDOViewSetPackageRegistryImpl extends EPackageRegistryImpl
-{
- private static final long serialVersionUID = 1L;
-
- private CDOViewSet viewSet;
-
- public CDOViewSetPackageRegistryImpl(CDOViewSet viewSet, EPackage.Registry delegateRegistry)
- {
- super(delegateRegistry);
- this.viewSet = viewSet;
- }
-
- @Override
- protected EPackage delegatedGetEPackage(String nsURI)
- {
- for (CDOView view : viewSet.getViews())
- {
- EPackage ePackage = view.getSession().getPackageRegistry().getEPackage(nsURI);
- if (ePackage != null)
- {
- return ePackage;
- }
- }
-
- return super.delegatedGetEPackage(nsURI);
- }
-
- @Override
- public Object put(String key, Object value)
- {
- super.put(key, value);
- for (CDOView view : viewSet.getViews())
- {
- view.getSession().getPackageRegistry().put(key, value);
- }
-
- return null;
- }
-
- @Override
- public synchronized Object get(Object key)
- {
- Object ePackage = super.get(key);
- if (ePackage == null)
- {
- for (CDOView view : viewSet.getViews())
- {
- ePackage = view.getSession().getPackageRegistry().get(key);
- if (ePackage != null)
- {
- return ePackage;
- }
- }
- }
-
- return ePackage;
- }
-}
+/* + * Copyright (c) 2004 - 2012 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: + * Simon McDuff - initial API and implementation + * Eike Stepper - maintenance + */ +package org.eclipse.emf.internal.cdo.view; + +import org.eclipse.emf.cdo.view.CDOView; +import org.eclipse.emf.cdo.view.CDOViewSet; + +import org.eclipse.emf.ecore.EPackage; +import org.eclipse.emf.ecore.impl.EPackageRegistryImpl; + +/** + * @author Simon McDuff + */ +public class CDOViewSetPackageRegistryImpl extends EPackageRegistryImpl +{ + private static final long serialVersionUID = 1L; + + private CDOViewSet viewSet; + + public CDOViewSetPackageRegistryImpl(CDOViewSet viewSet, EPackage.Registry delegateRegistry) + { + super(delegateRegistry); + this.viewSet = viewSet; + } + + @Override + protected EPackage delegatedGetEPackage(String nsURI) + { + for (CDOView view : viewSet.getViews()) + { + EPackage ePackage = view.getSession().getPackageRegistry().getEPackage(nsURI); + if (ePackage != null) + { + return ePackage; + } + } + + return super.delegatedGetEPackage(nsURI); + } + + @Override + public Object put(String key, Object value) + { + super.put(key, value); + for (CDOView view : viewSet.getViews()) + { + view.getSession().getPackageRegistry().put(key, value); + } + + return null; + } + + @Override + public synchronized Object get(Object key) + { + Object ePackage = super.get(key); + if (ePackage == null) + { + for (CDOView view : viewSet.getViews()) + { + ePackage = view.getSession().getPackageRegistry().get(key); + if (ePackage != null) + { + return ePackage; + } + } + } + + return ePackage; + } +} diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/view/PluginContainerViewProvider.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/view/PluginContainerViewProvider.java index bbaaab45c4..30f24476ff 100644 --- a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/view/PluginContainerViewProvider.java +++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/view/PluginContainerViewProvider.java @@ -1,82 +1,82 @@ -/*
- * Copyright (c) 2004 - 2012 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:
- * Victor Roldan Betancort - initial API and implementation
- * Eike Stepper - maintenance
- */
-package org.eclipse.emf.internal.cdo.view;
-
-import org.eclipse.emf.cdo.session.CDOSession;
-import org.eclipse.emf.cdo.util.CDOURIUtil;
-import org.eclipse.emf.cdo.view.CDOView;
-import org.eclipse.emf.cdo.view.CDOViewProvider;
-import org.eclipse.emf.cdo.view.ManagedContainerViewProvider;
-
-import org.eclipse.emf.internal.cdo.session.CDOSessionFactory;
-
-import org.eclipse.net4j.util.container.IManagedContainer;
-import org.eclipse.net4j.util.container.IPluginContainer;
-
-import org.eclipse.emf.common.util.URI;
-import org.eclipse.emf.ecore.resource.ResourceSet;
-
-/**
- * Provides <code>CDOView</code> from <code>CDOSession</code> registered in IPluginContainer
- *
- * @author Victor Roldan Betancort
- */
-public class PluginContainerViewProvider extends ManagedContainerViewProvider
-{
- public static final CDOViewProvider INSTANCE = new PluginContainerViewProvider();
-
- private final static String REGEX = "cdo:.*"; //$NON-NLS-1$
-
- private final static int PRIORITY = DEFAULT_PRIORITY - 200;
-
- public PluginContainerViewProvider()
- {
- super(IPluginContainer.INSTANCE, REGEX, PRIORITY);
- }
-
- public CDOView getView(URI uri, ResourceSet resourceSet)
- {
- IManagedContainer container = getContainer();
- if (container == null)
- {
- return null;
- }
-
- String repoUUID = CDOURIUtil.extractRepositoryUUID(uri);
- for (Object element : container.getElements(CDOSessionFactory.PRODUCT_GROUP))
- {
- CDOSession session = (CDOSession)element;
- String uuid = session.getRepositoryInfo().getUUID();
- if (repoUUID.equals(uuid))
- {
- CDOView view = openView(session, resourceSet);
- if (view != null)
- {
- return view;
- }
- }
- }
-
- return null;
- }
-
- @Override
- protected IManagedContainer getContainer()
- {
- return IPluginContainer.INSTANCE;
- }
-
- protected CDOView openView(CDOSession session, ResourceSet resourceSet)
- {
- return session.openTransaction(resourceSet);
- }
-}
+/* + * Copyright (c) 2004 - 2012 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: + * Victor Roldan Betancort - initial API and implementation + * Eike Stepper - maintenance + */ +package org.eclipse.emf.internal.cdo.view; + +import org.eclipse.emf.cdo.session.CDOSession; +import org.eclipse.emf.cdo.util.CDOURIUtil; +import org.eclipse.emf.cdo.view.CDOView; +import org.eclipse.emf.cdo.view.CDOViewProvider; +import org.eclipse.emf.cdo.view.ManagedContainerViewProvider; + +import org.eclipse.emf.internal.cdo.session.CDOSessionFactory; + +import org.eclipse.net4j.util.container.IManagedContainer; +import org.eclipse.net4j.util.container.IPluginContainer; + +import org.eclipse.emf.common.util.URI; +import org.eclipse.emf.ecore.resource.ResourceSet; + +/** + * Provides <code>CDOView</code> from <code>CDOSession</code> registered in IPluginContainer + * + * @author Victor Roldan Betancort + */ +public class PluginContainerViewProvider extends ManagedContainerViewProvider +{ + public static final CDOViewProvider INSTANCE = new PluginContainerViewProvider(); + + private final static String REGEX = "cdo:.*"; //$NON-NLS-1$ + + private final static int PRIORITY = DEFAULT_PRIORITY - 200; + + public PluginContainerViewProvider() + { + super(IPluginContainer.INSTANCE, REGEX, PRIORITY); + } + + public CDOView getView(URI uri, ResourceSet resourceSet) + { + IManagedContainer container = getContainer(); + if (container == null) + { + return null; + } + + String repoUUID = CDOURIUtil.extractRepositoryUUID(uri); + for (Object element : container.getElements(CDOSessionFactory.PRODUCT_GROUP)) + { + CDOSession session = (CDOSession)element; + String uuid = session.getRepositoryInfo().getUUID(); + if (repoUUID.equals(uuid)) + { + CDOView view = openView(session, resourceSet); + if (view != null) + { + return view; + } + } + } + + return null; + } + + @Override + protected IManagedContainer getContainer() + { + return IPluginContainer.INSTANCE; + } + + protected CDOView openView(CDOSession session, ResourceSet resourceSet) + { + return session.openTransaction(resourceSet); + } +} diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/view/ViewProperties.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/view/ViewProperties.java index 6481acf0c6..b54422df34 100644 --- a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/view/ViewProperties.java +++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/view/ViewProperties.java @@ -1,166 +1,166 @@ -/*
- * Copyright (c) 2004 - 2012 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.internal.cdo.view;
-
-import org.eclipse.emf.cdo.common.util.CDOCommonUtil;
-import org.eclipse.emf.cdo.view.CDOView;
-
-import org.eclipse.net4j.util.properties.DefaultPropertyTester;
-import org.eclipse.net4j.util.properties.IProperties;
-import org.eclipse.net4j.util.properties.Properties;
-import org.eclipse.net4j.util.properties.Property;
-
-/**
- * @author Eike Stepper
- */
-public class ViewProperties extends Properties<CDOView>
-{
- public static final IProperties<CDOView> INSTANCE = new ViewProperties();
-
- private static final String CATEGORY_VIEW = "View"; //$NON-NLS-1$
-
- private static final String CATEGORY_SESSION = "Session"; //$NON-NLS-1$
-
- private ViewProperties()
- {
- super(CDOView.class);
-
- add(new Property<CDOView>("open", //$NON-NLS-1$
- "Open", "Whether this view is open or not.", CATEGORY_VIEW)
- {
- @Override
- protected Object eval(CDOView view)
- {
- return !view.isClosed();
- }
- });
-
- add(new Property<CDOView>("viewID", //$NON-NLS-1$
- "ID", "The ID of this view.", CATEGORY_VIEW)
- {
- @Override
- protected Object eval(CDOView view)
- {
- return view.getViewID();
- }
- });
-
- add(new Property<CDOView>("branchName") //$NON-NLS-1$
- {
- @Override
- protected Object eval(CDOView view)
- {
- return view.getBranch().getName();
- }
- });
-
- add(new Property<CDOView>("branch", //$NON-NLS-1$
- "Branch", "The branch of this view.", CATEGORY_VIEW)
- {
- @Override
- protected Object eval(CDOView view)
- {
- return view.getBranch().getPathName();
- }
- });
-
- add(new Property<CDOView>("timeStamp", //$NON-NLS-1$
- "Time Stamp", "The time stamp of this view.", CATEGORY_VIEW)
- {
- @Override
- protected Object eval(CDOView view)
- {
- return CDOCommonUtil.formatTimeStamp(view.getTimeStamp());
- }
- });
-
- add(new Property<CDOView>("lastUpdateTime", //$NON-NLS-1$
- "Last Update", "The time stamp of the last passive update.", CATEGORY_VIEW)
- {
- @Override
- protected Object eval(CDOView view)
- {
- return CDOCommonUtil.formatTimeStamp(view.getLastUpdateTime());
- }
- });
-
- add(new Property<CDOView>("readOnly", //$NON-NLS-1$
- "Read-Only", "Whether this view is read-only or not.", CATEGORY_VIEW)
- {
- @Override
- protected Object eval(CDOView view)
- {
- return view.isReadOnly();
- }
- });
-
- add(new Property<CDOView>("dirty", //$NON-NLS-1$
- "Dirty", "Whether this view is dirty or not.", CATEGORY_VIEW)
- {
- @Override
- protected Object eval(CDOView view)
- {
- return view.isDirty();
- }
- });
-
- add(new Property<CDOView>("durable", //$NON-NLS-1$
- "Durable", "Whether this view is durable or not.", CATEGORY_VIEW)
- {
- @Override
- protected Object eval(CDOView view)
- {
- return view.getDurableLockingID() != null;
- }
- });
-
- add(new Property<CDOView>("sessionID", //$NON-NLS-1$
- "Session ID", "The ID of the session of this view.", CATEGORY_SESSION)
- {
- @Override
- protected Object eval(CDOView view)
- {
- return view.getSession().getSessionID();
- }
- });
-
- add(new Property<CDOView>("userID", //$NON-NLS-1$
- "User ID", "The user ID of the session of this view.", CATEGORY_SESSION)
- {
- @Override
- protected Object eval(CDOView view)
- {
- return view.getSession().getUserID();
- }
- });
- }
-
- /**
- *
- */
- public static void main(String[] args)
- {
- new Tester().dumpContributionMarkup();
- }
-
- /**
- * @author Eike Stepper
- */
- public static final class Tester extends DefaultPropertyTester<CDOView>
- {
- public static final String NAMESPACE = "org.eclipse.emf.cdo.view";
-
- public Tester()
- {
- super(NAMESPACE, INSTANCE);
- }
- }
-}
+/* + * Copyright (c) 2004 - 2012 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.internal.cdo.view; + +import org.eclipse.emf.cdo.common.util.CDOCommonUtil; +import org.eclipse.emf.cdo.view.CDOView; + +import org.eclipse.net4j.util.properties.DefaultPropertyTester; +import org.eclipse.net4j.util.properties.IProperties; +import org.eclipse.net4j.util.properties.Properties; +import org.eclipse.net4j.util.properties.Property; + +/** + * @author Eike Stepper + */ +public class ViewProperties extends Properties<CDOView> +{ + public static final IProperties<CDOView> INSTANCE = new ViewProperties(); + + private static final String CATEGORY_VIEW = "View"; //$NON-NLS-1$ + + private static final String CATEGORY_SESSION = "Session"; //$NON-NLS-1$ + + private ViewProperties() + { + super(CDOView.class); + + add(new Property<CDOView>("open", //$NON-NLS-1$ + "Open", "Whether this view is open or not.", CATEGORY_VIEW) + { + @Override + protected Object eval(CDOView view) + { + return !view.isClosed(); + } + }); + + add(new Property<CDOView>("viewID", //$NON-NLS-1$ + "ID", "The ID of this view.", CATEGORY_VIEW) + { + @Override + protected Object eval(CDOView view) + { + return view.getViewID(); + } + }); + + add(new Property<CDOView>("branchName") //$NON-NLS-1$ + { + @Override + protected Object eval(CDOView view) + { + return view.getBranch().getName(); + } + }); + + add(new Property<CDOView>("branch", //$NON-NLS-1$ + "Branch", "The branch of this view.", CATEGORY_VIEW) + { + @Override + protected Object eval(CDOView view) + { + return view.getBranch().getPathName(); + } + }); + + add(new Property<CDOView>("timeStamp", //$NON-NLS-1$ + "Time Stamp", "The time stamp of this view.", CATEGORY_VIEW) + { + @Override + protected Object eval(CDOView view) + { + return CDOCommonUtil.formatTimeStamp(view.getTimeStamp()); + } + }); + + add(new Property<CDOView>("lastUpdateTime", //$NON-NLS-1$ + "Last Update", "The time stamp of the last passive update.", CATEGORY_VIEW) + { + @Override + protected Object eval(CDOView view) + { + return CDOCommonUtil.formatTimeStamp(view.getLastUpdateTime()); + } + }); + + add(new Property<CDOView>("readOnly", //$NON-NLS-1$ + "Read-Only", "Whether this view is read-only or not.", CATEGORY_VIEW) + { + @Override + protected Object eval(CDOView view) + { + return view.isReadOnly(); + } + }); + + add(new Property<CDOView>("dirty", //$NON-NLS-1$ + "Dirty", "Whether this view is dirty or not.", CATEGORY_VIEW) + { + @Override + protected Object eval(CDOView view) + { + return view.isDirty(); + } + }); + + add(new Property<CDOView>("durable", //$NON-NLS-1$ + "Durable", "Whether this view is durable or not.", CATEGORY_VIEW) + { + @Override + protected Object eval(CDOView view) + { + return view.getDurableLockingID() != null; + } + }); + + add(new Property<CDOView>("sessionID", //$NON-NLS-1$ + "Session ID", "The ID of the session of this view.", CATEGORY_SESSION) + { + @Override + protected Object eval(CDOView view) + { + return view.getSession().getSessionID(); + } + }); + + add(new Property<CDOView>("userID", //$NON-NLS-1$ + "User ID", "The user ID of the session of this view.", CATEGORY_SESSION) + { + @Override + protected Object eval(CDOView view) + { + return view.getSession().getUserID(); + } + }); + } + + /** + * + */ + public static void main(String[] args) + { + new Tester().dumpContributionMarkup(); + } + + /** + * @author Eike Stepper + */ + public static final class Tester extends DefaultPropertyTester<CDOView> + { + public static final String NAMESPACE = "org.eclipse.emf.cdo.view"; + + public Tester() + { + super(NAMESPACE, INSTANCE); + } + } +} |