Package com.fourspaces.couchdb

Examples of com.fourspaces.couchdb.Document


    assertEquals(1, adhoc);
  }

  @Test
  public void addNamed() throws Exception {
    Document d = new Document();
    d.put("foo", "bar");

    log.debug("Saving d");
    foo.saveDocument(d);

    Document d2 = new Document();
    //d2.put("foo","baz");
    //  d2.addView("all_documents", "function (doc){ return doc; }");
    d2.addView("viewfoobar", "testview", "function (doc){ if (doc.foo=='bar'){ emit(null, doc); }}");
    log.debug("Saving d2 - " + d2.getId() + " - " + d2.toString());
    foo.saveDocument(d2);
    log.debug("Saved d2  - " + d2.getId() + " - " + d2.toString());
    System.err.println("Saved d2  - " + d2.getId() + " - " + d2.toString());
    Document d2_2 = foo.getDocument(d2.getId());
    log.debug("Saved d2_2 - " + d2_2.toString());

    assertNotNull(d2_2.getView("testview"));
    assertEquals(2, foo.view(d2.getView("testview")).getResults().size());

    foo.deleteDocument(d);
    foo.deleteDocument(d2);
View Full Code Here


  Session sess = TestSession.getTestSession();
  Database foo;
 
  @Before public void createTestDB() throws Exception {
    foo=sess.createDatabase("foo");
    foo.saveDocument(new Document(),"foo");
    foo.saveDocument(new Document());
    foo.saveDocument(new Document());
    foo.saveDocument(new Document());
    foo.saveDocument(new Document());

  }
View Full Code Here

    JSONObject obj = new JSONObject();
    obj.put("foo","bar");
    obj.accumulate("array", "ar1");
    obj.accumulate("array", "ar2");
    obj.accumulate("array", "ar3");
    Document doc = new Document(obj);
    foo.saveDocument(doc,"foodoc");

    Document foodoc = foo.getDocumentWithRevisions("foodoc");

    System.out.println(foodoc.getRev());
    String oldId = foodoc.getId();
    String oldRev = foodoc.getRev();
    assertEquals(foodoc.getRevisions().length,1);

    foodoc.put("now", new Date());
    foo.saveDocument(foodoc);
    //System.out.println(foodoc.getRev());
    assertEquals(oldId,foodoc.getId());
    assertFalse(oldRev.equals(foodoc.getRev()));

    foodoc = foo.getDocumentWithRevisions("foodoc");
    //System.out.println(Arrays.toString(foodoc.getRevisions()));
    assertEquals(foodoc.getRevisions().length,2);
   
  }
View Full Code Here

    JSONObject obj = new JSONObject();
    obj.put("foo","bar");
    obj.accumulate("array", "ar1");
    obj.accumulate("array", "ar2");
    obj.accumulate("array", "ar3");
    Document doc = new Document(obj);
    foo.saveDocument(doc,"foodoc");
   
    assertNotNull(doc.getId());
    assertNotNull(doc.getRev());
   
    Document foodoc = foo.getDocument("foodoc");
    assertEquals(foodoc.get("foo"),"bar");
   
    foo.deleteDocument(foodoc);
    foodoc = foo.getDocument("foodoc");
    assertNull(foodoc);
   
View Full Code Here

  }
 
  @Test public void bulkSave() throws Exception {
   
    Document[] docs = new Document[3];
    docs[0] = new Document();
    docs[1] = new Document();
    docs[2] = new Document();
   
    docs[0].accumulate("foo", "bar1" + System.currentTimeMillis());
    docs[1].accumulate("foo", "bar2" + System.currentTimeMillis());
    docs[2].accumulate("foo", "bar3" + System.currentTimeMillis());
   
View Full Code Here

  public void createTestDB()
      throws Exception {
    foo = sess.createDatabase("update_test");
   
    // Create test design document
    Document design = new Document();
   
    design.put("_id", "_design/junit");
   
    JSONObject funcs = new JSONObject();  
    funcs.put("put", JSONUtils.stringSerializedFunction("function(doc,req){doc.Field1=req.query.field1; return [doc, '{\\\"ok\\\":\\\"true\\\"}'];}"));
    funcs.put("post", JSONUtils.stringSerializedFunction("function(doc,req){doc.Field2=req.form.field2; return [doc, '{\\\"ok\\\":\\\"true\\\"}'];}"));
   
    design.accumulate("updates", funcs);
   
    // System.err.println("UDFUNCS: " + design.toString());
   
    foo.saveDocument(design);
   
    // Create a document containing test data to process
    Document testDoc = new Document();
   
    testDoc.put("_id", "test_data");
    testDoc.put("Field1", "Default");
    testDoc.put("Field2", "Default");
   
    foo.saveDocument(testDoc);
  }
View Full Code Here

       
    boolean result = foo.updateDocument(putUpdate);
    assertTrue(result);
   
    // Retrieve the field and make sure the value is correct
    Document testDoc = foo.getDocument("test_data");
    assertNotNull(testDoc);
    assertEquals("UpdatedByPUT", testDoc.getString("Field1"));
  }
View Full Code Here

       
    boolean result = foo.updateDocument(postUpdate);
    assertTrue(result);
   
    // Retrieve the field and make sure the value is correct
    Document testDoc = foo.getDocument("test_data");
    assertNotNull(testDoc);
    assertEquals("UpdatedByPOST", testDoc.getString("Field2"));
  }
View Full Code Here

TOP

Related Classes of com.fourspaces.couchdb.Document

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.