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