⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 userinfodao.java

📁 java web模拟的简单的一个网络硬盘
💻 JAVA
字号:
package com.dark.nethd.dao.hibernate;

import java.util.List;

import org.hibernate.HibernateException;
import org.hibernate.Query;
import org.hibernate.Session;
import org.springframework.dao.DataAccessException;
import org.springframework.orm.hibernate3.HibernateCallback;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import com.dark.nethd.bean.UserInfo;
import com.dark.nethd.dao.IUserInfoDao;

public class UserInfoDAO extends HibernateDaoSupport implements IUserInfoDao {
	private static final String DELETE_USER_BY_ID = "delete from UserInfo where userId = ?";

	public boolean deleteUserByID(final Integer id) throws DataAccessException {
		try {
			this.getHibernateTemplate().execute(new HibernateCallback() {
				public Object doInHibernate(Session session)
						throws HibernateException {
					Query query = session.createQuery(DELETE_USER_BY_ID);
					query.setInteger(0, id.intValue());
					query.executeUpdate();
					return null;
				}
			});
		} catch (DataAccessException e) {
			e.printStackTrace();
			return false;
		}
		return true;
	}

	public UserInfo findUserByID(Integer id) {
		return (UserInfo) this.getHibernateTemplate().get(UserInfo.class, id);
	}

	private static final String FIND_USER_BY_NAME = "from UserInfo where userName = ?";

	public UserInfo findUserByName(String name) {
		List result = this.getHibernateTemplate().find(FIND_USER_BY_NAME, name);
		if (result.size() != 0)
			return (UserInfo) result.get(0);
		return null;
	}

	private static final String FIND_USER_BY_USERNAME_AND_PASSWORD = "from UserInfo where userName = ? and passWord = ?";

	public UserInfo findUserByNameAndPassword(String userName, String password)
			throws DataAccessException {
		List result = this.getHibernateTemplate().find(
				FIND_USER_BY_USERNAME_AND_PASSWORD,
				new Object[] { userName, password });
		if (result.size() != 0)
			return (UserInfo) result.get(0);
		return null;
	}

	public boolean saveUserInfo(UserInfo user) throws DataAccessException {
		try {
			this.getHibernateTemplate().saveOrUpdate(user);
			
		} catch (DataAccessException e) {
			e.printStackTrace();
			return false;
		}
		return true;
	}

}

⌨️ 快捷键说明

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