Example usage for com.mongodb BasicDBObject append

List of usage examples for com.mongodb BasicDBObject append

Introduction

In this page you can find the example usage for com.mongodb BasicDBObject append.

Prototype

@Override
public BasicDBObject append(final String key, final Object val) 

Source Link

Document

Add a key/value pair to this object

Usage

From source file:gov.llnl.iscr.iris.LDAModel.java

License:Open Source License

/**
 * returns the topics within the given list of topic IDs greater than the given threshold argument
 * @param semcoArgs/*from w w  w.j a  va  2  s  . c  o m*/
 * @param threshold
 * @return
 */
public DBCursor getTopicsGreaterThan(List<Integer> semcoArgs, double threshold) {
    //Building queries for retrieving topic semco values greater than threshold
    BasicDBObject query = new BasicDBObject();
    query.put("topic", new BasicDBObject("$in", semcoArgs));
    query.append("semco", new BasicDBObject("$gt", threshold));
    BasicDBObject query2 = new BasicDBObject();
    query2.put("_id", 0);
    query2.put("words", 0);

    return semco.find(query, query2);
}

From source file:gov.llnl.iscr.iris.LDAModel.java

License:Open Source License

/**
 * returns the topics less than the given threshold argument that are associated with the given document
 * @param doc/*from w w  w .j  ava2 s .co  m*/
 * @param threshold
 * @return
 */
public DBCursor getTopicsLessThan(SolrDocument doc, double threshold) {
    @SuppressWarnings("unchecked")
    List<DBObject> topics = (List<DBObject>) this.getTopics(doc).get("topics");

    List<Integer> semcoArgs = new ArrayList<Integer>();
    for (DBObject topic : topics) {
        semcoArgs.add((Integer) topic.get("topic"));
    }

    //Building queries for retrieving topic semco values less than threshold
    BasicDBObject query = new BasicDBObject();
    query.put("topic", new BasicDBObject("$in", semcoArgs));
    query.append("semco", new BasicDBObject("$lt", threshold));
    BasicDBObject query2 = new BasicDBObject();
    query2.put("_id", 0);
    query2.put("words", 0);

    return semco.find(query, query2);
}

From source file:gov.llnl.iscr.iris.LDAModel.java

License:Open Source License

/**
 * returns the topics greater than the given threshold argument that are associated with the given document
 * @param doc//from  w  ww .j  ava  2 s  . c  o  m
 * @param threshold
 * @return
 */
public DBCursor getTopicsGreaterThan(SolrDocument doc, double threshold) {
    @SuppressWarnings("unchecked")
    List<DBObject> topics = (List<DBObject>) this.getTopics(doc).get("topics");

    List<Integer> semcoArgs = new ArrayList<Integer>();
    for (DBObject topic : topics) {
        semcoArgs.add((Integer) topic.get("topic"));
    }

    //Building queries for retrieving topic semco values less than threshold
    BasicDBObject query = new BasicDBObject();
    query.put("topic", new BasicDBObject("$in", semcoArgs));
    query.append("semco", new BasicDBObject("$gt", threshold));
    BasicDBObject query2 = new BasicDBObject();
    query2.put("_id", 0);
    query2.put("words", 0);

    return semco.find(query, query2);
}

From source file:govt_import_export.aircrafts2.java

private void placeorderActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_placeorderActionPerformed
    try {//from   www  . ja  v  a  2  s. c o  m
        MongoClient mongo = new MongoClient("localhost", 27017);

        DB db0 = mongo.getDB("admindata");
        DBCollection collection0 = db0.getCollection("admin");
        DBCursor c = collection0.find();
        DBObject o;

        while (c.hasNext()) {
            o = c.next();
            if (o.get("rate") != null) {
                db_rate = o.get("rate").toString();
            }
        }

        c = collection0.find();

        while (c.hasNext()) {
            o = c.next();
            if (o.get("balance") != null) {
                db_balance = nf.format(o.get("balance"));

            }
        }

        ratio = ((double) unitsXcost) / Double.parseDouble(db_balance);
        newbalance = Long.parseLong(db_balance) - unitsXcost;
        newrate = Double.parseDouble(db_rate) * pow(Math.E, ratio);
        System.out.println("'newrate'" + newrate);
        //System.out.println(newbalance);
        String q = nf.format(newbalance);
        //System.out.println(q);

        //--------------------setting the updated values in the db----------------------

        BasicDBObject searchupdate = new BasicDBObject();
        searchupdate.append("rate", Double.parseDouble(db_rate)); //finds the document(s) where "date":last_activity

        BasicDBObject update = new BasicDBObject();
        update.append("$set", new BasicDBObject("rate", /*Double.toString(newrate)*/newrate));

        collection0.update(searchupdate, update);

        //-----
        BasicDBObject searchupdate1 = new BasicDBObject();
        searchupdate1.append("balance", Long.parseLong(db_balance));

        BasicDBObject update1 = new BasicDBObject();
        update1.append("$set", new BasicDBObject("balance", Long.parseLong(q)));

        collection0.update(searchupdate1, update1);

        //------------------------------------------------------------------------------

        DB db = mongo.getDB("AIRCRAFTS");
        DBCollection collection = db.getCollection(type);

        //insert
        BasicDBObject document = new BasicDBObject();
        document.append("model", make_model);
        document.append("type", type);
        document.append("cost", zzz);
        document.append("month", java_month);
        document.append("year", java_year);
        document.append("units", Integer.parseInt(units_string));
        document.append("totalcost", totalcost.getText());

        javax.swing.JOptionPane.showMessageDialog(aircrafts2.this, "Waiting for acceptance");

        collection.insert(document);

    }

    catch (UnknownHostException | MongoException e) {
        //e.printStackTrace();
    }
}

From source file:govt_import_export.display_2.java

private void disp(String s) {
    MongoClient mongo = null;//w w  w .  j a va  2 s.c  om
    int x = 0;
    try {
        mongo = new MongoClient("localhost", 27017);
    } catch (UnknownHostException | MongoException e) {
    }
    if (jTable1.getRowCount() > 0) {
        for (int i = jTable1.getRowCount() - 1; i > -1; i--) {
            model.removeRow(i);
        }
    }
    DB db = mongo.getDB("AUTOMOBILEXPO");
    String[] st = new String[10];
    st[0] = "HYUNDAI";
    st[1] = "MARUTISUZUKI";
    st[2] = "NISSAN";
    st[3] = "BAJAJ";
    st[4] = "KTM";
    st[5] = "VOLKSVAGEN";
    String s1, s2, s3;
    s1 = jComboBox1.getSelectedItem().toString();
    s2 = jComboBox2.getSelectedItem().toString();
    s3 = jComboBox3.getSelectedItem().toString();
    BasicDBObject search = new BasicDBObject();
    BasicDBObject result = new BasicDBObject();
    BasicDBObject sp = new BasicDBObject();
    if (s.equals(s1)) {
        int i = Integer.parseInt(s);
        sp.put("Year", i);
        if (jCheckBox2.isSelected() && jCheckBox3.isSelected()) {

            sp.append("country", s2);
            sp.append("manufacturer", s3);
        } else if (jCheckBox2.isSelected()) {
            sp.append("country", s2);
        } else if (jCheckBox3.isSelected()) {
            sp.append("manufacturer", s3);
        }

    } else if (s.equals(s2)) {
        sp.put("country", s2);
        int i = Integer.parseInt(s1);
        if (jCheckBox1.isSelected() && jCheckBox3.isSelected()) {
            sp.append("Year", i);
            //sp.append("country",s2);
            sp.append("manufacturer", s3);
        } else if (jCheckBox1.isSelected()) {
            //sp.append("country",s2);
            sp.append("Year", i);
        } else if (jCheckBox3.isSelected()) {
            sp.append("manufacturer", s3);
        }

    } else if (s.equals(s3)) {
        sp.put("manufacturer", s3);
        int i = Integer.parseInt(s1);
        if (jCheckBox1.isSelected() && jCheckBox2.isSelected()) {
            sp.append("Year", i);
            sp.append("country", s2);
            //sp.append("manufacturer",s3);
        } else if (jCheckBox1.isSelected()) {
            //sp.append("country",s2);
            sp.append("Year", i);
        } else if (jCheckBox2.isSelected()) {
            sp.append("country", s2);
        }

    }
    ArrayList<String> arr = new ArrayList();
    for (int j = 0; j <= 5; j++) {
        DBCollection table;

        table = db.getCollection(st[j]);
        if (table.findOne() != null) {
            DBCursor cr = table.find(sp);
            DBObject obj;

            while (cr.hasNext()) {
                obj = cr.next();
                x++;
                //jLabel1.setText(jLabel1.getText()+"Model\n"+(obj.toString())+"\n");
                //jTextArea1.
                //  jTextArea1.setText(jTextArea1.getText()+"Manufacture:   "+(obj.get("manufacturer").toString())+"    Model: "+(obj.get("model").toString())+"   Units : "+(obj.get("Units").toString())+"Cost : "+(obj.get("Cost").toString())+" Continent  : "+(obj.get("country").toString())+"  Year :"+(obj.get("Year").toString())+"\n");        
                model.addRow(new Object[] { obj.get("manufacturer").toString(), (obj.get("model").toString()),
                        (obj.get("Units").toString()), (obj.get("Cost").toString()),
                        (obj.get("country").toString()), (obj.get("Year").toString()) });
            }

        }
    }

    total = x;
    String a = Integer.toString(total);
    jLabel5.setText(a);

}

