Example usage for com.mongodb DBObject get

List of usage examples for com.mongodb DBObject get

Introduction

In this page you can find the example usage for com.mongodb DBObject get.

Prototype

Object get(String key);

Source Link

Document

Gets a field from this object by a given name.

Usage

From source file:achmad.rifai.erp1.entity.Penjualan.java

public static Penjualan of(Db d, String nota) throws Exception {
    Penjualan v = null;/*from ww w . ja v a  2 s. c o  m*/
    achmad.rifai.erp1.util.RSA r = achmad.rifai.erp1.util.Work.loadRSA();
    com.mongodb.DBObject p = new com.mongodb.BasicDBObject();
    p.put("berkas", nota);
    com.mongodb.DBCursor c = d.getD().getCollectionFromString("penjualan").find(p);
    while (c.hasNext()) {
        com.mongodb.DBObject o = c.next();
        com.mongodb.BasicDBList l = (com.mongodb.BasicDBList) o.get("bin");
        String json = "";
        for (int x = 0; x < l.size(); x++)
            json += r.decrypt("" + l.get(x));
        v = new Penjualan(json);
        break;
    }
    return v;
}

From source file:achmad.rifai.erp1.entity.Pesan.java

public static Pesan of(Db d, String kode) throws Exception {
    Pesan v = null;//from   w w w . j  av a 2s  .  c  o  m
    achmad.rifai.erp1.util.RSA r = achmad.rifai.erp1.util.Work.loadRSA();
    com.mongodb.DBObject p = new com.mongodb.BasicDBObject();
    p.put("berkas", kode);
    com.mongodb.DBCursor c = d.getD().getCollectionFromString("pesan").find(p);
    while (c.hasNext()) {
        com.mongodb.DBObject o = c.next();
        com.mongodb.BasicDBList l = (com.mongodb.BasicDBList) o.get("bin");
        String json = "";
        for (int x = 0; x < l.size(); x++)
            json += r.decrypt("" + l.get(x));
        v = new Pesan(json);
        break;
    }
    return v;
}

From source file:achmad.rifai.erp1.entity.Rekening.java

public static Rekening of(Db d, String kode) throws Exception {
    Rekening v = null;//from   w w w. j a  v a2 s .c o m
    achmad.rifai.erp1.util.RSA r = achmad.rifai.erp1.util.Work.loadRSA();
    com.mongodb.DBObject p = new com.mongodb.BasicDBObject();
    p.put("berkas", kode);
    com.mongodb.DBCursor c = d.getD().getCollectionFromString("rekening").find(p);
    while (c.hasNext()) {
        com.mongodb.DBObject o = c.next();
        com.mongodb.BasicDBList l = (com.mongodb.BasicDBList) o.get("bin");
        String json = "";
        for (int x = 0; x < l.size(); x++)
            json += r.decrypt("" + l.get(x));
        v = new Rekening(json);
        break;
    }
    return v;
}

From source file:achmad.rifai.erp1.entity.Suplier.java

public static Suplier of(Db d, String kode) throws Exception {
    Suplier v = null;/*from   w w w.  j  av  a2  s .c  o m*/
    achmad.rifai.erp1.util.RSA r = achmad.rifai.erp1.util.Work.loadRSA();
    com.mongodb.DBObject p = new com.mongodb.BasicDBObject();
    p.put("berkas", kode);
    com.mongodb.DBCursor c = d.getD().getCollectionFromString("suplier").find(p);
    while (c.hasNext()) {
        com.mongodb.DBObject o = c.next();
        com.mongodb.BasicDBList l = (com.mongodb.BasicDBList) o.get("bin");
        String json = "";
        for (int x = 0; x < l.size(); x++)
            json += r.decrypt("" + l.get(x));
        v = new Suplier(json);
        break;
    }
    return v;
}

From source file:achmad.rifai.erp1.entity.Tracks.java

public static Tracks of(Db d, String kode) throws Exception {
    Tracks v = null;//  www . ja v a2  s .co  m
    achmad.rifai.erp1.util.RSA r = achmad.rifai.erp1.util.Work.loadRSA();
    com.mongodb.DBObject p = new com.mongodb.BasicDBObject();
    p.put("berkas", kode);
    com.mongodb.DBCursor c = d.getD().getCollectionFromString("tracks").find(p);
    while (c.hasNext()) {
        com.mongodb.DBObject o = c.next();
        com.mongodb.BasicDBList l = (com.mongodb.BasicDBList) o.get("bin");
        String json = "";
        for (int x = 0; x < l.size(); x++)
            json += r.decrypt("" + l.get(x));
        v = new Tracks(json);
        break;
    }
    return v;
}

From source file:achmad.rifai.erp1.entity.Tugas.java

public static Tugas of(Db d, String kode) throws Exception {
    Tugas t = null;/*from   w w w .  ja va 2 s . co m*/
    achmad.rifai.erp1.util.RSA r = achmad.rifai.erp1.util.Work.loadRSA();
    com.mongodb.DBObject p = new com.mongodb.BasicDBObject();
    p.put("berkas", kode);
    com.mongodb.DBCursor c = d.getD().getCollection("tugas").find(p);
    while (c.hasNext()) {
        com.mongodb.DBObject o = c.next();
        com.mongodb.BasicDBList l = (com.mongodb.BasicDBList) o.get("bin");
        String json = "";
        for (int x = 0; x < l.size(); x++)
            json += r.decrypt("" + l.get(x));
        t = new Tugas(json);
        break;
    }
    return t;
}

From source file:act.server.MongoDB.java

License:Open Source License

public static P<P<List, List>, Map<Object, Object>> compare(String coll, String id_key, int thisport,
        int refport, boolean listsAreSet) throws UnknownHostException {
    String host = "localhost";
    String dbs = "actv01";

    List<Object> add = new ArrayList<Object>();
    List<Object> del = new ArrayList<Object>();
    Set<Object> seen = new HashSet<Object>();
    Map<Object, Object> upd = new HashMap<Object, Object>();

    DBCollection c = new Mongo(host, thisport).getDB(dbs).getCollection(coll);
    DBCollection cref = new Mongo(host, refport).getDB(dbs).getCollection(coll);

    // yes, we indeed need to iterate over the entire collection! so unrestricted find() ok here.
    DBCursor cur = c.find();/*www.j ava 2s  . c om*/
    while (cur.hasNext()) {
        DBObject doc = cur.next();
        Object id = doc.get(id_key);

        DBObject docref = findOneDoc(cref, id_key, id);
        if (docref == null) {
            // reference collection does not have doc, log as newly created
            add.add(id);
        } else {
            // reference collection has doc:
            // compare the differences between these two docs and log it as updated if they differ

            Object diff = compare(doc, docref, listsAreSet);
            if (diff != null) {
                // the docs differ. Log it as updated, and note the diff
                upd.put(id, diff);
            }
        }
        seen.add(id);
    }

    // now iterate over ref db and see if there are any docs deleted (i.e., not in notDeleted)
    DBCursor curref = c.find();
    while (curref.hasNext()) {
        DBObject doc = curref.next();
        Object id = doc.get(id_key);

        if (!seen.contains(id)) {
            // this doc was not seen in the updated collection, so deleted. log that
            del.add(id);
        }
    }

    return new P<P<List, List>, Map<Object, Object>>(new P<List, List>(add, del), upd);
}

From source file:act.server.MongoDB.java

License:Open Source License

