ds = (DaoDataset) repo.load("default", datasetName);
// ensure the new entities are what we expect with get operations
for (int i = 0; i < 10; ++i) {
String iStr = Long.toString(i);
Key key = new Key.Builder(ds)
.add("part1", new Utf8("part1_" + iStr))
.add("part2", new Utf8("part2_" + iStr)).build();
compareEntitiesWithUtf8(i, ds.get(key));
}
// ensure the new entities are what we expect with scan operations
int cnt = 0;
DatasetReader<GenericRecord> reader = ds.newReader();
assertTrue("Reader should be open initially", reader.isOpen());
try {
for (GenericRecord entity : reader) {
compareEntitiesWithUtf8(cnt, entity);
cnt++;
}
assertEquals(10, cnt);
} finally {
reader.close();
assertFalse("Reader should be closed after calling close", reader.isOpen());
}
// test a partial scan
cnt = 3;
reader = new DaoView<GenericRecord>(ds, GenericRecord.class)
.from("part1", new Utf8("part1_3")).from("part2", new Utf8("part2_3"))
.to("part1", new Utf8("part1_7")).to("part2", new Utf8("part2_7"))
.newReader();
try {
for (GenericRecord entity : reader) {
compareEntitiesWithUtf8(cnt, entity);
cnt++;
}
assertEquals(8, cnt);
} finally {
reader.close();
}
Key key = new Key.Builder(ds)
.add("part1", new Utf8("part1_5"))
.add("part2", new Utf8("part2_5")).build();
// test delete
ds.delete(key);