@Override public Long from(Key<E> from) { return from.getId(); } };
@Override public Long from(Key from) { return from == null ? null : from.getId(); }
@Override protected Map<S, T> wrap(Map<Key<T>, T> base) throws Exception { Map<S, T> result = new LinkedHashMap<S, T>(base.size() * 2); for (Map.Entry<Key<T>, T> entry: base.entrySet()) { Object mapKey = entry.getKey().getName() != null ? entry.getKey().getName() : entry.getKey().getId(); result.put((S)mapKey, entry.getValue()); } return result; } };
/** * Allocates a single id from the allocator for the specified kind. Safe to use in concert * with the automatic generator. This is just a convenience method for allocateIds(). * * @param clazz must be a registered entity class with a Long or long id field. */ public <T> long allocateId(Class<T> clazz) { return allocateIds(clazz, 1).iterator().next().getId(); }
/** * Allocates a single id from the allocator for the specified kind. Safe to use in concert * with the automatic generator. This is just a convenience method for allocateIds(). * * Note that the id is only unique within the parent, not across the entire kind. * * @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. */ public <T> long allocateId(Object parentKeyOrEntity, Class<T> clazz) { return allocateIds(parentKeyOrEntity, clazz, 1).iterator().next().getId(); }