Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEike Stepper2011-02-21 19:51:52 +0000
committerEike Stepper2011-02-21 19:51:52 +0000
commit6ee64c3c5e3cbb57fbfd890249244611ab256df1 (patch)
tree64ab7a9b1d398743e8d85492648b71250d22b59b /plugins/org.eclipse.emf.cdo.server.mongodb
parent069515f7f8154a59f225d563881e5f18dd1d8225 (diff)
downloadcdo-6ee64c3c5e3cbb57fbfd890249244611ab256df1.tar.gz
cdo-6ee64c3c5e3cbb57fbfd890249244611ab256df1.tar.xz
cdo-6ee64c3c5e3cbb57fbfd890249244611ab256df1.zip
[337152] [Mongo] Create a MongoDBStore
https://bugs.eclipse.org/bugs/show_bug.cgi?id=337152
Diffstat (limited to 'plugins/org.eclipse.emf.cdo.server.mongodb')
-rw-r--r--plugins/org.eclipse.emf.cdo.server.mongodb/plugin.xml9
-rw-r--r--plugins/org.eclipse.emf.cdo.server.mongodb/src/org/eclipse/emf/cdo/server/internal/mongodb/Classes.java59
-rw-r--r--plugins/org.eclipse.emf.cdo.server.mongodb/src/org/eclipse/emf/cdo/server/internal/mongodb/Commits.java103
-rw-r--r--plugins/org.eclipse.emf.cdo.server.mongodb/src/org/eclipse/emf/cdo/server/internal/mongodb/MongoDBBrowserPage.java4
-rw-r--r--plugins/org.eclipse.emf.cdo.server.mongodb/src/org/eclipse/emf/cdo/server/internal/mongodb/MongoDBStore.java420
-rw-r--r--plugins/org.eclipse.emf.cdo.server.mongodb/src/org/eclipse/emf/cdo/server/internal/mongodb/MongoDBStoreAccessor.java26
-rw-r--r--plugins/org.eclipse.emf.cdo.server.mongodb/src/org/eclipse/emf/cdo/server/internal/mongodb/MongoDBStoreFactory.java61
7 files changed, 412 insertions, 270 deletions
diff --git a/plugins/org.eclipse.emf.cdo.server.mongodb/plugin.xml b/plugins/org.eclipse.emf.cdo.server.mongodb/plugin.xml
index d980c26f32..858d1961e6 100644
--- a/plugins/org.eclipse.emf.cdo.server.mongodb/plugin.xml
+++ b/plugins/org.eclipse.emf.cdo.server.mongodb/plugin.xml
@@ -14,6 +14,15 @@
<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"
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 93796b1674..0ef66c5ae2 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
@@ -29,46 +29,65 @@ public class Classes
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;
- private int lastClassifierID;
+ public Classes(MongoDBStore store)
+ {
+ this.store = store;
+ }
- public Classes()
+ public MongoDBStore getStore()
{
+ return store;
}
- public int getResourceNodeClassID()
+ public int getLastClassifierID()
{
- return resourceNodeClassID;
+ return lastClassifierID;
}
- public int getResourceFolderClassID()
+ public void setLastClassifierID(int lastClassifierID)
{
- return resourceFolderClassID;
+ this.lastClassifierID = lastClassifierID;
}
- public int getResourceClassID()
+ public synchronized int getResourceNodeClassID()
{
- return resourceClassID;
+ initialize();
+ return resourceNodeClassID;
}
- public int getLastClassifierID()
+ public synchronized int getResourceFolderClassID()
{
- return lastClassifierID;
+ initialize();
+ return resourceFolderClassID;
}
- public void setLastClassifierID(int lastClassifierID)
+ public synchronized int getResourceClassID()
{
- this.lastClassifierID = lastClassifierID;
+ 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);
@@ -84,22 +103,32 @@ public class Classes
{
resourceClassID = id;
}
-
- return 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)idToClassifiers.get(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/Commits.java b/plugins/org.eclipse.emf.cdo.server.mongodb/src/org/eclipse/emf/cdo/server/internal/mongodb/Commits.java
index 8236469e61..b6b148353c 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
@@ -18,6 +18,7 @@ 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;
@@ -51,6 +52,7 @@ 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;
@@ -60,6 +62,7 @@ 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;
/**
@@ -115,6 +118,8 @@ public class Commits extends Coll
private static final boolean ZIP_PACKAGE_BYTES = true;
+ private InternalCDOPackageRegistry packageRegistry;
+
private IDHandler idHandler;
private InternalCDOPackageUnit[] systemPackageUnits;
@@ -140,6 +145,7 @@ public class Commits extends Coll
ensureIndex(REVISIONS, REVISIONS_ID, REVISIONS_VERSION);
}
+ packageRegistry = store.getRepository().getPackageRegistry();
idHandler = store.getIDHandler();
}
@@ -257,11 +263,77 @@ public class Commits extends Coll
{
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
@@ -473,11 +545,7 @@ public class Commits extends Coll
addToQuery(query, context);
query.put(REVISIONS + "." + REVISIONS_CONTAINER, idHandler.toValue(folderID));
- if (name == null)
- {
- query.put(REVISIONS + "." + "name", new BasicDBObject("$exists", false));
- }
- else if (exactMatch)
+ if (name == null || exactMatch)
{
query.put(REVISIONS + "." + "name", name);
}
@@ -509,35 +577,20 @@ public class Commits extends Coll
return null;
}
- if (name == null)
+ String revisionName = (String)embedded.get("name");
+ if (name == null || exactMatch)
{
- if (embedded.containsField("name"))
+ if (!ObjectUtil.equals(revisionName, name))
{
return null;
}
}
else
{
- String revisionName = (String)embedded.get("name");
- if (revisionName == null)
+ if (!revisionName.startsWith(name))
{
return null;
}
-
- if (exactMatch)
- {
- if (!revisionName.equals(name))
- {
- return null;
- }
- }
- else
- {
- if (!revisionName.startsWith(name))
- {
- return null;
- }
- }
}
CDOID id = idHandler.read(embedded, REVISIONS_ID);
diff --git a/plugins/org.eclipse.emf.cdo.server.mongodb/src/org/eclipse/emf/cdo/server/internal/mongodb/MongoDBBrowserPage.java b/plugins/org.eclipse.emf.cdo.server.mongodb/src/org/eclipse/emf/cdo/server/internal/mongodb/MongoDBBrowserPage.java
index 6bd3a5ce4f..04790ac8d6 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
@@ -22,11 +22,11 @@ import java.util.Set;
*/
public class MongoDBBrowserPage extends AbstractPage
{
- private static final boolean SHOW_INDEXES = false;
+ private static final boolean SHOW_INDEXES = true;
private static final boolean SHOW_DOCUMENTS = true;
- private static final boolean SHOW_INITIAL_COMMIT = false;
+ private static final boolean SHOW_INITIAL_COMMIT = true;
public 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 6936c01910..78c3e8416e 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
@@ -30,6 +30,7 @@ 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;
@@ -69,14 +70,15 @@ public class MongoDBStore extends Store implements IMongoDBStore, //
{
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 IDHandler idHandler = new IDHandler.LongValue(this);
-
private DB db;
private Props props;
@@ -105,6 +107,212 @@ public class MongoDBStore extends Store implements IMongoDBStore, //
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;
@@ -127,17 +335,6 @@ public class MongoDBStore extends Store implements IMongoDBStore, //
this.dbName = dbName;
}
- public IDHandler getIDHandler()
- {
- return idHandler;
- }
-
- public void setIDHandler(IDHandler idHandler)
- {
- checkInactive();
- this.idHandler = idHandler;
- }
-
public DB getDB()
{
return db;
@@ -275,7 +472,7 @@ public class MongoDBStore extends Store implements IMongoDBStore, //
props = new Props(this);
commits = new Commits(this);
- classes = new Classes();
+ classes = new Classes(this);
LifecycleUtil.activate(idHandler);
setObjectIDTypes(idHandler.getObjectIDTypes());
@@ -321,201 +518,6 @@ public class MongoDBStore extends Store implements IMongoDBStore, //
super.doDeactivate();
}
- 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;
- }
-
protected void firstStart()
{
setCreationTime(getRepository().getTimeStamp());
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 ea817c6e61..67aebfaf20 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
@@ -51,14 +51,18 @@ import java.util.Set;
*/
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
@@ -75,24 +79,24 @@ public class MongoDBStoreAccessor extends StoreAccessorBase implements IMongoDBS
public Collection<InternalCDOPackageUnit> readPackageUnits()
{
- return getStore().getCommits().readPackageUnits();
+ return commits.readPackageUnits();
}
public EPackage[] loadPackageUnit(InternalCDOPackageUnit packageUnit)
{
- throw new UnsupportedOperationException("Not yet implemented"); // TODO Implement me
+ return commits.loadPackageUnit(packageUnit);
}
public InternalCDORevision readRevision(CDOID id, CDOBranchPoint branchPoint, int listChunk,
CDORevisionCacheAdder cache)
{
- return getStore().getCommits().readRevision(id, branchPoint, listChunk, cache);
+ return commits.readRevision(id, branchPoint, listChunk, cache);
}
public InternalCDORevision readRevisionByVersion(CDOID id, CDOBranchVersion branchVersion, int listChunk,
CDORevisionCacheAdder cache)
{
- return getStore().getCommits().readRevisionByVersion(id, branchVersion, listChunk, cache);
+ return commits.readRevisionByVersion(id, branchVersion, listChunk, cache);
}
public void handleRevisions(EClass eClass, CDOBranch branch, long timeStamp, boolean exactTime,
@@ -108,13 +112,7 @@ public class MongoDBStoreAccessor extends StoreAccessorBase implements IMongoDBS
public void queryResources(QueryResourcesContext context)
{
- // // Only support timestamp in audit mode
- // if (context.getTimeStamp() != CDORevision.UNSPECIFIED_DATE && !getStore().getRepository().isSupportingAudits())
- // {
- // throw new IllegalArgumentException("Auditing not supported");
- // }
-
- getStore().getCommits().queryResources(context);
+ commits.queryResources(context);
}
public void queryXRefs(QueryXRefsContext context)
@@ -164,18 +162,18 @@ public class MongoDBStoreAccessor extends StoreAccessorBase implements IMongoDBS
public void loadCommitInfos(CDOBranch branch, long startTime, long endTime, CDOCommitInfoHandler handler)
{
- getStore().getCommits().loadCommitInfos(branch, startTime, endTime, handler);
+ commits.loadCommitInfos(branch, startTime, endTime, handler);
}
public void writePackageUnits(InternalCDOPackageUnit[] packageUnits, OMMonitor monitor)
{
- getStore().getCommits().writePackageUnits(this, packageUnits, monitor);
+ commits.writePackageUnits(this, packageUnits, monitor);
}
@Override
protected void doWrite(InternalCommitContext context, OMMonitor monitor)
{
- getStore().getCommits().write(this, context, monitor);
+ commits.write(this, context, monitor);
}
@Override
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 ef8e0b2fa9..e26cd06d01 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
@@ -12,29 +12,80 @@ 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.InternalRepository;
+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 static final String TYPE = "mongodb";
-
public MongoDBStoreFactory()
{
}
public String getStoreType()
{
- return TYPE;
+ return MongoDBStore.TYPE;
}
public IStore createStore(InternalRepository repository, Element storeConfig)
{
- // TODO: implement MongoDBStoreFactory.createStore(repository, storeConfig)
- throw new UnsupportedOperationException();
+ 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 = repository.getName();
+ }
+
+ String drop = properties.get("drop");
+ if (Boolean.toString(true).equals(drop))
+ {
+ dropDatabase(mongoURI, dbName);
+ }
+
+ return CDOMongoDBUtil.createStore(mongoURI, 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();
+ }
+ }
}
}

Back to the top