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:com.berkgokden.mongodb.MongoMapStore.java

License:Open Source License

public Object load(Object key) {
    DBObject dbo = new BasicDBObject();
    dbo.put("_id", key);
    DBObject obj = coll.findOne(dbo);
    if (obj == null)
        return null;

    try {//from   w w  w .j av  a  2  s .  c om
        Class clazz = Class.forName(obj.get("_class").toString());
        return converter.toObject(clazz, obj);
    } catch (ClassNotFoundException e) {
        logger.log(Level.WARNING, e.getMessage(), e);
    }
    return null;
}

From source file:com.berkgokden.mongodb.MongoMapStore.java

License:Open Source License

public Map loadAll(Collection keys) {
    Map map = new HashMap();
    BasicDBList dbo = new BasicDBList();
    for (Object key : keys) {
        dbo.add(new BasicDBObject("_id", key));
    }/*from   ww  w .j a v a  2 s .com*/
    BasicDBObject dbb = new BasicDBObject("$or", dbo);
    DBCursor cursor = coll.find(dbb);
    while (cursor.hasNext()) {
        try {
            DBObject obj = cursor.next();
            Class clazz = Class.forName(obj.get("_class").toString());
            map.put(obj.get("_id"), converter.toObject(clazz, obj));
        } catch (ClassNotFoundException e) {
            logger.log(Level.WARNING, e.getMessage(), e);
        }
    }
    return map;
}

From source file:com.berkgokden.mongodb.SpringMongoDBConverter.java

License:Open Source License

public Object toObject(Class clazz, DBObject dbObject) {
    if (clazz.equals(ValueWrapper.class))
        return dbObject.get("value");
    return mongoTemplate.getConverter().read(clazz, dbObject);
}

From source file:com.bigdid.model.counters.java

public long getRevenueTotal() {

    List a = new ArrayList<String>();

    // Now the $group operation
    DBObject groupFields = new BasicDBObject("_id", null);
    groupFields.put("revenue", new BasicDBObject("$sum", "$Order_Value"));
    DBObject group = new BasicDBObject("$group", groupFields);

    coll = db.getCollection("item_revenue");

    // run aggregation
    List<DBObject> pipeline = Arrays.asList(group);
    long total = 0l;
    AggregationOutput output = coll.aggregate(pipeline);

    for (DBObject result : output.results()) {
        //System.out.println(result.get("_id"));
        total = Long.valueOf(result.get("revenue").toString());
    }/*from ww  w .j  a va  2  s.  c o m*/
    return total;
}

From source file:com.bigdid.model.Customer_Feedback.java

public int[] getCount() throws UnknownHostException {
    // Now connect to your databases
    String item[] = new String[100];
    int i = 0;/*w w w. j  a v  a  2  s .com*/
    int count[] = new int[4];
    DBCursor obj = coll.find();
    while (obj.hasNext()) {

        DBObject dbObj = obj.next();
        count[i] = (Integer) dbObj.get("Count");
        i++;
    }
    return count;
}

From source file:com.bigdid.model.Feedback_Location.java

public List getCity() throws SQLException, UnknownHostException {

    List a = new ArrayList<String>();

    // Now the $group operation
    DBObject groupFields = new BasicDBObject("_id", "$Location");
    groupFields.put("revenue", new BasicDBObject("$sum", "$Order_Value"));
    DBObject group = new BasicDBObject("$group", groupFields);

    // Finally the $sort operation
    DBObject sort = new BasicDBObject("$sort", new BasicDBObject("revenue", -1));

    DBObject limit = new BasicDBObject("$limit", 10);

    // run aggregation
    List<DBObject> pipeline = Arrays.asList(group, sort, limit);

    AggregationOutput output = coll.aggregate(pipeline);

    for (DBObject result : output.results()) {
        //System.out.println(result.get("_id"));
        a.add(result.get("_id"));
    }/*from w ww. j a va  2  s . co  m*/

    //numCity= l.size();
    return a;

}

From source file:com.bigdid.model.Feedback_Order_Days.java

public LinkedHashMap<String, int[]> getFeedback() {
    DBCursor obj = coll.find();/* www  .  j  a v  a 2s . c o  m*/
    String current_date = "0";
    String prev_date = "0";
    int counter = 0;
    int[] count = new int[4];
    ;
    while (obj.hasNext()) {

        DBObject dbObj = obj.next();
        prev_date = current_date;
        Date d = (Date) dbObj.get("Order_Date");

        current_date = (String) d.toString().substring(4, 10) + " " + (String) d.toString().substring(24);
        //
        //            int prev_excellent = 0;
        //            int prev_good = 0;
        //            int prev_average = 0;
        //            int prev_bad=0;

        if (dbObj.get("Feedback").equals("Excellent")) {
            count[0] = (Integer) dbObj.get("feedback_count");

            data.put(current_date, count);
            counter++;
        }
        if (dbObj.get("Feedback").equals("Good")) {
            count[1] = (Integer) dbObj.get("feedback_count");

            data.put(current_date, count);
            counter++;
        }
        if (dbObj.get("Feedback").equals("Average")) {
            count[2] = (Integer) dbObj.get("feedback_count");

            data.put(current_date, count);
            counter++;
        }
        if (dbObj.get("Feedback").equals("Bad")) {
            count[3] = (Integer) dbObj.get("feedback_count");

            data.put(current_date, count);
            counter++;
        }

        if (counter % 4 == 0) {
            //    System.out.println(current_date);
            //    System.out.println(count[0]);
            //    System.out.println(count[1]);
            //    System.out.println(count[2]);
            //    System.out.println(count[3]);
            data.put(current_date, count);
            count = new int[4];
        }

    }

    return data;
}

