Example usage for com.mongodb DBCursor curr

List of usage examples for com.mongodb DBCursor curr

Introduction

In this page you can find the example usage for com.mongodb DBCursor curr.

Prototype

public DBObject curr() 

Source Link

Document

Returns the element the cursor is at.

Usage

From source file:Search_trainer.java

@Override
public void actionPerformed(ActionEvent ae) {
    // TODO Auto-generated method stub
    add(jLabel3);//from  w w w .j  a v a 2 s  .  c  o m
    add(jTextField1);
    add(jButton1);

    if (ae.getSource() == jComboBox1) {
        String Variable = jComboBox1.getSelectedItem().toString();
        jLabel3.setText("");
        jTextField1.setText("");

        if (Variable == "All_Trainers") {
            try {
                MongoClient mongo = new MongoClient("localhost", 27017);
                DB db = mongo.getDB("Gym");
                DBCollection Gym_Collection = db.getCollection("trainer");
                DBCursor cursor1 = Gym_Collection.find();
                int i = 0;
                String[][] s = new String[20][10];
                while (cursor1.hasNext()) {
                    cursor1.next();
                    s[i][0] = cursor1.curr().get("First_Name").toString();
                    s[i][1] = cursor1.curr().get("Last_Name").toString();
                    s[i][2] = cursor1.curr().get("Batch").toString();
                    s[i][3] = cursor1.curr().get("Age").toString();
                    s[i][4] = cursor1.curr().get("Username").toString();
                    s[i][5] = cursor1.curr().get("Password").toString();
                    s[i][6] = cursor1.curr().get("Phone_Number").toString();
                    s[i][7] = cursor1.curr().get("Address").toString();
                    i++;
                }

                JFrame frame = new JFrame("Resulted Trainers");
                frame.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
                Trainer_Table ne = new Trainer_Table(s);
                ne.setOpaque(true);
                frame.setContentPane(ne);
                frame.pack();
                frame.setVisible(true);
            } catch (UnknownHostException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        } else {
            jLabel3.setFont(new java.awt.Font("SansSerif", 3, 14)); // NOI18N
            jLabel3.setForeground(new java.awt.Color(204, 255, 204));
            jLabel3.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
            jLabel3.setText("Enter " + Variable + ": ");
            jLabel3.setBounds(55, 230, 200, 40);

            jTextField1.setBounds(267, 230, 200, 40);

            jButton1.setBackground(new java.awt.Color(51, 0, 51));
            jButton1.setFont(new java.awt.Font("SansSerif", 3, 12)); // NOI18N
            jButton1.setForeground(new java.awt.Color(255, 255, 255));
            jButton1.setText("Search Trainer");
            jButton1.setBounds(160, 300, 300, 40);
            setVisible(true);
        }
    } else if (ae.getSource() == jButton1) {

        try {

            String Variable = jComboBox1.getSelectedItem().toString();
            MongoClient mongo = new MongoClient("localhost", 27017);
            DB db = mongo.getDB("Gym");
            DBCollection Gym_Collection = db.getCollection("trainer");
            BasicDBObject fields;
            if (Variable == "First_Name" || Variable == "Last_Name" || Variable == "Username"
                    || Variable == "Batch") {
                fields = new BasicDBObject(Variable, jTextField1.getText().toString());
            } else {
                fields = new BasicDBObject(Variable, Integer.parseInt(jTextField1.getText().toString()));
            }
            DBCursor cursor1 = Gym_Collection.find(fields);
            int i = 0;
            String[][] s = new String[20][10];
            while (cursor1.hasNext()) {
                cursor1.next();
                s[i][0] = cursor1.curr().get("First_Name").toString();
                s[i][1] = cursor1.curr().get("Last_Name").toString();
                s[i][2] = cursor1.curr().get("Batch").toString();
                s[i][3] = cursor1.curr().get("Age").toString();
                s[i][4] = cursor1.curr().get("Username").toString();
                s[i][5] = cursor1.curr().get("Password").toString();
                s[i][6] = cursor1.curr().get("Phone_Number").toString();
                s[i][7] = cursor1.curr().get("Address").toString();
                i++;
            }

            JFrame frame = new JFrame("Resulted Trainers");
            frame.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
            Trainer_Table ne = new Trainer_Table(s);
            ne.setOpaque(true);
            frame.setContentPane(ne);
            frame.pack();
            frame.setVisible(true);
        } catch (UnknownHostException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (NumberFormatException e) {// To validate for data types
            JOptionPane.showMessageDialog(this, "Please Check the Data types");
            jTextField1.setText("");
        }
    } else if (ae.getSource() == jButton2) {
        this.setVisible(false);
        new Admin().setVisible(true);
    }
}

From source file:mail.java

@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    int success = 0;
    String id = request.getParameter("email");
    System.out.println(id);/*from   ww w.ja  v  a  2  s .c  om*/
    //String id="anjaliverma25792@gmail.com";
    MongoClient mongo = new MongoClient();
    DB db = mongo.getDB("WebDB");
    DBCollection table = db.getCollection("User");
    Document d = new Document();
    d.put("Email", id);
    DBObject ob = new BasicDBObject(d);
    DBCursor cur = table.find(ob);
    System.out.println(cur.size());
    System.out.println("Above value");
    String user = null;
    if (cur.hasNext()) {
        success = 1;
        cur.next();
        DBObject temp = cur.curr();
        String pass = (String) temp.get("Password");

        HttpSession session = request.getSession();
        user = (String) temp.get("Name");

        final String username = "nature.lover.ritika@gmail.com";
        final String password = "ritika7vision";

        Properties props = new Properties();
        props.put("mail.smtp.auth", "true");
        props.put("mail.smtp.starttls.enable", "true");
        props.put("mail.smtp.host", "smtp.gmail.com");
        props.put("mail.smtp.port", "587");

        Session sess = Session.getInstance(props, new javax.mail.Authenticator() {
            @Override
            protected PasswordAuthentication getPasswordAuthentication() {
                return new PasswordAuthentication(username, password);
            }
        });

        try {
            Message message = new MimeMessage(sess);
            message.setFrom(new InternetAddress("papertree.official@gmail.com"));
            message.setRecipients(Message.RecipientType.TO, InternetAddress.parse(id)); //retrive email id from forgot your password form.
            message.setSubject("PaperTree: Password Reset");
            message.setText("Dear, " + user + ". Your password is " + pass
                    + ". \n\n Directly LOGIN And START READING...");

            Transport.send(message);

            // Mongo DB connectivity LEFT 

            //                        response.sendRedirect("success.jsp");

        } catch (MessagingException e) {
            throw new RuntimeException(e);
        }

    }
    if (success == 1) {
        response.sendRedirect("success.jsp?success=yes");

    } else {
        response.sendRedirect("success.jsp?success=no");

    }
}

From source file:NewJFrame.java

@Override
public void actionPerformed(ActionEvent ae) {
    // TODO Auto-generated method stub
    add(jLabel5);//from w  ww.  j  a  v a2  s  .  c  o  m
    String user = jTextField1.getText().toString();
    @SuppressWarnings("deprecation")
    String pass = jPassword1.getText().toString();
    jLabel5.setText("");

    if (ae.getSource() == jButton1) {
        if ((String) jComboBox1.getSelectedItem() == "Admin") {
            if (user.equals("admin") && pass.equals("admin123")) {
                this.setVisible(false);
                new Admin().setVisible(true);
            } else {
                jLabel5.setFont(new java.awt.Font("SansSerif", 3, 14)); // NOI18N
                jLabel5.setForeground(new java.awt.Color(25, 25, 112));
                jLabel5.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
                jLabel5.setText("Login Not Successful ");
                jTextField1.setText("");
                jPassword1.setText("");
                jLabel5.setBounds(120, 245, 170, 50);
            }
        } else if ((String) jComboBox1.getSelectedItem() == "Trainer") {
            try {
                MongoClient mongo = new MongoClient("localhost", 27017);
                DB db = mongo.getDB("Gym");
                DBCollection Gym_Collection = db.getCollection("trainer");
                BasicDBObject fields = new BasicDBObject("Username", user).append("Password", pass);
                String s;
                DBCursor cursor1 = Gym_Collection.find(fields);
                if (cursor1.hasNext()) {
                    cursor1.next();
                    s = cursor1.curr().get("First_Name").toString();
                    new Receptionist(s);
                    this.setVisible(false);
                    new Receptionist().setVisible(true);
                } else {
                    jLabel5.setFont(new java.awt.Font("SansSerif", 3, 14)); // NOI18N
                    jLabel5.setForeground(new java.awt.Color(25, 25, 112));
                    jLabel5.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
                    jLabel5.setText("Login Not Successful ");
                    jTextField1.setText("");
                    jPassword1.setText("");
                    jLabel5.setBounds(120, 245, 170, 50);
                }
            } catch (UnknownHostException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }

        }
    }
}

From source file:Add_cust.java

@Override
/* Check The code below for insertion of values */
public void actionPerformed(ActionEvent ae) {
    // TODO Auto-generated method stub
    add(jLabel9);/*from w  ww . ja v a  2 s .  com*/
    String History = jComboBox3.getSelectedItem().toString();
    if (ae.getSource() == jButton1) {
        try {
            MongoClient mongo = new MongoClient("localhost", 27017);
            DB db = mongo.getDB("Gym");
            DBCollection Gym_Collection = db.getCollection("Customers");
            DBCollection Allot = db.getCollection("Batch"); //Declaration of collection for Batch
            DBCursor cursor = Allot.find();
            float Slots, Morning, Evening, Night;
            cursor.next();
            Slots = Float.parseFloat(cursor.curr().get("Slots").toString());
            Morning = Float.parseFloat(cursor.curr().get("Morning").toString());
            Evening = Float.parseFloat(cursor.curr().get("Evening").toString());
            Night = Float.parseFloat(cursor.curr().get("Night").toString());
            String first_name = jTextField1.getText();
            String last_name = jTextField2.getText();
            float weight = Float.parseFloat(jTextField6.getText().toString());
            float height = Float.parseFloat(jTextField5.getText().toString());
            String address = jTextArea1.getText();
            int age = Integer.parseInt(jComboBox1.getSelectedItem().toString());
            String Subs = jComboBox2.getSelectedItem().toString();

            String Batches = jComboBox5.getSelectedItem().toString();
            String phone_number = jTextField3.getText().toString();
            if (!isAlpha(first_name) || !isAlpha(last_name)) {
                JOptionPane.showMessageDialog(this, "Enter a valid name");
                jTextField1.setText("");
                jTextField2.setText("");
            } else if (weight > 150 || weight < 40) {
                JOptionPane.showMessageDialog(this, "Please add weight between 40 and 150");
                jTextField6.setText("");
            } else if (height > 250 || height < 50) {
                JOptionPane.showMessageDialog(this, "Please add height between 100 and 250");
                jTextField5.setText("");
            } else if (phone_number.length() < 8 || phone_number.length() > 11) {
                JOptionPane.showMessageDialog(this, "Enter a valid Phone no.");
                jTextField3.setText("");
            } else {
                int random_1, random_2, sub_sum = 0, days = 0;
                if (Subs.equals("1 Month")) {
                    sub_sum = 1000;
                    days = 30;
                } else if (Subs.equals("2 Months")) {
                    sub_sum = 1500;
                    days = 60;
                } else if (Subs.equals("3 Months")) {
                    sub_sum = 2250;
                    days = 90;
                } else if (Subs.equals("1 YEAR")) {
                    sub_sum = 6000;
                    days = 360;
                }
                int flag = 0, flag1 = 0, flag2 = 0, flag3 = 0;
                if (Batches.equals("Morning")) {
                    Morning += 1;
                    flag1 = 1;
                } else if (Batches.equals("Evening")) {
                    Evening += 1;
                    flag2 = 1;
                } else if (Batches.equals("Night")) {
                    Night += 1;
                    flag3 = 1;
                }
                if (Morning > Slots || Evening > Slots || Night > Slots) {
                    if (flag1 == 1) {
                        Morning -= 1;
                    } else if (flag2 == 1) {
                        Evening -= 1;
                    } else if (flag3 == 1) {
                        Night -= 1;
                    }
                    flag = 1;
                }
                if (flag == 1) {
                    float temp1, temp2;
                    if (flag1 == 1) {
                        temp1 = Slots - Evening;
                        temp2 = Slots - Night;
                        JOptionPane.showMessageDialog(this, "This time slot slot is full. Evening has " + temp1
                                + " Slots. Night has " + temp2 + " Slots.");
                    } else if (flag2 == 1) {
                        temp1 = Slots - Morning;
                        temp2 = Slots - Night;
                        JOptionPane.showMessageDialog(this, "This time slot slot is full. Morning has " + temp1
                                + " Slots. Night has " + temp2 + " Slots.");
                    } else {
                        temp1 = Slots - Morning;
                        temp2 = Slots - Evening;
                        JOptionPane.showMessageDialog(this, "This time slot slot is full. Morning has " + temp1
                                + " Slots. Evening has " + temp2 + " Slots.");
                    }
                } else {
                    do {
                        random_1 = (int) Math.floor(Math.random() * 360);
                        random_2 = (int) Math.floor(Math.random() * 360);
                    } while (random_1 >= random_2 || days <= random_2);
                    BasicDBObject doc = new BasicDBObject("First_Name", first_name.toLowerCase())
                            .append("Last_Name", last_name.toLowerCase()).append("Phone_Number", phone_number)
                            .append("Age", age).append("Height", height).append("History", History)
                            .append("Subscribe", days).append("Batch", Batches).append("Weight", weight)
                            .append("Attended", random_1).append("Total", random_2).append("Fees", sub_sum)
                            .append("Address", address);
                    Gym_Collection.insert(doc);
                    jTextField1.setText("");
                    jTextField2.setText("");
                    jTextField3.setText("");
                    jTextField5.setText("");
                    jTextField6.setText("");
                    jTextArea1.setText("");

                    BasicDBObject newDocument = new BasicDBObject();
                    newDocument.append("$set", new BasicDBObject().append("Morning", Morning)
                            .append("Evening", Evening).append("Night", Night));

                    BasicDBObject searchQuery = new BasicDBObject().append("Slots", Slots);

                    Allot.update(searchQuery, newDocument);

                    this.setVisible(false);
                    new work(History, first_name.toLowerCase(), last_name.toLowerCase());
                    this.setVisible(false);
                    new work().setVisible(true);
                }
            }
        } catch (UnknownHostException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (NumberFormatException e) {// To validate for data types
            JOptionPane.showMessageDialog(this, "Please Check the Data types");
            jTextField1.setText("");
            jTextField2.setText("");
            jTextField3.setText("");
            jTextField5.setText("");
            jTextField6.setText("");
            jTextArea1.setText("");
        }
    }

    else if (ae.getSource() == jButton2) {
        this.setVisible(false);
        new Receptionist().setVisible(true);
    }
}

From source file:Add_train.java

@Override
/* Check The code below for insertion of values */
public void actionPerformed(ActionEvent ae) {
    // TODO Auto-generated method stub
    add(jLabel9);//w  ww . jav  a  2  s .  c  o m
    jLabel9.setText("");
    if (ae.getSource() == jButton1) {
        try {
            MongoClient mongo = new MongoClient("localhost", 27017);
            DB db = mongo.getDB("Gym");
            DBCollection Allot = db.getCollection("Batch_Trainer");
            DBCursor cursor1 = Allot.find();
            DBCollection Gym_Collection = db.getCollection("trainer");
            String first_name = jTextField1.getText();
            String last_name = jTextField2.getText();
            String password = jPassword1.getText().toString();
            String dup = jPassword2.getText().toString();
            String username = jTextField5.getText().toString();
            String address = jTextArea1.getText();

            String Batches = jComboBox5.getSelectedItem().toString();
            float Slots, Morning, Evening, Night;
            cursor1.next();
            Slots = Float.parseFloat(cursor1.curr().get("Slots").toString());
            Morning = Float.parseFloat(cursor1.curr().get("Morning").toString());
            Evening = Float.parseFloat(cursor1.curr().get("Evening").toString());
            Night = Float.parseFloat(cursor1.curr().get("Night").toString());
            int age = Integer.parseInt(jComboBox1.getSelectedItem().toString());
            String phone_number = jTextField3.getText().toString();
            DBCursor cursor = Gym_Collection.find();
            int i = 0;
            while (cursor.hasNext()) {
                cursor.next();
                if (username.equals(cursor.curr().get("Username").toString())) {
                    i = 1;
                }
            }
            if (i == 1) {
                JOptionPane.showMessageDialog(this, "Username has been taken !!!");
                jTextField5.setText("");
            } else if (!isAlpha(first_name) || !isAlpha(last_name)) {
                JOptionPane.showMessageDialog(this, "Enter a valid name");
                jTextField1.setText("");
                jTextField2.setText("");
            } else if (phone_number.length() < 8 || phone_number.length() > 10) {
                JOptionPane.showMessageDialog(this, "Enter a valid Phone no.");
                jTextField3.setText("");
            } else if (!password.equals(dup)) {
                JOptionPane.showMessageDialog(this, "Passwords didn't match");
                jPassword1.setText("");
                jPassword2.setText("");
            } else {

                int flag = 0, flag1 = 0, flag2 = 0, flag3 = 0;
                if (Batches.equals("Morning")) {
                    Morning += 1;
                    flag1 = 1;
                } else if (Batches.equals("Evening")) {
                    Evening += 1;
                    flag2 = 1;
                } else if (Batches.equals("Night")) {
                    Night += 1;
                    flag3 = 1;
                }
                if (Morning > Slots || Evening > Slots || Night > Slots) {
                    if (flag1 == 1) {
                        Morning -= 1;
                    } else if (flag2 == 1) {
                        Evening -= 1;
                    } else if (flag3 == 1) {
                        Night -= 1;
                    }
                    flag = 1;
                }
                if (flag == 1) {
                    float temp1, temp2;
                    if (flag1 == 1) {
                        temp1 = Slots - Evening;
                        temp2 = Slots - Night;
                        JOptionPane.showMessageDialog(this, "This time slot slot is full. Evening has " + temp1
                                + " Slots. Night has " + temp2 + " Slots.");
                    } else if (flag2 == 1) {
                        temp1 = Slots - Morning;
                        temp2 = Slots - Night;
                        JOptionPane.showMessageDialog(this, "This time slot slot is full. Morning has " + temp1
                                + " Slots. Night has " + temp2 + " Slots.");
                    } else {
                        temp1 = Slots - Morning;
                        temp2 = Slots - Evening;
                        JOptionPane.showMessageDialog(this, "This time slot slot is full. Morning has " + temp1
                                + " Slots. Evening has " + temp2 + " Slots.");
                    }
                } else {

                    BasicDBObject doc = new BasicDBObject("First_Name", first_name.toLowerCase())
                            .append("Last_Name", last_name.toLowerCase()).append("Batch", Batches)
                            .append("Phone_Number", phone_number).append("Age", age)
                            .append("Username", username).append("Password", password)
                            .append("Address", address);
                    Gym_Collection.insert(doc);
                    jTextField1.setText("");
                    jTextField2.setText("");
                    jTextField3.setText("");
                    jTextField5.setText("");
                    jPassword1.setText("");
                    jPassword2.setText("");
                    jTextArea1.setText("");
                    jLabel9.setFont(new java.awt.Font("SansSerif", 3, 16)); // NOI18N
                    jLabel9.setForeground(new java.awt.Color(204, 255, 204));
                    jLabel9.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
                    jLabel9.setText("Successfully Added");
                    jLabel9.setBounds(200, 10, 200, 40);

                    BasicDBObject newDocument = new BasicDBObject();
                    newDocument.append("$set", new BasicDBObject().append("Morning", Morning)
                            .append("Evening", Evening).append("Night", Night));

                    BasicDBObject searchQuery = new BasicDBObject().append("Slots", Slots);

                    Allot.update(searchQuery, newDocument);

                    setVisible(true);
                }
            }
        } catch (UnknownHostException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (NumberFormatException e) {
            JOptionPane.showMessageDialog(this, "Please Check the Data types");
            jTextField1.setText("");
            jTextField2.setText("");
            jTextField3.setText("");
            jTextField5.setText("");
            jPassword1.setText("");
            jPassword2.setText("");
            jTextArea1.setText("");
        }
    }

    else if (ae.getSource() == jButton2) {
        this.setVisible(false);
        new Admin().setVisible(true);
    }
}

From source file:com.avanza.ymer.MirrorEnvironment.java

License:Apache License

public void removeFormatVersion(Class<?> dataType, Object id) {
    String collectionName = dataType.getSimpleName().substring(0, 1).toLowerCase()
            + dataType.getSimpleName().substring(1);
    DBCollection collection = getMongoDb().getCollection(collectionName);
    DBObject idQuery = BasicDBObjectBuilder.start("_id", id).get();
    DBCursor cursor = collection.find(idQuery);

    cursor.next();//w w w.  j  a v a  2  s  .  co  m
    DBObject obj = cursor.curr();
    cursor.close();

    obj.removeField("_formatVersion");
    collection.update(idQuery, obj);
}

From source file:com.deliveronthego.DbConnection.java

public boolean login(String emailId, String password, String userType) {
    mongoclient = getConnection();//from   w  w w .  ja  v  a2  s .  co m
    @SuppressWarnings("deprecation")
    DB db = mongoclient.getDB("deliveronthego");
    DBCollection login = db.getCollection("login");
    if (emailId.contains("@")) {
        BasicDBObject logInObj = new BasicDBObject();
        logInObj.put("emailId", emailId);
        DBCursor logInCursor = login.find(logInObj);

        while (logInCursor.hasNext()) {
            logInCursor.next();
            DBObject userDetailObj = logInCursor.curr();
            if (userDetailObj != null) {
                String logInPassword = userDetailObj.get("password").toString();
                String loginUserType = userDetailObj.get("userType").toString();
                System.out.println(logInPassword);
                if ((logInPassword != null) && (logInPassword.equalsIgnoreCase(password))
                        && (loginUserType != null) && (loginUserType.equalsIgnoreCase(userType))) {
                    return true;
                } else {
                    return false;
                }
            } else {
                return false;
            }

        }
        return true;
    } else {
        return false;
    }
}

From source file:com.deliveronthego.DbConnection.java

public String location(String date, double transitionLatitude, double transitionLongitude, double stopLatitude,
        double stopLongitude, String driverId) {
    mongoclient = getConnection();//from w  ww  . ja  v  a2  s .  c o m
    @SuppressWarnings("deprecation")
    DB db = mongoclient.getDB("deliveronthego");
    DBCollection location = db.getCollection("location");
    BasicDBObject whereQuery = new BasicDBObject();
    whereQuery.put("driverID", driverId);
    DBCursor locationCursor = location.find(whereQuery);
    boolean updateFlag = false;

    while (locationCursor.hasNext()) {
        locationCursor.next();
        DBObject locDB = locationCursor.curr();
        System.out.println(locDB);
        String dateStr = locDB.get("Date").toString();
        if (dateStr.equals(date)) {
            location.update(new BasicDBObject("driverID", driverId),
                    new BasicDBObject("$set", new BasicDBObject("transitionLatitude", transitionLatitude)
                            .append("transitionLongitude", transitionLongitude)));
            Double previousStopLatitude = (Double) locDB.get("stopLatitude");
            Double previousStopLongitude = (Double) locDB.get("stopLongitude");
            System.out.println("previousStopLatitude: " + previousStopLatitude);
            System.out.println("previousStopLongitude: " + previousStopLongitude);
            /*if((previousStopLatitude==0.0) && (previousStopLongitude==0.0))
            {
               location.update(new BasicDBObject("driverID", driverId), new BasicDBObject("$set", new BasicDBObject("stopLatitude", stopLatitude).append("stopLongitude", stopLongitude)));
            }*/
        }
        updateFlag = true;
    }

    if (!updateFlag) {
        BasicDBObject locationObj = new BasicDBObject("Date", date.toString())
                .append("transitionLatitude", transitionLatitude)
                .append("transitionLongitude", transitionLongitude).append("stopLatitude", stopLatitude)
                .append("stopLongitude", stopLongitude).append("driverID", driverId);
        location.insert(locationObj);
        return "Location Details Inserted Sucessfully";
    } else {
        return "Location Details Updated";
    }

}

From source file:com.deliveronthego.DbConnection.java

public String transcationNotification(String driverID, Boolean pickedUp, Boolean delivered) {
    mongoclient = getConnection();//from   ww  w.j  a va 2  s  .c om
    @SuppressWarnings("deprecation")
    DB db = mongoclient.getDB("deliveronthego");
    DBCollection notification = db.getCollection("notification");

    BasicDBObject notificationObj = new BasicDBObject();
    notificationObj.append("driverID", driverID);
    Date date = new Date();
    Calendar cal = Calendar.getInstance();
    cal.setTime(date);

    DBCursor notificationCursor = notification.find(notificationObj);

    if (pickedUp && !delivered) {
        notificationObj.append("pickedUp", pickedUp.toString()).append("delivered", delivered.toString())
                .append("date", cal.toString());
        notification.insert(notificationObj);

        return "New Transaction Data inserted";
    } else {
        if (notificationCursor.hasNext()) {
            notificationCursor.next();
            DBObject notifyObj = notificationCursor.curr();
            Date currentDateInDatabase = (Date) notifyObj.get("date");
            if (!(boolean) notifyObj.get("delivered") && currentDateInDatabase.before(date)) {
                notification.update(new BasicDBObject("driverID", driverID),
                        new BasicDBObject("$set", new BasicDBObject("delivered", delivered.toString())));
                return "Transaction Completed";
            } else {
                return "Transaction failed to update";
            }
        } else {
            return "Transaction failed";
        }
    }
}

From source file:com.miya.twit.mongodb.DBConnectSentiment.java

public ArrayList getTwitterFindAll() {
    ArrayList arr = new ArrayList();
    DBCollection collection = dbConnection();
    DBCursor cursor = collection.find();
    try {/* www.j  a v  a 2  s . co m*/
        String str = "";
        while (cursor.hasNext()) {
            str = cursor.curr().get("text").toString();
            arr.add(str);
        }
    } finally {
        cursor.close();
    }

    return arr;

}