Example usage for com.mongodb DBCursor close

List of usage examples for com.mongodb DBCursor close

Introduction

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

Prototype

@Override
    public void close() 

Source Link

Usage

From source file:org.opencb.cellbase.mongodb.db.network.PathwayMongoDBAdaptor.java

License:Apache License

@Override
public String getTree() {
    BasicDBObject query = new BasicDBObject();
    query.put("parentPathway", "none");

    BasicDBObject returnFields = new BasicDBObject();
    returnFields.put("_id", 0);
    returnFields.put("name", 1);
    returnFields.put("displayName", 1);
    returnFields.put("subPathways", 1);

    BasicDBObject orderBy = new BasicDBObject();
    orderBy.put("displayName", 1);

    DBCursor cursor = coll.find(query, returnFields).sort(orderBy);
    String result = cursor.toArray().toString();
    cursor.close();

    return result;
}

From source file:org.opencb.cellbase.mongodb.db.network.PathwayMongoDBAdaptor.java

License:Apache License

@Override
public String getPathway(String pathwayId) {
    BasicDBObject query = new BasicDBObject();
    query.put("name", pathwayId);

    BasicDBObject returnFields = new BasicDBObject();
    returnFields.put("_id", 0);

    DBCursor cursor = coll.find(query, returnFields);
    String result = cursor.toArray().toString();
    cursor.close();

    return result;
}

From source file:org.opencb.cellbase.mongodb.db.network.PathwayMongoDBAdaptor.java

License:Apache License

@Override
public String search(String searchBy, String searchText, boolean returnOnlyIds) {
    Pattern regex = Pattern.compile(searchText, Pattern.CASE_INSENSITIVE);

    BasicDBObject query = new BasicDBObject();
    if (searchBy.equalsIgnoreCase("pathway")) {
        query.put("displayName", regex);
    } else {/* www  .  j  a  v a 2  s.  co m*/
        BasicDBObject query1 = new BasicDBObject("physicalEntities.params.displayName", regex);
        BasicDBObject query2 = new BasicDBObject("interactions.params.displayName", regex);
        ArrayList<BasicDBObject> queryList = new ArrayList<BasicDBObject>();
        queryList.add(query1);
        queryList.add(query2);
        query.put("$or", queryList);
    }

    System.out.println("Query: " + query);

    BasicDBObject returnFields = new BasicDBObject();
    returnFields.put("_id", 0);
    if (returnOnlyIds) {
        returnFields.put("name", 1);
    }

    DBCursor cursor = coll.find(query, returnFields);
    String result = cursor.toArray().toString();
    cursor.close();
    return result;
}

From source file:org.opendaylight.controller.samples.onftappingapp.TappingApp.java

License:Apache License

public List<TapPolicy> getAllTapPolicies() {

    DBCollection tpTable = database.getCollection(DatabaseNames.getTapPolicyTableName());
    DBCursor cursor = tpTable.find();

    List<TapPolicy> tapPolicyList = new ArrayList<TapPolicy>(cursor.size());

    try {/*from ww w . j ava  2  s.c o m*/
        while (cursor.hasNext()) {
            // Get the object from the database
            DBObject tapPolicyObj = cursor.next();

            // Construct a new tap policy from the DBobject and add it to list
            tapPolicyList.add(new TapPolicy(tapPolicyObj));
        }
    } catch (NotFoundException e) {
        logger.error("Object referenced by Tap Policy cannot be found", e);
    } finally {
        cursor.close();
    }

    return tapPolicyList;
}

From source file:org.opendaylight.controller.samples.onftappingapp.TappingApp.java

License:Apache License

