waresdao.java
来自「一个很好的网上商城系统」· Java 代码 · 共 168 行
JAVA
168 行
package com.hb.shop.dao;
import java.util.Date;
import java.util.List;
import java.util.Set;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.LockMode;
import org.springframework.context.ApplicationContext;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
import com.hb.shop.model.Wares;
/**
* Data access object (DAO) for domain model class Wares.
*
* @see com.hb.shop.model.Wares
* @author MyEclipse Persistence Tools
*/
public class WaresDAO extends HibernateDaoSupport {
private static final Log log = LogFactory.getLog(WaresDAO.class);
// property constants
public static final String WARE_NAME = "wareName";
public static final String WARE_PRICE = "warePrice";
public static final String WARE_PHOTO = "warePhoto";
public static final String WARE_INFO = "wareInfo";
public static final String WARE_STATE = "wareState";
protected void initDao() {
// do nothing
}
public void save(Wares transientInstance) {
log.debug("saving Wares instance");
try {
getHibernateTemplate().save(transientInstance);
log.debug("save successful");
} catch (RuntimeException re) {
log.error("save failed", re);
throw re;
}
}
public void delete(Wares persistentInstance) {
log.debug("deleting Wares instance");
try {
getHibernateTemplate().delete(persistentInstance);
log.debug("delete successful");
} catch (RuntimeException re) {
log.error("delete failed", re);
throw re;
}
}
public Wares findById(java.lang.Integer id) {
log.debug("getting Wares instance with id: " + id);
try {
Wares instance = (Wares) getHibernateTemplate().get(
"com.hb.shop.model.Wares", id);
return instance;
} catch (RuntimeException re) {
log.error("get failed", re);
throw re;
}
}
public List findByExample(Wares instance) {
log.debug("finding Wares instance by example");
try {
List results = getHibernateTemplate().findByExample(instance);
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 Wares instance with property: " + propertyName
+ ", value: " + value);
try {
String queryString = "from Wares as model where model."
+ propertyName + " like ?";
return getHibernateTemplate().find(queryString, value);
} catch (RuntimeException re) {
log.error("find by property name failed", re);
throw re;
}
}
public List findByWareName(Object wareName) {
return findByProperty(WARE_NAME, wareName);
}
public List findByWarePrice(Object warePrice) {
return findByProperty(WARE_PRICE, warePrice);
}
public List findByWarePhoto(Object warePhoto) {
return findByProperty(WARE_PHOTO, warePhoto);
}
public List findByWareInfo(Object wareInfo) {
return findByProperty(WARE_INFO, wareInfo);
}
public List findByWareState(Object wareState) {
return findByProperty(WARE_STATE, wareState);
}
public List findAll() {
log.debug("finding all Wares instances");
try {
String queryString = "from Wares";
return getHibernateTemplate().find(queryString);
} catch (RuntimeException re) {
log.error("find all failed", re);
throw re;
}
}
public Wares merge(Wares detachedInstance) {
log.debug("merging Wares instance");
try {
Wares result = (Wares) getHibernateTemplate().merge(
detachedInstance);
log.debug("merge successful");
return result;
} catch (RuntimeException re) {
log.error("merge failed", re);
throw re;
}
}
public void attachDirty(Wares instance) {
log.debug("attaching dirty Wares instance");
try {
getHibernateTemplate().saveOrUpdate(instance);
log.debug("attach successful");
} catch (RuntimeException re) {
log.error("attach failed", re);
throw re;
}
}
public void attachClean(Wares instance) {
log.debug("attaching clean Wares instance");
try {
getHibernateTemplate().lock(instance, LockMode.NONE);
log.debug("attach successful");
} catch (RuntimeException re) {
log.error("attach failed", re);
throw re;
}
}
public static WaresDAO getFromApplicationContext(ApplicationContext ctx) {
return (WaresDAO) ctx.getBean("WaresDAO");
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?