Example usage for com.mongodb DBCursor next

List of usage examples for com.mongodb DBCursor next

Introduction

In this page you can find the example usage for com.mongodb DBCursor next.

Prototype

@Override
public DBObject next() 

Source Link

Document

Returns the object the cursor is at and moves the cursor ahead by one.

Usage

From source file:com.card.loop.xyz.dao.LearningElementDAO.java

public ArrayList<DBObject> listAll(String collection) throws UnknownHostException {
    ArrayList<DBObject> list = new ArrayList<DBObject>();
    Mongo mongo = new Mongo(AppConfig.mongodb_host, AppConfig.mongodb_port);
    DB db = mongo.getDB(AppConfig.DATABASE_LOOP);
    GridFS le_gfs = new GridFS(db, collection);
    DBCursor cursor = le_gfs.getFileList();
    System.out.println(le_gfs.getFileList() + "");
    while (cursor.hasNext()) {
        list.add(cursor.next());
    }/*from w ww  .j  ava2 s.c  o  m*/
    return list;
}

From source file:com.ccoe.build.alerts.connector.Connector.java

License:Apache License

public static DBObject getLastRecord(DBCollection collection, Date startDate, Date endDate) {
    DBObject lastone = null;/*from   w w w . j  a v  a  2  s  .c o  m*/
    try {
        BasicDBObject searchQuery = new BasicDBObject();
        QueryBuilder qb = new QueryBuilder();
        qb.put("Date").greaterThanEquals(startDate).lessThanEquals(endDate);
        searchQuery.putAll(qb.get());
        DBCursor cursor = collection.find(searchQuery);

        while (cursor.hasNext()) {

            lastone = cursor.next();
        }

    } catch (MongoException e) {
        e.printStackTrace();

    }
    return lastone;
}

From source file:com.ccoe.build.alerts.connector.Connector.java

License:Apache License

public static double getMovingAverage(DBCollection collection, String field, Date startDate, Date endDate) {
    double weekSum = 0;
    DBObject record = null;/*from   w  w  w  .j  ava  2s.  co m*/
    int count = 0;
    try {
        BasicDBObject searchQuery = new BasicDBObject();
        QueryBuilder qb = new QueryBuilder();
        qb.put("Date").greaterThanEquals(startDate).lessThanEquals(endDate);
        searchQuery.putAll(qb.get());
        DBCursor cursor = collection.find(searchQuery);

        while (cursor.hasNext()) {
            record = cursor.next();
            DBObject dbo = (DBObject) record.get("Data");
            Set<String> keySet = dbo.keySet();

            for (String keyName : keySet) {
                if (field.equals(keyName)) {
                    count++;
                    Object keyValue = dbo.get(keyName);
                    double keyValueNum = 0;
                    if (keyValue instanceof Integer) {
                        int intValue = (Integer) keyValue;
                        keyValueNum = Double.parseDouble("" + intValue);
                    } else if (keyValue instanceof Double) {
                        keyValueNum = (Double) keyValue;
                    }
                    weekSum += keyValueNum;
                }
            }
        }
    } catch (MongoException e) {
        e.printStackTrace();
    }
    DAYS = count;
    return weekSum * 1.0 / count;
}

From source file:com.cedac.security.acls.mongo.MongoAclService.java

License:Apache License

@Override
public List<ObjectIdentity> findChildren(ObjectIdentity parentIdentity) {
    LOG.debug(ACL, "Looking for children of object identity {}", parentIdentity);

    DBObject query = queryByParentIdentity(parentIdentity);
    DBObject projection = new BasicDBObject(objectIdFieldName, true);
    DBCursor cursor = null;
    try {//from  w w  w.  j a  va2 s  .  c om
        cursor = getAclCollection().find(query, projection);
        if (cursor.count() == 0) {
            LOG.debug(ACL, "No child object found for identity {}", parentIdentity);

            return null;
        }

        LOG.trace(ACL, "Streaming cursor in order to retrieve child object identities");

        List<ObjectIdentity> oids = new ArrayList<ObjectIdentity>();
        while (cursor.hasNext()) {
            oids.add(toObjectIdentity((DBObject) cursor.next().get(objectIdFieldName)));
        }
        return oids;
    } finally {
        if (cursor != null) {
            cursor.close();
        }
    }
}

From source file:com.cedac.security.oauth2.provider.approval.MongoApprovalStore.java

License:Apache License

