Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEike Stepper2012-07-19 08:22:04 +0000
committerEike Stepper2012-07-19 08:22:04 +0000
commit1460904fd3c193ffaf809913b2983a400fce9d94 (patch)
tree72f3a17b75fedba3ae1060df1d32c9c7889be954 /plugins/org.eclipse.emf.cdo.server.mongodb
parent5f360965ae87478e0681899bf310a210cafc2c44 (diff)
downloadcdo-1460904fd3c193ffaf809913b2983a400fce9d94.tar.gz
cdo-1460904fd3c193ffaf809913b2983a400fce9d94.tar.xz
cdo-1460904fd3c193ffaf809913b2983a400fce9d94.zip
Fix line endings in master (dos2unix)
Diffstat (limited to 'plugins/org.eclipse.emf.cdo.server.mongodb')
-rw-r--r--plugins/org.eclipse.emf.cdo.server.mongodb/.settings/org.eclipse.core.resources.prefs6
-rw-r--r--plugins/org.eclipse.emf.cdo.server.mongodb/.settings/org.eclipse.jdt.launching.prefs6
-rw-r--r--plugins/org.eclipse.emf.cdo.server.mongodb/copyright.txt14
-rw-r--r--plugins/org.eclipse.emf.cdo.server.mongodb/plugin.xml66
-rw-r--r--plugins/org.eclipse.emf.cdo.server.mongodb/src/org/eclipse/emf/cdo/server/internal/mongodb/Classes.java268
-rw-r--r--plugins/org.eclipse.emf.cdo.server.mongodb/src/org/eclipse/emf/cdo/server/internal/mongodb/Coll.java228
-rw-r--r--plugins/org.eclipse.emf.cdo.server.mongodb/src/org/eclipse/emf/cdo/server/internal/mongodb/Commits.java1960
-rw-r--r--plugins/org.eclipse.emf.cdo.server.mongodb/src/org/eclipse/emf/cdo/server/internal/mongodb/IDHandler.java366
-rw-r--r--plugins/org.eclipse.emf.cdo.server.mongodb/src/org/eclipse/emf/cdo/server/internal/mongodb/MongoDBBrowserPage.java538
-rw-r--r--plugins/org.eclipse.emf.cdo.server.mongodb/src/org/eclipse/emf/cdo/server/internal/mongodb/MongoDBStore.java1180
-rw-r--r--plugins/org.eclipse.emf.cdo.server.mongodb/src/org/eclipse/emf/cdo/server/internal/mongodb/MongoDBStoreAccessor.java392
-rw-r--r--plugins/org.eclipse.emf.cdo.server.mongodb/src/org/eclipse/emf/cdo/server/internal/mongodb/MongoDBStoreFactory.java180
-rw-r--r--plugins/org.eclipse.emf.cdo.server.mongodb/src/org/eclipse/emf/cdo/server/internal/mongodb/Props.java220
-rw-r--r--plugins/org.eclipse.emf.cdo.server.mongodb/src/org/eclipse/emf/cdo/server/internal/mongodb/bundle/OM.java90
-rw-r--r--plugins/org.eclipse.emf.cdo.server.mongodb/src/org/eclipse/emf/cdo/server/mongodb/package-info.java30
15 files changed, 2772 insertions, 2772 deletions
diff --git a/plugins/org.eclipse.emf.cdo.server.mongodb/.settings/org.eclipse.core.resources.prefs b/plugins/org.eclipse.emf.cdo.server.mongodb/.settings/org.eclipse.core.resources.prefs
index d22541e2af..6ad01f1b16 100644
--- a/plugins/org.eclipse.emf.cdo.server.mongodb/.settings/org.eclipse.core.resources.prefs
+++ b/plugins/org.eclipse.emf.cdo.server.mongodb/.settings/org.eclipse.core.resources.prefs
@@ -1,3 +1,3 @@
-#Mon Jul 04 12:58:44 CEST 2011
-eclipse.preferences.version=1
-encoding//model/org.eclipse.emf.cdo.defs.ecorediag=UTF-8
+#Mon Jul 04 12:58:44 CEST 2011
+eclipse.preferences.version=1
+encoding//model/org.eclipse.emf.cdo.defs.ecorediag=UTF-8
diff --git a/plugins/org.eclipse.emf.cdo.server.mongodb/.settings/org.eclipse.jdt.launching.prefs b/plugins/org.eclipse.emf.cdo.server.mongodb/.settings/org.eclipse.jdt.launching.prefs
index 4658ec1435..556ed07a3c 100644
--- a/plugins/org.eclipse.emf.cdo.server.mongodb/.settings/org.eclipse.jdt.launching.prefs
+++ b/plugins/org.eclipse.emf.cdo.server.mongodb/.settings/org.eclipse.jdt.launching.prefs
@@ -1,3 +1,3 @@
-#Fri Sep 02 05:38:34 CEST 2011
-eclipse.preferences.version=1
-org.eclipse.jdt.launching.PREF_STRICTLY_COMPATIBLE_JRE_NOT_AVAILABLE=ignore
+#Fri Sep 02 05:38:34 CEST 2011
+eclipse.preferences.version=1
+org.eclipse.jdt.launching.PREF_STRICTLY_COMPATIBLE_JRE_NOT_AVAILABLE=ignore
diff --git a/plugins/org.eclipse.emf.cdo.server.mongodb/copyright.txt b/plugins/org.eclipse.emf.cdo.server.mongodb/copyright.txt
index 8f6328980e..0a0f67e6d7 100644
--- a/plugins/org.eclipse.emf.cdo.server.mongodb/copyright.txt
+++ b/plugins/org.eclipse.emf.cdo.server.mongodb/copyright.txt
@@ -1,8 +1,8 @@
-Copyright (c) 2004 - 2012 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:
+Copyright (c) 2004 - 2012 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 \ No newline at end of file
diff --git a/plugins/org.eclipse.emf.cdo.server.mongodb/plugin.xml b/plugins/org.eclipse.emf.cdo.server.mongodb/plugin.xml
index 8902746e0a..726db4e245 100644
--- a/plugins/org.eclipse.emf.cdo.server.mongodb/plugin.xml
+++ b/plugins/org.eclipse.emf.cdo.server.mongodb/plugin.xml
@@ -1,33 +1,33 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<?eclipse version="3.4"?>
-<!--
- Copyright (c) 2004 - 2012 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
--->
-
-<plugin>
-
- <extension
- point="org.eclipse.net4j.util.factories">
- <factory
- class="org.eclipse.emf.cdo.server.internal.mongodb.MongoDBBrowserPage$Factory"
- productGroup="org.eclipse.emf.cdo.server.browserPages"
- type="mongodb">
- </factory>
- </extension>
-
- <extension
- point="org.eclipse.emf.cdo.server.storeFactories">
- <storeFactory
- class="org.eclipse.emf.cdo.server.internal.mongodb.MongoDBStoreFactory"
- storeType="mongodb">
- </storeFactory>
- </extension>
-
-</plugin>
+<?xml version="1.0" encoding="UTF-8"?>
+<?eclipse version="3.4"?>
+<!--
+ Copyright (c) 2004 - 2012 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
+-->
+
+<plugin>
+
+ <extension
+ point="org.eclipse.net4j.util.factories">
+ <factory
+ class="org.eclipse.emf.cdo.server.internal.mongodb.MongoDBBrowserPage$Factory"
+ productGroup="org.eclipse.emf.cdo.server.browserPages"
+ type="mongodb">
+ </factory>
+ </extension>
+
+ <extension
+ point="org.eclipse.emf.cdo.server.storeFactories">
+ <storeFactory
+ class="org.eclipse.emf.cdo.server.internal.mongodb.MongoDBStoreFactory"
+ storeType="mongodb">
+ </storeFactory>
+ </extension>
+
+</plugin>
diff --git a/plugins/org.eclipse.emf.cdo.server.mongodb/src/org/eclipse/emf/cdo/server/internal/mongodb/Classes.java b/plugins/org.eclipse.emf.cdo.server.mongodb/src/org/eclipse/emf/cdo/server/internal/mongodb/Classes.java
index e858ae76aa..64c43c5382 100644
--- a/plugins/org.eclipse.emf.cdo.server.mongodb/src/org/eclipse/emf/cdo/server/internal/mongodb/Classes.java
+++ b/plugins/org.eclipse.emf.cdo.server.mongodb/src/org/eclipse/emf/cdo/server/internal/mongodb/Classes.java
@@ -1,134 +1,134 @@
-/*
- * Copyright (c) 2004 - 2012 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.eresource.EresourcePackage;
-
-import org.eclipse.emf.ecore.EClass;
-import org.eclipse.emf.ecore.EClassifier;
-
-import java.util.HashMap;
-import java.util.Map;
-
-/**
- * @author Eike Stepper
- */
-public class Classes
-{
- public static final String PROPERTIES = "props";
-
- private Map<EClassifier, Integer> classifierToIDs = new HashMap<EClassifier, Integer>();
-
- private Map<Integer, EClassifier> idToClassifiers = new HashMap<Integer, EClassifier>();
-
- private MongoDBStore store;
-
- private boolean initialized;
-
- private int lastClassifierID;
-
- private int resourceNodeClassID;
-
- private int resourceFolderClassID;
-
- private int resourceClassID;
-
- public Classes(MongoDBStore store)
- {
- this.store = store;
- }
-
- public MongoDBStore getStore()
- {
- return store;
- }
-
- public int getLastClassifierID()
- {
- return lastClassifierID;
- }
-
- public void setLastClassifierID(int lastClassifierID)
- {
- this.lastClassifierID = lastClassifierID;
- }
-
- public synchronized int getResourceNodeClassID()
- {
- initialize();
- return resourceNodeClassID;
- }
-
- public synchronized int getResourceFolderClassID()
- {
- initialize();
- return resourceFolderClassID;
- }
-
- public synchronized int getResourceClassID()
- {
- initialize();
- return resourceClassID;
- }
-
- public synchronized int mapNewClassifier(EClassifier classifier)
- {
- int id = ++lastClassifierID;
- mapClassifier(classifier, id);
- return id;
- }
-
- public synchronized void mapClassifier(EClassifier classifier, int id)
- {
- classifierToIDs.put(classifier, id);
- idToClassifiers.put(id, classifier);
-
- if (classifier == EresourcePackage.eINSTANCE.getCDOResourceNode())
- {
- resourceNodeClassID = id;
- }
- else if (classifier == EresourcePackage.eINSTANCE.getCDOResourceFolder())
- {
- resourceFolderClassID = id;
- }
- else if (classifier == EresourcePackage.eINSTANCE.getCDOResource())
- {
- resourceClassID = id;
- }
- }
-
- public synchronized int getClassifierID(EClassifier classifier)
- {
- initialize();
- return classifierToIDs.get(classifier);
- }
-
- public synchronized EClassifier getClassifier(int id)
- {
- initialize();
- return idToClassifiers.get(id);
- }
-
- public synchronized EClass getClass(int id)
- {
- return (EClass)getClassifier(id);
- }
-
- private void initialize()
- {
- if (!initialized)
- {
- Commits commits = store.getCommits();
- commits.initializeClassifiers();
- initialized = true;
- }
- }
-}
+/*
+ * Copyright (c) 2004 - 2012 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.eresource.EresourcePackage;
+
+import org.eclipse.emf.ecore.EClass;
+import org.eclipse.emf.ecore.EClassifier;
+
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * @author Eike Stepper
+ */
+public class Classes
+{
+ public static final String PROPERTIES = "props";
+
+ private Map<EClassifier, Integer> classifierToIDs = new HashMap<EClassifier, Integer>();
+
+ private Map<Integer, EClassifier> idToClassifiers = new HashMap<Integer, EClassifier>();
+
+ private MongoDBStore store;
+
+ private boolean initialized;
+
+ private int lastClassifierID;
+
+ private int resourceNodeClassID;
+
+ private int resourceFolderClassID;
+
+ private int resourceClassID;
+
+ public Classes(MongoDBStore store)
+ {
+ this.store = store;
+ }
+
+ public MongoDBStore getStore()
+ {
+ return store;
+ }
+
+ public int getLastClassifierID()
+ {
+ return lastClassifierID;
+ }
+
+ public void setLastClassifierID(int lastClassifierID)
+ {
+ this.lastClassifierID = lastClassifierID;
+ }
+
+ public synchronized int getResourceNodeClassID()
+ {
+ initialize();
+ return resourceNodeClassID;
+ }
+
+ public synchronized int getResourceFolderClassID()
+ {
+ initialize();
+ return resourceFolderClassID;
+ }
+
+ public synchronized int getResourceClassID()
+ {
+ initialize();
+ return resourceClassID;
+ }
+
+ public synchronized int mapNewClassifier(EClassifier classifier)
+ {
+ int id = ++lastClassifierID;
+ mapClassifier(classifier, id);
+ return id;
+ }
+
+ public synchronized void mapClassifier(EClassifier classifier, int id)
+ {
+ classifierToIDs.put(classifier, id);
+ idToClassifiers.put(id, classifier);
+
+ if (classifier == EresourcePackage.eINSTANCE.getCDOResourceNode())
+ {
+ resourceNodeClassID = id;
+ }
+ else if (classifier == EresourcePackage.eINSTANCE.getCDOResourceFolder())
+ {
+ resourceFolderClassID = id;
+ }
+ else if (classifier == EresourcePackage.eINSTANCE.getCDOResource())
+ {
+ resourceClassID = id;
+ }
+ }
+
+ public synchronized int getClassifierID(EClassifier classifier)
+ {
+ initialize();
+ return classifierToIDs.get(classifier);
+ }
+
+ public synchronized EClassifier getClassifier(int id)
+ {
+ initialize();
+ return idToClassifiers.get(id);
+ }
+
+ public synchronized EClass getClass(int id)
+ {
+ return (EClass)getClassifier(id);
+ }
+
+ private void initialize()
+ {
+ if (!initialized)
+ {
+ Commits commits = store.getCommits();
+ commits.initializeClassifiers();
+ initialized = true;
+ }
+ }
+}
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 abd92fcc3f..79fd5f8446 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
@@ -1,114 +1,114 @@
-/*
- * Copyright (c) 2004 - 2012 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.DBCursor;
-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);
- }
-
- /**
- * @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);
- }
-}
+/*
+ * Copyright (c) 2004 - 2012 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.DBCursor;
+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);
+ }
+
+ /**
+ * @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 130969dc36..ed28641cb9 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
@@ -1,980 +1,980 @@
-/*
- * Copyright (c) 2004 - 2012 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.CDOBranch;
-import org.eclipse.emf.cdo.common.branch.CDOBranchPoint;
-import org.eclipse.emf.cdo.common.branch.CDOBranchVersion;
-import org.eclipse.emf.cdo.common.commit.CDOChangeKind;
-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.model.CDOClassInfo;
-import org.eclipse.emf.cdo.common.model.CDOClassifierRef;
-import org.eclipse.emf.cdo.common.model.CDOModelConstants;
-import org.eclipse.emf.cdo.common.model.CDOModelUtil;
-import org.eclipse.emf.cdo.common.model.CDOPackageUnit;
-import org.eclipse.emf.cdo.common.model.CDOType;
-import org.eclipse.emf.cdo.common.model.EMFUtil;
-import org.eclipse.emf.cdo.common.revision.CDOList;
-import org.eclipse.emf.cdo.common.revision.CDORevisionCacheAdder;
-import org.eclipse.emf.cdo.common.revision.CDORevisionData;
-import org.eclipse.emf.cdo.common.util.CDOCommonUtil;
-import org.eclipse.emf.cdo.server.IStoreAccessor;
-import org.eclipse.emf.cdo.server.IStoreAccessor.QueryResourcesContext;
-import org.eclipse.emf.cdo.server.StoreThreadLocal;
-import org.eclipse.emf.cdo.server.internal.mongodb.MongoDBStore.ValueHandler;
-import org.eclipse.emf.cdo.spi.common.branch.InternalCDOBranchManager;
-import org.eclipse.emf.cdo.spi.common.commit.InternalCDOCommitInfoManager;
-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.DetachedCDORevision;
-import org.eclipse.emf.cdo.spi.common.revision.InternalCDORevision;
-import org.eclipse.emf.cdo.spi.common.revision.SyntheticCDORevision;
-import org.eclipse.emf.cdo.spi.server.InternalCommitContext;
-import org.eclipse.emf.cdo.spi.server.InternalRepository;
-
-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.EClass;
-import org.eclipse.emf.ecore.EClassifier;
-import org.eclipse.emf.ecore.EPackage;
-import org.eclipse.emf.ecore.EStructuralFeature;
-import org.eclipse.emf.ecore.InternalEObject.EStore;
-import org.eclipse.emf.ecore.resource.ResourceSet;
-
-import com.mongodb.BasicDBList;
-import com.mongodb.BasicDBObject;
-import com.mongodb.DBObject;
-import com.mongodb.QueryOperators;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.List;
-import java.util.Set;
-import java.util.regex.Pattern;
-
-/**
- * @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_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 SET_SUFFIX = "___set";
-
- public static final String REVISIONS = "revisions";
-
- public static final String REVISIONS_ID = "cdo_id";
-
- public static final String REVISIONS_VERSION = "cdo_version";
-
- private static final String REVISIONS_REVISED = "cdo_revised";
-
- 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 InternalCDOPackageRegistry packageRegistry;
-
- private IDHandler idHandler;
-
- private InternalCDOPackageUnit[] systemPackageUnits;
-
- private EStructuralFeature resourceNameFeature;
-
- public Commits(MongoDBStore store)
- {
- super(store, COMMITS);
- ensureIndex(UNITS, UNITS_ID);
-
- if (store.isBranching())
- {
- DBObject index = new BasicDBObject();
- index.put(REVISIONS + "." + REVISIONS_ID, 1);
- index.put(COMMITS_BRANCH, 1);
- index.put(REVISIONS + "." + REVISIONS_VERSION, 1);
-
- collection.ensureIndex(index);
- }
- else
- {
- ensureIndex(REVISIONS, REVISIONS_ID, REVISIONS_VERSION);
- }
-
- packageRegistry = store.getRepository().getPackageRegistry();
- idHandler = store.getIDHandler();
- }
-
- public void writePackageUnits(MongoDBStoreAccessor mongoDBStoreAccessor, InternalCDOPackageUnit[] packageUnits,
- OMMonitor monitor)
- {
- // This must be the first commit into the repo.
- systemPackageUnits = packageUnits;
-
- for (int i = 0; i < packageUnits.length; i++)
- {
- InternalCDOPackageUnit packageUnit = packageUnits[i];
- InternalCDOPackageInfo[] packageInfos = packageUnit.getPackageInfos();
- for (int j = 0; j < packageInfos.length; j++)
- {
- InternalCDOPackageInfo packageInfo = packageInfos[j];
- for (EClassifier classifier : packageInfo.getEPackage().getEClassifiers())
- {
- store.getClasses().mapNewClassifier(classifier);
- }
- }
- }
- }
-
- private DBObject[] marshallUnits(InternalCDOPackageUnit[] packageUnits)
- {
- DBObject[] result = new DBObject[packageUnits.length];
- InternalCDOPackageRegistry packageRegistry = store.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_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 = store.getClasses().mapNewClassifier(classifier);
- doc.put(CLASSIFIER_PREFIX + classifierID, classifier.getName());
- }
-
- result[i] = doc;
- }
-
- return result;
- }
-
- public Collection<InternalCDOPackageUnit> readPackageUnits()
- {
- final Collection<InternalCDOPackageUnit> packageUnits = new ArrayList<InternalCDOPackageUnit>();
-
- DBObject query = new BasicDBObject();
- query.put(UNITS, new BasicDBObject("$exists", true));
-
- new QueryEmbeddedUnits<Object>(query)
- {
- @Override
- protected Object handleEmbedded(DBObject doc, DBObject embedded)
- {
- long time = (Long)doc.get(COMMITS_ID);
- CDOPackageUnit.Type type = CDOPackageUnit.Type.valueOf((String)embedded.get(UNITS_TYPE));
- InternalCDOPackageInfo[] infos = readPackageInfos(embedded);
-
- InternalCDOPackageUnit packageUnit = createPackageUnit();
- packageUnit.setOriginalType(type);
- packageUnit.setTimeStamp(time);
- packageUnit.setPackageInfos(infos);
-
- packageUnits.add(packageUnit);
- return null;
- }
-
- private InternalCDOPackageInfo[] readPackageInfos(DBObject embedded)
- {
- BasicDBList infos = (BasicDBList)embedded.get(PACKAGES);
- InternalCDOPackageInfo[] result = new InternalCDOPackageInfo[infos.size()];
- int i = 0;
-
- for (Object info : infos)
- {
- DBObject infoObject = (DBObject)info;
- String uri = (String)infoObject.get(PACKAGES_URI);
- String parent = (String)infoObject.get(PACKAGES_PARENT);
-
- InternalCDOPackageInfo packageInfo = createPackageInfo();
- packageInfo.setPackageURI(uri);
- packageInfo.setParentURI(parent);
-
- result[i++] = packageInfo;
- }
-
- return result;
- }
-
- private InternalCDOPackageUnit createPackageUnit()
- {
- return (InternalCDOPackageUnit)CDOModelUtil.createPackageUnit();
- }
-
- private InternalCDOPackageInfo createPackageInfo()
- {
- return (InternalCDOPackageInfo)CDOModelUtil.createPackageInfo();
- }
- }.execute();
-
- return packageUnits;
- }
-
- public EPackage[] loadPackageUnit(final InternalCDOPackageUnit packageUnit)
- {
- DBObject query = new BasicDBObject();
- query.put(UNITS + "." + UNITS_ID, packageUnit.getID());
-
- return new QueryEmbeddedUnits<EPackage[]>(query)
- {
- @Override
- protected EPackage[] handleEmbedded(DBObject doc, DBObject embedded)
- {
- byte[] data = (byte[])embedded.get(UNITS_DATA);
- EPackage ePackage = createEPackage(packageUnit, data);
- return EMFUtil.getAllPackages(ePackage);
- }
-
- private EPackage createEPackage(InternalCDOPackageUnit packageUnit, byte[] bytes)
- {
- ResourceSet resourceSet = EMFUtil.newEcoreResourceSet(packageRegistry);
- return EMFUtil.createEPackage(packageUnit.getID(), bytes, ZIP_PACKAGE_BYTES, resourceSet, false);
- }
- }.execute();
- }
-
- public void initializeClassifiers()
- {
- final Classes classes = store.getClasses();
-
- DBObject query = new BasicDBObject();
- query.put(UNITS, new BasicDBObject("$exists", true));
-
- new QueryEmbeddedUnits<Object>(query)
- {
- @Override
- protected Object handleEmbedded(DBObject doc, DBObject embedded)
- {
- BasicDBList infos = (BasicDBList)embedded.get(PACKAGES);
- for (Object info : infos)
- {
- DBObject infoObject = (DBObject)info;
- String uri = (String)infoObject.get(PACKAGES_URI);
- handleClassifiers(infoObject, uri);
- }
-
- return null;
- }
-
- private void handleClassifiers(DBObject embedded, String packageURI)
- {
- Set<String> keys = embedded.keySet();
- for (String key : keys)
- {
- if (key.startsWith(CLASSIFIER_PREFIX))
- {
- int id = Integer.parseInt(key.substring(CLASSIFIER_PREFIX.length()));
- String classifierName = (String)embedded.get(key);
-
- CDOClassifierRef classifierRef = new CDOClassifierRef(packageURI, classifierName);
- EClassifier classifier = classifierRef.resolve(packageRegistry);
-
- classes.mapClassifier(classifier, id);
- }
- }
- }
- }.execute();
- }
-
- 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 (store.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, context.getNewObjects(), CDOChangeKind.NEW);
- marshalRevisions(docs, context, context.getDirtyObjects(), CDOChangeKind.CHANGED);
- marshalRevisions(docs, context, context.getDetachedRevisions(), CDOChangeKind.DETACHED);
-
- if (!docs.isEmpty())
- {
- doc.put(REVISIONS, docs);
- }
-
- monitor.worked();
-
- collection.insert(doc);
- monitor.worked(100);
- }
- finally
- {
- monitor.done();
- }
- }
-
- private void marshalRevisions(List<DBObject> docs, InternalCommitContext context, InternalCDORevision[] revisions,
- CDOChangeKind changeKind)
- {
- for (InternalCDORevision revision : revisions)
- {
- DBObject doc = marshallRevision(context, revision, changeKind);
- docs.add(doc);
- }
- }
-
- private DBObject marshallRevision(InternalCommitContext context, InternalCDORevision revision,
- CDOChangeKind changeKind)
- {
- boolean resource = !(revision instanceof SyntheticCDORevision) && revision.isResource();
- if (resource && resourceNameFeature == null)
- {
- resourceNameFeature = revision.getEClass().getEStructuralFeature(CDOModelConstants.RESOURCE_NODE_NAME_ATTRIBUTE);
- }
-
- DBObject doc = new BasicDBObject();
- idHandler.write(doc, REVISIONS_ID, revision.getID());
-
- EClass eClass = revision.getEClass();
- doc.put(REVISIONS_CLASS, store.getClasses().getClassifierID(eClass));
-
- if (changeKind == CDOChangeKind.DETACHED)
- {
- doc.put(REVISIONS_VERSION, -revision.getVersion() - 1);
- return doc;
- }
-
- doc.put(REVISIONS_VERSION, revision.getVersion());
-
- CDOID resourceID = revision.getResourceID();
- idHandler.write(doc, REVISIONS_RESOURCE, resourceID);
-
- CDOID containerID = (CDOID)revision.getContainerID();
- idHandler.write(doc, REVISIONS_CONTAINER, containerID);
-
- int featureID = revision.getContainingFeatureID();
- doc.put(REVISIONS_FEATURE, featureID);
-
- if (resource && changeKind != CDOChangeKind.DETACHED)
- {
- String name = (String)revision.data().get(resourceNameFeature, 0);
- IStoreAccessor accessor = StoreThreadLocal.getAccessor();
-
- CDOID existingID = accessor.readResourceID(containerID, name, revision);
- if (existingID != null && !existingID.equals(revision.getID()) && !isBeingDetached(context, existingID))
- {
- throw new IllegalStateException("Duplicate resource: name=" + name + ", folderID=" + containerID); //$NON-NLS-1$ //$NON-NLS-2$
- }
- }
-
- CDOClassInfo classInfo = revision.getClassInfo();
- for (EStructuralFeature feature : classInfo.getAllPersistentFeatures())
- {
- Object value = revision.getValue(feature);
-
- CDOType type = CDOModelUtil.getType(feature);
- ValueHandler valueHandler = store.getValueHandler(type);
-
- if (feature.isUnsettable())
- {
- if (value == null)
- {
- doc.put(feature.getName() + SET_SUFFIX, false);
- doc.put(feature.getName(), valueHandler.getMongoDefaultValue(feature));
- continue;
- }
-
- doc.put(feature.getName() + SET_SUFFIX, true);
- }
-
- if (value == CDORevisionData.NIL)
- {
- doc.put(feature.getName(), null);
- }
- else if (value == null)
- {
- if (feature.isMany() || feature.getDefaultValue() == null)
- {
- doc.put(feature.getName(), null);
- }
- else
- {
- doc.put(feature.getName(), valueHandler.getMongoDefaultValue(feature));
- }
- }
- else
- {
- if (feature.isMany())
- {
- List<?> cdoList = (List<?>)value;
- BasicDBList mongoList = new BasicDBList();
- for (Object element : cdoList)
- {
- element = valueHandler.toMongo(element);
- mongoList.add(element);
- }
-
- value = mongoList;
- }
- else
- {
- value = valueHandler.toMongo(value);
- }
-
- doc.put(feature.getName(), value);
- }
- }
-
- return doc;
- }
-
- private boolean isBeingDetached(InternalCommitContext context, CDOID id)
- {
- for (CDOID idBeingDetached : context.getDetachedObjects())
- {
- if (id.equals(idBeingDetached))
- {
- return true;
- }
- }
-
- return false;
- }
-
- public void queryResources(final QueryResourcesContext context)
- {
- Classes classes = getStore().getClasses();
- final int folderCID = classes.getResourceFolderClassID();
- final int resourceCID = classes.getResourceClassID();
-
- final CDOID folderID = context.getFolderID();
- final String name = context.getName();
- final boolean exactMatch = context.exactMatch();
- final long timeStamp = context.getTimeStamp();
-
- DBObject query = new BasicDBObject();
-
- query.put(REVISIONS + "." + REVISIONS_CLASS, new BasicDBObject("$in", new int[] { folderCID, resourceCID }));
-
- addToQuery(query, context);
- query.put(REVISIONS + "." + REVISIONS_CONTAINER, idHandler.toValue(folderID));
-
- if (name == null || exactMatch)
- {
- query.put(REVISIONS + "." + "name", name);
- }
- else
- {
- query.put(REVISIONS + "." + "name", Pattern.compile("^" + name));
- }
-
- new QueryEmbeddedRevisions<Boolean>(query)
- {
- @Override
- protected Boolean handleEmbedded(DBObject doc, DBObject embedded)
- {
- int classID = (Integer)embedded.get(REVISIONS_CLASS);
- if (classID != folderCID && classID != resourceCID)
- {
- return null;
- }
-
- int version = (Integer)embedded.get(REVISIONS_VERSION);
- if (version <= 0)
- {
- return null;
- }
-
- CDOID container = idHandler.read(embedded, REVISIONS_CONTAINER);
- if (!ObjectUtil.equals(container, folderID))
- {
- return null;
- }
-
- String revisionName = (String)embedded.get("name");
- if (name == null || exactMatch)
- {
- if (!ObjectUtil.equals(revisionName, name))
- {
- return null;
- }
- }
- else
- {
- if (!revisionName.startsWith(name))
- {
- return null;
- }
- }
-
- CDOID id = idHandler.read(embedded, REVISIONS_ID);
-
- long created = (Long)doc.get(COMMITS_ID);
- long revised = getRevised(id, context.getBranch(), version, doc, embedded);
- if (!CDOCommonUtil.isValidTimeStamp(timeStamp, created, revised))
- {
- return null;
- }
-
- if (!context.addResource(id))
- {
- // No more results allowed
- return true;
- }
-
- return null;
- }
- }.execute();
- }
-
- private long getRevised(CDOID id, CDOBranch branch, int version, DBObject doc, DBObject revision)
- {
- Object value = revision.get(REVISIONS_REVISED);
- if (value instanceof Long)
- {
- return (Long)value;
- }
-
- DBObject query = new BasicDBObject();
- idHandler.write(query, REVISIONS + "." + REVISIONS_ID, id);
- if (store.isBranching())
- {
- query.put(COMMITS_BRANCH, branch.getID());
- }
-
- int nextVersion = version + 1;
- query.put(REVISIONS + "." + REVISIONS_VERSION, new BasicDBObject("$in", new int[] { nextVersion, -nextVersion }));
-
- Long result = new Query<Long>(query)
- {
- @Override
- protected Long handleDoc(DBObject doc)
- {
- return (Long)doc.get(COMMITS_ID);
- }
- }.execute();
-
- if (result != null)
- {
- long revised = result - 1;
-
- // try
- // {
- // revision.put(REVISIONS_REVISED, revised);
- // collection.save(doc);
- // }
- // catch (Exception ex)
- // {
- // OM.LOG.warn(ex);
- // }
-
- return revised;
- }
-
- return CDOBranchPoint.UNSPECIFIED_DATE;
- }
-
- public InternalCDORevision readRevision(final CDOID id, final CDOBranchPoint branchPoint, int listChunk,
- CDORevisionCacheAdder cache)
- {
- final CDOBranch branch = branchPoint.getBranch();
- final long timeStamp = branchPoint.getTimeStamp();
-
- DBObject query = new BasicDBObject();
- idHandler.write(query, REVISIONS + "." + REVISIONS_ID, id);
-
- addToQuery(query, branchPoint);
-
- return new QueryEmbeddedRevisions<InternalCDORevision>(query)
- {
- @Override
- public InternalCDORevision execute()
- {
- return execute(collection.find(getRef()).sort(new BasicDBObject(COMMITS_ID, -1)).limit(1));
- }
-
- @Override
- protected InternalCDORevision handleEmbedded(DBObject doc, DBObject embedded)
- {
- CDOID embeddedID = idHandler.read(embedded, REVISIONS_ID);
- if (!ObjectUtil.equals(embeddedID, id))
- {
- return null;
- }
-
- long created = (Long)doc.get(COMMITS_ID);
- CDOBranchPoint revisionBranchPoint = branch.getPoint(created);
-
- InternalCDORevision revision = unmarshallRevision(doc, embedded, id, revisionBranchPoint);
-
- long revised = revision.getRevised();
- if (!CDOCommonUtil.isValidTimeStamp(timeStamp, created, revised))
- {
- return null;
- }
-
- return revision;
- }
- }.execute();
- }
-
- private void addToQuery(DBObject query, CDOBranchPoint branchPoint)
- {
- // Exclude detached objects
- query.put(REVISIONS + "." + REVISIONS_VERSION, new BasicDBObject("$gte", CDOBranchVersion.FIRST_VERSION));
-
- long timeStamp = branchPoint.getTimeStamp();
- if (timeStamp != CDOBranchPoint.UNSPECIFIED_DATE)
- {
- query.put(COMMITS_ID, new BasicDBObject("$lte", timeStamp));
- }
-
- if (store.isBranching())
- {
- int branch = branchPoint.getBranch().getID();
- query.put(COMMITS_BRANCH, branch);
- }
- }
-
- public InternalCDORevision readRevisionByVersion(final CDOID id, CDOBranchVersion branchVersion, int listChunk,
- CDORevisionCacheAdder cache)
- {
- DBObject query = new BasicDBObject();
- idHandler.write(query, REVISIONS + "." + REVISIONS_ID, id);
-
- int version = branchVersion.getVersion();
- query.put(REVISIONS + "." + REVISIONS_VERSION, new BasicDBObject("$in", new int[] { version, -version }));
-
- final CDOBranch branch = branchVersion.getBranch();
- if (store.isBranching())
- {
- query.put(COMMITS_BRANCH, branch.getID());
- }
-
- return new QueryEmbeddedRevisions<InternalCDORevision>(query)
- {
- @Override
- protected InternalCDORevision handleEmbedded(DBObject doc, DBObject embedded)
- {
- CDOID revisionID = idHandler.read(embedded, REVISIONS_ID);
- if (!ObjectUtil.equals(revisionID, id))
- {
- return null;
- }
-
- long revisionTime = (Long)doc.get(COMMITS_ID);
- CDOBranchPoint branchPoint = branch.getPoint(revisionTime);
-
- return unmarshallRevision(doc, embedded, id, branchPoint);
- }
- }.execute();
- }
-
- private InternalCDORevision unmarshallRevision(DBObject doc, DBObject embedded, CDOID id, CDOBranchPoint branchPoint)
- {
- int classID = (Integer)embedded.get(REVISIONS_CLASS);
- EClass eClass = store.getClasses().getClass(classID);
-
- CDOBranch branch = branchPoint.getBranch();
- int version = (Integer)embedded.get(REVISIONS_VERSION);
- long revised = getRevised(id, branch, Math.abs(version), doc, embedded);
-
- if (version < CDOBranchVersion.FIRST_VERSION)
- {
- long timeStamp = branchPoint.getTimeStamp();
- return new DetachedCDORevision(eClass, id, branch, -version, timeStamp, revised);
- }
-
- CDOID resourceID = idHandler.read(embedded, REVISIONS_RESOURCE);
- CDOID containerID = idHandler.read(embedded, REVISIONS_CONTAINER);
- int featureID = (Integer)embedded.get(REVISIONS_FEATURE);
-
- InternalCDORevision result = store.createRevision(eClass, id);
- result.setBranchPoint(branchPoint);
- result.setRevised(revised);
- result.setVersion(version);
- result.setResourceID(resourceID);
- result.setContainerID(containerID);
- result.setContainingFeatureID(featureID);
-
- unmarshallRevision(embedded, result);
-
- return result;
- }
-
- private void unmarshallRevision(DBObject doc, InternalCDORevision revision)
- {
- CDOClassInfo classInfo = revision.getClassInfo();
- for (EStructuralFeature feature : classInfo.getAllPersistentFeatures())
- {
- Object value = doc.get(feature.getName());
-
- if (feature.isUnsettable())
- {
- boolean set = (Boolean)doc.get(feature.getName() + SET_SUFFIX);
- if (!set)
- {
- continue;
- }
- }
-
- if (value == null)
- {
- if (!feature.isMany())
- {
- if (feature.getDefaultValue() != null)
- {
- value = CDORevisionData.NIL;
- }
- }
- }
-
- CDOType type = CDOModelUtil.getType(feature);
- ValueHandler valueHandler = store.getValueHandler(type);
-
- if (feature.isMany())
- {
- if (value != null)
- {
- List<?> list = (List<?>)value;
- CDOList revisionList = revision.getList(feature, list.size());
- for (Object element : list)
- {
- element = valueHandler.fromMongo(element);
- revisionList.add(element);
- }
- }
- }
- else
- {
- value = valueHandler.fromMongo(value);
- revision.set(feature, EStore.NO_INDEX, value);
- }
- }
- }
-
- public void loadCommitInfos(CDOBranch branch, long startTime, long endTime, final CDOCommitInfoHandler handler)
- {
- DBObject query = new BasicDBObject();
-
- if (branch != null && store.isBranching())
- {
- query.put(COMMITS_BRANCH, branch.getID());
- }
-
- BasicDBList list = new BasicDBList();
- if (startTime != CDOBranchPoint.UNSPECIFIED_DATE)
- {
- list.add(new BasicDBObject(QueryOperators.GTE, startTime));
- }
-
- if (endTime != CDOBranchPoint.UNSPECIFIED_DATE)
- {
- list.add(new BasicDBObject(QueryOperators.LTE, endTime));
- }
-
- int size = list.size();
- if (size == 2)
- {
- query.put(COMMITS_ID, list);
- }
- else if (size == 1)
- {
- query.put(COMMITS_ID, list.get(0));
- }
-
- InternalRepository repository = store.getRepository();
- final InternalCDOBranchManager branchManager = repository.getBranchManager();
- final InternalCDOCommitInfoManager commitManager = repository.getCommitInfoManager();
-
- new Query<Object>(query)
- {
- @Override
- public Object execute()
- {
- return execute(collection.find(getRef()).sort(new BasicDBObject(COMMITS_ID, 1)));
- }
-
- @Override
- protected Object handleDoc(DBObject doc)
- {
- long time = (Long)doc.get(COMMITS_ID);
- Object value = doc.get(COMMITS_PREVIOUS);
- long previous = value == null ? 0L : (Long)value;
-
- CDOBranch commitBranch;
- if (store.isBranching())
- {
- int branchID = (Integer)doc.get(COMMITS_BRANCH);
- commitBranch = branchManager.getBranch(branchID);
- }
- else
- {
- commitBranch = branchManager.getMainBranch();
- }
-
- String user = (String)doc.get(COMMITS_USER);
- String comment = (String)doc.get(COMMITS_COMMENT);
-
- CDOCommitInfo commitInfo = commitManager.createCommitInfo(commitBranch, time, previous, user, comment, null);
- handler.handleCommitInfo(commitInfo);
- return null;
- }
- }.execute();
- }
-
- /**
- * @author Eike Stepper
- */
- public abstract class QueryEmbedded<RESULT> extends Query<RESULT>
- {
- private String field;
-
- public QueryEmbedded(DBObject ref, String field)
- {
- super(ref);
- this.field = field;
- }
-
- @Override
- protected RESULT handleDoc(DBObject doc)
- {
- BasicDBList list = (BasicDBList)doc.get(field);
- for (Object object : list)
- {
- DBObject embedded = (DBObject)object;
- RESULT result = handleEmbedded(doc, embedded);
- if (result != null)
- {
- return result;
- }
- }
-
- return null;
- }
-
- protected abstract RESULT handleEmbedded(DBObject doc, DBObject embedded);
- }
-
- /**
- * @author Eike Stepper
- */
- public abstract class QueryEmbeddedUnits<RESULT> extends QueryEmbedded<RESULT>
- {
- public QueryEmbeddedUnits(DBObject ref)
- {
- super(ref, UNITS);
- }
- }
-
- /**
- * @author Eike Stepper
- */
- public abstract class QueryEmbeddedRevisions<RESULT> extends QueryEmbedded<RESULT>
- {
- public QueryEmbeddedRevisions(DBObject ref)
- {
- super(ref, REVISIONS);
- }
- }
-}
+/*
+ * Copyright (c) 2004 - 2012 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.CDOBranch;
+import org.eclipse.emf.cdo.common.branch.CDOBranchPoint;
+import org.eclipse.emf.cdo.common.branch.CDOBranchVersion;
+import org.eclipse.emf.cdo.common.commit.CDOChangeKind;
+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.model.CDOClassInfo;
+import org.eclipse.emf.cdo.common.model.CDOClassifierRef;
+import org.eclipse.emf.cdo.common.model.CDOModelConstants;
+import org.eclipse.emf.cdo.common.model.CDOModelUtil;
+import org.eclipse.emf.cdo.common.model.CDOPackageUnit;
+import org.eclipse.emf.cdo.common.model.CDOType;
+import org.eclipse.emf.cdo.common.model.EMFUtil;
+import org.eclipse.emf.cdo.common.revision.CDOList;
+import org.eclipse.emf.cdo.common.revision.CDORevisionCacheAdder;
+import org.eclipse.emf.cdo.common.revision.CDORevisionData;
+import org.eclipse.emf.cdo.common.util.CDOCommonUtil;
+import org.eclipse.emf.cdo.server.IStoreAccessor;
+import org.eclipse.emf.cdo.server.IStoreAccessor.QueryResourcesContext;
+import org.eclipse.emf.cdo.server.StoreThreadLocal;
+import org.eclipse.emf.cdo.server.internal.mongodb.MongoDBStore.ValueHandler;
+import org.eclipse.emf.cdo.spi.common.branch.InternalCDOBranchManager;
+import org.eclipse.emf.cdo.spi.common.commit.InternalCDOCommitInfoManager;
+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.DetachedCDORevision;
+import org.eclipse.emf.cdo.spi.common.revision.InternalCDORevision;
+import org.eclipse.emf.cdo.spi.common.revision.SyntheticCDORevision;
+import org.eclipse.emf.cdo.spi.server.InternalCommitContext;
+import org.eclipse.emf.cdo.spi.server.InternalRepository;
+
+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.EClass;
+import org.eclipse.emf.ecore.EClassifier;
+import org.eclipse.emf.ecore.EPackage;
+import org.eclipse.emf.ecore.EStructuralFeature;
+import org.eclipse.emf.ecore.InternalEObject.EStore;
+import org.eclipse.emf.ecore.resource.ResourceSet;
+
+import com.mongodb.BasicDBList;
+import com.mongodb.BasicDBObject;
+import com.mongodb.DBObject;
+import com.mongodb.QueryOperators;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+import java.util.Set;
+import java.util.regex.Pattern;
+
+/**
+ * @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_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 SET_SUFFIX = "___set";
+
+ public static final String REVISIONS = "revisions";
+
+ public static final String REVISIONS_ID = "cdo_id";
+
+ public static final String REVISIONS_VERSION = "cdo_version";
+
+ private static final String REVISIONS_REVISED = "cdo_revised";
+
+ 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 InternalCDOPackageRegistry packageRegistry;
+
+ private IDHandler idHandler;
+
+ private InternalCDOPackageUnit[] systemPackageUnits;
+
+ private EStructuralFeature resourceNameFeature;
+
+ public Commits(MongoDBStore store)
+ {
+ super(store, COMMITS);
+ ensureIndex(UNITS, UNITS_ID);
+
+ if (store.isBranching())
+ {
+ DBObject index = new BasicDBObject();
+ index.put(REVISIONS + "." + REVISIONS_ID, 1);
+ index.put(COMMITS_BRANCH, 1);
+ index.put(REVISIONS + "." + REVISIONS_VERSION, 1);
+
+ collection.ensureIndex(index);
+ }
+ else
+ {
+ ensureIndex(REVISIONS, REVISIONS_ID, REVISIONS_VERSION);
+ }
+
+ packageRegistry = store.getRepository().getPackageRegistry();
+ idHandler = store.getIDHandler();
+ }
+
+ public void writePackageUnits(MongoDBStoreAccessor mongoDBStoreAccessor, InternalCDOPackageUnit[] packageUnits,
+ OMMonitor monitor)
+ {
+ // This must be the first commit into the repo.
+ systemPackageUnits = packageUnits;
+
+ for (int i = 0; i < packageUnits.length; i++)
+ {
+ InternalCDOPackageUnit packageUnit = packageUnits[i];
+ InternalCDOPackageInfo[] packageInfos = packageUnit.getPackageInfos();
+ for (int j = 0; j < packageInfos.length; j++)
+ {
+ InternalCDOPackageInfo packageInfo = packageInfos[j];
+ for (EClassifier classifier : packageInfo.getEPackage().getEClassifiers())
+ {
+ store.getClasses().mapNewClassifier(classifier);
+ }
+ }
+ }
+ }
+
+ private DBObject[] marshallUnits(InternalCDOPackageUnit[] packageUnits)
+ {
+ DBObject[] result = new DBObject[packageUnits.length];
+ InternalCDOPackageRegistry packageRegistry = store.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_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 = store.getClasses().mapNewClassifier(classifier);
+ doc.put(CLASSIFIER_PREFIX + classifierID, classifier.getName());
+ }
+
+ result[i] = doc;
+ }
+
+ return result;
+ }
+
+ public Collection<InternalCDOPackageUnit> readPackageUnits()
+ {
+ final Collection<InternalCDOPackageUnit> packageUnits = new ArrayList<InternalCDOPackageUnit>();
+
+ DBObject query = new BasicDBObject();
+ query.put(UNITS, new BasicDBObject("$exists", true));
+
+ new QueryEmbeddedUnits<Object>(query)
+ {
+ @Override
+ protected Object handleEmbedded(DBObject doc, DBObject embedded)
+ {
+ long time = (Long)doc.get(COMMITS_ID);
+ CDOPackageUnit.Type type = CDOPackageUnit.Type.valueOf((String)embedded.get(UNITS_TYPE));
+ InternalCDOPackageInfo[] infos = readPackageInfos(embedded);
+
+ InternalCDOPackageUnit packageUnit = createPackageUnit();
+ packageUnit.setOriginalType(type);
+ packageUnit.setTimeStamp(time);
+ packageUnit.setPackageInfos(infos);
+
+ packageUnits.add(packageUnit);
+ return null;
+ }
+
+ private InternalCDOPackageInfo[] readPackageInfos(DBObject embedded)
+ {
+ BasicDBList infos = (BasicDBList)embedded.get(PACKAGES);
+ InternalCDOPackageInfo[] result = new InternalCDOPackageInfo[infos.size()];
+ int i = 0;
+
+ for (Object info : infos)
+ {
+ DBObject infoObject = (DBObject)info;
+ String uri = (String)infoObject.get(PACKAGES_URI);
+ String parent = (String)infoObject.get(PACKAGES_PARENT);
+
+ InternalCDOPackageInfo packageInfo = createPackageInfo();
+ packageInfo.setPackageURI(uri);
+ packageInfo.setParentURI(parent);
+
+ result[i++] = packageInfo;
+ }
+
+ return result;
+ }
+
+ private InternalCDOPackageUnit createPackageUnit()
+ {
+ return (InternalCDOPackageUnit)CDOModelUtil.createPackageUnit();
+ }
+
+ private InternalCDOPackageInfo createPackageInfo()
+ {
+ return (InternalCDOPackageInfo)CDOModelUtil.createPackageInfo();
+ }
+ }.execute();
+
+ return packageUnits;
+ }
+
+ public EPackage[] loadPackageUnit(final InternalCDOPackageUnit packageUnit)
+ {
+ DBObject query = new BasicDBObject();
+ query.put(UNITS + "." + UNITS_ID, packageUnit.getID());
+
+ return new QueryEmbeddedUnits<EPackage[]>(query)
+ {
+ @Override
+ protected EPackage[] handleEmbedded(DBObject doc, DBObject embedded)
+ {
+ byte[] data = (byte[])embedded.get(UNITS_DATA);
+ EPackage ePackage = createEPackage(packageUnit, data);
+ return EMFUtil.getAllPackages(ePackage);
+ }
+
+ private EPackage createEPackage(InternalCDOPackageUnit packageUnit, byte[] bytes)
+ {
+ ResourceSet resourceSet = EMFUtil.newEcoreResourceSet(packageRegistry);
+ return EMFUtil.createEPackage(packageUnit.getID(), bytes, ZIP_PACKAGE_BYTES, resourceSet, false);
+ }
+ }.execute();
+ }
+
+ public void initializeClassifiers()
+ {
+ final Classes classes = store.getClasses();
+
+ DBObject query = new BasicDBObject();
+ query.put(UNITS, new BasicDBObject("$exists", true));
+
+ new QueryEmbeddedUnits<Object>(query)
+ {
+ @Override
+ protected Object handleEmbedded(DBObject doc, DBObject embedded)
+ {
+ BasicDBList infos = (BasicDBList)embedded.get(PACKAGES);
+ for (Object info : infos)
+ {
+ DBObject infoObject = (DBObject)info;
+ String uri = (String)infoObject.get(PACKAGES_URI);
+ handleClassifiers(infoObject, uri);
+ }
+
+ return null;
+ }
+
+ private void handleClassifiers(DBObject embedded, String packageURI)
+ {
+ Set<String> keys = embedded.keySet();
+ for (String key : keys)
+ {
+ if (key.startsWith(CLASSIFIER_PREFIX))
+ {
+ int id = Integer.parseInt(key.substring(CLASSIFIER_PREFIX.length()));
+ String classifierName = (String)embedded.get(key);
+
+ CDOClassifierRef classifierRef = new CDOClassifierRef(packageURI, classifierName);
+ EClassifier classifier = classifierRef.resolve(packageRegistry);
+
+ classes.mapClassifier(classifier, id);
+ }
+ }
+ }
+ }.execute();
+ }
+
+ 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 (store.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, context.getNewObjects(), CDOChangeKind.NEW);
+ marshalRevisions(docs, context, context.getDirtyObjects(), CDOChangeKind.CHANGED);
+ marshalRevisions(docs, context, context.getDetachedRevisions(), CDOChangeKind.DETACHED);
+
+ if (!docs.isEmpty())
+ {
+ doc.put(REVISIONS, docs);
+ }
+
+ monitor.worked();
+
+ collection.insert(doc);
+ monitor.worked(100);
+ }
+ finally
+ {
+ monitor.done();
+ }
+ }
+
+ private void marshalRevisions(List<DBObject> docs, InternalCommitContext context, InternalCDORevision[] revisions,
+ CDOChangeKind changeKind)
+ {
+ for (InternalCDORevision revision : revisions)
+ {
+ DBObject doc = marshallRevision(context, revision, changeKind);
+ docs.add(doc);
+ }
+ }
+
+ private DBObject marshallRevision(InternalCommitContext context, InternalCDORevision revision,
+ CDOChangeKind changeKind)
+ {
+ boolean resource = !(revision instanceof SyntheticCDORevision) && revision.isResource();
+ if (resource && resourceNameFeature == null)
+ {
+ resourceNameFeature = revision.getEClass().getEStructuralFeature(CDOModelConstants.RESOURCE_NODE_NAME_ATTRIBUTE);
+ }
+
+ DBObject doc = new BasicDBObject();
+ idHandler.write(doc, REVISIONS_ID, revision.getID());
+
+ EClass eClass = revision.getEClass();
+ doc.put(REVISIONS_CLASS, store.getClasses().getClassifierID(eClass));
+
+ if (changeKind == CDOChangeKind.DETACHED)
+ {
+ doc.put(REVISIONS_VERSION, -revision.getVersion() - 1);
+ return doc;
+ }
+
+ doc.put(REVISIONS_VERSION, revision.getVersion());
+
+ CDOID resourceID = revision.getResourceID();
+ idHandler.write(doc, REVISIONS_RESOURCE, resourceID);
+
+ CDOID containerID = (CDOID)revision.getContainerID();
+ idHandler.write(doc, REVISIONS_CONTAINER, containerID);
+
+ int featureID = revision.getContainingFeatureID();
+ doc.put(REVISIONS_FEATURE, featureID);
+
+ if (resource && changeKind != CDOChangeKind.DETACHED)
+ {
+ String name = (String)revision.data().get(resourceNameFeature, 0);
+ IStoreAccessor accessor = StoreThreadLocal.getAccessor();
+
+ CDOID existingID = accessor.readResourceID(containerID, name, revision);
+ if (existingID != null && !existingID.equals(revision.getID()) && !isBeingDetached(context, existingID))
+ {
+ throw new IllegalStateException("Duplicate resource: name=" + name + ", folderID=" + containerID); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+ }
+
+ CDOClassInfo classInfo = revision.getClassInfo();
+ for (EStructuralFeature feature : classInfo.getAllPersistentFeatures())
+ {
+ Object value = revision.getValue(feature);
+
+ CDOType type = CDOModelUtil.getType(feature);
+ ValueHandler valueHandler = store.getValueHandler(type);
+
+ if (feature.isUnsettable())
+ {
+ if (value == null)
+ {
+ doc.put(feature.getName() + SET_SUFFIX, false);
+ doc.put(feature.getName(), valueHandler.getMongoDefaultValue(feature));
+ continue;
+ }
+
+ doc.put(feature.getName() + SET_SUFFIX, true);
+ }
+
+ if (value == CDORevisionData.NIL)
+ {
+ doc.put(feature.getName(), null);
+ }
+ else if (value == null)
+ {
+ if (feature.isMany() || feature.getDefaultValue() == null)
+ {
+ doc.put(feature.getName(), null);
+ }
+ else
+ {
+ doc.put(feature.getName(), valueHandler.getMongoDefaultValue(feature));
+ }
+ }
+ else
+ {
+ if (feature.isMany())
+ {
+ List<?> cdoList = (List<?>)value;
+ BasicDBList mongoList = new BasicDBList();
+ for (Object element : cdoList)
+ {
+ element = valueHandler.toMongo(element);
+ mongoList.add(element);
+ }
+
+ value = mongoList;
+ }
+ else
+ {
+ value = valueHandler.toMongo(value);
+ }
+
+ doc.put(feature.getName(), value);
+ }
+ }
+
+ return doc;
+ }
+
+ private boolean isBeingDetached(InternalCommitContext context, CDOID id)
+ {
+ for (CDOID idBeingDetached : context.getDetachedObjects())
+ {
+ if (id.equals(idBeingDetached))
+ {
+ return true;
+ }
+ }
+
+ return false;
+ }
+
+ public void queryResources(final QueryResourcesContext context)
+ {
+ Classes classes = getStore().getClasses();
+ final int folderCID = classes.getResourceFolderClassID();
+ final int resourceCID = classes.getResourceClassID();
+
+ final CDOID folderID = context.getFolderID();
+ final String name = context.getName();
+ final boolean exactMatch = context.exactMatch();
+ final long timeStamp = context.getTimeStamp();
+
+ DBObject query = new BasicDBObject();
+
+ query.put(REVISIONS + "." + REVISIONS_CLASS, new BasicDBObject("$in", new int[] { folderCID, resourceCID }));
+
+ addToQuery(query, context);
+ query.put(REVISIONS + "." + REVISIONS_CONTAINER, idHandler.toValue(folderID));
+
+ if (name == null || exactMatch)
+ {
+ query.put(REVISIONS + "." + "name", name);
+ }
+ else
+ {
+ query.put(REVISIONS + "." + "name", Pattern.compile("^" + name));
+ }
+
+ new QueryEmbeddedRevisions<Boolean>(query)
+ {
+ @Override
+ protected Boolean handleEmbedded(DBObject doc, DBObject embedded)
+ {
+ int classID = (Integer)embedded.get(REVISIONS_CLASS);
+ if (classID != folderCID && classID != resourceCID)
+ {
+ return null;
+ }
+
+ int version = (Integer)embedded.get(REVISIONS_VERSION);
+ if (version <= 0)
+ {
+ return null;
+ }
+
+ CDOID container = idHandler.read(embedded, REVISIONS_CONTAINER);
+ if (!ObjectUtil.equals(container, folderID))
+ {
+ return null;
+ }
+
+ String revisionName = (String)embedded.get("name");
+ if (name == null || exactMatch)
+ {
+ if (!ObjectUtil.equals(revisionName, name))
+ {
+ return null;
+ }
+ }
+ else
+ {
+ if (!revisionName.startsWith(name))
+ {
+ return null;
+ }
+ }
+
+ CDOID id = idHandler.read(embedded, REVISIONS_ID);
+
+ long created = (Long)doc.get(COMMITS_ID);
+ long revised = getRevised(id, context.getBranch(), version, doc, embedded);
+ if (!CDOCommonUtil.isValidTimeStamp(timeStamp, created, revised))
+ {
+ return null;
+ }
+
+ if (!context.addResource(id))
+ {
+ // No more results allowed
+ return true;
+ }
+
+ return null;
+ }
+ }.execute();
+ }
+
+ private long getRevised(CDOID id, CDOBranch branch, int version, DBObject doc, DBObject revision)
+ {
+ Object value = revision.get(REVISIONS_REVISED);
+ if (value instanceof Long)
+ {
+ return (Long)value;
+ }
+
+ DBObject query = new BasicDBObject();
+ idHandler.write(query, REVISIONS + "." + REVISIONS_ID, id);
+ if (store.isBranching())
+ {
+ query.put(COMMITS_BRANCH, branch.getID());
+ }
+
+ int nextVersion = version + 1;
+ query.put(REVISIONS + "." + REVISIONS_VERSION, new BasicDBObject("$in", new int[] { nextVersion, -nextVersion }));
+
+ Long result = new Query<Long>(query)
+ {
+ @Override
+ protected Long handleDoc(DBObject doc)
+ {
+ return (Long)doc.get(COMMITS_ID);
+ }
+ }.execute();
+
+ if (result != null)
+ {
+ long revised = result - 1;
+
+ // try
+ // {
+ // revision.put(REVISIONS_REVISED, revised);
+ // collection.save(doc);
+ // }
+ // catch (Exception ex)
+ // {
+ // OM.LOG.warn(ex);
+ // }
+
+ return revised;
+ }
+
+ return CDOBranchPoint.UNSPECIFIED_DATE;
+ }
+
+ public InternalCDORevision readRevision(final CDOID id, final CDOBranchPoint branchPoint, int listChunk,
+ CDORevisionCacheAdder cache)
+ {
+ final CDOBranch branch = branchPoint.getBranch();
+ final long timeStamp = branchPoint.getTimeStamp();
+
+ DBObject query = new BasicDBObject();
+ idHandler.write(query, REVISIONS + "." + REVISIONS_ID, id);
+
+ addToQuery(query, branchPoint);
+
+ return new QueryEmbeddedRevisions<InternalCDORevision>(query)
+ {
+ @Override
+ public InternalCDORevision execute()
+ {
+ return execute(collection.find(getRef()).sort(new BasicDBObject(COMMITS_ID, -1)).limit(1));
+ }
+
+ @Override
+ protected InternalCDORevision handleEmbedded(DBObject doc, DBObject embedded)
+ {
+ CDOID embeddedID = idHandler.read(embedded, REVISIONS_ID);
+ if (!ObjectUtil.equals(embeddedID, id))
+ {
+ return null;
+ }
+
+ long created = (Long)doc.get(COMMITS_ID);
+ CDOBranchPoint revisionBranchPoint = branch.getPoint(created);
+
+ InternalCDORevision revision = unmarshallRevision(doc, embedded, id, revisionBranchPoint);
+
+ long revised = revision.getRevised();
+ if (!CDOCommonUtil.isValidTimeStamp(timeStamp, created, revised))
+ {
+ return null;
+ }
+
+ return revision;
+ }
+ }.execute();
+ }
+
+ private void addToQuery(DBObject query, CDOBranchPoint branchPoint)
+ {
+ // Exclude detached objects
+ query.put(REVISIONS + "." + REVISIONS_VERSION, new BasicDBObject("$gte", CDOBranchVersion.FIRST_VERSION));
+
+ long timeStamp = branchPoint.getTimeStamp();
+ if (timeStamp != CDOBranchPoint.UNSPECIFIED_DATE)
+ {
+ query.put(COMMITS_ID, new BasicDBObject("$lte", timeStamp));
+ }
+
+ if (store.isBranching())
+ {
+ int branch = branchPoint.getBranch().getID();
+ query.put(COMMITS_BRANCH, branch);
+ }
+ }
+
+ public InternalCDORevision readRevisionByVersion(final CDOID id, CDOBranchVersion branchVersion, int listChunk,
+ CDORevisionCacheAdder cache)
+ {
+ DBObject query = new BasicDBObject();
+ idHandler.write(query, REVISIONS + "." + REVISIONS_ID, id);
+
+ int version = branchVersion.getVersion();
+ query.put(REVISIONS + "." + REVISIONS_VERSION, new BasicDBObject("$in", new int[] { version, -version }));
+
+ final CDOBranch branch = branchVersion.getBranch();
+ if (store.isBranching())
+ {
+ query.put(COMMITS_BRANCH, branch.getID());
+ }
+
+ return new QueryEmbeddedRevisions<InternalCDORevision>(query)
+ {
+ @Override
+ protected InternalCDORevision handleEmbedded(DBObject doc, DBObject embedded)
+ {
+ CDOID revisionID = idHandler.read(embedded, REVISIONS_ID);
+ if (!ObjectUtil.equals(revisionID, id))
+ {
+ return null;
+ }
+
+ long revisionTime = (Long)doc.get(COMMITS_ID);
+ CDOBranchPoint branchPoint = branch.getPoint(revisionTime);
+
+ return unmarshallRevision(doc, embedded, id, branchPoint);
+ }
+ }.execute();
+ }
+
+ private InternalCDORevision unmarshallRevision(DBObject doc, DBObject embedded, CDOID id, CDOBranchPoint branchPoint)
+ {
+ int classID = (Integer)embedded.get(REVISIONS_CLASS);
+ EClass eClass = store.getClasses().getClass(classID);
+
+ CDOBranch branch = branchPoint.getBranch();
+ int version = (Integer)embedded.get(REVISIONS_VERSION);
+ long revised = getRevised(id, branch, Math.abs(version), doc, embedded);
+
+ if (version < CDOBranchVersion.FIRST_VERSION)
+ {
+ long timeStamp = branchPoint.getTimeStamp();
+ return new DetachedCDORevision(eClass, id, branch, -version, timeStamp, revised);
+ }
+
+ CDOID resourceID = idHandler.read(embedded, REVISIONS_RESOURCE);
+ CDOID containerID = idHandler.read(embedded, REVISIONS_CONTAINER);
+ int featureID = (Integer)embedded.get(REVISIONS_FEATURE);
+
+ InternalCDORevision result = store.createRevision(eClass, id);
+ result.setBranchPoint(branchPoint);
+ result.setRevised(revised);
+ result.setVersion(version);
+ result.setResourceID(resourceID);
+ result.setContainerID(containerID);
+ result.setContainingFeatureID(featureID);
+
+ unmarshallRevision(embedded, result);
+
+ return result;
+ }
+
+ private void unmarshallRevision(DBObject doc, InternalCDORevision revision)
+ {
+ CDOClassInfo classInfo = revision.getClassInfo();
+ for (EStructuralFeature feature : classInfo.getAllPersistentFeatures())
+ {
+ Object value = doc.get(feature.getName());
+
+ if (feature.isUnsettable())
+ {
+ boolean set = (Boolean)doc.get(feature.getName() + SET_SUFFIX);
+ if (!set)
+ {
+ continue;
+ }
+ }
+
+ if (value == null)
+ {
+ if (!feature.isMany())
+ {
+ if (feature.getDefaultValue() != null)
+ {
+ value = CDORevisionData.NIL;
+ }
+ }
+ }
+
+ CDOType type = CDOModelUtil.getType(feature);
+ ValueHandler valueHandler = store.getValueHandler(type);
+
+ if (feature.isMany())
+ {
+ if (value != null)
+ {
+ List<?> list = (List<?>)value;
+ CDOList revisionList = revision.getList(feature, list.size());
+ for (Object element : list)
+ {
+ element = valueHandler.fromMongo(element);
+ revisionList.add(element);
+ }
+ }
+ }
+ else
+ {
+ value = valueHandler.fromMongo(value);
+ revision.set(feature, EStore.NO_INDEX, value);
+ }
+ }
+ }
+
+ public void loadCommitInfos(CDOBranch branch, long startTime, long endTime, final CDOCommitInfoHandler handler)
+ {
+ DBObject query = new BasicDBObject();
+
+ if (branch != null && store.isBranching())
+ {
+ query.put(COMMITS_BRANCH, branch.getID());
+ }
+
+ BasicDBList list = new BasicDBList();
+ if (startTime != CDOBranchPoint.UNSPECIFIED_DATE)
+ {
+ list.add(new BasicDBObject(QueryOperators.GTE, startTime));
+ }
+
+ if (endTime != CDOBranchPoint.UNSPECIFIED_DATE)
+ {
+ list.add(new BasicDBObject(QueryOperators.LTE, endTime));
+ }
+
+ int size = list.size();
+ if (size == 2)
+ {
+ query.put(COMMITS_ID, list);
+ }
+ else if (size == 1)
+ {
+ query.put(COMMITS_ID, list.get(0));
+ }
+
+ InternalRepository repository = store.getRepository();
+ final InternalCDOBranchManager branchManager = repository.getBranchManager();
+ final InternalCDOCommitInfoManager commitManager = repository.getCommitInfoManager();
+
+ new Query<Object>(query)
+ {
+ @Override
+ public Object execute()
+ {
+ return execute(collection.find(getRef()).sort(new BasicDBObject(COMMITS_ID, 1)));
+ }
+
+ @Override
+ protected Object handleDoc(DBObject doc)
+ {
+ long time = (Long)doc.get(COMMITS_ID);
+ Object value = doc.get(COMMITS_PREVIOUS);
+ long previous = value == null ? 0L : (Long)value;
+
+ CDOBranch commitBranch;
+ if (store.isBranching())
+ {
+ int branchID = (Integer)doc.get(COMMITS_BRANCH);
+ commitBranch = branchManager.getBranch(branchID);
+ }
+ else
+ {
+ commitBranch = branchManager.getMainBranch();
+ }
+
+ String user = (String)doc.get(COMMITS_USER);
+ String comment = (String)doc.get(COMMITS_COMMENT);
+
+ CDOCommitInfo commitInfo = commitManager.createCommitInfo(commitBranch, time, previous, user, comment, null);
+ handler.handleCommitInfo(commitInfo);
+ return null;
+ }
+ }.execute();
+ }
+
+ /**
+ * @author Eike Stepper
+ */
+ public abstract class QueryEmbedded<RESULT> extends Query<RESULT>
+ {
+ private String field;
+
+ public QueryEmbedded(DBObject ref, String field)
+ {
+ super(ref);
+ this.field = field;
+ }
+
+ @Override
+ protected RESULT handleDoc(DBObject doc)
+ {
+ BasicDBList list = (BasicDBList)doc.get(field);
+ for (Object object : list)
+ {
+ DBObject embedded = (DBObject)object;
+ RESULT result = handleEmbedded(doc, embedded);
+ if (result != null)
+ {
+ return result;
+ }
+ }
+
+ return null;
+ }
+
+ protected abstract RESULT handleEmbedded(DBObject doc, DBObject embedded);
+ }
+
+ /**
+ * @author Eike Stepper
+ */
+ public abstract class QueryEmbeddedUnits<RESULT> extends QueryEmbedded<RESULT>
+ {
+ public QueryEmbeddedUnits(DBObject ref)
+ {
+ super(ref, UNITS);
+ }
+ }
+
+ /**
+ * @author Eike Stepper
+ */
+ public abstract class QueryEmbeddedRevisions<RESULT> extends QueryEmbedded<RESULT>
+ {
+ public QueryEmbeddedRevisions(DBObject ref)
+ {
+ super(ref, REVISIONS);
+ }
+ }
+}
diff --git a/plugins/org.eclipse.emf.cdo.server.mongodb/src/org/eclipse/emf/cdo/server/internal/mongodb/IDHandler.java b/plugins/org.eclipse.emf.cdo.server.mongodb/src/org/eclipse/emf/cdo/server/internal/mongodb/IDHandler.java
index 306e5bc574..a29aedef6a 100644
--- a/plugins/org.eclipse.emf.cdo.server.mongodb/src/org/eclipse/emf/cdo/server/internal/mongodb/IDHandler.java
+++ b/plugins/org.eclipse.emf.cdo.server.mongodb/src/org/eclipse/emf/cdo/server/internal/mongodb/IDHandler.java
@@ -1,183 +1,183 @@
-/*
- * Copyright (c) 2004 - 2012 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;
-import org.eclipse.emf.cdo.spi.server.LongIDStore;
-
-import org.eclipse.net4j.util.lifecycle.Lifecycle;
-
-import com.mongodb.DBObject;
-
-import java.util.Comparator;
-import java.util.Set;
-
-/**
- * @author Eike Stepper
- */
-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);
-
- public void write(DBObject doc, String key, CDOID id);
-
- public CDOID read(DBObject doc, String key);
-
- public Object toValue(CDOID id);
-
- public CDOID fromValue(Object value);
-
- /**
- * @author Eike Stepper
- */
- public class LongValue 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 LongValue(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);
- }
-
- public void write(DBObject doc, String key, CDOID id)
- {
- long value = toValue(id);
- doc.put(key, value);
- }
-
- public CDOID read(DBObject doc, String key)
- {
- long value = (Long)doc.get(key);
- return fromValue(value);
- }
-
- public Long toValue(CDOID id)
- {
- return CDOIDUtil.getLong(id);
- }
-
- public CDOID fromValue(Object value)
- {
- return CDOIDUtil.createLong((Long)value);
- }
- }
-}
+/*
+ * Copyright (c) 2004 - 2012 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;
+import org.eclipse.emf.cdo.spi.server.LongIDStore;
+
+import org.eclipse.net4j.util.lifecycle.Lifecycle;
+
+import com.mongodb.DBObject;
+
+import java.util.Comparator;
+import java.util.Set;
+
+/**
+ * @author Eike Stepper
+ */
+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);
+
+ public void write(DBObject doc, String key, CDOID id);
+
+ public CDOID read(DBObject doc, String key);
+
+ public Object toValue(CDOID id);
+
+ public CDOID fromValue(Object value);
+
+ /**
+ * @author Eike Stepper
+ */
+ public class LongValue 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 LongValue(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);
+ }
+
+ public void write(DBObject doc, String key, CDOID id)
+ {
+ long value = toValue(id);
+ doc.put(key, value);
+ }
+
+ public CDOID read(DBObject doc, String key)
+ {
+ long value = (Long)doc.get(key);
+ return fromValue(value);
+ }
+
+ public Long toValue(CDOID id)
+ {
+ return CDOIDUtil.getLong(id);
+ }
+
+ public CDOID fromValue(Object value)
+ {
+ return CDOIDUtil.createLong((Long)value);
+ }
+ }
+}
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 3e3bf662c7..cdf9a5b870 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
@@ -1,269 +1,269 @@
-/*
- * Copyright (c) 2004 - 2012 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.server.CDOServerBrowser;
-import org.eclipse.emf.cdo.server.CDOServerBrowser.AbstractPage;
-import org.eclipse.emf.cdo.server.mongodb.IMongoDBStore;
-import org.eclipse.emf.cdo.spi.server.InternalRepository;
-
-import org.eclipse.net4j.util.factory.ProductCreationException;
-
-import com.mongodb.BasicDBObject;
-import com.mongodb.DB;
-import com.mongodb.DBCollection;
-import com.mongodb.DBCursor;
-import com.mongodb.DBObject;
-
-import java.io.PrintStream;
-import java.util.Set;
-
-/**
- * @author Eike Stepper
- * @since 4.0
- */
-public class MongoDBBrowserPage extends AbstractPage
-{
- private static final boolean SHOW_INDEXES = true;
-
- private static final boolean SHOW_DOCUMENTS = true;
-
- private static final boolean SHOW_INITIAL_COMMIT = true;
-
- public MongoDBBrowserPage()
- {
- super("collections", "MongoDB Collections");
- }
-
- public boolean canDisplay(InternalRepository repository)
- {
- return repository.getStore() instanceof IMongoDBStore;
- }
-
- public void display(CDOServerBrowser browser, InternalRepository repository, PrintStream out)
- {
- IMongoDBStore store = (IMongoDBStore)repository.getStore();
- DB db = (DB)store.getDB();
-
- out.print("<table border=\"0\">\r\n");
- out.print("<tr>\r\n");
-
- out.print("<td valign=\"top\">\r\n");
- String collection = showCollections(browser, out, db, repository.getName());
- out.print("</td>\r\n");
- out.print("<td>&nbsp;&nbsp;&nbsp;</td>\r\n");
-
- if (collection != null)
- {
- out.print("<td valign=\"top\">\r\n");
- showCollection(browser, out, db, collection);
- out.print("</td>\r\n");
- }
-
- out.print("</tr>\r\n");
- out.print("</table>\r\n");
- }
-
- protected String showCollections(CDOServerBrowser browser, PrintStream pout, DB db, String repo)
- {
- String collection = browser.getParam("collection");
-
- Set<String> allCollectionNames = db.getCollectionNames();
- for (String collectionName : allCollectionNames)
- {
- if (collection == null)
- {
- collection = collectionName;
- }
-
- String label = browser.escape(collectionName)/* .toLowerCase() */;
- if (collectionName.equals(collection))
- {
- pout.print("<b>" + label + "</b><br>\r\n");
- }
- else
- {
- pout.print(browser.href(label, getName(), "collection", collectionName) + "<br>\r\n");
- }
- }
-
- return collection;
- }
-
- protected void showCollection(CDOServerBrowser browser, PrintStream pout, DB db, String collection)
- {
- DBCollection coll = db.getCollection(collection);
- pout.print("<table border=\"1\" cellpadding=\"4\">\r\n");
- pout.print("<tr><td colspan=\"2\" align=\"center\"><h2>" + collection + "</h2></td></tr>\r\n");
-
- if (SHOW_INDEXES)
- {
- showIndexes(browser, pout, coll);
- }
-
- if (SHOW_DOCUMENTS)
- {
- showDocuments(browser, pout, coll);
- }
- }
-
- protected void showIndexes(CDOServerBrowser browser, PrintStream pout, DBCollection coll)
- {
- pout.print("<tr><td colspan=\"2\" align=\"center\" bgcolor=\"EEEEEE\"><h4>Indexes</h4></td></tr>\r\n");
-
- int i = 0;
- for (DBObject index : coll.getIndexInfo())
- {
- ++i;
- String bg = (i & 1) == 1 ? "bgcolor=\"DDDDDD\"" : "bgcolor=\"EEEEEE\"";
- pout.print("<tr><td valign=\"top\" " + bg + "><b>" + i + "&nbsp;</b></td><td valign=\"top\">");
- showObject(browser, pout, index, "");
- pout.print("</td></tr>\r\n");
- }
- }
-
- protected void showDocuments(CDOServerBrowser browser, PrintStream pout, DBCollection coll)
- {
- DBCursor cursor = null;
-
- try
- {
- pout.print("<tr><td colspan=\"2\" align=\"center\" bgcolor=\"EEEEEE\"><h4>Documents</h4></td></tr>\r\n");
-
- int i = 0;
- cursor = coll.find();
-
- try
- {
- cursor = cursor.sort(new BasicDBObject("_id", 1));
- }
- catch (Exception ex)
- {
- // Ignore
- }
-
- while (cursor.hasNext())
- {
- DBObject doc = cursor.next();
-
- ++i;
- if (i == 1 && showFirstCommit(coll))
- {
- continue;
- }
-
- String bg = (i & 1) == 1 ? "bgcolor=\"DDDDDD\"" : "bgcolor=\"EEEEEE\"";
- pout.print("<tr><td valign=\"top\" " + bg + "><b>" + i + "&nbsp;</b></td><td valign=\"top\">");
- showObject(browser, pout, doc, "");
- pout.print("</td></tr>\r\n");
- }
-
- pout.print("</table>\r\n");
- }
- finally
- {
- if (cursor != null)
- {
- cursor.close();
- }
- }
- }
-
- protected void showObject(CDOServerBrowser browser, PrintStream pout, DBObject doc, String level)
- {
- Set<String> keySet = doc.keySet();
-
- boolean highlight = false;
- try
- {
- String paramKey = browser.getParam("key");
- if (paramKey != null)
- {
- String paramValue = browser.getParam("value");
- Object value = doc.get(paramKey);
- if (String.valueOf(value).equals(paramValue))
- {
- highlight = true;
- }
- }
- }
- catch (Exception ex)
- {
- // Ignore
- }
-
- if (highlight)
- {
- pout.print("<table border=\"0\" bgcolor=\"#FFFFA8\"><tr><td>");
- }
-
- for (String key : keySet)
- {
- pout.print(level);
- pout.print("<b>");
- pout.print(key);
- pout.print("</b> = ");
-
- Object value = doc.get(key);
- if (value instanceof DBObject)
- {
- DBObject child = (DBObject)value;
- pout.print("<br>");
- showObject(browser, pout, child, level + "&nbsp;&nbsp;");
- }
- else
- {
- pout.print("<font color=\"#0000FF\">");
- if (value instanceof String)
- {
- pout.print("\"");
- pout.print(browser.escape((String)value));
- pout.print("\"");
- }
- else
- {
- String string = String.valueOf(value);
- pout.print(browser.href(string, "collections", "key", key, "value", string));
- }
-
- pout.print("</font><br>");
- }
- }
-
- if (highlight)
- {
- pout.print("</td></tr></table>");
- }
- }
-
- protected boolean showFirstCommit(DBCollection coll)
- {
- return coll.getName().equals(Commits.COMMITS) && !SHOW_INITIAL_COMMIT;
- }
-
- /**
- * @author Eike Stepper
- */
- public static class Factory extends org.eclipse.net4j.util.factory.Factory
- {
- public static final String TYPE = "default";
-
- public Factory()
- {
- super(PRODUCT_GROUP, TYPE);
- }
-
- public MongoDBBrowserPage create(String description) throws ProductCreationException
- {
- return new MongoDBBrowserPage();
- }
- }
-}
+/*
+ * Copyright (c) 2004 - 2012 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.server.CDOServerBrowser;
+import org.eclipse.emf.cdo.server.CDOServerBrowser.AbstractPage;
+import org.eclipse.emf.cdo.server.mongodb.IMongoDBStore;
+import org.eclipse.emf.cdo.spi.server.InternalRepository;
+
+import org.eclipse.net4j.util.factory.ProductCreationException;
+
+import com.mongodb.BasicDBObject;
+import com.mongodb.DB;
+import com.mongodb.DBCollection;
+import com.mongodb.DBCursor;
+import com.mongodb.DBObject;
+
+import java.io.PrintStream;
+import java.util.Set;
+
+/**
+ * @author Eike Stepper
+ * @since 4.0
+ */
+public class MongoDBBrowserPage extends AbstractPage
+{
+ private static final boolean SHOW_INDEXES = true;
+
+ private static final boolean SHOW_DOCUMENTS = true;
+
+ private static final boolean SHOW_INITIAL_COMMIT = true;
+
+ public MongoDBBrowserPage()
+ {
+ super("collections", "MongoDB Collections");
+ }
+
+ public boolean canDisplay(InternalRepository repository)
+ {
+ return repository.getStore() instanceof IMongoDBStore;
+ }
+
+ public void display(CDOServerBrowser browser, InternalRepository repository, PrintStream out)
+ {
+ IMongoDBStore store = (IMongoDBStore)repository.getStore();
+ DB db = (DB)store.getDB();
+
+ out.print("<table border=\"0\">\r\n");
+ out.print("<tr>\r\n");
+
+ out.print("<td valign=\"top\">\r\n");
+ String collection = showCollections(browser, out, db, repository.getName());
+ out.print("</td>\r\n");
+ out.print("<td>&nbsp;&nbsp;&nbsp;</td>\r\n");
+
+ if (collection != null)
+ {
+ out.print("<td valign=\"top\">\r\n");
+ showCollection(browser, out, db, collection);
+ out.print("</td>\r\n");
+ }
+
+ out.print("</tr>\r\n");
+ out.print("</table>\r\n");
+ }
+
+ protected String showCollections(CDOServerBrowser browser, PrintStream pout, DB db, String repo)
+ {
+ String collection = browser.getParam("collection");
+
+ Set<String> allCollectionNames = db.getCollectionNames();
+ for (String collectionName : allCollectionNames)
+ {
+ if (collection == null)
+ {
+ collection = collectionName;
+ }
+
+ String label = browser.escape(collectionName)/* .toLowerCase() */;
+ if (collectionName.equals(collection))
+ {
+ pout.print("<b>" + label + "</b><br>\r\n");
+ }
+ else
+ {
+ pout.print(browser.href(label, getName(), "collection", collectionName) + "<br>\r\n");
+ }
+ }
+
+ return collection;
+ }
+
+ protected void showCollection(CDOServerBrowser browser, PrintStream pout, DB db, String collection)
+ {
+ DBCollection coll = db.getCollection(collection);
+ pout.print("<table border=\"1\" cellpadding=\"4\">\r\n");
+ pout.print("<tr><td colspan=\"2\" align=\"center\"><h2>" + collection + "</h2></td></tr>\r\n");
+
+ if (SHOW_INDEXES)
+ {
+ showIndexes(browser, pout, coll);
+ }
+
+ if (SHOW_DOCUMENTS)
+ {
+ showDocuments(browser, pout, coll);
+ }
+ }
+
+ protected void showIndexes(CDOServerBrowser browser, PrintStream pout, DBCollection coll)
+ {
+ pout.print("<tr><td colspan=\"2\" align=\"center\" bgcolor=\"EEEEEE\"><h4>Indexes</h4></td></tr>\r\n");
+
+ int i = 0;
+ for (DBObject index : coll.getIndexInfo())
+ {
+ ++i;
+ String bg = (i & 1) == 1 ? "bgcolor=\"DDDDDD\"" : "bgcolor=\"EEEEEE\"";
+ pout.print("<tr><td valign=\"top\" " + bg + "><b>" + i + "&nbsp;</b></td><td valign=\"top\">");
+ showObject(browser, pout, index, "");
+ pout.print("</td></tr>\r\n");
+ }
+ }
+
+ protected void showDocuments(CDOServerBrowser browser, PrintStream pout, DBCollection coll)
+ {
+ DBCursor cursor = null;
+
+ try
+ {
+ pout.print("<tr><td colspan=\"2\" align=\"center\" bgcolor=\"EEEEEE\"><h4>Documents</h4></td></tr>\r\n");
+
+ int i = 0;
+ cursor = coll.find();
+
+ try
+ {
+ cursor = cursor.sort(new BasicDBObject("_id", 1));
+ }
+ catch (Exception ex)
+ {
+ // Ignore
+ }
+
+ while (cursor.hasNext())
+ {
+ DBObject doc = cursor.next();
+
+ ++i;
+ if (i == 1 && showFirstCommit(coll))
+ {
+ continue;
+ }
+
+ String bg = (i & 1) == 1 ? "bgcolor=\"DDDDDD\"" : "bgcolor=\"EEEEEE\"";
+ pout.print("<tr><td valign=\"top\" " + bg + "><b>" + i + "&nbsp;</b></td><td valign=\"top\">");
+ showObject(browser, pout, doc, "");
+ pout.print("</td></tr>\r\n");
+ }
+
+ pout.print("</table>\r\n");
+ }
+ finally
+ {
+ if (cursor != null)
+ {
+ cursor.close();
+ }
+ }
+ }
+
+ protected void showObject(CDOServerBrowser browser, PrintStream pout, DBObject doc, String level)
+ {
+ Set<String> keySet = doc.keySet();
+
+ boolean highlight = false;
+ try
+ {
+ String paramKey = browser.getParam("key");
+ if (paramKey != null)
+ {
+ String paramValue = browser.getParam("value");
+ Object value = doc.get(paramKey);
+ if (String.valueOf(value).equals(paramValue))
+ {
+ highlight = true;
+ }
+ }
+ }
+ catch (Exception ex)
+ {
+ // Ignore
+ }
+
+ if (highlight)
+ {
+ pout.print("<table border=\"0\" bgcolor=\"#FFFFA8\"><tr><td>");
+ }
+
+ for (String key : keySet)
+ {
+ pout.print(level);
+ pout.print("<b>");
+ pout.print(key);
+ pout.print("</b> = ");
+
+ Object value = doc.get(key);
+ if (value instanceof DBObject)
+ {
+ DBObject child = (DBObject)value;
+ pout.print("<br>");
+ showObject(browser, pout, child, level + "&nbsp;&nbsp;");
+ }
+ else
+ {
+ pout.print("<font color=\"#0000FF\">");
+ if (value instanceof String)
+ {
+ pout.print("\"");
+ pout.print(browser.escape((String)value));
+ pout.print("\"");
+ }
+ else
+ {
+ String string = String.valueOf(value);
+ pout.print(browser.href(string, "collections", "key", key, "value", string));
+ }
+
+ pout.print("</font><br>");
+ }
+ }
+
+ if (highlight)
+ {
+ pout.print("</td></tr></table>");
+ }
+ }
+
+ protected boolean showFirstCommit(DBCollection coll)
+ {
+ return coll.getName().equals(Commits.COMMITS) && !SHOW_INITIAL_COMMIT;
+ }
+
+ /**
+ * @author Eike Stepper
+ */
+ public static class Factory extends org.eclipse.net4j.util.factory.Factory
+ {
+ public static final String TYPE = "default";
+
+ public Factory()
+ {
+ super(PRODUCT_GROUP, TYPE);
+ }
+
+ public MongoDBBrowserPage create(String description) throws ProductCreationException
+ {
+ return new MongoDBBrowserPage();
+ }
+ }
+}
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 b4367e13c6..f6a8fccb5d 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
@@ -1,590 +1,590 @@
-/*
- * Copyright (c) 2004 - 2012 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.model.CDOType;
-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.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.InternalRepository;
-import org.eclipse.emf.cdo.spi.server.InternalStore.NoExternalReferences;
-import org.eclipse.emf.cdo.spi.server.InternalStore.NoFeatureMaps;
-import org.eclipse.emf.cdo.spi.server.InternalStore.NoHandleRevisions;
-import org.eclipse.emf.cdo.spi.server.InternalStore.NoLargeObjects;
-import org.eclipse.emf.cdo.spi.server.InternalStore.NoQueryXRefs;
-import org.eclipse.emf.cdo.spi.server.InternalStore.NoRawAccess;
-import org.eclipse.emf.cdo.spi.server.Store;
-import org.eclipse.emf.cdo.spi.server.StoreAccessorPool;
-
-import org.eclipse.net4j.util.ReflectUtil.ExcludeFromDump;
-import org.eclipse.net4j.util.lifecycle.LifecycleUtil;
-
-import org.eclipse.emf.common.util.Enumerator;
-import org.eclipse.emf.ecore.EClassifier;
-import org.eclipse.emf.ecore.EDataType;
-import org.eclipse.emf.ecore.EEnum;
-import org.eclipse.emf.ecore.EEnumLiteral;
-import org.eclipse.emf.ecore.EFactory;
-import org.eclipse.emf.ecore.EStructuralFeature;
-
-import com.mongodb.DB;
-import com.mongodb.Mongo;
-import com.mongodb.MongoURI;
-
-import java.math.BigDecimal;
-import java.math.BigInteger;
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Map;
-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?
- * <li>Ensure indexes: cdo_class, (cdo_branch/cdo_version)?
- * <li>Remove skipMongo() - server-side CommitInfoManager
- * </ul>
- *
- * @author Eike Stepper
- */
-public class MongoDBStore extends Store implements IMongoDBStore, //
- NoExternalReferences, NoQueryXRefs, NoLargeObjects, NoFeatureMaps, NoHandleRevisions, NoRawAccess
-{
- public static final String TYPE = "mongodb"; //$NON-NLS-1$
-
- @ExcludeFromDump
- private ValueHandler[] valueHandlers = new ValueHandler[Byte.MAX_VALUE - Byte.MIN_VALUE + 1];
-
- private IDHandler idHandler = new IDHandler.LongValue(this);
-
- private MongoURI mongoURI;
-
- private String dbName;
-
- private DB db;
-
- private Props props;
-
- private Commits commits;
-
- private Classes classes;
-
- private boolean firstStart;
-
- private long creationTime;
-
- private boolean branching;
-
- public static Map<String, InternalRepository> REPOS = new HashMap<String, InternalRepository>();
-
- public MongoDBStore()
- {
- super(TYPE, null, set(ChangeFormat.DELTA), //
- set(RevisionTemporality.AUDITING, RevisionTemporality.NONE), //
- set(RevisionParallelism.NONE, RevisionParallelism.BRANCHING));
- }
-
- public ValueHandler getValueHandler(CDOType type)
- {
- return valueHandlers[type.getTypeID() - Byte.MIN_VALUE];
- }
-
- protected void initValueHandlers()
- {
- initValueHandler(CDOType.OBJECT, new ValueHandler()
- {
- @Override
- public Object toMongo(Object value)
- {
- if (value == null)
- {
- return null;
- }
-
- return idHandler.toValue((CDOID)value);
- }
-
- @Override
- public Object fromMongo(Object value)
- {
- if (value == null)
- {
- return null;
- }
-
- return idHandler.fromValue(value);
- }
- });
-
- initValueHandler(CDOType.CHAR, new ValueHandler()
- {
- @Override
- public Object toMongo(Object value)
- {
- if (value == null)
- {
- return null;
- }
-
- return Character.toString((Character)value);
- }
-
- @Override
- public Object fromMongo(Object value)
- {
- if (value instanceof String)
- {
- return ((String)value).charAt(0);
- }
-
- return value;
- }
- });
-
- initValueHandler(CDOType.BYTE, new ValueHandler()
- {
- @Override
- public Object fromMongo(Object value)
- {
- if (value instanceof Integer)
- {
- return (byte)(int)(Integer)value;
- }
-
- return value;
- }
- });
-
- initValueHandler(CDOType.SHORT, new ValueHandler()
- {
- @Override
- public Object fromMongo(Object value)
- {
- if (value instanceof Integer)
- {
- return (short)(int)(Integer)value;
- }
-
- return value;
- }
- });
-
- initValueHandler(CDOType.LONG, new ValueHandler()
- {
- @Override
- public Object fromMongo(Object value)
- {
- if (value instanceof Integer)
- {
- return (long)(Integer)value;
- }
-
- return value;
- }
- });
-
- initValueHandler(CDOType.FLOAT, new ValueHandler()
- {
- @Override
- public Object fromMongo(Object value)
- {
- if (value instanceof Double)
- {
- return (float)(double)(Double)value;
- }
-
- return value;
- }
- });
-
- initValueHandler(CDOType.BIG_DECIMAL, new ValueHandler()
- {
- @Override
- public Object toMongo(Object value)
- {
- if (value == null)
- {
- return null;
- }
-
- return ((BigDecimal)value).toPlainString();
- }
-
- @Override
- public Object fromMongo(Object value)
- {
- if (value == null)
- {
- return null;
- }
-
- return new BigDecimal((String)value);
- }
- });
-
- initValueHandler(CDOType.BIG_INTEGER, new ValueHandler()
- {
- @Override
- public Object toMongo(Object value)
- {
- if (value == null)
- {
- return null;
- }
-
- return ((BigInteger)value).toString();
- }
-
- @Override
- public Object fromMongo(Object value)
- {
- if (value == null)
- {
- return null;
- }
-
- return new BigInteger((String)value);
- }
- });
-
- initValueHandler(CDOType.ENUM_ORDINAL, new ValueHandler()
- {
- @Override
- public Object getMongoDefaultValue(EStructuralFeature feature)
- {
- EEnum eenum = (EEnum)feature.getEType();
-
- String defaultValueLiteral = feature.getDefaultValueLiteral();
- if (defaultValueLiteral != null)
- {
- EEnumLiteral literal = eenum.getEEnumLiteralByLiteral(defaultValueLiteral);
- return literal.getValue();
- }
-
- Enumerator enumerator = (Enumerator)eenum.getDefaultValue();
- return enumerator.getValue();
- }
- });
-
- initValueHandler(CDOType.CUSTOM, new ValueHandler()
- {
- @Override
- public Object getMongoDefaultValue(EStructuralFeature feature)
- {
- Object defaultValue = feature.getDefaultValue();
- EClassifier eType = feature.getEType();
- EFactory factory = eType.getEPackage().getEFactoryInstance();
- return factory.convertToString((EDataType)eType, defaultValue);
- }
- });
- }
-
- protected void initValueHandler(CDOType type, ValueHandler valueHandler)
- {
- valueHandlers[type.getTypeID() - Byte.MIN_VALUE] = valueHandler;
- }
-
- public IDHandler getIDHandler()
- {
- return idHandler;
- }
-
- public void setIDHandler(IDHandler idHandler)
- {
- checkInactive();
- this.idHandler = idHandler;
- }
-
- public MongoURI getMongoURI()
- {
- return mongoURI;
- }
-
- public void setMongoURI(MongoURI mongoURI)
- {
- checkInactive();
- this.mongoURI = mongoURI;
- }
-
- public String getDBName()
- {
- return dbName;
- }
-
- public void setDBName(String dbName)
- {
- checkInactive();
- this.dbName = dbName;
- }
-
- public DB getDB()
- {
- return db;
- }
-
- public Props getProps()
- {
- return props;
- }
-
- public Commits getCommits()
- {
- return commits;
- }
-
- public Classes getClasses()
- {
- return classes;
- }
-
- public Map<String, String> getPersistentProperties(Set<String> names)
- {
- return props.get(names);
- }
-
- public void setPersistentProperties(Map<String, String> properties)
- {
- props.set(properties);
- }
-
- public void removePersistentProperties(Set<String> names)
- {
- props.remove(names);
- }
-
- public boolean isFirstStart()
- {
- return firstStart;
- }
-
- public long getCreationTime()
- {
- return creationTime;
- }
-
- public void setCreationTime(long creationTime)
- {
- this.creationTime = creationTime;
-
- Map<String, String> map = new HashMap<String, String>();
- map.put(Props.REPOSITORY_CREATED, Long.toString(creationTime));
- props.set(map);
- }
-
- public boolean isBranching()
- {
- return branching;
- }
-
- public CDOID createObjectID(String val)
- {
- throw new UnsupportedOperationException("Not yet implemented"); // TODO Implement me
- }
-
- public boolean isLocal(CDOID id)
- {
- throw new UnsupportedOperationException("Not yet implemented"); // TODO Implement me
- }
-
- @Override
- public IMongoDBStoreAccessor getReader(ISession session)
- {
- return (IMongoDBStoreAccessor)super.getReader(session);
- }
-
- @Override
- public IMongoDBStoreAccessor getWriter(ITransaction transaction)
- {
- return (IMongoDBStoreAccessor)super.getWriter(transaction);
- }
-
- @Override
- protected IStoreAccessor createReader(ISession session)
- {
- return new MongoDBStoreAccessor(this, session);
- }
-
- @Override
- protected IStoreAccessor createWriter(ITransaction transaction)
- {
- return new MongoDBStoreAccessor(this, transaction);
- }
-
- @Override
- protected StoreAccessorPool getReaderPool(ISession session, boolean forReleasing)
- {
- // No pooling needed
- return null;
- }
-
- @Override
- protected StoreAccessorPool getWriterPool(IView view, boolean forReleasing)
- {
- // No pooling needed
- return null;
- }
-
- @Override
- protected void doBeforeActivate() throws Exception
- {
- super.doBeforeActivate();
- checkState(mongoURI, "mongoURI");
- checkState(dbName, "dbName");
- }
-
- @Override
- protected void doActivate() throws Exception
- {
- InternalRepository repository = getRepository();
- branching = repository.isSupportingBranches();
- if (branching)
- {
- throw new IllegalStateException("Branching is not supported");
- }
-
- REPOS.put(repository.getName(), repository);
-
- super.doActivate();
-
- Mongo mongo = new Mongo(mongoURI);
- db = mongo.getDB(dbName);
-
- Set<String> collectionNames = db.getCollectionNames();
- firstStart = !collectionNames.contains(Props.NAME);
-
- props = new Props(this);
- commits = new Commits(this);
- classes = new Classes(this);
-
- LifecycleUtil.activate(idHandler);
- setObjectIDTypes(idHandler.getObjectIDTypes());
-
- Arrays.fill(valueHandlers, new ValueHandler());
- initValueHandlers();
-
- if (firstStart)
- {
- firstStart();
- }
- else
- {
- reStart();
- }
- }
-
- @Override
- protected void doDeactivate() throws Exception
- {
- Map<String, String> map = new HashMap<String, String>();
- 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(classes.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()));
- setPersistentProperties(map);
-
- LifecycleUtil.deactivate(idHandler);
-
- REPOS.remove(getRepository().getName());
-
- if (db != null)
- {
- db.getMongo().close();
- db = null;
- }
-
- 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(Props.REPOSITORY_CREATED);
- names.add(Props.GRACEFULLY_SHUT_DOWN);
-
- Map<String, String> map = getPersistentProperties(names);
- creationTime = Long.valueOf(map.get(Props.REPOSITORY_CREATED));
-
- if (map.containsKey(Props.GRACEFULLY_SHUT_DOWN))
- {
- names.clear();
- 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 = getPersistentProperties(names);
-
- idHandler.setNextLocalObjectID(stringToID(map.get(Props.NEXT_LOCAL_CDOID)));
- idHandler.setLastObjectID(stringToID(map.get(Props.LAST_CDOID)));
- classes.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();
- }
-
- removePersistentProperties(Collections.singleton(Props.GRACEFULLY_SHUT_DOWN));
- }
-
- protected void repairAfterCrash()
- {
- throw new UnsupportedOperationException("Not yet implemented"); // TODO Implement me
- }
-
- /**
- * @author Eike Stepper
- */
- public static class ValueHandler
- {
- public Object getMongoDefaultValue(EStructuralFeature feature)
- {
- Object defaultValue = feature.getDefaultValue();
- return toMongo(defaultValue);
- }
-
- public Object toMongo(Object value)
- {
- return value;
- }
-
- public Object fromMongo(Object value)
- {
- return value;
- }
- }
-}
+/*
+ * Copyright (c) 2004 - 2012 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.model.CDOType;
+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.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.InternalRepository;
+import org.eclipse.emf.cdo.spi.server.InternalStore.NoExternalReferences;
+import org.eclipse.emf.cdo.spi.server.InternalStore.NoFeatureMaps;
+import org.eclipse.emf.cdo.spi.server.InternalStore.NoHandleRevisions;
+import org.eclipse.emf.cdo.spi.server.InternalStore.NoLargeObjects;
+import org.eclipse.emf.cdo.spi.server.InternalStore.NoQueryXRefs;
+import org.eclipse.emf.cdo.spi.server.InternalStore.NoRawAccess;
+import org.eclipse.emf.cdo.spi.server.Store;
+import org.eclipse.emf.cdo.spi.server.StoreAccessorPool;
+
+import org.eclipse.net4j.util.ReflectUtil.ExcludeFromDump;
+import org.eclipse.net4j.util.lifecycle.LifecycleUtil;
+
+import org.eclipse.emf.common.util.Enumerator;
+import org.eclipse.emf.ecore.EClassifier;
+import org.eclipse.emf.ecore.EDataType;
+import org.eclipse.emf.ecore.EEnum;
+import org.eclipse.emf.ecore.EEnumLiteral;
+import org.eclipse.emf.ecore.EFactory;
+import org.eclipse.emf.ecore.EStructuralFeature;
+
+import com.mongodb.DB;
+import com.mongodb.Mongo;
+import com.mongodb.MongoURI;
+
+import java.math.BigDecimal;
+import java.math.BigInteger;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+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?
+ * <li>Ensure indexes: cdo_class, (cdo_branch/cdo_version)?
+ * <li>Remove skipMongo() - server-side CommitInfoManager
+ * </ul>
+ *
+ * @author Eike Stepper
+ */
+public class MongoDBStore extends Store implements IMongoDBStore, //
+ NoExternalReferences, NoQueryXRefs, NoLargeObjects, NoFeatureMaps, NoHandleRevisions, NoRawAccess
+{
+ public static final String TYPE = "mongodb"; //$NON-NLS-1$
+
+ @ExcludeFromDump
+ private ValueHandler[] valueHandlers = new ValueHandler[Byte.MAX_VALUE - Byte.MIN_VALUE + 1];
+
+ private IDHandler idHandler = new IDHandler.LongValue(this);
+
+ private MongoURI mongoURI;
+
+ private String dbName;
+
+ private DB db;
+
+ private Props props;
+
+ private Commits commits;
+
+ private Classes classes;
+
+ private boolean firstStart;
+
+ private long creationTime;
+
+ private boolean branching;
+
+ public static Map<String, InternalRepository> REPOS = new HashMap<String, InternalRepository>();
+
+ public MongoDBStore()
+ {
+ super(TYPE, null, set(ChangeFormat.DELTA), //
+ set(RevisionTemporality.AUDITING, RevisionTemporality.NONE), //
+ set(RevisionParallelism.NONE, RevisionParallelism.BRANCHING));
+ }
+
+ public ValueHandler getValueHandler(CDOType type)
+ {
+ return valueHandlers[type.getTypeID() - Byte.MIN_VALUE];
+ }
+
+ protected void initValueHandlers()
+ {
+ initValueHandler(CDOType.OBJECT, new ValueHandler()
+ {
+ @Override
+ public Object toMongo(Object value)
+ {
+ if (value == null)
+ {
+ return null;
+ }
+
+ return idHandler.toValue((CDOID)value);
+ }
+
+ @Override
+ public Object fromMongo(Object value)
+ {
+ if (value == null)
+ {
+ return null;
+ }
+
+ return idHandler.fromValue(value);
+ }
+ });
+
+ initValueHandler(CDOType.CHAR, new ValueHandler()
+ {
+ @Override
+ public Object toMongo(Object value)
+ {
+ if (value == null)
+ {
+ return null;
+ }
+
+ return Character.toString((Character)value);
+ }
+
+ @Override
+ public Object fromMongo(Object value)
+ {
+ if (value instanceof String)
+ {
+ return ((String)value).charAt(0);
+ }
+
+ return value;
+ }
+ });
+
+ initValueHandler(CDOType.BYTE, new ValueHandler()
+ {
+ @Override
+ public Object fromMongo(Object value)
+ {
+ if (value instanceof Integer)
+ {
+ return (byte)(int)(Integer)value;
+ }
+
+ return value;
+ }
+ });
+
+ initValueHandler(CDOType.SHORT, new ValueHandler()
+ {
+ @Override
+ public Object fromMongo(Object value)
+ {
+ if (value instanceof Integer)
+ {
+ return (short)(int)(Integer)value;
+ }
+
+ return value;
+ }
+ });
+
+ initValueHandler(CDOType.LONG, new ValueHandler()
+ {
+ @Override
+ public Object fromMongo(Object value)
+ {
+ if (value instanceof Integer)
+ {
+ return (long)(Integer)value;
+ }
+
+ return value;
+ }
+ });
+
+ initValueHandler(CDOType.FLOAT, new ValueHandler()
+ {
+ @Override
+ public Object fromMongo(Object value)
+ {
+ if (value instanceof Double)
+ {
+ return (float)(double)(Double)value;
+ }
+
+ return value;
+ }
+ });
+
+ initValueHandler(CDOType.BIG_DECIMAL, new ValueHandler()
+ {
+ @Override
+ public Object toMongo(Object value)
+ {
+ if (value == null)
+ {
+ return null;
+ }
+
+ return ((BigDecimal)value).toPlainString();
+ }
+
+ @Override
+ public Object fromMongo(Object value)
+ {
+ if (value == null)
+ {
+ return null;
+ }
+
+ return new BigDecimal((String)value);
+ }
+ });
+
+ initValueHandler(CDOType.BIG_INTEGER, new ValueHandler()
+ {
+ @Override
+ public Object toMongo(Object value)
+ {
+ if (value == null)
+ {
+ return null;
+ }
+
+ return ((BigInteger)value).toString();
+ }
+
+ @Override
+ public Object fromMongo(Object value)
+ {
+ if (value == null)
+ {
+ return null;
+ }
+
+ return new BigInteger((String)value);
+ }
+ });
+
+ initValueHandler(CDOType.ENUM_ORDINAL, new ValueHandler()
+ {
+ @Override
+ public Object getMongoDefaultValue(EStructuralFeature feature)
+ {
+ EEnum eenum = (EEnum)feature.getEType();
+
+ String defaultValueLiteral = feature.getDefaultValueLiteral();
+ if (defaultValueLiteral != null)
+ {
+ EEnumLiteral literal = eenum.getEEnumLiteralByLiteral(defaultValueLiteral);
+ return literal.getValue();
+ }
+
+ Enumerator enumerator = (Enumerator)eenum.getDefaultValue();
+ return enumerator.getValue();
+ }
+ });
+
+ initValueHandler(CDOType.CUSTOM, new ValueHandler()
+ {
+ @Override
+ public Object getMongoDefaultValue(EStructuralFeature feature)
+ {
+ Object defaultValue = feature.getDefaultValue();
+ EClassifier eType = feature.getEType();
+ EFactory factory = eType.getEPackage().getEFactoryInstance();
+ return factory.convertToString((EDataType)eType, defaultValue);
+ }
+ });
+ }
+
+ protected void initValueHandler(CDOType type, ValueHandler valueHandler)
+ {
+ valueHandlers[type.getTypeID() - Byte.MIN_VALUE] = valueHandler;
+ }
+
+ public IDHandler getIDHandler()
+ {
+ return idHandler;
+ }
+
+ public void setIDHandler(IDHandler idHandler)
+ {
+ checkInactive();
+ this.idHandler = idHandler;
+ }
+
+ public MongoURI getMongoURI()
+ {
+ return mongoURI;
+ }
+
+ public void setMongoURI(MongoURI mongoURI)
+ {
+ checkInactive();
+ this.mongoURI = mongoURI;
+ }
+
+ public String getDBName()
+ {
+ return dbName;
+ }
+
+ public void setDBName(String dbName)
+ {
+ checkInactive();
+ this.dbName = dbName;
+ }
+
+ public DB getDB()
+ {
+ return db;
+ }
+
+ public Props getProps()
+ {
+ return props;
+ }
+
+ public Commits getCommits()
+ {
+ return commits;
+ }
+
+ public Classes getClasses()
+ {
+ return classes;
+ }
+
+ public Map<String, String> getPersistentProperties(Set<String> names)
+ {
+ return props.get(names);
+ }
+
+ public void setPersistentProperties(Map<String, String> properties)
+ {
+ props.set(properties);
+ }
+
+ public void removePersistentProperties(Set<String> names)
+ {
+ props.remove(names);
+ }
+
+ public boolean isFirstStart()
+ {
+ return firstStart;
+ }
+
+ public long getCreationTime()
+ {
+ return creationTime;
+ }
+
+ public void setCreationTime(long creationTime)
+ {
+ this.creationTime = creationTime;
+
+ Map<String, String> map = new HashMap<String, String>();
+ map.put(Props.REPOSITORY_CREATED, Long.toString(creationTime));
+ props.set(map);
+ }
+
+ public boolean isBranching()
+ {
+ return branching;
+ }
+
+ public CDOID createObjectID(String val)
+ {
+ throw new UnsupportedOperationException("Not yet implemented"); // TODO Implement me
+ }
+
+ public boolean isLocal(CDOID id)
+ {
+ throw new UnsupportedOperationException("Not yet implemented"); // TODO Implement me
+ }
+
+ @Override
+ public IMongoDBStoreAccessor getReader(ISession session)
+ {
+ return (IMongoDBStoreAccessor)super.getReader(session);
+ }
+
+ @Override
+ public IMongoDBStoreAccessor getWriter(ITransaction transaction)
+ {
+ return (IMongoDBStoreAccessor)super.getWriter(transaction);
+ }
+
+ @Override
+ protected IStoreAccessor createReader(ISession session)
+ {
+ return new MongoDBStoreAccessor(this, session);
+ }
+
+ @Override
+ protected IStoreAccessor createWriter(ITransaction transaction)
+ {
+ return new MongoDBStoreAccessor(this, transaction);
+ }
+
+ @Override
+ protected StoreAccessorPool getReaderPool(ISession session, boolean forReleasing)
+ {
+ // No pooling needed
+ return null;
+ }
+
+ @Override
+ protected StoreAccessorPool getWriterPool(IView view, boolean forReleasing)
+ {
+ // No pooling needed
+ return null;
+ }
+
+ @Override
+ protected void doBeforeActivate() throws Exception
+ {
+ super.doBeforeActivate();
+ checkState(mongoURI, "mongoURI");
+ checkState(dbName, "dbName");
+ }
+
+ @Override
+ protected void doActivate() throws Exception
+ {
+ InternalRepository repository = getRepository();
+ branching = repository.isSupportingBranches();
+ if (branching)
+ {
+ throw new IllegalStateException("Branching is not supported");
+ }
+
+ REPOS.put(repository.getName(), repository);
+
+ super.doActivate();
+
+ Mongo mongo = new Mongo(mongoURI);
+ db = mongo.getDB(dbName);
+
+ Set<String> collectionNames = db.getCollectionNames();
+ firstStart = !collectionNames.contains(Props.NAME);
+
+ props = new Props(this);
+ commits = new Commits(this);
+ classes = new Classes(this);
+
+ LifecycleUtil.activate(idHandler);
+ setObjectIDTypes(idHandler.getObjectIDTypes());
+
+ Arrays.fill(valueHandlers, new ValueHandler());
+ initValueHandlers();
+
+ if (firstStart)
+ {
+ firstStart();
+ }
+ else
+ {
+ reStart();
+ }
+ }
+
+ @Override
+ protected void doDeactivate() throws Exception
+ {
+ Map<String, String> map = new HashMap<String, String>();
+ 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(classes.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()));
+ setPersistentProperties(map);
+
+ LifecycleUtil.deactivate(idHandler);
+
+ REPOS.remove(getRepository().getName());
+
+ if (db != null)
+ {
+ db.getMongo().close();
+ db = null;
+ }
+
+ 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(Props.REPOSITORY_CREATED);
+ names.add(Props.GRACEFULLY_SHUT_DOWN);
+
+ Map<String, String> map = getPersistentProperties(names);
+ creationTime = Long.valueOf(map.get(Props.REPOSITORY_CREATED));
+
+ if (map.containsKey(Props.GRACEFULLY_SHUT_DOWN))
+ {
+ names.clear();
+ 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 = getPersistentProperties(names);
+
+ idHandler.setNextLocalObjectID(stringToID(map.get(Props.NEXT_LOCAL_CDOID)));
+ idHandler.setLastObjectID(stringToID(map.get(Props.LAST_CDOID)));
+ classes.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();
+ }
+
+ removePersistentProperties(Collections.singleton(Props.GRACEFULLY_SHUT_DOWN));
+ }
+
+ protected void repairAfterCrash()
+ {
+ throw new UnsupportedOperationException("Not yet implemented"); // TODO Implement me
+ }
+
+ /**
+ * @author Eike Stepper
+ */
+ public static class ValueHandler
+ {
+ public Object getMongoDefaultValue(EStructuralFeature feature)
+ {
+ Object defaultValue = feature.getDefaultValue();
+ return toMongo(defaultValue);
+ }
+
+ public Object toMongo(Object value)
+ {
+ return value;
+ }
+
+ public Object fromMongo(Object value)
+ {
+ return value;
+ }
+ }
+}
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 dd6ee05b65..c661139050 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
@@ -1,196 +1,196 @@
-/*
- * Copyright (c) 2004 - 2012 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.CDOBranch;
-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.CDOCommitInfoHandler;
-import org.eclipse.emf.cdo.common.id.CDOID;
-import org.eclipse.emf.cdo.common.lob.CDOLobHandler;
-import org.eclipse.emf.cdo.common.revision.CDORevision;
-import org.eclipse.emf.cdo.common.revision.CDORevisionCacheAdder;
-import org.eclipse.emf.cdo.common.revision.CDORevisionHandler;
-import org.eclipse.emf.cdo.common.util.CDOQueryInfo;
-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.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;
-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.collection.Pair;
-import org.eclipse.net4j.util.om.monitor.OMMonitor;
-
-import org.eclipse.emf.ecore.EClass;
-import org.eclipse.emf.ecore.EPackage;
-import org.eclipse.emf.ecore.EStructuralFeature;
-
-import java.io.IOException;
-import java.io.OutputStream;
-import java.util.Collection;
-import java.util.List;
-import java.util.Set;
-
-/**
- * @author Eike Stepper
- */
-public class MongoDBStoreAccessor extends StoreAccessorBase implements IMongoDBStoreAccessor
-{
- private Commits commits;
-
- public MongoDBStoreAccessor(Store store, ISession session)
- {
- super(store, session);
- commits = getStore().getCommits();
- }
-
- public MongoDBStoreAccessor(Store store, ITransaction transaction)
- {
- super(store, transaction);
- commits = getStore().getCommits();
- }
-
- @Override
- public MongoDBStore getStore()
- {
- return (MongoDBStore)super.getStore();
- }
-
- public IStoreChunkReader createChunkReader(InternalCDORevision revision, EStructuralFeature feature)
- {
- // Partial collection loading not supported, yet.
- return null;
- }
-
- public Collection<InternalCDOPackageUnit> readPackageUnits()
- {
- return commits.readPackageUnits();
- }
-
- public EPackage[] loadPackageUnit(InternalCDOPackageUnit packageUnit)
- {
- return commits.loadPackageUnit(packageUnit);
- }
-
- public InternalCDORevision readRevision(CDOID id, CDOBranchPoint branchPoint, int listChunk,
- CDORevisionCacheAdder cache)
- {
- return commits.readRevision(id, branchPoint, listChunk, cache);
- }
-
- public InternalCDORevision readRevisionByVersion(CDOID id, CDOBranchVersion branchVersion, int listChunk,
- CDORevisionCacheAdder cache)
- {
- return commits.readRevisionByVersion(id, branchVersion, listChunk, cache);
- }
-
- public void handleRevisions(EClass eClass, CDOBranch branch, long timeStamp, boolean exactTime,
- CDORevisionHandler handler)
- {
- throw new UnsupportedOperationException("Not yet implemented"); // TODO Implement me
- }
-
- public Set<CDOID> readChangeSet(OMMonitor monitor, CDOChangeSetSegment... segments)
- {
- throw new UnsupportedOperationException("Not yet implemented"); // TODO Implement me
- }
-
- public void queryResources(QueryResourcesContext context)
- {
- commits.queryResources(context);
- }
-
- public void queryXRefs(QueryXRefsContext context)
- {
- throw new UnsupportedOperationException("Not yet implemented"); // TODO Implement me
- }
-
- public void queryLobs(List<byte[]> ids)
- {
- throw new UnsupportedOperationException("Not yet implemented"); // TODO Implement me
- }
-
- public void loadLob(byte[] id, OutputStream out) throws IOException
- {
- throw new UnsupportedOperationException("Not yet implemented"); // TODO Implement me
- }
-
- public void handleLobs(long fromTime, long toTime, CDOLobHandler handler) throws IOException
- {
- throw new UnsupportedOperationException("Not yet implemented"); // TODO Implement me
- }
-
- public IQueryHandler getQueryHandler(CDOQueryInfo info)
- {
- return null;
- }
-
- public Pair<Integer, Long> createBranch(int branchID, BranchInfo branchInfo)
- {
- throw new UnsupportedOperationException("Not yet implemented"); // TODO Implement me
- }
-
- public BranchInfo loadBranch(int branchID)
- {
- throw new UnsupportedOperationException("Not yet implemented"); // TODO Implement me
- }
-
- public SubBranchInfo[] loadSubBranches(int branchID)
- {
- throw new UnsupportedOperationException("Not yet implemented"); // TODO Implement me
- }
-
- public int loadBranches(int startID, int endID, CDOBranchHandler branchHandler)
- {
- throw new UnsupportedOperationException("Not yet implemented"); // TODO Implement me
- }
-
- public void loadCommitInfos(CDOBranch branch, long startTime, long endTime, CDOCommitInfoHandler handler)
- {
- commits.loadCommitInfos(branch, startTime, endTime, handler);
- }
-
- public void writePackageUnits(InternalCDOPackageUnit[] packageUnits, OMMonitor monitor)
- {
- commits.writePackageUnits(this, packageUnits, monitor);
- }
-
- @Override
- protected void doWrite(InternalCommitContext context, OMMonitor monitor)
- {
- commits.write(this, context, monitor);
- }
-
- @Override
- protected void doCommit(OMMonitor monitor)
- {
- // Do nothing
- }
-
- @Override
- protected void doRollback(CommitContext commitContext)
- {
- // Do nothing
- }
-
- @Override
- protected CDOID getNextCDOID(CDORevision revision)
- {
- return getStore().getIDHandler().getNextCDOID(revision);
- }
-}
+/*
+ * Copyright (c) 2004 - 2012 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.CDOBranch;
+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.CDOCommitInfoHandler;
+import org.eclipse.emf.cdo.common.id.CDOID;
+import org.eclipse.emf.cdo.common.lob.CDOLobHandler;
+import org.eclipse.emf.cdo.common.revision.CDORevision;
+import org.eclipse.emf.cdo.common.revision.CDORevisionCacheAdder;
+import org.eclipse.emf.cdo.common.revision.CDORevisionHandler;
+import org.eclipse.emf.cdo.common.util.CDOQueryInfo;
+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.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;
+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.collection.Pair;
+import org.eclipse.net4j.util.om.monitor.OMMonitor;
+
+import org.eclipse.emf.ecore.EClass;
+import org.eclipse.emf.ecore.EPackage;
+import org.eclipse.emf.ecore.EStructuralFeature;
+
+import java.io.IOException;
+import java.io.OutputStream;
+import java.util.Collection;
+import java.util.List;
+import java.util.Set;
+
+/**
+ * @author Eike Stepper
+ */
+public class MongoDBStoreAccessor extends StoreAccessorBase implements IMongoDBStoreAccessor
+{
+ private Commits commits;
+
+ public MongoDBStoreAccessor(Store store, ISession session)
+ {
+ super(store, session);
+ commits = getStore().getCommits();
+ }
+
+ public MongoDBStoreAccessor(Store store, ITransaction transaction)
+ {
+ super(store, transaction);
+ commits = getStore().getCommits();
+ }
+
+ @Override
+ public MongoDBStore getStore()
+ {
+ return (MongoDBStore)super.getStore();
+ }
+
+ public IStoreChunkReader createChunkReader(InternalCDORevision revision, EStructuralFeature feature)
+ {
+ // Partial collection loading not supported, yet.
+ return null;
+ }
+
+ public Collection<InternalCDOPackageUnit> readPackageUnits()
+ {
+ return commits.readPackageUnits();
+ }
+
+ public EPackage[] loadPackageUnit(InternalCDOPackageUnit packageUnit)
+ {
+ return commits.loadPackageUnit(packageUnit);
+ }
+
+ public InternalCDORevision readRevision(CDOID id, CDOBranchPoint branchPoint, int listChunk,
+ CDORevisionCacheAdder cache)
+ {
+ return commits.readRevision(id, branchPoint, listChunk, cache);
+ }
+
+ public InternalCDORevision readRevisionByVersion(CDOID id, CDOBranchVersion branchVersion, int listChunk,
+ CDORevisionCacheAdder cache)
+ {
+ return commits.readRevisionByVersion(id, branchVersion, listChunk, cache);
+ }
+
+ public void handleRevisions(EClass eClass, CDOBranch branch, long timeStamp, boolean exactTime,
+ CDORevisionHandler handler)
+ {
+ throw new UnsupportedOperationException("Not yet implemented"); // TODO Implement me
+ }
+
+ public Set<CDOID> readChangeSet(OMMonitor monitor, CDOChangeSetSegment... segments)
+ {
+ throw new UnsupportedOperationException("Not yet implemented"); // TODO Implement me
+ }
+
+ public void queryResources(QueryResourcesContext context)
+ {
+ commits.queryResources(context);
+ }
+
+ public void queryXRefs(QueryXRefsContext context)
+ {
+ throw new UnsupportedOperationException("Not yet implemented"); // TODO Implement me
+ }
+
+ public void queryLobs(List<byte[]> ids)
+ {
+ throw new UnsupportedOperationException("Not yet implemented"); // TODO Implement me
+ }
+
+ public void loadLob(byte[] id, OutputStream out) throws IOException
+ {
+ throw new UnsupportedOperationException("Not yet implemented"); // TODO Implement me
+ }
+
+ public void handleLobs(long fromTime, long toTime, CDOLobHandler handler) throws IOException
+ {
+ throw new UnsupportedOperationException("Not yet implemented"); // TODO Implement me
+ }
+
+ public IQueryHandler getQueryHandler(CDOQueryInfo info)
+ {
+ return null;
+ }
+
+ public Pair<Integer, Long> createBranch(int branchID, BranchInfo branchInfo)
+ {
+ throw new UnsupportedOperationException("Not yet implemented"); // TODO Implement me
+ }
+
+ public BranchInfo loadBranch(int branchID)
+ {
+ throw new UnsupportedOperationException("Not yet implemented"); // TODO Implement me
+ }
+
+ public SubBranchInfo[] loadSubBranches(int branchID)
+ {
+ throw new UnsupportedOperationException("Not yet implemented"); // TODO Implement me
+ }
+
+ public int loadBranches(int startID, int endID, CDOBranchHandler branchHandler)
+ {
+ throw new UnsupportedOperationException("Not yet implemented"); // TODO Implement me
+ }
+
+ public void loadCommitInfos(CDOBranch branch, long startTime, long endTime, CDOCommitInfoHandler handler)
+ {
+ commits.loadCommitInfos(branch, startTime, endTime, handler);
+ }
+
+ public void writePackageUnits(InternalCDOPackageUnit[] packageUnits, OMMonitor monitor)
+ {
+ commits.writePackageUnits(this, packageUnits, monitor);
+ }
+
+ @Override
+ protected void doWrite(InternalCommitContext context, OMMonitor monitor)
+ {
+ commits.write(this, context, monitor);
+ }
+
+ @Override
+ protected void doCommit(OMMonitor monitor)
+ {
+ // Do nothing
+ }
+
+ @Override
+ protected void doRollback(CommitContext commitContext)
+ {
+ // Do nothing
+ }
+
+ @Override
+ protected CDOID getNextCDOID(CDORevision revision)
+ {
+ return getStore().getIDHandler().getNextCDOID(revision);
+ }
+}
diff --git a/plugins/org.eclipse.emf.cdo.server.mongodb/src/org/eclipse/emf/cdo/server/internal/mongodb/MongoDBStoreFactory.java b/plugins/org.eclipse.emf.cdo.server.mongodb/src/org/eclipse/emf/cdo/server/internal/mongodb/MongoDBStoreFactory.java
index b511870034..5e090dcd3d 100644
--- a/plugins/org.eclipse.emf.cdo.server.mongodb/src/org/eclipse/emf/cdo/server/internal/mongodb/MongoDBStoreFactory.java
+++ b/plugins/org.eclipse.emf.cdo.server.mongodb/src/org/eclipse/emf/cdo/server/internal/mongodb/MongoDBStoreFactory.java
@@ -1,90 +1,90 @@
-/*
- * Copyright (c) 2004 - 2012 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.server.IStore;
-import org.eclipse.emf.cdo.server.IStoreFactory;
-import org.eclipse.emf.cdo.server.mongodb.CDOMongoDBUtil;
-import org.eclipse.emf.cdo.spi.server.RepositoryConfigurator;
-
-import org.eclipse.net4j.util.StringUtil;
-import org.eclipse.net4j.util.WrappedException;
-
-import com.mongodb.DB;
-import com.mongodb.Mongo;
-import com.mongodb.MongoURI;
-
-import org.w3c.dom.Element;
-
-import java.util.Map;
-
-/**
- * @author Eike Stepper
- */
-public class MongoDBStoreFactory implements IStoreFactory
-{
- public MongoDBStoreFactory()
- {
- }
-
- public String getStoreType()
- {
- return MongoDBStore.TYPE;
- }
-
- public IStore createStore(String repositoryName, Map<String, String> repositoryProperties, Element storeConfig)
- {
- Map<String, String> properties = RepositoryConfigurator.getProperties(storeConfig, 1);
- String uri = properties.get("uri");
- if (StringUtil.isEmpty(uri))
- {
- throw new IllegalArgumentException("Property 'uri' missing");
- }
-
- MongoURI mongoURI = new MongoURI(uri);
- String dbName = properties.get("db");
- if (StringUtil.isEmpty(dbName))
- {
- dbName = repositoryName;
- }
-
- String drop = properties.get("drop");
- if (Boolean.toString(true).equals(drop))
- {
- dropDatabase(mongoURI, dbName);
- }
-
- return CDOMongoDBUtil.createStore(uri, dbName);
- }
-
- protected void dropDatabase(MongoURI mongoURI, String dbName)
- {
- Mongo mongo = null;
-
- try
- {
- mongo = new Mongo(mongoURI);
- DB db = mongo.getDB(dbName);
- db.dropDatabase();
- }
- catch (Exception ex)
- {
- throw WrappedException.wrap(ex);
- }
- finally
- {
- if (mongo != null)
- {
- mongo.close();
- }
- }
- }
-}
+/*
+ * Copyright (c) 2004 - 2012 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.server.IStore;
+import org.eclipse.emf.cdo.server.IStoreFactory;
+import org.eclipse.emf.cdo.server.mongodb.CDOMongoDBUtil;
+import org.eclipse.emf.cdo.spi.server.RepositoryConfigurator;
+
+import org.eclipse.net4j.util.StringUtil;
+import org.eclipse.net4j.util.WrappedException;
+
+import com.mongodb.DB;
+import com.mongodb.Mongo;
+import com.mongodb.MongoURI;
+
+import org.w3c.dom.Element;
+
+import java.util.Map;
+
+/**
+ * @author Eike Stepper
+ */
+public class MongoDBStoreFactory implements IStoreFactory
+{
+ public MongoDBStoreFactory()
+ {
+ }
+
+ public String getStoreType()
+ {
+ return MongoDBStore.TYPE;
+ }
+
+ public IStore createStore(String repositoryName, Map<String, String> repositoryProperties, Element storeConfig)
+ {
+ Map<String, String> properties = RepositoryConfigurator.getProperties(storeConfig, 1);
+ String uri = properties.get("uri");
+ if (StringUtil.isEmpty(uri))
+ {
+ throw new IllegalArgumentException("Property 'uri' missing");
+ }
+
+ MongoURI mongoURI = new MongoURI(uri);
+ String dbName = properties.get("db");
+ if (StringUtil.isEmpty(dbName))
+ {
+ dbName = repositoryName;
+ }
+
+ String drop = properties.get("drop");
+ if (Boolean.toString(true).equals(drop))
+ {
+ dropDatabase(mongoURI, dbName);
+ }
+
+ return CDOMongoDBUtil.createStore(uri, dbName);
+ }
+
+ protected void dropDatabase(MongoURI mongoURI, String dbName)
+ {
+ Mongo mongo = null;
+
+ try
+ {
+ mongo = new Mongo(mongoURI);
+ DB db = mongo.getDB(dbName);
+ db.dropDatabase();
+ }
+ catch (Exception ex)
+ {
+ throw WrappedException.wrap(ex);
+ }
+ finally
+ {
+ if (mongo != null)
+ {
+ mongo.close();
+ }
+ }
+ }
+}
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
index 015b4c8a3c..2f9d4f31f6 100644
--- 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
@@ -1,110 +1,110 @@
-/*
- * Copyright (c) 2004 - 2012 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.BasicDBList;
-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.save(doc);
-
- }
- }
-
- public void remove(Set<String> names)
- {
- BasicDBList list = new BasicDBList();
- for (String name : names)
- {
- list.add(name);
- }
-
- DBObject ref = new BasicDBObject();
- ref.put(ID, new BasicDBObject("$in", list));
-
- collection.remove(ref);
- }
-}
+/*
+ * Copyright (c) 2004 - 2012 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.BasicDBList;
+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.save(doc);
+
+ }
+ }
+
+ public void remove(Set<String> names)
+ {
+ BasicDBList list = new BasicDBList();
+ for (String name : names)
+ {
+ list.add(name);
+ }
+
+ DBObject ref = new BasicDBObject();
+ ref.put(ID, new BasicDBObject("$in", list));
+
+ collection.remove(ref);
+ }
+}
diff --git a/plugins/org.eclipse.emf.cdo.server.mongodb/src/org/eclipse/emf/cdo/server/internal/mongodb/bundle/OM.java b/plugins/org.eclipse.emf.cdo.server.mongodb/src/org/eclipse/emf/cdo/server/internal/mongodb/bundle/OM.java
index 1b0c7a0dff..fe79b7c385 100644
--- a/plugins/org.eclipse.emf.cdo.server.mongodb/src/org/eclipse/emf/cdo/server/internal/mongodb/bundle/OM.java
+++ b/plugins/org.eclipse.emf.cdo.server.mongodb/src/org/eclipse/emf/cdo/server/internal/mongodb/bundle/OM.java
@@ -1,45 +1,45 @@
-/*
- * Copyright (c) 2004 - 2012 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
- * Stefan Winkler - Bug 285426: [DB] Implement user-defined typeMapping support
- */
-package org.eclipse.emf.cdo.server.internal.mongodb.bundle;
-
-import org.eclipse.net4j.util.om.OMBundle;
-import org.eclipse.net4j.util.om.OMPlatform;
-import org.eclipse.net4j.util.om.OSGiActivator;
-import org.eclipse.net4j.util.om.log.OMLogger;
-import org.eclipse.net4j.util.om.trace.OMTracer;
-
-/**
- * The <em>Operations & Maintenance</em> class of this bundle.
- *
- * @author Eike Stepper
- */
-public abstract class OM
-{
- public static final String BUNDLE_ID = "org.eclipse.emf.cdo.server.mongodb"; //$NON-NLS-1$
-
- public static final OMBundle BUNDLE = OMPlatform.INSTANCE.bundle(BUNDLE_ID, OM.class);
-
- public static final OMTracer DEBUG = BUNDLE.tracer("debug"); //$NON-NLS-1$
-
- public static final OMLogger LOG = BUNDLE.logger();
-
- /**
- * @author Eike Stepper
- */
- public static final class Activator extends OSGiActivator
- {
- public Activator()
- {
- super(BUNDLE);
- }
- }
-}
+/*
+ * Copyright (c) 2004 - 2012 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
+ * Stefan Winkler - Bug 285426: [DB] Implement user-defined typeMapping support
+ */
+package org.eclipse.emf.cdo.server.internal.mongodb.bundle;
+
+import org.eclipse.net4j.util.om.OMBundle;
+import org.eclipse.net4j.util.om.OMPlatform;
+import org.eclipse.net4j.util.om.OSGiActivator;
+import org.eclipse.net4j.util.om.log.OMLogger;
+import org.eclipse.net4j.util.om.trace.OMTracer;
+
+/**
+ * The <em>Operations & Maintenance</em> class of this bundle.
+ *
+ * @author Eike Stepper
+ */
+public abstract class OM
+{
+ public static final String BUNDLE_ID = "org.eclipse.emf.cdo.server.mongodb"; //$NON-NLS-1$
+
+ public static final OMBundle BUNDLE = OMPlatform.INSTANCE.bundle(BUNDLE_ID, OM.class);
+
+ public static final OMTracer DEBUG = BUNDLE.tracer("debug"); //$NON-NLS-1$
+
+ public static final OMLogger LOG = BUNDLE.logger();
+
+ /**
+ * @author Eike Stepper
+ */
+ public static final class Activator extends OSGiActivator
+ {
+ public Activator()
+ {
+ super(BUNDLE);
+ }
+ }
+}
diff --git a/plugins/org.eclipse.emf.cdo.server.mongodb/src/org/eclipse/emf/cdo/server/mongodb/package-info.java b/plugins/org.eclipse.emf.cdo.server.mongodb/src/org/eclipse/emf/cdo/server/mongodb/package-info.java
index 5c6495164a..5286db33f7 100644
--- a/plugins/org.eclipse.emf.cdo.server.mongodb/src/org/eclipse/emf/cdo/server/mongodb/package-info.java
+++ b/plugins/org.eclipse.emf.cdo.server.mongodb/src/org/eclipse/emf/cdo/server/mongodb/package-info.java
@@ -1,15 +1,15 @@
-/*
- * Copyright (c) 2004 - 2012 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
- */
-
-/**
- * Server concepts for dealing with MongoDB stores and accessors.
- */
-package org.eclipse.emf.cdo.server.mongodb;
+/*
+ * Copyright (c) 2004 - 2012 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
+ */
+
+/**
+ * Server concepts for dealing with MongoDB stores and accessors.
+ */
+package org.eclipse.emf.cdo.server.mongodb;

Back to the top