List of usage examples for com.mongodb.client MongoCollection insertOne
void insertOne(TDocument document);
From source file:com.mycompany.mavenproject2.AddItemListController.java
public void InsertMongo() { client = new MongoClient(); db = client.getDatabase("FinalDemo"); MongoCollection col = db.getCollection("ItemDetail"); System.out.println("colection created " + col.toString()); final Document seedData = createSeedData(); col.insertOne(seedData); SKUTextField.clear();//w ww . jav a 2 s . co m DescriptionTextField.clear(); ItemNameText.clear(); }
From source file:com.mycompany.team2.Game.java
private void ComputeButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ComputeButtonActionPerformed // TODO add your handling code here: if (jComboBox1.getSelectedItem().toString().equals("ADD")) { System.out.println("Heelo dropdown"); num1 = Textbox1.getText();/*from w w w.j a v a2 s .c o m*/ num2 = Textbox2.getText(); number1 = Integer.parseInt(num1); number2 = Integer.parseInt(num2); int answer = methd.addNum(number1, number2); String answerAsString = Integer.toString(answer); TextboxAnswer.setText(answerAsString); Document doc = new Document(); doc.put("ADD", answerAsString); collx.insertOne(doc); System.out.println("Inserted to log"); /* DBCursor cursor = (DBCursor) collx.find(); int i = 1; while(cursor.hasNext()){ System.out.println("Inserted Document: " + i); System.out.println(cursor.next()); i++; } */ } if (jComboBox1.getSelectedItem().toString().equals("SUBTRACT")) { System.out.println("Heelo dropdown"); num1 = Textbox1.getText(); num2 = Textbox2.getText(); number1 = Integer.parseInt(num1); number2 = Integer.parseInt(num2); int answer = methd.subNum(number1, number2); String answerAsString = Integer.toString(answer); TextboxAnswer.setText(answerAsString); try { MongoCollection collx = database.getCollection("TeamCity"); BasicDBObject doc = new BasicDBObject(); doc.put("SUBTRACT", answerAsString); collx.insertOne(doc); DBCursor cursor = (DBCursor) collx.find(); int i = 1; while (cursor.hasNext()) { System.out.println("Inserted Document: " + i); System.out.println(cursor.next()); i++; } } catch (Exception e) { System.out.println("Catch The answer"); } } if (jComboBox1.getSelectedItem().toString().equals("DIVIDE")) { System.out.println("Heelo dropdown"); num1 = Textbox1.getText(); num2 = Textbox2.getText(); number1 = Integer.parseInt(num1); number2 = Integer.parseInt(num2); int answer = methd.divNum(number1, number2); String answerAsString = Integer.toString(answer); TextboxAnswer.setText(answerAsString); try { BasicDBObject doc = new BasicDBObject(); doc.put("DIVIDE", answerAsString); collx.insertOne(doc); DBCursor cursor = (DBCursor) collx.find(); int i = 1; while (cursor.hasNext()) { System.out.println("Inserted Document: " + i); System.out.println(cursor.next()); i++; } } catch (Exception e) { System.out.println("Catch The answer"); } } if (jComboBox1.getSelectedItem().toString().equals("MULTIPLY")) { System.out.println("Heelo dropdown"); num1 = Textbox1.getText(); num2 = Textbox2.getText(); number1 = Integer.parseInt(num1); number2 = Integer.parseInt(num2); int answer = methd.mulNum(number1, number2); String answerAsString = Integer.toString(answer); TextboxAnswer.setText(answerAsString); try { BasicDBObject doc = new BasicDBObject(); doc.put("MULTIPLY", answerAsString); collx.insertOne(doc); DBCursor cursor = (DBCursor) collx.find(); int i = 1; while (cursor.hasNext()) { System.out.println("Inserted Document: " + i); System.out.println(cursor.next()); i++; } } catch (Exception e) { System.out.println("Catch The answer"); } } if (jComboBox1.getSelectedItem().toString().equals("COUNTRY")) { System.out.println("Heelo dropdown"); num1 = Textbox1.getText(); num2 = Textbox2.getText(); number1 = Integer.parseInt(num1); number2 = Integer.parseInt(num2); int answer = methd.retCountry(number1, number2); String answerAsString = methd.getCountry(); TextboxAnswer.setText(answerAsString); try { BasicDBObject doc = new BasicDBObject(); doc.put("COUNTRY", answerAsString); collx.insertOne(doc); DBCursor cursor = (DBCursor) collx.find(); int i = 1; while (cursor.hasNext()) { System.out.println("Inserted Document: " + i); System.out.println(cursor.next()); i++; } } catch (Exception e) { System.out.println("Catch The answer"); } } }
From source file:com.navercorp.pinpoint.plugin.mongodb.MongoDBBase.java
License:Apache License
public void insertComlexBsonValueData30(PluginTestVerifier verifier, MongoCollection<Document> collection, Class<?> mongoDatabaseImpl, String collectionInfo, String collectionOption) { //insert Data BsonValue a = new BsonString("stest"); BsonValue b = new BsonDouble(111); BsonValue c = new BsonBoolean(true); Document document = new Document().append("int32", new BsonInt32(12)).append("int64", new BsonInt64(77L)) .append("bo\"olean", new BsonBoolean(true)).append("date", new BsonDateTime(new Date().getTime())) .append("double", new BsonDouble(12.3)).append("string", new BsonString("pinpoint")) .append("objectId", new BsonObjectId(new ObjectId())) .append("code", new BsonJavaScript("int i = 10;")) .append("codeWithScope", new BsonJavaScriptWithScope("int x = y", new BsonDocument("y", new BsonInt32(1)))) .append("regex", new BsonRegularExpression("^test.*regex.*xyz$", "big")) .append("symbol", new BsonSymbol("wow")).append("timestamp", new BsonTimestamp(0x12345678, 5)) .append("undefined", new BsonUndefined()) .append("binary1", new BsonBinary(new byte[] { (byte) 0xe0, 0x4f, (byte) 0xd0, 0x20 })) .append("oldBinary", new BsonBinary(BsonBinarySubType.OLD_BINARY, new byte[] { 1, 1, 1, 1, 1 })) .append("arrayInt", new BsonArray(Arrays.asList(a, b, c, new BsonInt32(7)))) .append("document", new BsonDocument("a", new BsonInt32(77))) .append("dbPointer", new BsonDbPointer("db.coll", new ObjectId())).append("null", new BsonNull()); collection.insertOne(document); Object[] objects = new Object[1]; objects[0] = document;// w ww . j a v a2 s. c o m StringStringValue parsedBson = MongoUtil.parseBson(objects, true); Method insertOne; try { insertOne = mongoDatabaseImpl.getDeclaredMethod("insertOne", Object.class); } catch (NoSuchMethodException e) { insertOne = null; } verifier.verifyTrace(event(MONGO_EXECUTE_QUERY, insertOne, null, MONGODB_ADDRESS, null, new ExpectedAnnotation(MongoConstants.MONGO_COLLECTION_INFO.getName(), collectionInfo), new ExpectedAnnotation(MongoConstants.MONGO_COLLECTION_OPTION.getName(), collectionOption), new ExpectedAnnotation(MongoConstants.MONGO_JSON_DATA.getName(), parsedBson))); }
From source file:com.navercorp.pinpoint.plugin.mongodb.MongoDBBase.java
License:Apache License
public void insertComlexBsonValueData34(PluginTestVerifier verifier, MongoCollection<Document> collection, Class<?> mongoDatabaseImpl, String collectionInfo, String collectionOption) { //insert Data BsonValue a = new BsonString("stest"); BsonValue b = new BsonDouble(111); BsonValue c = new BsonBoolean(true); Document document = new Document().append("int32", new BsonInt32(12)).append("int64", new BsonInt64(77L)) .append("bo\"olean", new BsonBoolean(true)).append("date", new BsonDateTime(new Date().getTime())) .append("double", new BsonDouble(12.3)).append("string", new BsonString("pinpoint")) .append("objectId", new BsonObjectId(new ObjectId())) .append("code", new BsonJavaScript("int i = 10;")) .append("codeWithScope", new BsonJavaScriptWithScope("int x = y", new BsonDocument("y", new BsonInt32(1)))) .append("regex", new BsonRegularExpression("^test.*regex.*xyz$", "big")) .append("symbol", new BsonSymbol("wow")).append("timestamp", new BsonTimestamp(0x12345678, 5)) .append("undefined", new BsonUndefined()) .append("binary1", new BsonBinary(new byte[] { (byte) 0xe0, 0x4f, (byte) 0xd0, 0x20 })) .append("oldBinary", new BsonBinary(BsonBinarySubType.OLD_BINARY, new byte[] { 1, 1, 1, 1, 1 })) .append("arrayInt", new BsonArray(Arrays.asList(a, b, c, new BsonInt32(7)))) .append("document", new BsonDocument("a", new BsonInt32(77))) .append("dbPointer", new BsonDbPointer("db.coll", new ObjectId())).append("null", new BsonNull()) .append("decimal128", new BsonDecimal128(new Decimal128(55))); collection.insertOne(document); Object[] objects = new Object[1]; objects[0] = document;/*from w w w .j ava2 s.co m*/ StringStringValue parsedBson = MongoUtil.parseBson(objects, true); Method insertOne; try { insertOne = mongoDatabaseImpl.getDeclaredMethod("insertOne", Object.class); } catch (NoSuchMethodException e) { insertOne = null; } verifier.verifyTrace(event(MONGO_EXECUTE_QUERY, insertOne, null, MONGODB_ADDRESS, null, new ExpectedAnnotation(MongoConstants.MONGO_COLLECTION_INFO.getName(), collectionInfo), new ExpectedAnnotation(MongoConstants.MONGO_COLLECTION_OPTION.getName(), collectionOption), new ExpectedAnnotation(MongoConstants.MONGO_JSON_DATA.getName(), parsedBson))); }
From source file:com.navercorp.pinpoint.plugin.mongodb.MongoDBBase.java
License:Apache License
public void insertData(PluginTestVerifier verifier, MongoCollection<Document> collection, Class<?> mongoDatabaseImpl, String collectionInfo, String collectionOption) { //insert Data Document doc = new Document("name", "Roy").append("company", "Naver"); collection.insertOne(doc); Object[] objects = new Object[1]; objects[0] = doc;/*from ww w . j av a 2 s . c o m*/ StringStringValue parsedBson = MongoUtil.parseBson(objects, true); Method insertOne; try { insertOne = mongoDatabaseImpl.getDeclaredMethod("insertOne", Object.class); } catch (NoSuchMethodException e) { insertOne = null; } verifier.verifyTrace(event(MONGO_EXECUTE_QUERY, insertOne, null, MONGODB_ADDRESS, null, new ExpectedAnnotation(MongoConstants.MONGO_COLLECTION_INFO.getName(), collectionInfo), new ExpectedAnnotation(MongoConstants.MONGO_COLLECTION_OPTION.getName(), collectionOption), new ExpectedAnnotation(MongoConstants.MONGO_JSON_DATA.getName(), parsedBson))); }
From source file:com.shampan.model.LoginAttemptModel.java
/** * this method will add login attempt of a user * * @param email */*from w w w . j ava 2s.co m*/ */ public ResultEvent increaseLoginAttempt(String loginAttemptInfo) { try { MongoCollection<LoginAttemptDAO> mongoCollection = DBConnection.getInstance().getConnection() .getCollection(Collections.LOGINATTEMPTS.toString(), LoginAttemptDAO.class); LoginAttemptDAO loginInfo = new LoginAttemptDAOBuilder().build(loginAttemptInfo); if (loginInfo != null) { loginInfo.setTime(utility.getCurrentTime()); mongoCollection.insertOne(loginInfo); this.getResultEvent().setResponseCode(PropertyProvider.get("SUCCESSFUL_OPERATION")); } else { this.getResultEvent().setResponseCode(PropertyProvider.get("NULL_POINTER_EXCEPTION")); } } catch (Exception ex) { this.getResultEvent().setResponseCode(PropertyProvider.get("ERROR_EXCEPTION")); } return this.resultEvent; }
From source file:com.shampan.model.PageModel.java
public ResultEvent addPage(String pageInfo) { try {//from w w w. j av a2 s .c o m MongoCollection<PageDAO> mongoCollection = DBConnection.getInstance().getConnection() .getCollection(Collections.PAGES.toString(), PageDAO.class); PageDAO pageInformation = new PageDAOBuilder().build(pageInfo); if (pageInformation != null) { String title = pageInformation.getTitle(); String categoryId = pageInformation.getCategory().getCategoryId(); String subCategoryId = pageInformation.getSubCategory().getSubCategoryId(); ResultEvent result = getPageExist(title, categoryId); if (result.getResponseCode().equals(PropertyProvider.get("USER_ALLOW_TO_CREATE_PAGE"))) { mongoCollection.insertOne(pageInformation); this.getResultEvent().setResponseCode(PropertyProvider.get("SUCCESSFUL_OPERATION")); } else { this.getResultEvent().setResponseCode(result.getResponseCode()); } } else { this.getResultEvent().setResponseCode(PropertyProvider.get("NULL_POINTER_EXCEPTION")); } } catch (Exception ex) { this.getResultEvent().setResponseCode(PropertyProvider.get("ERROR_EXCEPTION")); } return this.resultEvent; }
From source file:com.shampan.model.PageModel.java
public ResultEvent addPageMember(String pageId, String memberInfo) { try {//from w w w . j av a2 s. c o m MongoCollection<PageMemberDAO> mongoCollection = DBConnection.getInstance().getConnection() .getCollection(Collections.PAGEMEMBERS.toString(), PageMemberDAO.class); Document selectDocument = new Document(); selectDocument.put("pageId", pageId); MemberInfo mInfo = MemberInfo.getMemberInfo(memberInfo); if (mInfo != null) { PageMemberDAO pageInfo = mongoCollection.find(selectDocument).first(); boolean userIsExist = false; if (pageInfo != null) { List<MemberInfo> memberList = pageInfo.getMemberList(); List<MemberInfo> tempMemberList = new ArrayList<>(); if (memberList.size() > 0) { for (int i = 0; i < memberList.size(); i++) { MemberInfo tempMemberInfo = memberList.get(i); if (tempMemberInfo.getUserId().equals(mInfo.getUserId())) { tempMemberInfo .setRelationTypeId(PropertyProvider.get("PAGE_MEMBER_STATUS_ID_LIKED")); userIsExist = true; } tempMemberList.add(tempMemberInfo); } } if (userIsExist != false) { mongoCollection.findOneAndUpdate(selectDocument, new Document("$set", new Document("memberList", JSON.parse(tempMemberList.toString())))); } else { mongoCollection.findOneAndUpdate(selectDocument, new Document("$push", new Document("memberList", JSON.parse(mInfo.toString())))); } } else { List<MemberInfo> mList = new ArrayList<MemberInfo>(); mList.add(mInfo); PageMemberDAO pageMember = new PageMemberDAO(); pageMember.setPageId(pageId); pageMember.setMemberList(mList); mongoCollection.insertOne(pageMember); } this.getResultEvent().setResponseCode(PropertyProvider.get("SUCCESSFUL_OPERATION")); } else { this.getResultEvent().setResponseCode(PropertyProvider.get("NULL_POINTER_EXCEPTION")); } } catch (Exception ex) { this.getResultEvent().setResponseCode(PropertyProvider.get("ERROR_EXCEPTION")); } return this.resultEvent; }
From source file:com.shampan.model.PageModel.java
public ResultEvent createAlbum(String albumInfo) { try {//www .java2 s.c o m MongoCollection<PageAlbumDAO> mongoCollection = DBConnection.getInstance().getConnection() .getCollection(Collections.PAGEALBUMS.toString(), PageAlbumDAO.class); PageAlbumDAO albumInfoObj = new PageAlbumDAOBuilder().build(albumInfo); if (albumInfoObj != null) { mongoCollection.insertOne(albumInfoObj); this.getResultEvent().setResponseCode(PropertyProvider.get("SUCCESSFUL_OPERATION")); } else { this.getResultEvent().setResponseCode(PropertyProvider.get("NULL_POINTER_EXCEPTION")); } } catch (Exception ex) { this.getResultEvent().setResponseCode(PropertyProvider.get("ERROR_EXCEPTION")); } return this.resultEvent; }
From source file:com.shampan.model.SocialNetworkingModel.java
public void addSocialNetworkInfo(String socialNetworkingInfo) { try {/*from w ww. ja va 2s. com*/ MongoCollection<SocialNetworkDAO> mongoCollection = DBConnection.getInstance().getConnection() .getCollection(Collections.USERS.toString(), SocialNetworkDAO.class); SocialNetworkDAO sNetworkInfo = new SocalNetworkingDAOBulider().build(socialNetworkingInfo); if (sNetworkInfo != null) { mongoCollection.insertOne(sNetworkInfo); this.resultEvent.setResponseCode(PropertyProvider.get("SUCCESSFUL_OPERATION")); } else { this.resultEvent.setResponseCode(PropertyProvider.get("NULL_POINTER_EXCEPTION")); } } catch (Exception ex) { this.resultEvent.setResponseCode(PropertyProvider.get("ERROR_EXCEPTION")); } }