List of usage examples for com.mongodb BasicDBObject BasicDBObject
public BasicDBObject(final String key, final Object value)
From source file:Highscores.java
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed // TODO add your handling code here: try {/* ww w . jav a 2s . c om*/ String user; int count = 1; String highscore; jTextArea2.append("SR No.\tUSERNAME\tHIGHSCORE\n"); int high; MongoClient mc = new MongoClient("localhost", 27017); DB db = mc.getDB("Classic_Hangman"); System.out.println("Connected to database successfully!!"); DBCollection coll = db.getCollection("high_score"); System.out.println("Collection Retrieved"); DBCursor cursor = coll.find(); cursor.sort(new BasicDBObject("value", -1)); while (cursor.hasNext() && count < 4) { DBObject result = cursor.next(); high = ((Number) result.get("value")).intValue(); highscore = Integer.toString(high); user = (String) result.get("_id"); jTextArea2.append(count + "\t" + user + "\t" + highscore + "\n"); count++; } } catch (UnknownHostException ex) { Logger.getLogger(Highscores.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:Add_cust.java
@Override /* Check The code below for insertion of values */ public void actionPerformed(ActionEvent ae) { // TODO Auto-generated method stub add(jLabel9);// w ww.j a va2 s. c o m String History = jComboBox3.getSelectedItem().toString(); if (ae.getSource() == jButton1) { try { MongoClient mongo = new MongoClient("localhost", 27017); DB db = mongo.getDB("Gym"); DBCollection Gym_Collection = db.getCollection("Customers"); DBCollection Allot = db.getCollection("Batch"); //Declaration of collection for Batch DBCursor cursor = Allot.find(); float Slots, Morning, Evening, Night; cursor.next(); Slots = Float.parseFloat(cursor.curr().get("Slots").toString()); Morning = Float.parseFloat(cursor.curr().get("Morning").toString()); Evening = Float.parseFloat(cursor.curr().get("Evening").toString()); Night = Float.parseFloat(cursor.curr().get("Night").toString()); String first_name = jTextField1.getText(); String last_name = jTextField2.getText(); float weight = Float.parseFloat(jTextField6.getText().toString()); float height = Float.parseFloat(jTextField5.getText().toString()); String address = jTextArea1.getText(); int age = Integer.parseInt(jComboBox1.getSelectedItem().toString()); String Subs = jComboBox2.getSelectedItem().toString(); String Batches = jComboBox5.getSelectedItem().toString(); String phone_number = jTextField3.getText().toString(); if (!isAlpha(first_name) || !isAlpha(last_name)) { JOptionPane.showMessageDialog(this, "Enter a valid name"); jTextField1.setText(""); jTextField2.setText(""); } else if (weight > 150 || weight < 40) { JOptionPane.showMessageDialog(this, "Please add weight between 40 and 150"); jTextField6.setText(""); } else if (height > 250 || height < 50) { JOptionPane.showMessageDialog(this, "Please add height between 100 and 250"); jTextField5.setText(""); } else if (phone_number.length() < 8 || phone_number.length() > 11) { JOptionPane.showMessageDialog(this, "Enter a valid Phone no."); jTextField3.setText(""); } else { int random_1, random_2, sub_sum = 0, days = 0; if (Subs.equals("1 Month")) { sub_sum = 1000; days = 30; } else if (Subs.equals("2 Months")) { sub_sum = 1500; days = 60; } else if (Subs.equals("3 Months")) { sub_sum = 2250; days = 90; } else if (Subs.equals("1 YEAR")) { sub_sum = 6000; days = 360; } int flag = 0, flag1 = 0, flag2 = 0, flag3 = 0; if (Batches.equals("Morning")) { Morning += 1; flag1 = 1; } else if (Batches.equals("Evening")) { Evening += 1; flag2 = 1; } else if (Batches.equals("Night")) { Night += 1; flag3 = 1; } if (Morning > Slots || Evening > Slots || Night > Slots) { if (flag1 == 1) { Morning -= 1; } else if (flag2 == 1) { Evening -= 1; } else if (flag3 == 1) { Night -= 1; } flag = 1; } if (flag == 1) { float temp1, temp2; if (flag1 == 1) { temp1 = Slots - Evening; temp2 = Slots - Night; JOptionPane.showMessageDialog(this, "This time slot slot is full. Evening has " + temp1 + " Slots. Night has " + temp2 + " Slots."); } else if (flag2 == 1) { temp1 = Slots - Morning; temp2 = Slots - Night; JOptionPane.showMessageDialog(this, "This time slot slot is full. Morning has " + temp1 + " Slots. Night has " + temp2 + " Slots."); } else { temp1 = Slots - Morning; temp2 = Slots - Evening; JOptionPane.showMessageDialog(this, "This time slot slot is full. Morning has " + temp1 + " Slots. Evening has " + temp2 + " Slots."); } } else { do { random_1 = (int) Math.floor(Math.random() * 360); random_2 = (int) Math.floor(Math.random() * 360); } while (random_1 >= random_2 || days <= random_2); BasicDBObject doc = new BasicDBObject("First_Name", first_name.toLowerCase()) .append("Last_Name", last_name.toLowerCase()).append("Phone_Number", phone_number) .append("Age", age).append("Height", height).append("History", History) .append("Subscribe", days).append("Batch", Batches).append("Weight", weight) .append("Attended", random_1).append("Total", random_2).append("Fees", sub_sum) .append("Address", address); Gym_Collection.insert(doc); jTextField1.setText(""); jTextField2.setText(""); jTextField3.setText(""); jTextField5.setText(""); jTextField6.setText(""); jTextArea1.setText(""); BasicDBObject newDocument = new BasicDBObject(); newDocument.append("$set", new BasicDBObject().append("Morning", Morning) .append("Evening", Evening).append("Night", Night)); BasicDBObject searchQuery = new BasicDBObject().append("Slots", Slots); Allot.update(searchQuery, newDocument); this.setVisible(false); new work(History, first_name.toLowerCase(), last_name.toLowerCase()); this.setVisible(false); new work().setVisible(true); } } } catch (UnknownHostException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (NumberFormatException e) {// To validate for data types JOptionPane.showMessageDialog(this, "Please Check the Data types"); jTextField1.setText(""); jTextField2.setText(""); jTextField3.setText(""); jTextField5.setText(""); jTextField6.setText(""); jTextArea1.setText(""); } } else if (ae.getSource() == jButton2) { this.setVisible(false); new Receptionist().setVisible(true); } }
From source file:Add_train.java
@Override /* Check The code below for insertion of values */ public void actionPerformed(ActionEvent ae) { // TODO Auto-generated method stub add(jLabel9);//from ww w. j a v a 2s .c o m jLabel9.setText(""); if (ae.getSource() == jButton1) { try { MongoClient mongo = new MongoClient("localhost", 27017); DB db = mongo.getDB("Gym"); DBCollection Allot = db.getCollection("Batch_Trainer"); DBCursor cursor1 = Allot.find(); DBCollection Gym_Collection = db.getCollection("trainer"); String first_name = jTextField1.getText(); String last_name = jTextField2.getText(); String password = jPassword1.getText().toString(); String dup = jPassword2.getText().toString(); String username = jTextField5.getText().toString(); String address = jTextArea1.getText(); String Batches = jComboBox5.getSelectedItem().toString(); float Slots, Morning, Evening, Night; cursor1.next(); Slots = Float.parseFloat(cursor1.curr().get("Slots").toString()); Morning = Float.parseFloat(cursor1.curr().get("Morning").toString()); Evening = Float.parseFloat(cursor1.curr().get("Evening").toString()); Night = Float.parseFloat(cursor1.curr().get("Night").toString()); int age = Integer.parseInt(jComboBox1.getSelectedItem().toString()); String phone_number = jTextField3.getText().toString(); DBCursor cursor = Gym_Collection.find(); int i = 0; while (cursor.hasNext()) { cursor.next(); if (username.equals(cursor.curr().get("Username").toString())) { i = 1; } } if (i == 1) { JOptionPane.showMessageDialog(this, "Username has been taken !!!"); jTextField5.setText(""); } else if (!isAlpha(first_name) || !isAlpha(last_name)) { JOptionPane.showMessageDialog(this, "Enter a valid name"); jTextField1.setText(""); jTextField2.setText(""); } else if (phone_number.length() < 8 || phone_number.length() > 10) { JOptionPane.showMessageDialog(this, "Enter a valid Phone no."); jTextField3.setText(""); } else if (!password.equals(dup)) { JOptionPane.showMessageDialog(this, "Passwords didn't match"); jPassword1.setText(""); jPassword2.setText(""); } else { int flag = 0, flag1 = 0, flag2 = 0, flag3 = 0; if (Batches.equals("Morning")) { Morning += 1; flag1 = 1; } else if (Batches.equals("Evening")) { Evening += 1; flag2 = 1; } else if (Batches.equals("Night")) { Night += 1; flag3 = 1; } if (Morning > Slots || Evening > Slots || Night > Slots) { if (flag1 == 1) { Morning -= 1; } else if (flag2 == 1) { Evening -= 1; } else if (flag3 == 1) { Night -= 1; } flag = 1; } if (flag == 1) { float temp1, temp2; if (flag1 == 1) { temp1 = Slots - Evening; temp2 = Slots - Night; JOptionPane.showMessageDialog(this, "This time slot slot is full. Evening has " + temp1 + " Slots. Night has " + temp2 + " Slots."); } else if (flag2 == 1) { temp1 = Slots - Morning; temp2 = Slots - Night; JOptionPane.showMessageDialog(this, "This time slot slot is full. Morning has " + temp1 + " Slots. Night has " + temp2 + " Slots."); } else { temp1 = Slots - Morning; temp2 = Slots - Evening; JOptionPane.showMessageDialog(this, "This time slot slot is full. Morning has " + temp1 + " Slots. Evening has " + temp2 + " Slots."); } } else { BasicDBObject doc = new BasicDBObject("First_Name", first_name.toLowerCase()) .append("Last_Name", last_name.toLowerCase()).append("Batch", Batches) .append("Phone_Number", phone_number).append("Age", age) .append("Username", username).append("Password", password) .append("Address", address); Gym_Collection.insert(doc); jTextField1.setText(""); jTextField2.setText(""); jTextField3.setText(""); jTextField5.setText(""); jPassword1.setText(""); jPassword2.setText(""); jTextArea1.setText(""); jLabel9.setFont(new java.awt.Font("SansSerif", 3, 16)); // NOI18N jLabel9.setForeground(new java.awt.Color(204, 255, 204)); jLabel9.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); jLabel9.setText("Successfully Added"); jLabel9.setBounds(200, 10, 200, 40); BasicDBObject newDocument = new BasicDBObject(); newDocument.append("$set", new BasicDBObject().append("Morning", Morning) .append("Evening", Evening).append("Night", Night)); BasicDBObject searchQuery = new BasicDBObject().append("Slots", Slots); Allot.update(searchQuery, newDocument); setVisible(true); } } } catch (UnknownHostException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (NumberFormatException e) { JOptionPane.showMessageDialog(this, "Please Check the Data types"); jTextField1.setText(""); jTextField2.setText(""); jTextField3.setText(""); jTextField5.setText(""); jPassword1.setText(""); jPassword2.setText(""); jTextArea1.setText(""); } } else if (ae.getSource() == jButton2) { this.setVisible(false); new Admin().setVisible(true); } }
From source file:admin_Add_newEmp.java
private void Add_buttonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_Add_buttonActionPerformed // TODO add your handling code here: try {//from w w w . j a va 2 s. com MongoClient mc = new MongoClient("localhost", 27017); DB db = mc.getDB("parking_system"); DBCollection collection = db.getCollection("employee_info"); name = name_field.getText(); lname = lname_field.getText(); mobno = mobno_field.getText().toCharArray(); //userid = userid_field.getText(); //password = password_field.getText(); //mobno = Integer.parseInt(mobno_field.getText()); //mobno = mobno_field.getText(); String mobnoStr = new String(mobno); BasicDBObject doc = new BasicDBObject("_id", userid).append("name", name).append("lname", lname) .append("password", password).append("mobileno", mobnoStr); collection.insert(doc); JOptionPane.showMessageDialog(null, "Added!"); setVisible(false); new Admin_rights().setVisible(true); } catch (Exception e) { } }
From source file:ChangeUserRole.java
protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("application/json"); response.setCharacterEncoding("utf-8"); response.setHeader("Access-Control-Allow-Origin", "*"); try {/* ww w.j ava 2 s . com*/ out = response.getWriter(); String id = request.getParameter("id"); status = request.getParameter("type"); System.out.println("id received : " + id); MongoClient mongoClient = new MongoClient("localhost", 27017); // Now connect to your databases DB db = mongoClient.getDB("XHiring"); System.out.println("Connect to database successfully"); DBCollection coll = db.getCollection("users"); System.out.println("Collection users selected successfully"); //read example try { BasicDBObject query = new BasicDBObject("_id", new ObjectId(id)); BasicDBObject update; if (status != null && status.equalsIgnoreCase(" ")) { update = new BasicDBObject("isAdmin", "true"); } else { update = new BasicDBObject("isAdmin", "false"); } coll.update(query, update); success = new JSONObject(); success.put("message", "document updated"); out.println(success); } catch (NullPointerException ex) { error = new JSONObject(); error.put("message", "No result found"); out.println(error); } System.out.println("Document updated successfully"); } catch (Exception e) { exception = new JSONObject(); try { exception.put("message", "exception"); out.println(exception); } catch (JSONException ex) { Logger.getLogger(ChangeUserRole.class.getName()).log(Level.SEVERE, null, ex); } System.err.println(e.getClass().getName() + ": " + e.getMessage()); e.printStackTrace(); } }
From source file:RegisterUI.java
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed String username = Usernamefield.getText(); char[] pw1 = Passwordfield.getPassword(); String pw1s = new String(pw1); char[] pw2 = Repeat.getPassword(); String pw2s = new String(pw2); if (usernames.contains(username)) { JOptionPane.showMessageDialog(null, "Username already exists!", "Failed", JOptionPane.ERROR_MESSAGE); }/*w w w . java2 s .c om*/ else if (!pw1s.equals(pw2s)) { JOptionPane.showMessageDialog(null, "Passwords do not match!", "Failed", JOptionPane.ERROR_MESSAGE); } else { DBCollection col = db.getCollection("Users"); BasicDBObject doc = new BasicDBObject("Info", new BasicDBObject("Username", username).append("Password", pw1s)) .append("Beginner", new BasicDBObject("Total", 0).append("Correct", 0)) .append("Easy", new BasicDBObject("Total", 0).append("Correct", 0)) .append("Medium", new BasicDBObject("Total", 0).append("Correct", 0)) .append("Hard", new BasicDBObject("Total", 0).append("Correct", 0)).append("Last", new BasicDBObject("Question", "").append("Answer", "").append("Correct", "")); col.insert(doc); JOptionPane.showMessageDialog(null, "Registration Successful!", "Success!", JOptionPane.INFORMATION_MESSAGE); WindowEvent winClosingEvent = new WindowEvent(this, WindowEvent.WINDOW_CLOSING); Toolkit.getDefaultToolkit().getSystemEventQueue().postEvent(winClosingEvent); } }
From source file:act.installer.bing.UsageTermUrlSet.java
License:Open Source License
public BasicDBObject getBasicDBObject() { BasicDBObject usageTermUrlSetBasicDBObject = new BasicDBObject("usage_term", usageTerm); BasicDBList urlsBasicDBList = new BasicDBList(); for (String url : urlSet) { urlsBasicDBList.add(url);//from w ww. j av a 2s . com } usageTermUrlSetBasicDBObject.put("urls", urlsBasicDBList); return usageTermUrlSetBasicDBObject; }
From source file:act.installer.reachablesexplorer.FreemarkerRenderer.java
License:Open Source License
public PathwayDoc generatePathDoc(Reachable target, ReactionPath path, File pathDestination, File sequenceDestination) throws IOException, TemplateException { DBCursor<ReactionPath> cursor = Cascade.get_pathway_collection() .find(new BasicDBObject("target", target.getId())); String sourceDocName = makeSourceDocName(target); if (sourceDocName == null) { LOGGER.error("Target %d does not have inchiKey", path.getTarget()); return null; }//from www . ja v a2s .c o m String pathwayDocName = String.format("Pathway_%s_%d", sourceDocName, path.getRank()); List<DnaDesignTableProperties> designDocsAndSummaries = path.getDnaDesignRef() != null ? renderSequences(sequenceDestination, pathwayDocName, path.getDnaDesignRef()) : Collections.emptyList(); Pair<Object, String> model = buildPathModel(path, designDocsAndSummaries); if (model != null) { pathwayTemplate.process(model.getLeft(), new FileWriter(new File(pathDestination, pathwayDocName))); } return new PathwayDoc(pathwayDocName, model.getRight(), designDocsAndSummaries != null && designDocsAndSummaries.size() > 0); }
From source file:act.installer.reachablesexplorer.Loader.java
License:Open Source License
/** * Constructor for Loader. Instantiates connexions to Mongo databases * and Virtuoso triple store (Pubchem synonyms only) * @param host The host for the target Reachables MongoDB * @param port The port for the target Reachables MongoDB * @param targetDB The database for the target Reachables MongoDB * @param targetCollection The collection for the target Reachables MongoDB * @param targetSequenceCollection The collection for the target SequenceData MongoDB * @param renderingCache A directory where rendered images should live *//*from w w w . jav a2s . c o m*/ public Loader(String host, Integer port, String sourceDB, String targetDB, String targetCollection, String targetSequenceCollection, String renderingCache) { // when the caller does not intend to touch the sourceDB, it can pass null as a param and we // won't setup a "source" connection. Creating a connection with "dummy" params leads mongod // to create (!) those dummy collections, mucking up our database with empty dbs/collections if (sourceDB != null) { sourceDBconn = new MongoDB(host, port, sourceDB); wordCloudGenerator = new WordCloudGenerator(host, port, sourceDB, renderingCache); } pubchemSynonymsDriver = new PubchemMeshSynonyms(); moleculeRenderer = new MoleculeRenderer(new File(renderingCache)); MongoClient mongoClient; try { mongoClient = new MongoClient(new ServerAddress(host, port)); } catch (UnknownHostException e) { LOGGER.error( "Connection to MongoClient failed. Please double check the target database's host and port."); throw new RuntimeException(e); } DB reachables = mongoClient.getDB(targetDB); // TODO: this unsafe initialization does not belong in the constructor. try { calculator = new PhysiochemicalPropertiesCalculator.Factory().build(); } catch (PluginException e) { LOGGER.error("Unable to initialize physiochemical calculator: %s", e.getMessage()); throw new RuntimeException(e); } if (targetCollection != null) { jacksonReachablesCollection = JacksonDBCollection.wrap(reachables.getCollection(targetCollection), Reachable.class, String.class); jacksonReachablesCollection.ensureIndex(new BasicDBObject(Reachable.INCHI_FIELD_NAME, "hashed")); } if (targetSequenceCollection != null) { jacksonSequenceCollection = JacksonDBCollection.wrap(reachables.getCollection(targetSequenceCollection), SequenceData.class, String.class); jacksonSequenceCollection.createIndex(new BasicDBObject(SequenceData.SEQUENCE_FIELD_NAME, "hashed")); jacksonSequenceCollection.createIndex(new BasicDBObject(SequenceData.ORGANISM_FIELD_NAME, 1)); } }
From source file:act.installer.reachablesexplorer.Loader.java
License:Open Source License
private Reachable queryByInchi(String inchi) { DBObject query = new BasicDBObject(Reachable.INCHI_FIELD_NAME, inchi); return jacksonReachablesCollection.findOne(query); }