/** * <p>Preallocate multiple unique ids within the namespace of the * specified entity class. These ids can be used in concert with the normal * automatic allocation of ids when save()ing entities with null Long id fields.</p> * * <p>The {@code KeyRange<?>} class is deprecated; when using this method, * treat the return value as {@code List<Key<T>>}.</p> * * @param clazz must be a registered entity class with a Long or long id field. * @param num must be >= 1 and small enough we can fit a set of keys in RAM. */ public <T> KeyRange<T> allocateIds(final Class<T> clazz, final int num) { final String kind = Key.getKind(clazz); final IncompleteKey incompleteKey = datastore().newKeyFactory().setKind(kind).newKey(); return allocate(incompleteKey, num); }
/** * Preallocate a contiguous range of unique ids within the namespace of the * specified entity class and the parent key. These ids can be used in concert with the normal * automatic allocation of ids when put()ing entities with null Long id fields. * * @param parentKeyOrEntity must be a legitimate parent for the class type. It need not * point to an existent entity, but it must be the correct type for clazz. * @param clazz must be a registered entity class with a Long or long id field, and * a parent key of the correct type. * @param num must be >= 1 and <= 1 billion */ public <T> KeyRange<T> allocateIds(final Object parentKeyOrEntity, final Class<T> clazz, final int num) { final Key<?> parent = keys().anythingToKey(parentKeyOrEntity); final String kind = Key.getKind(clazz); final IncompleteKey incompleteKey = com.google.cloud.datastore.Key.newBuilder(parent.getRaw(), kind).build(); return allocate(incompleteKey, num); }