Example usage for com.mongodb BasicDBObjectBuilder start

List of usage examples for com.mongodb BasicDBObjectBuilder start

Introduction

In this page you can find the example usage for com.mongodb BasicDBObjectBuilder start.

Prototype

public static BasicDBObjectBuilder start(final String key, final Object val) 

Source Link

Document

Creates a builder initialized with the given key/value.

Usage

From source file:org.sglover.entities.dao.mongo.MongoEntitiesDAO.java

License:Open Source License

@Override
// TODO use skip and maxItems
public Stream<Entity<String>> getOrgs(Node node, int skip, int maxItems) {
    String nodeId = node.getNodeId();
    String nodeVersion = node.getVersionLabel();

    Collection<Entity<String>> ret = new LinkedList<>();

    QueryBuilder queryBuilder = QueryBuilder.start("n").is(nodeId).and("v").is(nodeVersion);
    DBObject query = queryBuilder.get();

    BasicDBObjectBuilder orderByBuilder = BasicDBObjectBuilder.start("o", 1);
    DBObject orderBy = orderByBuilder.get();

    DBCursor cursor = entitiesData.find(query).sort(orderBy);
    try {/*w  ww  . j  a  v a 2  s  . c o  m*/
        for (DBObject dbObject : cursor) {
            String org = (String) dbObject.get("o");
            int count = (Integer) dbObject.get("c");
            String type = map.get("nm");
            Entity<String> entity = new Entity<>(EntityType.valueOf(type), org, count);
            ret.add(entity);
        }
    } finally {
        if (cursor != null) {
            cursor.close();
        }
    }

    return ret.stream();
}

From source file:org.sglover.entities.dao.mongo.MongoEntitiesDAO.java

License:Open Source License

@Override
public Stream<Node> matchingNodes(EntityType type, String name) {
    List<Node> nodes = new LinkedList<>();

    QueryBuilder queryBuilder = QueryBuilder.start("t").is(type).and("nm").is(name);
    DBObject query = queryBuilder.get();

    BasicDBObjectBuilder orderByBuilder = BasicDBObjectBuilder.start("c", 1);
    DBObject orderBy = orderByBuilder.get();

    DBCursor cursor = entitiesData.find(query).sort(orderBy);
    try {//from  ww w . j  a  va2  s  .com
        for (DBObject dbObject : cursor) {
            String nodeId = (String) dbObject.get("n");
            long nodeInternalId = (Long) dbObject.get("ni");
            Long nodeVersion = (Long) dbObject.get("v");
            Node node = Node.build().nodeInternalId(nodeInternalId).nodeId(nodeId).nodeVersion(nodeVersion);
            nodes.add(node);
        }
    } finally {
        if (cursor != null) {
            cursor.close();
        }
    }

    return nodes.stream();
}

From source file:org.sglover.entities.dao.mongo.MongoSimilarityDAO.java

License:Open Source License

private void init() {
    if (db == null) {
        throw new RuntimeException("Mongo DB must not be null");
    }/*from ww w .  ja va 2 s  . co  m*/

    this.similarityData = getCollection(db, similarityCollectionName, WriteConcern.ACKNOWLEDGED);

    {
        DBObject keys = BasicDBObjectBuilder.start("tx", 1).get();
        this.similarityData.ensureIndex(keys, "btTxn", false);
    }
}