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