private static DBObject compare(DBObject doc, DBObject docref, boolean listsAreSet) {
    boolean different = false;

    BasicDBObject diff = new BasicDBObject();
    Set<String> refKeys = new HashSet<String>();
    refKeys.addAll(docref.keySet());//from  ww  w . java 2 s .c o m
    for (String k : doc.keySet()) {
        // as numerical calculations are improved, some computed fields are
        // bound to change: e.g., rarity and estimateEnergy
        // so make a special exception for those and ignore its val field...
        // but compare any other key recursively for differences...
        if (k.equals("rarity") || k.equals("estimateEnergy") || k.equals("coefficient"))
            continue;

        Object val = doc.get(k);

        if (!docref.containsKey(k)) {
            // this field is new
            diff.put("+" + k, val);
            different = true;
        } else {
            // field exists in old doc, recursively compare
            Object refval = docref.get(k);
            refKeys.remove(k);

            Object d;
            if ((d = compare(val, refval, listsAreSet)) != null) {
                // keys identical but values differ, add without the + or - to key
                different = true;
                diff.put(k, d);
            } else {
                // values identical and keys same too, do not put in diff.
            }
        }
    }

    // all remaining fields were deleted from old doc
    for (String kref : refKeys) {
        if (kref.equals("rarity") || kref.equals("estimateEnergy") || kref.equals("coefficient")) // see why in loop above
            continue;

        diff.put("-" + kref, docref.get(kref));
        different = true;
    }

    return different ? diff : null;

    // the following is not order invariant and therefore problematic:
    // return org.apache.commons.lang.StringUtils.difference(doc.toString(), docref.toString());
}

From source file:act.server.MongoDB.java

License:Open Source License

public void updateStoichiometry(Reaction r) {
    BasicDBObject query = new BasicDBObject().append("_id", r.getUUID());
    DBObject obj = this.dbReactions.findOne(query);
    DBObject enz_summary = (DBObject) obj.get("enz_summary");
    BasicDBList substrates = (BasicDBList) enz_summary.get("substrates");
    BasicDBList newSubstrates = new BasicDBList();
    Set<Long> originalSubstrateIDs = new HashSet<Long>();
    for (int i = 0; i < substrates.size(); i++) {
        DBObject substrate = (DBObject) substrates.get(i);
        Long substrateID = (Long) substrate.get("pubchem");
        Boolean isForBalance = (Boolean) substrate.get("balance");
        if (isForBalance != null && isForBalance)
            continue;
        originalSubstrateIDs.add(substrateID);
        substrate.put("coefficient", r.getSubstrateCoefficient(substrateID));
        newSubstrates.add(substrate);/*w w  w  .ja v  a2 s.  com*/
    }
    Set<Long> substratesNew = r.getSubstrateIdsOfSubstrateCoefficients();
    for (Long s : substratesNew) {
        if (originalSubstrateIDs.contains(s))
            continue;
        if (r.getSubstrateCoefficient(s) == null)
            continue;
        DBObject substrate = new BasicDBObject();
        substrate.put("pubchem", s);
        substrate.put("coefficient", r.getSubstrateCoefficient(s));
        substrate.put("balance", true);
        newSubstrates.add(substrate);
    }

    BasicDBList products = (BasicDBList) enz_summary.get("products");
    BasicDBList newProducts = new BasicDBList();
    Set<Long> originalProductIDs = new HashSet<Long>();
    for (int i = 0; i < products.size(); i++) {
        DBObject product = (DBObject) products.get(i);
        Long productID = (Long) product.get("pubchem");
        Boolean isForBalance = (Boolean) product.get("balance");
        if (isForBalance != null && isForBalance)
            continue;
        originalProductIDs.add(productID);
        product.put("coefficient", r.getProductCoefficient(productID));
        newProducts.add(product);
    }
    Set<Long> productsNew = r.getProductIdsOfProductCoefficients();
    for (Long p : productsNew) {
        if (originalProductIDs.contains(p))
            continue;
        if (r.getProductCoefficient(p) == null)
            continue;
        DBObject product = new BasicDBObject();
        product.put("pubchem", p);
        product.put("coefficient", r.getProductCoefficient(p));
        product.put("balance", true);
        newProducts.add(product);
    }
    enz_summary.put("substrates", newSubstrates);
    enz_summary.put("products", newProducts);
    this.dbReactions.update(query, obj);
}

From source file:act.server.MongoDB.java

License:Open Source License

private long alreadyEntered(Chemical c) {
    BasicDBObject query;/*  w w  w . j av  a  2  s.com*/
    String inchi = c.getInChI();
    long retId = -1;

    if (inchi != null) {
        query = new BasicDBObject();
        query.put("InChI", inchi);
        DBObject o = this.dbChemicals.findOne(query);
        if (o != null)
            retId = (Long) o.get("_id"); // checked: db type IS long
    }
    return retId;
}