public List<MatchCriteria> getAllMatchCriteria() {

    DBCollection mcTable = database.getCollection(DatabaseNames.getMatchCriteriaTableName());
    DBCursor cursor = mcTable.find();

    List<MatchCriteria> matchCriteriaList = new ArrayList<MatchCriteria>(cursor.size());

    try {/*from   ww w .  j av  a 2 s  .  c o m*/
        while (cursor.hasNext()) {
            DBObject matchCriteriaObj = cursor.next();
            MatchCriteria matchCriteria = new MatchCriteria(matchCriteriaObj);

            matchCriteriaList.add(matchCriteria);

        }
    } finally {
        cursor.close();
    }

    return matchCriteriaList;
}

From source file:org.opendaylight.controller.samples.onftappingapp.TappingApp.java

License:Apache License

public List<SwitchEntry> getAllSwitchEntries() {

    DBCollection seTable = database.getCollection(DatabaseNames.getSwitchEntryTableName());
    DBCursor cursor = seTable.find();

    List<SwitchEntry> switchEntryList = new ArrayList<SwitchEntry>(cursor.size());

    try {// w ww . j  av a 2s. c o  m
        while (cursor.hasNext()) {
            DBObject switchEntryObj = cursor.next();

            SwitchEntry switchEntry = new SwitchEntry(switchEntryObj, this);

            // Add the new SwitchEntry to the list
            switchEntryList.add(switchEntry);
        }
    } finally {
        cursor.close();
    }

    return switchEntryList;
}

From source file:org.opendaylight.controller.samples.onftappingapp.TappingApp.java

License:Apache License

public List<NextHopSwitch> getAllNextHopSwitches() {
    DBCollection nhsTable = database.getCollection(DatabaseNames.getNextHopSwitchTableName());
    DBCursor cursor = nhsTable.find();

    List<NextHopSwitch> nextHopSwitchList = new ArrayList<NextHopSwitch>(cursor.size());

    try {/*from w w w.ja va  2s  . c o  m*/
        while (cursor.hasNext()) {
            DBObject nhsObj = cursor.next();

            NextHopSwitch nhs = new NextHopSwitch(nhsObj);

            // Add the new SwitchEntry to the list
            nextHopSwitchList.add(nhs);
        }
    } finally {
        cursor.close();
    }

    return nextHopSwitchList;
}

From source file:org.opendaylight.controller.samples.onftappingapp.TappingApp.java

License:Apache License

public List<PortChain> getAllPortChains() {
    DBCollection pcTable = database.getCollection(DatabaseNames.getPortChainTableName());
    DBCursor cursor = pcTable.find();

    List<PortChain> portChainList = new ArrayList<PortChain>(cursor.size());

    try {/*from  w ww . ja  va2  s  .  c o  m*/
        while (cursor.hasNext()) {
            DBObject portChainObj = cursor.next();

            // Construct a new port chain from the DB object
            PortChain portChain = new PortChain(portChainObj);

            // Add the new port chain to the list
            portChainList.add(portChain);
        }
    } finally {
        cursor.close();
    }

    return portChainList;
}

From source file:org.opendaylight.controller.samples.onftappingapp.TappingApp.java

License:Apache License

public List<LoggedMessage> loadLoggedMessagesFromDatabase() {

    DBCollection logTable = database.getCollection(DatabaseNames.getLoggerTableName());

    DBCursor cursor = logTable.find();
    List<LoggedMessage> loggedMessageList = processLogMessageCursor(cursor);
    cursor.close();

    return loggedMessageList;
}

From source file:org.opendaylight.controller.samples.onftappingapp.TappingApp.java

License:Apache License

public List<LoggedMessage> loadLoggedMessagesFromDatabase(final Date startDate, final Date endDate) {
    DBCollection logTable = database.getCollection(DatabaseNames.getLoggerTableName());

    // Create a query to look for log entries after the start date
    BasicDBObject searchQuery = new BasicDBObject();
    searchQuery.put("timestamp", BasicDBObjectBuilder.start("$gte", startDate).add("$lte", endDate).get());

    DBCursor cursor = logTable.find(searchQuery);
    List<LoggedMessage> loggedMessageList = processLogMessageCursor(cursor);
    cursor.close();

    return loggedMessageList;
}