All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.threewks.thundr.gae.objectify.Refs Maven / Gradle / Ivy

The newest version!
/*
 * This file is a component of thundr, a software library from 3wks.
 * Read more: http://3wks.github.io/thundr/
 * Copyright (C) 2015 3wks, 
 *
 * 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.threewks.thundr.gae.objectify;

import static com.googlecode.objectify.ObjectifyService.ofy;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;

import com.atomicleopard.expressive.Expressive;
import com.googlecode.objectify.Key;
import com.googlecode.objectify.Ref;

public class Refs {
	public static  T unref(Ref ref) {
		return ref == null ? null : ref.get();
	}

	public static  Collection unref(Collection> refs) {
		return Expressive.isEmpty(refs) ? Collections. emptyList() : ofy().load().refs(refs).values();
	}

	public static  Ref ref(T instance) {
		return instance == null ? null : Ref.create(instance);
	}

	public static  List> ref(Iterable instances) {
		List> result = new ArrayList<>();
		if (instances != null) {
			for (T t : instances) {
				result.add(Refs.ref(t));
			}
		}
		return result;
	}

	public static  Ref ref(Key key) {
		return key == null ? null : Ref.create(key);
	}

	public static  Key key(T instance) {
		return instance == null ? null : Key.create(instance);
	}

	public static  Key key(com.google.appengine.api.datastore.Key key) {
		return key == null ? null : Key. create(key);
	}

	public static  T unkey(Key key) {
		return key == null ? null : ofy().load().key(key).now();
	}

	public static  Collection unkey(Iterable> keys) {
		return Expressive.isEmpty(keys) ? Collections. emptyList() : ofy().load().keys(keys).values();
	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy