Ver Mensaje Individual
  #1 (permalink)  
Antiguo 21/01/2007, 11:32
solyluna
 
Fecha de Ingreso: enero-2007
Mensajes: 156
Antigüedad: 17 años, 4 meses
Puntos: 1
Pregunta Interface

Hola, estoy hcaiendo algunas pruebas de acceso a una base de datos de mySQL, y eclipse me ha genrado el código automáticamente.

El caso es que me declara un atributo de tipo org.apache.commons.logging.Log, he estado mirando el api en internet pero mi ingles no es del todo bueno y no me queda muy claro que es lo que hace este interface.

¿Alguna ayuda? Pongo el código generado para que lo veais.

Código:
package example.hibernate;

// Generated 21-ene-2007 17:25:15 by Hibernate Tools 3.2.0.beta8

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

/**
 * Home object for domain model class Person.
 * @see example.hibernate.Person
 * @author Hibernate Tools
 */
public class PersonHome {

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

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

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

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

	public Person findById(int id) {
		log.debug("getting Person instance with id: " + id);
		try {
			Person instance = (Person) sessionFactory.getCurrentSession().get(
					"example.Person", 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 findByExample(Person instance) {
		log.debug("finding Person instance by example");
		try {
			List results = sessionFactory.getCurrentSession().createCriteria(
					"example.Person").add(Example.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;
		}
	}
}
Muchas gracias.
Saludos