articledao.java

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

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

import java.util.Date;
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.criterion.Example;

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

public class ArticleDAO extends BaseHibernateDAO {
	private static final Log log = LogFactory.getLog(ArticleDAO.class);
	// property constants
	public static final String ART_TITLE = "artTitle";
	public static final String ART_TITLES = "artTitles";
	public static final String ART_BRIEF = "artBrief";
	public static final String ART_AUTHOR_ID = "artAuthorId";
	public static final String ART_AUTHOR_NAME = "artAuthorName";
	public static final String ART_CONTENT = "artContent";

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

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

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

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

	public List findByArtTitles(Object artTitles) {
		return findByProperty(ART_TITLES, artTitles);
	}

	public List findByArtBrief(Object artBrief) {
		return findByProperty(ART_BRIEF, artBrief);
	}

	public List findByArtAuthorId(Object artAuthorId) {
		return findByProperty(ART_AUTHOR_ID, artAuthorId);
	}

	public List findByArtAuthorName(Object artAuthorName) {
		return findByProperty(ART_AUTHOR_NAME, artAuthorName);
	}

	public List findByArtContent(Object artContent) {
		return findByProperty(ART_CONTENT, artContent);
	}

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

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

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

	public void attachClean(Article instance) {
		log.debug("attaching clean Article 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 + -
显示快捷键?