From source file:govt_import_export.export.java

public export(String item1, String item2) {
    initComponents();/* w ww  .ja  v  a  2 s .  c  om*/
    model_selected = item1;
    manufac = item2;
    MongoClient mongo = null;
    try {
        mongo = new MongoClient("localhost", 27017);
    } catch (UnknownHostException e) {
        e.printStackTrace();
    }

    catch (MongoException e) {
        e.printStackTrace();
    }
    DB db = mongo.getDB("automobile_expo");
    DBCollection table = db.getCollection(manufac);
    BasicDBObject doc = new BasicDBObject();
    BasicDBObject doc1 = new BasicDBObject();

    String s = new String();
    doc.put("model_name", model_selected);
    doc1.append("_id", 0);
    DBCursor c = table.find(doc, doc1);
    //while(c.hasNext())
    {
        DBObject doc2 = c.next();
        //System.out.println(doc2.toString());
        jLabel6.setText("<html>Model " + (doc2.get("model_name").toString()) + "<br> date "
                + (doc2.get("date").toString()) + " <br>EngineType" + (doc2.get("EngineType").toString())
                + "<br>EngineDisplacement" + (doc2.get("EngineDisplacement").toString()) + "<br>Maximum_torque"
                + (doc2.get("Maximum_torque").toString()) + "<br>Noof_cylinders"
                + (doc2.get("Noof_cylinders").toString()) + "<br>Seating_Capacity"
                + (doc2.get("Seating_Capacity").toString()) + "<br>Length" + (doc2.get("Length").toString())
                + "<br>Width" + (doc2.get("Width").toString()) + "<br>Height" + (doc2.get("Height").toString())
                + "<br>Cost" + (doc2.get("Cost").toString()) + "</html>");
        //jTextArea1.setText(s);

    }
    String[] split = s.split(",");

    //jTextArea1.setText(s);
    doc.put("model_name", model_selected);
    BasicDBObject sp = new BasicDBObject();
    sp.put("Cost", 1);
    sp.put("_id", 0);
    DBCursor cursor = table.find(doc, sp);
    while (cursor.hasNext())
        z = cursor.next().toString();
    z = z.substring(z.indexOf("st\" : \"") + 7);
    z = z.substring(0, z.indexOf("INR"));
    String s2;
    //while(cursor.hasNext())

    //BasicDBObject h=(BasicDBObject)cursor.next();
    //s2=h.get("Cost").toString();

    //insert
    cost = Integer.parseInt(z);
    total_cost = 1000 * cost;
    String st;
    st = String.valueOf(total_cost);
    jTextField1.setText(st);
    //jTextField1.setText(z);

}

From source file:govt_import_export.export.java

