List of usage examples for com.mongodb DBCursor close
@Override public void close()
From source file:net.scran24.datastore.mongodb.MongoDbDataStore.java
License:Apache License
@Override public List<SecureUserRecord> getUserRecords(String survey_id, String role) throws DataStoreException { DBCollection col = getUsersCollection(survey_id); DBObject q = new BasicDBObject(FIELD_ROLES, role); DBCursor cursor = col.find(q); try {/*w w w.j a v a2 s.com*/ ArrayList<SecureUserRecord> result = new ArrayList<SecureUserRecord>(); for (DBObject obj : cursor) result.add(parseUserRecord((BasicDBObject) obj)); return result; } catch (MongoException e) { throw new DataStoreException(e); } finally { cursor.close(); } }
From source file:net.scran24.datastore.mongodb.MongoDbDataStore.java
License:Apache License
@Override public Option<SecureUserRecord> getUserRecord(String survey_id, String username) throws DataStoreException { DBCollection col = getUsersCollection(survey_id); DBObject q = new BasicDBObject(FIELD_USERNAME, username); DBCursor result = col.find(q); try {/*from w w w. j a v a2 s .c om*/ if (result.size() == 0) return Option.none(); else { BasicDBObject userData = (BasicDBObject) result.next(); return Option.some(parseUserRecord(userData)); } } catch (MongoException e) { throw new DataStoreException(e); } finally { result.close(); } }
From source file:net.scran24.datastore.mongodb.MongoDbDataStore.java
License:Apache License
@Override public Map<String, Integer> getPopularityCount(Set<String> foodCodes) throws DataStoreException { DBCollection col = getPopularityCollection(); DBObject query = new BasicDBObject(FIELD_CODE, new BasicDBObject("$in", foodCodes)); Set<String> missing = new HashSet<String>(); missing.addAll(foodCodes);/*from w ww .java2s.c o m*/ DBCursor cursor = col.find(query); try { Map<String, Integer> result = new HashMap<String, Integer>(); for (DBObject o : cursor) { String code = (String) o.get(FIELD_CODE); Integer count = (Integer) o.get(FIELD_COUNT); missing.remove(code); result.put(code, count); } for (String code : missing) { result.put(code, 0); } return result; } catch (MongoException e) { throw new DataStoreException(e); } finally { cursor.close(); } }
From source file:net.scran24.datastore.mongodb.MongoDbDataStore.java
License:Apache License
@Override public void processMissingFoods(long timeFrom, long timeTo, Callback1<MissingFoodRecord> processMissingFood) throws DataStoreException { DBCollection col = getMissingFoodsCollection(); DBObject query = new BasicDBObject("submitted_at", new BasicDBObject("$gte", timeFrom).append("$lt", timeTo)); DBCursor cursor = col.find(query); try {/* w ww. ja va 2 s . c o m*/ for (DBObject o : cursor) { processMissingFood.call(deserialiser.deserializeMissingFood(o)); } } catch (MongoException e) { throw new DataStoreException(e); } finally { cursor.close(); } }
From source file:net.scran24.datastore.mongodb.MongoDbDataStore.java
License:Apache License
@Override public Option<Long> getLastHelpRequestTime(String survey, String username) throws DataStoreException { DBCollection col = getHelpRequestTimeCollection(); DBObject query = new BasicDBObject("user_id", survey + "/" + username); DBCursor cursor = col.find(query); try {//from www . j a v a2s .c o m if (!cursor.hasNext()) return Option.none(); else { DBObject obj = cursor.next(); return Option.some((long) obj.get("last_help_request_at")); } } catch (Throwable e) { throw new DataStoreException(e); } finally { cursor.close(); } }
From source file:net.scran24.datastore.mongodb.MongoDbDataStore.java
License:Apache License
public List<String> getSurveyNames() throws DataStoreException { DBCollection col = getSurveyStateCollection(); DBCursor cursor = col.find(); List<String> result = new ArrayList<String>(); try {//from w w w . j a v a 2s . co m while (cursor.hasNext()) { DBObject obj = cursor.next(); result.add((String) obj.get("surveyId")); } return result; } catch (Throwable e) { throw new DataStoreException(e); } finally { cursor.close(); } }
From source file:net.scran24.datastore.mongodb.MongoDbDataStore.java
License:Apache License
@Override public List<SecureUserRecord> getUserRecords(String survey_id) throws DataStoreException { DBCollection col = getUsersCollection(survey_id); DBCursor cursor = col.find(); try {//from w w w. j a v a 2 s . co m ArrayList<SecureUserRecord> result = new ArrayList<SecureUserRecord>(); for (DBObject obj : cursor) result.add(parseUserRecord((BasicDBObject) obj)); return result; } catch (MongoException e) { throw new DataStoreException(e); } finally { cursor.close(); } }
From source file:net.sf.okapi.lib.tmdb.mongodb.Repository.java
License:Open Source License
@Override public List<String> getTmNames() { tm_coll = repository.getCollection(Repository.TM_COLL); List<String> list = new ArrayList<String>(); DBCursor cur = tm_coll.find(); while (cur.hasNext()) { DBObject obj = cur.next();/* ww w . j a v a 2 s . c o m*/ list.add((String) obj.get(Repository.TM_COL_NAME)); } cur.close(); return list; }
From source file:net.tooan.ynpay.third.mongodb.fs.BuguFS.java
License:Apache License
private List<GridFSDBFile> toFileList(DBCursor cursor) { List<GridFSDBFile> list = new ArrayList<GridFSDBFile>(); while (cursor.hasNext()) { DBObject dbo = cursor.next();// w w w .ja v a 2 s .co m ObjectId id = (ObjectId) dbo.get(Operator.ID); DBObject query = new BasicDBObject(Operator.ID, id); GridFSDBFile f = this.findOne(query); list.add(f); } cursor.close(); return list; }
From source file:net.ymate.platform.persistence.mongodb.impl.MongoGridFSSession.java
License:Apache License
public List<GridFSDBFile> findAll(OrderBy orderBy, Page page) { DBCursor _cursor = __dbCollection.find(); if (orderBy != null) { _cursor.sort(orderBy.toBson());// w ww . j a v a 2 s . co m } if (page != null && page.page() > 0 && page.pageSize() > 0) { _cursor.skip((page.page() - 1) * page.pageSize()).limit(page.pageSize()); } List<GridFSDBFile> _results = new ArrayList<GridFSDBFile>(); while (_cursor.hasNext()) { _results.add((GridFSDBFile) _cursor.next()); } _cursor.close(); return _results; }