List of usage examples for com.mongodb DBObject get
Object get(String key);
From source file:co.edu.uniandes.cloud.simuladorcredito.persistencia.AdministradorDAO.java
public Administrador login(Administrador usr) { DBObject doc = super.leerBD("email", usr.getEmail()); Administrador a = new Administrador(); a.setId((Long) doc.get("id")); a.setApellidos((String) doc.get("apellidos")); a.setEmail((String) doc.get("email")); a.setNombres((String) doc.get("nombres")); a.setPassword((String) doc.get("password")); return a;/*from www . j a v a2 s . c o m*/ }
From source file:co.edu.uniandes.cloud.simuladorcredito.persistencia.CuotaDAO.java
public List<Cuota> leer(Long planId) { List<DBObject> docs = super.leerVariosBD("idPlan", planId); List<Cuota> cuotas = new ArrayList(); for (DBObject doc : docs) { Cuota a = new Cuota(); a.setId((Long) doc.get("id")); a.setNumeroCuota((Integer) doc.get("numeroCuota")); a.setIntereses((Double) doc.get("intereses")); a.setCapital((Double) doc.get("capital")); a.setTotal((Double) doc.get("total")); a.setSaldo((Double) doc.get("saldo")); a.setIdPlan((Long) doc.get("idPlan")); cuotas.add(a);/*from w w w . j a va2 s.c om*/ } Collections.sort(cuotas); return cuotas; }
From source file:co.edu.uniandes.cloud.simuladorcredito.persistencia.LineaDAO.java
public Linea leer(Long llave) { DBObject doc = super.leerBD("id", llave); Linea a = new Linea(); a.setId((Long) doc.get("id")); a.setNombre((String) doc.get("nombre")); a.setTasa((Double) doc.get("tasa")); a.setAdministrador((Long) doc.get("administrador")); return a;/*from ww w. j a v a 2s. co m*/ }
From source file:co.edu.uniandes.cloud.simuladorcredito.persistencia.LineaDAO.java
public List<Linea> getLineaAdministrador(Long idAdministrador) { List<DBObject> documentos = super.leerVariosBD("administrador", idAdministrador); List<Linea> lineas = new ArrayList(); for (DBObject doc : documentos) { Linea a = new Linea(); a.setId((Long) doc.get("id")); a.setNombre((String) doc.get("nombre")); a.setTasa((Double) doc.get("tasa")); a.setAdministrador((Long) doc.get("administrador")); lineas.add(a);//from w ww. ja v a 2s.c o m } return lineas; }
From source file:co.edu.uniandes.cloud.simuladorcredito.persistencia.PlanPagoDAO.java
public PlanPago leer(Long llave) { DBObject doc = super.leerBD("id", llave); PlanPago a = new PlanPago(); a.setId((Long) doc.get("id")); a.setFechaCreacion((Date) doc.get("fechaCreacion")); a.setDocumento((String) doc.get("documento")); a.setValor((Integer) doc.get("valor")); a.setPlazo((Integer) doc.get("plazo")); a.setEstado((String) doc.get("estado")); a.setNivelRiesgo((Double) doc.get("nivelRiesgo")); a.setFechaNacimiento((Date) doc.get("fechaNacimiento")); a.setFechaModificacion((Date) doc.get("fechaModificacion")); a.setLinea(new Linea()); DBObject l = (DBObject) doc.get("linea"); a.getLinea().setId((Long) l.get("id")); a.getLinea().setNombre((String) l.get("nombre")); a.getLinea().setTasa((Double) l.get("tasa")); a.setCuotas(new CuotaDAO().leer(a.getId())); return a;// w ww. j ava 2 s. c om }
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);/* w ww . j a va2 s.co m*/ try { 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.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);//w w w .j av a 2s . c o m 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); } 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./*w w w .j a v a 2 s . 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.act.biointerpretation.analytics.ReactionDeletion.java
License:Open Source License
public static void searchForDroppedReactions(NoSQLAPI srcApi, NoSQLAPI sinkApi, File outputFile) throws IOException { Set<Long> srcIds = new HashSet<>(); DBIterator iterator = srcApi.getReadDB().getIteratorOverReactions( new BasicDBObject("$query", new BasicDBObject()).append("$orderby", new BasicDBObject("_id", 1)), new BasicDBObject("_id", true)); while (iterator.hasNext()) { DBObject obj = iterator.next(); Object id = obj.get("_id"); if (id instanceof Integer) { Integer idi = (Integer) id; srcIds.add(idi.longValue()); } else {/* w w w. ja va 2s .c o m*/ String msg = String.format("Found unexpected %s value for _id in src DB: %s", id.getClass().getName(), id); LOGGER.error(msg); throw new RuntimeException(msg); } } iterator.close(); Iterator<Reaction> sinkRxns = sinkApi.readRxnsFromInKnowledgeGraph(); while (sinkRxns.hasNext()) { Reaction rxn = sinkRxns.next(); for (JSONObject protein : rxn.getProteinData()) { if (protein.has("source_reaction_id")) { Long srcId = protein.getLong("source_reaction_id"); srcIds.remove(srcId); } else LOGGER.error("Found protein without source id for reaction %d", rxn.getUUID()); } } if (srcIds.size() == 0) { LOGGER.info( "No source read DB ids were unaccounted for in the write DB. Exiting without writing output."); return; } List<Long> sortedSrcIds = new ArrayList<>(srcIds); Collections.sort(sortedSrcIds); try (TSVWriter<String, String> writer = new TSVWriter<>(OUTPUT_HEADER)) { writer.open(outputFile); int noProteinReactions = 0; for (Long id : sortedSrcIds) { Reaction rxn = srcApi.readReactionFromInKnowledgeGraph(id); if (rxn == null) { LOGGER.error("Could not read reaction %d from source DB", id); continue; } if (rxn.getProteinData().size() == 0) { LOGGER.debug("Reaction %d has no proteins, and so cannot participate in the provenance chain", rxn.getUUID()); noProteinReactions++; continue; } Map<String, String> row = new HashMap<String, String>(OUTPUT_HEADER.size()) { { put("id", Long.valueOf(rxn.getUUID()).toString()); put("substrates", "{" + StringUtils.join(rxn.getSubstrates(), ",") + "}"); put("products", "{" + StringUtils.join(rxn.getProducts(), ",") + "}"); put("ecnum", rxn.getECNum()); put("easy_desc", rxn.getReactionName()); } }; writer.append(row); writer.flush(); } LOGGER.info("Found %d reactions with no proteins of %d reactions that might have been deleted", noProteinReactions, srcIds.size()); } }
From source file:com.almende.eve.state.mongo.MongoStateFactory.java
License:Apache License
@Override public Iterator<String> getAllAgentIds() { try {//from w w w. ja va2 s . c o m Find find = getCollection().find().projection("{_id:1}"); Iterable<String> agentIDs = find.map(new ResultHandler<String>() { @Override public String map(DBObject result) { return (String) result.get("_id"); } }); return agentIDs.iterator(); } catch (final Exception e) { LOG.log(Level.WARNING, "getAllAgentIds error", e); } return new ArrayList<String>().iterator(); }