Examples of VBranch


Examples of de.fhg.igd.mongomvcc.VBranch

    VFactory factory = new MongoDBVFactory();
    VDatabase db = factory.createDatabase();
    db.connect("mongomvcc-five-minutes-tutorial");
   
    // Checkout the "master" branch
    VBranch master = db.checkout(VConstants.MASTER);
   
    // 2. Put something into the index
    VCollection persons = master.getCollection("persons");
    Map<String, Object> elvis = factory.createDocument();
    elvis.put("name", "Elvis");
    elvis.put("age", 3);
    persons.insert(elvis);
   
    // insert another person
    persons.insert(factory.createDocument("name", "Peter"));
   
    // 3. Commit index to the database
    long firstCid = master.commit();
   
    // 4. Read documents from the database
    VCursor c = persons.find();
    for (Map<String, Object> person : c) {
      System.out.print("Person { name: " + person.get("name"));
      if (person.containsKey("age")) {
         System.out.print(", age: " + person.get("age"));
      }
      System.out.println(" }");
    }
   
    Map<String, Object> elvis2 = persons.findOne(factory.createDocument("name", "Elvis"));
    if (elvis2 != null) {
      System.out.println("Elvis lives!");
    }
   
    // 5. Make another commit
    persons.insert(factory.createDocument("name", "Max"));
    elvis.put("age", 4);
    persons.insert(elvis);
    master.commit();
   
    // 6. Checkout a previous version
    System.out.println("There are " + persons.find().size() + " persons");
    Map<String, Object> elvis3 = persons.findOne(factory.createDocument("name", "Elvis"));
    System.out.println("Elvis is now " + elvis3.get("age") + " years old");
   
    VBranch oldMaster = db.checkout(firstCid);
    VCollection oldPersons = oldMaster.getCollection("persons");
    System.out.println("Previously, there were only " + oldPersons.find().size() + " persons");
    Map<String, Object> oldElvis = oldPersons.findOne(factory.createDocument("name", "Elvis"));
    System.out.println("Last year, Elvis was " + oldElvis.get("age") + " years old");
   
    // 7. Drop the database
View Full Code Here

Examples of de.fhg.igd.mongomvcc.VBranch

   
    persons = _master.getCollection("persons");
    max2 = persons.findOne(_factory.createDocument("name", "Max"));
    assertEquals(7, max2.get("age"));
   
    VBranch oldMaster = _db.checkout(oldCid);
    persons = oldMaster.getCollection("persons");
    max2 = persons.findOne(_factory.createDocument("name", "Max"));
    assertEquals(6, max2.get("age"));
  }
View Full Code Here

Examples of de.fhg.igd.mongomvcc.VBranch

  @Test
  public void branch() {
    putPerson("Peter", 26);
    long peterCid = _master.commit();
   
    VBranch maxBranch = _db.createBranch("Max", peterCid);
    VCollection maxPersons = maxBranch.getCollection("persons");
    assertEquals(1, maxPersons.find().size());
   
    maxPersons.insert(_factory.createDocument("name", "Max"));
    long maxCid = maxBranch.commit();
   
    maxBranch = _db.checkout("Max");
    assertEquals(maxCid, maxBranch.getHead());
   
    VBranch peterBranch = _db.checkout(VConstants.MASTER);
    assertEquals(peterCid, peterBranch.getHead());
   
    maxPersons = maxBranch.getCollection("persons");
    VCollection peterPersons = peterBranch.getCollection("persons");
    assertEquals(2, maxPersons.find().size());
    assertEquals(1, peterPersons.find().size());
    assertNotNull(maxPersons.findOne(_factory.createDocument("name", "Max")));
    assertNull(peterPersons.findOne(_factory.createDocument("name", "Max")));
   
    putPerson("Elvis", 3);
    long elvisCid = _master.commit();
   
    maxBranch = _db.checkout("Max");
    peterBranch = _db.checkout(VConstants.MASTER);
    assertEquals(maxCid, maxBranch.getHead());
    assertEquals(elvisCid, peterBranch.getHead());
    maxPersons = maxBranch.getCollection("persons");
    peterPersons = peterBranch.getCollection("persons");
    assertEquals(2, maxPersons.find().size());
    assertEquals(2, peterPersons.find().size());
    assertNotNull(maxPersons.findOne(_factory.createDocument("name", "Max")));
    assertNull(peterPersons.findOne(_factory.createDocument("name", "Max")));
    assertNotNull(peterPersons.findOne(_factory.createDocument("name", "Elvis")));
View Full Code Here

Examples of de.fhg.igd.mongomvcc.VBranch

  /**
   * Creates another branch after a conflict has happened
   */
  @Test
  public void createBranchAfterConflict() {
    VBranch master2 = _db.checkout(VConstants.MASTER);
    putPerson("Max", 3);

    VCollection persons2 = master2.getCollection("persons");
    persons2.insert(_factory.createDocument("name", "Elvis"));

    long masterCid = _master.commit();
    try {
      master2.commit();
      fail("We expect a VException here since the branch's head " +
          "could not be updated");
    } catch (VException e) {
      //this is what we expect here
    }
   
    //committing master2 failed, but the commit is still there
    long master2Cid = master2.getHead();
    assertTrue(masterCid != master2Cid);
    _db.createBranch("master2", master2Cid);
   
    VBranch master = _db.checkout(VConstants.MASTER);
    assertEquals(masterCid, master.getHead());
    master2 = _db.checkout("master2");
    assertEquals(master2Cid, master2.getHead());
  }
View Full Code Here

Examples of de.fhg.igd.mongomvcc.VBranch

*/
public class MongoDBVMaintenanceTest extends AbstractMongoDBVDatabaseTest {
  private Object[] makeDanglingCommits() throws InterruptedException {
    putPerson("Max", 6);
    long cid1 = _master.commit();
    VBranch master2 = _db.createBranch("master2", cid1);
    putPerson("Elvis", 3);
    long cid2 = _master.commit();
    VBranch master3 = _db.createBranch("master3", cid2);
   
    VCollection persons2 = master2.getCollection("persons");
    persons2.insert(_factory.createDocument("name", "Pax"));
    long cid3 = master2.commit();
   
    VCollection persons3 = master3.getCollection("persons");
    persons3.insert(_factory.createDocument("name", "Peter"));
    long cid4 = master3.commit();
   
    VBranch master1a = _db.checkout(cid2);
    VCollection persons1a = master1a.getCollection("persons");
    persons1a.insert(_factory.createDocument("name", "Tom"));
    long cid5 = master1a.commit();
   
    VBranch master2a = _db.checkout(cid3);
    VCollection persons2a = master2a.getCollection("persons");
    persons2a.insert(_factory.createDocument("name", "Bob"));
    long cid6 = master2a.commit();
   
    VBranch master3a = _db.checkout(cid4);
    VCollection persons3a = master3a.getCollection("persons");
    persons3a.insert(_factory.createDocument("name", "Howard"));
    long cid7 = master3a.commit();
   
    long stime = System.currentTimeMillis();
    Thread.sleep(500);
   
    persons3a.insert(_factory.createDocument("name", "Brenda"));
    long cid8 = master3a.commit();
   
    return new Object[] { new long[] { cid5, cid6, cid7, cid8 }, stime };
  }
View Full Code Here

Examples of de.fhg.igd.mongomvcc.VBranch

    putPerson("Brenda", 40);
    _master.commit();
    Map<String, Object> elvis = putPerson("Elvis", 3);
    r[0] = (Long)elvis.get(MongoDBConstants.ID);
   
    VBranch master2 = _db.createBranch("master2", cid1);
    VCollection persons2 = master2.getCollection("persons");
    persons2.insert(_factory.createDocument("name", "Howard"));
    master2.commit();
    Map<String, Object> fritz = _factory.createDocument("name", "Fritz");
    persons2.insert(fritz);
    r[1] = (Long)fritz.get(MongoDBConstants.ID);
   
    long stime = System.currentTimeMillis();
View Full Code Here

Examples of de.fhg.igd.mongomvcc.VBranch

    putPerson("Pax", 8);
    long firstCID = _master.commit();
    putPerson("Elvis", 3);
    _master.commit();
   
    VBranch oldMaster = _db.checkout(firstCID);
    VCollection persons = oldMaster.getCollection("persons");
    VCursor cursor = persons.find();
    DBCursor dbcursor = extractDBCursor(cursor);
    assertEquals(2, cursor.size());
    assertTrue(hasAttachedFilter(cursor));
    assertEquals(2, dbcursor.size());
View Full Code Here

Examples of de.fhg.igd.mongomvcc.VBranch

    assertArrayEquals(new long[] { root }, h.getChildren(0));
    assertArrayEquals(new long[] { c1 }, h.getChildren(root));
    assertArrayEquals(new long[] { c2 }, h.getChildren(c1));
    assertArrayEquals(new long[0], h.getChildren(c2));
   
    VBranch master2 = _db.createBranch("master2", c1);
    VCollection persons = master2.getCollection("persons");
    persons.insert(_factory.createDocument("name", "Elvis"));
    long c3 = master2.commit();
   
    h = _db.getHistory();
    assertEquals(c1, h.getParent(c2));
    assertEquals(c1, h.getParent(c3));
    assertEquals(root, h.getParent(c1));
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.