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

📄 announcedao.java

📁 基于struts+hibernate的电子商务网站。可运行。数据库mysql
💻 JAVA
字号:
package tarena.dao;

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;

import tarena.entity.Announce;

/**
 * Data access object (DAO) for domain model class Announce.
 * 
 * @see tarena.entity.Announce
 * @author MyEclipse Persistence Tools
 */

public class AnnounceDAO extends BaseHibernateDAO {
	private static final Log log = LogFactory.getLog(AnnounceDAO.class);

	// property constants
	public static final String USERNAME = "username";

	public static final String ATYPE = "atype";

	public static final String TITLE = "title";

	public static final String CONTENT = "content";
	
	private Session session = null;
	private Transaction transaction = null;
	
	public AnnounceDAO() {
		session = getSession();
		transaction = session.beginTransaction();
	}

	public void save(Announce transientInstance) {
		log.debug("saving Announce instance");
		try {
			transaction.begin();
			session.save(transientInstance);
			transaction.commit();
			log.debug("save successful");
		} catch (RuntimeException re) {
			log.error("save failed", re);
			throw re;
		}
	}

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

	public Announce findById(java.lang.Integer id) {
		log.debug("getting Announce instance with id: " + id);
		try {
			Announce instance = (Announce) session.get(
					"tarena.entity.Announce", id);
			return instance;
		} catch (RuntimeException re) {
			log.error("get failed", re);
			throw re;
		}
	}

	public List findByExample(Announce instance) {
		log.debug("finding Announce instance by example");
		try {
			List results = session
					.createCriteria("tarena.entity.Announce").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 Announce instance with property: " + propertyName
				+ ", value: " + value);
		try {
			String queryString = "from Announce as model where model."
					+ propertyName + "= ?";
			Query queryObject = session.createQuery(queryString);
			queryObject.setParameter(0, value);
			return queryObject.list();
		} catch (RuntimeException re) {
			log.error("find by property name failed", re);
			throw re;
		}
	}

	public List findByUsername(Object username) {
		return findByProperty(USERNAME, username);
	}

	public List findByAtype(Object atype) {
		return findByProperty(ATYPE, atype);
	}

	public List findByTitle(Object title) {
		return findByProperty(TITLE, title);
	}

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

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

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

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

	public void attachClean(Announce instance) {
		log.debug("attaching clean Announce instance");
		try {
			session.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 + -