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

📄 adminimpl.java

📁 野蔷薇论坛源码 java 自己看看吧。 学习用
💻 JAVA
字号:
/* 
 * Created on 2007-3-11
 * Last modified on 2007-3-11
 * Powered by YeQiangWei.com
 */
package com.yeqiangwei.club.dao.hibernate.impl;

import java.util.List;

import org.hibernate.HibernateException;

import com.yeqiangwei.club.dao.AdminDAO;
import com.yeqiangwei.club.dao.hibernate.support.HibernateFacade;
import com.yeqiangwei.club.dao.hibernate.support.HibernateProvider;
import com.yeqiangwei.club.dao.model.Admin;
import com.yeqiangwei.club.exception.DAOException;
import com.yeqiangwei.club.param.AdminParameter;

public class AdminImpl implements AdminDAO {
	
	private static final String FIND_USERNAME_PASSWORD = "from Admin where userName=? and password=?";
	
	private static final String FIND_USERNAME = "from Admin where userName=?";
	
	private static final String FIND_ADMINID = "from Admin where adminId=?";
	
	private static final String DELETE_ADMINID = "delete from Admin where adminId=?";
	
	private static final String DELETES_ADMINID = "delete from Admin where adminId in (:ids)";

	public void create(Admin item) throws DAOException {
		HibernateProvider<Admin> facade = new HibernateFacade<Admin>();
		try{
			facade.save(item);
		}catch(HibernateException e){
			throw new DAOException(e);
		}
	}

	public void update(Admin item) throws DAOException {
		HibernateProvider<Admin> facade = new HibernateFacade<Admin>();
		try{
			facade.update(item);
		}catch(HibernateException e){
			throw new DAOException(e);
		}
	}

	public int delete(Admin item) throws DAOException {
		HibernateProvider<Admin> facade = new HibernateFacade<Admin>();
		facade.createQuery(DELETE_ADMINID);
		facade.setInt(0, item.getAdminId());
		try{
			return facade.executeUpdate();
		}catch(HibernateException e){
			throw new DAOException(e);
		}
	}

	public int delete(List<Integer> ids) throws DAOException {
		HibernateProvider<Admin> facade = new HibernateFacade<Admin>();
		facade.createQuery(DELETES_ADMINID);
		facade.setParameterList("ids", ids);
		try{
			return facade.executeUpdate();
		}catch(HibernateException e){
			throw new DAOException(e);
		}
	}

	public Admin findById(int id) {
		HibernateProvider<Admin> facade = new HibernateFacade<Admin>();
		facade.createQuery(FIND_ADMINID);
		facade.setInt(0, id);
		facade.setMaxResults(1);
		return facade.uniqueResult();
	}

	public List<Admin> findByParameter(AdminParameter param){
		StringBuffer hql = new StringBuffer();
		hql.append("from Admin order by adminId desc ");
		HibernateProvider<Admin> facade = new HibernateFacade<Admin>();
		//facade.setFirstResult(param.getPagination().getStartRow());
		//facade.setMaxResults(param.getPagination().getPage());
		facade.createQuery(hql);
		return facade.executeQuery();
	}

	public Admin findByUserNameAndPassword(String userName, String password)
	{
		HibernateProvider<Admin> facade = new HibernateFacade<Admin>();
		facade.createQuery(FIND_USERNAME_PASSWORD);
		facade.setString(0,userName);
		facade.setString(1,password);
		facade.setMaxResults(1);
		return facade.uniqueResult();
	}

	public Admin findByUserName(String userName)
	{
		HibernateProvider<Admin> facade = new HibernateFacade<Admin>();
		facade.createQuery(FIND_USERNAME);
		facade.setString(0,userName);
		facade.setMaxResults(1);
		return facade.uniqueResult();
	}
	
	public long countByParameter(AdminParameter param){
		StringBuffer hql = new StringBuffer();
		hql.append("select count(adminId) from Admin");
		HibernateProvider<Admin> facade = new HibernateFacade<Admin>();
		facade.createQuery(hql);
		return facade.resultTotal();
	}

	public List<Admin> findAll(AdminParameter param) {
		return null;
	}

	public long countAll(AdminParameter param) {
		return 0;
	}

}

⌨️ 快捷键说明

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