List of usage examples for com.mongodb.client MongoCursor hasNext
@Override
boolean hasNext();
From source file:Dao.AccessDataNOSQL.java
License:Open Source License
/** * Mtodo para cargar en memoria los usuarios *///from ww w .ja va 2 s . c om @Override public void cargarUserDAO() { MongoCollection<Document> collec = consultaBD("nosql", "ratings"); MongoCursor<Document> cursor = collec.find().iterator(); while (cursor.hasNext()) { try { String stringjson = cursor.next().toJson(); JSONObject obj1 = new JSONObject(stringjson); String userId = obj1.getString("userId"); User u = new User(); //Integer.parseInt(userId); u.setUserId(Integer.parseInt(userId)); getUserDAO().add(u); } catch (JSONException ex) { Logger.getLogger(AccessDataNOSQL.class.getName()).log(Level.SEVERE, null, ex); } } cursor.close(); }
From source file:dao.DaoDocumentos.java
public List<Compra> buscarCompras() { MongoClient client = new MongoClient("localhost", 27017); MongoDatabase dataBase = client.getDatabase("bdnc-loja"); MongoCollection<Document> collection = dataBase.getCollection("vendas"); List<Compra> compras = new ArrayList<>(); MongoCursor<Document> cursor = collection.find().iterator(); while (cursor.hasNext()) { Compra compra = new Compra(); compras.add(compra.convertFromDocument(cursor.next())); }//from www.j av a2s . co m client.close(); return compras; }
From source file:data.Activity.java
License:Open Source License
public static Activity getByPrimaryKey(int id, DBManagerMongo manager) throws Exception { MongoCollection<Document> coll = manager.getDb().getCollection("activity"); FindIterable<Document> doc = coll.find(eq("id", id)); MongoCursor<Document> cursor = doc.iterator(); if (!cursor.hasNext()) throw new Exception("no such record"); return extractActivity(cursor.next(), manager); }
From source file:data.Activity.java
License:Open Source License
public static List<Activity> getAll(DBManagerMongo manager) throws Exception { ArrayList<Activity> list = new ArrayList<>(); MongoCollection<Document> coll = manager.getDb().getCollection("activity"); FindIterable<Document> doc = coll.find(); MongoCursor<Document> cursor = doc.iterator(); while (cursor.hasNext()) list.add(extractActivity(cursor.next(), manager)); return list;//from w ww. j a v a 2s . c o m }
From source file:data.Project.java
License:Open Source License
public static Project getByPrimaryKey(int projectId, DBManagerMongo manager) throws Exception { MongoCollection<Document> coll = manager.getDb().getCollection("project"); FindIterable<Document> doc = coll.find(eq("id", projectId)); MongoCursor<Document> cursor = doc.iterator(); if (!cursor.hasNext()) throw new Exception("no such record"); return extractProject(cursor.next()); }
From source file:data.Project.java
License:Open Source License
public static String getDescriptionByProjectName(String projectName, DBManagerMongo manager) throws Exception { MongoCollection<Document> coll = manager.getDb().getCollection("project"); FindIterable<Document> doc = coll.find(eq("name", projectName)); MongoCursor<Document> cursor = doc.iterator(); if (!cursor.hasNext()) throw new Exception("no such record"); return cursor.next().getString("description"); }
From source file:data.Project.java
License:Open Source License
public static List<Project> getAll(DBManagerMongo manager) throws Exception { ArrayList<Project> list = new ArrayList<>(); MongoCollection<Document> coll = manager.getDb().getCollection("project"); FindIterable<Document> doc = coll.find(); MongoCursor<Document> cursor = doc.iterator(); while (cursor.hasNext()) list.add(extractProject(cursor.next())); return list;//from w w w .j av a 2 s.c om }
From source file:data.ProjectMember.java
License:Open Source License
public static ProjectMember getByPrimaryKey(String userLoginName, int projectId, DBManagerMongo manager) throws Exception { MongoCollection<Document> coll = manager.getDb().getCollection("project_member"); FindIterable<Document> doc = coll .find(and(eq("user_login_name", userLoginName), eq("project_id", projectId))); MongoCursor<Document> cursor = doc.iterator(); if (!cursor.hasNext()) throw new Exception("no such record"); return extractMember(cursor.next(), manager); }
From source file:data.ProjectMember.java
License:Open Source License
public static ArrayList<ProjectMember> getMembersByProjectId(int projectId, DBManagerMongo manager) throws Exception { ArrayList<ProjectMember> list = new ArrayList<>(); MongoCollection<Document> coll = manager.getDb().getCollection("project_member"); FindIterable<Document> doc = coll.find(eq("project_id", projectId)); MongoCursor<Document> cursor = doc.iterator(); while (cursor.hasNext()) list.add(extractMember(cursor.next(), manager)); return list;//from www.ja v a 2 s .co m }
From source file:data.ProjectMember.java
License:Open Source License
public static ArrayList<ProjectMember> getInvolvedProjects(String loginName, DBManagerMongo manager) throws Exception { ArrayList<ProjectMember> list = new ArrayList<>(); MongoCollection<Document> coll = manager.getDb().getCollection("project_member"); FindIterable<Document> doc = coll.find(and(eq("user_login_name", loginName), eq("role", "MEMBER"))); MongoCursor<Document> cursor = doc.iterator(); while (cursor.hasNext()) list.add(extractMember(cursor.next(), manager)); return list;/*w w w .j ava 2s . c o m*/ }