📄 categorydaoimpl.java
字号:
package cn.com.tarena.ecport.dao.impl;
import java.util.List;
import org.hibernate.LockMode;
import org.hibernate.Query;
import org.hibernate.criterion.Example;
import cn.com.tarena.ecport.common.util.HibernateUtil;
import cn.com.tarena.ecport.dao.ICategoryDAO;
import cn.com.tarena.ecport.exception.ECPortException;
import cn.com.tarena.ecport.pojo.Category;
public class CategoryDAOImpl implements ICategoryDAO {
public void delete(Category persistencePojo) {
try {
HibernateUtil.getSessionFactory().getCurrentSession().delete(persistencePojo);
} catch (RuntimeException e) {
throw e;
}
}
@SuppressWarnings("unchecked")
public List<Category> findByExample(Category instanse) {
try {
List<Category> results = HibernateUtil.getSessionFactory().getCurrentSession().createCriteria("Category").add(
Example.create(instanse)).list();
return results;
} catch (RuntimeException e) {
throw e;
}
}
public Category findById(Long id) {
try {
Category category = (Category) HibernateUtil.getSessionFactory().getCurrentSession().get(Category.class, id);
return category;
} catch (RuntimeException e) {
throw e;
}
}
@SuppressWarnings("unchecked")
public List<Category> findByProperty(String propertyName, Object value) {
try {
String hql = "from Category as c where c." + propertyName + "=?";
Query q = HibernateUtil.getSessionFactory().getCurrentSession().createQuery(hql);
q.setParameter(0, value);
return q.list();
} catch (RuntimeException e) {
throw e;
}
}
public void lock(Category pojo) {
try {
HibernateUtil.getSessionFactory().getCurrentSession().lock(pojo,LockMode.READ);
} catch (RuntimeException e) {
throw e;
}
}
public Category merge(Category detachedPojo) {
try {
Category category = (Category) HibernateUtil.getSessionFactory().getCurrentSession().merge(detachedPojo);
return category;
} catch (RuntimeException e) {
throw e;
}
}
public void save(Category transientPojo) {
try {
HibernateUtil.getSessionFactory().getCurrentSession().save(
transientPojo);
} catch (RuntimeException e) {
throw e;
}
}
public void saveOrUpdate(Category pojo) {
try {
HibernateUtil.getSessionFactory().getCurrentSession().saveOrUpdate(pojo);
} catch (RuntimeException e) {
throw e;
}
}
@SuppressWarnings("unchecked")
public List<Category> findAllCategory() throws ECPortException {
try {
String hql = "from Category";
List<Category> results = HibernateUtil.getSessionFactory().getCurrentSession().createQuery(hql).list();
return results;
} catch (RuntimeException e) {
throw e;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -