📄 roledaoimpl.java
字号:
package com.sgm.partybranch.persistence.sysadmin.hibernateImpl;
import java.sql.SQLException;
import java.util.List;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.springframework.dao.DataAccessException;
import org.springframework.orm.hibernate3.HibernateCallback;
import com.sgm.partybranch.common.constants.ErrorCode;
import com.sgm.partybranch.persistence.PaginationHibernateDaoSupport;
import com.sgm.partybranch.persistence.sysadmin.RoleDAO;
import com.sgm.partybranch.temp.sysadmin.hibernate.Role;
public class RoleDAOImpl extends PaginationHibernateDaoSupport implements
RoleDAO {
private static final Log log = LogFactory.getLog(RoleDAOImpl.class);
public void create(Role role) throws DataAccessException {
if (log.isDebugEnabled()) {
log.debug("creating Role");
}
try {
getHibernateTemplate().save(role);
log.debug("Create Role succesful");
} catch (DataAccessException e) {
log.error(ErrorCode.DATA_ACCESS_EXCEPTION_CODE
+ "create role failed", e);
throw e;
}
}
public void delete(Role role) throws DataAccessException {
if (log.isDebugEnabled()) {
log.debug("deleting Role");
}
try {
getHibernateTemplate().delete(role);
log.debug("delete Role succesful");
} catch (DataAccessException e) {
log.error(ErrorCode.DATA_ACCESS_EXCEPTION_CODE
+ "delete role failed", e);
throw e;
}
}
public List<Role> getAllRoles(Integer offset, Integer pageSize)
throws DataAccessException {
if (log.isDebugEnabled()) {
log.debug("getting all Roles");
}
try {
String hql = "from Role";
List<Role> result = findByPage(hql, offset, pageSize);
return result;
} catch (DataAccessException e) {
log.error(ErrorCode.DATA_ACCESS_EXCEPTION_CODE
+ "getting all roles failed", e);
throw e;
}
}
public Role getRoleById(String uuid) throws DataAccessException {
if (log.isDebugEnabled()) {
log.debug("get role instance by id: " + uuid);
}
try {
Role instance = (Role) getHibernateTemplate().get(Role.class, uuid);
return instance;
} catch (DataAccessException e) {
log.error(ErrorCode.DATA_ACCESS_EXCEPTION_CODE
+ "get role by id failed", e);
throw e;
}
}
public List<Role> getRolesByUser(final String userId)
throws DataAccessException {
// TODO Auto-generated method stub
List<Role> result = getHibernateTemplate().executeFind(
new HibernateCallback() {
public Object doInHibernate(Session session)
throws HibernateException, SQLException {
final String sql = "SELECT * FROM TM_ROLE r WHERE r.ROLE_ID IN (SELECT ROLE_ID FROM TM_USER_ROLE WHERE ROLE_ID=:uId)";
List<Role> userRoles=session.createSQLQuery(sql).addEntity("TM_ROLE", Role.class).setString("uId", userId).list();
return userRoles;
}
});
return result;
}
public void update(Role role) throws DataAccessException {
if (log.isDebugEnabled()) {
log.debug("updating role:" + role);
}
try {
getHibernateTemplate().update(role);
log.debug("update role:" + role + " successful");
} catch (DataAccessException e) {
log.error(ErrorCode.DATA_ACCESS_EXCEPTION_CODE + "update role "
+ role + "failed", e);
throw e;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -