userinfohibernatedao.java

来自「是一个网站的博客系统」· Java 代码 · 共 74 行

JAVA
74
字号
package com.opensource.blog.dao.hibernate;

import java.util.*;
import org.springframework.orm.hibernate3.support.*;
import com.opensource.blog.dao.UserInfoDAO;
import com.opensource.blog.model.UserInfo;


public class UserInfoHibernateDAO
    extends HibernateDaoSupport implements UserInfoDAO {

  private static final String LOAD_USERNAME = "from UserInfo where username = ?";

  private static final String LOAD_EMAIL = "from UserInfo where email = ?";

  public UserInfoHibernateDAO() {
    super();
  }

  /**
   *
   * @param ui UserInfo
   * @return UserInfo
   * @todo Implement this com.opensource.blog.dao.UserInfoDAO method
   */
  public UserInfo saveUserInfo(UserInfo ui) {
    this.getHibernateTemplate().saveOrUpdate(ui);
    return ui;
  }

  /**
   *
   * @param id long
   * @return UserInfo
   * @todo Implement this com.opensource.blog.dao.UserInfoDAO method
   */
  public UserInfo findUserInfoByID(long id) {
    return (UserInfo)this.getHibernateTemplate().get(UserInfo.class,
        new Long(id));
  }

  /**
   *
   * @param userName String
   * @return UserInfo
   * @todo Implement this com.opensource.blog.dao.UserInfoDAO method
   */
  public UserInfo findUserInfoByUserName(String userName) {
    List l = this.getHibernateTemplate().find(LOAD_USERNAME, userName);
    if (l == null || l.isEmpty()) {
      return null;
    }
    else {
      return (UserInfo) l.get(0);
    }
  }

  /**
   *
   * @param email String
   * @return UserInfo
   * @todo Implement this com.opensource.blog.dao.UserInfoDAO method
   */
  public UserInfo findUserInfoByEmail(String email) {
    List l = this.getHibernateTemplate().find(LOAD_EMAIL, email);
    if (l == null || l.isEmpty()) {
      return null;
    }
    else {
      return (UserInfo) l.get(0);
    }
  }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?