Java Code Examples for com.mongodb.DBCursor#close()

The following examples show how to use com.mongodb.DBCursor#close() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Feature.java    From XBDD with Apache License 2.0 6 votes vote down vote up
public static void embedTestingTips(final DBObject feature, final Coordinates coordinates, final DB db) {
	final DBCollection tips = db.getCollection("testingTips");
	final List<DBObject> elements = (List<DBObject>) feature.get("elements");
	for (final DBObject scenario : elements) {
		DBObject oldTip;
		final BasicDBObject tipQuery = coordinates
				.getTestingTipsCoordinatesQueryObject((String) feature.get("id"), (String) scenario.get("id"));
		// get the most recent tip that is LTE to the current coordinates. i.e. sort in reverse chronological order and take the first
		// item (if one exists).
		final DBCursor oldTipCursor = tips.find(tipQuery)
				.sort(new BasicDBObject("coordinates.major", -1).append("coordinates.minor", -1)
						.append("coordinates.servicePack", -1).append("coordinates.build", -1))
				.limit(1);
		try {
			if (oldTipCursor.hasNext()) {
				oldTip = oldTipCursor.next();
				scenario.put("testing-tips", oldTip.get("testing-tips"));
			}
		} finally {
			oldTipCursor.close();
		}
	}
}
 
Example 2
Source File: MongoDB.java    From act with GNU General Public License v3.0 6 votes vote down vote up
public List<Seq> getSeqWithSARConstraints() {
  List<Seq> seqs = new ArrayList<Seq>();
  BasicDBObject query = new BasicDBObject();
  query.put("sar_constraints", new BasicDBObject("$exists", true));

  BasicDBObject keys = new BasicDBObject();

  DBCursor cur = this.dbSeq.find(query, keys);
  while (cur.hasNext()) {
    DBObject o = cur.next();
    seqs.add( convertDBObjectToSeq(o) );
  }
  cur.close();

  return seqs;
}
 
Example 3
Source File: MongoDB.java    From act with GNU General Public License v3.0 6 votes vote down vote up
public List<Seq> getSeqFromGenbankNucAccessionSeq(String accession, String seq) {
  List<Seq> seqs = new ArrayList<>();
  BasicDBObject query = new BasicDBObject();
  query.put("seq", seq);
  query.put("metadata.accession.genbank_nucleotide",
      new BasicDBObject("$elemMatch", new BasicDBObject("$eq", accession)));

  DBCursor cur = this.dbSeq.find(query, new BasicDBObject());
  try {
    while (cur.hasNext()) {
      DBObject o = cur.next();
      seqs.add(convertDBObjectToSeq(o));
    }
  } finally {
    if (cur != null) {
      cur.close();
    }
  }

  return seqs;
}
 
Example 4
Source File: MongoDB.java    From act with GNU General Public License v3.0 6 votes vote down vote up
public List<Seq> getSeqFromGenbankProtAccession(String accession) {
  List<Seq> seqs = new ArrayList<>();
  BasicDBObject query = new BasicDBObject();
  query.put("metadata.accession.genbank_protein",
      new BasicDBObject("$elemMatch", new BasicDBObject("$eq", accession)));

  DBCursor cur = this.dbSeq.find(query, new BasicDBObject());
  try {
    while (cur.hasNext()) {
      DBObject o = cur.next();
      seqs.add(convertDBObjectToSeq(o));
    }
  } finally {
    if (cur != null) {
      cur.close();
    }
  }

  return seqs;
}
 
Example 5
Source File: MongoDB.java    From act with GNU General Public License v3.0 6 votes vote down vote up
public List<Seq> getSeqFromSeqEcOrg(String seq, String ec, String organism) {
  List<Seq> seqs = new ArrayList<>();
  BasicDBObject query = new BasicDBObject();
  query.put("seq", seq);
  query.put("ecnum", ec);
  query.put("org", organism);

  DBCursor cur = this.dbSeq.find(query, new BasicDBObject());
  try {
    while (cur.hasNext()) {
      DBObject o = cur.next();
      seqs.add(convertDBObjectToSeq(o));
    }
  } finally {
    if (cur != null) {
      cur.close();
    }
  }

  return seqs;
}
 
