Skip to main content
aboutsummaryrefslogtreecommitdiffstats
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
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')
-rw-r--r--plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/DBStore.java23
-rw-r--r--plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/LongIDHandler.java32
-rw-r--r--plugins/org.eclipse.emf.cdo.server.db4o/src/org/eclipse/emf/cdo/server/internal/db4o/DB4OStore.java2
-rw-r--r--plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/HibernateStore.java2
-rw-r--r--plugins/org.eclipse.emf.cdo.server.mongodb/META-INF/MANIFEST.MF2
-rw-r--r--plugins/org.eclipse.emf.cdo.server.mongodb/src/org/eclipse/emf/cdo/server/internal/mongodb/LongIDHandler.java122
-rw-r--r--plugins/org.eclipse.emf.cdo.server.mongodb/src/org/eclipse/emf/cdo/server/internal/mongodb/MongoDBBrowserPage.java2
-rw-r--r--plugins/org.eclipse.emf.cdo.server.mongodb/src/org/eclipse/emf/cdo/server/internal/mongodb/MongoDBStore.java182
-rw-r--r--plugins/org.eclipse.emf.cdo.server.mongodb/src/org/eclipse/emf/cdo/server/internal/mongodb/MongoDBStoreAccessor.java2
-rw-r--r--plugins/org.eclipse.emf.cdo.server.mongodb/src/org/eclipse/emf/cdo/server/mongodb/CDOMongoDBUtil.java2
-rw-r--r--plugins/org.eclipse.emf.cdo.server.mongodb/src/org/eclipse/emf/cdo/server/mongodb/IMongoDBStore.java38
-rw-r--r--plugins/org.eclipse.emf.cdo.server.mongodb/src/org/eclipse/emf/cdo/server/mongodb/IMongoDBStoreAccessor.java2
-rw-r--r--plugins/org.eclipse.emf.cdo.server.objectivity/src/org/eclipse/emf/cdo/server/internal/objectivity/ObjectivityStore.java2
-rw-r--r--plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/Repository.java2
-rw-r--r--plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/mem/MEMStore.java2
-rw-r--r--plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/syncing/SynchronizableRepository.java2
-rw-r--r--plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/IStore.java4
-rw-r--r--plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/spi/server/Store.java19
-rw-r--r--plugins/org.eclipse.emf.cdo.tests.mongodb/src/org/eclipse/emf/cdo/tests/mongodb/MongoDBStoreRepositoryConfig.java36
19 files changed, 408 insertions, 70 deletions
diff --git a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/DBStore.java b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/DBStore.java
index f7a2b4b8a8..039606e9bd 100644
--- a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/DBStore.java
+++ b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/DBStore.java
@@ -17,7 +17,6 @@ package org.eclipse.emf.cdo.server.internal.db;
import org.eclipse.emf.cdo.common.branch.CDOBranch;
import org.eclipse.emf.cdo.common.branch.CDOBranchPoint;
import org.eclipse.emf.cdo.common.id.CDOID;
-import org.eclipse.emf.cdo.common.id.CDOIDUtil;
import org.eclipse.emf.cdo.common.revision.CDOAllRevisionsProvider;
import org.eclipse.emf.cdo.common.revision.CDORevision;
import org.eclipse.emf.cdo.common.revision.CDORevisionHandler;
@@ -467,7 +466,7 @@ public class DBStore extends Store implements IDBStore, CDOAllRevisionsProvider
setPropertyValues(map);
}
- public boolean isFirstTime()
+ public boolean isFirstStart()
{
return firstTime;
}
@@ -541,8 +540,8 @@ public class DBStore extends Store implements IDBStore, CDOAllRevisionsProvider
Map<String, String> map = new HashMap<String, String>();
map.put(PROP_GRACEFULLY_SHUT_DOWN, Boolean.TRUE.toString());
map.put(PROP_REPOSITORY_STOPPED, Long.toString(getRepository().getTimeStamp()));
- map.put(PROP_NEXT_LOCAL_CDOID, idToString(idHandler.getNextLocalObjectID()));
- map.put(PROP_LAST_CDOID, idToString(idHandler.getLastObjectID()));
+ map.put(PROP_NEXT_LOCAL_CDOID, Store.idToString(idHandler.getNextLocalObjectID()));
+ map.put(PROP_LAST_CDOID, Store.idToString(idHandler.getLastObjectID()));
map.put(PROP_LAST_BRANCHID, Integer.toString(getLastBranchID()));
map.put(PROP_LAST_LOCAL_BRANCHID, Integer.toString(getLastLocalBranchID()));
map.put(PROP_LAST_COMMITTIME, Long.toString(getLastCommitTime()));
@@ -599,8 +598,8 @@ public class DBStore extends Store implements IDBStore, CDOAllRevisionsProvider
names.add(PROP_LAST_NONLOCAL_COMMITTIME);
map = getPropertyValues(names);
- idHandler.setNextLocalObjectID(stringToID(map.get(PROP_NEXT_LOCAL_CDOID)));
- idHandler.setLastObjectID(stringToID(map.get(PROP_LAST_CDOID)));
+ idHandler.setNextLocalObjectID(Store.stringToID(map.get(PROP_NEXT_LOCAL_CDOID)));
+ idHandler.setLastObjectID(Store.stringToID(map.get(PROP_LAST_CDOID)));
setLastBranchID(Integer.valueOf(map.get(PROP_LAST_BRANCHID)));
setLastLocalBranchID(Integer.valueOf(map.get(PROP_LAST_LOCAL_BRANCHID)));
setLastCommitTime(Long.valueOf(map.get(PROP_LAST_COMMITTIME)));
@@ -661,16 +660,4 @@ public class DBStore extends Store implements IDBStore, CDOAllRevisionsProvider
String name = getRepository().getName();
return new DBSchema(name);
}
-
- private String idToString(CDOID id)
- {
- StringBuilder builder = new StringBuilder();
- CDOIDUtil.write(builder, id);
- return builder.toString();
- }
-
- private CDOID stringToID(String string)
- {
- return CDOIDUtil.read(string);
- }
}
diff --git a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/LongIDHandler.java b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/LongIDHandler.java
index e3d8217524..948ba1d9ca 100644
--- a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/LongIDHandler.java
+++ b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/LongIDHandler.java
@@ -55,19 +55,24 @@ public class LongIDHandler extends Lifecycle implements IIDHandler
return store;
}
- public int compare(CDOID id1, CDOID id2)
+ public Set<ObjectType> getObjectIDTypes()
{
- return id1.compareTo(id2);
+ return LongIDStore.OBJECT_ID_TYPES;
}
- public DBType getDBType()
+ public CDOID getMinCDOID()
{
- return DBType.BIGINT;
+ return MIN;
}
- public Set<ObjectType> getObjectIDTypes()
+ public CDOID getMaxCDOID()
{
- return LongIDStore.OBJECT_ID_TYPES;
+ return MAX;
+ }
+
+ public int compare(CDOID id1, CDOID id2)
+ {
+ return id1.compareTo(id2);
}
public CDOID createCDOID(String val)
@@ -114,6 +119,11 @@ public class LongIDHandler extends Lifecycle implements IIDHandler
return compare(id, nextLocalObjectID) > 0;
}
+ public DBType getDBType()
+ {
+ return DBType.BIGINT;
+ }
+
public ITypeMapping getObjectTypeMapping()
{
return new CoreTypeMappings.TMObject();
@@ -184,16 +194,6 @@ public class LongIDHandler extends Lifecycle implements IIDHandler
return create(id);
}
- public CDOID getMinCDOID()
- {
- return MIN;
- }
-
- public CDOID getMaxCDOID()
- {
- return MAX;
- }
-
public CDOID mapURI(IDBStoreAccessor accessor, String uri, long commitTime)
{
return create(externalReferenceManager.mapURI(accessor, uri, commitTime));
diff --git a/plugins/org.eclipse.emf.cdo.server.db4o/src/org/eclipse/emf/cdo/server/internal/db4o/DB4OStore.java b/plugins/org.eclipse.emf.cdo.server.db4o/src/org/eclipse/emf/cdo/server/internal/db4o/DB4OStore.java
index d9c9c4e2f6..58b7a09f08 100644
--- a/plugins/org.eclipse.emf.cdo.server.db4o/src/org/eclipse/emf/cdo/server/internal/db4o/DB4OStore.java
+++ b/plugins/org.eclipse.emf.cdo.server.db4o/src/org/eclipse/emf/cdo/server/internal/db4o/DB4OStore.java
@@ -94,7 +94,7 @@ public class DB4OStore extends LongIDStore implements IDB4OStore
getServerInfo().setCreationTime(creationTime);
}
- public boolean isFirstTime()
+ public boolean isFirstStart()
{
return getServerInfo().isFirstTime();
}
diff --git a/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/HibernateStore.java b/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/HibernateStore.java
index c033b206bc..c6c8b62695 100644
--- a/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/HibernateStore.java
+++ b/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/HibernateStore.java
@@ -536,7 +536,7 @@ public class HibernateStore extends Store implements IHibernateStore
return currentHibernateStore.get();
}
- public boolean isFirstTime()
+ public boolean isFirstStart()
{
return getSystemInformation().isFirstTime();
}
diff --git a/plugins/org.eclipse.emf.cdo.server.mongodb/META-INF/MANIFEST.MF b/plugins/org.eclipse.emf.cdo.server.mongodb/META-INF/MANIFEST.MF
index ff47debfff..b7c044b7df 100644
--- a/plugins/org.eclipse.emf.cdo.server.mongodb/META-INF/MANIFEST.MF
+++ b/plugins/org.eclipse.emf.cdo.server.mongodb/META-INF/MANIFEST.MF
@@ -13,7 +13,7 @@ Require-Bundle: org.eclipse.core.runtime;bundle-version="[3.4.0,4.0.0)",
org.eclipse.emf.cdo.server;bundle-version="[4.0.0,5.0.0)";visibility:=reexport
Export-Package: org.eclipse.emf.cdo.server.internal.mongodb;version="4.0.0";x-friends:="org.eclipse.emf.cdo.tests,org.eclipse.emf.cdo.tests.mongodb",
org.eclipse.emf.cdo.server.internal.mongodb.bundle;version="4.0.0";x-internal:=true,
- org.eclipse.emf.cdo.server.mongodbdb;version="4.0.0"
+ org.eclipse.emf.cdo.server.mongodb;version="4.0.0"
Import-Package: com.mongodb;version="[2.0.0,3.0.0)",
com.mongodb.gridfs;version="[2.0.0,3.0.0)",
com.mongodb.io;version="[2.0.0,3.0.0)",
diff --git a/plugins/org.eclipse.emf.cdo.server.mongodb/src/org/eclipse/emf/cdo/server/internal/mongodb/LongIDHandler.java b/plugins/org.eclipse.emf.cdo.server.mongodb/src/org/eclipse/emf/cdo/server/internal/mongodb/LongIDHandler.java
new file mode 100644
index 0000000000..37cafaef6e
--- /dev/null
+++ b/plugins/org.eclipse.emf.cdo.server.mongodb/src/org/eclipse/emf/cdo/server/internal/mongodb/LongIDHandler.java
@@ -0,0 +1,122 @@
+/**
+ * Copyright (c) 2004 - 2011 Eike Stepper (Berlin, Germany) and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Eike Stepper - initial API and implementation
+ */
+package org.eclipse.emf.cdo.server.internal.mongodb;
+
+import org.eclipse.emf.cdo.common.id.CDOID;
+import org.eclipse.emf.cdo.common.id.CDOID.ObjectType;
+import org.eclipse.emf.cdo.common.id.CDOIDUtil;
+import org.eclipse.emf.cdo.common.revision.CDORevision;
+import org.eclipse.emf.cdo.server.mongodb.IMongoDBStore.IDHandler;
+import org.eclipse.emf.cdo.spi.server.LongIDStore;
+
+import org.eclipse.net4j.util.lifecycle.Lifecycle;
+
+import java.util.Set;
+
+/**
+ * @author Eike Stepper
+ */
+public class LongIDHandler extends Lifecycle implements IDHandler
+{
+ public static final CDOID MIN = CDOID.NULL;
+
+ public static final CDOID MAX = create(Long.MAX_VALUE);
+
+ private MongoDBStore store;
+
+ private CDOID lastObjectID = MIN;
+
+ private CDOID nextLocalObjectID = MAX;
+
+ public LongIDHandler(MongoDBStore store)
+ {
+ this.store = store;
+ }
+
+ public MongoDBStore getStore()
+ {
+ return store;
+ }
+
+ public Set<ObjectType> getObjectIDTypes()
+ {
+ return LongIDStore.OBJECT_ID_TYPES;
+ }
+
+ public CDOID getMinCDOID()
+ {
+ return MIN;
+ }
+
+ public CDOID getMaxCDOID()
+ {
+ return MAX;
+ }
+
+ public int compare(CDOID id1, CDOID id2)
+ {
+ return id1.compareTo(id2);
+ }
+
+ public CDOID createCDOID(String val)
+ {
+ Long id = Long.valueOf(val);
+ return create(id);
+ }
+
+ public synchronized CDOID getLastObjectID()
+ {
+ return lastObjectID;
+ }
+
+ public synchronized void setLastObjectID(CDOID lastObjectID)
+ {
+ this.lastObjectID = lastObjectID;
+ }
+
+ public synchronized CDOID getNextLocalObjectID()
+ {
+ return nextLocalObjectID;
+ }
+
+ public synchronized void setNextLocalObjectID(CDOID nextLocalObjectID)
+ {
+ this.nextLocalObjectID = nextLocalObjectID;
+ }
+
+ public synchronized CDOID getNextCDOID(CDORevision revision)
+ {
+ if (revision.getBranch().isLocal())
+ {
+ CDOID result = nextLocalObjectID;
+ nextLocalObjectID = create(value(result) - 1);
+ return result;
+ }
+
+ lastObjectID = create(value(lastObjectID) + 1);
+ return lastObjectID;
+ }
+
+ public boolean isLocalCDOID(CDOID id)
+ {
+ return compare(id, nextLocalObjectID) > 0;
+ }
+
+ private static CDOID create(long id)
+ {
+ return CDOIDUtil.createLong(id);
+ }
+
+ private static long value(CDOID id)
+ {
+ return CDOIDUtil.getLong(id);
+ }
+}
diff --git a/plugins/org.eclipse.emf.cdo.server.mongodb/src/org/eclipse/emf/cdo/server/internal/mongodb/MongoDBBrowserPage.java b/plugins/org.eclipse.emf.cdo.server.mongodb/src/org/eclipse/emf/cdo/server/internal/mongodb/MongoDBBrowserPage.java
index 92d10902cc..9da127721f 100644
--- a/plugins/org.eclipse.emf.cdo.server.mongodb/src/org/eclipse/emf/cdo/server/internal/mongodb/MongoDBBrowserPage.java
+++ b/plugins/org.eclipse.emf.cdo.server.mongodb/src/org/eclipse/emf/cdo/server/internal/mongodb/MongoDBBrowserPage.java
@@ -2,7 +2,7 @@ package org.eclipse.emf.cdo.server.internal.mongodb;
import org.eclipse.emf.cdo.server.CDOServerBrowser;
import org.eclipse.emf.cdo.server.CDOServerBrowser.AbstractPage;
-import org.eclipse.emf.cdo.server.mongodbdb.IMongoDBStore;
+import org.eclipse.emf.cdo.server.mongodb.IMongoDBStore;
import org.eclipse.emf.cdo.spi.server.InternalRepository;
import org.eclipse.net4j.util.factory.ProductCreationException;
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 f0364e31f6..d71d7020e3 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
@@ -11,20 +11,32 @@
package org.eclipse.emf.cdo.server.internal.mongodb;
import org.eclipse.emf.cdo.common.id.CDOID;
+import org.eclipse.emf.cdo.common.util.CDOCommonUtil;
import org.eclipse.emf.cdo.server.ISession;
import org.eclipse.emf.cdo.server.IStoreAccessor;
import org.eclipse.emf.cdo.server.ITransaction;
import org.eclipse.emf.cdo.server.IView;
-import org.eclipse.emf.cdo.server.mongodbdb.IMongoDBStore;
-import org.eclipse.emf.cdo.server.mongodbdb.IMongoDBStoreAccessor;
+import org.eclipse.emf.cdo.server.internal.mongodb.bundle.OM;
+import org.eclipse.emf.cdo.server.mongodb.IMongoDBStore;
+import org.eclipse.emf.cdo.server.mongodb.IMongoDBStoreAccessor;
import org.eclipse.emf.cdo.spi.server.Store;
import org.eclipse.emf.cdo.spi.server.StoreAccessorPool;
+import org.eclipse.net4j.util.lifecycle.LifecycleUtil;
+
+import com.mongodb.BasicDBObject;
import com.mongodb.DB;
+import com.mongodb.DBCollection;
+import com.mongodb.DBCursor;
+import com.mongodb.DBObject;
import com.mongodb.Mongo;
import com.mongodb.MongoURI;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
import java.util.Map;
+import java.util.Map.Entry;
import java.util.Set;
/**
@@ -34,17 +46,41 @@ public class MongoDBStore extends Store implements IMongoDBStore
{
public static final String TYPE = "mongodb"; //$NON-NLS-1$
+ private static final String PROP_REPOSITORY_CREATED = "org.eclipse.emf.cdo.server.mongodb.repositoryCreated"; //$NON-NLS-1$
+
+ private static final String PROP_REPOSITORY_STOPPED = "org.eclipse.emf.cdo.server.mongodb.repositoryStopped"; //$NON-NLS-1$
+
+ private static final String PROP_NEXT_LOCAL_CDOID = "org.eclipse.emf.cdo.server.mongodb.nextLocalCDOID"; //$NON-NLS-1$
+
+ private static final String PROP_LAST_CDOID = "org.eclipse.emf.cdo.server.mongodb.lastCDOID"; //$NON-NLS-1$
+
+ private static final String PROP_LAST_BRANCHID = "org.eclipse.emf.cdo.server.mongodb.lastBranchID"; //$NON-NLS-1$
+
+ private static final String PROP_LAST_LOCAL_BRANCHID = "org.eclipse.emf.cdo.server.mongodb.lastLocalBranchID"; //$NON-NLS-1$
+
+ private static final String PROP_LAST_COMMITTIME = "org.eclipse.emf.cdo.server.mongodb.lastCommitTime"; //$NON-NLS-1$
+
+ private static final String PROP_LAST_NONLOCAL_COMMITTIME = "org.eclipse.emf.cdo.server.mongodb.lastNonLocalCommitTime"; //$NON-NLS-1$
+
+ private static final String PROP_GRACEFULLY_SHUT_DOWN = "org.eclipse.emf.cdo.server.mongodb.gracefullyShutDown"; //$NON-NLS-1$
+
private MongoURI mongoURI;
private String dbName;
- private DB db;
-
private IsolationLevel isolationLevel;
private EmbeddingStrategy embeddingStrategy;
- private IDHandler idHandler;
+ private IDHandler idHandler = new LongIDHandler(this);
+
+ private DB db;
+
+ private DBCollection propertiesCollection;
+
+ private boolean firstStart;
+
+ private long creationTime;
public MongoDBStore()
{
@@ -75,12 +111,6 @@ public class MongoDBStore extends Store implements IMongoDBStore
this.dbName = dbName;
}
- public DB getDB()
- {
- checkActive();
- return db;
- }
-
public IsolationLevel getIsolationLevel()
{
return isolationLevel;
@@ -114,14 +144,52 @@ public class MongoDBStore extends Store implements IMongoDBStore
this.idHandler = idHandler;
}
+ public DB getDB()
+ {
+ return db;
+ }
+
+ public DBCollection getPropertiesCollection()
+ {
+ return propertiesCollection;
+ }
+
public Map<String, String> getPropertyValues(Set<String> names)
{
- throw new UnsupportedOperationException("Not yet implemented"); // TODO Implement me
+ Map<String, String> result = new HashMap<String, String>();
+ for (String name : names)
+ {
+ DBObject query = new BasicDBObject("_id", name);
+ DBCursor cursor = propertiesCollection.find(query);
+
+ try
+ {
+ if (cursor.hasNext())
+ {
+ DBObject doc = cursor.next();
+ result.put(name, (String)doc.get("v"));
+ }
+ }
+ finally
+ {
+ cursor.close();
+ }
+ }
+
+ return result;
}
public void setPropertyValues(Map<String, String> properties)
{
- throw new UnsupportedOperationException("Not yet implemented"); // TODO Implement me
+ for (Entry<String, String> property : properties.entrySet())
+ {
+ DBObject doc = new BasicDBObject();
+ doc.put("_id", property.getKey());
+ doc.put("v", property.getValue());
+
+ propertiesCollection.insert(doc);
+
+ }
}
public void removePropertyValues(Set<String> names)
@@ -129,19 +197,23 @@ public class MongoDBStore extends Store implements IMongoDBStore
throw new UnsupportedOperationException("Not yet implemented"); // TODO Implement me
}
- public boolean isFirstTime()
+ public boolean isFirstStart()
{
- throw new UnsupportedOperationException("Not yet implemented"); // TODO Implement me
+ return firstStart;
}
public long getCreationTime()
{
- throw new UnsupportedOperationException("Not yet implemented"); // TODO Implement me
+ return creationTime;
}
public void setCreationTime(long creationTime)
{
- throw new UnsupportedOperationException("Not yet implemented"); // TODO Implement me
+ this.creationTime = creationTime;
+
+ Map<String, String> map = new HashMap<String, String>();
+ map.put(PROP_REPOSITORY_CREATED, Long.toString(creationTime));
+ setPropertyValues(map);
}
public CDOID createObjectID(String val)
@@ -204,14 +276,44 @@ public class MongoDBStore extends Store implements IMongoDBStore
protected void doActivate() throws Exception
{
super.doActivate();
+ setObjectIDTypes(idHandler.getObjectIDTypes());
Mongo mongo = new Mongo(mongoURI);
db = mongo.getDB(dbName);
+
+ Set<String> collectionNames = db.getCollectionNames();
+ firstStart = !collectionNames.contains("cdo.properties");
+
+ propertiesCollection = db.getCollection("cdo.properties");
+
+ LifecycleUtil.activate(idHandler);
+
+ if (firstStart)
+ {
+ firstStart();
+ }
+ else
+ {
+ reStart();
+ }
}
@Override
protected void doDeactivate() throws Exception
{
+ Map<String, String> map = new HashMap<String, String>();
+ map.put(PROP_GRACEFULLY_SHUT_DOWN, Boolean.TRUE.toString());
+ map.put(PROP_REPOSITORY_STOPPED, Long.toString(getRepository().getTimeStamp()));
+ map.put(PROP_NEXT_LOCAL_CDOID, Store.idToString(idHandler.getNextLocalObjectID()));
+ map.put(PROP_LAST_CDOID, Store.idToString(idHandler.getLastObjectID()));
+ map.put(PROP_LAST_BRANCHID, Integer.toString(getLastBranchID()));
+ map.put(PROP_LAST_LOCAL_BRANCHID, Integer.toString(getLastLocalBranchID()));
+ map.put(PROP_LAST_COMMITTIME, Long.toString(getLastCommitTime()));
+ map.put(PROP_LAST_NONLOCAL_COMMITTIME, Long.toString(getLastNonLocalCommitTime()));
+ setPropertyValues(map);
+
+ LifecycleUtil.activate(idHandler);
+
if (db != null)
{
db.getMongo().close();
@@ -220,4 +322,50 @@ public class MongoDBStore extends Store implements IMongoDBStore
super.doDeactivate();
}
+
+ protected void firstStart()
+ {
+ setCreationTime(getRepository().getTimeStamp());
+ OM.LOG.info("First start: " + CDOCommonUtil.formatTimeStamp(creationTime));
+ }
+
+ protected void reStart()
+ {
+ Set<String> names = new HashSet<String>();
+ names.add(PROP_REPOSITORY_CREATED);
+ names.add(PROP_GRACEFULLY_SHUT_DOWN);
+
+ Map<String, String> map = getPropertyValues(names);
+ creationTime = Long.valueOf(map.get(PROP_REPOSITORY_CREATED));
+
+ if (map.containsKey(PROP_GRACEFULLY_SHUT_DOWN))
+ {
+ names.clear();
+ names.add(PROP_NEXT_LOCAL_CDOID);
+ names.add(PROP_LAST_CDOID);
+ names.add(PROP_LAST_BRANCHID);
+ names.add(PROP_LAST_LOCAL_BRANCHID);
+ names.add(PROP_LAST_COMMITTIME);
+ names.add(PROP_LAST_NONLOCAL_COMMITTIME);
+ map = getPropertyValues(names);
+
+ idHandler.setNextLocalObjectID(stringToID(map.get(PROP_NEXT_LOCAL_CDOID)));
+ idHandler.setLastObjectID(stringToID(map.get(PROP_LAST_CDOID)));
+ setLastBranchID(Integer.valueOf(map.get(PROP_LAST_BRANCHID)));
+ setLastLocalBranchID(Integer.valueOf(map.get(PROP_LAST_LOCAL_BRANCHID)));
+ setLastCommitTime(Long.valueOf(map.get(PROP_LAST_COMMITTIME)));
+ setLastNonLocalCommitTime(Long.valueOf(map.get(PROP_LAST_NONLOCAL_COMMITTIME)));
+ }
+ else
+ {
+ repairAfterCrash();
+ }
+
+ removePropertyValues(Collections.singleton(PROP_GRACEFULLY_SHUT_DOWN));
+ }
+
+ protected void repairAfterCrash()
+ {
+ throw new UnsupportedOperationException("Not yet implemented"); // TODO Implement me
+ }
}
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 a945776539..4217b3d6c8 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
@@ -25,7 +25,7 @@ import org.eclipse.emf.cdo.server.IQueryHandler;
import org.eclipse.emf.cdo.server.ISession;
import org.eclipse.emf.cdo.server.IStoreChunkReader;
import org.eclipse.emf.cdo.server.ITransaction;
-import org.eclipse.emf.cdo.server.mongodbdb.IMongoDBStoreAccessor;
+import org.eclipse.emf.cdo.server.mongodb.IMongoDBStoreAccessor;
import org.eclipse.emf.cdo.spi.common.commit.CDOChangeSetSegment;
import org.eclipse.emf.cdo.spi.common.model.InternalCDOPackageUnit;
import org.eclipse.emf.cdo.spi.common.revision.InternalCDORevision;
diff --git a/plugins/org.eclipse.emf.cdo.server.mongodb/src/org/eclipse/emf/cdo/server/mongodb/CDOMongoDBUtil.java b/plugins/org.eclipse.emf.cdo.server.mongodb/src/org/eclipse/emf/cdo/server/mongodb/CDOMongoDBUtil.java
index 7c08a601bb..b8e1e85a63 100644
--- a/plugins/org.eclipse.emf.cdo.server.mongodb/src/org/eclipse/emf/cdo/server/mongodb/CDOMongoDBUtil.java
+++ b/plugins/org.eclipse.emf.cdo.server.mongodb/src/org/eclipse/emf/cdo/server/mongodb/CDOMongoDBUtil.java
@@ -10,7 +10,7 @@
* Stefan Winkler - 271444: [DB] Multiple refactorings
* Stefan Winkler - 249610: [DB] Support external references (Implementation)
*/
-package org.eclipse.emf.cdo.server.mongodbdb;
+package org.eclipse.emf.cdo.server.mongodb;
import org.eclipse.emf.cdo.server.internal.mongodb.MongoDBBrowserPage;
import org.eclipse.emf.cdo.server.internal.mongodb.MongoDBStore;
diff --git a/plugins/org.eclipse.emf.cdo.server.mongodb/src/org/eclipse/emf/cdo/server/mongodb/IMongoDBStore.java b/plugins/org.eclipse.emf.cdo.server.mongodb/src/org/eclipse/emf/cdo/server/mongodb/IMongoDBStore.java
index be42766c13..5c2bd44cc4 100644
--- a/plugins/org.eclipse.emf.cdo.server.mongodb/src/org/eclipse/emf/cdo/server/mongodb/IMongoDBStore.java
+++ b/plugins/org.eclipse.emf.cdo.server.mongodb/src/org/eclipse/emf/cdo/server/mongodb/IMongoDBStore.java
@@ -10,15 +10,22 @@
* Stefan Winkler - 271444: [DB] Multiple refactorings
* Stefan Winkler - 249610: [DB] Support external references (Implementation)
*/
-package org.eclipse.emf.cdo.server.mongodbdb;
+package org.eclipse.emf.cdo.server.mongodb;
+import org.eclipse.emf.cdo.common.id.CDOID;
+import org.eclipse.emf.cdo.common.id.CDOID.ObjectType;
+import org.eclipse.emf.cdo.common.revision.CDORevision;
import org.eclipse.emf.cdo.server.ISession;
import org.eclipse.emf.cdo.server.IStore;
import org.eclipse.emf.cdo.server.ITransaction;
import com.mongodb.DB;
+import com.mongodb.DBCollection;
import com.mongodb.MongoURI;
+import java.util.Comparator;
+import java.util.Set;
+
/**
* @author Eike Stepper
*/
@@ -28,8 +35,6 @@ public interface IMongoDBStore extends IStore
public String getDBName();
- public DB getDB();
-
public IsolationLevel getIsolationLevel();
public EmbeddingStrategy getEmbeddingStrategy();
@@ -40,6 +45,10 @@ public interface IMongoDBStore extends IStore
public IMongoDBStoreAccessor getWriter(ITransaction transaction);
+ public DB getDB();
+
+ public DBCollection getPropertiesCollection();
+
/**
* @author Eike Stepper
*/
@@ -57,7 +66,28 @@ public interface IMongoDBStore extends IStore
/**
* @author Eike Stepper
*/
- public interface IDHandler
+ public interface IDHandler extends Comparator<CDOID>
{
+ public IMongoDBStore getStore();
+
+ public Set<ObjectType> getObjectIDTypes();
+
+ public CDOID getMinCDOID();
+
+ public CDOID getMaxCDOID();
+
+ public boolean isLocalCDOID(CDOID id);
+
+ public CDOID getNextCDOID(CDORevision revision);
+
+ public CDOID createCDOID(String val);
+
+ public CDOID getNextLocalObjectID();
+
+ public void setNextLocalObjectID(CDOID nextLocalObjectID);
+
+ public CDOID getLastObjectID();
+
+ public void setLastObjectID(CDOID lastObjectID);
}
}
diff --git a/plugins/org.eclipse.emf.cdo.server.mongodb/src/org/eclipse/emf/cdo/server/mongodb/IMongoDBStoreAccessor.java b/plugins/org.eclipse.emf.cdo.server.mongodb/src/org/eclipse/emf/cdo/server/mongodb/IMongoDBStoreAccessor.java
index d9166d0155..6ad0e8be0f 100644
--- a/plugins/org.eclipse.emf.cdo.server.mongodb/src/org/eclipse/emf/cdo/server/mongodb/IMongoDBStoreAccessor.java
+++ b/plugins/org.eclipse.emf.cdo.server.mongodb/src/org/eclipse/emf/cdo/server/mongodb/IMongoDBStoreAccessor.java
@@ -8,7 +8,7 @@
* Contributors:
* Eike Stepper - initial API and implementation
*/
-package org.eclipse.emf.cdo.server.mongodbdb;
+package org.eclipse.emf.cdo.server.mongodb;
import org.eclipse.emf.cdo.server.IStoreAccessor;
diff --git a/plugins/org.eclipse.emf.cdo.server.objectivity/src/org/eclipse/emf/cdo/server/internal/objectivity/ObjectivityStore.java b/plugins/org.eclipse.emf.cdo.server.objectivity/src/org/eclipse/emf/cdo/server/internal/objectivity/ObjectivityStore.java
index edc0f3348f..4d6be2d2f4 100644
--- a/plugins/org.eclipse.emf.cdo.server.objectivity/src/org/eclipse/emf/cdo/server/internal/objectivity/ObjectivityStore.java
+++ b/plugins/org.eclipse.emf.cdo.server.objectivity/src/org/eclipse/emf/cdo/server/internal/objectivity/ObjectivityStore.java
@@ -235,7 +235,7 @@ public class ObjectivityStore extends Store implements IObjectivityStore
throw new UnsupportedOperationException();
}
- public boolean isFirstTime()
+ public boolean isFirstStart()
{
return firstTime;
}
diff --git a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/Repository.java b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/Repository.java
index fdd1e229dd..4233004dca 100644
--- a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/Repository.java
+++ b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/Repository.java
@@ -1556,7 +1556,7 @@ public class Repository extends Container<Object> implements InternalRepository
lastCommitTimeStamp = Math.max(store.getCreationTime(), store.getLastCommitTime());
initMainBranch(branchManager, lastCommitTimeStamp);
- if (store.isFirstTime())
+ if (store.isFirstStart())
{
initSystemPackages();
initRootResource();
diff --git a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/mem/MEMStore.java b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/mem/MEMStore.java
index 41328182c9..d750f09347 100644
--- a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/mem/MEMStore.java
+++ b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/mem/MEMStore.java
@@ -814,7 +814,7 @@ public class MEMStore extends LongIDStore implements IMEMStore, BranchLoader
this.creationTime = creationTime;
}
- public boolean isFirstTime()
+ public boolean isFirstStart()
{
return true;
}
diff --git a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/syncing/SynchronizableRepository.java b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/syncing/SynchronizableRepository.java
index 875add2267..ae3ba3f7e3 100644
--- a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/syncing/SynchronizableRepository.java
+++ b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/syncing/SynchronizableRepository.java
@@ -342,7 +342,7 @@ public abstract class SynchronizableRepository extends Repository.Default implem
super.doActivate();
InternalStore store = getStore();
- if (!store.isFirstTime())
+ if (!store.isFirstStart())
{
Map<String, String> map = store.getPropertyValues(Collections.singleton(PROP_GRACEFULLY_SHUT_DOWN));
if (!map.containsKey(PROP_GRACEFULLY_SHUT_DOWN))
diff --git a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/IStore.java b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/IStore.java
index ec261217b6..b47bffd5a7 100644
--- a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/IStore.java
+++ b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/IStore.java
@@ -72,9 +72,9 @@ public interface IStore
/**
* Returns <code>true</code>if this store was activated for the first time, <code>false</code> otherwise.
*
- * @since 2.0
+ * @since 4.0
*/
- public boolean isFirstTime();
+ public boolean isFirstStart();
/**
* Returns the store creation time.
diff --git a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/spi/server/Store.java b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/spi/server/Store.java
index 6502c09aa6..e4930defd9 100644
--- a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/spi/server/Store.java
+++ b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/spi/server/Store.java
@@ -15,6 +15,7 @@ import org.eclipse.emf.cdo.common.branch.CDOBranch;
import org.eclipse.emf.cdo.common.branch.CDOBranchPoint;
import org.eclipse.emf.cdo.common.id.CDOID;
import org.eclipse.emf.cdo.common.id.CDOID.ObjectType;
+import org.eclipse.emf.cdo.common.id.CDOIDUtil;
import org.eclipse.emf.cdo.common.revision.CDORevisionFactory;
import org.eclipse.emf.cdo.internal.server.Repository;
import org.eclipse.emf.cdo.server.IRepository;
@@ -473,6 +474,24 @@ public abstract class Store extends Lifecycle implements InternalStore
}
/**
+ * @since 4.0
+ */
+ public static String idToString(CDOID id)
+ {
+ StringBuilder builder = new StringBuilder();
+ CDOIDUtil.write(builder, id);
+ return builder.toString();
+ }
+
+ /**
+ * @since 4.0
+ */
+ public static CDOID stringToID(String string)
+ {
+ return CDOIDUtil.read(string);
+ }
+
+ /**
* @since 3.0
*/
public static IStoreAccessor.QueryResourcesContext.ExactMatch createExactMatchContext(final CDOID folderID,
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