package com.szpg.db.dao.impl;

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

import org.apache.commons.dbutils.DbUtils;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanListHandler;
import org.apache.log4j.Logger;

import com.szpg.db.dao.PgHjsbblDao;
import com.szpg.db.data.PgHjsbbl;
import com.szpg.db.util.ConnectionManager;

public class PgHjsbblDaoImpl implements PgHjsbblDao {
	
	private final Logger logger = Logger.getLogger(this.getClass().getName());

	@Override
	public PgHjsbbl findBlByBh(String blbh) {
		Connection conn = null;
		
		String queryStr = "SELECT * FROM PG_HJSBBL WHERE BLBH = ?";
		Object[] param = new Object[1];
		param[0] = blbh;
		
		try {
			conn = ConnectionManager.getConnectionFromC3P0();
			conn.setAutoCommit(false);
			
			QueryRunner runner = new QueryRunner();
			List<PgHjsbbl> list = (List<PgHjsbbl>) runner.query(conn, queryStr, new BeanListHandler<PgHjsbbl>(PgHjsbbl.class), param);
			
			if (null != list && list.size() == 1) {
				logger.debug("根据编号查询变量成功[" + list.size() + "]");
				
				return list.get(0);
			} else 
				return null;
		} catch (Exception ex) {
			logger.error("根据编号查询变量异常", ex);
		} finally {
			try {
				DbUtils.commitAndClose(conn);
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
		
		return null;
	}

}
