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

📄 treedao.java

📁 dtree 是java编程的树形菜单。。我做的一个例子可也动态连接数据库
💻 JAVA
字号:
package com.kongnan.bean;

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;

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

public class TreeDAO extends BaseHibernateDAO {
	private static final Log log = LogFactory.getLog(TreeDAO.class);
	// property constants
	public static final String PID = "pid";
	public static final String NAME = "name";
	public static final String URL = "url";
	public static final String TITLE = "title";
	public static final String TARGET = "target";
	public static final String ICON = "icon";
	public static final String ICONOPEN = "iconopen";
	public static final String OPENED = "opened";

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

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

	public Tree findById(java.lang.String id) {
		log.debug("getting Tree instance with id: " + id);
		try {
			Tree instance = (Tree) getSession()
					.get("com.kongnan.bean.Tree", id);
			return instance;
		} catch (RuntimeException re) {
			log.error("get failed", re);
			throw re;
		}
	}

	public List findByExample(Tree instance) {
		log.debug("finding Tree instance by example");
		try {
			List results = getSession().createCriteria("com.kongnan.bean.Tree")
					.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 Tree instance with property: " + propertyName
				+ ", value: " + value);
		try {
			String queryString = "from Tree 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 findByPid(Object pid) {
		return findByProperty(PID, pid);
	}

	public List findByName(Object name) {
		return findByProperty(NAME, name);
	}

	public List findByUrl(Object url) {
		return findByProperty(URL, url);
	}

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

	public List findByTarget(Object target) {
		return findByProperty(TARGET, target);
	}

	public List findByIcon(Object icon) {
		return findByProperty(ICON, icon);
	}

	public List findByIconopen(Object iconopen) {
		return findByProperty(ICONOPEN, iconopen);
	}

	public List findByOpened(Object opened) {
		return findByProperty(OPENED, opened);
	}

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

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

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

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