List of usage examples for com.mongodb DBCursor iterator
@Override
public Iterator<DBObject> iterator()
Creates a copy of this cursor object that can be iterated.
From source file:org.ow2.play.governance.storage.MongoPatternRegistry.java
License:Open Source License
@Override public List<Pattern> all() throws GovernanceExeption { List<Pattern> result = new ArrayList<Pattern>(); DBCursor cursor = getDbCollection().find(); Iterator<DBObject> iter = cursor.iterator(); while (iter.hasNext()) { DBObject dbo = iter.next();/* ww w . j a v a 2 s . c om*/ if (logger.isLoggable(Level.FINE)) { logger.fine("Extracting Pattern : " + dbo); } Pattern s = Helper.toPattern(dbo); if (s != null) { result.add(s); } } return result; }
From source file:org.ow2.play.governance.storage.MongoSubscriptionRegistry.java
License:Open Source License
@Override @WebMethod//from w w w . ja va 2s . com public List<Subscription> getSubscriptions() { if (logger.isLoggable(Level.FINE)) { logger.fine("Getting subscritions"); } DBCursor cursor = getDbCollection().find(); Iterator<DBObject> iter = cursor.iterator(); List<Subscription> result = new ArrayList<Subscription>(); while (iter.hasNext()) { DBObject dbo = iter.next(); if (logger.isLoggable(Level.FINE)) { logger.fine("Extracting subscription : " + dbo); } Subscription s = toSubscription(dbo); if (s != null) { result.add(toSubscription(dbo)); } } return result; }
From source file:org.ow2.play.governance.storage.MongoSubscriptionRegistry.java
License:Open Source License
@Override @WebMethod//ww w . j a v a2 s . c o m public List<Subscription> getSubscriptions(@WebParam(name = "filter") Subscription filter) { List<Subscription> result = null; if (filter == null) { return getSubscriptions(); } result = new ArrayList<Subscription>(); DBObject f = new BasicDBObject(); if (filter.getDate() >= 0L) { f.put(DATE_KEY, Long.toString(filter.getDate())); } if (filter.getId() != null) { f.put(ID_KEY, filter.getId()); } if (filter.getProvider() != null) { f.put(PRODUCER_KEY, filter.getProvider()); } if (filter.getSubscriber() != null) { f.put(SUBSCRIBER_KEY, filter.getSubscriber()); } if (filter.getStatus() != null) { f.put(STATUS_KEY, filter.getStatus()); } // use the dot notation to search inner args if (filter.getTopic() != null) { if (filter.getTopic().getName() != null) { f.put(TOPIC_KEY + "." + TOPIC_NAME_KEY, filter.getTopic().getName()); } if (filter.getTopic().getNs() != null) { f.put(TOPIC_KEY + "." + TOPIC_NS_KEY, filter.getTopic().getNs()); } if (filter.getTopic().getPrefix() != null) { f.put(TOPIC_KEY + "." + TOPIC_PREFIX_KEY, filter.getTopic().getNs()); } } logger.fine("Filtering with : " + f); DBCursor cursor = getDbCollection().find(f); Iterator<DBObject> iter = cursor.iterator(); while (iter.hasNext()) { DBObject dbo = iter.next(); if (logger.isLoggable(Level.FINE)) { logger.fine("Extracting subscription : " + dbo); } Subscription s = toSubscription(dbo); if (s != null) { result.add(toSubscription(dbo)); } } return result; }
From source file:org.ow2.play.metadata.mongodb.MongoMetadataServiceImpl.java
License:Open Source License
@Override @WebMethod//from ww w . j a v a 2s .c o m public List<MetaResource> list() throws MetadataException { checkInitialized(); List<MetaResource> result = new ArrayList<MetaResource>(); DBCursor cursor = this.collection.find(); Iterator<DBObject> iter = cursor.iterator(); while (iter.hasNext()) { DBObject dbObject = iter.next(); if (dbObject != null) { if (logger.isLoggable(Level.FINE)) { logger.fine(dbObject.toString()); } MetaResource mr = bsonAdapter.readMetaResource(dbObject); if (mr != null) { result.add(mr); } } else { if (logger.isLoggable(Level.FINE)) { logger.fine("Null object, not added"); } } } return result; }
From source file:org.ow2.play.metadata.mongodb.MongoMetadataServiceImpl.java
License:Open Source License
protected List<DBObject> findAll(Resource resource) { List<DBObject> result = new ArrayList<DBObject>(); BasicDBObject query = new BasicDBObject(); BasicDBObject resourceObject = new BasicDBObject(); resourceObject.put("name", resource.getName()); resourceObject.put("url", resource.getUrl()); query.put("resource", resourceObject); DBCursor cursor = this.collection.find(query); Iterator<DBObject> iter = cursor.iterator(); while (iter.hasNext()) { result.add(iter.next());/* w w w .j a va 2s.c o m*/ } return result; }
From source file:org.ow2.play.service.registry.mongo.RegistryImpl.java
License:Open Source License
@Override @WebMethod/*from w ww . j av a 2 s. com*/ public List<String> keys() throws RegistryException { if (logger.isLoggable(Level.FINE)) { logger.fine("Get keys"); } checkInitialized(); List<String> result = new ArrayList<String>(); DBCursor cursor = collection.find(); Iterator<DBObject> iter = cursor.iterator(); while (iter.hasNext()) { DBObject dbObject = iter.next(); if (dbObject != null && dbObject.get(NAME_KEY) != null) { result.add(dbObject.get(NAME_KEY).toString()); } } return result; }
From source file:org.sipfoundry.commons.userdb.ValidUsers.java
License:Open Source License
/** * Loading all users into memory is an extremely expensive call for large systems (10K-50K user system). * Consider refactoring your code to not call this method. * * @return// w w w . jav a 2 s. c o m */ public List<User> getValidUsers() { List<User> users = new ArrayList<User>(); try { DBCursor cursor = getEntityCollection().find(QueryBuilder.start(VALID_USER).is(Boolean.TRUE).get()); Iterator<DBObject> objects = cursor.iterator(); while (objects.hasNext()) { DBObject validUser = objects.next(); if (!validUser.get(ID).toString().startsWith("User")) { BasicDBList aliasesObj = (BasicDBList) validUser.get(ALIASES); if (aliasesObj != null) { for (int i = 0; i < aliasesObj.size(); i++) { DBObject aliasObj = (DBObject) aliasesObj.get(i); users.add(extractValidUserFromAlias(aliasObj)); } } } else { users.add(extractValidUser(validUser)); } } } catch (Exception e) { e.printStackTrace(); } return users; }
From source file:org.sipfoundry.commons.userdb.ValidUsers.java
License:Open Source License
/** * Loading all users into memory is an extremely expensive call for large systems (10K-50K user system). * Consider refactoring your code to not call this method. * * @return//from ww w . j a v a 2s.co m */ public List<User> getUsersWithImEnabled() { List<User> users = new ArrayList<User>(); DBCursor cursor = getEntityCollection().find(QueryBuilder.start(IM_ENABLED).is(Boolean.TRUE).get()); Iterator<DBObject> objects = cursor.iterator(); while (objects.hasNext()) { DBObject user = objects.next(); users.add(extractUser(user)); } return users; }
From source file:org.sipfoundry.commons.userdb.ValidUsers.java
License:Open Source License
/** * Returns a list of all im ids (of users with im enabled) * * @return//w ww.j a v a2 s. c om */ public List<String> getAllImIdsInGroup(String group) { List<String> imIds = new ArrayList<String>(); DBCursor cursor = getEntityCollection() .find(QueryBuilder.start(GROUPS).is(group).and(IM_ENABLED).is(Boolean.TRUE).get()); Iterator<DBObject> objects = cursor.iterator(); while (objects.hasNext()) { DBObject user = objects.next(); imIds.add(user.get(IM_ID).toString()); } return imIds; }
From source file:org.sipfoundry.commons.userdb.ValidUsers.java
License:Open Source License
public List<User> getUsersUpdatedAfter(Long ms) { List<User> users = new ArrayList<User>(); DBObject query = QueryBuilder.start(ENTITY_NAME).is(ENTITY_NAME_USER).and(MongoConstants.TIMESTAMP) .greaterThan(ms).get();//from w w w . ja va 2 s .c om DBCursor cursor = getEntityCollection().find(query); Iterator<DBObject> objects = cursor.iterator(); while (objects.hasNext()) { DBObject user = objects.next(); users.add(extractUser(user)); } return users; }