diff options
Diffstat (limited to 'plugins/org.eclipse.emf.cdo.server.mongodb/src/org/eclipse/emf/cdo/server/internal/mongodb/Coll.java')
-rw-r--r-- | plugins/org.eclipse.emf.cdo.server.mongodb/src/org/eclipse/emf/cdo/server/internal/mongodb/Coll.java | 228 |
1 files changed, 114 insertions, 114 deletions
diff --git a/plugins/org.eclipse.emf.cdo.server.mongodb/src/org/eclipse/emf/cdo/server/internal/mongodb/Coll.java b/plugins/org.eclipse.emf.cdo.server.mongodb/src/org/eclipse/emf/cdo/server/internal/mongodb/Coll.java 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); + } +} |