Пример #1
0
  @Test
  public void testCursorPutAndGet() throws Exception {
    k1.putLong(0, 14);
    v1.putLong(0, 15);
    k2.putLong(0, 16);
    v2.putLong(0, 17);

    try (Transaction tx = env.createWriteTransaction()) {
      try (Cursor cursor = db.openCursor(tx)) {
        cursor.put(k1, v1, 0);
        cursor.put(k2, v2, 0);
      }
      tx.commit();
    }

    DirectBuffer k = new DirectBuffer();
    DirectBuffer v = new DirectBuffer();

    try (Transaction tx = env.createReadTransaction()) {
      try (Cursor cursor = db.openCursor(tx)) {
        cursor.position(k, v, GetOp.FIRST);
        assertThat(k.getLong(0), is(14L));
        assertThat(v.getLong(0), is(15L));

        cursor.position(k, v, GetOp.NEXT);
        assertThat(k.getLong(0), is(16L));
        assertThat(v.getLong(0), is(17L));
      }
    }
  }
Пример #2
0
 @Test
 public void testIteration() {
   k1.putLong(0, 18);
   v1.putLong(0, 19);
   k2.putLong(0, 20);
   v2.putLong(0, 21);
   db.put(k1, v1, 0);
   db.put(k2, v2, 0);
   List<Long> result = new ArrayList<>();
   try (Transaction tx = env.createWriteTransaction()) {
     try (Cursor cursor = db.openCursor(tx)) {
       DirectBuffer k = new DirectBuffer();
       DirectBuffer v = new DirectBuffer();
       for (int rc = cursor.position(k, v, FIRST);
           rc != NOTFOUND;
           rc = cursor.position(k, v, NEXT)) {
         result.add(k.getLong(0));
       }
     }
     tx.commit();
   }
   assertThat(result.size(), is(2));
   assertThat(result.get(0), is(18L));
   assertThat(result.get(1), is(20L));
 }