package es.dalocar.software.daos;

// Generated 29-oct-2009 22:34:39 by Hibernate Tools 3.2.4.GA

import java.util.List;

import org.apache.log4j.Logger;
import org.hibernate.LockMode;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import es.dalocar.software.beans.Factura;

/**
 * Home object for domain model class Factura.
 * 
 * @see es.dalocar.software.beans.Factura
 * @author Hibernate Tools
 */
public class FacturaDAO extends HibernateDaoSupport {

	private static final Logger log = Logger.getLogger(FacturaDAO.class);
	private static final boolean DEBUG = log.isDebugEnabled();

	public void persist(Factura transientInstance) {
		if (DEBUG)
			log.debug("persisting Factura instance");
		try {
			getHibernateTemplate().persist(transientInstance);
			if (DEBUG)
				log.debug("persist successful");
		} catch (RuntimeException re) {
			log.error("persist failed", re);
			throw re;
		}
	}

	/**
	 * Distingue si debe guardar o salvar el objeto en cuestión
	 * @param instance
	 */
	public void saveOrUpdate(Factura instance) {
		if (DEBUG)
			log.debug("saving or updating Factura instance");
		try {
			getHibernateTemplate().saveOrUpdate(instance);
			if (DEBUG)
				log.debug("saveOrUpdate successful");
		} catch (RuntimeException re) {
			log.error("persist failed", re);
			throw re;
		}
	}

	public void attachDirty(Factura instance) {
		if (DEBUG)
			log.debug("attaching dirty Factura instance");
		try {
			getHibernateTemplate().saveOrUpdate(instance);
			if (DEBUG)
				log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}

	public void attachClean(Factura instance) {
		if (DEBUG)
			log.debug("attaching clean Factura instance");
		try {
			getHibernateTemplate().lock(instance, LockMode.NONE);
			if (DEBUG)
				log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}

	public void delete(Factura persistentInstance) {
		if (DEBUG)
			log.debug("deleting Factura instance");
		try {
			getHibernateTemplate().delete(persistentInstance);
			if (DEBUG)
				log.debug("delete successful");
		} catch (RuntimeException re) {
			log.error("delete failed", re);
			throw re;
		}
	}

	public Factura merge(Factura detachedInstance) {
		if (DEBUG)
			log.debug("merging Factura instance");
		try {
			Factura result = (Factura) getHibernateTemplate().merge(
					detachedInstance);
			if (DEBUG)
				log.debug("merge successful");
			return result;
		} catch (RuntimeException re) {
			log.error("merge failed", re);
			throw re;
		}
	}

	public Factura findById(es.dalocar.software.beans.FacturaId id) {
		if (DEBUG)
			log.debug("getting Factura instance with id: " + id);
		try {
			Factura instance = (Factura) getHibernateTemplate().get(
					"es.dalocar.software.beans.Factura", id);
			if (instance == null) {
				if (DEBUG)
					log.debug("get successful, no instance found");
			} else {
				if (DEBUG)
					log.debug("get successful, instance found");
			}
			return instance;
		} catch (RuntimeException re) {
			log.error("get failed", re);
			throw re;
		}
	}

	public List findByExample(Factura instance) {
		if (DEBUG)
			log.debug("finding Factura instance by example");
		try {
			List results = getHibernateTemplate().findByExample(instance);
			if (DEBUG)
				log.debug("find by example successful, result size: "
						+ results.size());
			return results;
		} catch (RuntimeException re) {
			log.error("find by example failed", re);
			throw re;
		}
	}

	/**
	 * @param instance
	 * @return
	 */
	public List findAll() {
		if (DEBUG)
			log.debug("finding Factura instance by example");
		try {
			List results = getHibernateTemplate().find("from Factura");
			if (DEBUG)
				log.debug("find all, result size: " + results.size());
			return results;
		} catch (RuntimeException re) {
			log.error("find by example failed", re);
			throw re;
		}
	}
}
