package fr.zng.xxzx.common.dao.impl;

import java.util.List;

import fr.zng.xxzx.common.dao.LockDao;
import fr.zng.xxzx.common.dao.base.BaseDao;
import fr.zng.xxzx.common.entity.LockEntity;
import fr.zng.xxzx.util.StringUtil;

public class LockDaoImpl extends BaseDao implements LockDao{

	public List<LockEntity> search(LockEntity en) {
		List<LockEntity> result = null;
		try {
			makeSession();
			result = session.selectList("Lock.search", en);
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			close();
		}
        return result;
	}

	public int getCount(LockEntity en) {
		Integer cnt = 0;
		try {
			makeSession();
			cnt = session.selectOne("Lock.getCount", en);
	        if (StringUtil.isEmpty(cnt)) {
	        	cnt = 0;
	        }
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			close();
		}
        return cnt;
	}

	public LockEntity getDetailByPk(String pk) {
		List<LockEntity> result = null;
		try {
			makeSession();
			result = session.selectList("Lock.getDetailByPk", pk);
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			close();
		}
		if(result.size()>0){
			return result.get(0);
		}else{
			return new LockEntity();
		}
	}

	@Override
	public int insert(LockEntity en) {
		int ret = 0;
		try {
			makeSession();
			ret = session.insert("Lock.insert", en);
			if(ret>0){
				session.commit();
			}else{
				session.rollback();
			}
		} catch (Exception e) {
			session.rollback();
			e.printStackTrace();
		} finally {
			close();
		}
        return ret;
	}

}
