Sha256: 66b52d54ef17199f4aa2a442bf3701b551d10813bbf702a6e617eab3290fb790

Contents?: true

Size: 934 Bytes

Versions: 3

Compression:

Stored size: 934 Bytes

Contents

package <%= options[:package] %>.<%= options[:repositories_package] %>;

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 lib/vraptor-scaffold/generators/app/templates/orm/Repository-objectify.java.tt
vraptor-scaffold-1.3.0 lib/vraptor-scaffold/generators/app/templates/orm/Repository-objectify.java.tt
vraptor-scaffold-1.3.0.rc lib/vraptor-scaffold/generators/app/templates/orm/Repository-objectify.java.tt