List of usage examples for com.mongodb DBCursor close
@Override public void close()
From source file:com.ebay.cloud.cms.dal.persistence.MongoExecutor.java
License:Apache License
public static List<DBObject> find(PersistenceContext context, MetaClass metadata, DBObject queryObject, DBObject fieldObject, SearchOption option) { long start = System.currentTimeMillis(); String msg = "success"; DBCollection dbCollection = context.getDBCollection(metadata); DBCursor findCursor = null; Integer size = 0;/* w ww . j a va 2 s . c om*/ try { findCursor = dbCollection.find(queryObject, fieldObject); // set option if (option.hasLimit()) { findCursor.limit(option.getLimit()); } if (option.hasSkip()) { findCursor.skip(option.getSkip()); } if (option.hasSort()) { findCursor.sort(option.getSort()); } // populate search result List<DBObject> result = findCursor.toArray(); size = result.size(); return result; } catch (Throwable t) { msg = t.getMessage(); handleMongoException(t); } finally { if (findCursor != null) { findCursor.close(); } logMongoAction(context, "find", start, dbCollection, queryObject, fieldObject, option, size, msg); } return Collections.emptyList(); }
From source file:com.ebay.jetstream.config.mongo.MongoDAO.java
License:MIT License
public static List<JetStreamBeanConfigurationDo> findConfigurationByAppNameAndVersion(BasicDBObject query, MongoConnection mongoConnection) { List<JetStreamBeanConfigurationDo> beanConfigs = new ArrayList<JetStreamBeanConfigurationDo>(); List<BasicDBObject> dbObjects = new ArrayList<BasicDBObject>(); DBCollection dbCol = mongoConnection.getDBCollection(); if (dbCol == null) { throw new MongoConfigRuntimeException("jetstreamconfig collection is unknown"); }/*from w w w . j a v a2 s. c o m*/ Exception e = null; DBCursor cur = null; try { cur = (query == null ? dbCol.find() : dbCol.find(query)); while (cur.hasNext()) { dbObjects.add((BasicDBObject) cur.next()); } for (BasicDBObject dbObject : dbObjects) { String jsonString = dbObject.toString(); beanConfigs.add(unMarshalJSONResponse(jsonString)); } } catch (Exception err) { e = err; throw new MongoConfigRuntimeException(err); } finally { if (cur != null) { cur.close(); } } return beanConfigs; }
From source file:com.ebay.jetstream.config.mongo.MongoDAO.java
License:MIT License
public static List<JetStreamBeanConfigurationDo> findConfigurationByQuery(BasicDBObject query, MongoConnection mongoConnection) { List<JetStreamBeanConfigurationDo> beanConfigs = new ArrayList<JetStreamBeanConfigurationDo>(); List<BasicDBObject> dbObjects = new ArrayList<BasicDBObject>(); DBCollection dbCol = mongoConnection.getDBCollection(); if (dbCol == null) { throw new MongoConfigRuntimeException("jetstreamconfig collection is unknown"); }//from w w w. j a v a 2 s. c o m Exception e = null; DBCursor cur = null; try { cur = (query == null ? dbCol.find() : dbCol.find(query)); while (cur.hasNext()) { dbObjects.add((BasicDBObject) cur.next()); } for (BasicDBObject dbObject : dbObjects) { String jsonString = dbObject.toString(); beanConfigs.add(unMarshalJSONResponse(jsonString)); //beanConfig = (JetStreamBeanConfigurationDo)fromJson(jsonString, JetStreamBeanConfigurationDo.class); } } catch (Exception err) { e = err; throw new MongoConfigRuntimeException(err); } finally { if (cur != null) { cur.close(); } } return beanConfigs; }
From source file:com.ebay.jetstream.configurationmanagement.MongoLogDAO.java
License:MIT License
public static List<JetStreamBeanConfigurationLogDo> findConfigurationByAppNameAndVersion(BasicDBObject query, MongoLogConnection mongoConnection) { List<JetStreamBeanConfigurationLogDo> beanConfigs = new ArrayList<JetStreamBeanConfigurationLogDo>(); List<BasicDBObject> dbObjects = new ArrayList<BasicDBObject>(); DBCollection dbCol = mongoConnection.getDBCollection(); if (dbCol == null) { throw new MongoConfigRuntimeException("jetstreamconfiglog collection is unknown"); }/*ww w .j a v a 2s .co m*/ Exception e = null; DBCursor cur = null; try { cur = (query == null ? dbCol.find() : dbCol.find(query)); while (cur.hasNext()) { dbObjects.add((BasicDBObject) cur.next()); } for (BasicDBObject dbObject : dbObjects) { String jsonString = dbObject.toString(); beanConfigs.add(unMarshalJSONResponse(jsonString)); } } catch (Exception err) { e = err; throw new MongoConfigRuntimeException(err); } finally { if (cur != null) { cur.close(); } } return beanConfigs; }
From source file:com.ebay.jetstream.configurationmanagement.MongoLogDAO.java
License:MIT License
public static List<JetStreamBeanConfigurationLogDo> findConfigurationByQuery(BasicDBObject query, MongoLogConnection mongoLogConnection) { List<JetStreamBeanConfigurationLogDo> beanConfigs = new ArrayList<JetStreamBeanConfigurationLogDo>(); List<BasicDBObject> dbObjects = new ArrayList<BasicDBObject>(); DBCollection dbCol = mongoLogConnection.getDBCollection(); if (dbCol == null) { throw new MongoConfigRuntimeException("jetstreamconfigLog collection is unknown"); }/*from www .j a va 2 s .co m*/ Exception e = null; DBCursor cur = null; try { cur = (query == null ? dbCol.find() : dbCol.find(query)); while (cur.hasNext()) { dbObjects.add((BasicDBObject) cur.next()); } for (BasicDBObject dbObject : dbObjects) { String jsonString = dbObject.toString(); beanConfigs.add(unMarshalJSONResponse(jsonString)); // beanConfig = // (JetStreamBeanConfigurationDo)fromJson(jsonString, // JetStreamBeanConfigurationDo.class); } } catch (Exception err) { e = err; throw new MongoConfigRuntimeException(err); } finally { if (cur != null) { cur.close(); } } return beanConfigs; }
From source file:com.edduarte.argus.document.Document.java
License:Apache License
public List<Occurrence> getAllOccurrences(String occurrencesText) { if (occurrencesText.isEmpty()) { return null; }/*w w w. j a va 2 s.com*/ DBCursor cursor = occCollection.find(new BasicDBObject(Occurrence.TEXT, occurrencesText)); List<Occurrence> list = new ArrayList<>(); while (cursor.hasNext()) { BasicDBObject obj = (BasicDBObject) cursor.next(); list.add(new Occurrence(obj)); } cursor.close(); return list; }
From source file:com.ff.reportgenerator.mongodb.DynamicDatabase.java
public String query() { String records = "<table>" + Utility.formTableHead() + "<tbody>"; DB myDB = getDB(DB_NAME);/* w w w .j ava 2 s . co m*/ DBCollection coll = myDB.getCollection("projects"); DBCursor ret = coll.find(); BasicDBObject sort = new BasicDBObject("PROJECT_ID", 1); ret.sort(sort); try { while (ret.hasNext()) { records = records + "<tr>"; DBObject rec = (DBObject) ret.next(); Iterator keys = Utility.DATA_KEYS.iterator(); while (keys.hasNext()) { String key = (String) keys.next(); String value = (String) rec.get(key); if (key.equals("PROJECT_ID")) { records = records + "<td><a href=\"" + Utility.PROJECT_URL_PREFIX + value + "\">" + value + "</td>"; } else { records = records + "<td>" + value + "</td>"; } } records = records + "</tr>"; //System.out.println(rec); } } finally { ret.close(); } records = records + "</tbody></table>"; return records; }
From source file:com.ff.reportgenerator.mongodb.DynamicDatabase.java
public String query(String condition) { List<DBObject> list = null; DB myDB = getDB(DB_NAME);//from w w w .j a v a 2 s .c o m DBCollection coll = myDB.getCollection("projects"); DBCursor ret = coll.find(); BasicDBObject sort = new BasicDBObject("PROJECT_ID", 1); ret.sort(sort); try { list = ret.toArray(); } finally { ret.close(); } System.out.println("quering...." + condition); return list.toString(); }
From source file:com.ff.reportgenerator.mongodb.DynamicDatabase.java
public String query(Hashtable conditions) { List<DBObject> list = null; DB myDB = getDB(DB_NAME);//from w w w. j av a2 s . co m DBCollection coll = myDB.getCollection("projects"); BasicDBObject cond = new BasicDBObject(); Set<String> keySet = conditions.keySet(); Iterator<String> it = keySet.iterator(); while (it.hasNext()) { String key = it.next(); String value = (String) conditions.get(key); if (value == null || value.equals("All")) { continue; } Pattern pattern = null; if (key.equals("Project_Phase")) { if (value.equals("Ongoing")) { BasicDBList dlist = new BasicDBList(); dlist.add(new BasicDBObject(key, new BasicDBObject("$ne", "Completed"))); dlist.add(new BasicDBObject(key, new BasicDBObject("$ne", "Eng-Complete"))); dlist.add(new BasicDBObject(key, new BasicDBObject("$ne", "Canceled"))); dlist.add(new BasicDBObject(key, new BasicDBObject("$ne", "Publication"))); cond.append("$and", dlist); } else if (value.equals("Complete")) { ArrayList<String> slist = new ArrayList(); slist.add("Completed"); slist.add("Eng-Complete"); slist.add("Publication"); cond.append(key, new BasicDBObject("$in", slist)); //Limited to FY15 projects //pattern = Pattern.compile("^.*15-\\[.*$", Pattern.CASE_INSENSITIVE); //Limited to FY16 projects pattern = Pattern.compile("^.*16-.*$", Pattern.CASE_INSENSITIVE); cond.append("ISVe_Goal", pattern); } } else if (key.equals("Keywords") && value.equals("Non-OPI")) { // not like 'OPI' pattern = Pattern.compile("^((?!OPI).)*$", Pattern.CASE_INSENSITIVE); cond.append(key, pattern); } else { // like '*OPI*' pattern = Pattern.compile("^.*" + value + ".*$", Pattern.CASE_INSENSITIVE); cond.append(key, pattern); } System.out.println(key + ":" + value); } DBCursor ret = coll.find(cond); BasicDBObject sort = new BasicDBObject("PROJECT_ID", 1); ret.sort(sort); try { list = ret.toArray(); } finally { ret.close(); } //System.out.println(list.toString()); return list.toString(); }
From source file:com.fpt.xml.hth.db.lib.DAO.MovieDAO.java
public List<MovieTheaterSessionDTO> getAll() { connection();/* ww w .j a va 2 s. c o m*/ List<MovieTheaterSessionDTO> lst = new ArrayList<MovieTheaterSessionDTO>(); DBCollection collection = movieCollection; DBCursor cursor = collection.find(); while (cursor.hasNext()) { BasicDBObject basic = (BasicDBObject) cursor.next(); MovieTheaterSessionDTO movieDto = converter.convertBasicObjectToModel(basic); lst.add(movieDto); } cursor.close(); mongoClient.close(); return lst; }