Example usage for com.mongodb.client MongoCursor hasNext

List of usage examples for com.mongodb.client MongoCursor hasNext

Introduction

In this page you can find the example usage for com.mongodb.client MongoCursor hasNext.

Prototype

@Override
    boolean hasNext();

Source Link

Usage

From source file:com.mycompany.mavenproject2.AddUOMController.java

public void InsertMongo() {
    count = (int) col.count();
    if (count == 0) {
        seedData = createSeedData();//from  w  w w  .j  a v  a 2  s .com
        col.insertOne(seedData);
    } else {
        sort1 = new BasicDBObject();

        MongoCursor<Document> cursor = col.find().sort(sort1).limit(1).skip((int) count - 1).iterator();
        try {
            while (cursor.hasNext()) {

                ID = cursor.next().getInteger("ID");
                System.out.println("last ID " + ID);
                ID++;
                System.out.println("Inserted " + ID);
            }
        } finally {
            cursor.close();
        }
        final Document seedData = createSeedData();
        name.clear();
        local_name.clear();
        col.insertOne(seedData);
    }
}

From source file:com.mycompany.mavenproject2.AddUser8Controller.java

private void InsertMongo() {
    if (GlobalFlag == 1) {
        UpdateMongo();/*from   w  w w .ja  v a  2  s .  c om*/
    } else {
        count = (int) col.count();
        if (count == 0) {
            seedData = createSeedData();
            col.insertOne(seedData);
        } else {
            sort1 = new BasicDBObject();
            MongoCursor<Document> cursor = col.find().sort(sort1).limit(1).skip((int) count - 1).iterator();
            try {
                while (cursor.hasNext()) {
                    EID = cursor.next().getInteger("ID");
                    System.out.println("last EID " + EID);
                    EID++;
                    System.out.println("Inserted " + EID);
                }
            } finally {
                cursor.close();
            }
            final Document seedData = createSeedData();
            col.insertOne(seedData);
        }
    }
}

From source file:com.mycompany.mavenproject2.AddUser8Controller.java

public void EditButton(int para1, String para2, String para3, String para4, String para5) {
    GlobalFlag = 1;/*from   www.  j  a  v  a2 s. c o m*/
    UserId = para4;
    fname.setText(para2);
    lname.setText(para3);
    uid.setText(para4);
    phone.setText(para5);
    sort2 = new BasicDBObject();
    sort2.put("FirstName", para2);
    sort2.put("LastName", para3);
    sort2.put("UserEID", para4);
    MongoCursor<Document> cursor = col.find(sort2).iterator();
    while (cursor.hasNext()) {
        Document dr = cursor.next();
        add1.setText(dr.getString("Address1"));
        add2.setText(dr.getString("Address2"));
        city.setText(dr.getString("City"));
        state.setText(dr.getString("State"));
        country.setText(dr.getString("Country"));
        zip.setText(dr.getString("ZIP"));
        ext.setText(dr.getString("EXT"));
        pwd.setText(dr.getString("Password"));
        cpwd.setText(dr.getString("ConfirmPWD"));
        roleCombo.setValue(dr.getString("Role"));
        GenderCombo.setValue(dr.getString("Gender"));
        email.setText(dr.getString("Email"));

        condition = new BasicDBObject();
        condition.put("UserEID", para4);
        System.out.println("Value of UserEID is " + para4);
        MongoCursor<Document> cursor4 = col.find(condition).iterator();
        while (cursor4.hasNext()) {

            PID = cursor4.next().getInteger("ID");
            //UID=cursor4.next().getInteger("ID");
            System.out.println("Updated Selected _id is " + PID + "IUd is " + UID);
        }
    }

}

From source file:com.mycompany.mavenproject2.AddUser8Controller.java

