List of usage examples for com.mongodb.client MongoCursor next
@Override TResult next();
From source file:Dao.AccessDataNOSQL.java
License:Open Source License
/** * Mtodo para cargar en memoria las calificaciones *//* w w w . jav a 2s. co m*/ @Override public void cargarEventosDAO() { 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"); String movieID = obj1.getString("movieId"); String rating = obj1.getString("rating"); String timestamp = obj1.getString("timestamp"); User u = new User(Integer.parseInt(userId)); Item i = new Movie(Integer.parseInt(movieID)); double rat = Double.parseDouble(rating); int tim = Integer.parseInt(timestamp); Events evento = new Events(u, (Movie) i, rat, tim); getEventsDAO().add(evento); } catch (JSONException ex) { Logger.getLogger(AccessDataNOSQL.class.getName()).log(Level.SEVERE, null, ex); } } cursor.close(); }
From source file:Dao.AccessDataNOSQL.java
License:Open Source License
/** * Metodo para cargar en memoria los elementos * *//* www . j a v a 2 s . com*/ @Override public void cargarItemsDAO() { MongoCollection<Document> collec = consultaBD("nosql", "movies"); MongoCursor<Document> cursor = collec.find().iterator(); while (cursor.hasNext()) { try { String stringjson = cursor.next().toJson(); //JsonReader jr=new JsonReader(stringjson); JSONObject obj1 = new JSONObject(stringjson); String movieId = obj1.getString("movieId"); String title = obj1.getString("title"); String genres = obj1.getString("genres"); Movie peli = new Movie(); peli.setId(Integer.parseInt(movieId)); peli.setTitle(title); peli.setGenre(genres); getItemsDAO().add(peli); } catch (JSONException ex) { Logger.getLogger(AccessDataNOSQL.class.getName()).log(Level.SEVERE, null, ex); System.err.print("error en cargarItemsDAO en AccesoNoSQL"); } } cursor.close(); }
From source file:Dao.AccessDataNOSQL.java
License:Open Source License
/** * Mtodo para cargar en memoria los usuarios *//* ww w . j a v a 2s .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())); }/* www .j a v a 2 s.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 ww w . ja v a2 s. c om*/ }
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 . ja v a2s . com }
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); }