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

📄 springcommondao.java

📁 权限组件的java代码写法例子下载
💻 JAVA
字号:
package com.parddu.crm.pers.hibeimpl;

import java.io.Serializable;
import java.util.Iterator;
import java.util.List;

import org.hibernate.Query;
import org.hibernate.SQLQuery;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import com.parddu.crm.pers.IcommonDAO;
import com.parddu.crm.util.Page;

public class SpringCommonDAO extends HibernateDaoSupport implements IcommonDAO {

	public boolean delete(Object obj) throws Exception {
		super.getHibernateTemplate().delete(obj);
		return true;
	}

	public boolean deleteById(Class cla, Serializable id) throws Exception {
		super.getHibernateTemplate().delete(this.queryById(cla, id));
		return true;
	}

	public boolean insert(Object obj) throws Exception {
		super.getHibernateTemplate().save(obj);
		return true;
	}

	public Object queryById(Class cla, Serializable id) throws Exception {
		return super.getHibernateTemplate().get(cla, id);
	}

	public List queryByProperty(Class cla, String property, Object value)
			throws Exception {
		// TODO Auto-generated method stub
		return null;
	}

	public List queryHQL(String hql, List param) throws Exception {
		Query q = super.getSession().createQuery(hql);
		this.setParameter(q, param);
		return q.list();
	}

	public List queryPageHQL(String hql, List param, Page p) throws Exception {
		Query q = super.getSession().createQuery(hql);
		this.setParameter(q, param);
		q.setFirstResult((p.getPageIndex()-1)*p.getPageNumber());
		q.setMaxResults(p.getPageNumber());
		return q.list();
	}

	public List queryPageSQL(String sql, List param, Page p) throws Exception {
		SQLQuery q = super.getSession().createSQLQuery(sql);
		this.setParameter(q, param);
		q.setFirstResult((p.getPageIndex()-1)*p.getPageNumber());
		q.setMaxResults(p.getPageNumber());
		return q.list();
	}

	public List querySQL(String sql, List param) throws Exception {
		SQLQuery q = super.getSession().createSQLQuery(sql);
		this.setParameter(q, param);
		return q.list();
	}

	public boolean update(Object obj) throws Exception {
		super.getHibernateTemplate().update(obj);
		return true;
	}

	public int updateHQL(String ql, List param) throws Exception {
		Query q = super.getSession().createQuery(ql);
		this.setParameter(q, param);
		return q.executeUpdate();
	}

	public int updateSQL(String ql, List param) throws Exception {
		SQLQuery q = super.getSession().createSQLQuery(ql);
		this.setParameter(q, param);
		return q.executeUpdate();
	}

	private void setParameter(Query q,List param){
		if(param!=null && param.size()>0){
			for(int i=0;i<param.size();i++){
				q.setParameter(i, param.get(i));
			}
		}
	}

}

⌨️ 快捷键说明

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