ar.edu.unju.fi.apu.dao.imp.mysql.PropietarioDAOImp.java Source code

Java tutorial

Introduction

Here is the source code for ar.edu.unju.fi.apu.dao.imp.mysql.PropietarioDAOImp.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.imp.mysql;

import ar.edu.unju.fi.apu.dao.IPropietarioDAO;
import ar.edu.unju.fi.apu.hibernate.configuracion.HibernateUtil;
import ar.edu.unju.fi.apu.modelo.dominio.Propietario;
import java.util.List;
import org.hibernate.Criteria;
import org.hibernate.Session;
import org.hibernate.criterion.Order;
import org.hibernate.criterion.Restrictions;

/**
 *
 * @author celso-pc
 */
public class PropietarioDAOImp implements IPropietarioDAO {

    @Override
    public void crearPropietario(Propietario propietario) {
        propietario.setEstado(true);
        Session session = HibernateUtil.getSessionFactory().openSession();
        session.beginTransaction();
        session.save(propietario);
        session.getTransaction().commit();
        session.close();
    }

    @Override
    public void modificarPropietario(Propietario propietario) {
        Session session = HibernateUtil.getSessionFactory().openSession();
        session.beginTransaction();
        session.update(propietario);
        session.getTransaction().commit();
        session.close();
    }

    @Override
    public List<Propietario> obtenerTodos() {
        Session session = HibernateUtil.getSessionFactory().openSession();
        Criteria criteria = session.createCriteria(Propietario.class);
        criteria.add(Restrictions.eq("estado", true));
        criteria.addOrder(Order.asc("apellido"));
        List propietarios = criteria.list();
        return propietarios;
    }

}