Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVictor Roldan Betancort2010-12-23 19:25:27 +0000
committerVictor Roldan Betancort2010-12-23 19:25:27 +0000
commit7fa1884de8538045c6b4b8b70ab1771dd78fea56 (patch)
treec6e94c534172a3ba2b6f848f27110a67255c7d13 /plugins
parent372b3d6317c18a6fc761d7f73c851211299af26b (diff)
downloadcdo-7fa1884de8538045c6b4b8b70ab1771dd78fea56.tar.gz
cdo-7fa1884de8538045c6b4b8b70ab1771dd78fea56.tar.xz
cdo-7fa1884de8538045c6b4b8b70ab1771dd78fea56.zip
fixed testFeatureMaps for DB4OStore implementation
Diffstat (limited to 'plugins')
-rw-r--r--plugins/org.eclipse.emf.cdo.server.db4o/src/org/eclipse/emf/cdo/server/internal/db4o/DB4ORevision.java94
1 files changed, 94 insertions, 0 deletions
diff --git a/plugins/org.eclipse.emf.cdo.server.db4o/src/org/eclipse/emf/cdo/server/internal/db4o/DB4ORevision.java b/plugins/org.eclipse.emf.cdo.server.db4o/src/org/eclipse/emf/cdo/server/internal/db4o/DB4ORevision.java
index 8be1e5a9a3..8c767c596a 100644
--- a/plugins/org.eclipse.emf.cdo.server.db4o/src/org/eclipse/emf/cdo/server/internal/db4o/DB4ORevision.java
+++ b/plugins/org.eclipse.emf.cdo.server.db4o/src/org/eclipse/emf/cdo/server/internal/db4o/DB4ORevision.java
@@ -21,7 +21,9 @@ import org.eclipse.emf.cdo.common.revision.CDOList;
import org.eclipse.emf.cdo.common.revision.CDOListFactory;
import org.eclipse.emf.cdo.common.revision.CDORevision;
import org.eclipse.emf.cdo.common.revision.CDORevisionFactory;
+import org.eclipse.emf.cdo.common.revision.CDORevisionUtil;
import org.eclipse.emf.cdo.server.IStore;
+import org.eclipse.emf.cdo.spi.common.revision.CDOFeatureMapEntry;
import org.eclipse.emf.cdo.spi.common.revision.InternalCDOList;
import org.eclipse.emf.cdo.spi.common.revision.InternalCDORevision;
@@ -29,6 +31,7 @@ import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.EPackage;
import org.eclipse.emf.ecore.EReference;
import org.eclipse.emf.ecore.EStructuralFeature;
+import org.eclipse.emf.ecore.util.FeatureMap;
import java.util.ArrayList;
import java.util.List;
@@ -262,6 +265,10 @@ public class DB4ORevision
values.add(i, list);
}
+ else if (listContainsInstancesOfClass(obj, CDOFeatureMapEntry.class)) // FeatureMap
+ {
+ values.add(i, DB4OFeatureMapEntry.getPrimitiveFeatureMapEntryList(obj));
+ }
else
{
values.add(i, obj);
@@ -308,6 +315,10 @@ public class DB4ORevision
value = list;
}
+ else if (listContainsInstancesOfClass(value, DB4OFeatureMapEntry.class))
+ {
+ value = DB4OFeatureMapEntry.getCDOFeatureMapEntryList(eClass, value);
+ }
revision.setValue(feature, value);
}
@@ -344,4 +355,87 @@ public class DB4ORevision
return CDOIDUtil.createLong((Long)id);
}
+
+ public static boolean listContainsInstancesOfClass(Object obj, Class<?> clazz)
+ {
+ if (obj instanceof List)
+ {
+ List<?> list = (List<?>)obj;
+ for (Object potentialFeatureMap : list)
+ {
+ if (!clazz.isAssignableFrom(potentialFeatureMap.getClass()))
+ {
+ return false;
+ }
+ }
+ return true;
+ }
+ return false;
+ }
+
+ private static final class DB4OFeatureMapEntry
+ {
+
+ private int featureID;
+
+ private Object valueID;
+
+ public DB4OFeatureMapEntry(int featureID, Object valueID)
+ {
+ setFeatureID(featureID);
+ setValueID(valueID);
+ }
+
+ private void setFeatureID(int featureID)
+ {
+ this.featureID = featureID;
+ }
+
+ public int getFeatureID()
+ {
+ return featureID;
+ }
+
+ private void setValueID(Object valueID)
+ {
+ this.valueID = valueID;
+ }
+
+ public Object getValueID()
+ {
+ return valueID;
+ }
+
+ public static List<DB4OFeatureMapEntry> getPrimitiveFeatureMapEntryList(Object obj)
+ {
+ InternalCDOList cdoList = (InternalCDOList)obj;
+ List<DB4OFeatureMapEntry> list = new ArrayList<DB4OFeatureMapEntry>();
+ for (Object listElement : cdoList)
+ {
+ if (listElement instanceof FeatureMap.Entry)
+ {
+ FeatureMap.Entry entry = (FeatureMap.Entry)listElement;
+ EStructuralFeature entryFeature = entry.getEStructuralFeature();
+ CDOID entryValue = (CDOID)entry.getValue();
+ DB4OFeatureMapEntry db4oEntry = new DB4OFeatureMapEntry(entryFeature.getFeatureID(), getDB4OID(entryValue));
+ list.add(db4oEntry);
+ }
+ }
+ return list;
+ }
+
+ public static CDOList getCDOFeatureMapEntryList(EClass eClass, Object value)
+ {
+ List<?> sourceList = (List<?>)value;
+ CDOList list = CDOListFactory.DEFAULT.createList(sourceList.size(), sourceList.size(), CDORevision.UNCHUNKED);
+ for (int j = 0; j < sourceList.size(); j++)
+ {
+ DB4OFeatureMapEntry mapEntry = (DB4OFeatureMapEntry)sourceList.get(j);
+ EStructuralFeature entryFeature = eClass.getEStructuralFeature(mapEntry.getFeatureID());
+ CDOID valueID = getCDOID(mapEntry.getValueID());
+ list.set(j, CDORevisionUtil.createFeatureMapEntry(entryFeature, valueID));
+ }
+ return list;
+ }
+ }
}

Back to the top