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.PriceAddonnController.java

@FXML
public void handleAddOnButtonAction(ActionEvent a) throws UnknownHostException {

    ref = new BasicDBObject();
    ref.put("Name", Pattern.compile(ChargeNameText.getText(), Pattern.CASE_INSENSITIVE));
    MongoCursor<Document> myDoc2 = col.find(ref).iterator();
    if (myDoc2.hasNext()) {
        Alert alert = new Alert(Alert.AlertType.ERROR);
        alert.setTitle("Error ");
        alert.setContentText("ChargeName Already exist!");
        alert.showAndWait();/*from  w w w  .  j  a  v a  2  s  .  c  o  m*/
        ChargeNameText.clear();
        ChargeValue.clear();
        repeat = 1;
    } else {
        repeat = 0;
    }
    if (repeat == 0 && GlobalFlag == 0) {
        InsertMongo();
        // InsertSQl(conn);
    }
    if (GlobalFlag == 1) {
        /*db.getCollection("PriceDetail").updateOne(eq("ChargeName", addon), up.append("$set", new Document("ChargeName", ChargeNameText.getText())));
        db.getCollection("PriceDetail").updateOne(eq("ChargeName", addon), up.append("$set", new Document("ChargeValue", ChargeValue.getText())));
        db.getCollection("PriceDetail").updateOne(eq("ChargeName", addon),new Document(var, var)*/
        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());

            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);        */
            updateDocument.put("$set", up.append("ChargeName", ChargeNameText.getText()));
            updateDocument.put("$set", up.append("ChargeValue", ChargeValue.getText()));
            updateDocument.put("$set", up.append("PercentageCheck", cost1));
            updateDocument.put("$set", up.append("Amountcheck", cost2));
            updateDocument.put("$set", up.append("Inactive", IFlag));
            updateDocument.put("$set", up.append("Tax", TFlag));

            db.getCollection("PriceDetail").updateOne(d1, up);
            //MongoUtils.printAllDocument("founder", "mongodb");

            //  db.getCollection("PriceDetail").updateOne(d1,updateDocument);

        }
    }
    System.out.println("global value is " + GlobalFlag);
    Stage stage = (Stage) SaveButton.getScene().getWindow();
    stage.close();
}

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

public void EditButton(String para1, String para2, String para3, String para4) {
    addon = para1;//from   ww w .ja  va 2s.  com
    GlobalFlag = 1;
    System.out.println("global value is edit button" + GlobalFlag);
    int op = 0, amt = 0;
    System.out.println("Percentage " + para3 + " Tax " + para4);
    BasicDBObject b = new BasicDBObject();
    b.put("ChargeName", para1);
    MongoCursor<Document> cursor = db.getCollection("PriceDetail").find(b).iterator();
    try {
        while (cursor.hasNext()) {
            Document d = cursor.next();
            amt = d.getInteger("Amountcheck");
            op = d.getInteger("Inactive");
        }
    } finally {
        cursor.close();
    }
    if (amt == 1) {
        AmountRadio.setSelected(true);
    } else {
        AmountRadio.setSelected(false);
    }
    if (op == 1) {
        InactiveCheck.setSelected(true);
    } else {
        InactiveCheck.setSelected(false);
    }
    if (para3.equals("Yes")) {
        PercentageRadio.setSelected(true);
        System.out.println("Percentage should be checked ");
    } else {
        PercentageRadio.setSelected(false);
    }
    if (para4.equals("Yes")) {
        TaxCheck.setSelected(true);
        System.out.println("CheckBox should check");
    } else {
        TaxCheck.setSelected(false);
    }
    ChargeNameText.setText(para1);
    ChargeValue.setText(para2);
}

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

@Override
public void initialize(URL url, ResourceBundle rb) {
    idcol.setCellValueFactory(new javafx.scene.control.cell.PropertyValueFactory<Person, Integer>("ID"));
    namecol.setCellValueFactory(new javafx.scene.control.cell.PropertyValueFactory<Person, String>("SaleName"));
    sdatecol.setCellValueFactory(//w ww. ja  v  a2  s .c om
            new javafx.scene.control.cell.PropertyValueFactory<Person, String>("StartDate"));
    edatecol.setCellValueFactory(new javafx.scene.control.cell.PropertyValueFactory<Person, String>("EndDate"));
    targetcol.setCellValueFactory(new javafx.scene.control.cell.PropertyValueFactory<Person, String>("Target"));
    couponcol.setCellValueFactory(new javafx.scene.control.cell.PropertyValueFactory<Person, String>("Coupon"));
    data.removeAll(data);
    SalesTable.getItems().removeAll(data);
    MongoCursor<Document> cur = col.find().iterator();
    while (cur.hasNext()) {
        Document d = cur.next();
        data.add(new Person(d.getInteger("ID"), d.getString("Name"), d.getString("StartDate"),
                d.getDate("EndDate").toString(), d.getString("TargetCust"), "c"));
    }
    cur.close();
    final ObservableList<Integer> highlightRows = FXCollections.observableArrayList();
    SalesTable.setItems(data);
    SalesTable.getItems().forEach(item -> Date(item));

}

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

@Override
public void initialize(URL url, ResourceBundle rb) {

    entitycol.setCellValueFactory(//ww w. j a va  2s. co  m
            new javafx.scene.control.cell.PropertyValueFactory<Person, String>("EntityName"));
    addcol.setCellValueFactory(new PropertyValueFactory("Add"));
    editcol.setCellValueFactory(new PropertyValueFactory("Edit"));
    delcol.setCellValueFactory(new PropertyValueFactory("Delete"));
    uidcol.setCellValueFactory(new PropertyValueFactory("UID"));
    fnmcol.setCellValueFactory(new PropertyValueFactory("FirstName"));
    lnmcol.setCellValueFactory(new PropertyValueFactory("LastName"));
    roleTable.setItems(empData);
    /* MongoCursor<Document> cur=db.getCollection("EmployeeDetail").find().iterator();
     while(cur.hasNext()){
         Document rs=cur.next();
         System.out.println("UserEID is "+rs.getString("UserEID")+" first name is "+rs.getString("FirstName")+" Last Name is "+rs.getString("LastName"));
         //empData.add(new Person2(rs.getString("UserEID"),rs.getString("FirstName"),rs.getString("LastName")));
     } */
    roleCombo.setOnAction((event) -> {
        String selectedPerson = roleCombo.getSelectionModel().getSelectedItem().toString();
        System.out.println("ComboBox Action (selected: " + selectedPerson + ")");
        basicdb.clear();
        data1.clear();
        RoleID = 0;
        basicdb.put("Role", selectedPerson);
        MongoCursor<Document> cursorFind = db.getCollection("EmployeeDetail").find(basicdb).iterator();
        while (cursorFind.hasNext()) {
            Document g = cursorFind.next();
            //RoleID=g.getInteger("ID");
            data1.add(new Person2(g.getString("UserEID"), g.getString("FirstName"), g.getString("LastName")));
            System.out.println("usereid " + g.getString("FirstName"));
        }
        roleTable.setItems(data1);
        System.out.println("Set data of table");
    });
    addcol.setCellFactory(new Callback<TableColumn<Person, Boolean>, TableCell<Person, Boolean>>() {
        public TableCell<Person, Boolean> call(TableColumn<Person, Boolean> p) {
            return new CheckBoxTableCell<Person, Boolean>();
        }

    });
    editcol.setCellFactory(new Callback<TableColumn<Person, Boolean>, TableCell<Person, Boolean>>() {
        public TableCell<Person, Boolean> call(TableColumn<Person, Boolean> p) {
            return new CheckBoxTableCell<Person, Boolean>();
        }
    });
    delcol.setCellFactory(new Callback<TableColumn<Person, Boolean>, TableCell<Person, Boolean>>() {

        public TableCell<Person, Boolean> call(TableColumn<Person, Boolean> p) {

            return new CheckBoxTableCell<Person, Boolean>();

        }

    });

    EntityTable.setItems(data);
    MongoCursor<Document> cursor4 = col.find().iterator();
    try {
        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.SecurityRolesController.java

@FXML
private void handleAddAction(ActionEvent event) {
    System.out.println("You clicked add of role security button!");
    try {/*from  w  w  w . ja va2  s . c om*/
        TextInputDialog dialog = new TextInputDialog();
        dialog.setTitle("Role Data");
        // dialog.setHeaderText("Look, a Text Input Dialog");
        dialog.setContentText("Security Role Name");
        // Traditional way to get the response value.
        Optional<String> result = dialog.showAndWait();
        if (result.isPresent()) {

            input = result.get();
        }
        // The Java 8 way to get the response value (with lambda expression).
        result.ifPresent(name -> System.out.println("Your name: " + name));

        ref = new BasicDBObject();
        ref.put("Name", Pattern.compile(input, Pattern.CASE_INSENSITIVE));
        MongoCursor<Document> myDoc2 = col.find(ref).iterator();
        if (myDoc2.hasNext()) {
            Alert alert = new Alert(Alert.AlertType.ERROR);
            alert.setTitle("Error ");
            alert.setContentText("Role already exist!");
            alert.showAndWait();

            repeat = 1;
        } else {
            repeat = 0;
        }
        if (repeat == 0) {
            InsertMongo();
            // InsertSQl(conn);
        }

    } catch (Exception e) {
        e.printStackTrace();
    }
}

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

public void InsertMongo() {
    count = (int) col.count();
    if (count == 0) {
        seedData = createSeedData();/*w  w w.  ja  v a  2  s. co m*/
        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();
        }
        Document input = createSeedData();
        db.getCollection("SecurityRole").insertOne(input);

    }
}

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

@Override
public void initialize(URL url, ResourceBundle rb) {
    System.out.println("intialize");
    MongoCursor<Document> cursor4 = db.getCollection("SecurityRole").find().iterator();

    try {//w w w  .  j a v  a 2  s  .c o m
        while (cursor4.hasNext()) {

            String rs = cursor4.next().getString("Role");

            rolelist.getItems().addAll(rs.toString());

            //   System.out.println("output is "+String.valueOf(rs1)));
        }
    } finally {
        cursor4.close();
    }

}

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

@Override
public void initialize(URL url, ResourceBundle rb) {

    /*  String qry="select name from brand_detail";
    java.sql.Connection conn=Connection.getConnect();            
    PreparedStatement pst2=conn.prepareStatement(qry);
    ResultSet rs = pst2.executeQuery(qry);
    while(rs.next()){                //ww w  .j av a2  s  . c om
       List.getItems().addAll(rs.getString("name"));
    }*/
    MongoCursor<Document> cursor4 = col.find().iterator();
    try {
        while (cursor4.hasNext()) {

            String rs = cursor4.next().getString("Name");

            List.getItems().addAll(rs);

        }
    } finally {
        cursor4.close();
    }

}

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

@Override
public void initialize(URL url, ResourceBundle rb) {

    /*  String qry="select name from category_detail";
    java.sql.Connection conn=Connection.getConnect();            
    PreparedStatement pst2=conn.prepareStatement(qry);
    ResultSet rs = pst2.executeQuery(qry);
    while(rs.next()){//from  www  .ja  va  2  s.  co m
                
       List.getItems().addAll(rs.getString("name"));
    }*/
    MongoCursor<Document> cursor4 = col.find().iterator();
    try {
        while (cursor4.hasNext()) {

            String rs = cursor4.next().getString("Name");

            List.getItems().addAll(rs);

        }
    } finally {
        cursor4.close();
    }

}

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

public void update() {

    /*Stage stage=new Stage();
    FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("AddDept.fxml"));
    Parent root4=(Parent) fxmlLoader.load();
    AddDeptController controller=fxmlLoader.<AddDeptController>getController();
    stage.setScene(new Scene(root4));/* www . ja v  a 2 s .co m*/
    System.out.println("dept name entered is "+ controller.getData());
    List.getItems().add("Hello");*/
    /*String qry="select name from dept_detail";
    java.sql.Connection conn=Connection.getConnect();
            
    PreparedStatement pst2=conn.prepareStatement(qry);
    ResultSet rs = pst2.executeQuery(qry);
    while(rs.next()){
        List.getItems().addAll(rs.getString("name"));               
    }*/
    MongoCursor<Document> cursor4 = col.find().iterator();
    try {
        while (cursor4.hasNext()) {

            String rs = cursor4.next().getString("Name");

            List.getItems().addAll(rs);

        }
    } finally {
        cursor4.close();
    }

}