⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 studentdao.java

📁 通过此代码可实现 学生信息的增删改查
💻 JAVA
字号:
package com.jinshi.struts.dao.impl;

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;

import com.jinshi.struts.bean.Student;
import com.jinshi.struts.dao.IStudentDAO;

/**
 * A data access object (DAO) providing persistence and search support for
 * Student entities. Transaction control of the save(), update() and delete()
 * operations can directly support Spring container-managed transactions or they
 * can be augmented to handle user-managed Spring transactions. Each of these
 * methods provides additional information for how to configure it for the
 * desired type of transaction control.
 * 
 * @see com.jinshi.struts.bean.Student
 * @author MyEclipse Persistence Tools
 */

public class StudentDAO extends HibernateDaoSupport implements IStudentDAO {
	private static final Log log = LogFactory.getLog(StudentDAO.class);
	// property constants
	public static final String STUD_NAME = "studName";
	public static final String STUD_PWD = "studPwd";
	public static final String STUD_SEX = "studSex";
	public static final String STUD_AGE = "studAge";
	public static final String STUD_COL = "studCol";
	public static final String STUD_CLASS = "studClass";

	protected void initDao() {
		// do nothing
	}

	/* (non-Javadoc)
	 * @see com.jinshi.struts.dao.impl.IStudentDAO#save(com.jinshi.struts.bean.Student)
	 */
	public void save(Student transientInstance) {
		log.debug("saving Student instance");
		try {
			getHibernateTemplate().save(transientInstance);
			log.debug("save successful");
		} catch (RuntimeException re) {
			log.error("save failed", re);
			throw re;
		}
	}

	/* (non-Javadoc)
	 * @see com.jinshi.struts.dao.impl.IStudentDAO#delete(com.jinshi.struts.bean.Student)
	 */
	public void delete(Student persistentInstance) {
		log.debug("deleting Student instance");
		try {
			getHibernateTemplate().delete(persistentInstance);
			log.debug("delete successful");
		} catch (RuntimeException re) {
			log.error("delete failed", re);
			throw re;
		}
	}

	/* (non-Javadoc)
	 * @see com.jinshi.struts.dao.impl.IStudentDAO#findById(java.lang.Integer)
	 */
	public Student findById(java.lang.Integer id) {
		log.debug("getting Student instance with id: " + id);
		try {
			Student instance = (Student) getHibernateTemplate().get(
					"com.jinshi.struts.bean.Student", id);
			return instance;
		} catch (RuntimeException re) {
			log.error("get failed", re);
			throw re;
		}
	}

	/* (non-Javadoc)
	 * @see com.jinshi.struts.dao.impl.IStudentDAO#findByExample(com.jinshi.struts.bean.Student)
	 */
	public List findByExample(Student instance) {
		log.debug("finding Student 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;
		}
	}

	/* (non-Javadoc)
	 * @see com.jinshi.struts.dao.impl.IStudentDAO#findByProperty(java.lang.String, java.lang.Object)
	 */
	public List findByProperty(String propertyName, Object value) {
		log.debug("finding Student instance with property: " + propertyName
				+ ", value: " + value);
		try {
			String queryString = "from Student as model where model."
					+ propertyName + "= ?";
			return getHibernateTemplate().find(queryString, value);
		} catch (RuntimeException re) {
			log.error("find by property name failed", re);
			throw re;
		}
	}

	/* (non-Javadoc)
	 * @see com.jinshi.struts.dao.impl.IStudentDAO#findByStudName(java.lang.Object)
	 */
	public List findByStudName(Object studName) {
		return findByProperty(STUD_NAME, studName);
	}

	/* (non-Javadoc)
	 * @see com.jinshi.struts.dao.impl.IStudentDAO#findByStudPwd(java.lang.Object)
	 */
	public List findByStudPwd(Object studPwd) {
		return findByProperty(STUD_PWD, studPwd);
	}

	/* (non-Javadoc)
	 * @see com.jinshi.struts.dao.impl.IStudentDAO#findByStudSex(java.lang.Object)
	 */
	public List findByStudSex(Object studSex) {
		return findByProperty(STUD_SEX, studSex);
	}

	/* (non-Javadoc)
	 * @see com.jinshi.struts.dao.impl.IStudentDAO#findByStudAge(java.lang.Object)
	 */
	public List findByStudAge(Object studAge) {
		return findByProperty(STUD_AGE, studAge);
	}

	/* (non-Javadoc)
	 * @see com.jinshi.struts.dao.impl.IStudentDAO#findByStudCol(java.lang.Object)
	 */
	public List findByStudCol(Object studCol) {
		return findByProperty(STUD_COL, studCol);
	}

	/* (non-Javadoc)
	 * @see com.jinshi.struts.dao.impl.IStudentDAO#findByStudClass(java.lang.Object)
	 */
	public List findByStudClass(Object studClass) {
		return findByProperty(STUD_CLASS, studClass);
	}

	/* (non-Javadoc)
	 * @see com.jinshi.struts.dao.impl.IStudentDAO#findAll()
	 */
	public List findAll() {
		log.debug("finding all Student instances");
		try {
			String queryString = "from Student";
			return getHibernateTemplate().find(queryString);
		} catch (RuntimeException re) {
			log.error("find all failed", re);
			throw re;
		}
	}

	/* (non-Javadoc)
	 * @see com.jinshi.struts.dao.impl.IStudentDAO#merge(com.jinshi.struts.bean.Student)
	 */
	public Student merge(Student detachedInstance) {
		log.debug("merging Student instance");
		try {
			Student result = (Student) getHibernateTemplate().merge(
					detachedInstance);
			log.debug("merge successful");
			return result;
		} catch (RuntimeException re) {
			log.error("merge failed", re);
			throw re;
		}
	}

	/* (non-Javadoc)
	 * @see com.jinshi.struts.dao.impl.IStudentDAO#attachDirty(com.jinshi.struts.bean.Student)
	 */
	public void attachDirty(Student instance) {
		log.debug("attaching dirty Student instance");
		try {
			getHibernateTemplate().saveOrUpdate(instance);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}

	/* (non-Javadoc)
	 * @see com.jinshi.struts.dao.impl.IStudentDAO#attachClean(com.jinshi.struts.bean.Student)
	 */
	public void attachClean(Student instance) {
		log.debug("attaching clean Student instance");
		try {
			getHibernateTemplate().lock(instance, LockMode.NONE);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}

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

⌨️ 快捷键说明

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