package dao;
// Generated Oct 23, 2017 4:32:37 PM by Hibernate Tools 3.5.0.Final

import java.util.List;
import javax.naming.InitialContext;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.LockMode;
import org.hibernate.SessionFactory;

import model.Jouer;

import static org.hibernate.criterion.Example.create;

/**
 * Home object for domain model class Jouer.
 * @see dao.Jouer
 * @author Hibernate Tools
 */
public class JouerHome {

	private static final Log log = LogFactory.getLog(JouerHome.class);

	private final SessionFactory sessionFactory = getSessionFactory();

	protected SessionFactory getSessionFactory() {
		try {
			return (SessionFactory) new InitialContext().lookup("SessionFactory");
		} catch (Exception e) {
			log.error("Could not locate SessionFactory in JNDI", e);
			throw new IllegalStateException("Could not locate SessionFactory in JNDI");
		}
	}

	public void persist(Jouer transientInstance) {
		log.debug("persisting Jouer instance");
		try {
			sessionFactory.getCurrentSession().persist(transientInstance);
			log.debug("persist successful");
		} catch (RuntimeException re) {
			log.error("persist failed", re);
			throw re;
		}
	}

	public void attachDirty(Jouer instance) {
		log.debug("attaching dirty Jouer instance");
		try {
			sessionFactory.getCurrentSession().saveOrUpdate(instance);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}

	public void attachClean(Jouer instance) {
		log.debug("attaching clean Jouer instance");
		try {
			sessionFactory.getCurrentSession().lock(instance, LockMode.NONE);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}

	public void delete(Jouer persistentInstance) {
		log.debug("deleting Jouer instance");
		try {
			sessionFactory.getCurrentSession().delete(persistentInstance);
			log.debug("delete successful");
		} catch (RuntimeException re) {
			log.error("delete failed", re);
			throw re;
		}
	}

	public Jouer merge(Jouer detachedInstance) {
		log.debug("merging Jouer instance");
		try {
			Jouer result = (Jouer) sessionFactory.getCurrentSession().merge(detachedInstance);
			log.debug("merge successful");
			return result;
		} catch (RuntimeException re) {
			log.error("merge failed", re);
			throw re;
		}
	}

	public Jouer findById(dao.JouerId id) {
		log.debug("getting Jouer instance with id: " + id);
		try {
			Jouer instance = (Jouer) sessionFactory.getCurrentSession().get("dao.Jouer", id);
			if (instance == null) {
				log.debug("get successful, no instance found");
			} else {
				log.debug("get successful, instance found");
			}
			return instance;
		} catch (RuntimeException re) {
			log.error("get failed", re);
			throw re;
		}
	}

	public List<Jouer> findByExample(Jouer instance) {
		log.debug("finding Jouer instance by example");
		try {
			List<Jouer> results = (List<Jouer>) sessionFactory.getCurrentSession().createCriteria("dao.Jouer")
					.add(create(instance)).list();
			log.debug("find by example successful, result size: " + results.size());
			return results;
		} catch (RuntimeException re) {
			log.error("find by example failed", re);
			throw re;
		}
	}
}
