package es.dalocar.software;

// Generated 03-may-2010 22:59:56 by Hibernate Tools 3.2.4.GA

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 static org.hibernate.criterion.Example.create;

/**
 * Home object for domain model class Amortizacion.
 * @see es.dalocar.software.Amortizacion
 * @author Hibernate Tools
 */
public class AmortizacionHome {

	private static final Log log = LogFactory.getLog(AmortizacionHome.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(Amortizacion transientInstance) {
		log.debug("persisting Amortizacion instance");
		try {
			sessionFactory.getCurrentSession().persist(transientInstance);
			log.debug("persist successful");
		} catch (RuntimeException re) {
			log.error("persist failed", re);
			throw re;
		}
	}

	public void attachDirty(Amortizacion instance) {
		log.debug("attaching dirty Amortizacion instance");
		try {
			sessionFactory.getCurrentSession().saveOrUpdate(instance);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}

	public void attachClean(Amortizacion instance) {
		log.debug("attaching clean Amortizacion 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(Amortizacion persistentInstance) {
		log.debug("deleting Amortizacion instance");
		try {
			sessionFactory.getCurrentSession().delete(persistentInstance);
			log.debug("delete successful");
		} catch (RuntimeException re) {
			log.error("delete failed", re);
			throw re;
		}
	}

	public Amortizacion merge(Amortizacion detachedInstance) {
		log.debug("merging Amortizacion instance");
		try {
			Amortizacion result = (Amortizacion) sessionFactory
					.getCurrentSession().merge(detachedInstance);
			log.debug("merge successful");
			return result;
		} catch (RuntimeException re) {
			log.error("merge failed", re);
			throw re;
		}
	}

	public Amortizacion findById(es.dalocar.software.AmortizacionId id) {
		log.debug("getting Amortizacion instance with id: " + id);
		try {
			Amortizacion instance = (Amortizacion) sessionFactory
					.getCurrentSession().get(
							"es.dalocar.software.Amortizacion", 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<Amortizacion> findByExample(Amortizacion instance) {
		log.debug("finding Amortizacion instance by example");
		try {
			List<Amortizacion> results = (List<Amortizacion>) sessionFactory
					.getCurrentSession().createCriteria(
							"es.dalocar.software.Amortizacion").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;
		}
	}
}
