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

@FXML
public void handleSaveNewButtonAction(ActionEvent a) {

    /*java.sql.Connection conn=Connection.getConnect();
     String Add1="INSERT INTO pack_detail "
          +"(`name`,`local_name`,`unit`) "
          + "VALUES (?,?,?)";/*  w w w.java 2 s . co m*/
     PreparedStatement inQuery=conn.prepareStatement(Add1);
     inQuery.setString(1, name.getText().toString());
     inQuery.setString(2, LocalName.getText().toString());  
     inQuery.setInt(3, Integer.parseInt(unit.getText().toString()));  
            
     inQuery.executeUpdate();
     name.clear();
     LocalName.clear();
     unit.clear();*/
    ref = new BasicDBObject();
    ref.put("Name", Pattern.compile(name.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("Area already exist!");
        alert.showAndWait();
        name.clear();
        LocalName.clear();
        unit.clear();
        repeat = 1;
    } else {
        repeat = 0;
    }
    if (repeat == 0) {
        InsertMongo();
        // InsertSQl(conn);
    }

}

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

@FXML
public void handleSaveCloseButtonAction(ActionEvent a) {
    ref = new BasicDBObject();
    ref.put("Name", Pattern.compile(name.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("Area already exist!");
        alert.showAndWait();// w ww.j av  a 2 s. c o m
        name.clear();
        LocalName.clear();
        unit.clear();
        repeat = 1;
    } else {
        repeat = 0;
    }
    if (repeat == 0) {
        InsertMongo();
        // InsertSQl(conn);
    }
    Stage stage = (Stage) Save.getScene().getWindow();
    stage.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  a  2 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

@FXML
public void handleSaveNewButtonAction(ActionEvent a) {
    ref = new BasicDBObject();
    ref.put("Name", Pattern.compile(SizeName.getText(), Pattern.CASE_INSENSITIVE));
    MongoCursor<Document> myDoc2 = db.getCollection("SizeDetail").find(ref).iterator();
    if (myDoc2.hasNext()) {
        Alert alert = new Alert(Alert.AlertType.ERROR);
        alert.setTitle("Error ");
        alert.setContentText("Size Name already exist!");
        alert.showAndWait();/*  w ww  .  jav a 2s.  c  om*/
        LocalName.clear();
        SizeName.clear();
        UnitText.clear();
        repeat = 1;
    } else {
        repeat = 0;
    }
    if (repeat == 0) {
        InsertMongo();
    }
}

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

@FXML
public void handleSaveCloseButtonAction(ActionEvent a) {
    ref = new BasicDBObject();
    ref.put("Name", Pattern.compile(SizeName.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("Size Name already exist!");
        alert.showAndWait();//  ww w  . j  a va2 s  .  c om
        LocalName.clear();
        SizeName.clear();
        UnitText.clear();
        repeat = 1;
    } else {
        repeat = 0;
    }
    if (repeat == 0) {
        InsertMongo();
    }
    Stage stage = (Stage) Save.getScene().getWindow();
    stage.close();
}

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  av a 2 s  .c  o  m*/
        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 {/*from  w  w  w  .  j  a  v a 2  s. 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";
            /*ww w .  j  a  v a 2  s  .  co m*/
    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

@FXML
public void handleSaveNewButtonAction(ActionEvent a) {
    ref = new BasicDBObject();
    ref.put("Name", Pattern.compile(name.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("UOM already exist!");
        alert.showAndWait();/*from   w w  w. j a v  a 2  s.c o m*/
        name.clear();
        local_name.clear();
        repeat = 1;
    } else {
        repeat = 0;
    }
    if (repeat == 0) {
        InsertMongo();

    }
}

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

@FXML
public void handleSaveCloseButtonAction(ActionEvent a) {
    ref = new BasicDBObject();
    ref.put("Name", Pattern.compile(name.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("UOM already exist!");
        alert.showAndWait();/*  w  w  w .  j a  v a  2  s .  co m*/
        name.clear();
        local_name.clear();
        repeat = 1;
    } else {
        repeat = 0;
    }
    if (repeat == 0) {
        InsertMongo();
    }
    Stage stage = (Stage) Save.getScene().getWindow();
    stage.close();

}