Example usage for com.mongodb BasicDBObject getLong

List of usage examples for com.mongodb BasicDBObject getLong

Introduction

In this page you can find the example usage for com.mongodb BasicDBObject getLong.

Prototype

public long getLong(final String key) 

Source Link

Document

Returns the value of a field as a long .

Usage

From source file:rapture.sheet.mongodb.MongoCellStore.java

License:Open Source License

public List<RaptureSheetCell> findCellsByEpoch(final String sheetName, final int dimension,
        final long minEpochFilter) {

    MongoRetryWrapper<List<RaptureSheetCell>> wrapper = new MongoRetryWrapper<List<RaptureSheetCell>>() {

        public DBCursor makeCursor() {
            DBCollection collection = MongoDBFactory.getDB(instanceName).getCollection(tableName);
            BasicDBObject query = new BasicDBObject();
            query.put(KEY, sheetName);//w ww  . j a  v a2  s .  com
            query.put(DIM, dimension);
            return collection.find(query);
        }

        public List<RaptureSheetCell> action(DBCursor cursor) {
            List<RaptureSheetCell> ret = new ArrayList<RaptureSheetCell>();
            Long maxEpoch = 0L;

            while (cursor.hasNext()) {
                BasicDBObject val = (BasicDBObject) cursor.next();
                RaptureSheetCell cell = new RaptureSheetCell();
                cell.setColumn(val.getInt(COL));
                cell.setRow(val.getInt(ROW));
                cell.setData(val.getString(VALUE));
                boolean shouldAdd;
                if (val.containsField(EPOCH)) {
                    long currEpoch = val.getLong(EPOCH);
                    shouldAdd = (currEpoch > minEpochFilter);
                    cell.setEpoch(currEpoch);
                    if (maxEpoch < currEpoch) {
                        maxEpoch = currEpoch;
                    }
                } else {
                    shouldAdd = true;
                }

                if (shouldAdd)
                    ret.add(cell);
            }
            return ret;
        }
    };
    return wrapper.doAction();
}

From source file:rapture.sheet.mongodb.MongoCellStore.java

License:Open Source License

private Long getLatestEpoch(final String sheetName, final int dimension) {
    MongoRetryWrapper<Long> wrapper = new MongoRetryWrapper<Long>() {

        public DBCursor makeCursor() {
            BasicDBObject query = new BasicDBObject();
            query.put(KEY, sheetName);/*from  ww w. ja va2 s  . co  m*/
            query.put(DIM, dimension);
            BasicDBObject gt = new BasicDBObject();
            gt.put("$gt", knownEpoch);
            query.put(EPOCH, gt);
            DBCollection collection = MongoDBFactory.getDB(instanceName).getCollection(tableName);
            BasicDBObject vals = new BasicDBObject();
            vals.put(EPOCH, 1);
            return collection.find(query, vals);
        }

        public Long action(DBCursor cursor) {
            while (cursor.hasNext()) {
                BasicDBObject val = (BasicDBObject) cursor.next();
                long thisEpoch = val.getLong(EPOCH);
                if (thisEpoch > knownEpoch) {
                    knownEpoch = thisEpoch;
                    log.debug(String.format("Epoch for %s(%d) is %d", sheetName, dimension, knownEpoch));
                }
            }
            return knownEpoch;
        }
    };
    return wrapper.doAction();
}