public void UpdateMongo() {

    System.out.println("global 1 update called");
    /*  condition=new BasicDBObject();    
      condition.put("UserEID", uid.getText());
               //ww  w.  j ava  2 s .  co m
      MongoCursor<Document> cursor = col.find(condition).iterator();      
        while (cursor.hasNext()) {       
      System.out.println("Updated Selected _id is "+Eid);
     Eid=cursor.next().getObjectId("_id").toString();
     System.out.println("Updated Selected _id is "+Eid);
        }*/
    MongoCursor<Document> cursor4 = col.find().iterator();
    try {
        while (cursor4.hasNext()) {
            System.out.println("ID=> " + cursor4.next().getString("UserEID"));
        }
    } finally {
        cursor4.close();
    }
    //  col.updateOne(eq("_id",Eid), new Document("$set",new Document("UserEID","U25")) );
    //col.replaceOne(eq("_id",Eid),UpdateSeedData());
    System.out.println("Updated Selected _id is " + PID);
    col.updateOne(new Document("ID", PID), new Document("$set", UpdateSeedData()));
    //.append("$currentDate", new Document("lastModified", true)));
    MongoCursor<Document> cursor5 = col.find().iterator();
    try {
        while (cursor5.hasNext()) {
            System.out.println("After UpdateID=> " + cursor5.next().getString("UserEID"));

        }
    } finally {
        cursor5.close();
    }

    /*   BasicDBObject b=new BasicDBObject();
           b.put("ChargeName", addon);
                 
    MongoCursor<Document> cursor = db.getCollection("PriceDetail").find(b).iterator();
                 
    while (cursor.hasNext()) {               
    Document d1 = cursor.next();
    System.out.println("output is "+d1.toString());
    Document updateDocument = d1;
    if(PercentageRadio.isSelected()){
            cost1=1;
        }
        if(AmountRadio.isSelected()){
            cost2=1;
        }
                
        if(InactiveCheck.isSelected()){
            IFlag=1;
        }
        if(TaxCheck.isSelected()){
            TFlag=1;
        }
    updateDocument.put("ChargeName",ChargeNameText.getText());            
    updateDocument.put("ChargeValue", ChargeValue.getText());
    updateDocument.put("PercentageCheck", cost1);
        updateDocument.put("Amountcheck", cost2);
         updateDocument.put("Inactive", IFlag);
         updateDocument.put("Tax", TFlag);        
    //col1.update(updateDocument); 
    db.getCollection("PriceDetail").updateOne(d1,updateDocument);
    }*/

}

From source file:com.mycompany.mavenproject2.AddUser8Controller.java

@Override
public void initialize(URL url, ResourceBundle rb) {
    MongoCursor<Document> cursor4 = db.getCollection("SecurityRole").find().iterator();
    try {//from   w w w .  ja v  a  2 s . c  o  m
        while (cursor4.hasNext()) {
            String rs = cursor4.next().getString("Role");
            roleCombo.setValue(rs);
            roleCombo.getItems().addAll(rs);
        }
    } finally {
        cursor4.close();
    }
}

From source file:com.mycompany.mavenproject2.CashDrawerController.java

@FXML
private void handleAddButtonAction(ActionEvent eve) {
    ref = new BasicDBObject();
    ref.put("UnitName", Pattern.compile(UnitText.getText(), Pattern.CASE_INSENSITIVE));
    MongoCursor<Document> myDoc2 = db.getCollection("CashDrawerDetail").find(ref).iterator();
    if (myDoc2.hasNext()) {
        Alert alert = new Alert(Alert.AlertType.ERROR);
        alert.setTitle("Error ");
        alert.setContentText("ChargeName Already exist!");
        alert.showAndWait();/*  w w w. jav  a  2 s .com*/
        UnitText.clear();
        CurrencyText.clear();
        repeat = 1;
    } else {
        repeat = 0;
    }
    if (repeat == 0) {
        InsertMongo();
        // InsertSQl(conn);

        if (BillRadio.isSelected()) {
            select = "Bill";
        }
        if (CoinRadio.isSelected()) {
            select = "Coin";
        }
        if (NCCheck.isSelected()) {
            NC = "Y";
        } else {
            NC = "N";
        }
        data.add(new Person(UnitText.getText(), CurrencyText.getText(), select, NC));

    }
    UnitText.clear();
    CurrencyText.clear();

}

From source file:com.mycompany.mavenproject2.CashDrawerController.java

