Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEike Stepper2011-02-16 09:40:34 +0000
committerEike Stepper2011-02-16 09:40:34 +0000
commit8b618a1471a8ea22951b87c8d1cadeab7daa1cce (patch)
tree598c9110ac25c3b3400a413c3f5a0a779bc099a8 /plugins/org.eclipse.emf.cdo.tests.mongodb
parent4cc3c90d4ba00d0943caa8b3ccaa2f9849567a34 (diff)
downloadcdo-8b618a1471a8ea22951b87c8d1cadeab7daa1cce.tar.gz
cdo-8b618a1471a8ea22951b87c8d1cadeab7daa1cce.tar.xz
cdo-8b618a1471a8ea22951b87c8d1cadeab7daa1cce.zip
[337152] [Mongo] Create a MongoDBStore
https://bugs.eclipse.org/bugs/show_bug.cgi?id=337152
Diffstat (limited to 'plugins/org.eclipse.emf.cdo.tests.mongodb')
-rw-r--r--plugins/org.eclipse.emf.cdo.tests.mongodb/src/org/eclipse/emf/cdo/tests/mongodb/MongoDBStoreRepositoryConfig.java36
1 files changed, 34 insertions, 2 deletions
diff --git a/plugins/org.eclipse.emf.cdo.tests.mongodb/src/org/eclipse/emf/cdo/tests/mongodb/MongoDBStoreRepositoryConfig.java b/plugins/org.eclipse.emf.cdo.tests.mongodb/src/org/eclipse/emf/cdo/tests/mongodb/MongoDBStoreRepositoryConfig.java
index da1c2eb7a9..2628e155d2 100644
--- a/plugins/org.eclipse.emf.cdo.tests.mongodb/src/org/eclipse/emf/cdo/tests/mongodb/MongoDBStoreRepositoryConfig.java
+++ b/plugins/org.eclipse.emf.cdo.tests.mongodb/src/org/eclipse/emf/cdo/tests/mongodb/MongoDBStoreRepositoryConfig.java
@@ -11,11 +11,14 @@
package org.eclipse.emf.cdo.tests.mongodb;
import org.eclipse.emf.cdo.server.IStore;
-import org.eclipse.emf.cdo.server.mongodbdb.CDOMongoDBUtil;
+import org.eclipse.emf.cdo.server.mongodb.CDOMongoDBUtil;
import org.eclipse.emf.cdo.tests.config.impl.RepositoryConfig;
+import org.eclipse.net4j.util.WrappedException;
import org.eclipse.net4j.util.container.IPluginContainer;
+import com.mongodb.DB;
+import com.mongodb.Mongo;
import com.mongodb.MongoURI;
/**
@@ -42,6 +45,35 @@ public class MongoDBStoreRepositoryConfig extends RepositoryConfig
@Override
public IStore createStore(String repoName)
{
- return CDOMongoDBUtil.createStore(new MongoURI("mongodb://localhost"), repoName);
+ MongoURI mongoURI = new MongoURI("mongodb://localhost");
+ dropDatabase(mongoURI, repoName);
+
+ return CDOMongoDBUtil.createStore(mongoURI, repoName);
+ }
+
+ protected void dropDatabase(MongoURI mongoURI, String repoName)
+ {
+ Mongo mongo = null;
+
+ try
+ {
+ mongo = new Mongo(mongoURI);
+ DB db = mongo.getDB(repoName);
+ if (!db.getCollectionNames().isEmpty())
+ {
+ db.dropDatabase();
+ }
+ }
+ catch (Exception ex)
+ {
+ throw WrappedException.wrap(ex);
+ }
+ finally
+ {
+ if (mongo != null)
+ {
+ mongo.close();
+ }
+ }
}
}

Back to the top