List of usage examples for com.mongodb BasicDBObject BasicDBObject
public BasicDBObject()
From source file:Publisher.java
public static void mongoInsertTest2(DB db, List<TripUpdate> tripUpdates) { DBCollection coll = db.getCollection("testCollection"); BasicDBObject doc = new BasicDBObject(); // Now, copy and update current agency data to mongo. for (int i = 0; i < tripUpdates.size(); i++) { doc.append("_id", tripUpdates.get(i).tripId + ": " + new Date().getTime()); coll.save(doc);/*from w ww . j a va 2 s. c o m*/ for (int j = 0; j < tripUpdates.get(i).stopUpdates.size(); j++) { doc = new BasicDBObject(); doc.append("_id", tripUpdates.get(i).tripId + "-" + j + ": " + new Date().getTime()) .append("arrivalDelay", tripUpdates.get(i).stopUpdates.get(j).arrivalDelay) .append("arrivalTime", tripUpdates.get(i).stopUpdates.get(j).arrivalTime) .append("departureDelay", tripUpdates.get(i).stopUpdates.get(j).departureDelay) .append("departureTime", tripUpdates.get(i).stopUpdates.get(j).departureTime) .append("stopSeq", tripUpdates.get(i).stopUpdates.get(j).stopSeq) .append("trip", tripUpdates.get(i).tripId); coll.save(doc); } } }
From source file:Publisher.java
public static void mongoInsertTest(DB db, List<VehiclePositionTest> positions) { DBCollection coll = db.getCollection("testCollection"); BasicDBObject doc = new BasicDBObject(); // Now, copy and update current agency data to mongo. for (int i = 0; i < positions.size(); i++) { doc.append("_id", positions.get(i).getVehicleId() + ": " + new Date().getTime()) .append("stopId", positions.get(i).getStopId()).append("tripId", positions.get(i).getTripId()) .append("agencyId", positions.get(i).getAgencyId()) .append("timeOfRecord", positions.get(i).getTimeOfRecord()) .append("timeOfLocationUpdate", positions.get(i).getTimeOfLocationUpdate()) .append("speed", positions.get(i).getSpeed()) .append("currentLocationLat", positions.get(i).getCurrentLocationLat()) .append("currentLocationLon", positions.get(i).getCurrentLocationLon()) .append("odometer", positions.get(i).getOdometer()) .append("currentOrientation", positions.get(i).getCurrentOrientation()) .append("congestionLevel", positions.get(i).getCongestionLevel()) .append("status", positions.get(i).getStatus()).append("label", positions.get(i).getLabel()) .append("licensePlate", positions.get(i).getLicensePlate()); coll.save(doc);// w ww. j a v a 2 s. co m } }
From source file:HW4.java
/** * Creates new form dbGui/* w w w .j a va 2 s . c om*/ */ public HW4() throws SQLException { initComponents(); label = true; finalCat = new ArrayList<>(); fromCheckin = ""; fromCheckinHour = ""; toCheckin = ""; toCheckinHour = ""; operationCheckin = ""; valueCheckin = ""; operationStar = ""; operationVote = ""; valueStar = ""; valueVote = ""; fromReview = ""; toReview = ""; memberSince = ""; operReviewCount = ""; operNoOfFriends = ""; operAvgStar = ""; valueReviewCount = ""; valueNoOfFriends = ""; valueAvgStar = ""; andOrAttribute = ""; Address = ""; proximity = ""; searchFor = ""; latitude = 0.0; longitude = 0.0; operNoOfVotes = ""; valueNoOfVotes = ""; // checkinList = new ArrayList<CheckinDetail>(); mongoClient = new MongoClient("localhost", 27017); memberSinceDateBox.setEnabled(false); reviewCountComboBox.setEnabled(false); reviewCountValueTextField.setEnabled(false); numberOfFriendsComboBox.setEnabled(false); numberOfFriendsValueTextField.setEnabled(false); avgStarComboBox.setEnabled(false); avgStarValueTextField.setEnabled(false); andOrComboBox.setEnabled(false); model = (DefaultListModel) jList1.getModel(); checkinValueTextField.getDocument().addDocumentListener(new DocumentListener() { @Override public void insertUpdate(DocumentEvent e) { text(); } @Override public void removeUpdate(DocumentEvent e) { text(); } @Override public void changedUpdate(DocumentEvent e) { text(); } public void text() { valueCheckin = checkinValueTextField.getText(); //System.out.println(valueCheckin); } }); starsValueTextField.getDocument().addDocumentListener(new DocumentListener() { @Override public void insertUpdate(DocumentEvent e) { text(); } @Override public void removeUpdate(DocumentEvent e) { text(); } @Override public void changedUpdate(DocumentEvent e) { text(); } public void text() { valueStar = starsValueTextField.getText(); //System.out.println(valueStar); } }); votesValueTextField.getDocument().addDocumentListener(new DocumentListener() { @Override public void insertUpdate(DocumentEvent e) { text(); } @Override public void removeUpdate(DocumentEvent e) { text(); } @Override public void changedUpdate(DocumentEvent e) { text(); } public void text() { valueVote = votesValueTextField.getText(); //System.out.println(valueVote); } }); reviewCountValueTextField.getDocument().addDocumentListener(new DocumentListener() { @Override public void insertUpdate(DocumentEvent e) { text(); } @Override public void removeUpdate(DocumentEvent e) { text(); } @Override public void changedUpdate(DocumentEvent e) { text(); } public void text() { valueReviewCount = reviewCountValueTextField.getText(); //System.out.println(valueCheckin); } }); numberOfFriendsValueTextField.getDocument().addDocumentListener(new DocumentListener() { @Override public void insertUpdate(DocumentEvent e) { text(); } @Override public void removeUpdate(DocumentEvent e) { text(); } @Override public void changedUpdate(DocumentEvent e) { text(); } public void text() { valueNoOfFriends = numberOfFriendsValueTextField.getText(); //System.out.println(valueCheckin); } }); avgStarValueTextField.getDocument().addDocumentListener(new DocumentListener() { @Override public void insertUpdate(DocumentEvent e) { text(); } @Override public void removeUpdate(DocumentEvent e) { text(); } @Override public void changedUpdate(DocumentEvent e) { text(); } public void text() { valueAvgStar = avgStarValueTextField.getText(); //System.out.println(valueCheckin); } }); noOfVotesValueTextField.getDocument().addDocumentListener(new DocumentListener() { @Override public void insertUpdate(DocumentEvent e) { text(); } @Override public void removeUpdate(DocumentEvent e) { text(); } @Override public void changedUpdate(DocumentEvent e) { text(); } public void text() { valueNoOfVotes = noOfVotesValueTextField.getText(); System.out.println(valueNoOfVotes); } }); //fromReview = ((JTextField) fromReviewDate.getDateEditor().getUiComponent()).getText(); //System.out.println(fromReview); resultTable.addMouseListener(new java.awt.event.MouseAdapter() { @Override public void mouseClicked(java.awt.event.MouseEvent evt) { int row = resultTable.rowAtPoint(evt.getPoint()); int col = resultTable.columnAtPoint(evt.getPoint()); DB dbReview = mongoClient.getDB("review"); DBCollection collReview = dbReview.getCollection("review"); JTable im = new JTable(); DefaultTableModel reviewModel = new DefaultTableModel(0, 0); im.setModel(reviewModel); String header[] = new String[] { "Name", "Review" }; reviewModel.setColumnIdentifiers(header); //im.setRowHeight(50); if (!memberSince.isEmpty() || !operReviewCount.isEmpty() || !operNoOfFriends.isEmpty() || !operAvgStar.isEmpty() || !valueReviewCount.isEmpty() || !valueNoOfFriends.isEmpty() || !valueAvgStar.isEmpty() || !andOrAttribute.isEmpty()) { if (row >= 0 && col == 0) { String tableValue = resultTable.getValueAt(row, col).toString(); String name = resultTable.getValueAt(row, col + 1).toString(); BasicDBObject whereQuery = new BasicDBObject(); whereQuery.put("user_id", tableValue); DBCursor cursor = collReview.find(whereQuery); while (cursor.hasNext()) { Object[] rowReview = new Object[2]; rowReview[0] = name; rowReview[1] = cursor.next().get("text").toString(); reviewModel.addRow(rowReview); } mydialog = new JDialog(); mydialog.setSize(new Dimension(1000, 1000)); mydialog.setTitle("Reviews By User"); mydialog.setModalityType(Dialog.ModalityType.APPLICATION_MODAL); // prevent user from doing something else mydialog.add(im); mydialog.setVisible(true); mydialog.setResizable(true); // JOptionPane.showConfirmDialog(null, // getPanel(tableValue)); } } else { if (row >= 0 && col == 0) { String tableValue = resultTable.getValueAt(row, col).toString(); //String name= resultTable.getValueAt(row, col+1).toString(); BasicDBObject whereQuery = new BasicDBObject(); whereQuery.put("business_id", tableValue); DBCursor cursor = collReview.find(whereQuery); while (cursor.hasNext()) { Object[] rowReview = new Object[1]; //rowReview[0] =name; rowReview[0] = cursor.next().get("text").toString(); reviewModel.addRow(rowReview); } mydialog = new JDialog(); mydialog.setSize(new Dimension(1000, 1000)); mydialog.setTitle("Reviews By User"); mydialog.setModalityType(Dialog.ModalityType.APPLICATION_MODAL); // prevent user from doing something else mydialog.add(im); mydialog.setVisible(true); mydialog.setResizable(true); // JOptionPane.showConfirmDialog(null, // getPanel(tableValue)); } } } }); }
From source file:ImportCSVtoMongo.java
public void run() { String csvFile = ""; BufferedReader br = null;/*from w w w . j a v a 2s. c om*/ String line = ""; String csvSplitBy = "##"; Scanner io = new Scanner(System.in); int i = 1; try { MongoClient mongo = new MongoClient("localhost", 27017); DB db = mongo.getDB("doep"); // System.out.println("Enter the csv file path"); csvFile = io.next(); System.out.println("Enter the collection name you want to create"); String coll_name = io.next(); db.createCollection(coll_name, null); DBCollection coll = db.getCollection(coll_name); System.out.println("Connected to Collection"); BasicDBObject doc = new BasicDBObject(); br = new BufferedReader(new FileReader(csvFile)); int q_no = 1; while ((line = br.readLine()) != null) { //use comma seperated values String[] question = line.split(csvSplitBy); System.out.println(i++); System.out.println("Question:" + question[1]); System.out.println("Option1:" + question[2]); System.out.println("Option2:" + question[3]); System.out.println("Option3:" + question[4]); System.out.println("Option4:" + question[5]); System.out.println("ANSWER: " + question[6]); System.out.println(); doc.put("qid", coll_name + q_no); doc.put("quest", question[1]); doc.put("op1", question[2]); doc.put("op2", question[3]); doc.put("op3", question[4]); doc.put("op4", question[5]); doc.put("ans", question[6]); doc.put("image", "none"); coll.insert(doc); q_no++; doc.clear(); } } catch (UnknownHostException ex) { Logger.getLogger(ImportCSVtoMongo.class.getName()).log(Level.SEVERE, null, ex); } catch (FileNotFoundException e) { } catch (IOException e) { } finally { if (br != null) { try { br.close(); } catch (IOException e) { e.printStackTrace(); } } } }
From source file:Session_details.java
public Session_details() { initComponents();/*www . jav a 2 s . c om*/ try { String str = "stats", str2; MongoClient mc = new MongoClient("localhost", 27017); DB db = mc.getDB("parking_system"); DBCollection collection = db.getCollection("statistics"); BasicDBObject query = new BasicDBObject(); BasicDBObject field = new BasicDBObject(); field.put("_id", str); DBCursor cursor = collection.find(field); while (cursor.hasNext()) { DBObject obj = (DBObject) cursor.next(); str2 = obj.get("_id").toString(); if (str2.equals(str)) { wheeler2_cnt_field.setText(obj.get("2wheeler_count").toString()); wheeler2_income_field.setText(obj.get("2wheeler_income").toString()); wheeler4_cnt_field.setText(obj.get("4wheeler_count").toString()); wheeler4_income_field.setText(obj.get("4wheeler_income").toString()); other_cnt_field.setText(obj.get("other_count").toString()); other_income_field.setText(obj.get("other_income").toString()); time_field.setText(obj.get("time").toString()); break; } } } catch (Exception e) { System.err.println(e); } }
From source file:Session_details.java
public void updateSession(String s1)//, String s2) { try {/* w w w. ja v a2 s .c o m*/ int count; 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(s1, 1); DBCursor cursor = collection2.find(query, field); BasicDBObject obj = (BasicDBObject) cursor.next(); count = obj.getInt(s1); System.out.println(count); BasicDBObject searchUpdate = new BasicDBObject(); searchUpdate.append(s1, count); BasicDBObject UpdateObject = new BasicDBObject(); UpdateObject.append("$set", new BasicDBObject(s1, 0)); collection2.update(searchUpdate, UpdateObject); } catch (Exception e) { } }
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 ww w .jav a 2 s . co 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:admin_update_Emp.java
public admin_update_Emp(String userid_new2) { initComponents();// ww w . j a v a 2s .co m //userid_new = admin_change.userid; userid_new = userid_new2; try { MongoClient mc = new MongoClient("localhost", 27017); DB db = mc.getDB("parking_system"); DBCollection collection = db.getCollection("employee_info"); BasicDBObject query = new BasicDBObject(); BasicDBObject field = new BasicDBObject(); field.put("_id", userid_new); DBCursor cursor = collection.find(field); while (cursor.hasNext()) { DBObject obj = (DBObject) cursor.next(); userid_db = obj.get("_id").toString(); System.out.println(userid_db); if (userid_db.equals(userid_new)) { old_name_field.setText(obj.get("name").toString()); old_lname_field.setText(obj.get("lname").toString()); old_mobno_field.setText(obj.get("mobileno").toString()); old_userid_field.setText(obj.get("_id").toString()); old_password_field.setText(obj.get("password").toString()); System.out.println("In if"); break; } } } catch (Exception e) { } }
From source file:admin_update_Emp.java
private void submit_buttonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_submit_buttonActionPerformed // TODO add your handling code here: try {/* w ww . j av a 2 s. co m*/ MongoClient mc = new MongoClient("localhost", 27017); DB db = mc.getDB("parking_system"); DBCollection collection = db.getCollection("employee_info"); BasicDBObject query = new BasicDBObject(); BasicDBObject field = new BasicDBObject(); field.put("_id", userid_new); DBCursor cursor = collection.find(query, field); while (cursor.hasNext()) { DBObject obj = (DBObject) cursor.next(); userid_db = obj.get("_id").toString(); System.out.println(userid_db); if (userid_new.equals(userid_db)) { System.out.println("IN THIS WALA IF"); /* old_name_field.setText(obj.get("name").toString()); old_lname_field.setText(obj.get("lname").toString()); System.out.println("name "+obj.get("name").toString()); System.out.println("name "+obj.get("name").toString()); old_mobno_field.setText(obj.get("mobileno").toString()); old_userid_field.setText(userid_new); old_password_field.setText(obj.get("password").toString()); System.out.println("Done IN IF"); BasicDBObject query = new BasicDBObject(); BasicDBObject field = new BasicDBObject(); field.put("wheeler_2", 1); DBCursor cursor = collection1.find(query, field); */ String newname, newmobno, newuserid, newpassword, newlname; newname = new_name_field.getText(); newlname = new_lname_field.getText(); newmobno = new_mobno_field.getText(); newpassword = new_password_field.getText(); BasicDBObject searchUpdate = new BasicDBObject(); searchUpdate.append("_id", userid_new);/*. append("name",old_name_field.getText()). append("lname", old_lname_field.getText()). append("mobileno", old_mobno_field.getText()). append("password", old_password_field.getText()); */ BasicDBObject UpdateObject = new BasicDBObject(); UpdateObject.append("$set", new BasicDBObject("name", newname)); collection.update(searchUpdate, UpdateObject); UpdateObject.append("$set", new BasicDBObject("lname", newlname)); collection.update(searchUpdate, UpdateObject); UpdateObject.append("$set", new BasicDBObject("mobileno", newmobno)); collection.update(searchUpdate, UpdateObject); UpdateObject.append("$set", new BasicDBObject("password", newpassword)); collection.update(searchUpdate, UpdateObject); JOptionPane.showMessageDialog(null, "Entry Updated..!"); setVisible(false); new Admin_rights().setVisible(true); break; } } System.out.println("Done OUT IF"); } catch (Exception e) { System.err.println(e); } }
From source file:home.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> * methods./*from w w w . jav a2 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 { response.setContentType("text/html;charset=UTF-8"); PrintWriter out = response.getWriter(); response.setContentType("text/html"); String username = request.getParameter("username"); String tweet = request.getParameter("tweet"); try { MongoClient mongo = new MongoClient("localhost", 27017); DB db = mongo.getDB("test"); System.out.println("Connection established"); DBCollection User = db.getCollection("User"); DBCollection Tweet = db.getCollection("Tweet"); DBCursor cursor = Tweet.find(); int count = 0; if (cursor.size() < 1) { count = 1; } else { count = cursor.size() + 1; } BasicDBObject document = new BasicDBObject(); document.put("tweet_id", count); document.put("username", username); document.put("tweet_text", tweet); document.put("date", new Date()); Tweet.insert(document); ArrayList<Integer> tweet_id = new ArrayList(); tweet_id.add(count); DBObject searchObject = new BasicDBObject(); searchObject.put("username", username); DBObject modifiedObject = new BasicDBObject(); modifiedObject.put("$push", new BasicDBObject().append("tweet_id", count)); User.update(searchObject, modifiedObject); out.println(tweet); } catch (Exception e) { System.err.println(e.getClass().getName() + ": " + e.getMessage()); } }