📄 userbusinessimpl.java
字号:
package cn.com.tarena.ecport.biz.impl;
import java.util.List;
import org.hibernate.HibernateException;
import cn.com.tarena.ecport.biz.IUserBusiness;
import cn.com.tarena.ecport.common.util.HibernateUtil;
import cn.com.tarena.ecport.dao.IContactInfoDAO;
import cn.com.tarena.ecport.dao.IUserDAO;
import cn.com.tarena.ecport.dao.factory.DAOFactory;
import cn.com.tarena.ecport.exception.ECPortException;
import cn.com.tarena.ecport.pojo.ContactInfo;
import cn.com.tarena.ecport.pojo.User;
public class UserBusinessImpl implements IUserBusiness {
public void deleteUser(User user) throws ECPortException {
IUserDAO iua = (IUserDAO) DAOFactory.getDAO(IUserDAO.class.getName());
try {
HibernateUtil.getSessionFactory().getCurrentSession().beginTransaction();
iua.delete(user);
HibernateUtil.getSessionFactory().getCurrentSession().beginTransaction().commit();
} catch (HibernateException e) {
e.printStackTrace();
HibernateUtil.getSessionFactory().getCurrentSession().beginTransaction().rollback();
}
}
public List<User> findAllUsers() throws ECPortException {
IUserDAO iua = (IUserDAO) DAOFactory.getDAO(IUserDAO.class.getName());
try {
HibernateUtil.getSessionFactory().getCurrentSession().beginTransaction();
List<User> users = iua.findAllUsers();
HibernateUtil.getSessionFactory().getCurrentSession().beginTransaction().commit();
return users;
} catch (HibernateException e) {
e.printStackTrace();
HibernateUtil.getSessionFactory().getCurrentSession().beginTransaction().rollback();
}
return null;
}
public ContactInfo getContactInfoByUserid(String userid)
throws ECPortException {
IUserDAO iua = (IUserDAO) DAOFactory.getDAO(IUserDAO.class.getName());
try {
HibernateUtil.getSessionFactory().getCurrentSession().beginTransaction();
User user = iua.findUserById(userid);
ContactInfo ci = user.getContactinfo();
HibernateUtil.getSessionFactory().getCurrentSession().beginTransaction().commit();
return ci;
} catch (Exception e) {
e.printStackTrace();
HibernateUtil.getSessionFactory().getCurrentSession().beginTransaction().rollback();
}
return null;
}
public User getUserById(String userid) throws ECPortException {
IUserDAO iua = (IUserDAO) DAOFactory.getDAO(IUserDAO.class.getName());
try {
HibernateUtil.getSessionFactory().getCurrentSession().beginTransaction();
User user = iua.findUserById(userid);
HibernateUtil.getSessionFactory().getCurrentSession().beginTransaction().commit();
return user;
} catch (Exception e) {
e.printStackTrace();
HibernateUtil.getSessionFactory().getCurrentSession().beginTransaction().rollback();
}
return null;
}
public boolean hasUser(String userid) throws ECPortException {
IUserDAO iua = (IUserDAO) DAOFactory.getDAO(IUserDAO.class.getName());
try {
HibernateUtil.getSessionFactory().getCurrentSession().beginTransaction();
User user = iua.findUserById(userid);
HibernateUtil.getSessionFactory().getCurrentSession().beginTransaction().commit();
if (user == null) {
return false;
} else {
return true;
}
} catch (Exception e) {
e.printStackTrace();
HibernateUtil.getSessionFactory().getCurrentSession().beginTransaction().rollback();
}
return false;
}
public void updateContactInfo(ContactInfo contactInfo)
throws ECPortException {
IContactInfoDAO icid = (IContactInfoDAO) DAOFactory.getDAO(IContactInfoDAO.class.getName());
try {
HibernateUtil.getSessionFactory().getCurrentSession().beginTransaction();
icid.saveOrUpdate(contactInfo);
HibernateUtil.getSessionFactory().getCurrentSession().beginTransaction().commit();
} catch (HibernateException e) {
e.printStackTrace();
HibernateUtil.getSessionFactory().getCurrentSession().beginTransaction().rollback();
}
}
public void updateUserInfo(User user, ContactInfo contactInfo)
throws ECPortException {
IUserDAO iud = (IUserDAO) DAOFactory.getDAO(IUserDAO.class.getName());
IContactInfoDAO icd = (IContactInfoDAO) DAOFactory.getDAO(IContactInfoDAO.class.getName());
try {
HibernateUtil.getSessionFactory().getCurrentSession().beginTransaction();
ContactInfo con = icd.merge(contactInfo);
User u = iud.merge(user);
u.setContactinfo(con);
con.setUsers(u);
iud.saveOrUpdate(u);
HibernateUtil.getSessionFactory().getCurrentSession().beginTransaction().commit();
} catch (HibernateException e) {
e.printStackTrace();
HibernateUtil.getSessionFactory().getCurrentSession().beginTransaction().rollback();
}
}
public void userRegister(User user, ContactInfo contactInfo)
throws ECPortException {
IUserDAO iud = (IUserDAO) DAOFactory.getDAO(IUserDAO.class.getName());
try {
HibernateUtil.getSessionFactory().getCurrentSession().beginTransaction();
contactInfo.setUsers(user);
user.setContactinfo(contactInfo);
User u = iud.merge(user);
iud.save(u);
HibernateUtil.getSessionFactory().getCurrentSession().beginTransaction().commit();
} catch (HibernateException e) {
e.printStackTrace();
HibernateUtil.getSessionFactory().getCurrentSession().beginTransaction().rollback();
throw e;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -