Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEike Stepper2011-02-17 09:27:25 +0000
committerEike Stepper2011-02-17 09:27:25 +0000
commit952ba43620adc754d958fed730cc707d639b5b42 (patch)
treeaf4745619eded268462a079bfcbbd9c1a2684d98 /plugins/org.eclipse.emf.cdo.server.mongodb/src
parent64fe8e0918c52f66279ab34ccd0cf8a26773c899 (diff)
downloadcdo-952ba43620adc754d958fed730cc707d639b5b42.tar.gz
cdo-952ba43620adc754d958fed730cc707d639b5b42.tar.xz
cdo-952ba43620adc754d958fed730cc707d639b5b42.zip
[337152] [Mongo] Create a MongoDBStore
https://bugs.eclipse.org/bugs/show_bug.cgi?id=337152
Diffstat (limited to 'plugins/org.eclipse.emf.cdo.server.mongodb/src')
-rw-r--r--plugins/org.eclipse.emf.cdo.server.mongodb/src/org/eclipse/emf/cdo/server/internal/mongodb/MongoDBStore.java21
-rw-r--r--plugins/org.eclipse.emf.cdo.server.mongodb/src/org/eclipse/emf/cdo/server/internal/mongodb/MongoDBStoreAccessor.java53
2 files changed, 47 insertions, 27 deletions
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 b0f8cb4c97..207a86a24d 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
@@ -41,6 +41,12 @@ import java.util.Map.Entry;
import java.util.Set;
/**
+ * TODO:
+ * <ul>
+ * <li>Are indexes always unique? Do unique indexes exist?
+ * <li>Are <code>_id</code> fields in embedded objects automatically indexed?
+ * </ul>
+ *
* @author Eike Stepper
*/
public class MongoDBStore extends Store implements IMongoDBStore
@@ -294,6 +300,21 @@ public class MongoDBStore extends Store implements IMongoDBStore
packageUnitsCollection = db.getCollection("cdo.packageUnits");
commitInfosCollection = db.getCollection("cdo.commitInfos");
+ DBObject packages_pk = new BasicDBObject("packages.id", 1);
+ commitInfosCollection.ensureIndex(packages_pk, "packages_pk");
+
+ DBObject packages_time = new BasicDBObject("packages.time", 1);
+ commitInfosCollection.ensureIndex(packages_time, "packages_time");
+
+ DBObject revisions_pk = new BasicDBObject("revisions.cdo_id", 1).append("revisions.cdo_version", 1);
+ commitInfosCollection.ensureIndex(revisions_pk, "revisions_pk");
+
+ DBObject revisions_created = new BasicDBObject("revisions.cdo_created", 1);
+ commitInfosCollection.ensureIndex(revisions_created, "revisions_created");
+
+ DBObject revisions_revised = new BasicDBObject("revisions.cdo_revised", 1);
+ commitInfosCollection.ensureIndex(revisions_revised, "revisions_revised");
+
LifecycleUtil.activate(idHandler);
setObjectIDTypes(idHandler.getObjectIDTypes());
diff --git a/plugins/org.eclipse.emf.cdo.server.mongodb/src/org/eclipse/emf/cdo/server/internal/mongodb/MongoDBStoreAccessor.java b/plugins/org.eclipse.emf.cdo.server.mongodb/src/org/eclipse/emf/cdo/server/internal/mongodb/MongoDBStoreAccessor.java
index b470a4d9b8..36d04287f1 100644
--- a/plugins/org.eclipse.emf.cdo.server.mongodb/src/org/eclipse/emf/cdo/server/internal/mongodb/MongoDBStoreAccessor.java
+++ b/plugins/org.eclipse.emf.cdo.server.mongodb/src/org/eclipse/emf/cdo/server/internal/mongodb/MongoDBStoreAccessor.java
@@ -58,6 +58,7 @@ import com.mongodb.DBObject;
import java.io.IOException;
import java.io.OutputStream;
+import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
@@ -267,7 +268,7 @@ public class MongoDBStoreAccessor extends StoreAccessorBase implements IMongoDBS
{
try
{
- monitor.begin(107);
+ monitor.begin(104);
CDOBranchPoint branchPoint = context.getBranchPoint();
DBObject doc = new BasicDBObject();
@@ -299,34 +300,23 @@ public class MongoDBStoreAccessor extends StoreAccessorBase implements IMongoDBS
InternalCDOPackageUnit[] newPackageUnits = context.getNewPackageUnits();
if (!ObjectUtil.isEmpty(newPackageUnits))
{
- doc.put("meta", marshallPackageUnits(newPackageUnits));
+ doc.put("packages", marshallPackageUnits(newPackageUnits));
}
monitor.worked();
addIDMappings(context, monitor.fork());
context.applyIDMappings(monitor.fork());
- InternalCDORevision[] newObjects = context.getNewObjects();
- if (!ObjectUtil.isEmpty(newObjects))
+ List<DBObject> docs = new ArrayList<DBObject>();
+ marshalRevisions(docs, context.getNewObjects());
+ marshalRevisions(docs, context.getDirtyObjects());
+ if (!docs.isEmpty())
{
- doc.put("new", marshallRevisions(newObjects));
+ doc.put("revisions", docs);
}
monitor.worked();
- InternalCDORevisionDelta[] dirtyObjectDeltas = context.getDirtyObjectDeltas();
- if (!ObjectUtil.isEmpty(dirtyObjectDeltas))
- {
- doc.put("changed", marshallRevisionDeltas(dirtyObjectDeltas));
- }
-
- monitor.worked();
- Map<CDOID, EClass> detachedObjectTypes = context.getDetachedObjectTypes();
- if (!ObjectUtil.isEmpty(detachedObjectTypes))
- {
- doc.put("detached", marshallObjectTypes(detachedObjectTypes));
- }
- monitor.worked();
getStore().getCommitInfosCollection().insert(doc);
monitor.worked(100);
@@ -355,7 +345,7 @@ public class MongoDBStoreAccessor extends StoreAccessorBase implements IMongoDBS
return getStore().getIDHandler().getNextCDOID(revision);
}
- protected DBObject[] marshallPackageUnits(InternalCDOPackageUnit[] packageUnits)
+ private DBObject[] marshallPackageUnits(InternalCDOPackageUnit[] packageUnits)
{
DBObject[] result = new DBObject[packageUnits.length];
InternalCDOPackageRegistry packageRegistry = getStore().getRepository().getPackageRegistry();
@@ -367,10 +357,10 @@ public class MongoDBStoreAccessor extends StoreAccessorBase implements IMongoDBS
byte[] bytes = EMFUtil.getEPackageBytes(ePackage, ZIP_PACKAGE_BYTES, packageRegistry);
DBObject doc = new BasicDBObject();
- doc.put("_id", packageUnit.getID());
- doc.put("originalType", packageUnit.getOriginalType().toString());
- doc.put("timeStamp", packageUnit.getTimeStamp());
- doc.put("packageData", bytes);
+ doc.put("id", packageUnit.getID());
+ doc.put("type", packageUnit.getOriginalType().toString());
+ doc.put("time", packageUnit.getTimeStamp());
+ doc.put("data", bytes);
result[i] = doc;
}
@@ -378,7 +368,16 @@ public class MongoDBStoreAccessor extends StoreAccessorBase implements IMongoDBS
return result;
}
- protected DBObject[] marshallRevisions(InternalCDORevision[] revisions)
+ private void marshalRevisions(List<DBObject> docs, InternalCDORevision[] revisions)
+ {
+ for (InternalCDORevision revision : revisions)
+ {
+ DBObject doc = marshallRevision(revision);
+ docs.add(doc);
+ }
+ }
+
+ private DBObject[] marshallRevisions(InternalCDORevision[] revisions)
{
DBObject[] result = new DBObject[revisions.length];
for (int i = 0; i < revisions.length; i++)
@@ -390,7 +389,7 @@ public class MongoDBStoreAccessor extends StoreAccessorBase implements IMongoDBS
return result;
}
- protected DBObject marshallRevision(InternalCDORevision revision)
+ private DBObject marshallRevision(InternalCDORevision revision)
{
IDHandler idHandler = getStore().getIDHandler();
@@ -436,7 +435,7 @@ public class MongoDBStoreAccessor extends StoreAccessorBase implements IMongoDBS
return doc;
}
- protected DBObject[] marshallRevisionDeltas(InternalCDORevisionDelta[] revisionDeltas)
+ private DBObject[] marshallRevisionDeltas(InternalCDORevisionDelta[] revisionDeltas)
{
DBObject[] result = new DBObject[revisionDeltas.length];
for (int i = 0; i < revisionDeltas.length; i++)
@@ -448,7 +447,7 @@ public class MongoDBStoreAccessor extends StoreAccessorBase implements IMongoDBS
return result;
}
- protected DBObject marshallRevisionDelta(InternalCDORevisionDelta revisionDelta)
+ private DBObject marshallRevisionDelta(InternalCDORevisionDelta revisionDelta)
{
IDHandler idHandler = getStore().getIDHandler();

Back to the top