package hibr;

import java.util.List;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.LockMode;
import org.hibernate.Query;
import org.hibernate.criterion.Example;

/**
 * Data access object (DAO) for domain model class Client.
 * 
 * @see hibr.Client
 * @author MyEclipse Persistence Tools
 */

public class ClientDAO extends BaseHibernateDAO {
	private static final Log log = LogFactory.getLog(ClientDAO.class);

	// property constants
	public static final String CNAME = "cname";

	public static final String CORP = "corp";

	public static final String ADDRESS = "address";

	public static final String TEL = "tel";

	public static final String FAX = "fax";

	public static final String EMAIL = "email";

	public boolean save(Client transientInstance) {
		log.debug("saving Client instance");
		try {
			getSession().save(transientInstance);
			log.debug("save successful");
			return true;
		} catch (RuntimeException re) {
			log.error("save failed", re);
			return false;
		}
	}
	

	public void delete(Client persistentInstance) {
		log.debug("deleting Client instance");
		try {
			getSession().delete(persistentInstance);
			log.debug("delete successful");
		} catch (RuntimeException re) {
			log.error("delete failed", re);
			throw re;
		}
	}

	public Client findById(java.lang.Integer id) {
		log.debug("getting Client instance with id: " + id);
		try {
			Client instance = (Client) getSession().get("hibr.Client", id);
			return instance;
		} catch (RuntimeException re) {
			log.error("get failed", re);
			throw re;
		}
	}

	public List findByExample(Client instance) {
		log.debug("finding Client instance by example");
		try {
			List results = getSession().createCriteria("hibr.Client").add(
					Example.create(instance)).list();
			log.debug("find by example successful, result size: "
					+ results.size());
			return results;
		} catch (RuntimeException re) {
			log.error("find by example failed", re);
			throw re;
		}
	}

	public List findByProperty(String propertyName, Object value) {
		log.debug("finding Client instance with property: " + propertyName
				+ ", value: " + value);
		try {
			String queryString = "from Client as model where model."
					+ propertyName + "= ?";
			Query queryObject = getSession().createQuery(queryString);
			queryObject.setParameter(0, value);
			return queryObject.list();
		} catch (RuntimeException re) {
			log.error("find by property name failed", re);
			throw re;
		}
	}

	public List findByCname(Object cname) {
		return findByProperty(CNAME, cname);
	}

	public List findByCorp(Object corp) {
		return findByProperty(CORP, corp);
	}

	public List findByAddress(Object address) {
		return findByProperty(ADDRESS, address);
	}

	public List findByTel(Object tel) {
		return findByProperty(TEL, tel);
	}

	public List findByFax(Object fax) {
		return findByProperty(FAX, fax);
	}

	public List findByEmail(Object email) {
		return findByProperty(EMAIL, email);
	}

	public List findAll() {
		log.debug("finding all Client instances");
		try {
			String queryString = "from Client";
			Query queryObject = getSession().createQuery(queryString);
			return queryObject.list();
		} catch (RuntimeException re) {
			log.error("find all failed", re);
			throw re;
		}
	}

	public boolean merge(Client detachedInstance) {
		log.debug("merging Client instance");
		try {
			Client result = (Client) getSession().merge(detachedInstance);
			log.debug("merge successful");
			
			return true;
			
		} catch (RuntimeException re) {
			log.error("merge failed", re);
			return false;
		}
	}

	public void attachDirty(Client instance) {
		log.debug("attaching dirty Client instance");
		try {
			getSession().saveOrUpdate(instance);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}

	public void attachClean(Client instance) {
		log.debug("attaching clean Client instance");
		try {
			getSession().lock(instance, LockMode.NONE);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}
	public List allpage(int currpage)
	{
		String querystring = "from Client";
		Query queryobj =getSession().createQuery(querystring);
		queryobj.setFirstResult((currpage-1)*4);
		queryobj.setMaxResults(4);
		return queryobj.list();
	}
	public int count()
	{
		String querystring="from Client";
	    Query	queryobj =getSession().createQuery(querystring);
	    return queryobj.list().size();
	}
}
最近下载更多
微信网友_6403021990891520  LV1 2023年3月24日
17330686178  LV1 2022年12月1日
地上有草  LV12 2022年5月11日
Jeasonchan898  LV2 2022年4月26日
ForestStone  LV2 2022年4月25日
isfrand  LV4 2022年4月18日
1532593037  LV8 2022年3月31日
and123456  LV11 2022年2月7日
七七qqqq25055  LV1 2021年11月23日
zww1223  LV4 2021年9月1日
最近浏览更多
floweyws  LV6 3月25日
kaye7549317 3月18日
暂无贡献等级
2010160433  LV3 3月9日
WBelong  LV7 2023年12月25日
haha不会 2023年12月12日
暂无贡献等级
草帽小小鸡  LV7 2023年11月26日
Henew168  LV2 2023年11月19日
政政123456  LV3 2023年10月22日
wankongs 2023年9月19日
暂无贡献等级
  LV8 2023年9月8日
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友