class CloudDatastoreBackend extends AbstractDatabaseBackend {

    @Override
    public int deleteExpiredItems(Class modelClass, String field, Long cutoffTime, Integer numItems) {
        Datastore datastore = getService();
        KeyQuery.Builder queryBuilder = Query.newKeyQueryBuilder()
            .setKind(modelClass.getSimpleName())
            .setFilter(PropertyFilter.le(field, cutoffTime))
            .setOrderBy(OrderBy.asc(field));
        if (numItems != null) {
            queryBuilder.setLimit(numItems);
        }
        KeyQuery query = queryBuilder.build();
        final QueryResults<Key> keys = datastore.run(query);
        int numDeletedItems = 0;
        while (keys.hasNext()) {
            datastore.delete(keys.next());
            numDeletedItems++;
        }
        return numDeletedItems;
    }

}