Java tutorial
/** * Copyright 2013 ArcBees Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); you may not * use this file except in compliance with the License. You may obtain a copy of * the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations under * the License. */ package com.centretown.planets.server.dao.objectify; import java.util.Collection; import java.util.Map; import java.util.Set; import com.google.common.collect.Sets; import com.googlecode.objectify.Key; import com.googlecode.objectify.Ref; public class Deref { public static <T> T deref(Ref<T> ref) { return ref == null ? null : ref.get(); } public static <T> T deref(Ref<T> ref, final Class<?>... groups) { return ref == null ? null : ofy().load().group(groups).key(ref.key()).now(); } public static <T> Set<T> deref(Collection<Ref<T>> reflist) { return deref(reflist, (Class<?>[]) null); } public static <T> Set<T> deref(Collection<Ref<T>> reflist, Class<?>... groups) { if (reflist == null) { return null; } return Sets.newHashSet(values(reflist, groups).values()); } public static <T> Map<Key<T>, T> values(Collection<Ref<T>> reflist, Class<?>... groups) { if (reflist == null) { return null; } if (groups == null || groups.length <= 0) { return ofy().load().values(reflist); } return ofy().load().group(groups).values(reflist); } private final static Ofy ofy() { return OfyService.ofy(); } }