List of usage examples for com.mongodb BasicDBObject get
public Object get(final String key)
From source file:Vehicle_exit.java
public void fetch() { try {// w ww . jav a 2 s. c o m MongoClient mc = new MongoClient("localhost", 27017); DB db = mc.getDB("parking_system"); DBCollection collectionx = db.getCollection("entry_info"); if (veh_count == 2) { BasicDBObject queryx = new BasicDBObject(); BasicDBObject fieldx = new BasicDBObject(); fieldx.put("vehno", 1); DBCursor cursorx = collectionx.find(queryx, fieldx); while (cursorx.hasNext()) { System.out.println("hmmmWOW---n"); BasicDBObject objx = (BasicDBObject) cursorx.next(); char[] temp; temp = objx.getString("vehno").toCharArray(); char last; last = temp[temp.length - 1]; if (last == '2') { vehno_combo.addItem(objx.get("vehno").toString()); } System.out.println("hello"); } } else if (veh_count == 4) { BasicDBObject queryx = new BasicDBObject(); BasicDBObject fieldx = new BasicDBObject(); fieldx.put("vehno", 1); DBCursor cursorx = collectionx.find(queryx, fieldx); while (cursorx.hasNext()) { System.out.println("hmmmWOW---n"); BasicDBObject objx = (BasicDBObject) cursorx.next(); char[] temp; temp = objx.getString("vehno").toCharArray(); char last; last = temp[temp.length - 1]; if (last == '4') { vehno_combo.addItem(objx.get("vehno").toString()); //vehno = vehno_combo.getSelectedItem().toString(); } System.out.println("hello"); } } else { BasicDBObject queryx = new BasicDBObject(); BasicDBObject fieldx = new BasicDBObject(); fieldx.put("vehno", 1); DBCursor cursorx = collectionx.find(queryx, fieldx); while (cursorx.hasNext()) { System.out.println("hmmmWOW---n"); BasicDBObject objx = (BasicDBObject) cursorx.next(); char[] temp; temp = objx.getString("vehno").toCharArray(); char last; last = temp[temp.length - 1]; if (last == '6') { vehno_combo.addItem(objx.get("vehno").toString()); //vehno = vehno_combo.getSelectedItem().toString(); } System.out.println("hello"); } } } catch (Exception e) { } }
From source file:gMIRC_handler.java
/** * Register a user to the server (used in RegUser) * * @param username//from w ww. j a v a2 s. c o m * @return code */ private int AddUser(String username) { int ret = 0; try { MongoClient mongoClient = new MongoClient(); DB db = mongoClient.getDB("mirc"); DBCollection coll = db.getCollection("activeUser"); BasicDBObject query = new BasicDBObject("username", username); DBCursor cursor = coll.find(query); try { if (cursor.hasNext()) { Date now = new Date(); long timestamp_now = now.getTime(); long treshold = timestamp_now - (1000 * 10); //10 BasicDBObject temp = (BasicDBObject) cursor.next(); Date time_temp = (Date) temp.get("timestamp"); long timestamp_temp = time_temp.getTime(); if (timestamp_temp < treshold) { ret = 2; System.out.println(username + " has joined back!"); } else { ret = 1; System.err.println(username + " has been used !"); } } else { java.util.Date date = new java.util.Date(); BasicDBObject doc = new BasicDBObject("username", username).append("timestamp", date); coll.insert(doc); System.out.println(username + " online !"); } } finally { cursor.close(); } } catch (UnknownHostException ex) { Logger.getLogger(gMIRC_handler.class.getName()).log(Level.SEVERE, null, ex); } return ret; }
From source file:gMIRC_handler.java
private int PutMessage(String username, String channelname, String msg) { int ret = 0;//from w w w . j a va2 s . co m try { MongoClient mongoClient = new MongoClient(); DB db = mongoClient.getDB("mirc"); DBCollection coll = db.getCollection("inbox"); DBCollection coll2 = db.getCollection("channelCollection"); BasicDBObject query2 = new BasicDBObject("channel", channelname); BasicDBObject query = new BasicDBObject("channel", channelname).append("username", username); DBCursor cursor = coll2.find(query); try { if (cursor.hasNext()) { DBCursor cursor2 = coll2.find(query2); System.out.println("Got message from " + username); try { java.util.Date date = new java.util.Date(); while (cursor2.hasNext()) { ret = 1; BasicDBObject temp = (BasicDBObject) cursor2.next(); String target = temp.get("username").toString(); BasicDBObject put = new BasicDBObject("target", target).append("username", username) .append("channel", channelname).append("message", msg) .append("timestamp", date.getTime()); coll.insert(put); ret = 0; } } finally { cursor2.close(); } } else { ret = 2; System.out.println(username + " not registered to Channel : " + channelname); } } finally { cursor.close(); } } catch (UnknownHostException ex) { ret = 1; Logger.getLogger(gMIRC_handler.class.getName()).log(Level.SEVERE, null, ex); } return ret; }
From source file:TeacherSection.java
private void GradeListValueChanged(javax.swing.event.ListSelectionEvent evt) {//GEN-FIRST:event_GradeListValueChanged // TODO add your handling code here: if (!evt.getValueIsAdjusting()) { String selected = GradeList.getSelectedValue(); int grade = 0; int section = 0; for (int i = 0; i < selected.length(); ++i) { if (selected.charAt(i) == '-') { grade = (int) Double.parseDouble(selected.substring(0, i)); section = (int) Double.parseDouble(selected.substring(i + 1)); }/*ww w. j av a 2s .com*/ } DBCollection coll = db.getCollection("student"); BasicDBObject andQuery = new BasicDBObject(); List<BasicDBObject> obj = new ArrayList<BasicDBObject>(); obj.add(new BasicDBObject("grade", grade)); obj.add(new BasicDBObject("section", section)); andQuery.put("$and", obj); DBCursor cursor = coll.find(andQuery); while (cursor.hasNext()) { DBObject object = cursor.next(); this.FirstnameField.setText(object.get("firstname").toString()); this.MidnameField.setText(object.get("mid_name").toString()); LastnameField.setText(object.get("lastname").toString()); BasicDBList marks = (BasicDBList) object.get("marks"); for (int i = 0; i < marks.size(); ++i) { BasicDBObject mark = (BasicDBObject) marks.get(i); if (mark.getString("teacher").equals(firstname)) { if (mark.get("mid") == null) { MidField.setText("-1"); FinalField.setText("-1"); } else if (mark.get("mid") != null && mark.get("final") == null) { MidField.setText(mark.getString("mid")); FinalField.setText("-1"); } else { MidField.setText(mark.getString("mid")); FinalField.setText(mark.getString("final")); } break; } } int reply = JOptionPane.showConfirmDialog(null, "if you want to update press yes", "Update or Skip", JOptionPane.YES_NO_OPTION); if (reply == JOptionPane.YES_OPTION) { int midmark = Integer.parseInt(JOptionPane.showInputDialog("Please input mark for mid: ")); int finalmark = Integer.parseInt(JOptionPane.showInputDialog("Please input mark for final: ")); BasicDBObject andQuery1 = new BasicDBObject(); List<BasicDBObject> obj1 = new ArrayList<BasicDBObject>(); obj1.add(new BasicDBObject("firstname", FirstnameField.getText())); obj1.add(new BasicDBObject("mid_name", MidnameField.getText())); obj1.add(new BasicDBObject("lastname", LastnameField.getText())); obj1.add(new BasicDBObject("grade", grade)); obj1.add(new BasicDBObject("section", section)); obj1.add(new BasicDBObject("marks.teacher", firstname)); andQuery1.put("$and", obj1); BasicDBObject data = new BasicDBObject(); if (midmark == -1 && finalmark == -1) { JOptionPane.showMessageDialog(null, "No data was updated!"); } else if (midmark != -1 && finalmark != -1) { data.put("marks.$.mid", midmark); JOptionPane.showMessageDialog(null, "data was updated ."); } else { data.put("marks.$.mid", midmark); data.put("marks.$.final", finalmark); JOptionPane.showMessageDialog(null, "data was updated ."); } BasicDBObject command = new BasicDBObject(); command.put("$set", data); coll.update(andQuery1, command); } } } }
From source file:Parent.java
private void formComponentResized(java.awt.event.ComponentEvent evt) {//GEN-FIRST:event_formComponentResized // TODO add your handling code here: DBCollection coll = db.getCollection("parent"); BasicDBObject andQuery = new BasicDBObject(); List<BasicDBObject> obj = new ArrayList<BasicDBObject>(); obj.add(new BasicDBObject("firstname", firstname)); obj.add(new BasicDBObject("lastname", lastname)); andQuery.put("$and", obj); DBCursor cursor = coll.find(andQuery); while (cursor.hasNext()) { BasicDBList sons = (BasicDBList) cursor.next().get("sons"); String data[] = new String[sons.size()]; for (int j = 0; j < sons.size(); ++j) { BasicDBObject son = (BasicDBObject) sons.get(j); data[j] = son.get("name").toString(); }// w w w . java2 s . c o m SonList.setListData(data); } }
From source file:Parent.java
private void SonListValueChanged(javax.swing.event.ListSelectionEvent evt) {//GEN-FIRST:event_SonListValueChanged // TODO add your handling code here: if (!evt.getValueIsAdjusting()) { DefaultTableModel model = (DefaultTableModel) jTable1.getModel(); model.setRowCount(0);/*from w ww .j a va 2 s.c o m*/ String selected = SonList.getSelectedValue(); DBCollection coll = db.getCollection("student"); BasicDBObject andQuery = new BasicDBObject(); List<BasicDBObject> obj = new ArrayList<BasicDBObject>(); obj.add(new BasicDBObject("firstname", selected)); obj.add(new BasicDBObject("mid_name", firstname)); obj.add(new BasicDBObject("lastname", lastname)); andQuery.put("$and", obj); DBCursor cursor = coll.find(andQuery); while (cursor.hasNext()) { BasicDBList marks = (BasicDBList) cursor.next().get("marks"); for (int j = 0; j < marks.size(); ++j) { BasicDBObject mark = (BasicDBObject) marks.get(j); String material = mark.get("course").toString(); String teacher = mark.get("teacher").toString(); if (mark.get("mid") == null) { Object[] row = { material, teacher, "not readay", "not ready" }; model.addRow(row); } else if (mark.get("mid") != null && mark.get("final") == null) { Object[] row = { material, teacher, mark.get("mid"), "not ready" }; model.addRow(row); } else { Object[] row = { material, teacher, mark.get("mid"), mark.get("final") }; model.addRow(row); } } } } }
From source file:search.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> * methods./*from www . ja v a 2 s .c om*/ * * @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 { response.setContentType("text/html;charset=UTF-8"); 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 search</title>"); out.println("</head>"); out.println("<body>"); out.println("<h1>Servlet search at " + request.getContextPath() + "</h1>"); String srch_id = request.getParameter("search"); DB db; Mongo mongo = new Mongo("LocalHost", 27017); db = mongo.getDB("local"); out.println("db connected is..." + db); DBCollection collection = db.getCollection("StartupHun"); out.println("table used connected is..." + collection); BasicDBObject query = new BasicDBObject("founded_year", new BasicDBObject("$gt", 2005)); BasicDBObject cat = new BasicDBObject(); //query.put("name", srch_id); DBCursor cursor = collection.find(); // Print out "highest" priority items BasicDBObject query1 = null; int i = 0; while (cursor.hasNext()) { //out.println(cursor.next()); query1 = (BasicDBObject) cursor.next(); out.println((Integer) query1.get("founded_year") + " " + i); i++; } out.println("</body>"); out.println("</html>"); } }
From source file:TeacherOne.java
private void GetdataBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_GetdataBtnActionPerformed // TODO add your handling code here: stuFirst = FirstnameField.getText(); stuMid = MidnameField.getText();//from w w w. j a v a2s .c om stuLast = LastnameField.getText(); grade = Integer.parseInt(GradeField.getText()); section = Integer.parseInt(SectionField.getText()); DBCollection coll = db.getCollection("student"); BasicDBObject andQuery = new BasicDBObject(); List<BasicDBObject> obj = new ArrayList<BasicDBObject>(); obj.add(new BasicDBObject("firstname", stuFirst)); obj.add(new BasicDBObject("mid_name", stuMid)); obj.add(new BasicDBObject("lastname", stuLast)); obj.add(new BasicDBObject("grade", grade)); obj.add(new BasicDBObject("section", section)); andQuery.put("$and", obj); DBCursor cursor = coll.find(andQuery); if (cursor.count() != 0) { UpdateBtn.setVisible(true); MidField.setVisible(true); FinalField.setVisible(true); jLabel6.setVisible(true); jLabel7.setVisible(true); jLabel8.setVisible(true); BasicDBList marks = (BasicDBList) cursor.next().get("marks"); for (int j = 0; j < marks.size(); ++j) { BasicDBObject mark = (BasicDBObject) marks.get(j); if (mark.getString("teacher").equals(firstname)) { if (mark.get("mid") == null) { MidField.setText("-1"); FinalField.setText("-1"); } else if (mark.get("mid") != null && mark.get("final") == null) { MidField.setText(mark.getString("mid")); FinalField.setText("-1"); } else { MidField.setText(mark.getString("mid")); FinalField.setText(mark.getString("final")); } } } } else { JOptionPane.showMessageDialog(null, "wrong data,try again!"); FirstnameField.setText(""); MidnameField.setText(""); LastnameField.setText(""); GradeField.setText(""); SectionField.setText(""); } }
From source file:gMIRC_server.java
public static void cleaner() { try {//from ww w. jav a2s . c om boolean hard_clean = false; MongoClient mongoClient = new MongoClient(); DB db = mongoClient.getDB("mirc"); DBCollection coll = db.getCollection("activeUser"); DBCursor cursor = coll.find(); try { Date now = new Date(); long timestamp_now = now.getTime(); long treshold = timestamp_now - (1000 * 60 * 5); //5 minutes while (cursor.hasNext()) { hard_clean = true; BasicDBObject temp = (BasicDBObject) cursor.next(); Date time_temp = (Date) temp.get("timestamp"); long timestamp_temp = time_temp.getTime(); if (timestamp_temp < treshold) { String target = temp.getString("username"); gMIRC_handler.SoftDelete(target); } } HardClean(); } finally { cursor.close(); } } catch (UnknownHostException ex) { Logger.getLogger(gMIRC_server.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:act.installer.bing.BingSearchRanker.java
License:Open Source License
/** * Updates a TSV row (actually a Map from header to value) with InChI, names and usage information. * @param o BasicDBObject containing InChI, and xrefs.{BING, CHEBI, WIKIPEDIA} info * @param row TSV row (map from TSV header to value) to be updated */// ww w . ja v a 2 s . c o m private void updateRowWithChemicalInformation(BasicDBObject o, Map<String, String> row) { String inchi = o.get("InChI").toString(); row.put(BingRankerHeaderFields.INCHI.name(), inchi); BasicDBObject xref = (BasicDBObject) o.get("xref"); BasicDBObject bing = (BasicDBObject) xref.get("BING"); BasicDBObject bingMetadata = (BasicDBObject) bing.get("metadata"); row.put(BingRankerHeaderFields.BEST_NAME.name(), bingMetadata.get("best_name").toString()); row.put(BingRankerHeaderFields.TOTAL_COUNT_SEARCH_RESULTS.name(), bingMetadata.get("total_count_search_results").toString()); NamesOfMolecule namesOfMolecule = mongoDB.getNamesFromBasicDBObject(o); Set<String> names = namesOfMolecule.getAllNames(); row.put(BingRankerHeaderFields.ALL_NAMES.name(), names.toString()); if (includeChebiApplications) { BasicDBObject chebi = (BasicDBObject) xref.get("CHEBI"); if (chebi != null) { BasicDBObject chebiMetadata = (BasicDBObject) chebi.get("metadata"); BasicDBObject chebiApplications = (BasicDBObject) chebiMetadata.get("applications"); if (chebiApplications != null) { row.put(BingRankerHeaderFields.CHEBI_MAIN_APPLICATIONS.name(), chebiApplications.get("main_applications").toString()); row.put(BingRankerHeaderFields.CHEBI_DIRECT_APPLICATIONS.name(), chebiApplications.get("direct_applications").toString()); } else { LOGGER.debug("ChEBI cross-reference found, but no ChEBI applications for %s", inchi); row.put(BingRankerHeaderFields.CHEBI_MAIN_APPLICATIONS.name(), EMPTY_STRING); row.put(BingRankerHeaderFields.CHEBI_DIRECT_APPLICATIONS.name(), EMPTY_STRING); } } else { LOGGER.debug("No ChEBI cross-reference found for %s", inchi); } } if (includeWikipediaUrl) { BasicDBObject wikipedia = (BasicDBObject) xref.get("WIKIPEDIA"); if (wikipedia != null) { row.put(BingRankerHeaderFields.WIKIPEDIA_URL.name(), wikipedia.get("dbid").toString()); } else { LOGGER.debug("No Wikipedia cross-reference found for %s", inchi); row.put(BingRankerHeaderFields.WIKIPEDIA_URL.name(), EMPTY_STRING); } } if (includeUsageExplorerUrl) { row.put(BingRankerHeaderFields.USAGE_EXPLORER_URL.name(), getUsageExplorerURLStringFromInchi(inchi)); } }