【Java开源代码栏目提醒】:网学会员Java开源代码为您提供BspUserDAOImpl.java参考,解决您在BspUserDAOImpl.java学习中工作中的难题,参考学习。
package ch17.dao;
import java.util.List;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.Query;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
import ch17.hibernate.BspCorp;
import ch17.hibernate.BspUser;
public class BspUserDAOImpl extends HibernateDaoSupport implements BspUserDAO {
public static final Log log = LogFactory.getLog(BspUser.class);
public int valid(String id, String pass) {// 验证用户登录信息
int code = 0;
BspUser user = this.findById(id);
if (user == null) {
code = 1;// 用户名不存在
return code;
}
String passw=user.getPassword();
if(passw==null)passw="";
if (!user.getPassword().equals(pass)) {
code = 2;// 密码错误
return code;
}
String ast = user.getAst();
if (ast == null)
ast = "";
if (ast.equals("N"))
code = 3;// 用户账号未激活
if (ast.equals("C"))
code = 4;// 用户账号己被禁用
return code;
}
@Override
public void delete(String id) {
log.debug("deleting BspUser instance");
try {
BspUser instance = (BspUser) this.getHibernateTemplate().get(
"ch17.hibernate.BspUser", id);
this.getHibernateTemplate().delete(instance);
log.debug("delete successful");
} catch (RuntimeException re) {
log.error("delete failed", re);
throw re;
}
}
@Override//根据用户ID查找用户信息
public BspUser findById(String id) {
log.debug("getting BspUser instance with id: " + id);
try {
BspUser instance = (BspUser) getHibernateTemplate().get(
"ch17.hibernate.BspUser", id);
return instance;
} catch (RuntimeException re) {
log.error("get failed", re);
throw re;
}
}
@Override//根据属性和对应的值查找用户信息
public List findByProperty(String propertyName, Object value) {
log.debug("finding BspUser instance with property: " + propertyName
+ ", value: " + value);
try {
String queryString = "from BspUser as model where model."
+ propertyName + " like ?";
Query queryObject = getSession().createQuery(queryString);
queryObject.setParameter(0, value);
return queryObject.list();
} catch (RuntimeException re) {
log.error("find by property name failed", re);
throw re;
}
}
@Override//保存员工信息
public void save(BspUser transientInstance) {
log.debug("saving BspUser instance");
try {
this.getHibernateTemplate().save(transientInstance);
log.debug("save successful");
} catch (RuntimeException re) {
log.error("save failed", re);
throw re;
}
}
@Override//更新用户信息
public void update(BspUser transientInstance) {
log.debug("updating BspUser instance");
try {
this.getHibernateTemplate().update(transientInstance);
log.debug("update successful");
} catch (RuntimeException re) {
log.error("update failed", re);
throw re;
}
}
}
上一篇:
BspUserDAO.java
下一篇:
爱情只不过就是,爱与不爱