Created
May 29, 2018 16:02
-
-
Save nosrednawall/20a97af13c236eadbb764dad4e23456b to your computer and use it in GitHub Desktop.
BaseDao Java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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