📄 storagedao.java
字号:
package crm.dao.other;
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.DetachedCriteria;
import org.hibernate.criterion.MatchMode;
import org.hibernate.criterion.Restrictions;
import org.springframework.context.ApplicationContext;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
import crm.entity.other.StorageEntity;
/**
* Data access object (DAO) for domain model class StorageEntity.
*
* @see crm.entity.other.StorageEntity
* @author MyEclipse Persistence Tools
*/
public class StorageDAO extends HibernateDaoSupport {
private static final Log log = LogFactory.getLog(StorageDAO.class);
// property constants
public static final String STK_WAREHOUSE = "stkWarehouse";
public static final String STK_WARE = "stkWare";
public static final String STK_COUNT = "stkCount";
public static final String STK_MEMO = "stkMemo";
protected void initDao() {
// do nothing
}
public void save(StorageEntity transientInstance) {
log.debug("saving StorageEntity instance");
try {
getHibernateTemplate().save(transientInstance);
log.debug("save successful");
} catch (RuntimeException re) {
log.error("save failed", re);
throw re;
}
}
public void delete(StorageEntity persistentInstance) {
log.debug("deleting StorageEntity instance");
try {
getHibernateTemplate().delete(persistentInstance);
log.debug("delete successful");
} catch (RuntimeException re) {
log.error("delete failed", re);
throw re;
}
}
public List findByIdstorag(Object[] collection,String se)
{
DetachedCriteria criteria = DetachedCriteria.forClass(StorageEntity.class);
criteria.add(Restrictions.in("product.prodId", collection));
if(!(se.equals(""))&& se!=null)
{
criteria.add(Restrictions.like("stkWarehouse", se,MatchMode.ANYWHERE));
}
return getHibernateTemplate().findByCriteria(criteria);
}
/**
* 分页
* @param pagNow
* @return
*/
public List fenye(Integer pagNow)
{
String HQL="from StorageEntity";
Query query=this.getSession().createQuery(HQL);
int pagesie=5;
query.setFirstResult((pagNow-1)*pagesie);
query.setMaxResults(pagesie);
return query.list();
}
public int count()
{
String hql="select count(de) from StorageEntity de ";
Query query=this.getSession().createQuery(hql);
int count=(Integer)query.uniqueResult();
return count;
}
/**
* 删除方法(根据id删除)
*/
public void delete(int id)
{
long lid=id; //将int型转换成long型
this.delete(this.findById(lid));
}
public StorageEntity findById(java.lang.Long id) {
log.debug("getting StorageEntity instance with id: " + id);
try {
StorageEntity instance = (StorageEntity) getHibernateTemplate()
.get("crm.entity.other.StorageEntity", id);
return instance;
} catch (RuntimeException re) {
log.error("get failed", re);
throw re;
}
}
public List findByExample(StorageEntity instance) {
log.debug("finding StorageEntity 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 StorageEntity instance with property: "
+ propertyName + ", value: " + value);
try {
String queryString = "from StorageEntity as model where model."
+ propertyName + "= ?";
return getHibernateTemplate().find(queryString, value);
} catch (RuntimeException re) {
log.error("find by property name failed", re);
throw re;
}
}
public List findByStkWarehouse(Object stkWarehouse) {
return findByProperty(STK_WAREHOUSE, stkWarehouse);
}
public List findByStkWare(Object stkWare) {
return findByProperty(STK_WARE, stkWare);
}
public List findByStkCount(Object stkCount) {
return findByProperty(STK_COUNT, stkCount);
}
public List findByStkMemo(Object stkMemo) {
return findByProperty(STK_MEMO, stkMemo);
}
public List findAll() {
log.debug("finding all StorageEntity instances");
try {
String queryString = "from StorageEntity";
return getHibernateTemplate().find(queryString);
} catch (RuntimeException re) {
log.error("find all failed", re);
throw re;
}
}
public StorageEntity merge(StorageEntity detachedInstance) {
log.debug("merging StorageEntity instance");
try {
StorageEntity result = (StorageEntity) getHibernateTemplate()
.merge(detachedInstance);
log.debug("merge successful");
return result;
} catch (RuntimeException re) {
log.error("merge failed", re);
throw re;
}
}
public void attachDirty(StorageEntity instance) {
log.debug("attaching dirty StorageEntity instance");
try {
getHibernateTemplate().saveOrUpdate(instance);
log.debug("attach successful");
} catch (RuntimeException re) {
log.error("attach failed", re);
throw re;
}
}
public void attachClean(StorageEntity instance) {
log.debug("attaching clean StorageEntity instance");
try {
getHibernateTemplate().lock(instance, LockMode.NONE);
log.debug("attach successful");
} catch (RuntimeException re) {
log.error("attach failed", re);
throw re;
}
}
public static StorageDAO getFromApplicationContext(
ApplicationContext ctx) {
return (StorageDAO) ctx.getBean("StorageEntityDAO");
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -