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.Films90;

import static org.hibernate.criterion.Example.create;

/**
 * Home object for domain model class Films90.
 * @see dao.Films90
 * @author Hibernate Tools
 */
public class Films90Home {

	private static final Log log = LogFactory.getLog(Films90Home.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(Films90 transientInstance) {
		log.debug("persisting Films90 instance");
		try {
			sessionFactory.getCurrentSession().persist(transientInstance);
			log.debug("persist successful");
		} catch (RuntimeException re) {
			log.error("persist failed", re);
			throw re;
		}
	}

	public void attachDirty(Films90 instance) {
		log.debug("attaching dirty Films90 instance");
		try {
			sessionFactory.getCurrentSession().saveOrUpdate(instance);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}

	public void attachClean(Films90 instance) {
		log.debug("attaching clean Films90 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(Films90 persistentInstance) {
		log.debug("deleting Films90 instance");
		try {
			sessionFactory.getCurrentSession().delete(persistentInstance);
			log.debug("delete successful");
		} catch (RuntimeException re) {
			log.error("delete failed", re);
			throw re;
		}
	}

	public Films90 merge(Films90 detachedInstance) {
		log.debug("merging Films90 instance");
		try {
			Films90 result = (Films90) sessionFactory.getCurrentSession().merge(detachedInstance);
			log.debug("merge successful");
			return result;
		} catch (RuntimeException re) {
			log.error("merge failed", re);
			throw re;
		}
	}

	public Films90 findById(dao.Films90Id id) {
		log.debug("getting Films90 instance with id: " + id);
		try {
			Films90 instance = (Films90) sessionFactory.getCurrentSession().get("dao.Films90", 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<Films90> findByExample(Films90 instance) {
		log.debug("finding Films90 instance by example");
		try {
			List<Films90> results = (List<Films90>) sessionFactory.getCurrentSession().createCriteria("dao.Films90")
					.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;
		}
	}
}
