List of usage examples for com.mongodb BasicDBObject getString
public String getString(final String key)
From source file:Vehicle_exit.java
public void fetch() { try {//w ww .j a v a2 s .co 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:Vehicle_exit.java
private void Exit_buttonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_Exit_buttonActionPerformed // TODO add your handling code here: try {//ww w .j a v a2 s .co m vehno = vehno_combo.getSelectedItem().toString(); vehno_copy = vehno; System.out.println("in button number niald" + vehno); MongoClient mc = new MongoClient("localhost", 27017); DB db = mc.getDB("parking_system"); DBCollection collection = db.getCollection("entry_info"); BasicDBObject query_time = new BasicDBObject(); BasicDBObject field_time = new BasicDBObject(); field_time.put("intime", 1); DBCursor cursor = collection.find(query_time, field_time); BasicDBObject query_token = new BasicDBObject(); BasicDBObject field_token = new BasicDBObject(); field_time.put("vehno", 1); DBCursor cursor_token = collection.find(query_token, field_token); while (cursor.hasNext()) { BasicDBObject obj_time = (BasicDBObject) cursor.next(); in_time_mills = Long.parseLong(obj_time.getString("intime")); BasicDBObject obj_token = (BasicDBObject) cursor_token.next(); //db_token = obj_token.getInt("_id"); vehno_db = obj_token.getString("vehno"); System.out.println(vehno_db); System.out.println("hello"); System.out.println("hey ayu"); DBCollection collection1 = db.getCollection("vehicle_count"); DBCollection collection2 = db.getCollection("statistics"); vehno = vehno_copy; if (veh_count == 2) { //vehno = vehno + "W2"; if (vehno.equals(vehno_db)) { flag = 1; BasicDBObject deleteObject = new BasicDBObject(); //deleteObject.put("_id",Token); deleteObject.put("vehno", vehno); DBCursor findQuery = collection.find(deleteObject); collection.remove(deleteObject); int count_bike; BasicDBObject query = new BasicDBObject(); BasicDBObject field = new BasicDBObject(); field.put("wheeler_2", 1); DBCursor cursor1 = collection1.find(query, field); BasicDBObject obj = (BasicDBObject) cursor1.next(); count_bike = obj.getInt("wheeler_2"); System.out.println(count_bike); BasicDBObject searchUpdate = new BasicDBObject(); searchUpdate.append("wheeler_2", count_bike); BasicDBObject UpdateObject = new BasicDBObject(); UpdateObject.append("$set", new BasicDBObject("wheeler_2", count_bike - 1)); collection1.update(searchUpdate, UpdateObject); System.out.println("Checking..."); time_diff = exit_time_mills - in_time_mills; time_diff = time_diff / 1000; time_diff = time_diff / 60; System.out.println("difftime" + time_diff); if (time_diff > 60) charges = 20 + (time_diff) / 2; else charges = 20; //updating session... int income_bike; BasicDBObject query2 = new BasicDBObject(); BasicDBObject field2 = new BasicDBObject(); field2.put("2wheeler_income", 1); DBCursor cursor2 = collection2.find(query2, field2); BasicDBObject obj2 = (BasicDBObject) cursor2.next(); income_bike = obj2.getInt("2wheeler_income"); System.out.println(income_bike); BasicDBObject searchUpdate2 = new BasicDBObject(); searchUpdate2.append("2wheeler_income", income_bike); BasicDBObject UpdateObject2 = new BasicDBObject(); UpdateObject2.append("$set", new BasicDBObject("2wheeler_income", income_bike + charges)); collection2.update(searchUpdate2, UpdateObject2); JOptionPane.showMessageDialog(null, "Vehicle Out !\n" + /*"In Time : " + in_time_mills + "\n" +*/ "Extra Parking Time : " + time_diff + "Min.\n" + "Charges : " + charges); System.out.println("Checked..."); setVisible(false); new Entry_OR_Exit().setVisible(true); break; } } else if (veh_count == 4) { //vehno = vehno + "W4"; if (vehno.equals(vehno_db)) { flag = 1; BasicDBObject deleteObject = new BasicDBObject(); //deleteObject.put("_id",Token); deleteObject.put("vehno", vehno); DBCursor findQuery = collection.find(deleteObject); collection.remove(deleteObject); int count_car; BasicDBObject query = new BasicDBObject(); BasicDBObject field = new BasicDBObject(); field.put("wheeler_4", 1); DBCursor cursor1 = collection1.find(query, field); BasicDBObject obj = (BasicDBObject) cursor1.next(); count_car = obj.getInt("wheeler_4"); System.out.println(count_car); BasicDBObject searchUpdate = new BasicDBObject(); searchUpdate.append("wheeler_4", count_car); BasicDBObject UpdateObject = new BasicDBObject(); UpdateObject.append("$set", new BasicDBObject("wheeler_4", count_car - 1)); collection1.update(searchUpdate, UpdateObject); System.out.println("Checking...2"); time_diff = exit_time_mills - in_time_mills; time_diff = time_diff / 1000; time_diff = time_diff / 60; System.out.println("difftime" + time_diff); if (time_diff > 60) charges = 40 + (time_diff) * 3 / 2; else charges = 40; //Session update.... int income_car; BasicDBObject query2 = new BasicDBObject(); BasicDBObject field2 = new BasicDBObject(); field2.put("4wheeler_income", 1); DBCursor cursor2 = collection2.find(query2, field2); BasicDBObject obj2 = (BasicDBObject) cursor2.next(); income_car = obj2.getInt("4wheeler_income"); System.out.println(income_car); BasicDBObject searchUpdate2 = new BasicDBObject(); searchUpdate2.append("4wheeler_income", income_car); BasicDBObject UpdateObject2 = new BasicDBObject(); UpdateObject2.append("$set", new BasicDBObject("4wheeler_income", income_car + charges)); collection2.update(searchUpdate2, UpdateObject2); JOptionPane.showMessageDialog(null, "Vehicle Out !\n" + /*"In Time : " + in_time_mills + "\n" +*/ "Extra Parking Time : " + time_diff + "Min.\n" + "Charges : " + charges); System.out.println("Checking...2"); setVisible(false); new Entry_OR_Exit().setVisible(true); break; } } else { //vehno = vehno + "W6"; if (vehno.equals(vehno_db)) { flag = 1; BasicDBObject deleteObject = new BasicDBObject(); //deleteObject.put("_id",Token); deleteObject.put("vehno", vehno); DBCursor findQuery = collection.find(deleteObject); collection.remove(deleteObject); int count_other; BasicDBObject query = new BasicDBObject(); BasicDBObject field = new BasicDBObject(); field.put("other", 1); DBCursor cursor1 = collection1.find(query, field); BasicDBObject obj = (BasicDBObject) cursor1.next(); count_other = obj.getInt("other"); System.out.println(count_other); BasicDBObject searchUpdate = new BasicDBObject(); searchUpdate.append("other", count_other); BasicDBObject UpdateObject = new BasicDBObject(); UpdateObject.append("$set", new BasicDBObject("other", count_other - 1)); collection1.update(searchUpdate, UpdateObject); System.out.println("Checking...3"); time_diff = exit_time_mills - in_time_mills; time_diff = time_diff / 1000; time_diff = time_diff / 60; System.out.println("difftime" + time_diff); if (time_diff > 60) charges = 60 + (time_diff); else charges = 60; //sessiuon update.... int income_other; BasicDBObject query2 = new BasicDBObject(); BasicDBObject field2 = new BasicDBObject(); field2.put("other_income", 1); DBCursor cursor2 = collection2.find(query2, field2); BasicDBObject obj2 = (BasicDBObject) cursor2.next(); income_other = obj2.getInt("other_income"); System.out.println(income_other); BasicDBObject searchUpdate2 = new BasicDBObject(); searchUpdate2.append("other_income", income_other); BasicDBObject UpdateObject2 = new BasicDBObject(); UpdateObject2.append("$set", new BasicDBObject("other_income", income_other + charges)); collection2.update(searchUpdate2, UpdateObject2); JOptionPane.showMessageDialog(null, "Vehicle Out !\n" + /*"In Time : " + in_time_mills + "\n" +*/ "Extra Parking Time : " + time_diff + "Min.\n" + "Charges : " + charges); System.out.println("Checked...3"); setVisible(false); new Entry_OR_Exit().setVisible(true); break; } } //} } if (flag == 0) { JOptionPane.showMessageDialog(null, "Invalid Vehicle Number or Type"); setVisible(false); new Entry_OR_Exit().setVisible(true); } /* BasicDBObject searchUpdate = new BasicDBObject(); searchUpdate.append("wheeler_2", count_bike); BasicDBObject UpdateObject = new BasicDBObject(); UpdateObject.append("$set", new BasicDBObject("wheeler_2", count_bike + 1)); collection.update(searchUpdate, UpdateObject); */ //} } catch (Exception e) { } }
From source file:gMIRC_handler.java
public String GetMessage(String username) { String ret = ""; try {//from w w w .ja va2 s . c o m MongoClient mongoClient = new MongoClient(); DB db = mongoClient.getDB("mirc"); DBCollection coll = db.getCollection("inbox"); BasicDBObject query = new BasicDBObject("target", username); JSONObject obj = new JSONObject(); JSONArray arr = new JSONArray(); DBCursor cursor = coll.find(query); try { while (cursor.hasNext()) { BasicDBObject temp = (BasicDBObject) cursor.next(); JSONObject sav = new JSONObject(); sav.put("target", temp.getString("target")); sav.put("username", temp.getString("username")); sav.put("channel", temp.getString("channel")); sav.put("message", temp.getString("message")); sav.put("timestamp", temp.getLong("timestamp")); arr.add(sav); coll.remove(temp); } obj.put("msg", arr); ret = obj.toJSONString(); } finally { cursor.close(); } } catch (UnknownHostException ex) { Logger.getLogger(gMIRC_handler.class.getName()).log(Level.SEVERE, null, ex); } UpdateLastActive(username); return ret; }
From source file:gMIRC_handler.java
private int PutMessageWild(String username, String msg) { int ret = 1;/*from w w w . ja v a 2 s .co m*/ try { MongoClient mongoClient = new MongoClient(); DB db = mongoClient.getDB("mirc"); DBCollection coll2 = db.getCollection("channelCollection"); BasicDBObject query = new BasicDBObject("username", username); System.out.println("Wild message appear from " + username + " !"); DBCursor cursor = coll2.find(query); try { while (cursor.hasNext()) { ret = 1; BasicDBObject temp = (BasicDBObject) cursor.next(); String channelname = temp.getString("channel"); ret = ret & PutMessage(username, channelname, msg); } } finally { cursor.close(); } } catch (UnknownHostException ex) { Logger.getLogger(gMIRC_handler.class.getName()).log(Level.SEVERE, null, ex); } return ret; }
From source file:TeacherSection.java
private void formComponentResized(java.awt.event.ComponentEvent evt) {//GEN-FIRST:event_formComponentResized // TODO add your handling code here: DBCollection coll = db.getCollection("user"); BasicDBObject andQuery = new BasicDBObject(); List<BasicDBObject> obj = new ArrayList<BasicDBObject>(); String username = login.user; obj.add(new BasicDBObject("user", username)); andQuery.put("$and", obj); DBCursor cursor = coll.find(andQuery); while (cursor.hasNext()) { lastname = cursor.next().get("lastname").toString(); }// w w w. j av a 2 s. c o m DBCollection coll1 = db.getCollection("teacher"); BasicDBObject andQuery1 = new BasicDBObject(); List<BasicDBObject> obj1 = new ArrayList<BasicDBObject>(); obj1.add(new BasicDBObject("firstname", firstname)); obj1.add(new BasicDBObject("lastname", lastname)); andQuery1.put("$and", obj1); cursor = coll1.find(andQuery1); while (cursor.hasNext()) { BasicDBList teache = (BasicDBList) cursor.next().get("teach"); String data[] = new String[teache.size()]; for (int j = 0; j < teache.size(); ++j) { BasicDBObject teach = (BasicDBObject) teache.get(j); String val = teach.getString("grade") + "-" + teach.getString("section"); data[j] = val; } GradeList.setListData(data); } }
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)); }/* w w w .j a v a 2 s . co m*/ } 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:Session_details.java
private void clear_buttonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_clear_buttonActionPerformed // TODO add your handling code here: updateSession("2wheeler_count");//, "2wheeler_count" ); updateSession("2wheeler_income");// , "2wheeler_income"); updateSession("4wheeler_count");// , "4wheeler_count"); updateSession("4wheeler_income");// , "4wheeler_income"); updateSession("other_count");//, "other_count"); updateSession("other_income");//, "other_income"); Calendar cal = Calendar.getInstance(); SimpleDateFormat dt = new SimpleDateFormat("HH:mm:ss"); time_str = cal.getTime().toString(); try {//from w w w .ja v a 2 s .c o m String s; MongoClient mc = new MongoClient("localhost", 27017); DB db = mc.getDB("parking_system"); DBCollection collection2 = db.getCollection("statistics"); BasicDBObject query = new BasicDBObject(); BasicDBObject field = new BasicDBObject(); field.put("time", 1); DBCursor cursor = collection2.find(query, field); BasicDBObject obj = (BasicDBObject) cursor.next(); s = obj.getString("time"); System.out.println(s); BasicDBObject searchUpdate = new BasicDBObject(); searchUpdate.append("time", s); BasicDBObject UpdateObject = new BasicDBObject(); UpdateObject.append("$set", new BasicDBObject("time", time_str)); collection2.update(searchUpdate, UpdateObject); } catch (Exception e) { } JOptionPane.showMessageDialog(null, "Session Details Cleared!"); setVisible(false); new Admin_rights().setVisible(true); }
From source file:Veehicle_entry.java
private void Entry_buttonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_Entry_buttonActionPerformed // TODO add your handling code here: try {//from ww w .j a va2 s. c o m String name, vehno, mobno; Random rand = new Random(); token = rand.nextInt(10000); name = Name_field.getText(); mobno = mobno_field.getText(); vehno = vehno_strt1.getSelectedItem().toString() + "-" + vehno_strt2.getText() + "-" + vehno_strt3.getSelectedItem().toString() + "-" + vehno_strt4.getText(); //System.out.println(vehno); MongoClient mc = new MongoClient("localhost", 27017); DB db = mc.getDB("parking_system"); DBCollection collection = db.getCollection("entry_info"); DBCollection collection1 = db.getCollection("vehicle_count"); DBCollection collection2 = db.getCollection("statistics"); if (veh_count == 2) { vehno = vehno + "W2"; BasicDBObject queryx = new BasicDBObject(); BasicDBObject fieldx = new BasicDBObject(); fieldx.put("vehno", 1); DBCursor cursorx = collection.find(queryx, fieldx); while (cursorx.hasNext()) { BasicDBObject objx = (BasicDBObject) cursorx.next(); String temp; temp = objx.getString("vehno"); if (temp.equals(vehno)) { JOptionPane.showMessageDialog(null, "vehicle number already exits!\n Entry Rejected!"); exists = 1; setVisible(false); new Veehicle_entry(veh_count).setVisible(true); } } if (exists == 0) { int count_bike; BasicDBObject doc = new BasicDBObject("_id", token).append("name", name) .append("mobileno", mobno).append("vehno", vehno).append("intime", time_mills); validator = validate(collection, doc); if (validator == 1) { //Updating vehicle count.... BasicDBObject query = new BasicDBObject(); BasicDBObject field = new BasicDBObject(); field.put("wheeler_2", 1); DBCursor cursor = collection1.find(query, field); BasicDBObject obj = (BasicDBObject) cursor.next(); count_bike = obj.getInt("wheeler_2"); System.out.println(count_bike); BasicDBObject searchUpdate = new BasicDBObject(); searchUpdate.append("wheeler_2", count_bike); BasicDBObject UpdateObject = new BasicDBObject(); UpdateObject.append("$set", new BasicDBObject("wheeler_2", count_bike + 1)); collection1.update(searchUpdate, UpdateObject); //updating session... int cnt_bike; BasicDBObject query2 = new BasicDBObject(); BasicDBObject field2 = new BasicDBObject(); field2.put("2wheeler_count", 1); DBCursor cursor2 = collection2.find(query2, field2); BasicDBObject obj2 = (BasicDBObject) cursor2.next(); cnt_bike = obj2.getInt("2wheeler_count"); System.out.println(cnt_bike); BasicDBObject searchUpdate2 = new BasicDBObject(); searchUpdate2.append("2wheeler_count", cnt_bike); BasicDBObject UpdateObject2 = new BasicDBObject(); UpdateObject2.append("$set", new BasicDBObject("2wheeler_count", cnt_bike + 1)); collection2.update(searchUpdate2, UpdateObject2); setVisible(false); new Entry_OR_Exit().setVisible(true); } } } else if (veh_count == 4) { vehno = vehno + "W4"; BasicDBObject queryx = new BasicDBObject(); BasicDBObject fieldx = new BasicDBObject(); fieldx.put("vehno", 1); DBCursor cursorx = collection.find(queryx, fieldx); while (cursorx.hasNext()) { BasicDBObject objx = (BasicDBObject) cursorx.next(); String temp; temp = objx.getString("vehno"); if (temp.equals(vehno)) { JOptionPane.showMessageDialog(null, "vehicle number already exits!\n Entry Rejected!"); exists = 1; setVisible(false); new Veehicle_entry(veh_count).setVisible(true); } } if (exists == 0) { int count_car; BasicDBObject doc = new BasicDBObject("_id", token).append("name", name) .append("mobileno", mobno).append("vehno", vehno).append("intime", time_mills); validator = validate(collection, doc); if (validator == 1) { BasicDBObject query = new BasicDBObject(); BasicDBObject field = new BasicDBObject(); field.put("wheeler_4", 1); DBCursor cursor = collection1.find(query, field); BasicDBObject obj = (BasicDBObject) cursor.next(); count_car = obj.getInt("wheeler_4"); System.out.println(count_car); BasicDBObject searchUpdate = new BasicDBObject(); searchUpdate.append("wheeler_4", count_car); BasicDBObject UpdateObject = new BasicDBObject(); UpdateObject.append("$set", new BasicDBObject("wheeler_4", count_car + 1)); collection1.update(searchUpdate, UpdateObject); //updating session... int cnt_car; BasicDBObject query2 = new BasicDBObject(); BasicDBObject field2 = new BasicDBObject(); field2.put("4wheeler_count", 1); DBCursor cursor2 = collection2.find(query2, field2); BasicDBObject obj2 = (BasicDBObject) cursor2.next(); cnt_car = obj2.getInt("4wheeler_count"); System.out.println(cnt_car); BasicDBObject searchUpdate2 = new BasicDBObject(); searchUpdate2.append("4wheeler_count", cnt_car); BasicDBObject UpdateObject2 = new BasicDBObject(); UpdateObject2.append("$set", new BasicDBObject("4wheeler_count", cnt_car + 1)); collection2.update(searchUpdate2, UpdateObject2); setVisible(false); new Entry_OR_Exit().setVisible(true); } } } else { vehno = vehno + "W6"; BasicDBObject queryx = new BasicDBObject(); BasicDBObject fieldx = new BasicDBObject(); fieldx.put("vehno", 1); DBCursor cursorx = collection.find(queryx, fieldx); while (cursorx.hasNext()) { BasicDBObject objx = (BasicDBObject) cursorx.next(); String temp; temp = objx.getString("vehno"); if (temp.equals(vehno)) { JOptionPane.showMessageDialog(null, "vehicle number already exits!\n Entry Rejected!"); exists = 1; setVisible(false); new Veehicle_entry(veh_count).setVisible(true); } } if (exists == 0) { int count_other; BasicDBObject doc = new BasicDBObject("_id", token).append("name", name) .append("mobileno", mobno).append("vehno", vehno).append("intime", time_mills); validator = validate(collection, doc); if (validator == 1) { System.out.println("Came 1"); BasicDBObject query = new BasicDBObject(); BasicDBObject field = new BasicDBObject(); field.put("other", 1); DBCursor cursor = collection1.find(query, field); BasicDBObject obj = (BasicDBObject) cursor.next(); count_other = obj.getInt("other"); System.out.println(count_other); BasicDBObject searchUpdate = new BasicDBObject(); searchUpdate.append("other", count_other); BasicDBObject UpdateObject = new BasicDBObject(); UpdateObject.append("$set", new BasicDBObject("other", count_other + 1)); collection1.update(searchUpdate, UpdateObject); //updating session... int cnt_other; BasicDBObject query2 = new BasicDBObject(); BasicDBObject field2 = new BasicDBObject(); field2.put("other_count", 1); DBCursor cursor2 = collection2.find(query2, field2); BasicDBObject obj2 = (BasicDBObject) cursor2.next(); cnt_other = obj2.getInt("other_count"); System.out.println(cnt_other); BasicDBObject searchUpdate2 = new BasicDBObject(); searchUpdate2.append("other_count", cnt_other); BasicDBObject UpdateObject2 = new BasicDBObject(); UpdateObject2.append("$set", new BasicDBObject("other_count", cnt_other + 1)); collection2.update(searchUpdate2, UpdateObject2); setVisible(false); new Entry_OR_Exit().setVisible(true); } } } } catch (Exception e) { } }
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 ww . ja va2 s .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 w w w. j a v a 2 s. com*/ 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); } }