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:MDBInt.DBMongo.java
License:Apache License
/** * Returns an ArraList<String> where each String is a JSONObject in String * version./*from ww w . ja v a2 s . c om*/ * * @param tenant * @param geoShape * @return */ public ArrayList<String> getDatacenters(String tenant, String geoShape) { DB database = this.getDB(tenant); DBCollection collection = database.getCollection("datacenters"); BasicDBObject shape = (BasicDBObject) JSON.parse(geoShape); ArrayList<String> datacenters = new ArrayList(); BasicDBObject geoJSON = (BasicDBObject) shape.get("geometry"); BasicDBObject geometry = new BasicDBObject(); BasicDBObject geoSpazialOperator = new BasicDBObject(); BasicDBObject query = new BasicDBObject(); BasicDBObject constrains = new BasicDBObject("_id", 0); Iterator<DBObject> it; DBCursor cursore; geometry.put("$geometry", geoJSON); geoSpazialOperator.put("$geoIntersects", geometry); query.put("geometry", geoSpazialOperator); cursore = collection.find(query, constrains); it = cursore.iterator(); while (it.hasNext()) { datacenters.add(it.next().toString()); } return datacenters; }
From source file:MDBInt.DBMongo.java
License:Apache License
/** * Returns an ArraList<String> where each String is a JSONObject in String * version.//from www . ja va 2s. c o m * * @param tenant * @param deviceId, this is the Vm Name * @return */ public ArrayList<String> getportinfoes(String tenant, String deviceId) { DB database = this.getDB(tenant); DBCollection collection = database.getCollection("portInfo"); DBCursor cursore; BasicDBObject campi; Iterator<DBObject> it; campi = new BasicDBObject(); campi.put("deviceId", deviceId); cursore = collection.find(new BasicDBObject(), campi); it = cursore.iterator(); ArrayList<String> pI = new ArrayList<String>(); while (it.hasNext()) { pI.add(it.next().toString()); } return pI; }
From source file:MDBInt.DBMongo.java
License:Apache License
public ArrayList<String> findResourceMate(String dbName, String uuid) { BasicDBObject first = new BasicDBObject(); first.put("phisicalResourceId", uuid); DB database = this.getDB(dbName); DBCollection collection = database.getCollection("runTimeInfo"); DBObject obj = null;//from w w w .j a v a 2s .c o m BasicDBObject query = new BasicDBObject(); DBCursor cursore = null; ArrayList<String> mates = new ArrayList(); Iterator<DBObject> it; obj = collection.findOne(first); if (obj != null) { query.put("localResourceName", obj.get("localResourceName")); query.put("stackName", obj.get("stackName")); query.put("resourceName", obj.get("resourceName")); query.put("type", obj.get("type")); query.put("state", false); query.put("idCloud", new BasicDBObject("$ne", obj.get("idCloud"))); System.out.println(query); cursore = collection.find(query); } if (cursore != null) { it = cursore.iterator(); while (it.hasNext()) { mates.add(it.next().toString()); } } return mates; }
From source file:MDBInt.DBMongo.java
License:Apache License
public String findResourceMate(String dbName, String uuid, String dcid) { BasicDBObject first = new BasicDBObject(); first.put("phisicalResourceId", uuid); DB database = this.getDB(dbName); DBCollection collection = database.getCollection("runTimeInfo"); DBObject obj = null;/*from w w w. j a v a 2 s . co m*/ BasicDBObject query = new BasicDBObject(); DBCursor cursore = null; Iterator<DBObject> it; obj = collection.findOne(first); if (obj != null) { query.put("requestUID", obj.get("requestUID")); query.put("uuidTemplate", obj.get("uuidTemplate")); query.put("stackName", obj.get("stackName")); query.put("resourceName", obj.get("resourceName")); query.put("type", obj.get("type")); //query.put("state", false); query.put("idCloud", dcid); System.out.println("MONGO QUERY " + query + " in DB:" + dbName + " for UUID:" + uuid); DBCursor b = collection.find(query).sort(new BasicDBObject("insertTimestamp", -1)).limit(1); Iterator i = b.iterator(); if (b != null && i.hasNext()) return i.next().toString(); else return null; } return null; }
From source file:MDBInt.DBMongo.java
License:Apache License
public ArrayList<String> findALLResourceMate(String dbName, String uuid) { ArrayList<String> finalOb = new ArrayList<String>(); BasicDBObject first = new BasicDBObject(); first.put("phisicalResourceId", uuid); DB database = this.getDB(dbName); DBCollection collection = database.getCollection("runTimeInfo"); DBObject obj = null;/*from w w w. j a v a 2 s . c om*/ BasicDBObject query = new BasicDBObject(); DBCursor cursore = null; Iterator<DBObject> it; obj = collection.findOne(first); if (obj != null) { query.put("requestUID", obj.get("requestUID")); query.put("uuidTemplate", obj.get("uuidTemplate")); query.put("localResourceName", obj.get("localResourceName")); query.put("stackName", obj.get("stackName")); query.put("resourceName", obj.get("resourceName")); query.put("type", obj.get("type")); query.put("state", false); System.out.println("MONGO QUERY " + query + " in DB:" + dbName + " for UUID:" + uuid); DBCursor b = collection.find(query).sort(new BasicDBObject("insertTimestamp", -1)); Iterator i = b.iterator(); if (i.hasNext()) while (i.hasNext()) { DBObject tmp = (DBObject) i.next(); tmp.removeField("_id"); tmp.removeField("insertTimestamp"); finalOb.add(tmp.toString()); } else return null; } return finalOb; }
From source file:MDBInt.DBMongo.java
License:Apache License
public ArrayList<String> findALLResourceMatefromTemplate(String dbName, String uuid) { ArrayList<String> finalOb = new ArrayList<String>(); BasicDBObject first = new BasicDBObject(); first.put("uuidTemplate", uuid); DB database = this.getDB(dbName); DBCollection collection = database.getCollection("runTimeInfo"); DBObject obj = null;//from w w w. j av a2 s . c o m BasicDBObject query = new BasicDBObject(); DBCursor cursore = null; Iterator<DBObject> it; //obj = collection.findOne(first); DBCursor bobj = collection.find(first).sort(new BasicDBObject("insertTimestamp", -1)); obj = bobj.next(); if (obj != null) { query.put("requestUID", obj.get("requestUID")); query.put("uuidTemplate", uuid); query.put("localResourceName", obj.get("localResourceName")); query.put("stackName", obj.get("stackName")); query.put("resourceName", obj.get("resourceName")); query.put("type", obj.get("type")); //query.put("state", false); System.out.println("MONGO QUERY " + query + " in DB:" + dbName + " for UUID:" + uuid); DBCursor b = collection.find(query).sort(new BasicDBObject("insertTimestamp", -1)); Iterator i = b.iterator(); if (i.hasNext()) while (i.hasNext()) { DBObject tmp = (DBObject) i.next(); tmp.removeField("_id"); tmp.removeField("insertTimestamp"); finalOb.add(tmp.toString()); } else return null; } return finalOb; }
From source file:MDBInt.DBMongo.java
License:Apache License
/** * Returns ArrayList with all federatedUser registrated for the * federationUser/* w ww . ja v a 2 s .c o m*/ * * @param dbName * @param collectionName * @param federationUserName * @return * @author gtricomi */ public ArrayList<String> listFederatedUser(String dbName, String collectionName, String federationUserName) { DBCursor cursore; DB dataBase; DBCollection collezione; BasicDBObject campi; Iterator<DBObject> it; dataBase = this.getDB(dbName); collezione = this.getCollection(dataBase, collectionName); campi = new BasicDBObject(); campi.put("federationUser", federationUserName); cursore = collezione.find(campi); it = cursore.iterator(); ArrayList<String> als = new ArrayList(); while (it.hasNext()) { als.add(it.next().get("crediantialList").toString()); } return als; }
From source file:MDBInt.DBMongo.java
License:Apache License
public ArrayList<String> listTemplates(String dbName) { DBCursor cursore; DB dataBase;//from ww w. j av a2 s . c o m DBCollection collezione; Iterator<DBObject> it; dataBase = this.getDB(dbName); collezione = dataBase.getCollection("templateInfo"); cursore = collezione.find(); it = cursore.iterator(); ArrayList<String> templatesInfo = new ArrayList(); while (it.hasNext()) { templatesInfo.add(it.next().toString()); } return templatesInfo; }
From source file:MDBInt.DBMongo.java
License:Apache License
public String getMapInfo(String dbName, String uuidTemplate) { DB database = this.getDB(dbName); DBCollection collection = database.getCollection("runTimeInfo"); DBObject obj = null, datacenter, punto, country, geoShape; BasicDBObject query = new BasicDBObject(); DBCursor cursore = null; Set<String> attivi = new HashSet<String>(); ArrayList<String> listCloud = new ArrayList(); Iterator<DBObject> it;//from w w w.j a v a 2s . c o m String idCloud, idmEndpoint, idRisorsa, nameRisorsa; boolean isPresent, linkAttivo; MapInfo map; Shape s; boolean state; Risorse r; int i, j; Collegamenti link; Object array[]; query.put("uuidTemplate", uuidTemplate); cursore = collection.find(query).sort(new BasicDBObject("insertTimestamp", -1)).limit(1); map = new MapInfo(); if (cursore != null) { it = cursore.iterator(); while (it.hasNext()) { //oggetto map info obj = it.next(); idCloud = (String) obj.get("idCloud"); isPresent = listCloud.contains(idCloud); if (!isPresent) { datacenter = this.getDatacenterFromId(dbName, idCloud); idmEndpoint = (String) datacenter.get("idmEndpoint"); state = (boolean) obj.get("state"); punto = (DBObject) datacenter.get("geometry"); country = this.getFirstCountry(dbName, punto); geoShape = (DBObject) country.get("geometry"); System.out.println("geogeo" + geoShape); s = new Shape(idCloud, idmEndpoint, geoShape.toString(), state); if (state) { attivi.add(idCloud); idRisorsa = (String) obj.get("phisicalResourceId"); nameRisorsa = (String) obj.get("resourceName"); r = new Risorse(idRisorsa, nameRisorsa); s.addResource(r); } listCloud.add(idCloud); map.addShape(s); } else { s = map.getShape(idCloud); state = (boolean) obj.get("state"); if (state) { s.setState(state); attivi.add(idCloud); idRisorsa = (String) obj.get("phisicalResourceId"); nameRisorsa = (String) obj.get("resourceName"); r = new Risorse(idRisorsa, nameRisorsa); s.addResource(r); } } } array = attivi.toArray(); for (i = 0; i < array.length; i++) { for (j = i + 1; j < array.length; j++) { //verifico se il link e' attivo linkAttivo = this.testLink(dbName, (String) array[i], (String) array[j]); if (linkAttivo) { link = new Collegamenti((String) array[i], (String) array[j]); map.addCollegamento(link); } } } } return map.toString(); }
From source file:MDBInt.DBMongo.java
License:Apache License
public ArrayList getCountry(String tenant, DBObject shape) { //{"geometry": {$geoIntersects: {$geometry: { "coordinates" : [ 15.434675, 38.193164 ], "type" : "Point" }}}} DB database = this.getDB(tenant); DBCollection collection = database.getCollection("Countries"); ArrayList<String> datacenters = new ArrayList(); BasicDBObject geometry = new BasicDBObject("$geometry", shape); BasicDBObject geoSpazialOperator = new BasicDBObject("$geoIntersects", geometry); BasicDBObject query = new BasicDBObject("geometry", geoSpazialOperator); BasicDBObject constrains = new BasicDBObject("_id", 0); Iterator<DBObject> it;//from w w w .j a v a2 s . co m DBCursor cursore; cursore = collection.find(query, constrains); it = cursore.iterator(); while (it.hasNext()) { datacenters.add(it.next().toString()); } return datacenters; }