Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
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.java61
-rw-r--r--plugins/org.eclipse.emf.cdo.server.mongodb/src/org/eclipse/emf/cdo/server/internal/mongodb/Commits.java275
-rw-r--r--plugins/org.eclipse.emf.cdo.server.mongodb/src/org/eclipse/emf/cdo/server/internal/mongodb/Mode.java94
-rw-r--r--plugins/org.eclipse.emf.cdo.server.mongodb/src/org/eclipse/emf/cdo/server/internal/mongodb/MongoDBBrowserPage.java8
-rw-r--r--plugins/org.eclipse.emf.cdo.server.mongodb/src/org/eclipse/emf/cdo/server/internal/mongodb/MongoDBStore.java237
-rw-r--r--plugins/org.eclipse.emf.cdo.server.mongodb/src/org/eclipse/emf/cdo/server/internal/mongodb/MongoDBStoreAccessor.java249
-rw-r--r--plugins/org.eclipse.emf.cdo.server.mongodb/src/org/eclipse/emf/cdo/server/internal/mongodb/Props.java100
7 files changed, 562 insertions, 462 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
new file mode 100644
index 0000000000..8ff125609a
--- /dev/null
+++ b/plugins/org.eclipse.emf.cdo.server.mongodb/src/org/eclipse/emf/cdo/server/internal/mongodb/Coll.java
@@ -0,0 +1,61 @@
+/**
+ * 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 com.mongodb.BasicDBObject;
+import com.mongodb.DBCollection;
+import com.mongodb.DBObject;
+
+/**
+ * @author Eike Stepper
+ */
+public class Coll
+{
+ protected MongoDBStore store;
+
+ protected DBCollection collection;
+
+ public Coll(MongoDBStore store, String name)
+ {
+ this.store = store;
+ collection = store.getDB().getCollection(name);
+ }
+
+ public MongoDBStore getStore()
+ {
+ return store;
+ }
+
+ public DBCollection getCollection()
+ {
+ return collection;
+ }
+
+ public void ensureIndex(String element, String field, boolean asc)
+ {
+ DBObject index = new BasicDBObject();
+ index.put(element + "." + field, asc ? 1 : -1);
+
+ collection.ensureIndex(index);
+ }
+
+ public void ensureIndex(String element, String... fields)
+ {
+ DBObject index = new BasicDBObject();
+ for (String field : fields)
+ {
+ index.put(element + "." + field, 1);
+
+ }
+
+ collection.ensureIndex(index);
+ }
+}
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
new file mode 100644
index 0000000000..ac0e2d6de6
--- /dev/null
+++ b/plugins/org.eclipse.emf.cdo.server.mongodb/src/org/eclipse/emf/cdo/server/internal/mongodb/Commits.java
@@ -0,0 +1,275 @@
+/**
+ * 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.branch.CDOBranchPoint;
+import org.eclipse.emf.cdo.common.id.CDOID;
+import org.eclipse.emf.cdo.common.id.CDOIDUtil;
+import org.eclipse.emf.cdo.common.model.EMFUtil;
+import org.eclipse.emf.cdo.spi.common.model.InternalCDOPackageInfo;
+import org.eclipse.emf.cdo.spi.common.model.InternalCDOPackageRegistry;
+import org.eclipse.emf.cdo.spi.common.model.InternalCDOPackageUnit;
+import org.eclipse.emf.cdo.spi.common.revision.InternalCDORevision;
+import org.eclipse.emf.cdo.spi.server.InternalCommitContext;
+
+import org.eclipse.net4j.util.ObjectUtil;
+import org.eclipse.net4j.util.StringUtil;
+import org.eclipse.net4j.util.om.monitor.OMMonitor;
+
+import org.eclipse.emf.ecore.EClassifier;
+import org.eclipse.emf.ecore.EPackage;
+
+import com.mongodb.BasicDBObject;
+import com.mongodb.DBObject;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * @author Eike Stepper
+ */
+public class Commits extends Coll
+{
+ public static final String COMMITS = "commits";
+
+ public static final String COMMITS_ID = "_id";
+
+ public static final String COMMITS_PREVIOUS = "previous";
+
+ public static final String COMMITS_BRANCH = "branch";
+
+ public static final String COMMITS_USER = "user";
+
+ public static final String COMMITS_COMMENT = "comment";
+
+ public static final String UNITS = "units";
+
+ public static final String UNITS_ID = "id";
+
+ 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";
+
+ public static final String PACKAGES_URI = "uri";
+
+ public static final String PACKAGES_PARENT = "parent";
+
+ public static final String CLASSIFIER_PREFIX = "c";
+
+ public static final String REVISIONS = "revisions";
+
+ 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";
+
+ public static final String REVISIONS_RESOURCE = "cdo_resource";
+
+ public static final String REVISIONS_CONTAINER = "cdo_container";
+
+ public static final String REVISIONS_FEATURE = "cdo_feature";
+
+ private static final boolean ZIP_PACKAGE_BYTES = true;
+
+ private InternalCDOPackageUnit[] systemPackageUnits;
+
+ public Commits(MongoDBStore store)
+ {
+ super(store, COMMITS);
+
+ ensureIndex(UNITS, UNITS_ID);
+ ensureIndex(UNITS, UNITS_TIME);
+
+ if (store.isBranching())
+ {
+ ensureIndex(REVISIONS, REVISIONS_ID, REVISIONS_BRANCH, REVISIONS_VERSION);
+ }
+ else
+ {
+ ensureIndex(REVISIONS, REVISIONS_ID, REVISIONS_VERSION);
+ }
+ }
+
+ public void writePackageUnits(MongoDBStoreAccessor mongoDBStoreAccessor, InternalCDOPackageUnit[] packageUnits,
+ OMMonitor monitor)
+ {
+ systemPackageUnits = packageUnits;
+ }
+
+ public void write(MongoDBStoreAccessor accessor, InternalCommitContext context, OMMonitor monitor)
+ {
+ try
+ {
+ monitor.begin(104);
+ CDOBranchPoint branchPoint = context.getBranchPoint();
+
+ DBObject doc = new BasicDBObject();
+ doc.put(COMMITS_ID, branchPoint.getTimeStamp());
+
+ long previous = context.getPreviousTimeStamp();
+ boolean firstCommit = previous == CDOBranchPoint.UNSPECIFIED_DATE;
+ if (!firstCommit)
+ {
+ doc.put(COMMITS_PREVIOUS, previous);
+ }
+
+ if (getStore().isBranching())
+ {
+ doc.put(COMMITS_BRANCH, branchPoint.getBranch().getID());
+ }
+
+ String user = context.getUserID();
+ if (!StringUtil.isEmpty(user))
+ {
+ doc.put(COMMITS_USER, user);
+ }
+
+ String comment = context.getCommitComment();
+ if (!StringUtil.isEmpty(comment))
+ {
+ doc.put(COMMITS_COMMENT, comment);
+ }
+
+ InternalCDOPackageUnit[] newPackageUnits = firstCommit ? systemPackageUnits : context.getNewPackageUnits();
+ if (!ObjectUtil.isEmpty(newPackageUnits))
+ {
+ doc.put(UNITS, marshallUnits(newPackageUnits));
+ }
+
+ monitor.worked();
+ accessor.addIDMappings(context, monitor.fork());
+ context.applyIDMappings(monitor.fork());
+
+ List<DBObject> docs = new ArrayList<DBObject>();
+ marshalRevisions(docs, context.getNewObjects());
+ marshalRevisions(docs, context.getDirtyObjects());
+ if (!docs.isEmpty())
+ {
+ doc.put(REVISIONS, docs);
+ }
+
+ monitor.worked();
+
+ collection.insert(doc);
+ monitor.worked(100);
+ }
+ finally
+ {
+ monitor.done();
+ }
+ }
+
+ private DBObject[] marshallUnits(InternalCDOPackageUnit[] packageUnits)
+ {
+ DBObject[] result = new DBObject[packageUnits.length];
+ InternalCDOPackageRegistry packageRegistry = getStore().getRepository().getPackageRegistry();
+
+ for (int i = 0; i < packageUnits.length; i++)
+ {
+ InternalCDOPackageUnit packageUnit = packageUnits[i];
+ EPackage ePackage = packageUnit.getTopLevelPackageInfo().getEPackage();
+ byte[] bytes = EMFUtil.getEPackageBytes(ePackage, ZIP_PACKAGE_BYTES, packageRegistry);
+ DBObject[] packages = marshallPackages(packageUnit.getPackageInfos());
+
+ DBObject doc = new BasicDBObject();
+ doc.put(UNITS_ID, packageUnit.getID());
+ doc.put(UNITS_TYPE, packageUnit.getOriginalType().toString());
+ doc.put(UNITS_TIME, packageUnit.getTimeStamp());
+ doc.put(UNITS_DATA, bytes);
+ doc.put(PACKAGES, packages);
+
+ result[i] = doc;
+ }
+
+ return result;
+ }
+
+ private DBObject[] marshallPackages(InternalCDOPackageInfo[] packageInfos)
+ {
+ DBObject[] result = new DBObject[packageInfos.length];
+ for (int i = 0; i < packageInfos.length; i++)
+ {
+ InternalCDOPackageInfo packageInfo = packageInfos[i];
+
+ DBObject doc = new BasicDBObject();
+ doc.put(PACKAGES_URI, packageInfo.getPackageURI());
+ String parent = packageInfo.getParentURI();
+ if (!StringUtil.isEmpty(parent))
+ {
+ doc.put(PACKAGES_PARENT, parent);
+ }
+
+ for (EClassifier classifier : packageInfo.getEPackage().getEClassifiers())
+ {
+ int classifierID = getStore().mapNewClassifier(classifier);
+ doc.put(CLASSIFIER_PREFIX + classifierID, classifier.getName());
+ }
+
+ result[i] = doc;
+ }
+
+ return result;
+ }
+
+ private void marshalRevisions(List<DBObject> docs, InternalCDORevision[] revisions)
+ {
+ for (InternalCDORevision revision : revisions)
+ {
+ DBObject doc = marshallRevision(revision);
+ docs.add(doc);
+ }
+ }
+
+ private DBObject marshallRevision(InternalCDORevision revision)
+ {
+ IDHandler idHandler = getStore().getIDHandler();
+
+ DBObject doc = new BasicDBObject();
+ idHandler.write(doc, REVISIONS_ID, revision.getID());
+ if (getStore().isBranching())
+ {
+ int branch = revision.getBranch().getID();
+ if (branch != 0)
+ {
+ doc.put(REVISIONS_BRANCH, branch);
+ }
+ }
+
+ doc.put(REVISIONS_VERSION, revision.getVersion());
+ doc.put(REVISIONS_CLASS, store.getClassifierID(revision.getEClass()));
+
+ CDOID resourceID = revision.getResourceID();
+ if (!CDOIDUtil.isNull(resourceID))
+ {
+ idHandler.write(doc, REVISIONS_RESOURCE, resourceID);
+ }
+
+ CDOID containerID = (CDOID)revision.getContainerID();
+ if (!CDOIDUtil.isNull(containerID))
+ {
+ idHandler.write(doc, REVISIONS_CONTAINER, containerID);
+ int featureID = revision.getContainingFeatureID();
+ if (featureID != 0)
+ {
+ doc.put(REVISIONS_FEATURE, featureID);
+ }
+ }
+
+ return doc;
+ }
+}
diff --git a/plugins/org.eclipse.emf.cdo.server.mongodb/src/org/eclipse/emf/cdo/server/internal/mongodb/Mode.java b/plugins/org.eclipse.emf.cdo.server.mongodb/src/org/eclipse/emf/cdo/server/internal/mongodb/Mode.java
deleted file mode 100644
index 5e4471ef6e..0000000000
--- a/plugins/org.eclipse.emf.cdo.server.mongodb/src/org/eclipse/emf/cdo/server/internal/mongodb/Mode.java
+++ /dev/null
@@ -1,94 +0,0 @@
-/**
- * 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.server.IStoreAccessor.QueryResourcesContext;
-
-import com.mongodb.BasicDBObject;
-import com.mongodb.DBObject;
-
-/**
- * @author Eike Stepper
- */
-public abstract class Mode
-{
- private MongoDBStore store;
-
- protected Mode()
- {
- }
-
- public MongoDBStore getStore()
- {
- return store;
- }
-
- public void setStore(MongoDBStore store)
- {
- this.store = store;
- }
-
- public abstract DBObject createResourcesQuery(CDOID folderID, String name, boolean exactMatch,
- QueryResourcesContext context);
-
- /**
- * @author Eike Stepper
- */
- public static class Normal extends Mode
- {
- @Override
- public DBObject createResourcesQuery(CDOID folderID, String name, boolean exactMatch, QueryResourcesContext context)
- {
- DBObject query = new BasicDBObject();
- query.put("_version", new BasicDBObject("$gt", 0));
- getStore().getIDHandler().write(query, "_container", folderID);
- if (name == null)
- {
- query.put("name", new BasicDBObject("$exists", false));
- }
- else if (exactMatch)
- {
- query.put("name", name);
- }
- else
- {
- query.put("name", new BasicDBObject("$regex", "/^" + name + "/"));
- }
-
- return query;
- }
- }
-
- /**
- * @author Eike Stepper
- */
- public static class Audditing extends Mode
- {
- @Override
- public DBObject createResourcesQuery(CDOID folderID, String name, boolean exactMatch, QueryResourcesContext context)
- {
- return null;
- }
- }
-
- /**
- * @author Eike Stepper
- */
- public static class Branching extends Mode
- {
- @Override
- public DBObject createResourcesQuery(CDOID folderID, String name, boolean exactMatch, QueryResourcesContext context)
- {
- return null;
- }
- }
-}
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 2e3e34fbdf..06509f2296 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
@@ -148,12 +148,12 @@ public class MongoDBBrowserPage extends AbstractPage
if (value instanceof String)
{
pout.print("\"");
+ pout.print(browser.escape((String)value));
+ pout.print("\"");
}
-
- pout.print(value);
- if (value instanceof String)
+ else
{
- pout.print("\"");
+ pout.print(value);
}
pout.print("</font><br>");
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 207a86a24d..ea017205a3 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
@@ -25,11 +25,10 @@ import org.eclipse.emf.cdo.spi.server.StoreAccessorPool;
import org.eclipse.net4j.util.lifecycle.LifecycleUtil;
-import com.mongodb.BasicDBObject;
+import org.eclipse.emf.ecore.EClass;
+import org.eclipse.emf.ecore.EClassifier;
+
import com.mongodb.DB;
-import com.mongodb.DBCollection;
-import com.mongodb.DBCursor;
-import com.mongodb.DBObject;
import com.mongodb.Mongo;
import com.mongodb.MongoURI;
@@ -37,7 +36,6 @@ 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;
/**
@@ -51,25 +49,9 @@ import java.util.Set;
*/
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$
+ public static final String PROPERTIES = "props";
- 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$
+ public static final String TYPE = "mongodb"; //$NON-NLS-1$
private MongoURI mongoURI;
@@ -79,20 +61,24 @@ public class MongoDBStore extends Store implements IMongoDBStore
private Mapper mapper = new Mapper(this);
- private Mode mode;
-
private DB db;
- private DBCollection propertiesCollection;
+ private Props props;
- private DBCollection packageUnitsCollection;
-
- private DBCollection commitInfosCollection;
+ private Commits commits;
private boolean firstStart;
private long creationTime;
+ private boolean branching;
+
+ private int lastClassifierID;
+
+ private Map<EClassifier, Integer> classifierToIDs = new HashMap<EClassifier, Integer>();
+
+ private Map<Integer, EClassifier> idToClassifiers = new HashMap<Integer, EClassifier>();
+
public static Map<String, InternalRepository> REPOS = new HashMap<String, InternalRepository>();
public MongoDBStore()
@@ -140,72 +126,34 @@ public class MongoDBStore extends Store implements IMongoDBStore
return mapper;
}
- public Mode getMode()
- {
- return mode;
- }
-
public DB getDB()
{
return db;
}
- public DBCollection getPropertiesCollection()
- {
- return propertiesCollection;
- }
-
- public DBCollection getPackageUnitsCollection()
+ public Props getProps()
{
- return packageUnitsCollection;
+ return props;
}
- public DBCollection getCommitInfosCollection()
+ public Commits getCommits()
{
- return commitInfosCollection;
+ return commits;
}
public Map<String, String> getPropertyValues(Set<String> names)
{
- 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("value"));
- }
- }
- finally
- {
- cursor.close();
- }
- }
-
- return result;
+ return props.get(names);
}
public void setPropertyValues(Map<String, String> properties)
{
- for (Entry<String, String> property : properties.entrySet())
- {
- DBObject doc = new BasicDBObject();
- doc.put("_id", property.getKey());
- doc.put("value", property.getValue());
-
- propertiesCollection.insert(doc);
-
- }
+ props.set(properties);
}
public void removePropertyValues(Set<String> names)
{
- throw new UnsupportedOperationException("Not yet implemented"); // TODO Implement me
+ props.remove(names);
}
public boolean isFirstStart()
@@ -223,8 +171,46 @@ public class MongoDBStore extends Store implements IMongoDBStore
this.creationTime = creationTime;
Map<String, String> map = new HashMap<String, String>();
- map.put(PROP_REPOSITORY_CREATED, Long.toString(creationTime));
- setPropertyValues(map);
+ map.put(Props.REPOSITORY_CREATED, Long.toString(creationTime));
+ props.set(map);
+ }
+
+ public boolean isBranching()
+ {
+ return branching;
+ }
+
+ public int getLastClassifierID()
+ {
+ return lastClassifierID;
+ }
+
+ public void setLastClassifierID(int lastClassifierID)
+ {
+ this.lastClassifierID = lastClassifierID;
+ }
+
+ public synchronized int mapNewClassifier(EClassifier classifier)
+ {
+ int id = ++lastClassifierID;
+ classifierToIDs.put(classifier, id);
+ idToClassifiers.put(id, classifier);
+ return id;
+ }
+
+ public synchronized int getClassifierID(EClassifier classifier)
+ {
+ return classifierToIDs.get(classifier);
+ }
+
+ public synchronized EClassifier getClassifier(int id)
+ {
+ return idToClassifiers.get(id);
+ }
+
+ public synchronized EClass getClass(int id)
+ {
+ return (EClass)idToClassifiers.get(id);
}
public CDOID createObjectID(String val)
@@ -286,7 +272,10 @@ public class MongoDBStore extends Store implements IMongoDBStore
@Override
protected void doActivate() throws Exception
{
- REPOS.put(getRepository().getName(), getRepository());
+ InternalRepository repository = getRepository();
+ branching = repository.isSupportingBranches();
+
+ REPOS.put(repository.getName(), repository);
super.doActivate();
@@ -294,32 +283,15 @@ public class MongoDBStore extends Store implements IMongoDBStore
db = mongo.getDB(dbName);
Set<String> collectionNames = db.getCollectionNames();
- firstStart = !collectionNames.contains("cdo.properties");
-
- propertiesCollection = db.getCollection("cdo.properties");
- 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");
+ firstStart = !collectionNames.contains(PROPERTIES);
- 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");
+ props = new Props(this);
+ commits = new Commits(this);
LifecycleUtil.activate(idHandler);
setObjectIDTypes(idHandler.getObjectIDTypes());
LifecycleUtil.activate(mapper);
- initMode();
if (firstStart)
{
@@ -337,14 +309,15 @@ public class MongoDBStore extends Store implements IMongoDBStore
REPOS.remove(getRepository().getName());
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()));
+ map.put(Props.GRACEFULLY_SHUT_DOWN, Boolean.TRUE.toString());
+ map.put(Props.REPOSITORY_STOPPED, Long.toString(getRepository().getTimeStamp()));
+ map.put(Props.NEXT_LOCAL_CDOID, Store.idToString(idHandler.getNextLocalObjectID()));
+ map.put(Props.LAST_CDOID, Store.idToString(idHandler.getLastObjectID()));
+ map.put(Props.LAST_CLASSIFIERID, Integer.toString(getLastClassifierID()));
+ map.put(Props.LAST_BRANCHID, Integer.toString(getLastBranchID()));
+ map.put(Props.LAST_LOCAL_BRANCHID, Integer.toString(getLastLocalBranchID()));
+ map.put(Props.LAST_COMMITTIME, Long.toString(getLastCommitTime()));
+ map.put(Props.LAST_NONLOCAL_COMMITTIME, Long.toString(getLastNonLocalCommitTime()));
setPropertyValues(map);
LifecycleUtil.activate(mapper);
@@ -359,24 +332,6 @@ public class MongoDBStore extends Store implements IMongoDBStore
super.doDeactivate();
}
- protected void initMode()
- {
- if (getRepository().isSupportingBranches())
- {
- mode = new Mode.Branching();
- }
- else if (getRepository().isSupportingBranches())
- {
- mode = new Mode.Audditing();
- }
- else
- {
- mode = new Mode.Normal();
- }
-
- mode.setStore(this);
- }
-
protected void firstStart()
{
setCreationTime(getRepository().getTimeStamp());
@@ -386,36 +341,38 @@ public class MongoDBStore extends Store implements IMongoDBStore
protected void reStart()
{
Set<String> names = new HashSet<String>();
- names.add(PROP_REPOSITORY_CREATED);
- names.add(PROP_GRACEFULLY_SHUT_DOWN);
+ names.add(Props.REPOSITORY_CREATED);
+ names.add(Props.GRACEFULLY_SHUT_DOWN);
Map<String, String> map = getPropertyValues(names);
- creationTime = Long.valueOf(map.get(PROP_REPOSITORY_CREATED));
+ creationTime = Long.valueOf(map.get(Props.REPOSITORY_CREATED));
- if (map.containsKey(PROP_GRACEFULLY_SHUT_DOWN))
+ if (map.containsKey(Props.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);
+ names.add(Props.NEXT_LOCAL_CDOID);
+ names.add(Props.LAST_CDOID);
+ names.add(Props.LAST_CLASSIFIERID);
+ names.add(Props.LAST_BRANCHID);
+ names.add(Props.LAST_LOCAL_BRANCHID);
+ names.add(Props.LAST_COMMITTIME);
+ names.add(Props.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)));
+ idHandler.setNextLocalObjectID(stringToID(map.get(Props.NEXT_LOCAL_CDOID)));
+ idHandler.setLastObjectID(stringToID(map.get(Props.LAST_CDOID)));
+ setLastClassifierID(Integer.valueOf(map.get(Props.LAST_CLASSIFIERID)));
+ setLastBranchID(Integer.valueOf(map.get(Props.LAST_BRANCHID)));
+ setLastLocalBranchID(Integer.valueOf(map.get(Props.LAST_LOCAL_BRANCHID)));
+ setLastCommitTime(Long.valueOf(map.get(Props.LAST_COMMITTIME)));
+ setLastNonLocalCommitTime(Long.valueOf(map.get(Props.LAST_NONLOCAL_COMMITTIME)));
}
else
{
repairAfterCrash();
}
- removePropertyValues(Collections.singleton(PROP_GRACEFULLY_SHUT_DOWN));
+ removePropertyValues(Collections.singleton(Props.GRACEFULLY_SHUT_DOWN));
}
protected void repairAfterCrash()
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 36d04287f1..d8226e5ea5 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
@@ -15,13 +15,9 @@ import org.eclipse.emf.cdo.common.branch.CDOBranchHandler;
import org.eclipse.emf.cdo.common.branch.CDOBranchPoint;
import org.eclipse.emf.cdo.common.branch.CDOBranchVersion;
import org.eclipse.emf.cdo.common.commit.CDOCommitData;
-import org.eclipse.emf.cdo.common.commit.CDOCommitInfo;
import org.eclipse.emf.cdo.common.commit.CDOCommitInfoHandler;
import org.eclipse.emf.cdo.common.id.CDOID;
-import org.eclipse.emf.cdo.common.id.CDOIDUtil;
import org.eclipse.emf.cdo.common.lob.CDOLobHandler;
-import org.eclipse.emf.cdo.common.model.CDOClassifierRef;
-import org.eclipse.emf.cdo.common.model.EMFUtil;
import org.eclipse.emf.cdo.common.revision.CDORevision;
import org.eclipse.emf.cdo.common.revision.CDORevisionCacheAdder;
import org.eclipse.emf.cdo.common.revision.CDORevisionHandler;
@@ -34,15 +30,12 @@ import org.eclipse.emf.cdo.server.ITransaction;
import org.eclipse.emf.cdo.server.internal.mongodb.bundle.OM;
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.InternalCDOPackageRegistry;
import org.eclipse.emf.cdo.spi.common.model.InternalCDOPackageUnit;
import org.eclipse.emf.cdo.spi.common.revision.InternalCDORevision;
-import org.eclipse.emf.cdo.spi.common.revision.InternalCDORevisionDelta;
import org.eclipse.emf.cdo.spi.server.InternalCommitContext;
import org.eclipse.emf.cdo.spi.server.Store;
import org.eclipse.emf.cdo.spi.server.StoreAccessorBase;
-import org.eclipse.net4j.util.ObjectUtil;
import org.eclipse.net4j.util.collection.Pair;
import org.eclipse.net4j.util.om.monitor.OMMonitor;
import org.eclipse.net4j.util.om.trace.ContextTracer;
@@ -58,12 +51,8 @@ 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;
-import java.util.Map;
-import java.util.Map.Entry;
import java.util.Set;
/**
@@ -73,8 +62,6 @@ public class MongoDBStoreAccessor extends StoreAccessorBase implements IMongoDBS
{
private static final ContextTracer TRACER = new ContextTracer(OM.DEBUG, MongoDBStoreAccessor.class);
- private static final boolean ZIP_PACKAGE_BYTES = true;
-
public MongoDBStoreAccessor(Store store, ISession session)
{
super(store, session);
@@ -170,8 +157,8 @@ public class MongoDBStoreAccessor extends StoreAccessorBase implements IMongoDBS
try
{
- DBObject query = getStore().getMode().createResourcesQuery(folderID, name, exactMatch, context);
- DBObject keys = new BasicDBObject("_cdoid", 1);
+ DBObject query = createResourcesQuery(folderID, name, exactMatch, context);
+ DBObject keys = new BasicDBObject(Commits.REVISIONS_ID, 1);
cursor = collection.find(query, keys);
while (cursor.hasNext())
{
@@ -197,6 +184,27 @@ public class MongoDBStoreAccessor extends StoreAccessorBase implements IMongoDBS
}
}
+ public DBObject createResourcesQuery(CDOID folderID, String name, boolean exactMatch, QueryResourcesContext context)
+ {
+ DBObject query = new BasicDBObject();
+ query.put("_version", new BasicDBObject("$gt", 0));
+ getStore().getIDHandler().write(query, "_container", folderID);
+ if (name == null)
+ {
+ query.put("name", new BasicDBObject("$exists", false));
+ }
+ else if (exactMatch)
+ {
+ query.put("name", name);
+ }
+ else
+ {
+ query.put("name", new BasicDBObject("$regex", "/^" + name + "/"));
+ }
+
+ return query;
+ }
+
public void queryXRefs(QueryXRefsContext context)
{
throw new UnsupportedOperationException("Not yet implemented"); // TODO Implement me
@@ -254,79 +262,12 @@ public class MongoDBStoreAccessor extends StoreAccessorBase implements IMongoDBS
public void writePackageUnits(InternalCDOPackageUnit[] packageUnits, OMMonitor monitor)
{
- MongoDBStore store = getStore();
- DBCollection packageUnitsCollection = store.getPackageUnitsCollection();
- DBObject[] docs = marshallPackageUnits(packageUnits);
-
- for (DBObject doc : docs)
- {
- packageUnitsCollection.insert(doc);
- }
+ getStore().getCommits().writePackageUnits(this, packageUnits, monitor);
}
public void write(InternalCommitContext context, OMMonitor monitor)
{
- try
- {
- monitor.begin(104);
- CDOBranchPoint branchPoint = context.getBranchPoint();
-
- DBObject doc = new BasicDBObject();
- doc.put("_id", branchPoint.getTimeStamp());
-
- long previous = context.getPreviousTimeStamp();
- if (previous != CDOBranchPoint.UNSPECIFIED_DATE)
- {
- doc.put("previous", previous);
- }
-
- if (getStore().getRepository().isSupportingBranches())
- {
- doc.put("branch", branchPoint.getBranch().getID());
- }
-
- String user = context.getUserID();
- if (user != null)
- {
- doc.put("user", user);
- }
-
- String comment = context.getCommitComment();
- if (comment != null)
- {
- doc.put("comment", comment);
- }
-
- InternalCDOPackageUnit[] newPackageUnits = context.getNewPackageUnits();
- if (!ObjectUtil.isEmpty(newPackageUnits))
- {
- doc.put("packages", marshallPackageUnits(newPackageUnits));
- }
-
- monitor.worked();
- addIDMappings(context, monitor.fork());
- context.applyIDMappings(monitor.fork());
-
- List<DBObject> docs = new ArrayList<DBObject>();
- marshalRevisions(docs, context.getNewObjects());
- marshalRevisions(docs, context.getDirtyObjects());
- if (!docs.isEmpty())
- {
- doc.put("revisions", docs);
- }
-
- monitor.worked();
-
- getStore().getCommitInfosCollection().insert(doc);
- monitor.worked(100);
-
- CDOCommitInfo commitInfo = context.createCommitInfo();
- getStore().getMapper().addWork(commitInfo);
- }
- finally
- {
- monitor.done();
- }
+ getStore().getCommits().write(this, context, monitor);
}
public void commit(OMMonitor monitor)
@@ -344,144 +285,4 @@ public class MongoDBStoreAccessor extends StoreAccessorBase implements IMongoDBS
{
return getStore().getIDHandler().getNextCDOID(revision);
}
-
- private DBObject[] marshallPackageUnits(InternalCDOPackageUnit[] packageUnits)
- {
- DBObject[] result = new DBObject[packageUnits.length];
- InternalCDOPackageRegistry packageRegistry = getStore().getRepository().getPackageRegistry();
-
- for (int i = 0; i < packageUnits.length; i++)
- {
- InternalCDOPackageUnit packageUnit = packageUnits[i];
- EPackage ePackage = packageUnit.getTopLevelPackageInfo().getEPackage();
- byte[] bytes = EMFUtil.getEPackageBytes(ePackage, ZIP_PACKAGE_BYTES, packageRegistry);
-
- DBObject doc = new BasicDBObject();
- doc.put("id", packageUnit.getID());
- doc.put("type", packageUnit.getOriginalType().toString());
- doc.put("time", packageUnit.getTimeStamp());
- doc.put("data", bytes);
-
- result[i] = doc;
- }
-
- return result;
- }
-
- 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++)
- {
- InternalCDORevision revision = revisions[i];
- result[i] = marshallRevision(revision);
- }
-
- return result;
- }
-
- private DBObject marshallRevision(InternalCDORevision revision)
- {
- IDHandler idHandler = getStore().getIDHandler();
-
- DBObject doc = new BasicDBObject();
- idHandler.write(doc, "cdo_id", revision.getID());
- if (getStore().getRepository().isSupportingBranches())
- {
- int branch = revision.getBranch().getID();
- if (branch != 0)
- {
- doc.put("cdo_branch", branch);
- }
- }
-
- doc.put("cdo_version", revision.getVersion());
- doc.put("cdo_created", revision.getTimeStamp());
-
- long revised = revision.getRevised();
- if (revised != CDOBranchPoint.UNSPECIFIED_DATE)
- {
- doc.put("cdo_revised", revised);
- }
-
- doc.put("cdo_class", new CDOClassifierRef(revision.getEClass()).getURI());
-
- CDOID resourceID = revision.getResourceID();
- if (!CDOIDUtil.isNull(resourceID))
- {
- idHandler.write(doc, "cdo_resource", resourceID);
- }
-
- CDOID containerID = (CDOID)revision.getContainerID();
- if (!CDOIDUtil.isNull(containerID))
- {
- idHandler.write(doc, "cdo_container", containerID);
- int featureID = revision.getContainingFeatureID();
- if (featureID != 0)
- {
- doc.put("cdo_feature", featureID);
- }
- }
-
- return doc;
- }
-
- private DBObject[] marshallRevisionDeltas(InternalCDORevisionDelta[] revisionDeltas)
- {
- DBObject[] result = new DBObject[revisionDeltas.length];
- for (int i = 0; i < revisionDeltas.length; i++)
- {
- InternalCDORevisionDelta revisionDelta = revisionDeltas[i];
- result[i] = marshallRevisionDelta(revisionDelta);
- }
-
- return result;
- }
-
- private DBObject marshallRevisionDelta(InternalCDORevisionDelta revisionDelta)
- {
- IDHandler idHandler = getStore().getIDHandler();
-
- DBObject doc = new BasicDBObject();
- idHandler.write(doc, "cdo_id", revisionDelta.getID());
- if (getStore().getRepository().isSupportingBranches())
- {
- doc.put("cdo_branch", revisionDelta.getBranch().getID());
- }
-
- // doc.put("cdo_version", revisionDelta.getVersion());
-
- return doc;
- }
-
- private DBObject[] marshallObjectTypes(Map<CDOID, EClass> objectTypes)
- {
- IDHandler idHandler = getStore().getIDHandler();
- Iterator<Entry<CDOID, EClass>> it = objectTypes.entrySet().iterator();
-
- DBObject[] result = new DBObject[objectTypes.size()];
- for (int i = 0; i < result.length; i++)
- {
- Entry<CDOID, EClass> entry = it.next();
- CDOID id = entry.getKey();
- EClass type = entry.getValue();
-
- DBObject doc = new BasicDBObject();
- idHandler.write(doc, "id", id);
- doc.put("type", new CDOClassifierRef(type).getURI());
-
- result[i] = doc;
- }
-
- return result;
- }
}
diff --git a/plugins/org.eclipse.emf.cdo.server.mongodb/src/org/eclipse/emf/cdo/server/internal/mongodb/Props.java b/plugins/org.eclipse.emf.cdo.server.mongodb/src/org/eclipse/emf/cdo/server/internal/mongodb/Props.java
new file mode 100644
index 0000000000..f654b4c555
--- /dev/null
+++ b/plugins/org.eclipse.emf.cdo.server.mongodb/src/org/eclipse/emf/cdo/server/internal/mongodb/Props.java
@@ -0,0 +1,100 @@
+/**
+ * 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 com.mongodb.BasicDBObject;
+import com.mongodb.DBCursor;
+import com.mongodb.DBObject;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Set;
+
+/**
+ * @author Eike Stepper
+ */
+public class Props extends Coll
+{
+ public static final String NAME = "props";
+
+ public static final String ID = "_id";
+
+ public static final String VALUE = "value";
+
+ public static final String REPOSITORY_CREATED = "org.eclipse.emf.cdo.server.mongodb.repositoryCreated"; //$NON-NLS-1$
+
+ public static final String REPOSITORY_STOPPED = "org.eclipse.emf.cdo.server.mongodb.repositoryStopped"; //$NON-NLS-1$
+
+ public static final String NEXT_LOCAL_CDOID = "org.eclipse.emf.cdo.server.mongodb.nextLocalCDOID"; //$NON-NLS-1$
+
+ public static final String LAST_CDOID = "org.eclipse.emf.cdo.server.mongodb.lastCDOID"; //$NON-NLS-1$
+
+ public static final String LAST_CLASSIFIERID = "org.eclipse.emf.cdo.server.mongodb.lastClassiferID"; //$NON-NLS-1$
+
+ public static final String LAST_BRANCHID = "org.eclipse.emf.cdo.server.mongodb.lastBranchID"; //$NON-NLS-1$
+
+ public static final String LAST_LOCAL_BRANCHID = "org.eclipse.emf.cdo.server.mongodb.lastLocalBranchID"; //$NON-NLS-1$
+
+ public static final String LAST_COMMITTIME = "org.eclipse.emf.cdo.server.mongodb.lastCommitTime"; //$NON-NLS-1$
+
+ public static final String LAST_NONLOCAL_COMMITTIME = "org.eclipse.emf.cdo.server.mongodb.lastNonLocalCommitTime"; //$NON-NLS-1$
+
+ public static final String GRACEFULLY_SHUT_DOWN = "org.eclipse.emf.cdo.server.mongodb.gracefullyShutDown"; //$NON-NLS-1$
+
+ public Props(MongoDBStore store)
+ {
+ super(store, NAME);
+ }
+
+ public Map<String, String> get(Set<String> names)
+ {
+ Map<String, String> result = new HashMap<String, String>();
+ for (String name : names)
+ {
+ DBObject query = new BasicDBObject(ID, name);
+ DBCursor cursor = collection.find(query);
+
+ try
+ {
+ if (cursor.hasNext())
+ {
+ DBObject doc = cursor.next();
+ result.put(name, (String)doc.get(VALUE));
+ }
+ }
+ finally
+ {
+ cursor.close();
+ }
+ }
+
+ return result;
+ }
+
+ public void set(Map<String, String> properties)
+ {
+ for (Entry<String, String> property : properties.entrySet())
+ {
+ DBObject doc = new BasicDBObject();
+ doc.put(ID, property.getKey());
+ doc.put(VALUE, property.getValue());
+
+ collection.insert(doc);
+
+ }
+ }
+
+ public void remove(Set<String> names)
+ {
+ throw new UnsupportedOperationException("Not yet implemented"); // TODO Implement me
+ }
+}

Back to the top