@Override
 @Nullable
 public EntityId nextIdImpl() {
   if (hasNextImpl()) {
     explain(getType());
     final Cursor cursor = getCursor();
     final long localId = LongBinding.compressedEntryToLong(cursor.getKey());
     final EntityId result = new PersistentEntityId(entityTypeId, localId);
     checkHasNext(cursor.getNext());
     return result;
   }
   return null;
 }
 @Override
 protected long countImpl(@NotNull final PersistentStoreTransaction txn) {
   final Cursor cursor = openCursor(txn);
   if (cursor == null) {
     return 0;
   }
   try {
     final ByteIterable key = LongBinding.longToCompressedEntry(min);
     long result = 0;
     boolean success = cursor.getSearchKeyRange(key) != null;
     while (success) {
       if (max > LongBinding.compressedEntryToLong(cursor.getKey())) {
         break;
       }
       result++;
       success = cursor.getNextNoDup();
     }
     return result;
   } finally {
     cursor.close();
   }
 }