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

📄 admindaoimpl.java

📁 该程序能够准确的记录互联网用户上网所用的流量
💻 JAVA
字号:
package com.briup.admin.dao.impl;import java.util.Date;import java.util.List;import org.hibernate.Query;import org.hibernate.Session;import org.springframework.orm.hibernate3.HibernateTemplate;import com.briup.admin.dao.IAdminDao;import com.briup.common.dao.pojo.Admin;import com.briup.common.dao.pojo.Product;import com.briup.common.dao.pojo.ProductType;import com.briup.common.dao.pojo.Role;import com.briup.common.util.DateUtil;public class AdminDaoImpl extends HibernateTemplate implements IAdminDao {	// 所有品牌查询	public List findProducts(int start, int num) throws Exception {		// TODO Auto-generated method stub		Session session = this.getSession();		Query sql = session.createQuery("from Product");		sql.setFirstResult(start);		sql.setMaxResults(num);		List list = sql.list();		return list;	}	// 品牌总数	public Integer findProducts() throws Exception {		// TODO Auto-generated method stub		Session session = this.getSession();		Query sql = session.createQuery("from Product");		List list = sql.list();		return list.size();	}	public ProductType findProductTypeById(Long id) throws Exception {		// TODO Auto-generated method stub		Session session = this.getSession();		Query sql = session.createQuery("from ProductType where id=?");		sql.setLong(0, id);		return (ProductType) sql.uniqueResult();	}	public void save(Product pro) throws Exception {		// TODO Auto-generated method stub		Session session = this.getSession();		session.saveOrUpdate(pro);	}	public void deleteProduct(Product pro) throws Exception {		// TODO Auto-generated method stub		Session session = this.getSession();		session.delete(pro);	}	public Product findProduct(String name) {		Session session = this.getSession();		Query sql = session.createQuery("from Product where name=?");		sql.setString(0, name);		return (Product) sql.uniqueResult();	}	public List findAdmins(int start, int num) throws Exception {		// TODO Auto-generated method stub		Session session = this.getSession();		Query sql = session.createQuery("from Admin");		sql.setFirstResult(start);		sql.setMaxResults(num);		List list = sql.list();		return list;	}	public Integer findAdmins() throws Exception {		// TODO Auto-generated method stub		Session session = this.getSession();		Query sql = session.createQuery("from Admin");		return sql.list().size();	}	public void deleteAdmin(Admin admin) throws Exception {		// TODO Auto-generated method stub		Session session = this.getSession();		session.delete(admin);	}	public Admin findAdmin(String name) throws Exception {		// TODO Auto-generated method stub		Session session = this.getSession();		Query sql = session.createQuery("from Admin where loginName=?");		sql.setString(0, name);		return (Admin) sql.uniqueResult();	}	public Role findRole(Long roleId) throws Exception {		// TODO Auto-generated method stub		Session session = this.getSession();		Query sql = session.createQuery("from Role where id=?");		sql.setLong(0, roleId);		return (Role) sql.uniqueResult();	}	public void saveAdmin(Admin admin) throws Exception {		// TODO Auto-generated method stub		Session session = this.getSession();		session.saveOrUpdate(admin);	}	public void UpdateAdmin(Admin admin) throws Exception {		// TODO Auto-generated method stub		Session session = this.getSession();		session.update(admin);	}	public void UpdateProduct(Product pro) throws Exception {		// TODO Auto-generated method stub		Session session = this.getSession();		session.update(pro);	}	public List findProductType() throws Exception {		// TODO Auto-generated method stub		Session session = this.getSession();		Query sql = session.createQuery("from ProductType");		List list = sql.list();		return list;	}	public List findRole() throws Exception {		// TODO Auto-generated method stub		Session session = this.getSession();		Query sql = session.createQuery("from Role");		List list = sql.list();		return list;	}	public List findAdminByConditions(String[] conditions, int start, int num)			throws Exception {		String realName = conditions[0];		String loginName = conditions[1];		String address = conditions[2];		String startDate = conditions[3];		String endDate = conditions[4];		String role = conditions[5];		String orderby = conditions[6];		String desc = conditions[7];		StringBuffer hql = new StringBuffer();		boolean flag = false;		if (!realName.equals("")) {			hql.append(" a.realName=:realName");			flag = true;		}		if (!loginName.equals("")) {			if (flag)				hql.append(" and");			hql.append(" a.loginName=:loginName");			flag = true;		}		if (!address.equals("")) {			if (flag)				hql.append(" and");			hql.append(" a.address=:address");			flag = true;		}		if (!startDate.equals("")) {			if (flag)				hql.append(" and");			hql.append(" a.registerDate>:startDate");			flag = true;		}		if (!endDate.equals("")) {			if (flag)				hql.append(" and");			hql.append(" a.registerDate<:endDate");			flag = true;		}		if (!role.equals("")) {			if (flag)				hql.append(" and");			hql.append(" a.role.id=:role");			flag = true;		}		if (!role.equals("")) {			if (flag)				hql.append(" and");			hql.append(" order by :orderby");			flag = true;		}		if (!desc.equals("")) {			if (flag)				hql.append(" and");			hql.append(" :desc");			flag = true;		}		String fromClause = flag ? "from Admin a where" : "from Admin";		hql.insert(0, fromClause);		Session session = this.getSession();		Query sql = session.createQuery(hql.toString());		if (!realName.equals("")) {			sql.setString("realName", realName);		}		if (!loginName.equals("")) {			sql.setString("loginName", loginName);		}		if (!address.equals("")) {			sql.setString("address", address);		}		if (!startDate.equals("")) {			Date startdate = DateUtil.parseDate(startDate, "yyyy-MM-dd");			sql.setDate("startDate", startdate);		}		if (!endDate.equals("")) {			Date enddate = DateUtil.parseDate(endDate, "yyyy-MM-dd");			sql.setDate("endDate", enddate);		}		if (!role.equals("")) {			Long id = Long.parseLong(role);			sql.setLong("role", id);		}		if (!orderby.equals("")) {			sql.setString("orderby", orderby);		}		if (!desc.equals("")) {			sql.setString("desc", desc);		}		sql.setFirstResult(start);		sql.setMaxResults(num);		return sql.list();	}	public Integer findNumByConditions(String[] conditions) throws Exception {		String realName = conditions[0];		String loginName = conditions[1];		String address = conditions[2];		String startDate = conditions[3];		String endDate = conditions[4];		String role = conditions[5];		String orderby = conditions[6];		String desc = conditions[7];		StringBuffer hql = new StringBuffer();		boolean flag = false;		if (!realName.equals("")) {			hql.append(" a.realName=:realName");			flag = true;		}		if (!loginName.equals("")) {			if (flag)				hql.append(" and");			hql.append(" a.loginName=:loginName");			flag = true;		}		if (!address.equals("")) {			if (flag)				hql.append(" and");			hql.append(" a.address=:address");			flag = true;		}		if (!startDate.equals("")) {			if (flag)				hql.append(" and");			hql.append(" a.registerDate>:startDate");			flag = true;		}		if (!endDate.equals("")) {			if (flag)				hql.append(" and");			hql.append(" a.registerDate<:endDate");			flag = true;		}		if (!role.equals("")) {			if (flag)				hql.append(" and");			hql.append(" a.role.id=:role");			flag = true;		}		if (!role.equals("")) {			if (flag)				hql.append(" and");			hql.append(" order by :orderby");			flag = true;		}		if (!desc.equals("")) {			if (flag)				hql.append(" and");			hql.append(" :desc");			flag = true;		}		String fromClause = flag ? "from Admin a where" : "from Admin";		hql.insert(0, fromClause);		Session session = this.getSession();		Query sql = session.createQuery(hql.toString());		if (!realName.equals("")) {			sql.setString("realName", realName);		}		if (!loginName.equals("")) {			sql.setString("loginName", loginName);		}		if (!address.equals("")) {			sql.setString("address", address);		}		if (!startDate.equals("")) {			Date startdate = DateUtil.parseDate(startDate, "yyyy-MM-dd");			sql.setDate("startDate", startdate);		}		if (!endDate.equals("")) {			Date enddate = DateUtil.parseDate(endDate, "yyyy-MM-dd");			sql.setDate("endDate", enddate);		}		if (!role.equals("")) {			Long id = Long.parseLong(role);			sql.setLong("role", id);		}		if (!orderby.equals("")) {			sql.setString("orderby", orderby);		}		if (!desc.equals("")) {			sql.setString("desc", desc);		}		return sql.list().size();	}		public List getAllRoles() throws Exception {		List<Role> roles = null;		String hql = "from Role";		roles = super.find(hql);		return roles;	}}

⌨️ 快捷键说明

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