/*
 * 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.Realtech.controladors;

import java.io.Serializable;
import javax.persistence.Query;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Root;
import com.Realtech.entity.TblLogTramas;
import java.util.List;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;

/**
 *
 * @author Realtech
 */
public class TblLogTramasJpaController implements Serializable {

    public TblLogTramasJpaController(EntityManagerFactory emf) {
        this.emf = emf;
    }
    private EntityManagerFactory emf = null;

    public EntityManager getEntityManager() {
        return emf.createEntityManager();
    }

    public void create(TblLogTramas tblLogTramas) {
        EntityManager em = null;
        try {
            em = getEntityManager();
            em.getTransaction().begin();
            em.persist(tblLogTramas);
            em.getTransaction().commit();
        } finally {
            if (em != null) {
                em.close();
            }
        }
    }


    public List<TblLogTramas> findTblLogTramasEntities() {
        return findTblLogTramasEntities(true, -1, -1);
    }

    public List<TblLogTramas> findTblLogTramasEntities(int maxResults, int firstResult) {
        return findTblLogTramasEntities(false, maxResults, firstResult);
    }

    private List<TblLogTramas> findTblLogTramasEntities(boolean all, int maxResults, int firstResult) {
        EntityManager em = getEntityManager();
        try {
            CriteriaQuery cq = em.getCriteriaBuilder().createQuery();
            cq.select(cq.from(TblLogTramas.class));
            Query q = em.createQuery(cq);
            if (!all) {
                q.setMaxResults(maxResults);
                q.setFirstResult(firstResult);
            }
            return q.getResultList();
        } finally {
            em.close();
        }
    }

    public TblLogTramas findTblLogTramas(Long id) {
        EntityManager em = getEntityManager();
        try {
            return em.find(TblLogTramas.class, id);
        } finally {
            em.close();
        }
    }

    public int getTblLogTramasCount() {
        EntityManager em = getEntityManager();
        try {
            CriteriaQuery cq = em.getCriteriaBuilder().createQuery();
            Root<TblLogTramas> rt = cq.from(TblLogTramas.class);
            cq.select(em.getCriteriaBuilder().count(rt));
            Query q = em.createQuery(cq);
            return ((Long) q.getSingleResult()).intValue();
        } finally {
            em.close();
        }
    }
    
}
