com.ust.coppel.incentivos.repository.impl.IncVariablesGlobalesRepositoryImpl.java Source code

Java tutorial

Introduction

Here is the source code for com.ust.coppel.incentivos.repository.impl.IncVariablesGlobalesRepositoryImpl.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 com.ust.coppel.incentivos.repository.impl;

import java.util.List;

import org.hibernate.Criteria;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.criterion.CriteriaSpecification;
import org.hibernate.criterion.Restrictions;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import com.model.CalculoIncentivos.IncPaqueteReglas;
import com.model.CalculoIncentivos.IncVariablesGlobales;
import com.ust.coppel.incentivos.repository.IncVariablesGlobalesRepository;

/**
 *
 * @author U35058
 */
@Repository
@SuppressWarnings({ "unchecked", "rawtypes" })
public class IncVariablesGlobalesRepositoryImpl implements IncVariablesGlobalesRepository {

    private SessionFactory sessionFactory;

    @Transactional
    @Override
    public List<IncVariablesGlobales> findAll() {
        Session session = sessionFactory.getCurrentSession();
        List incVentasPorGerentesProgc = session.createQuery("from IncVariablesGlobales").list();
        return incVentasPorGerentesProgc;
    }

    @Transactional
    @Override
    public void add(IncVariablesGlobales variables) {
        Session session = sessionFactory.getCurrentSession();

        session.save(variables);

    }

    @Transactional
    @Override
    public void update(IncVariablesGlobales variables) {
        Session session = sessionFactory.getCurrentSession();

        session.update(variables);

    }

    @Transactional
    @Override
    public void remove(IncVariablesGlobales variables) {
        Session session = sessionFactory.getCurrentSession();

        session.delete(variables);
    }

    @Transactional
    @Override
    public IncVariablesGlobales find(Integer Id) {
        Session session = sessionFactory.getCurrentSession();

        Criteria criteria = session.createCriteria(IncVariablesGlobales.class);

        criteria.add(Restrictions.eq("iduVariable", Id));
        IncVariablesGlobales aux = null;
        for (Object aux1 : criteria.list()) {
            aux = (IncVariablesGlobales) aux1;
        }
        return aux;
    }

    @Transactional
    @Override
    public List<IncVariablesGlobales> findAll(Integer nom_proceso) {
        Session session = sessionFactory.getCurrentSession();
        Criteria criteria = session.createCriteria(IncVariablesGlobales.class);

        criteria.add(Restrictions.eq("incPaqueteReglas.incProceso.iduProceso", nom_proceso));

        List<IncVariablesGlobales> incVentasPorGerentesProgc = criteria.list();

        return incVentasPorGerentesProgc;
    }

    @Transactional
    @Override
    public List<IncVariablesGlobales> findAll(IncPaqueteReglas paq_) {
        Session session = sessionFactory.getCurrentSession();
        Criteria criteria = session.createCriteria(IncVariablesGlobales.class);

        criteria.add(Restrictions.eq("incPaqueteReglas.iduPaquete", paq_.getIduPaquete()));
        criteria.setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY);

        List<IncVariablesGlobales> incVentasPorGerentesProgc = criteria.list();

        return incVentasPorGerentesProgc;
    }

}