List of usage examples for com.mongodb DBCursor close
@Override public void close()
From source file:org.alfresco.bm.event.mongo.MongoEventService.java
License:Open Source License
@Override public List<Event> getEvents(int skip, int limit) { DBCursor cursor = collection.find().skip(skip).limit(limit); List<Event> events = new ArrayList<Event>(limit); while (cursor.hasNext()) { DBObject eventObj = cursor.next(); Event event = convertDBObject(eventObj); events.add(event);/*from www . j a va2 s . c om*/ } cursor.close(); // Done if (logger.isDebugEnabled()) { logger.debug("Fetched " + events.size() + "events."); } return events; }
From source file:org.alfresco.bm.event.mongo.MongoResultService.java
License:Open Source License
@Override public List<EventRecord> getResults(String eventName, int skip, int limit) { DBObject queryObj = QueryBuilder.start().get(); if (eventName != null) { queryObj.put(EventRecord.FIELD_EVENT_NAME, eventName); }/*from w w w. j av a2 s . c o m*/ DBObject sortObj = BasicDBObjectBuilder.start().add(EventRecord.FIELD_START_TIME, Integer.valueOf(1)).get(); DBCursor cursor = collection.find(queryObj); cursor.sort(sortObj); cursor.skip(skip); cursor.limit(limit); // Get all the results and convert them int size = cursor.size(); List<EventRecord> results = new ArrayList<EventRecord>(size); try { while (cursor.hasNext()) { DBObject obj = cursor.next(); EventRecord eventRecord = convertToEventRecord(obj); results.add(eventRecord); } } finally { cursor.close(); } // Done if (logger.isDebugEnabled()) { logger.debug( "\n" + "Found results: \n" + " Query: " + queryObj + "\n" + " Skip: " + skip + "\n" + " Limit: " + limit + "\n" + " Results: " + size); } return results; }
From source file:org.alfresco.bm.event.mongo.MongoResultService.java
License:Open Source License
@Override public List<EventRecord> getResults(long startTime, long endTime, boolean chartOnly, int skip, int limit) { QueryBuilder queryBuilder = QueryBuilder.start().and(EventRecord.FIELD_START_TIME) .greaterThanEquals(new Date(startTime)).and(EventRecord.FIELD_START_TIME) .lessThan(new Date(endTime)); if (chartOnly) { queryBuilder.and(EventRecord.FIELD_CHART).is(true); }/* w ww . j av a 2 s . co m*/ DBObject queryObj = queryBuilder.get(); DBObject sortObj = BasicDBObjectBuilder.start().add(EventRecord.FIELD_START_TIME, Integer.valueOf(1)).get(); DBCursor cursor = collection.find(queryObj); cursor.sort(sortObj); cursor.skip(skip); cursor.limit(limit); // Get all the results and convert them int size = cursor.size(); List<EventRecord> results = new ArrayList<EventRecord>(size); try { while (cursor.hasNext()) { DBObject obj = cursor.next(); EventRecord eventRecord = convertToEventRecord(obj); results.add(eventRecord); } } finally { cursor.close(); } // Done if (logger.isDebugEnabled()) { logger.debug( "\n" + "Found results: \n" + " Query: " + queryObj + "\n" + " Skip: " + skip + "\n" + " Limit: " + limit + "\n" + " Results: " + size); } return results; }
From source file:org.alfresco.bm.event.mongo.MongoResultService.java
License:Open Source License
@Override public List<EventDetails> getEventDetails(EventResultFilter filter, String filterEventName, int skip, int limit) { QueryBuilder queryBuilder = QueryBuilder.start(); // apply filter switch (filter) { case Failed://from ww w .j a va2 s.c om queryBuilder.and(EventRecord.FIELD_SUCCESS).is(false); break; case Success: queryBuilder.and(EventRecord.FIELD_SUCCESS).is(true); break; default: break; } //apply event name filter if (null != filterEventName && !filterEventName.isEmpty()) { queryBuilder.and(EventRecord.FIELD_EVENT_NAME).is(filterEventName); } DBObject queryObj = queryBuilder.get(); // sort descending to get the newest values first DBObject sortObj = BasicDBObjectBuilder.start().add(EventRecord.FIELD_START_TIME, Integer.valueOf(-1)) .get(); DBCursor cursor = collection.find(queryObj); cursor.sort(sortObj); cursor.skip(skip); cursor.limit(limit); // Get all the results and convert them int size = cursor.size(); List<EventDetails> results = new ArrayList<EventDetails>(size); try { while (cursor.hasNext()) { DBObject obj = cursor.next(); EventDetails eventDetails = convertToEventDetails(obj); results.add(eventDetails); } } finally { cursor.close(); } return results; }
From source file:org.alfresco.bm.test.mongo.MongoTestDAO.java
License:Open Source License
/** * Get the test run names associated with a given test * /*from w w w . j av a2 s. c om*/ * @param test * the name of the test * @return the names of all test runs associated with the given test */ public List<String> getTestRunNames(String test) { DBObject testObj = getTest(test, false); if (testObj == null) { // The test no longer exists, so the run effectively doesn't either logger.warn("Test not found: " + test); return Collections.emptyList(); } ObjectId testObjId = (ObjectId) testObj.get(FIELD_ID); DBObject queryObj = QueryBuilder.start().and(FIELD_TEST).is(testObjId).get(); DBObject fieldsObj = BasicDBObjectBuilder.start().add(FIELD_ID, true).add(FIELD_NAME, true).get(); DBCursor cursor = testRuns.find(queryObj, fieldsObj); List<String> testRunNames = new ArrayList<String>(cursor.count()); try { while (cursor.hasNext()) { DBObject testRunObj = cursor.next(); String testRunName = (String) testRunObj.get(FIELD_NAME); testRunNames.add(testRunName); } } finally { cursor.close(); } // Done if (logger.isDebugEnabled()) { logger.debug("Found and returned " + testRunNames.size() + " test run names for test '" + test + "'"); } return testRunNames; }
From source file:org.alfresco.bm.user.UserDataServiceImpl.java
License:Open Source License
/** * Turn a cursor into an array of API-friendly objects *//*from w w w . ja v a2 s. c o m*/ protected List<UserData> fromDBCursor(DBCursor cursor) { int count = cursor.count(); try { List<UserData> userDatas = new ArrayList<UserData>(count); while (cursor.hasNext()) { DBObject userDataObj = cursor.next(); UserData userData = fromDBObject(userDataObj); userDatas.add(userData); } // Done return userDatas; } finally { cursor.close(); } }
From source file:org.alfresco.repo.domain.node.mongo.MongoNodeDAO.java
License:Open Source License
private NodeEntity getLatest(long nodeId) { NodeEntity nodeEntity = null;/*from ww w.jav a2 s . c o m*/ DBObject query = QueryBuilder.start("n").is(nodeId).and("c").is(true).get(); DBObject order = BasicDBObjectBuilder.start("v", -1).get(); DBCursor cursor = nodes.find(query).sort(order).limit(1); try { if (cursor.hasNext()) { DBObject dbObject = cursor.next(); nodeEntity = toNodeEntity(dbObject); } } finally { cursor.close(); } return nodeEntity; }
From source file:org.alfresco.repo.domain.node.mongo.MongoNodeDAO.java
License:Open Source License
@Override public NodeEntity getByVersionLabel(long nodeId, String versionLabel) { NodeEntity nodeEntity = null;/*from w w w . j av a2 s .c o m*/ DBObject query = QueryBuilder.start("n").is(nodeId).and("vl").is(versionLabel).and("c").is(true).get(); DBObject orderBy = BasicDBObjectBuilder.start("v", -1).get(); DBCursor cursor = nodes.find(query).sort(orderBy).limit(1); try { int size = cursor.size(); if (size > 1) { throw new RuntimeException(); } else if (size == 1) { DBObject dbObject = cursor.next(); nodeEntity = toNodeEntity(dbObject); } } finally { cursor.close(); } return nodeEntity; }
From source file:org.alfresco.semantics.MongoSemantics.java
License:Open Source License
public List<Relation> relationsFrom(String fromId, Set<String> categories, int skip, int maxItems) { List<Relation> ret = new LinkedList<>(); QueryBuilder queryBuilder = QueryBuilder.start("f").is(fromId); if (categories != null && categories.size() > 0) { queryBuilder.and("c").in(categories); }//from www . ja va 2 s.c o m DBObject query = queryBuilder.get(); BasicDBObjectBuilder orderByBuilder = BasicDBObjectBuilder.start("t", 1).add("w", 1); DBObject orderBy = orderByBuilder.get(); DBCursor cursor = relations.find(query).sort(orderBy).skip(skip).limit(maxItems); try { for (DBObject dbObject : cursor) { String toId = (String) dbObject.get("t"); double weight = (Double) dbObject.get("w"); Relation r = new Relation(fromId, toId, weight); ret.add(r); } } finally { if (cursor != null) { cursor.close(); } } return ret; }
From source file:org.alfresco.semantics.MongoSemantics.java
License:Open Source License
public List<Relation> relationsTo(String toId, Set<String> categories, int skip, int maxItems) { List<Relation> ret = new LinkedList<>(); QueryBuilder queryBuilder = QueryBuilder.start("t").is(toId); if (categories != null && categories.size() > 0) { queryBuilder.and("c").in(categories); }//from w ww . j a va2s . co m DBObject query = queryBuilder.get(); BasicDBObjectBuilder orderByBuilder = BasicDBObjectBuilder.start("f", 1).add("w", 1); DBObject orderBy = orderByBuilder.get(); DBCursor cursor = relations.find(query).sort(orderBy).skip(skip).limit(maxItems); try { for (DBObject dbObject : cursor) { String fromId = (String) dbObject.get("f"); double weight = (Double) dbObject.get("w"); Relation r = new Relation(fromId, toId, weight); ret.add(r); } } finally { if (cursor != null) { cursor.close(); } } return ret; }