unitdao.java

来自「用于银行全面掌控公司及各个部门的员工信息与设备资料」· Java 代码 · 共 151 行

JAVA
151
字号
package com.bank.hibernate.pojo;

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

/**
 * Data access object (DAO) for domain model class Unit.
 * 
 * @see com.bank.hibernate.pojo.Unit
 * @author MyEclipse Persistence Tools
 */

public class UnitDAO extends BaseHibernateDAO {
	private static final Log log = LogFactory.getLog(UnitDAO.class);
	// property constants
	public static final String UNIT_IDS = "unitIds";
	public static final String UNIT_NAME = "unitName";
	public static final String UNIT_UP = "unitUp";
	public static final String UNIT_EXPLAIN = "unitExplain";

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

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

	public Unit findById(java.lang.Integer id) {
		log.debug("getting Unit instance with id: " + id);
		try {
			Unit instance = (Unit) getSession().get(
					"com.bank.hibernate.pojo.Unit", id);
			return instance;
		} catch (RuntimeException re) {
			log.error("get failed", re);
			throw re;
		}
	}

	public List findByExample(Unit instance) {
		log.debug("finding Unit instance by example");
		try {
			List results = getSession().createCriteria(
					"com.bank.hibernate.pojo.Unit").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 Unit instance with property: " + propertyName
				+ ", value: " + value);
		try {
			String queryString = "from Unit 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 findByUnitIds(Object unitIds) {
		return findByProperty(UNIT_IDS, unitIds);
	}

	public List findByUnitName(Object unitName) {
		return findByProperty(UNIT_NAME, unitName);
	}

	public List findByUnitUp(Object unitUp) {
		return findByProperty(UNIT_UP, unitUp);
	}

	public List findByUnitExplain(Object unitExplain) {
		return findByProperty(UNIT_EXPLAIN, unitExplain);
	}

	public List findAll() {
		log.debug("finding all Unit instances");
		try {
			String queryString = "from Unit";
			Query queryObject = getSession().createQuery(queryString);
			return queryObject.list();
		} catch (RuntimeException re) {
			log.error("find all failed", re);
			throw re;
		}
	}

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

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

	public void attachClean(Unit instance) {
		log.debug("attaching clean Unit 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 + =
减小字号Ctrl + -
显示快捷键?