public void doGet(HttpServletRequest req, HttpServletResponse res) throws IOException {
    Session s = new Session(getServletContext().getInitParameter("couchdb"), 5984);
    Database db = s.getDatabase("testdb");

    ViewResults results = db.getAllDocuments();
    PrintWriter out = res.getWriter();

    res.setContentType("text/plain");

    // Header
    out.println("index,id");

    @SuppressWarnings("unchecked")
    List<JSONObject> rows = (List<JSONObject>) results.get("rows");
    int i = 0;
    for (JSONObject doc : rows) {
      String line = i + "," + doc.getString("id");
      out.println(line);
      i++;
      if (i % 100 == 0) {
        out.flush();
      }
    }
    out.close();
  }
Esempio n. 2
0
  public static void main(String[] args) throws Exception {
    String hostname = args[0];
    String username = args[1];
    String password = args[2];

    ObjectMapper mapper = new ObjectMapper();

    AnotherObject ao = new AnotherObject();
    ao.setName("Foo");
    ao.getSomeList().add("Item 1");
    ao.getSomeList().add("Item 2");
    ao.getSomeList().add("Item 3");

    ao.getaMap().put("Key 1", "Value 1");
    ao.getaMap().put("Key 2", 34);
    ao.getaMap().put("Key 3", new BigDecimal(1234));
    ao.getaMap().put("Key 4", 100d);

    MyObject mo = new MyObject();
    mo.setName("Bar");
    // mo.setContent(mapper.writeValueAsBytes(ao));
    mo.setContent(mapper.writeValueAsString(ao).getBytes());

    Session s = new Session(hostname, 5984, username, password);

    Database db = s.createDatabaseIfNotExists("mydb");

    Document d = new Document();
    DocumentUtils.serialiseIntoDocument(d, mo);

    db.saveDocument(d);

    s.close();
  }