pmpuserdao.java

来自「一个实现struts+spring+hebernate的例子」· Java 代码 · 共 152 行

JAVA
152
字号
package springdao;

import java.util.List;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.LockMode;
import org.springframework.context.ApplicationContext;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

/**
 * Data access object (DAO) for domain model class Pmpuser.
 * 
 * @see springdao.Pmpuser
 * @author MyEclipse Persistence Tools
 */

public class PmpuserDAO extends HibernateDaoSupport {
	private static final Log log = LogFactory.getLog(PmpuserDAO.class);

	// property constants
	public static final String USERNAME = "username";

	public static final String PASSWORD = "password";

	public static final String AGE = "age";

	protected void initDao() {
		// do nothing
	}

	public void save(Pmpuser transientInstance) {
		log.debug("saving Pmpuser instance");
		try {
			getHibernateTemplate().save(transientInstance);
			log.debug("save successful");
		} catch (RuntimeException re) {
			log.error("save failed", re);
			throw re;
		}
	}

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

	public Pmpuser findById(java.lang.Integer id) {
		log.debug("getting Pmpuser instance with id: " + id);
		try {
			Pmpuser instance = (Pmpuser) getHibernateTemplate().get(
					"springdao.Pmpuser", id);
			return instance;
		} catch (RuntimeException re) {
			log.error("get failed", re);
			throw re;
		}
	}

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

	public List findByProperty(String propertyName, Object value) {
		log.debug("finding Pmpuser instance with property: " + propertyName
				+ ", value: " + value);
		try {
			String queryString = "from Pmpuser as model where model."
					+ propertyName + "= ?";
			return getHibernateTemplate().find(queryString, value);
		} catch (RuntimeException re) {
			log.error("find by property name failed", re);
			throw re;
		}
	}

	public List findByUsername(Object username) {
		return findByProperty(USERNAME, username);
	}

	public List findByPassword(Object password) {
		return findByProperty(PASSWORD, password);
	}

	public List findByAge(Object age) {
		return findByProperty(AGE, age);
	}

	public List findAll() {
		log.debug("finding all Pmpuser instances");
		try {
			String queryString = "from Pmpuser";
			return getHibernateTemplate().find(queryString);
		} catch (RuntimeException re) {
			log.error("find all failed", re);
			throw re;
		}
	}

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

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

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

	public static PmpuserDAO getFromApplicationContext(ApplicationContext ctx) {
		return (PmpuserDAO) ctx.getBean("PmpuserDAO");
	}
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?