ar.edu.unju.fi.apu.dao.impl.FacturaDetalleDAOImpl.java Source code

Java tutorial

Introduction

Here is the source code for ar.edu.unju.fi.apu.dao.impl.FacturaDetalleDAOImpl.java

Source

/*
 * 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 ar.edu.unju.fi.apu.dao.impl;

import ar.edu.unju.fi.apu.dao.IFacturaDetalleDAO;
import ar.edu.unju.fi.apu.hibernate.configuracion.HibernateUtil;
import ar.edu.unju.fi.apu.modelo.dominio.EncabezadoFactura;

import ar.edu.unju.fi.apu.modelo.dominio.FacturaDetalle;
import java.util.ArrayList;
import java.util.List;
import org.hibernate.Criteria;
import org.hibernate.Session;
import org.hibernate.criterion.Restrictions;

/**
 *
 * @author Fernando
 */
public class FacturaDetalleDAOImpl implements IFacturaDetalleDAO {

    @Override
    public void altaFacturaDetalle(FacturaDetalle facturaDetalle) {
        Session session = HibernateUtil.getSessionFactory().openSession();
        session.beginTransaction();
        session.save(facturaDetalle);
        session.getTransaction().commit();
        session.close();
    }

    @Override
    public void bajaFacturaDetalle(FacturaDetalle facturaDetalle) {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public void modificar(FacturaDetalle facturaDetalle) {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public List<FacturaDetalle> obtenerDetalles(EncabezadoFactura factura) {
        Session session = HibernateUtil.getSessionFactory().openSession();
        Criteria criteria = session.createCriteria(FacturaDetalle.class);

        criteria.add(Restrictions.eq("encabezadoFacturas", factura));

        return criteria.list();
    }

    @Override
    public FacturaDetalle obtenerFacturaDetalle(int codigo) {
        Session session = HibernateUtil.getSessionFactory().openSession();
        Criteria criteria = session.createCriteria(FacturaDetalle.class);

        criteria.add(Restrictions.like("codigo", codigo));
        return (FacturaDetalle) criteria.list().get(0);
    }

}