List of usage examples for com.mongodb.client MongoCursor close
@Override
void close();
From source file:com.mycompany.mavenproject2.AddCatController.java
public Document createSeedData() { d = new Document(); b = new BasicDBObject(); b.put("Name", DeptCombo.getValue()); MongoCursor<Document> cursor = db.getCollection("DeptDetail").find(b).iterator(); try {/*from w w w.j a v a2s . c o m*/ while (cursor.hasNext()) { i = cursor.next().getInteger("ID"); System.out.println("Searched Output " + i); } } finally { cursor.close(); } d.append("Name", CatName.getText()); d.append("LocalName", LocalName.getText()); d.append("Dept_ID", i); return d; }
From source file:com.mycompany.mavenproject2.AddCatController.java
@Override public void initialize(URL url, ResourceBundle rb) { /* String qry="select name from dept_detail"; java.sql.Connection conn=Connection.getConnect(); //w w w .j a va 2s. c o m PreparedStatement pst2=conn.prepareStatement(qry); ResultSet rs1 = pst2.executeQuery(qry); while(rs1.next()){ DeptCombo.setValue(rs1.getString("name")); DeptCombo.getItems().addAll(rs1.getString("name")); } */ MongoCursor<Document> cursor4 = db.getCollection("DeptDetail").find().iterator(); try { while (cursor4.hasNext()) { String rs = cursor4.next().getString("Name"); DeptCombo.setValue(rs); DeptCombo.getItems().addAll(rs); System.out.println("Intialize out put is " + rs); } } finally { cursor4.close(); } }
From source file:com.mycompany.mavenproject2.AddDeptController.java
public void InsertMongo() throws ParseException, IOException { if (Margin.isSelected()) { rFlag1 = 1;// ww w.j a v a 2 s. com } else { rFlag1 = 0; } if (MarkUp.isSelected()) { rFlag2 = 1; } else { rFlag2 = 0; } if (Taxable.isSelected()) { tFlag = 1; } else { tFlag = 0; } if (Price.isSelected()) { pFlag = 1; } else { pFlag = 0; } if (FoodStamp.isSelected()) { fFlag = 1; } else { fFlag = 0; } /* DateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'", Locale.ENGLISH); db.getCollection("restaurants").insertOne( new Document("address", new Document() .append("street", "2 Avenue") .append("zipcode", "10075") .append("building", "1480") .append("coord", asList(-73.9557413, 40.7720266))) .append("borough", "Manhattan") .append("cuisine", "Italian") .append("grades", asList( new Document() .append("date", format.parse("2014-10-01T00:00:00Z")) .append("grade", "A") .append("score", 11), new Document() .append("date", format.parse("2014-01-16T00:00:00Z")) .append("grade", "B") .append("score", 17))) .append("name", "Vella") .append("restaurant_id", "41704620")); System.out.println("Data are Inserted");*/ //Find all document /*b=new BasicDBObject(); b.put("Name", "sdfg"); MongoCursor<Document> cursor = db.getCollection("CategoryDetail").find(b).iterator(); try { while (cursor.hasNext()) { System.out.println("Searched Output "+cursor.next().toJson() ); } } finally { cursor.close(); }*/ /* MongoCursor<Document> cursor4 = db.getCollection("CategoryDetail").find().iterator(); try { while (cursor4.hasNext()) { System.out.println("column val is "+cursor4.next().getString("LocalName")); } } finally { cursor.close(); }*/ //Find First Document /* Document myDoc = db.getCollection("restaurants").find().first(); System.out.println("First Column is "+myDoc.toJson());*/ //Where Clause /*Document myDoc = db.getCollection("restaurants").find(eq("borough", "ManhattanFirst")).first(); System.out.println("sd" +myDoc.toJson());*/ //col.find({}).sort({_id:-1}).limit(1); 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()) { 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); } /*count= (long) col.count(); MongoCursor<Document> cursor = col.find().sort(sort1).limit(1).skip((int)count-1).iterator(); try { while (cursor.hasNext()) { System.out.println("Searched Output "+cursor.next().toJson()); } } finally { cursor.close(); }*/ /* MongoCursor<Document> cursor = col.find().limit(3).sort({timestamp:-1}); try { while (cursor.hasNext()) { System.out.println("Searched Output "+cursor.next().toJson()); } } finally { cursor.close(); }*/ Stage stage = new Stage(); FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("/fxml/SelectDept.fxml")); Parent root4 = (Parent) fxmlLoader.load(); SelectDeptController controller = fxmlLoader.<SelectDeptController>getController(); stage.setScene(new Scene(root4)); stage.setTitle("Select Department"); controller.update(); LocalName.clear(); DeptName.clear(); value.clear(); }
From source file:com.mycompany.mavenproject2.AddItemListController.java
public Document createSeedData() { d = new Document(); b = new BasicDBObject(); b.put("Name", DeptCombo.getValue()); MongoCursor<Document> cursor = db.getCollection("DeptDetail").find(b).iterator(); try {/*from w ww . ja v a 2 s.c o m*/ while (cursor.hasNext()) { dept_id = cursor.next().getInteger("ID"); System.out.println("Searched Output " + dept_id); } } finally { cursor.close(); } b.clear(); b.put("Name", SizeCombo.getValue().toString()); System.out.println("Size outtput is " + SizeCombo.getValue().toString()); cursor = db.getCollection("SizeDetail").find(b).iterator(); try { while (cursor.hasNext()) { size_name = cursor.next().getString("Name"); System.out.println("size Output " + size_name); } } finally { cursor.close(); } b.clear(); b.put("Name", PackCombo.getValue().toString()); cursor = db.getCollection("PackDetail").find(b).iterator(); try { while (cursor.hasNext()) { pack_name = cursor.next().getString("Name"); System.out.println("pack Output " + pack_name); } } finally { cursor.close(); } b.clear(); b.put("Name", BrandCombo.getValue().toString()); cursor = db.getCollection("BrandDetail").find(b).iterator(); try { while (cursor.hasNext()) { brand_name = cursor.next().getString("Name"); System.out.println("brand Output " + brand_name); } } finally { cursor.close(); } if (NonStockCheck.isSelected()) { nonstock = 1; } else { nonstock = 0; } if (NonTaxCheck.isSelected()) { nontax = 1; } else { nontax = 0; } if (QuantityCheck.isSelected()) { qua = 1; } else { qua = 0; } if (PriceCheck.isSelected()) { priceF = 1; } else { priceF = 0; } if (WeightedItem.isSelected()) { check1 = 1; } else { check1 = 0; } if (WebItem.isSelected()) { check2 = 1; } else { check2 = 0; } if (ExcludeSale.isSelected()) { check3 = 1; } else { check3 = 0; } if (WIC.isSelected()) { check4 = 1; } else { check4 = 0; } if (HealthCard.isSelected()) { check5 = 1; } else { check5 = 0; } if (FoodStamp.isSelected()) { check6 = 1; } else { check6 = 0; } if (NonRevenueItem.isSelected()) { check7 = 1; } else { check7 = 0; } if (NonDiscountable.isSelected()) { check8 = 1; } else { check8 = 0; } d.append("SKU", SKUTextField.getText()); d.append("ItemDesc", DescriptionTextField.getText()); d.append("ItemName", ItemNameText.getText()); d.append("Dept_ID", dept_id); d.append("Size_Name", size_name); d.append("Pack_Name", pack_name); d.append("Cat_Name", CatCombo.getValue()); d.append("Brand_Name", brand_name); d.append("Location", LocationCombo.getValue()); d.append("Model_Num", ModelText.getText()); d.append("Part_Num", PartText.getText()); d.append("NonStock", nonstock); d.append("UnitType", IventoryTypeCombo.getValue()); d.append("NonText", nontax); d.append("Tax1", Tax1Text.getText()); d.append("Tax2", Tax2Text.getText()); d.append("Tax3", Tax3Text.getText()); d.append("QualityPrompt", priceF); d.append("PricePrompt", priceF); d.append("UnitCost", UnitCostText.getText()); d.append("UnitPrice", UnitPriceText.getText()); d.append("Margin", MarginText.getText()); d.append("MSRP", MSRPText.getText()); d.append("BuyDownAmount", BuyDownText.getText()); d.append("MarkUP", MarkUpText.getText()); d.append("SalesPrice", SaleText.getText()); d.append("WeightedItem", check1); d.append("WebItem", check2); d.append("ExcludeSale", check3); d.append("WIC", check4); d.append("HealthCard", check5); d.append("FoodStamp", check6); d.append("NonRevenueItem", check7); d.append("NonDiscountable", check8); table.getItems().forEach(item -> d.append("Quantity", item.getValue())); costTable.getItems().forEach(item -> d.append("CostQuantity", item.getUnitName())); costTable.getItems().forEach(item -> d.append("Price", item.getValue())); return d; }
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")); /* ww w . j av a 2 s. c om*/ 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();/* w ww . j ava2s . 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 ww.j a v a2s. c om 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 {/*ww w . j av a2 s . co 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 ww . ja 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
public void InsertMongo() { count = (int) col.count(); if (count == 0) { seedData = createSeedData();//ww w . j a v a 2s . c om 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); } }