@SuppressWarnings("unchecked")
@Test
public void testTruncateClass() {
OSchema schema = database.getMetadata().getSchema();
OClass testClass = getOrCreateClass(schema);
final OIndex<?> index = getOrCreateIndex(testClass);
schema.save();
database.command(new OCommandSQL("truncate class test_class")).execute();
database.save(new ODocument(testClass).field("name", "x").field("data", Arrays.asList(1, 2)));
database.save(new ODocument(testClass).field("name", "y").field("data", Arrays.asList(3, 0)));
database.command(new OCommandSQL("truncate class test_class")).execute();
database.save(new ODocument(testClass).field("name", "x").field("data", Arrays.asList(5, 6, 7)));
database.save(new ODocument(testClass).field("name", "y").field("data", Arrays.asList(8, 9, -1)));
List<ODocument> result = database.query(new OSQLSynchQuery<ODocument>("select from test_class"));
Assert.assertEquals(result.size(), 2);
Set<Integer> set = new HashSet<Integer>();
for (ODocument document : result) {
set.addAll((Collection<Integer>) document.field("data"));
}
Assert.assertTrue(set.containsAll(Arrays.asList(5, 6, 7, 8, 9, -1)));
Assert.assertEquals(index.getSize(), 6);
OIndexCursor cursor = index.cursor();
Map.Entry<Object, OIdentifiable> entry = cursor.nextEntry();
while (entry != null) {
Assert.assertTrue(set.contains((Integer) entry.getKey()));
entry = cursor.nextEntry();
}
schema.dropClass("test_class");
}