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

📄 storydao.java

📁 在线书库系统 查看图书 编写文章 管理员管理
💻 JAVA
字号:
package StoryManage.Dal;

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.springframework.context.ApplicationContext;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

/**
 * A data access object (DAO) providing persistence and search support for Story
 * 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 StoryManage.Dal.Story
 * @author MyEclipse Persistence Tools
 */

public class StoryDAO extends HibernateDaoSupport {
	private static final Log log = LogFactory.getLog(StoryDAO.class);
	// property constants
	public static final String STORY_TITLE = "storyTitle";
	public static final String CONTENT = "content";
	public static final String WRITER_ID = "writerId";
	public static final String TYPE_ID = "typeId";
	public static final String IMAGE_URL = "imageUrl";
	public static final String HOT = "hot";
	public static final String VOTE = "vote";
	public static final String FIRST_CHAPTER_ID = "firstChapterId";
	public static final String DAY_HOT = "dayHot";
	public static final String WEEK_HOT = "weekHot";
	public static final String MONTH_HOT = "monthHot";
	public static final String IS_OVER = "isOver";

	protected void initDao() {
		// do nothing
	}

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

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

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

	public List findByExample(Story instance) {
		log.debug("finding Story 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 Story instance with property: " + propertyName
				+ ", value: " + value);
		try {
			String queryString = "from Story 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 findByStoryTitle(Object storyTitle) {
		return findByProperty(STORY_TITLE, storyTitle);
	}

	public List findByContent(Object content) {
		return findByProperty(CONTENT, content);
	}

	public List findByWriterId(Object writerId) {
		return findByProperty(WRITER_ID, writerId);
	}

	public List findByTypeId(Object typeId) {
		return findByProperty(TYPE_ID, typeId);
	}

	public List findByImageUrl(Object imageUrl) {
		return findByProperty(IMAGE_URL, imageUrl);
	}

	public List findByHot(Object hot) {
		return findByProperty(HOT, hot);
	}

	public List findByVote(Object vote) {
		return findByProperty(VOTE, vote);
	}

	public List findByFirstChapterId(Object firstChapterId) {
		return findByProperty(FIRST_CHAPTER_ID, firstChapterId);
	}

	public List findByDayHot(Object dayHot) {
		return findByProperty(DAY_HOT, dayHot);
	}

	public List findByWeekHot(Object weekHot) {
		return findByProperty(WEEK_HOT, weekHot);
	}

	public List findByMonthHot(Object monthHot) {
		return findByProperty(MONTH_HOT, monthHot);
	}

	public List findByIsOver(Object isOver) {
		return findByProperty(IS_OVER, isOver);
	}

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

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

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

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

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

⌨️ 快捷键说明

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