@Override
public void initialize(URL url, ResourceBundle rb) {
    unitcol.setCellValueFactory(new javafx.scene.control.cell.PropertyValueFactory<Person, String>("UnitName"));
    valuecol.setCellValueFactory(new javafx.scene.control.cell.PropertyValueFactory<Person, String>("Value"));
    typecol.setCellValueFactory(new javafx.scene.control.cell.PropertyValueFactory<Person, String>("Type"));
    nccol.setCellValueFactory(new javafx.scene.control.cell.PropertyValueFactory<Person, String>("NC"));
    MongoCursor<Document> cursor = db.getCollection("CashDrawerDetail").find().iterator();
    System.out.println("Intilization");
    try {//  w  ww.  j  a  v  a2 s .  c o m
        while (cursor.hasNext()) {
            Document i = cursor.next();
            System.out.println("Unit name is " + i.getString("UnitName"));
            data.add(new Person(i.getString("UnitName"), i.getString("Currency"), i.getString("UnitType"),
                    i.getString("NonCashUnit")));

        }
    } finally {
        cursor.close();
    }
    table.setItems(data);

}

From source file:com.mycompany.mavenproject2.ConfTenderController.java

@Override
public void initialize(URL url, ResourceBundle rb) {
    TDesc.setCellValueFactory(new javafx.scene.control.cell.PropertyValueFactory<Person, String>("TDesc"));
    TType.setCellValueFactory(new javafx.scene.control.cell.PropertyValueFactory<Person, String>("TType"));
    MongoCursor<Document> cursor5 = col.find().iterator();
    try {//from  ww w .j  a  v a2 s  .  co m
        while (cursor5.hasNext()) {
            Document rs = cursor5.next();
            data.add(new Person(rs.getString("TenderName"), rs.getString("PaymentMode")));
        }
    } finally {
        cursor5.close();
    }
    TenderTable.setItems(data);
    filterField.textProperty().addListener(new ChangeListener<String>() {
        @Override
        public void changed(ObservableValue<? extends String> observable, String oldValue, String newValue) {
            initFilter();
        }
    });
}

From source file:com.mycompany.mavenproject2.Currency3Controller.java

@Override
public void initialize(URL url, ResourceBundle rb) {
    captioncol.setCellValueFactory(new javafx.scene.control.cell.PropertyValueFactory<Person, String>("Value"));
    amtcol.setCellValueFactory(new javafx.scene.control.cell.PropertyValueFactory<Person, String>("UnitName"));
    MongoCursor<Document> cursor4 = db.getCollection("CurrancyDetail").find().iterator();
    try {//w  w w. j  a v a 2  s.  c o m
        while (cursor4.hasNext()) {
            Document rs = cursor4.next();
            data.add(new Person((rs.getString("Caption")), (rs.getString("Amount"))));
        }
    } finally {
        cursor4.close();
    }
    table.setItems(data);
}

From source file:com.mycompany.mavenproject2.Currency3Controller.java

@FXML
public void handleEditSaveButtonAction(ActionEvent as) {

    MongoCursor<Document> cursor4 = db.getCollection("CurrancyDetail").find().iterator();
    try {/*ww w  .  j  a v  a2s .  c  om*/
        while (cursor4.hasNext()) {
            Document k = cursor4.next();
            System.out.println("before update => " + k.getString("Caption") + " " + k.getString("Amount"));
        }
    } finally {
        cursor4.close();
    }
    //Person person = table.getSelectionModel().getSelectedItem();
    //table.getSelectionModel().clearSelection();            

    //db.getCollection("CurrancyDetail").updateOne(new Document("Caption", person.getUnitName()),
    //new Document("$set", UpdateSeedData()));
    db.getCollection("CurrancyDetail").updateOne(eq("Caption", CaptionTextField.getText()),
            new Document("$set", new Document("Amount", AmountTextField.getText())));

    MongoCursor<Document> cursor5 = db.getCollection("CurrancyDetail").find().iterator();
    try {
        while (cursor5.hasNext()) {
            Document y = cursor5.next();
            System.out.println("After Update => " + y.getString("Caption") + " " + y.getString("Amount"));

        }
    } finally {
        cursor5.close();
    }
    AmountTextField.clear();
    CaptionTextField.clear();
}