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

📄 usertabledao.java

📁 一个ssh的网上购物系统
💻 JAVA
字号:
package com.xfaccp.bookonline.hib.dao;

import java.util.List;
import java.util.Set;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.criterion.Example;

import com.xfaccp.bookonline.hib.dao.base.BaseHibernateDAO;
import com.xfaccp.bookonline.hib.dto.UserTable;

/**
 * Data access object (DAO) for domain model class UserTable.
 * 
 * @see com.xfaccp.bookonline.hib.dto.UserTable
 * @author MyEclipse - Hibernate Tools
 */
public class UserTableDAO extends BaseHibernateDAO {

	private static final Log log = LogFactory.getLog(UserTableDAO.class);

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

	public static final String USERPASSWORD = "userpassword";

	public static final String USERSEX = "usersex";

	public static final String USERAGE = "userage";

	public UserTable findById(java.lang.Integer id) {
		log.debug("getting UserTable instance with id: " + id);
		Session session = this.getSession();
		try {
			UserTable instance = (UserTable) session.get(
					"com.xfaccp.bookonline.hib.dto.UserTable", id);
			return instance;
		} catch (RuntimeException re) {
			log.error("get failed", re);
			throw re;
		} finally {
			session.close();
		}
	}

	public List findByUserNameAndPwd(String username, String userpassword) {
		Session session = this.getSession();
		try {
			Query query = session
					.createQuery("from UserTable as c where c.username=? and c.userpassword=?");
			query.setString(0, username);
			query.setString(1, userpassword);
			List list = query.list();
			return list;
		} catch (Exception ex) {
			ex.printStackTrace();
		} finally {
			session.close();
		}
		return null;
	}

	public List findByExample(UserTable instance) {
		log.debug("finding UserTable instance by example");

		Session session = this.getSession();
		try {
			List results = session.createCriteria(
					"com.xfaccp.bookonline.hib.dto.UserTable").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;
		} finally {
			session.close();
		}
	}

	public List findByProperty(String propertyName, Object value) {
		log.debug("finding UserTable instance with property: " + propertyName
				+ ", value: " + value);
		Session session = this.getSession();
		try {
			String queryString = "from UserTable 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;
		} finally {
			session.close();
		}
	}

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

	public List findByUserpassword(Object userpassword) {
		return findByProperty(USERPASSWORD, userpassword);
	}

	public List findByUsersex(Object usersex) {
		return findByProperty(USERSEX, usersex);
	}

	public List findByUserage(Object userage) {
		return findByProperty(USERAGE, userage);
	}

}

⌨️ 快捷键说明

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