summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEike Stepper2007-09-14 06:21:13 (EDT)
committerEike Stepper2007-09-14 06:21:13 (EDT)
commitb151716fefd72acc69e0bba6cdea04aa4579c3b3 (patch)
tree7fe70d6481e5db76d8a0e2ab17aadbefed863ddb
parent0eabad94a1b7566b0c9e09a792bce018b7d63e54 (diff)
downloadcdo-b151716fefd72acc69e0bba6cdea04aa4579c3b3.zip
cdo-b151716fefd72acc69e0bba6cdea04aa4579c3b3.tar.gz
cdo-b151716fefd72acc69e0bba6cdea04aa4579c3b3.tar.bz2
[202833] Horizontal Mapping Strategy
https://bugs.eclipse.org/bugs/show_bug.cgi?id=202833
-rw-r--r--plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/MappingStrategy.java1
-rw-r--r--plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOTransactionImpl.java48
-rw-r--r--plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/util/EMFPackageClosure.java57
-rw-r--r--plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/util/IPackageClosure.java29
-rw-r--r--plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/util/PackageClosure.java124
-rw-r--r--plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/util/TraversingPackageClosure.java136
6 files changed, 274 insertions, 121 deletions
diff --git a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/MappingStrategy.java b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/MappingStrategy.java
index 63c9567..d3dfebd 100644
--- a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/MappingStrategy.java
+++ b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/MappingStrategy.java
@@ -274,6 +274,7 @@ public abstract class MappingStrategy implements IMappingStrategy
public CDOClassRef readObjectType(IDBStoreAccessor storeAccessor, CDOID id)
{
+ // TODO Change to support vertical mappings
String prefix = "SELECT DISTINCT " + CDODBSchema.ATTRIBUTES_CLASS + " FROM ";
String suffix = " WHERE " + CDODBSchema.ATTRIBUTES_ID + "=" + id;
for (CDOClass cdoClass : getClassesWithObjectInfo())
diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOTransactionImpl.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOTransactionImpl.java
index da91f91..b8c6481 100644
--- a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOTransactionImpl.java
+++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOTransactionImpl.java
@@ -16,23 +16,28 @@ import org.eclipse.emf.cdo.CDOTransactionDirtyEvent;
import org.eclipse.emf.cdo.eresource.impl.CDOResourceImpl;
import org.eclipse.emf.cdo.internal.protocol.CDOIDImpl;
import org.eclipse.emf.cdo.internal.protocol.model.CDOPackageImpl;
-import org.eclipse.emf.cdo.internal.protocol.model.CDOPackageManagerImpl;
import org.eclipse.emf.cdo.protocol.CDOID;
import org.eclipse.emf.cdo.protocol.util.TransportException;
+import org.eclipse.emf.ecore.EPackage;
+import org.eclipse.emf.internal.cdo.bundle.OM;
+import org.eclipse.emf.internal.cdo.protocol.CommitTransactionRequest;
+import org.eclipse.emf.internal.cdo.protocol.CommitTransactionResult;
+import org.eclipse.emf.internal.cdo.util.EMFPackageClosure;
+import org.eclipse.emf.internal.cdo.util.ModelUtil;
+
import org.eclipse.net4j.IChannel;
import org.eclipse.net4j.internal.util.om.trace.ContextTracer;
import org.eclipse.net4j.signal.IFailOverStrategy;
import org.eclipse.net4j.util.ImplementationError;
-import org.eclipse.emf.internal.cdo.bundle.OM;
-import org.eclipse.emf.internal.cdo.protocol.CommitTransactionRequest;
-import org.eclipse.emf.internal.cdo.protocol.CommitTransactionResult;
-
import java.text.MessageFormat;
+import java.util.ArrayList;
import java.util.HashMap;
+import java.util.HashSet;
import java.util.List;
import java.util.Map;
+import java.util.Set;
/**
* @author Eike Stepper
@@ -113,8 +118,7 @@ public class CDOTransactionImpl extends CDOViewImpl implements CDOTransaction
try
{
CDOSessionImpl session = getSession();
- CDOPackageManagerImpl packageManager = session.getPackageManager();
- newPackages = packageManager.getTransientPackages();
+ newPackages = analyzeNewPackages(session);
preCommit(newObjects);
preCommit(dirtyObjects);
@@ -233,6 +237,36 @@ public class CDOTransactionImpl extends CDOViewImpl implements CDOTransaction
}
}
+ private List<CDOPackageImpl> analyzeNewPackages(CDOSessionImpl session)
+ {
+ Set<EPackage> ePackages = new HashSet<EPackage>();
+ for (InternalCDOObject object : newObjects.values())
+ {
+ ePackages.add(object.eClass().getEPackage());
+ }
+
+ // Find all indirectly referenced EPackages as well
+ ePackages = new EMFPackageClosure().calculate(ePackages);
+
+ CDOSessionPackageManager packageManager = session.getPackageManager();
+ List<CDOPackageImpl> cdoPackages = new ArrayList<CDOPackageImpl>();
+ for (EPackage ePackage : ePackages)
+ {
+ CDOPackageImpl cdoPackage = ModelUtil.getCDOPackage(ePackage, packageManager);
+ if (cdoPackage == null)
+ {
+ throw new IllegalStateException("Missing CDO package: " + ePackage.getNsURI());
+ }
+
+ if (!cdoPackage.isPersistent())
+ {
+ cdoPackages.add(cdoPackage);
+ }
+ }
+
+ return cdoPackages;
+ }
+
@SuppressWarnings("unchecked")
private void preCommit(Map objects)
{
diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/util/EMFPackageClosure.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/util/EMFPackageClosure.java
new file mode 100644
index 0000000..b823c2a
--- /dev/null
+++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/util/EMFPackageClosure.java
@@ -0,0 +1,57 @@
+/***************************************************************************
+ * Copyright (c) 2004 - 2007 Eike Stepper, Germany.
+ * 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.EObject;
+import org.eclipse.emf.ecore.EPackage;
+
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Set;
+
+/**
+ * @author Eike Stepper
+ */
+public class EMFPackageClosure extends PackageClosure
+{
+ public EMFPackageClosure()
+ {
+ }
+
+ public Set<EPackage> calculate(EPackage ePackage)
+ {
+ Set<EPackage> visited = new HashSet<EPackage>();
+ collectContents(ePackage, visited);
+ return visited;
+ }
+
+ protected void collectContents(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)
+ {
+ for (EObject crossReference : content.eCrossReferences())
+ {
+ EPackage crossReferencePackage = crossReference.eClass().getEPackage();
+ if (!visited.contains(crossReferencePackage))
+ {
+ collectContents(crossReferencePackage, visited);
+ }
+ }
+ }
+}
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
new file mode 100644
index 0000000..d19dff1
--- /dev/null
+++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/util/IPackageClosure.java
@@ -0,0 +1,29 @@
+/***************************************************************************
+ * Copyright (c) 2004 - 2007 Eike Stepper, Germany.
+ * 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 8ca2a81..6d62b1b 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
@@ -10,38 +10,27 @@
**************************************************************************/
package org.eclipse.emf.internal.cdo.util;
-import org.eclipse.net4j.internal.util.om.trace.ContextTracer;
-
-import org.eclipse.emf.ecore.EClass;
-import org.eclipse.emf.ecore.EClassifier;
-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.internal.cdo.bundle.OM;
+import org.eclipse.net4j.internal.util.om.trace.ContextTracer;
+
import java.util.Collection;
-import java.util.Collections;
import java.util.HashSet;
-import java.util.List;
import java.util.Set;
/**
- * TODO Handle generic types and type parameters
- *
* @author Eike Stepper
*/
-public final class PackageClosure
+public abstract class PackageClosure implements IPackageClosure
{
private static final ContextTracer TRACER = new ContextTracer(OM.DEBUG_MODEL, PackageClosure.class);
- private static final Set<EPackage> EMPTY_CLOSURE = Collections.emptySet();
-
- private PackageClosure()
+ protected PackageClosure()
{
}
- public static Set<EPackage> calculate(Collection<EPackage> ePackages)
+ public Set<EPackage> calculate(Collection<EPackage> ePackages)
{
// Optimize no packages
if (ePackages.isEmpty())
@@ -66,110 +55,17 @@ public final class PackageClosure
return result;
}
- /**
- * TODO Handle Ecore generics
- */
- public static Set<EPackage> calculate(EPackage ePackage)
+ public Set<EPackage> calculate(EPackage ePackage)
{
if (TRACER.isEnabled())
{
TRACER.trace("Package closure for " + ePackage.getNsURI());
}
- Set<EClass> visited = new HashSet<EClass>();
-
- List<EClassifier> classifiers = ePackage.getEClassifiers();
- for (EClassifier classifier : classifiers)
- {
- handleEClassifier(classifier, visited);
- }
-
- Set<EPackage> result = new HashSet<EPackage>();
- for (EClass eClass : visited)
- {
- final EPackage p = eClass.getEPackage();
- if (p != null)
- {
- if (result.add(p))
- {
- if (TRACER.isEnabled())
- {
- TRACER.trace("Found package " + p.getNsURI());
- }
- }
- }
- else
- {
- String msg = "Package == null for " + eClass.getName();
- OM.LOG.warn(msg);
- if (TRACER.isEnabled())
- {
- TRACER.trace(msg);
- }
- }
- }
-
- return result;
+ Set<EPackage> visited = new HashSet<EPackage>();
+ collectContents(ePackage, visited);
+ return visited;
}
- private static void handleEClassifier(EClassifier classifier, Set<EClass> visited)
- {
- if (classifier instanceof EClass)
- {
- EClass eClass = (EClass)classifier;
- if (visited.add(eClass))
- {
- if (TRACER.isEnabled())
- {
- TRACER.trace("Found class " + eClass.getName());
- }
-
- handleEStructuralFeatures(eClass.getEStructuralFeatures(), visited);
- handleEOperations(eClass.getEOperations(), visited);
- handleESuperTypes(eClass.getESuperTypes(), visited);
- }
- }
- }
-
- private static void handleEStructuralFeatures(List<EStructuralFeature> structuralFeatures, Set<EClass> visited)
- {
- for (EStructuralFeature structuralFeature : structuralFeatures)
- {
- handleEClassifier(structuralFeature.getEType(), visited);
- }
- }
-
- private static void handleEOperations(List<EOperation> operations, Set<EClass> visited)
- {
- for (EOperation operation : operations)
- {
- handleEClassifier(operation.getEType(), visited);
- handleEParameters(operation.getEParameters(), visited);
- handleEExceptions(operation.getEExceptions(), visited);
- }
- }
-
- private static void handleEParameters(List<EParameter> parameters, Set<EClass> visited)
- {
- for (EParameter parameter : parameters)
- {
- handleEClassifier(parameter.getEType(), visited);
- }
- }
-
- private static void handleEExceptions(List<EClassifier> exceptions, Set<EClass> visited)
- {
- for (EClassifier exception : exceptions)
- {
- handleEClassifier(exception, visited);
- }
- }
-
- private static void handleESuperTypes(List<EClass> superTypes, Set<EClass> visited)
- {
- for (EClass superType : superTypes)
- {
- handleEClassifier(superType, visited);
- }
- }
+ protected abstract void collectContents(EPackage ePackage, Set<EPackage> visited);
}
diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/util/TraversingPackageClosure.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/util/TraversingPackageClosure.java
new file mode 100644
index 0000000..5550ca8
--- /dev/null
+++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/util/TraversingPackageClosure.java
@@ -0,0 +1,136 @@
+/***************************************************************************
+ * Copyright (c) 2004 - 2007 Eike Stepper, Germany.
+ * 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.EClass;
+import org.eclipse.emf.ecore.EClassifier;
+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.internal.cdo.bundle.OM;
+
+import org.eclipse.net4j.internal.util.om.trace.ContextTracer;
+
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+/**
+ * TODO Handle generic types and type parameters
+ *
+ * @author Eike Stepper
+ */
+@Deprecated
+public class TraversingPackageClosure extends PackageClosure
+{
+ private static final ContextTracer TRACER = new ContextTracer(OM.DEBUG_MODEL, TraversingPackageClosure.class);
+
+ public TraversingPackageClosure()
+ {
+ }
+
+ @Override
+ protected void collectContents(EPackage ePackage, Set<EPackage> visited)
+ {
+ Set<EClass> classes = new HashSet<EClass>();
+ List<EClassifier> classifiers = ePackage.getEClassifiers();
+ for (EClassifier classifier : classifiers)
+ {
+ handleEClassifier(classifier, classes);
+ }
+
+ for (EClass eClass : classes)
+ {
+ final EPackage p = eClass.getEPackage();
+ if (p != null)
+ {
+ if (visited.add(p))
+ {
+ if (TRACER.isEnabled())
+ {
+ TRACER.trace("Found package " + p.getNsURI());
+ }
+ }
+ }
+ else
+ {
+ String msg = "Package == null for " + eClass.getName();
+ OM.LOG.warn(msg);
+ if (TRACER.isEnabled())
+ {
+ TRACER.trace(msg);
+ }
+ }
+ }
+ }
+
+ private void handleEClassifier(EClassifier classifier, Set<EClass> visited)
+ {
+ if (classifier instanceof EClass)
+ {
+ EClass eClass = (EClass)classifier;
+ if (visited.add(eClass))
+ {
+ if (TRACER.isEnabled())
+ {
+ TRACER.trace("Found class " + eClass.getName());
+ }
+
+ handleEStructuralFeatures(eClass.getEStructuralFeatures(), visited);
+ handleEOperations(eClass.getEOperations(), visited);
+ handleESuperTypes(eClass.getESuperTypes(), visited);
+ }
+ }
+ }
+
+ private void handleEStructuralFeatures(List<EStructuralFeature> structuralFeatures, Set<EClass> visited)
+ {
+ for (EStructuralFeature structuralFeature : structuralFeatures)
+ {
+ handleEClassifier(structuralFeature.getEType(), visited);
+ }
+ }
+
+ private void handleEOperations(List<EOperation> operations, Set<EClass> visited)
+ {
+ for (EOperation operation : operations)
+ {
+ handleEClassifier(operation.getEType(), visited);
+ handleEParameters(operation.getEParameters(), visited);
+ handleEExceptions(operation.getEExceptions(), visited);
+ }
+ }
+
+ private void handleEParameters(List<EParameter> parameters, Set<EClass> visited)
+ {
+ for (EParameter parameter : parameters)
+ {
+ handleEClassifier(parameter.getEType(), visited);
+ }
+ }
+
+ private void handleEExceptions(List<EClassifier> exceptions, Set<EClass> visited)
+ {
+ for (EClassifier exception : exceptions)
+ {
+ handleEClassifier(exception, visited);
+ }
+ }
+
+ private void handleESuperTypes(List<EClass> superTypes, Set<EClass> visited)
+ {
+ for (EClass superType : superTypes)
+ {
+ handleEClassifier(superType, visited);
+ }
+ }
+}