YxySendMailDetailDaoImpl.java 4.8 KB
package com.espeed.dao.impl;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.util.List;

import org.hibernate.Session;
import org.hibernate.Transaction;

import com.espeed.dao.YxySendMailDetailDao;
import com.espeed.pojo.YxySendMailDetail;
import com.espeed.vo.PageBean;
/**
 * 程序名称:    	EspeedMail_时速邮箱
 * 程序版本:    	V1.0
 * 作    者:    	深圳市科飞时速网络技术有限公司(0755-88843776)
 * 版权所有:    	深圳市科飞时速网络技术有限公司
 * 技术支持:    	Tech@21gmail.com
 * 单元名称:     点读地址DAO实现类(营销游)
 * 开始时间:    	2013.12.09
 * 程 序 员:    	谢勇
 * 最后修改:    
 * 备    注:		如需修改请通知程序员    
 */
public class YxySendMailDetailDaoImpl extends HibernateBaseDAOImpl<YxySendMailDetail, Long> implements YxySendMailDetailDao{

	/**实体插入*/
	public int addPojo(YxySendMailDetail o)throws Exception{
		return super.add(o);
	}
	/**实体批量插入*/
	public void addPojoPi(List<YxySendMailDetail> list)throws Exception{
		if(list.size() > 500){
			Session session = super.getHibernateTemplate().getSessionFactory().openSession();
			Transaction tx=session.beginTransaction(); //注意用的是hibernate事务处理边界 
			Connection conn=session.connection();
			conn.setAutoCommit(false);
			String sql = "INSERT INTO yxy_send_mail_detail(send_mail_id,base_mail_id,receiver,email,email_suffix,variable,company_variable,loginid,domain) " +
					"VALUES(?,?,?,?,?,?,?,?,?)";
			PreparedStatement preparedStatement = conn.prepareStatement(sql);
			for(int i = 0; i < list.size(); i++){
				preparedStatement.setInt(1, list.get(i).getSend_mail_id());
				preparedStatement.setInt(2, list.get(i).getBase_mail_id());
	            preparedStatement.setString(3, list.get(i).getReceiver());
	            preparedStatement.setString(4, list.get(i).getEmail());
	            preparedStatement.setString(5, list.get(i).getEmail_suffix());
	            preparedStatement.setString(6, list.get(i).getVariable());
	            preparedStatement.setString(7, list.get(i).getCompany_variable());
	            preparedStatement.setString(8, list.get(i).getLoginid());
	            preparedStatement.setString(9, list.get(i).getDomain());
	            //"积攒" SQL 
	            preparedStatement.addBatch();
	            //当 "积攒" 到一定程度, 就统一的执行一次. 并且清空先前 "积攒" 的 SQL
	            if((i + 1) % 300 == 0){
	                preparedStatement.executeBatch();
                    conn.commit();
	                preparedStatement.clearBatch();
	            }
	        }
	        //若总条数不是批量数值的整数倍, 则还需要再额外的执行一次. 
	        if(list.size() % 300 != 0){
	            preparedStatement.executeBatch();
	            conn.commit();
	            preparedStatement.clearBatch();
	        }
			tx.commit(); //注意用的是hibernate事务处理边界
		}else{
			super.addPi(list);
		}
	}
	/**实体编辑*/
	public void updatePojo(YxySendMailDetail o)throws Exception{
		super.update(o);
	}
	/**HQL查询*/
	public List<YxySendMailDetail> findByHql(String hql)throws Exception{
		return super.getAll(hql);
	}
	/**指定条记录*/
	public List<YxySendMailDetail> findByHqlSet(String hql,int num)throws Exception{
		return super.findBySet(hql, num);
	}
	/**HQL查询分页*/
	public List<YxySendMailDetail> findByHqlPage(String hql,String hqlcount,PageBean pb)throws Exception{
		return super.findByPage(hql, hqlcount, pb);
	}
	/**SQL查询*/
	public List<Object> findBySqlQuery(String sql)throws Exception{
		return super.findBySql(sql);
	}
	/**HQL更新*/
	public void updateByHql(String hql)throws Exception{
		super.updateorDelByHql(hql);
	}
	/**HQL数量查询*/
	public int findByHqlCount(String hql)throws Exception{
		return super.count(hql);
	}
//	/**根据待发邮件ID查询待发地址*/
//	public List<YxySendMailDetail> findAddressByMailID(int mailID) throws Exception {
//		String hql="from YxySendMailDetail where send_mail_id="+mailID;
//		return super.getAll(hql);
//	}
//	/**修改此地址为已发送*/
//	public void updateMailDetailstatus(int addressID) throws Exception {
//		String hql="update YxySendMailDetail set status=1 where mail_id="+addressID;
//		super.updateorDelBySql(hql);
//	}
//	/**批量添加地址*/
//	public void addMailDetailPi(List<YxySendMailDetail> o) throws Exception {
//		super.addPi(o);
//	}
//	
//	/**根据待发邮件ID查询待发地址(基本表)*/
//	public List<YxySendMailDetail> findAddressBybaseMailID(int mailID)
//			throws Exception {
//		String hql="from YxySendMailDetail where base_mail_id="+mailID;
//		return super.getAll(hql);
//	}
//	/**根据邮件ID删除地址*/
//	public void delDetailByMailID(int mailID) throws Exception {
//		String sql="delete YxySendMailDetail where base_mail_id="+mailID;
//		super.updateorDelBySql(sql);
//		
//	}
}