Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/org.eclipse.emf.cdo.server.mongodb')
-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
2 files changed, 81 insertions, 19 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;

Back to the top