List of usage examples for com.mongodb DBCursor count
public int count()
From source file:com.janeluo.jfinalplus.plugin.monogodb.MongoKit.java
License:Apache License
public static Page<Record> paginate(String collection, int pageNumber, int pageSize, Map<String, Object> filter, Map<String, Object> like, Map<String, Object> sort) { DBCollection logs = MongoKit.getCollection(collection); BasicDBObject conditons = new BasicDBObject(); buildFilter(filter, conditons);//from www . j av a2s. c o m buildLike(like, conditons); DBCursor dbCursor = logs.find(conditons); page(pageNumber, pageSize, dbCursor); sort(sort, dbCursor); List<Record> records = new ArrayList<Record>(); while (dbCursor.hasNext()) { records.add(toRecord(dbCursor.next())); } int totalRow = dbCursor.count(); if (totalRow <= 0) { return new Page<Record>(new ArrayList<Record>(0), pageNumber, pageSize, 0, 0); } int totalPage = totalRow / pageSize; if (totalRow % pageSize != 0) { totalPage++; } Page<Record> page = new Page<Record>(records, pageNumber, pageSize, totalPage, totalRow); return page; }
From source file:com.jive.myco.seyren.mongo.MongoStore.java
License:Apache License
private void addTargetHashToAlerts() { LOGGER.info("Adding targetHash field to any alerts which don't have it"); DBCursor alerts = getAlertsCollection() .find(new BasicDBObject("targetHash", new BasicDBObject("$exists", false))); alerts.addOption(Bytes.QUERYOPTION_NOTIMEOUT); int alertCount = alerts.count(); if (alertCount > 0) { LOGGER.info("Found {} alert(s) which need updating", alertCount); }/*from w ww . j a va 2s .c o m*/ while (alerts.hasNext()) { DBObject alertObject = alerts.next(); Alert alert = mapper.alertFrom(alertObject); getAlertsCollection().save(mapper.alertToDBObject(alert)); } }
From source file:com.jive.myco.seyren.mongo.MongoStore.java
License:Apache License
@Override public SeyrenResponse<Check> getChecks(Boolean enabled, Boolean live) { List<Check> checks = new ArrayList<Check>(); DBObject query = new BasicDBObject(); if (enabled != null) { query.put("enabled", enabled); }// ww w .j a v a 2s.c o m if (live != null) { query.put("live", live); } DBCursor dbc = getChecksCollection().find(query); while (dbc.hasNext()) { checks.add(mapper.checkFrom(dbc.next())); } return new SeyrenResponse<Check>().withValues(checks).withTotal(dbc.count()); }
From source file:com.jive.myco.seyren.mongo.MongoStore.java
License:Apache License
@Override public SeyrenResponse<Check> getChecksByState(Set<String> states, Boolean enabled) { List<Check> checks = new ArrayList<Check>(); DBObject query = new BasicDBObject(); query.put("state", NiceDBObject.object("$in", states.toArray())); if (enabled != null) { query.put("enabled", enabled); }/*from w w w . jav a 2 s .co m*/ DBCursor dbc = getChecksCollection().find(query); while (dbc.hasNext()) { checks.add(mapper.checkFrom(dbc.next())); } dbc.close(); return new SeyrenResponse<Check>().withValues(checks).withTotal(dbc.count()); }
From source file:com.jive.myco.seyren.mongo.MongoStore.java
License:Apache License
@Override public SeyrenResponse<Alert> getAlerts(String checkId, int start, int items) { DBCursor dbc = getAlertsCollection().find(NiceDBObject.object("checkId", checkId)).sort(NiceDBObject .object("timestamp", -1)).skip(start).limit(items); List<Alert> alerts = new ArrayList<Alert>(); while (dbc.hasNext()) { alerts.add(mapper.alertFrom(dbc.next())); }//from w ww . j a va2 s.c o m dbc.close(); return new SeyrenResponse<Alert>().withValues(alerts).withItems(items).withStart(start) .withTotal(dbc.count()); }
From source file:com.jive.myco.seyren.mongo.MongoStore.java
License:Apache License
@Override public SeyrenResponse<Alert> getAlerts(int start, int items) { DBCursor dbc = getAlertsCollection().find().sort(NiceDBObject.object("timestamp", -1)).skip(start) .limit(items);/*from ww w. j a va 2s . c o m*/ List<Alert> alerts = new ArrayList<Alert>(); while (dbc.hasNext()) { alerts.add(mapper.alertFrom(dbc.next())); } dbc.close(); return new SeyrenResponse<Alert>().withValues(alerts).withItems(items).withStart(start) .withTotal(dbc.count()); }
From source file:com.liferay.mongodb.hook.service.impl.MongoExpandoValueLocalServiceImpl.java
License:Open Source License
@Override public int getColumnValuesCount(long companyId, long classNameId, String tableName, String columnName, String data) {/*from ww w. j ava 2 s. c om*/ try { ExpandoColumn expandoColumn = ExpandoColumnLocalServiceUtil.getColumn(companyId, classNameId, tableName, columnName); DBCollection dbCollection = MongoDBUtil.getCollection(companyId, classNameId, tableName); DBCursor dbCursor = null; if (Validator.isNotNull(data)) { DBObject queryDBObject = new BasicDBObject(); ExpandoValue expandoValue = ExpandoValueUtil.create(0); expandoValue.setColumnId(expandoColumn.getColumnId()); expandoValue.setData(data); queryDBObject.put(columnName, getData(expandoColumn, expandoValue)); dbCursor = dbCollection.find(queryDBObject); } else { dbCursor = dbCollection.find(); } return dbCursor.count(); } catch (PortalException pe) { throw new SystemException(pe); } }
From source file:com.linuxbox.enkive.statistics.gathering.mongodb.MongoGathererMessageSearchService.java
License:Open Source License
@Override public int getNumberOfMessages(Date startDate, Date endDate) throws MessageSearchException { String dateEarliest = new StringBuilder(SIMPLE_DATE.format(startDate)).toString(); String dateLatest = new StringBuilder(SIMPLE_DATE.format(endDate)).toString(); HashMap<String, String> fields = new HashMap<String, String>(); fields.put(DATE_EARLIEST_PARAMETER, dateEarliest); fields.put(DATE_LATEST_PARAMETER, dateLatest); fields.put(DATE_TYPE, ARCHIVE_TIME); try {/*from w w w. j a v a 2 s. co m*/ final DBObject query = buildQueryObject(fields); final DBCursor results = messageColl.find(query, ID_ONLY_QUERY); final int numOfMessages = results.count(); results.close(); return numOfMessages; } catch (EmptySearchResultsException e) { return 0; } }
From source file:com.linuxbox.enkive.statistics.gathering.mongodb.MongoStatsAttachmentsGatherer.java
License:Open Source License
@Override protected Map<String, Object> getIntervalStatistics(Date startTimestamp, Date endTimestamp) throws GathererException { Map<String, Object> intervalMap = createMap(); Map<String, Object> query = createMap(); Map<String, Object> innerQuery = createMap(); innerQuery.put("$gte", startTimestamp); innerQuery.put("$lt", endTimestamp); query.put(MONGO_UPLOAD_DATE, innerQuery); long dataByteSz = 0; DBCursor dataCursor = attachmentsColl.find(new BasicDBObject(query)); for (DBObject obj : dataCursor) { dataByteSz += (Long) (obj.get(MONGO_LENGTH)); }/*from w w w.ja v a2 s.c om*/ Map<String, Object> innerNumAttach = createMap(); innerNumAttach.put(CONSOLIDATION_AVG, dataCursor.count()); long avgAttSz = 0; if (dataCursor.count() != 0) { avgAttSz = dataByteSz / dataCursor.count(); } intervalMap.put(STAT_ATTACH_SIZE, avgAttSz); intervalMap.put(STAT_ATTACH_NUM, dataCursor.count()); return intervalMap; }
From source file:com.linuxbox.enkive.statistics.gathering.mongodb.MongoStatsFileAttachmentsGatherer.java
License:Open Source License
@Override protected Map<String, Object> getIntervalStatistics(Date startTimestamp, Date endTimestamp) throws GathererException { Map<String, Object> intervalMap = createMap(); Map<String, Object> query = createMap(); Map<String, Object> innerQuery = createMap(); innerQuery.put("$gte", startTimestamp); innerQuery.put("$lt", endTimestamp); query.put(FILE_CDATE, innerQuery);//from w w w .j ava2s . c o m long dataByteSz = 0; DBCursor dataCursor = attachmentsColl.find(new BasicDBObject(query)); for (DBObject obj : dataCursor) { dataByteSz += ((Integer) obj.get(FILE_SIZE)).longValue(); } Map<String, Object> innerNumAttach = createMap(); innerNumAttach.put(CONSOLIDATION_AVG, dataCursor.count()); long avgAttSz = 0; if (dataCursor.count() != 0) { avgAttSz = dataByteSz / dataCursor.count(); } intervalMap.put(STAT_ATTACH_SIZE, avgAttSz); intervalMap.put(STAT_ATTACH_NUM, dataCursor.count()); return intervalMap; }