Package de.fhg.igd.mongomvcc

Examples of de.fhg.igd.mongomvcc.VCursor


   
    // 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"));
      }
View Full Code Here


  @Test
  public void insertIntoIndex() {
    VCollection persons = _master.getCollection("persons");
    assertNotNull(persons);
    Map<String, Object> peter = putPerson("Peter", 26);
    VCursor c = persons.find();
    assertEquals(1, c.size());
    Map<String, Object> peter2 = c.iterator().next();
    assertDocEquals(peter, peter2);
  }
View Full Code Here

    final CountDownLatch latch2 = new CountDownLatch(1);
    final Integer[] tresult = new Integer[2];
    Thread t = new Thread() {
      @Override
      public void run() {
        VCursor pc = _master.getCollection("persons").find();
        tresult[0] = pc.size();
        Map<String, Object> p1 = pc.iterator().next();
        assertEquals("Peter", p1.get("name"));
        latch2.countDown();
        try {
          latch1.await();
        } catch (InterruptedException e) {
          fail();
          throw new RuntimeException(e);
        }
        VCursor pc2 = _master.getCollection("persons").find();
        tresult[1] = pc2.size();
        Map<String, Object> p2 = pc2.iterator().next();
        assertEquals("Peter", p2.get("name"));
      }
    };
   
    putPerson("Peter", 26);
View Full Code Here

    for (int i = 0; i < 20; ++i) {
      putPerson(String.valueOf(i), i);
    }
    _master.commit();
   
    VCursor vc = _master.getCollection("persons").find(_factory.createDocument("name", "10"));
    assertEquals(1, vc.size());
    Map<String, Object> p = vc.iterator().next();
    assertEquals("10", p.get("name"));
    assertEquals(Integer.valueOf(10), p.get("age"));
  }
View Full Code Here

  @Test
  public void findFields() {
    putPerson("Peter", 26);
    _master.commit();
   
    VCursor vc = _master.getCollection("persons").find(_factory.createDocument("name", "Peter"), "name");
    assertEquals(1, vc.size());
    Map<String, Object> p = vc.iterator().next();
    assertEquals("Peter", p.get("name"));
    assertNull(p.get("age"));
    assertNotNull(p.get("_id"));
    assertNotNull(p.get("uid"));
    assertEquals(3, p.size()); //name, UID and OID
View Full Code Here

    for (int i = 0; i < 20; ++i) {
      putPerson(String.valueOf(i / 2), i / 2);
    }
    _master.commit();
   
    VCursor vc = _master.getCollection("persons").find(_factory.createDocument("name", "5"));
    assertEquals(2, vc.size());
    Iterator<Map<String, Object>> it = vc.iterator();
    Map<String, Object> p1 = it.next();
    assertEquals("5", p1.get("name"));
    assertEquals(Integer.valueOf(5), p1.get("age"));
    Map<String, Object> p2 = it.next();
    assertEquals("5", p2.get("name"));
View Full Code Here

    for (int i = 0; i < 20; ++i) {
      putPerson(String.valueOf(i), i);
    }
    _master.commit();
   
    VCursor vc = _master.getCollection("persons").find(_factory.createDocument("name", "100"));
    assertEquals(0, vc.size());
  }
View Full Code Here

    if (commit) {
      _master.commit();
    }
   
    //retrieve peter again and check his age
    VCursor vc = _master.getCollection("persons").find(_factory.createDocument("name", "Peter"));
    assertEquals(1, vc.size());
    Map<String, Object> p2 = vc.iterator().next();
    assertDocEquals(p, p2);
  }
View Full Code Here

    putPerson("Max", 6);
    Map<String, Object> p = putPerson("Peter", 26);
    VCollection persons = _master.getCollection("persons");
    assertEquals(2, persons.find().size());
    persons.delete(_factory.createDocument("name", "Max"));
    VCursor ps = persons.find();
    assertEquals(1, ps.size());
    assertDocEquals(p, ps.iterator().next());
  }
View Full Code Here

    putPerson("Max", 6);
    putPerson("Pax", 8);
    _master.commit();
   
    VCollection persons = _master.getCollection("persons");
    VCursor cursor = persons.find();
    DBCursor dbcursor = extractDBCursor(cursor);
    assertEquals(2, cursor.size());
    assertTrue(hasAttachedFilter(cursor));
    assertEquals(2, dbcursor.size());
   
    putPerson("Elvis", 3);
    _master.commit();
   
    persons = _master.getCollection("persons");
    cursor = persons.find();
    dbcursor = extractDBCursor(cursor);
    assertEquals(3, cursor.size());
    assertTrue(hasAttachedFilter(cursor));
    assertEquals(3, dbcursor.size());
   
    persons.delete(_factory.createDocument("name", "Max"));
    _master.commit();
   
    persons = _master.getCollection("persons");
    cursor = persons.find();
    dbcursor = extractDBCursor(cursor);
    assertEquals(2, cursor.size());
    assertTrue(hasAttachedFilter(cursor));
    assertEquals(2, dbcursor.size());
  }
View Full Code Here

TOP

Related Classes of de.fhg.igd.mongomvcc.VCursor

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.