Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEike Stepper2011-02-21 08:07:20 +0000
committerEike Stepper2011-02-21 08:07:20 +0000
commitb10189b13ccb699c9fec6e8db387533f4cdd97c1 (patch)
tree5f6dad4f16a2ddc52690edce708c19f96725b2d5
parentd18ff9ce271c30857fb81a1c2bdca0534592a78a (diff)
downloadcdo-b10189b13ccb699c9fec6e8db387533f4cdd97c1.tar.gz
cdo-b10189b13ccb699c9fec6e8db387533f4cdd97c1.tar.xz
cdo-b10189b13ccb699c9fec6e8db387533f4cdd97c1.zip
[337152] [Mongo] Create a MongoDBStore
https://bugs.eclipse.org/bugs/show_bug.cgi?id=337152
-rw-r--r--plugins/org.eclipse.emf.cdo.server.mongodb/src/org/eclipse/emf/cdo/server/internal/mongodb/Commits.java55
-rw-r--r--plugins/org.eclipse.emf.cdo.server.mongodb/src/org/eclipse/emf/cdo/server/internal/mongodb/MongoDBStore.java45
-rw-r--r--plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_258933_Test.java5
-rw-r--r--plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/view/CDOStoreImpl.java4
4 files changed, 87 insertions, 22 deletions
diff --git a/plugins/org.eclipse.emf.cdo.server.mongodb/src/org/eclipse/emf/cdo/server/internal/mongodb/Commits.java b/plugins/org.eclipse.emf.cdo.server.mongodb/src/org/eclipse/emf/cdo/server/internal/mongodb/Commits.java
index cb0eca0211..1a01ab9bea 100644
--- a/plugins/org.eclipse.emf.cdo.server.mongodb/src/org/eclipse/emf/cdo/server/internal/mongodb/Commits.java
+++ b/plugins/org.eclipse.emf.cdo.server.mongodb/src/org/eclipse/emf/cdo/server/internal/mongodb/Commits.java
@@ -386,27 +386,39 @@ public class Commits extends Coll
{
Object value = revision.getValue(feature);
+ CDOType type = CDOModelUtil.getType(feature);
+ ValueHandler valueHandler = store.getValueHandler(type);
+
if (feature.isUnsettable())
{
- boolean set = value != null;
- doc.put(feature.getName() + SET_SUFFIX, set);
- if (!set)
+ if (value == null)
{
+ doc.put(feature.getName() + SET_SUFFIX, false);
+ doc.put(feature.getName(), valueHandler.getMongoDefaultValue(feature));
continue;
}
+
+ doc.put(feature.getName() + SET_SUFFIX, true);
}
if (value == CDORevisionData.NIL)
{
- value = null;
+ doc.put(feature.getName(), null);
}
-
- CDOType type = CDOModelUtil.getType(feature);
- ValueHandler valueHandler = store.getValueHandler(type);
-
- if (feature.isMany())
+ else if (value == null)
{
- if (value != null)
+ if (feature.isMany() || feature.getDefaultValue() == null)
+ {
+ doc.put(feature.getName(), null);
+ }
+ else
+ {
+ doc.put(feature.getName(), valueHandler.getMongoDefaultValue(feature));
+ }
+ }
+ else
+ {
+ if (feature.isMany())
{
List<?> cdoList = (List<?>)value;
BasicDBList mongoList = new BasicDBList();
@@ -418,13 +430,13 @@ public class Commits extends Coll
value = mongoList;
}
- }
- else
- {
- value = valueHandler.toMongo(value);
- }
+ else
+ {
+ value = valueHandler.toMongo(value);
+ }
- doc.put(feature.getName(), value);
+ doc.put(feature.getName(), value);
+ }
}
return doc;
@@ -742,11 +754,16 @@ public class Commits extends Coll
{
continue;
}
+ }
- if (value == null)
+ if (value == null)
+ {
+ if (!feature.isMany())
{
- revision.set(feature, EStore.NO_INDEX, CDORevisionData.NIL);
- continue;
+ if (feature.getDefaultValue() != null)
+ {
+ value = CDORevisionData.NIL;
+ }
}
}
diff --git a/plugins/org.eclipse.emf.cdo.server.mongodb/src/org/eclipse/emf/cdo/server/internal/mongodb/MongoDBStore.java b/plugins/org.eclipse.emf.cdo.server.mongodb/src/org/eclipse/emf/cdo/server/internal/mongodb/MongoDBStore.java
index f6321a3667..a734acbe29 100644
--- a/plugins/org.eclipse.emf.cdo.server.mongodb/src/org/eclipse/emf/cdo/server/internal/mongodb/MongoDBStore.java
+++ b/plugins/org.eclipse.emf.cdo.server.mongodb/src/org/eclipse/emf/cdo/server/internal/mongodb/MongoDBStore.java
@@ -32,6 +32,14 @@ import org.eclipse.emf.cdo.spi.server.StoreAccessorPool;
import org.eclipse.net4j.util.lifecycle.LifecycleUtil;
+import org.eclipse.emf.common.util.Enumerator;
+import org.eclipse.emf.ecore.EClassifier;
+import org.eclipse.emf.ecore.EDataType;
+import org.eclipse.emf.ecore.EEnum;
+import org.eclipse.emf.ecore.EEnumLiteral;
+import org.eclipse.emf.ecore.EFactory;
+import org.eclipse.emf.ecore.EStructuralFeature;
+
import com.mongodb.DB;
import com.mongodb.Mongo;
import com.mongodb.MongoURI;
@@ -466,6 +474,37 @@ public class MongoDBStore extends Store implements IMongoDBStore, //
return new BigInteger((String)value);
}
});
+
+ initValueHandler(CDOType.ENUM_ORDINAL, new ValueHandler()
+ {
+ @Override
+ public Object getMongoDefaultValue(EStructuralFeature feature)
+ {
+ EEnum eenum = (EEnum)feature.getEType();
+
+ String defaultValueLiteral = feature.getDefaultValueLiteral();
+ if (defaultValueLiteral != null)
+ {
+ EEnumLiteral literal = eenum.getEEnumLiteralByLiteral(defaultValueLiteral);
+ return literal.getValue();
+ }
+
+ Enumerator enumerator = (Enumerator)eenum.getDefaultValue();
+ return enumerator.getValue();
+ }
+ });
+
+ initValueHandler(CDOType.CUSTOM, new ValueHandler()
+ {
+ @Override
+ public Object getMongoDefaultValue(EStructuralFeature feature)
+ {
+ Object defaultValue = feature.getDefaultValue();
+ EClassifier eType = feature.getEType();
+ EFactory factory = eType.getEPackage().getEFactoryInstance();
+ return factory.convertToString((EDataType)eType, defaultValue);
+ }
+ });
}
protected void initValueHandler(CDOType type, ValueHandler valueHandler)
@@ -526,6 +565,12 @@ public class MongoDBStore extends Store implements IMongoDBStore, //
*/
public static class ValueHandler
{
+ public Object getMongoDefaultValue(EStructuralFeature feature)
+ {
+ Object defaultValue = feature.getDefaultValue();
+ return toMongo(defaultValue);
+ }
+
public Object toMongo(Object value)
{
return value;
diff --git a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_258933_Test.java b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_258933_Test.java
index cd0c3e75ab..b0e29f3bc3 100644
--- a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_258933_Test.java
+++ b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_258933_Test.java
@@ -136,10 +136,11 @@ public class Bugzilla_258933_Test extends AbstractCDOTest
EStructuralFeature feature = class1Class.getEStructuralFeature(featureName);
CDOTransaction transaction = session.openTransaction();
- CDOObject instance = CDOUtil.getCDOObject(transaction.getResource(getResourcePath("/test1")).getContents().get(0));
+ CDOResource resource = transaction.getResource(getResourcePath("/test1"));
+ CDOObject instance = CDOUtil.getCDOObject(resource.getContents().get(0));
assertEquals(isSet, instance.eIsSet(feature));
- transaction.getResource(getResourcePath("/test1")).getContents().remove(0);
+ resource.getContents().remove(0);
assertEquals(isSet, instance.eIsSet(feature));
if (feature.isUnsettable())
diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/view/CDOStoreImpl.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/view/CDOStoreImpl.java
index 3bd1be5fe7..54f201bed7 100644
--- a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/view/CDOStoreImpl.java
+++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/view/CDOStoreImpl.java
@@ -210,7 +210,9 @@ public final class CDOStoreImpl implements CDOStore
return list != null && !list.isEmpty();
}
- return !ObjectUtil.equals(eObject.eGet(feature), feature.getDefaultValue());
+ Object value = eObject.eGet(feature);
+ Object defaultValue = feature.getDefaultValue();
+ return !ObjectUtil.equals(value, defaultValue);
}
// TODO This get() may not work for lists, see above

Back to the top