Sha256: 8b18cd4a7d309e4c195b51845c64acc62b5b50e6dfaef6e6c8a24609c9a58311

Contents?: true

Size: 888 Bytes

Versions: 3

Compression:

Stored size: 888 Bytes

Contents

package app.repositories;

import java.lang.reflect.ParameterizedType;
import java.util.List;

import com.googlecode.objectify.Objectify;

class Repository<T> {
	
	protected final Objectify objectify;
	
	public Repository(Objectify objectify) {
		this.objectify = objectify;
	}
	
	public void create(T entity) {
		objectify.put(entity);
	}
	
	public void update(T entity) {
		objectify.put(entity);
	}
	
	public void destroy(T entity) {
		objectify.delete(entity);
	}
	
	public T find(Long id) {
		return objectify.get(getParameterizedClass(), id);
	}
	
	public List<T> findAll() {
		return objectify.query(getParameterizedClass()).list();
	}
	
	@SuppressWarnings("unchecked")
	private Class<T> getParameterizedClass() {
		ParameterizedType parameterizedType = (ParameterizedType) getClass().getGenericSuperclass();
		return (Class<T>) parameterizedType.getActualTypeArguments()[0];
	}
}

Version data entries

3 entries across 3 versions & 2 rubygems

Version Path
heroku-vraptor-scaffold-0.9.0 spec/vraptor-scaffold/generators/app/templates/RepositoryObjectify.java
vraptor-scaffold-1.3.0 spec/vraptor-scaffold/generators/app/templates/RepositoryObjectify.java
vraptor-scaffold-1.3.0.rc spec/vraptor-scaffold/generators/app/templates/RepositoryObjectify.java