Example 6
Source File: AdvancedDao.java    From bugu-mongo with Apache License 2.0 6 votes vote down vote up
private synchronized Iterable<DBObject> mapReduce(String map, String reduce, String outputTarget, MapReduceCommand.OutputType outputType, String orderBy, int pageNum, int pageSize, DBObject query) {
    MapReduceOutput output = getCollection().mapReduce(map, reduce, outputTarget, outputType, query);
    DBCollection c = output.getOutputCollection();
    DBCursor cursor;
    if(orderBy != null){
        cursor = c.find().sort(SortUtil.getSort(orderBy)).skip((pageNum-1)*pageSize).limit(pageSize);
    }else{
        cursor = c.find().skip((pageNum-1)*pageSize).limit(pageSize);
    }
    List<DBObject> list = new ArrayList<>();
    for(Iterator<DBObject> it = cursor.iterator(); it.hasNext(); ){
        list.add(it.next());
    }
    cursor.close();
    return list;
}
 
Example 7
Source File: MongoGridFSSession.java    From ymate-platform-v2 with Apache License 2.0 6 votes vote down vote up
@Override
public List<GridFSDBFile> find(Query query, OrderBy orderBy, Page page) {
    DBCursor _cursor = __dbCollection.find(query.toBson());
    if (orderBy != null) {
        _cursor.sort(orderBy.toBson());
    }
    if (page != null && page.page() > 0 && page.pageSize() > 0) {
        _cursor.skip((page.page() - 1) * page.pageSize()).limit(page.pageSize());
    }
    List<GridFSDBFile> _results = new ArrayList<GridFSDBFile>();
    while (_cursor.hasNext()) {
        _results.add((GridFSDBFile) _cursor.next());
    }
    _cursor.close();
    return _results;
}
 
Example 8
Source File: MongoDB.java    From act with GNU General Public License v3.0 6 votes vote down vote up
private List<DBObject> keywordInCascade(String in_field, String keyword) {
  List<DBObject> cascades = new ArrayList<DBObject>();
  BasicDBObject query = new BasicDBObject();
  query.put(in_field, keyword);

  BasicDBObject keys = new BasicDBObject();

  DBCursor cur = this.dbCascades.find(query, keys);
  while (cur.hasNext()) {
    DBObject o = cur.next();
    cascades.add( convertDBObjectToCascade(o) );
  }
  cur.close();

  return cascades;
}
 
Example 9
Source File: MongoDB.java    From act with GNU General Public License v3.0 6 votes vote down vote up
private List<Seq> keywordInSequence(String in_field, String keyword) {
  List<Seq> seqs = new ArrayList<Seq>();
  BasicDBObject query = new BasicDBObject();
  query.put(in_field, keyword);

  BasicDBObject keys = new BasicDBObject();

  DBCursor cur = this.dbSeq.find(query, keys);
  while (cur.hasNext()) {
    DBObject o = cur.next();
    seqs.add( convertDBObjectToSeq(o) );
  }
  cur.close();

  return seqs;
}
 
Example 10
Source File: PrivateStorageRepository.java    From konker-platform with Apache License 2.0 6 votes vote down vote up
private void toPrivateStorageList(String collectionName, List<PrivateStorage> privatesStorage, DBCursor cursor) throws JsonProcessingException {
    try {
        while (cursor.hasNext()) {
            cursor.next();

            String content = jsonParsingService.toJsonString(cursor.curr().toMap());

            privatesStorage.add(PrivateStorage.builder()
                    .collectionName(collectionName)
                    .collectionContent(content)
                    .build());
        }
    } finally {
        cursor.close();
    }
}
 
Example 11
Source File: MongoDB.java    From act with GNU General Public License v3.0 6 votes vote down vote up
public Map<String, Long> constructAllInChIs() {
  Map<String, Long> chems = new HashMap<String, Long>();
  BasicDBObject keys = new BasicDBObject();
  keys.append("_id", true);
  keys.append("InChI", true);
  DBCursor cur = constructCursorForMatchingChemicals(null, null, keys);
  while (cur.hasNext()) {
    DBObject o = cur.next();
    long uuid = (Long)o.get("_id"); // checked: db type IS long
    String inchi = (String)o.get("InChI");
    chems.put(inchi, uuid);
  }

  cur.close();
  return chems;
}
 
Example 12
Source File: MongoGridFSSession.java    From ymate-platform-v2 with Apache License 2.0 6 votes vote down vote up
@Override
public List<GridFSDBFile> findAll(OrderBy orderBy, Page page) {
    DBCursor _cursor = __dbCollection.find();
    if (orderBy != null) {
        _cursor.sort(orderBy.toBson());
    }
    if (page != null && page.page() > 0 && page.pageSize() > 0) {
        _cursor.skip((page.page() - 1) * page.pageSize()).limit(page.pageSize());
    }
    List<GridFSDBFile> _results = new ArrayList<GridFSDBFile>();
    while (_cursor.hasNext()) {
        _results.add((GridFSDBFile) _cursor.next());
    }
    _cursor.close();
    return _results;
}
 
Example 13
Source File: MongoDB.java    From act with GNU General Public License v3.0 5 votes vote down vote up
public List<Chemical> constructAllChemicalsFromActData(String field, Object val, BasicDBObject keys) {
  DBCursor cur = constructCursorForMatchingChemicals(field, val, keys);

  List<Chemical> chems = new ArrayList<Chemical>();
  while (cur.hasNext())
    chems.add(convertDBObjectToChemical(cur.next()));

  cur.close();
  return chems;
}
 
Example 14
Source File: MongoDB.java    From act with GNU General Public License v3.0 5 votes vote down vote up
public List<Long> getRxnsWithSubstrate(String enzyme, Long org, List<Long> substrates) {
  BasicDBObject query = new BasicDBObject();
  query.put("organisms.id", org);
  BasicDBObject enzymeQuery = new BasicDBObject();
  enzymeQuery.put("ecnum", enzyme);
  query.put("$ne", enzymeQuery);
  for (Long substrate: substrates) {
    BasicDBList queryList = new BasicDBList();
    DBObject querySubstrate = new BasicDBObject();
    querySubstrate.put("enz_summary.substrates.pubchem", substrate);
    DBObject queryProduct = new BasicDBObject();
    queryProduct.put("enz_summary.products.pubchem", substrate);
    queryList.add(querySubstrate);
    queryList.add(queryProduct);
    query.put("$or", queryList);
  }

  DBCursor cur = this.dbReactions.find(query);
  List<Long> reactions = new ArrayList<Long>();
  while (cur.hasNext()) {
    DBObject o = cur.next();
    long id = (Integer) o.get("_id"); // checked: db type IS int
    reactions.add(id);
  }
  cur.close();
  return reactions;
}
 
Example 15
Source File: MongoDBKeyValueStore.java    From boon with Apache License 2.0 5 votes vote down vote up
@Override
public KeyValueIterable<K, V> search(K startKey) {


    final DBCursor cursor = collection.find(new BasicDBObject(map("key", new BasicDBObject("$gt", startKey))));
    return new KeyValueIterable<K, V>() {
        @Override
        public void close() {
            cursor.close();
        }

        @Override
        public Iterator<Entry<K, V>> iterator() {
            return new Iterator<Entry<K, V>>() {
                @Override
                public boolean hasNext() {
                    return cursor.hasNext();
                }

                @Override
                public Entry<K, V> next() {
                    //TODO left off here
                    return null;
                }

                @Override
                public void remove() {

                }
            };
        }
    };
}
 
Example 16
Source File: BuguFS.java    From bugu-mongo with Apache License 2.0 5 votes vote down vote up
private List<GridFSDBFile> toFileList(DBCursor cursor){
    List<GridFSDBFile> list = new ArrayList<GridFSDBFile>();
    while(cursor.hasNext()){
        DBObject dbo = cursor.next();
        list.add((GridFSDBFile)dbo);
    }
    cursor.close();
    return list;
}
 
Example 17
Source File: MongoStore.java    From todo-apps with Apache License 2.0 5 votes vote down vote up
@Override
public ToDo get(String id) {
  BasicDBObject query = new BasicDBObject("_id", id);
  DBCursor cursor = coll.find(query);
  if(cursor.hasNext()) {
    ToDo td = createToDo(cursor.next());
    cursor.close();
    return td;
  } else {
    return null;
  }
}
 
Example 18
Source File: DeviceManagerController.java    From SI with BSD 2-Clause "Simplified" License 4 votes vote down vote up
@ResponseBody
@RequestMapping(value="/getMgmtCmdResult.do")
public Map<String, Object> getMgmtCmdResult(HttpServletRequest request) throws Exception {
	Map<String, Object> response = new HashMap<String, Object>();
	HttpSession session = request.getSession(false);
	
	if(session != null){
		//페이지 권한 확인
		GroupAuthorization requestAuth = (GroupAuthorization) session.getAttribute("requestAuth");
		if(!requestAuth.getAuthorizationDBRead().equals("1")){
			response.put("result", 1);
			response.put("errorCode", -1);
			response.put("content", "authMessage: onem2m 페이지 접근 권한이 없습니다.");
		} else {
			String collection = HeritProperties.getProperty("Globals.MongoDB.Collection");
			DBCollection col = db.getCollection(collection);
			
			String rn = request.getParameter("rn");
			
			if (rn == null || rn.equals("")) {
				response.put("result", 1);
				response.put("errorCode", -1);
				response.put("content", "parameters[rn] is missing");
			}
			
			BasicDBObject query = new BasicDBObject();
			query.put("ty", 8);
			query.put("ext", rn);
			
			DBCursor cursor = col.find(query);
			
			List<DBObject> dbObjList = new ArrayList<DBObject>();
			try {
			    while (cursor.hasNext()) {
			
			        dbObjList.add(cursor.next());
			        ////System.out.println("############# dbObjList.toString() = " + dbObjList.toString());
			    }
			} finally {
			    cursor.close();
			}
			
			response.put("result", 0);
			response.put("errorCode", 0);
			response.put("content", dbObjList.toString());
			
		}
	} else {
		response.put("result", 1);
		response.put("errorCode", -1);
		response.put("content", "session is null");
	}
	
	return response;
}
 
Example 19
Source File: Feature.java    From XBDD with Apache License 2.0 4 votes vote down vote up
/**
 * Uses the '.+' regexp on featureId to allow for symbols such as slashes in the id
 *
 * @param featureId String The featureId to get the history for
 * @return DBObjet Returns the past feature status for the given featureId
 */
@GET
@Path("/rollup/{product}/{major}.{minor}.{servicePack}/{featureId:.+}")
@Produces(MediaType.APPLICATION_JSON)
public Response getFeatureRollup(@BeanParam final Coordinates coordinates, @PathParam("featureId") final String featureId) {
	final List<BasicDBObject> features = new ArrayList<>();
	final DBCollection collection = this.mongoLegacyDb.getCollection("features");
	final DBCollection summary = this.mongoLegacyDb.getCollection("summary");
	final BasicDBObject example = coordinates.getRollupQueryObject(featureId);
	final DBCursor cursor = collection.find(example,
			new BasicDBObject("id", 1).append("coordinates.build", 1).append("calculatedStatus", 1)
					.append("originalAutomatedStatus", 1).append("statusLastEditedBy", 1));
	try {
		while (cursor.hasNext()) {
			final DBObject doc = cursor.next();
			final BasicDBObject rollup = new BasicDBObject()
					.append("build", ((DBObject) doc.get("coordinates")).get("build"))
					.append("calculatedStatus", doc.get("calculatedStatus"))
					.append("originalAutomatedStatus", doc.get("originalAutomatedStatus"))
					.append("statusLastEditedBy", doc.get("statusLastEditedBy"));
			features.add(rollup);
		}
	} finally {
		cursor.close();
	}
	final BasicDBObject returns = new BasicDBObject()
			.append("coordinates", coordinates.getRollupCoordinates().append("featureId", featureId)
					.append("version", coordinates.getVersionString()));

	final DBObject buildOrder = summary.findOne(coordinates.getQueryObject());
	final List<String> buildArray = (List<String>) buildOrder.get("builds");
	final List<BasicDBObject> orderedFeatures = new ArrayList<>();

	for (final String build : buildArray) {
		for (final BasicDBObject feature : features) {
			if (feature.get("build").equals(build)) {
				orderedFeatures.add(feature);
				break;
			}
		}
	}

	returns.append("rollup", orderedFeatures);

	return Response.ok(SerializerUtil.serialise(returns)).build();
}
 
Example 20
Source File: TenantLogRepository.java    From konker-platform with Apache License 2.0 3 votes vote down vote up
public List<TenantLog> findAll(Tenant tenant) {

		List<TenantLog> logs = new ArrayList<>(MAX_DOCUMENTS);

		String collectionName = getCollectionName(tenant);

		checkCollection(collectionName);

		DBCollection collection = mongoAuditTemplate.getCollection(collectionName);
		DBCursor cursor = collection.find();

		try {
			while (cursor.hasNext()) {

				cursor.next();

				String message = (String) cursor.curr().get("message");
				String level = (String) cursor.curr().get("level");
				Long time = (Long) cursor.curr().get("time");

				logs.add(TenantLog.builder().level(level).message(message).time(new Date(time)).build());

			}
		} finally {
			cursor.close();
		}

		return logs;

	}