69 lines
1.8 KiB
Java
69 lines
1.8 KiB
Java
/*
|
|
* To change this license header, choose License Headers in Project Properties.
|
|
* To change this template file, choose Tools | Templates
|
|
* and open the template in the editor.
|
|
*/
|
|
package com.qsoft.erp.dao;
|
|
|
|
import com.qsoft.dao.bdd.AbstractDaoGenericoBDD;
|
|
import java.io.Serializable;
|
|
import javax.annotation.Resource;
|
|
import javax.persistence.EntityManager;
|
|
import javax.persistence.EntityManagerFactory;
|
|
import javax.persistence.Persistence;
|
|
import javax.persistence.PersistenceContext;
|
|
import javax.sql.DataSource;
|
|
|
|
/**
|
|
*
|
|
* @author james
|
|
* @param <T>
|
|
* @param <PK>
|
|
*/
|
|
public class DaoGenerico<T extends Serializable, PK extends Serializable> extends AbstractDaoGenericoBDD<T, PK> {
|
|
|
|
private final static Integer MAX_REGISTROS = 1000;
|
|
|
|
@PersistenceContext(unitName = "wmpPU")
|
|
private EntityManagerFactory emf;
|
|
/**
|
|
* Unidad de persistencia
|
|
*/
|
|
@PersistenceContext(unitName = "wmpPU")
|
|
private EntityManager em;
|
|
/**
|
|
* datasource inyectado, se obtiene del contenedor EJB
|
|
*/
|
|
@Resource(mappedName = "jdbc/werpDS")
|
|
private DataSource dataSource;
|
|
|
|
public DaoGenerico(Class<T> tipo) {
|
|
super(tipo, MAX_REGISTROS);
|
|
}
|
|
|
|
public DaoGenerico(Class<T> tipo, Integer maxRegistros) {
|
|
super(tipo, maxRegistros);
|
|
}
|
|
|
|
private EntityManagerFactory getEmf() {
|
|
if (this.emf == null || !this.emf.isOpen()) {//TODO: este codigo es para ejecucion local o ejecucion forzada
|
|
this.emf = Persistence.createEntityManagerFactory("wmpPU");
|
|
}
|
|
return this.emf;
|
|
}
|
|
|
|
@Override
|
|
public EntityManager getEm() {
|
|
if(this.em == null){
|
|
this.em = this.getEmf().createEntityManager();
|
|
}
|
|
return this.em;
|
|
}
|
|
|
|
@Override
|
|
public DataSource getDataSource() {
|
|
return this.dataSource;
|
|
}
|
|
|
|
}
|