private void indexedStringEntityQueriesRun(int count) { // create entities List<IndexedStringEntity> entities = new ArrayList<>(count); String[] fixedRandomStrings = StringGenerator.createFixedRandomStrings(count); for (int i = 0; i < count; i++) { IndexedStringEntity entity = new IndexedStringEntity(); entity.setId((long) i); entity.setIndexedString(fixedRandomStrings[i]); entities.add(entity); } log("Built entities."); // insert entities realm.beginTransaction(); realm.copyToRealm(entities); realm.commitTransaction(); log("Inserted entities."); // query for entities by indexed string at random int[] randomIndices = StringGenerator.getFixedRandomIndices(getQueryCount(), count - 1); startClock(); for (int i = 0; i < getQueryCount(); i++) { int nextIndex = randomIndices[i]; RealmQuery<IndexedStringEntity> query = realm.where(IndexedStringEntity.class); query.equalTo("indexedString", fixedRandomStrings[nextIndex]); RealmResults<IndexedStringEntity> result = query.findAll(); for (int j = 0, resultSize = result.size(); j < resultSize; j++) { // actually get each entity so its object is reconstructed, same with properties IndexedStringEntity entity = result.get(j); entity.getId(); entity.getIndexedString(); } } stopClock(Benchmark.Type.QUERY_INDEXED); // delete all entities realm.beginTransaction(); realm.delete(IndexedStringEntity.class); realm.commitTransaction(); log("Deleted all entities."); }
private void deleteAll() { realm.beginTransaction(); realm.delete(SimpleEntityNotNull.class); realm.commitTransaction(); }