List of usage examples for com.mongodb DBCursor next
@Override
public DBObject next()
From source file:cn.vlabs.clb.server.storage.mongo.extend.MyGridFS.java
License:Apache License
public List<MyGridFSDBFile> find(DBObject query, DBObject sort) { List<MyGridFSDBFile> files = new ArrayList<MyGridFSDBFile>(); DBCursor c = null; try {/*from w w w . j ava2s. co m*/ c = _filesCollection.find(query); if (sort != null) { c.sort(sort); } while (c.hasNext()) { files.add(_fix(c.next())); } } finally { if (c != null) { c.close(); } } return files; }
From source file:cn.vlabs.clb.server.storage.mongo.MongoStorageService.java
License:Apache License
private Set<Integer> queryChunkMap(String storageKey, String tableName) { DB db = options.getCollection(TABLE_TEMP_KEY).getDB(); DBObject query = new BasicDBObject(); query.put("storageKey", new ObjectId(storageKey)); Set<Integer> result = new HashSet<Integer>(); DBCollection chunkTable = db.getCollection(tableName + ".chunks"); DBObject ref = new BasicDBObject(); ref.put("files_id", new ObjectId(storageKey)); DBObject keys = new BasicDBObject(); keys.put("n", 1); DBCursor cursor = chunkTable.find(ref, keys); while (cursor.hasNext()) { DBObject o = cursor.next(); result.add(Integer.parseInt(o.get("n").toString())); }//w w w. jav a 2 s. c o m return result; }
From source file:cn.vlabs.clb.server.storage.mongo.MongoStorageService.java
License:Apache License
public String queryMd5(String storageKey, String tableName) { DB db = options.getCollection(TABLE_TEMP_KEY).getDB(); DBObject query = new BasicDBObject(); query.put("storageKey", new ObjectId(storageKey)); DBCollection fileTable = db.getCollection(tableName + ".files"); DBCursor cursor = fileTable.find(query); if (cursor.hasNext()) { DBObject o = cursor.next(); return o.get("md5").toString(); }//from w ww. j a v a2s .c om return ""; }
From source file:co.edu.uniandes.cloud.simuladorcredito.persistencia.SecuenciaDAO.java
public Secuencia leer(String llave) { BasicDBObject query = new BasicDBObject("tabla", llave); DBCursor cursor = col.find(query); try {//from w w w . j a v a 2s. c o m if (cursor.hasNext()) { Secuencia s = new Secuencia(); DBObject obj = cursor.next(); s.setTabla((String) obj.get("tabla")); s.setSecuencia((Long) obj.get("secuencia")); return s; } else { return null; } } finally { cursor.close(); } }
From source file:co.edu.uniandes.cloud.simuladorcredito.persistencia.SuperDAO.java
protected DBObject leerBD(String campo, Object valor) { BasicDBObject query = new BasicDBObject(campo, valor); DBCursor cursor = col.find(query); try {/*from w w w. j a v a2 s . co m*/ if (cursor.hasNext()) { return cursor.next(); } else { return null; } } finally { cursor.close(); } }
From source file:co.edu.uniandes.cloud.simuladorcredito.persistencia.SuperDAO.java
protected List<DBObject> leerVariosBD(String campo, Object valor) { List<DBObject> lista = new ArrayList(); BasicDBObject query = new BasicDBObject(campo, valor); DBCursor cursor = col.find(query); try {// ww w . jav a 2 s .c o m while (cursor.hasNext()) { lista.add(cursor.next()); } } finally { cursor.close(); } return lista; }
From source file:co.edu.uniandes.csw.Arquidalgos.usuario.persistence._UsuarioPersistence.java
License:MIT License
@SuppressWarnings("unchecked") public List<UsuarioDTO> getUsuarios() { // Query q = entityManager.createQuery("select u from UsuarioEntity u"); // return UsuarioConverter.entity2PersistenceDTOList(q.getResultList()); List listaUsuarios = new ArrayList(); DBCollection coll = db.getCollection("UsuarioDTO"); BasicDBObject query = new BasicDBObject(); DBCursor cursor = coll.find(query); while (cursor.hasNext()) { DBObject dBObject = cursor.next(); UsuarioDTO user = new UsuarioDTO(); user.setName((String) dBObject.get("name")); user.setContrasena((String) dBObject.get("contrasena")); user.setEmail((String) dBObject.get("email")); user.setFacebookId((String) dBObject.get("facebookId")); //TODO imprimir usuarios listaUsuarios.add(user);// w w w .j ava2 s . c o m } cursor.close(); return listaUsuarios; }
From source file:com.aankam.servlet.MongoCrudServlet.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> * methods./*from www.ja v a 2s . c o m*/ * * @param request servlet request * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { MongoClientURI uri = new MongoClientURI("mongodb://Username:Pasword@ds061721.mongolab.com:61721/cs612"); MongoClient client = new MongoClient(uri); DB db = client.getDB(uri.getDatabase()); response.setContentType("text/html;charset=UTF-8"); String serialNo = request.getParameter("serialNo"); String name = request.getParameter("name"); String emailId = request.getParameter("emailId"); String operation = request.getParameter("operation"); BasicDBObject customer; BasicDBObject updateQuery; BasicDBObject deleteQuery; BasicDBObject searchQuery; DBCollection customersCollection; customersCollection = db.getCollection("Customers"); DBObject searchResult = null; boolean flag = false; DBCursor cursor; switch (operation) { case "create": customer = new BasicDBObject(); customer.put("serialNo", serialNo); customer.put("name", name); customer.put("emailId", emailId); customersCollection.insert(customer); break; case "update": updateQuery = new BasicDBObject(); updateQuery.append("serialNo", serialNo); cursor = customersCollection.find(updateQuery); customer = new BasicDBObject(); customer.put("serialNo", serialNo); customer.put("name", name); customer.put("emailId", emailId); if (cursor.hasNext()) { customersCollection.update(updateQuery, customer); flag = true; } break; case "delete": deleteQuery = new BasicDBObject(); deleteQuery.append("serialNo", serialNo); customersCollection.remove(deleteQuery); break; case "search": searchQuery = new BasicDBObject(); searchQuery.append("serialNo", serialNo); cursor = customersCollection.find(searchQuery); while (cursor.hasNext()) { searchResult = cursor.next(); } break; default: break; } try (PrintWriter out = response.getWriter()) { /* TODO output your page here. You may use following sample code. */ out.println("<!DOCTYPE html>"); out.println("<html>"); out.println("<head>"); out.println("<title>Servlet MongoCrudServlet</title>"); out.println("</head>"); out.println("<body>"); switch (operation) { case "create": out.println("<h3>Customer was successfully created.</h3>"); break; case "update": if (flag == true) { out.println("<h3>Customer was successfully updated.</h3>"); } else { out.println("<h3>Customer was not found to update.</h3>"); } break; case "delete": out.println("<h3>Customer was successfully deleted.</h3>"); break; case "search": if (searchResult != null) { out.println("<h3>The following customer was found:</h3>"); out.println("<h4>Serial No :" + searchResult.get("serialNo") + "</h4>"); out.println("<h4>Name :" + searchResult.get("name") + "</h4>"); out.println("<h4>Email Id :" + searchResult.get("emailId") + "</h4>"); } else { out.println("<h3>Customer not found.</h3>"); } break; default: break; } out.println("<a href=\"index.html\">Back to Main Form</a>"); out.println("</body>"); out.println("</html>"); } }
From source file:com.affairs.dao.zaffar.CurrentAffairsDAO.java
License:Apache License
public DBObject findByObjectId(String ObjectId) { DBObject sayDoProjectObj = null;// w ww. j ava 2 s .c om DBCursor sayDoProjectCursor = null; try { sayDoProjectCursor = this.saydoCollection.find(new BasicDBObject("_id", ObjectId)); while (sayDoProjectCursor.hasNext()) { sayDoProjectObj = sayDoProjectCursor.next(); } } catch (Exception exp) { System.out.println(exp.getMessage()); } finally { sayDoProjectCursor.close(); } return sayDoProjectObj; }
From source file:com.affairs.dao.zaffar.CurrentAffairsDAO.java
License:Apache License
public List findAllObjectByCondition(BasicDBObject whereConditionObj) { List<DBObject> projectList = new ArrayList<DBObject>(); DBCursor projectListCursor = this.saydoCollection.find(whereConditionObj).limit(SAYDO_UI_DISPLAY_LIMIT); DBObject projectCursor = new BasicDBObject(); try {// www. j a va 2 s . c o m while (projectListCursor.hasNext()) { projectCursor = projectListCursor.next(); projectList.add(projectCursor); } } catch (Exception exp) { System.out.println(exp.getMessage()); } finally { projectListCursor.close(); } return projectList; }