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

📄 examroomdao.java

📁 数字校园 j2EE 有完整的说明 可直接用
💻 JAVA
字号:
package com.dcs.hibernate;

import java.util.List;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.LockMode;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.Transaction;
import org.hibernate.criterion.Example;

/**
 * Data access object (DAO) for domain model class ExamRoom.
 * 
 * @see com.dcs.hibernate.ExamRoom
 * @author MyEclipse - Hibernate Tools
 */
public class ExamRoomDAO extends BaseHibernateDAO {

	private static final Log log = LogFactory.getLog(ExamRoomDAO.class);

	// property constants
	public static final String EXAMROOM_TYPE = "examroomType";

	public void save(ExamRoom transientInstance) {
		log.debug("saving ExamRoom instance");
		Transaction transaction = null;
		Session session = getSession();
		try {
			transaction = session.beginTransaction();
			transaction.begin();
			session.save(transientInstance);
			log.debug("save successful");
			transaction.commit();
		} catch (RuntimeException re) {
			log.error("save failed", re);
			transaction.rollback();
			throw re;
		}
	}

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

	public ExamRoom findById(com.dcs.hibernate.ExamRoomId id) {
		log.debug("getting ExamRoom instance with id: " + id);
		try {
			ExamRoom instance = (ExamRoom) getSession().get(
					"com.dcs.hibernate.ExamRoom", id);
			return instance;
		} catch (RuntimeException re) {
			log.error("get failed", re);
			throw re;
		}
	}

	public List findByExample(ExamRoom instance) {
		log.debug("finding ExamRoom instance by example");
		try {
			List results = getSession().createCriteria(
					"com.dcs.hibernate.ExamRoom").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;
		}
	}

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

	public List findByExamroomType(Object examroomType) {
		return findByProperty(EXAMROOM_TYPE, examroomType);
	}

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

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

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

⌨️ 快捷键说明

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