From source file:com.bigdid.model.Feedback_Order_Months.java

public LinkedHashMap<String, int[]> getFeedback() {
    DBCursor obj = coll.find();/*from w w w .  j a va 2 s.  c  o m*/
    String current_date = "0";
    String prev_date = "0";
    int counter = 0;
    int[] count = new int[4];
    ;
    while (obj.hasNext()) {

        DBObject dbObj = obj.next();
        //            prev_date = current_date;
        //            Date d = (Date) dbObj.get("Order_Date");

        current_date = (String) dbObj.get("month");
        //
        //            int prev_excellent = 0;
        //            int prev_good = 0;
        //            int prev_average = 0;
        //            int prev_bad=0;

        if (dbObj.get("Feedback").equals("Excellent")) {
            count[0] = (Integer) dbObj.get("f_count");

            data.put(current_date, count);
            counter++;
        }
        if (dbObj.get("Feedback").equals("Good")) {
            count[1] = (Integer) dbObj.get("f_count");

            data.put(current_date, count);
            counter++;
        }
        if (dbObj.get("Feedback").equals("Average")) {
            count[2] = (Integer) dbObj.get("f_count");

            data.put(current_date, count);
            counter++;
        }
        if (dbObj.get("Feedback").equals("Bad")) {
            count[3] = (Integer) dbObj.get("f_count");

            data.put(current_date, count);
            counter++;
        }

        if (counter % 4 == 0) {
            //    System.out.println(current_date);
            //    System.out.println(count[0]);
            //    System.out.println(count[1]);
            //    System.out.println(count[2]);
            //    System.out.println(count[3]);
            data.put(current_date, count);

            count = new int[4];
        }

    }

    return data;
}

From source file:com.bigdid.model.Feedback_Order_Weeks.java

public LinkedHashMap<String, int[]> getFeedback() {
    DBCursor obj = coll.find();/*from   ww w .  j  av a  2  s  .  c o  m*/
    String current_date = "0";
    String prev_date = "0";
    int counter = 0;
    int[] count = new int[4];
    ;
    while (obj.hasNext()) {

        DBObject dbObj = obj.next();
        //            prev_date = current_date;
        //            Date d = (Date) dbObj.get("Order_Date");

        current_date = (String) dbObj.get("week");
        //
        //            int prev_excellent = 0;
        //            int prev_good = 0;
        //            int prev_average = 0;
        //            int prev_bad=0;

        if (dbObj.get("Feedback").equals("Excellent")) {
            count[0] = (Integer) dbObj.get("f_count");

            data.put(current_date, count);
            counter++;
        }
        if (dbObj.get("Feedback").equals("Good")) {
            count[1] = (Integer) dbObj.get("f_count");

            data.put(current_date, count);
            counter++;
        }
        if (dbObj.get("Feedback").equals("Average")) {
            count[2] = (Integer) dbObj.get("f_count");

            data.put(current_date, count);
            counter++;
        }
        if (dbObj.get("Feedback").equals("Bad")) {
            count[3] = (Integer) dbObj.get("f_count");

            data.put(current_date, count);
            counter++;
        }

        if (counter % 4 == 0) {
            //    System.out.println(current_date);
            //    System.out.println(count[0]);
            //    System.out.println(count[1]);
            //    System.out.println(count[2]);
            //    System.out.println(count[3]);
            data.put(current_date, count);
            count = new int[4];
        }

    }

    return data;
}

From source file:com.bigdid.model.Revenue_Location.java

public Map<String, Integer> getLocationRevenue() throws UnknownHostException {
    HashMap<String, Integer> locationRevenue = new HashMap<String, Integer>();

    int i = 0;/*from   ww w .  j a v a 2s . com*/
    BasicDBObject whereQuery = new BasicDBObject("Order_Value", -1);

    DBCursor obj = coll.find().sort(whereQuery).limit(10);

    while (obj.hasNext()) {
        DBObject dbObj = obj.next();

        locationRevenue.put((String) dbObj.get("Location"), (Integer) dbObj.get("Order_Value"));

    }
    Map<String, Integer> map = sortByValues(locationRevenue);

    return map;
}