@Override
public List<Approval> getApprovals(String userName, String clientId) {
    BasicDBObject query = new BasicDBObject(userIdFieldName, userName).append(clientIdFieldName, clientId);
    DBCursor cursor = null;
    try {/*  ww w .j a v a  2 s .com*/
        List<Approval> approvals = new ArrayList<Approval>();
        cursor = getApprovalsCollection().find(query);
        while (cursor.hasNext()) {
            DBObject dbo = cursor.next();
            approvals.add(new Approval((String) dbo.get(userIdFieldName), (String) dbo.get(clientIdFieldName),
                    (String) dbo.get(scopeFieldName), (Date) dbo.get(expiresAtFieldName),
                    Approval.ApprovalStatus.valueOf((String) dbo.get(statusFieldName)),
                    (Date) dbo.get(lastModifiedAtFieldName)));
        }
        return approvals;
    } finally {
        if (cursor != null) {
            cursor.close();
        }
    }
}

From source file:com.cedac.security.oauth2.provider.client.MongoClientDetailsService.java

License:Apache License

public List<ClientDetails> listClientDetails() {
    DBCursor cursor = null;
    try {//from w  w w. j  a  v a 2 s  .c o  m
        cursor = getClientDetailsCollection().find();
        List<ClientDetails> clientDetails = new ArrayList<ClientDetails>();
        while (cursor.hasNext()) {
            clientDetails.add(toClientDetails(cursor.next()));
        }
        return clientDetails;
    } finally {
        if (cursor != null) {
            cursor.close();
        }
    }
}

From source file:com.cedac.security.oauth2.provider.token.store.MongoTokenStore.java

License:Apache License

public Collection<OAuth2AccessToken> findTokensByClientId(String clientId) {
    List<OAuth2AccessToken> accessTokens = new ArrayList<OAuth2AccessToken>();

    DBObject query = new BasicDBObject(clientIdFieldName, clientId);
    DBObject projection = new BasicDBObject(tokenFieldName, 1);
    DBCursor cursor = null;
    try {//  ww w .j  a  v  a 2 s. com
        cursor = getAccessTokenCollection().find(query, projection);
        if (cursor.count() > 0) {
            while (cursor.hasNext()) {
                OAuth2AccessToken token = mapAccessToken(cursor.next());
                if (token != null) {
                    accessTokens.add(token);
                }
            }
        } else {
            LOG.info("Failed to find access token for clientId {}", clientId);
        }
        return accessTokens;
    } finally {
        if (cursor != null) {
            cursor.close();
        }
    }
}

From source file:com.cedac.security.oauth2.provider.token.store.MongoTokenStore.java

License:Apache License

public Collection<OAuth2AccessToken> findTokensByUserName(String userName) {
    List<OAuth2AccessToken> accessTokens = new ArrayList<OAuth2AccessToken>();

    DBObject query = new BasicDBObject(usernameFieldName, userName);
    DBObject projection = new BasicDBObject(tokenFieldName, 1);
    DBCursor cursor = null;
    try {//  w  w  w. j  a v  a  2 s.co  m
        cursor = getAccessTokenCollection().find(query, projection);
        if (cursor.count() > 0) {
            while (cursor.hasNext()) {
                OAuth2AccessToken token = mapAccessToken(cursor.next());
                if (token != null) {
                    accessTokens.add(token);
                }
            }
        } else {
            LOG.info("Failed to find access token for username {}.", userName);
        }
        return accessTokens;
    } finally {
        if (cursor != null) {
            cursor.close();
        }
    }
}

From source file:com.cedac.security.oauth2.provider.token.store.MongoTokenStore.java

License:Apache License

public Collection<OAuth2AccessToken> findTokensByClientIdAndUserName(String clientId, String userName) {
    List<OAuth2AccessToken> accessTokens = new ArrayList<OAuth2AccessToken>();

    DBObject query = new BasicDBObject(clientIdFieldName, clientId).append(usernameFieldName, userName);
    DBObject projection = new BasicDBObject(tokenFieldName, 1);
    DBCursor cursor = null;
    try {/* ww w . jav  a  2  s .co m*/
        cursor = getAccessTokenCollection().find(query, projection);
        if (cursor.count() > 0) {
            while (cursor.hasNext()) {
                OAuth2AccessToken token = mapAccessToken(cursor.next());
                if (token != null) {
                    accessTokens.add(token);
                }
            }
        } else {
            LOG.info("Failed to find access token for clientId {} and username {}.", clientId, userName);
        }
        return accessTokens;
    } finally {
        if (cursor != null) {
            cursor.close();
        }
    }
}

From source file:com.chdi.kundenverwaltung.KundenVerwaltungsLogic.java

public List<Customer> findAllCustomer() {
    List<Customer> customers = new ArrayList<Customer>();

    DBCollection table = db.getCollection("user");

    DBCursor cursor = table.find();

    while (cursor.hasNext()) {

        DBObject tobj = cursor.next();
        Customer tmp = new Customer((String) tobj.get("ID"), (String) tobj.get("CompanyName"),
                (String) tobj.get("Name"), (String) tobj.get("Adress"));
        customers.add(tmp);//ww  w.j  a  va 2s. co m
    }

    return customers;
}