model.ModelPosto.java Source code

Java tutorial

Introduction

Here is the source code for model.ModelPosto.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 model;

import DAO.DAOHibernateUtil;
import java.util.List;
import org.hibernate.Session;

/**
 *
 * @author Ronai
 */
public class ModelPosto {

    public void insertPosto(Posto posto) {
        Session session = DAOHibernateUtil.getSessionFactory().getCurrentSession();

        session.beginTransaction();
        session.save(posto);
        session.getTransaction().commit();
    }

    public void updatePosto(Posto posto) {
        Session session = DAOHibernateUtil.getSessionFactory().getCurrentSession();

        session.beginTransaction();
        session.merge(posto);
        session.getTransaction().commit();
    }

    public void deletePosto(Posto posto) {
        Session session = DAOHibernateUtil.getSessionFactory().getCurrentSession();

        session.beginTransaction();
        session.delete(posto);
        session.getTransaction().commit();
    }

    public List<String> pegaPosto(String bairro) {
        Session session = DAOHibernateUtil.getSessionFactory().getCurrentSession();

        session.beginTransaction();
        java.util.List<String> listaPosto = session.createQuery("From Posto where PostoBairro = " + bairro).list();

        return listaPosto;
    }
}