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