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

📄 levelsdao.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.Levels;

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

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

	// property constants
	public static final String LEVELNAME = "levelname";

	public static final String PHOTO = "photo";

	public static final String DESCRIPTION = "description";

	private Session session = null;
	private Transaction transaction = null;
	
	public LevelsDAO() {
		session = getSession();
		transaction = session.beginTransaction();
	}
	
	public void save(Levels transientInstance) {
		log.debug("saving Levels 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(Levels persistentInstance) {
		log.debug("deleting Levels instance");
		try {
			session.delete(persistentInstance);
			log.debug("delete successful");
		} catch (RuntimeException re) {
			log.error("delete failed", re);
			throw re;
		}
	}

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

	public List findByExample(Levels instance) {
		log.debug("finding Levels instance by example");
		try {
			List results = session.createCriteria("tarena.entity.Levels")
					.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 Levels instance with property: " + propertyName
				+ ", value: " + value);
		try {
			String queryString = "from Levels 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 findByLevelname(Object levelname) {
		return findByProperty(LEVELNAME, levelname);
	}

	public List findByPhoto(Object photo) {
		return findByProperty(PHOTO, photo);
	}

	public List findByDescription(Object description) {
		return findByProperty(DESCRIPTION, description);
	}

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

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

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

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