Exemplo n.º 1
0
  public static void put(String id, String msg) {

    try {
      DBCollection message = Database.gardensharing().getCollection("message");

      BasicDBObject document = new BasicDBObject();
      document.put("id", id);
      document.put("msg", msg);
      message.insert(document);
    } catch (MongoException e) {
      e.printStackTrace();
    }

    // messages.put(id, msg);
  }
Exemplo n.º 2
0
  public static String get(String id) {
    // Since 2.10.0, uses MongoClient
    try {
      DBCollection message = Database.gardensharing().getCollection("message");

      BasicDBObject searchQuery = new BasicDBObject();
      searchQuery.put("id", id);

      DBCursor cursor = message.find(searchQuery);

      if (cursor.hasNext()) {
        DBObject object = cursor.next();

        return object.toString();
      } else {
        return null;
      }
    } catch (MongoException e) {
      e.printStackTrace();
    }
    return null;
  }