Example usage for com.mongodb.client MongoCursor next

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

Introduction

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

Prototype

@Override
    TResult next();

Source Link

Usage

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

@Override
public void initialize(URL url, ResourceBundle rb) {
    // quantitycol.setCellValueFactory(new javafx.scene.control.cell.PropertyValueFactory<Person,String>("Value"));
    /*worked facilitycol.setCellValueFactory(new javafx.scene.control.cell.PropertyValueFactory<Person,String>("UnitName"));
            /* w  ww .  ja v a2 s  .  c o m*/
    quantitycol.setCellFactory(TextFieldTableCell.<Person>forTableColumn());
      table.setEditable(true);                
    table.setItems(data);*/
    // quantitycol.setCellValueFactory(new javafx.scene.control.cell.PropertyValueFactory<Person,String>("Value"));
    table.setEditable(true);

    Callback<TableColumn<Person, String>, TableCell<Person, String>> cellFactory = (
            TableColumn<Person, String> p) -> new EditCell3();

    facilitycol.setCellValueFactory(
            new javafx.scene.control.cell.PropertyValueFactory<Person, String>("UnitName"));

    // quantitycol.setCellFactory(TextFieldTableCell.<Person>forTableColumn());
    quantitycol.setCellValueFactory(new PropertyValueFactory<>("Qantity"));
    quantitycol.setCellFactory(cellFactory);
    /* quantitycol.setOnEditCommit((CellEditEvent<Person, String> t) -> {
    ((Person) t.getTableView().getItems().get(t.getTablePosition().getRow())).setValue(t.getNewValue());
     });*/
    table.setItems(data);
    /*table.addEventFilter(KeyEvent.KEY_PRESSED, new EventHandler<KeyEvent>() {
    @Override
    public void handle(KeyEvent e) {
            
        if( e.getCode() == KeyCode.TAB) { // commit should be performed implicitly via focusedProperty, but isn't
            table.getSelectionModel().selectNext();
            e.consume();
            return;
        }
        else if( e.getCode() == KeyCode.ENTER) { // commit should be performed implicitly via focusedProperty, but isn't
            table.getSelectionModel().selectBelowCell();
            e.consume();
            return;
        }
            
        // switch to edit mode on keypress, but only if we aren't already in edit mode
        if( table.getEditingCell() == null) {
            if( e.getCode().isLetterKey() || e.getCode().isDigitKey()) {  
            
                TablePosition focusedCellPosition = table.getFocusModel().getFocusedCell();
                table.edit(focusedCellPosition.getRow(), focusedCellPosition.getTableColumn());
            
            }
        }
            
    }
       });*/

    quantitycol.setOnEditCommit(new EventHandler<CellEditEvent<Person, String>>() {
        @Override
        public void handle(CellEditEvent<Person, String> t) {
            ((Person) t.getTableView().getItems().get(t.getTablePosition().getRow())).setValue(t.getNewValue());

        }
    });
    // single cell selection mode
    table.getSelectionModel().setCellSelectionEnabled(true);
    table.getSelectionModel().selectFirst();
    DeptCombo.valueProperty().addListener(new ChangeListener<String>() {
        @Override
        public void changed(ObservableValue ov, String t, String t1) {
            System.out.println("Observation value is " + ov);
            System.out.println("Last selected is " + t);
            System.out.println("current selection " + t1);
            SelctedDept = t1;
            obj.put("Name", SelctedDept);
            MongoCursor<Document> cur = db.getCollection("DeptDetail").find(obj).iterator();
            try {
                while (cur.hasNext()) {
                    int rs = cur.next().getInteger("ID");
                    System.out.println("first Selcted dept is " + SelctedDept + " id is   " + rs);
                    ADept = rs;
                }

            } finally {
                cur.close();
            }
            obj1.put("Dept_ID", ADept);
            cur = db.getCollection("CategoryDetail").find(obj1).iterator();
            CatCombo.getItems().clear();
            try {
                while (cur.hasNext()) {
                    String rs1 = cur.next().getString("Name");
                    System.out.println("Category for dept is " + SelctedDept + " Category is   " + rs1);

                    CatCombo.setValue(rs1);
                    CatCombo.getItems().addAll(rs1);
                }

            } finally {
                cur.close();
            }
        }
    });

    /*       String qry="select name from category_detail";
    String qry1="select name from dept_detail";
    String qry4="select name from size_detail";
    String qry5="select name from pack_detail";
    String qry6="select name from brand_detail";
    String qry7="select name from location_detail";
    java.sql.Connection conn=Connection.getConnect();            
    PreparedStatement pst2=conn.prepareStatement(qry);
    PreparedStatement pst1=conn.prepareStatement(qry1);
    PreparedStatement pst4=conn.prepareStatement(qry4);
    PreparedStatement pst5=conn.prepareStatement(qry5);
    PreparedStatement pst6=conn.prepareStatement(qry6);
    PreparedStatement pst7=conn.prepareStatement(qry7);
    ResultSet rs = pst2.executeQuery(qry);
    ResultSet rs1 = pst1.executeQuery(qry1);
    ResultSet rs4 = pst4.executeQuery(qry4);            
    ResultSet rs5 = pst5.executeQuery(qry5);            
    ResultSet rs6 = pst6.executeQuery(qry6);            
    ResultSet rs7 = pst7.executeQuery(qry7);            
    while(rs.next()){
      CatCombo.setValue(rs.getString("name"));
      CatCombo.getItems().addAll(rs.getString("name"));
    }            
          while(rs1.next()){
     DeptCombo.setValue(rs1.getString("name"));
     DeptCombo.getItems().addAll(rs1.getString("name"));
    }
          while(rs4.next()){
     SizeCombo.setValue(rs4.getString("name"));
     SizeCombo.getItems().addAll(rs4.getString("name"));
    }
          while(rs5.next()){
     PackCombo.setValue(rs5.getString("name"));
     PackCombo.getItems().addAll(rs5.getString("name"));
    }
          while(rs6.next()){
     BrandCombo.setValue(rs6.getString("name"));
     BrandCombo.getItems().addAll(rs6.getString("name"));
    }
          while(rs7.next()){
     LocationCombo.setValue(rs7.getString("name"));
     LocationCombo.getItems().addAll(rs7.getString("name"));
    }*/
    MongoCursor<Document> cursor4 = db.getCollection("CategoryDetail").find().iterator();
    try {
        while (cursor4.hasNext()) {
            String rs = cursor4.next().getString("Name");
            CatCombo.setValue(rs);
            CatCombo.getItems().addAll(rs);
        }
    } finally {
        cursor4.close();
    }
    cursor4 = db.getCollection("DeptDetail").find().iterator();
    try {
        while (cursor4.hasNext()) {
            String rs = cursor4.next().getString("Name");
            DeptCombo.setValue(rs);
            DeptCombo.getItems().addAll(rs);
        }
    } finally {
        cursor4.close();
    }
    cursor4 = db.getCollection("LocationDetail").find().iterator();
    try {
        while (cursor4.hasNext()) {
            String rs = cursor4.next().getString("Name");
            LocationCombo.setValue(rs);
            LocationCombo.getItems().addAll(rs);
        }
    } finally {
        cursor4.close();
    }
    cursor4 = db.getCollection("BrandDetail").find().iterator();
    try {
        while (cursor4.hasNext()) {
            String rs = cursor4.next().getString("Name");
            BrandCombo.setValue(rs);
            BrandCombo.getItems().addAll(rs);
        }
    } finally {
        cursor4.close();
    }
    cursor4 = db.getCollection("PackDetail").find().iterator();
    try {
        while (cursor4.hasNext()) {
            String rs = cursor4.next().getString("Name");
            PackCombo.setValue(rs);
            PackCombo.getItems().addAll(rs);
        }
    } finally {
        cursor4.close();
    }
    cursor4 = db.getCollection("SizeDetail").find().iterator();
    try {
        while (cursor4.hasNext()) {
            String rs = cursor4.next().getString("Name");
            SizeCombo.setValue(rs);
            SizeCombo.getItems().addAll(rs);
        }
    } finally {
        cursor4.close();
    }
}

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

public void InsertMongo() {
    count = (int) col.count();
    if (count == 0) {
        seedData = createSeedData();//ww  w  .  j a v a2 s .  c  o  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();
        }

        final Document seedData = createSeedData();
        col.insertOne(seedData);
    }
    name.clear();
    LocalName.clear();
    unit.clear();
}

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

public void InsertMongo() {
    count = (int) col.count();
    if (count == 0) {
        seedData = createSeedData();/*from w  w w  .  j a va  2s  . com*/
        col.insertOne(seedData);
    } else {
        sort2 = new BasicDBObject();
        MongoCursor<Document> cursor = col.find().sort(sort2).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();
        col.insertOne(seedData);

        LocalName.clear();
        SizeName.clear();
        UnitText.clear();
    }
}

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

public Document createSeedData() {
    d = new Document();
    b = new BasicDBObject();
    b.put("Name", UOMCombo.getValue());
    MongoCursor<Document> cursor = ucol.find(b).iterator();
    try {//w  w w  .  j  a  va2s  .c  o m
        while (cursor.hasNext()) {
            i = cursor.next().getInteger("ID");
            System.out.println("Searched Output " + i);
        }
    } finally {
        cursor.close();
    }

    Document d = new Document();
    d.append("Name", SizeName.getText());
    d.append("LocalName", LocalName.getText());
    d.append("Unit", Integer.parseInt(UnitText.getText()));
    d.append("UOM_ID", i);
    d.append("ID", ID);
    System.out.println("UOM Id is " + i);
    return d;
}

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

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

    /*      String qry="select name from uom_detail";
            /*from w  w  w.j ava2 s .com*/
    java.sql.Connection conn=Connection.getConnect();            
    PreparedStatement pst2=conn.prepareStatement(qry);
            
    ResultSet rs = pst2.executeQuery(qry);
            
    while(rs.next()){
      UOMCombo.setValue(rs.getString("name"));
      UOMCombo.getItems().addAll(rs.getString("name"));
    }            */
    MongoCursor<Document> cursor4 = ucol.find().iterator();
    try {
        while (cursor4.hasNext()) {

            String rs = cursor4.next().getString("Name");
            UOMCombo.getItems().addAll(rs);
            UOMCombo.setValue(rs);
        }
    } finally {
        cursor4.close();
    }

}

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

public void InsertMongo() {
    count = (int) col.count();
    if (count == 0) {
        seedData = createSeedData();// w  w  w  .ja  v a2s  . 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();
        }
        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  ww  w .j a  v a  2s.  c  o  m*/
    } 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  w w  w . j av a2 s. c om
    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());
               /*from  ww w.ja  va  2s  . c  o  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  ww  . ja va 2  s  .  c  o m
        while (cursor4.hasNext()) {
            String rs = cursor4.next().getString("Role");
            roleCombo.setValue(rs);
            roleCombo.getItems().addAll(rs);
        }
    } finally {
        cursor4.close();
    }
}