Package dao_impl

Source Code of dao_impl.ConditionDAOImpl

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package dao_impl;

import java.util.List;

import org.apache.log4j.Logger;
import org.hibernate.HibernateException;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.Transaction;

import dao.ConditionDAO;
import dao.UserDAO;
import pojo.Product;
import pojo.Condition;
import pojo.User;
import util.HibernateUtil;

/**
*
* @author phuc
*/
public class ConditionDAOImpl implements ConditionDAO {
  private static final Logger logger = Logger.getLogger(ConditionDAOImpl.class)
 

  //get all List Condition
  public List<Condition> getListCondition() {
    logger.debug("getListCondition start");
    List<Condition> ds = null;

    Session session = HibernateUtil.getSessionFactory().openSession();
   
    try {
      String hql = "from Condition";
      Query query = session.createQuery(hql);
      ds = query.list();
      logger.debug("getListCondition success");
    } catch (HibernateException ex) {
      System.err.println(ex);
      logger.error("getListCondition error : " + ex);
    } finally {
      session.close();
    }
    logger.debug("getListCondition end");
    return ds;
  }

  //get List Condition by id
  public Condition getInfoCondition(int id) {
    logger.debug("getListCondition by id start");
    Condition sp = null;
    Session session = HibernateUtil.getSessionFactory().openSession();
    try {
      sp = (Condition) session.get(Condition.class, id);
      logger.debug("getListCondition by id success");
    } catch (HibernateException ex) {
      System.err.println(ex);
      logger.error("getListCondition by id error : " + ex);
    } finally {
      session.close();
    }
    logger.debug("getListCondition by id end");
    return sp;
  }

  //add Condition
  public boolean addCondition(Condition sp) {
    logger.debug("addCondition start");
    Session session = HibernateUtil.getSessionFactory().openSession();
    ConditionDAO khDAO = new ConditionDAOImpl();
   
    Transaction transaction = null;
    try {
      transaction = session.beginTransaction();
      session.save(sp);
      transaction.commit();
      logger.debug("addCondition success");
    } catch (HibernateException ex) {
      transaction.rollback();
      System.err.println(ex);
      logger.error("addCondition error : " + ex);
    } finally {
      session.close();
    }
    logger.debug("addCondition end");
    return true;
  }

  //del Condition
  public boolean delCondition(int id) {
    logger.debug("delCondition start");
    Session session = HibernateUtil.getSessionFactory().openSession();
    Condition u = (Condition) session.get(Condition.class, id);
   
    Transaction transaction = null;
    try {
      transaction = session.beginTransaction();
      session.delete(u);
      transaction.commit();
      logger.debug("delCondition success");
    } catch (HibernateException ex) {
      transaction.rollback();
      System.err.println(ex);
      logger.error("delCondition error : " + ex);
    } finally {
      session.close();
    }
    logger.debug("delCondition end");
    return true;
  }
}
TOP

Related Classes of dao_impl.ConditionDAOImpl

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.