private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
    // TODO add your handling code here:
    MongoClient mongo = null;/*from  w ww.jav a2s  .com*/
    try {
        mongo = new MongoClient("localhost", 27017);
        //get database
    } catch (UnknownHostException e) {
        e.printStackTrace();
    }

    catch (MongoException e) {
        e.printStackTrace();
    }
    DB db = mongo.getDB("AUTOMOBILEXPO");
    //DB db2=mongo.getDB("automobile_expo");
    String batches = (String) jComboBox1.getSelectedItem();
    int unit, month, year;

    unit = Integer.parseInt(batches);
    //get collections
    DBCollection table = db.getCollection(manufac);
    //DBCollection table1=db2.getCollection(db1);
    BasicDBObject document1 = new BasicDBObject();
    String st = (String) jComboBox2.getSelectedItem();
    String st1 = (String) jComboBox3.getSelectedItem();
    String st2 = (String) jComboBox4.getSelectedItem();
    month = Integer.parseInt(st1);
    year = Integer.parseInt(st2);

    cost = cost * unit;
    //jTextField1.setText(z);
    DB db0 = mongo.getDB("admindata");
    DBCollection collection0 = db0.getCollection("admin");
    DBCursor c = collection0.find(); //yes            
    DBObject o;
    //DBCursor c=collection0.find(); //yes  
    while (c.hasNext()) {
        o = c.next();
        if (o.get("rate") != null) {
            db_rate = o.get("rate").toString();
        }
    }

    c = collection0.find();

    while (c.hasNext()) {
        o = c.next();
        if (o.get("balance") != null) {
            db_balance = nf.format(o.get("balance"));

        }
    }

    ratio = ((double) cost) / Double.parseDouble(db_balance);
    ratio = -ratio * .1;
    newbalance = Long.parseLong(db_balance) - cost;
    newrate = Double.parseDouble(db_rate) * pow(Math.E, ratio);
    System.out.println("'newrate'" + newrate);
    //System.out.println(newbalance);
    String q = nf.format(newbalance);
    //System.out.println(q);

    //--------------------setting the updated values in the db----------------------

    BasicDBObject searchupdate = new BasicDBObject();
    searchupdate.append("rate", Double.parseDouble(db_rate)); //finds the document(s) where "date":last_activity

    BasicDBObject update = new BasicDBObject();
    update.append("$set", new BasicDBObject("rate", /*Double.toString(newrate)*/newrate));

    collection0.update(searchupdate, update);

    //-----
    BasicDBObject searchupdate1 = new BasicDBObject();
    searchupdate1.append("balance", Long.parseLong(db_balance));

    BasicDBObject update1 = new BasicDBObject();
    update1.append("$set", new BasicDBObject("balance", Long.parseLong(q)));

    collection0.update(searchupdate1, update1);

    //DBObject o;
    BasicDBObject document = new BasicDBObject();
    BasicDBObject prev = new BasicDBObject();
    document.append("manufacturer", manufac);
    document.append("model", model_selected);
    document.append("country", st);
    document.append("Units", unit);
    document.append("Cost", cost);

    document.append("Month", month);
    document.append("Year", year);
    table.insert(document);
    //long x=table.count();
    //find and display
    //System.out.println(x);
    GroupCommand cmd = new GroupCommand(table, null, new BasicDBObject("model", model_selected),
            new BasicDBObject("Units", 0), "function(document,prev){prev.Units=prev.Units+this.Units;}", null);
    o = table.group(cmd);
    //System.out.println(o);
    sort_cars();
    javax.swing.JOptionPane.showMessageDialog(export.this, "Waiting for acceptance");
    st = String.valueOf(total_cost);
    jTextField1.setText(st);
    System.out.println("donee");
}

From source file:gr.forth.ics.icardea.pid.PrimKV.java

private void visitAtomic(BasicDBObject o, Object v, String name) {
    if (v == null)
        return;/*from  w w w.  j  av a  2s . c o  m*/
    if (v instanceof PrimKV) {
        PrimKV kv = (PrimKV) v;
        o.append(name, kv.toDBObject());
    } else
        o.append(name, v);
}

From source file:gr.forth.ics.icardea.pid.PrimKV.java

DBObject toDBObject() {
    BasicDBObject o = new BasicDBObject();
    try {//ww w.  j  a  va 2  s. c  o  m
        for (Field f : this.getClass().getDeclaredFields()) {
            Object v = f.get(this);
            if (v == null)
                continue;
            String name = f.getName();
            if (v instanceof List<?>) {
                ArrayList<Object> objs = new ArrayList<Object>();
                for (Object obj : (List<?>) v) {
                    if (obj instanceof PrimKV) {
                        PrimKV t = (PrimKV) obj;
                        objs.add(t.toDBObject());
                    } else
                        objs.add(obj);
                }
                o.append(name, objs);
            } else
                visitAtomic(o, v, name);
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return o;
}

From source file:gr.forth.ics.icardea.pid.PrimKV.java

public DBObject toDBObject() {

    BasicDBObject obj = new BasicDBObject();
    if (this.name != null)
        obj.append("name", this.name.toDBObject());
    if (this.mothers_name != null)
        obj.append("mothers_name", this.mothers_name.toDBObject());
    if (this.addr != null)
        obj.append("addr", this.addr.toDBObject());
    if (this.date_of_birth != null)
        obj.append("date_of_birth", this.date_of_birth);
    if (this.sex != null)
        obj.append("sex", this.sex);
    if (this.tel_home != null)
        obj.append("tel_home", this.tel_home);
    if (this.tel_work != null)
        obj.append("tel_work", this.tel_work);
    if (this.ssn != null)
        obj.append("ssn", this.ssn);
    if (this.drivers_lic != null)
        obj.append("drivers_lic", this.drivers_lic);
    if (this.accnum != null)
        obj.append("accnum", this.accnum);

    List<DBObject> lids = new ArrayList<DBObject>();
    for (ID id : this.ids)
        lids.add(id.toDBObject());//from w ww  .  j  a v  a  2 s  . co m
    obj.append("ids", lids);
    return obj;
}