Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEike Stepper2011-02-19 09:08:04 +0000
committerEike Stepper2011-02-19 09:08:04 +0000
commit6e99cdd14e293af3c5877f195063b781faa2141e (patch)
treed07792d8bfc9f60a20c2db63a2034589afc4f4f0 /plugins/org.eclipse.emf.cdo.server.mongodb/src
parent4fe854e3bbe501097a32fa96ca1d735c07c6401a (diff)
downloadcdo-6e99cdd14e293af3c5877f195063b781faa2141e.tar.gz
cdo-6e99cdd14e293af3c5877f195063b781faa2141e.tar.xz
cdo-6e99cdd14e293af3c5877f195063b781faa2141e.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/Coll.java53
-rw-r--r--plugins/org.eclipse.emf.cdo.server.mongodb/src/org/eclipse/emf/cdo/server/internal/mongodb/Commits.java73
2 files changed, 54 insertions, 72 deletions
diff --git a/plugins/org.eclipse.emf.cdo.server.mongodb/src/org/eclipse/emf/cdo/server/internal/mongodb/Coll.java b/plugins/org.eclipse.emf.cdo.server.mongodb/src/org/eclipse/emf/cdo/server/internal/mongodb/Coll.java
index 8ff125609a..94fa1ae99c 100644
--- a/plugins/org.eclipse.emf.cdo.server.mongodb/src/org/eclipse/emf/cdo/server/internal/mongodb/Coll.java
+++ b/plugins/org.eclipse.emf.cdo.server.mongodb/src/org/eclipse/emf/cdo/server/internal/mongodb/Coll.java
@@ -12,6 +12,7 @@ package org.eclipse.emf.cdo.server.internal.mongodb;
import com.mongodb.BasicDBObject;
import com.mongodb.DBCollection;
+import com.mongodb.DBCursor;
import com.mongodb.DBObject;
/**
@@ -58,4 +59,56 @@ public class Coll
collection.ensureIndex(index);
}
+
+ /**
+ * @author Eike Stepper
+ */
+ public abstract class Query<RESULT>
+ {
+ private DBObject ref;
+
+ public Query(DBObject ref)
+ {
+ this.ref = ref;
+ }
+
+ public DBObject getRef()
+ {
+ return ref;
+ }
+
+ public RESULT execute()
+ {
+ return execute(collection.find(ref));
+ }
+
+ public RESULT execute(DBObject keys)
+ {
+ return execute(collection.find(ref, keys));
+ }
+
+ protected RESULT execute(DBCursor cursor)
+ {
+ try
+ {
+ while (cursor.hasNext())
+ {
+ DBObject doc = cursor.next();
+ RESULT result = handleDoc(doc);
+ if (result != null)
+ {
+ return result;
+ }
+ }
+
+ return null;
+ }
+ finally
+ {
+ cursor.close();
+ }
+ }
+
+ protected abstract RESULT handleDoc(DBObject doc);
+ }
}
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 0f0e9c8611..48b0dd0bdb 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
@@ -69,8 +69,6 @@ public class Commits extends Coll
public static final String UNITS_TYPE = "type";
- // public static final String UNITS_TIME = "time";
-
public static final String UNITS_DATA = "data";
public static final String PACKAGES = "packages";
@@ -85,8 +83,6 @@ public class Commits extends Coll
public static final String REVISIONS_ID = "cdo_id";
- // public static final String REVISIONS_BRANCH = "cdo_branch";
-
public static final String REVISIONS_VERSION = "cdo_version";
public static final String REVISIONS_CLASS = "cdo_class";
@@ -540,74 +536,6 @@ public class Commits extends Coll
return result;
}
}.execute();
-
- // commit.id = 100
- // commit.branch = 3
- // commit.revisions.id = 5
- // commit.revisions.version = 1
-
- // commit.id = 200
- // commit.branch = 3
- // commit.revisions.id = 5
- // commit.revisions.version = 2
-
- // commit.id = 300
- // commit.branch = 3
- // commit.revisions.id = 5
- // commit.revisions.version = 3
-
- }
-
- /**
- * @author Eike Stepper
- */
- public abstract class Query<RESULT>
- {
- private DBObject ref;
-
- public Query(DBObject ref)
- {
- this.ref = ref;
- }
-
- public DBObject getRef()
- {
- return ref;
- }
-
- public RESULT execute()
- {
- return execute(collection.find(ref));
- }
-
- public RESULT execute(DBObject keys)
- {
- return execute(collection.find(ref, keys));
- }
-
- protected RESULT execute(DBCursor cursor)
- {
- try
- {
- while (cursor.hasNext())
- {
- DBObject doc = cursor.next();
- RESULT result = handleDoc(doc);
- if (result != null)
- {
- return result;
- }
- }
-
- return null;
- }
- finally
- {
- cursor.close();
- }
- }
-
- protected abstract RESULT handleDoc(DBObject doc);
}
/**
@@ -639,4 +567,5 @@ public class Commits extends Coll
protected abstract RESULT handleRevision(DBObject doc, DBObject revision);
}
+
}

Back to the top