Last active
August 29, 2015 14:04
-
-
Save dilnei/c4ea31c56b7e4b9e80ca to your computer and use it in GitHub Desktop.
DaoFactory (Produtor de DAO<T>)
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.weblog.service.factory; | |
import br.com.weblog.service.dao.DAO; | |
import java.lang.reflect.ParameterizedType; | |
import javax.enterprise.inject.Produces; | |
import javax.enterprise.inject.spi.InjectionPoint; | |
import javax.inject.Inject; | |
import javax.persistence.EntityManager; | |
/** | |
* Produtor de DAO<T> | |
* | |
* @author Dilnei Cunha. | |
*/ | |
public class DaoFactory { | |
@Inject | |
EntityManager entityManager; | |
@Inject | |
InjectionPoint injectionPoint; | |
@Produces | |
public DAO create() { | |
ParameterizedType type = (ParameterizedType) injectionPoint.getType(); | |
Class classe = (Class) type.getActualTypeArguments()[0]; | |
return new DAO(classe, entityManager); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment