main.java.Contexto.ContextoProvincia.java Source code

Java tutorial

Introduction

Here is the source code for main.java.Contexto.ContextoProvincia.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 main.java.Contexto;

/**
 *
 * @author developer
 */
import java.util.List;
import main.java.modelos.Provincia;
import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.Transaction;
import main.java.modelos.Partido;
import org.hibernate.Session;
import org.hibernate.Transaction;
import java.util.List;
import org.hibernate.HibernateException;
import org.hibernate.Query;

public class ContextoProvincia extends ContextoBase implements IConsultable<Provincia> {

    //<editor-fold defaultstate="collapsed" desc="Constructores">

    public ContextoProvincia(String NombreConf) throws HibernateException {
        super(NombreConf);

    }

    public ContextoProvincia() throws HibernateException {
        super();
    }

    //</editor-fold>

    @Override
    public void insertar(Provincia o) {
        Session ses = this.getFactory().openSession();
        Transaction tx = ses.beginTransaction();
        ses.save(o);
        tx.commit();
        ses.close();
    }

    @Override
    public Provincia buscar(long Id) {
        Session ses = this.getFactory().openSession();
        Transaction tx = ses.beginTransaction();
        Query q = ses.createQuery("from Provincia p where p.id=:id");
        q.setLong("id", Id);
        Provincia p = (Provincia) q.uniqueResult();
        tx.commit();
        ses.close();
        return p;
    }

    @Override
    public List<Provincia> seleccionarTodos() {
        Session ses = this.getFactory().openSession();
        Transaction tx = ses.beginTransaction();
        Query query = ses.createQuery("from Provincia p " + "where p.estado=:estado");
        query.setBoolean("estado", true);
        List<Provincia> Partidos = query.list();
        tx.commit();
        ses.close();
        return Partidos;
    }

    @Override
    public void eliminar(int Id) {
        Session ses = this.getFactory().openSession();
        Transaction tx = ses.beginTransaction();
        Provincia p = this.buscar(Id);
        p.setEstado(false);
        ses.update(p);
        tx.commit();
        ses.close();
    }

    @Override
    public void actualizar(Provincia elem) {
        Session ses = this.getFactory().openSession();
        Transaction tx = ses.beginTransaction();
        ses.update(elem);
        tx.commit();
        ses.close();
    }

}