Skip to content

Instantly share code, notes, and snippets.

@nosrednawall
Created May 29, 2018 16:02
Show Gist options
  • Save nosrednawall/20a97af13c236eadbb764dad4e23456b to your computer and use it in GitHub Desktop.
Save nosrednawall/20a97af13c236eadbb764dad4e23456b to your computer and use it in GitHub Desktop.
BaseDao Java
package br.com.brascov.querocomprar.model.dao;
import java.io.Serializable;
import javax.persistence.EntityManager;
/**
* @author Anderson
*
* classe base que possui os métodos comuns para todas as Daos
*
* @param <T> classe entity que deverá ser especificada na Dao concreta
*/
public abstract class BaseDao<T> implements Serializable{
/**
*
*/
private static final long serialVersionUID = 1L;
//construtor em branco
public BaseDao() {}
//Administrador de entidade
protected abstract EntityManager getEntityManager();
public void save(T entity) {
getEntityManager().persist(entity);
}
public T update(T entity) {
return getEntityManager().merge(entity);
}
public void remove(T entity) {
getEntityManager().remove(getEntityManager().merge(entity));
}
public T find(Class<T> type, Object id) {
return getEntityManager().find(type, id);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment