📄 ordersdaoimpl.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.IOrdersDAO;
import cn.com.tarena.ecport.exception.ECPortException;
import cn.com.tarena.ecport.pojo.Orders;
public class OrdersDAOImpl implements IOrdersDAO {
@SuppressWarnings("unchecked")
public List<Orders> findAllOrders() throws ECPortException {
try {
List<Orders> orders = HibernateUtil.getSessionFactory().getCurrentSession().createQuery("from Orders").list();
return orders;
} catch (RuntimeException re) {
throw re;
}
}
public void delete(Orders persistencePojo) {
try {
HibernateUtil.getSessionFactory().getCurrentSession().delete(persistencePojo);
} catch (RuntimeException e) {
throw e;
}
}
@SuppressWarnings("unchecked")
public List<Orders> findByExample(Orders ExamplePojo) {
try {
List<Orders> results = HibernateUtil.getSessionFactory().getCurrentSession().createCriteria("Orders").add(
Example.create(ExamplePojo)).list();
return results;
} catch (RuntimeException re) {
throw re;
}
}
public Orders findById(Long id) {
try {
Orders order = (Orders) HibernateUtil.getSessionFactory().getCurrentSession().get(Orders.class, id);
return order;
} catch (RuntimeException e) {
throw e;
}
}
@SuppressWarnings("unchecked")
public List<Orders> findByProperty(String propertyName, Object value) {
try {
String queryString = "from Orders as model where model."+ propertyName + "= ?";
Query queryObject = HibernateUtil.getSessionFactory().getCurrentSession().createQuery(queryString);
queryObject.setParameter(0, value);
return queryObject.list();
} catch (RuntimeException re) {
throw re;
}
}
public void lock(Orders pojo) {
try {
HibernateUtil.getSessionFactory().getCurrentSession().lock(pojo, LockMode.READ);
} catch (RuntimeException e) {
throw e;
}
}
public Orders merge(Orders detachedPojo) {
try {
Orders result = (Orders) HibernateUtil.getSessionFactory().getCurrentSession().merge(detachedPojo);
return result;
} catch (RuntimeException re) {
throw re;
}
}
public void save(Orders transientPojo) {
try {
HibernateUtil.getSessionFactory().getCurrentSession().save(transientPojo);
} catch (RuntimeException e) {
throw e;
}
}
public void saveOrUpdate(Orders pojo) {
try {
HibernateUtil.getSessionFactory().getCurrentSession().saveOrUpdate(pojo);
} catch (RuntimeException re) {
throw re;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -