📄 favoritedaoimpl.java
字号:
package org.bestteam.dao.impl;
import java.util.List;
import org.bestteam.dao.FavoriteDao;
import org.bestteam.domain.Favorite;
import org.hibernate.LockMode;
import org.springframework.context.ApplicationContext;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
public class FavoriteDaoImpl extends HibernateDaoSupport implements FavoriteDao {
/**
*
* @param ApplicationContext 一个ApplicationContext的对象
* @return Favorite的对象
* 在类加载时通过AplicationContext对象得到Favorite的对象
*/
public static Favorite getFromApplicationContext(ApplicationContext ctx) {
return (Favorite) ctx.getBean("favoriteDao");
}
public boolean attachClean(Favorite instance) {
try{
getHibernateTemplate().lock(instance, LockMode.NONE);
}catch(RuntimeException re) {
re.printStackTrace();
return false;
}
return true;
}
/**
* @param Favorite 一个Favorite的对象
* @return boolean
* 对传进来的Favorite对象保存或更新
* 当该对象为一个托管对象时,该方法会执行更新动作
* 当对象为一个瞬时对象时,该方法会执行保存动作
*/
public boolean attachDirty(Favorite instance) {
try{
getHibernateTemplate().saveOrUpdate(instance);
}catch(RuntimeException re) {
re.printStackTrace();
return false;
}
return true;
}
public boolean delete(Favorite persistentInstance) {
try{
getHibernateTemplate().delete(persistentInstance);
}catch(RuntimeException re) {
re.printStackTrace();
return false;
}
return true;
}
/**
* @param Integer 用户的ID
* @return Favorite的对象
* 根据该用户的用户ID(主键),查找该用户所收藏拍卖的信息
* 如果用户ID不存在,则返回空值
*/
public Favorite findFavoriteByUserId(Integer userID) {
Favorite favorite = null;
try{
favorite = (Favorite) getHibernateTemplate().get(Favorite.class, userID);
}catch(RuntimeException re) {
re.printStackTrace();
}
return favorite;
}
public List findFavoriteListByExample(Favorite instance) {
List favoriteList = null;
try{
favoriteList = getHibernateTemplate().findByExample(instance);
}catch(RuntimeException re) {
re.printStackTrace();
}
return favoriteList;
}
/**
* @param String 该类对象的一个属性的名称
* Object 该属性名所对应的对象的值
* @return List列表
* 根据类对象的一个属性的名称和其对应的值,查找该类对象的实例,
* 因为输入的属性不保证能唯一标识该对象,所以返回的对象将是一个由该类对象组成的List列表
*/
public List findFavoriteListByProperty(String propertyName, Object value) {
List favoriteList = null;
try{
String queryString = "from Favorite as favorite where favorite."
+ propertyName + "=?";
favoriteList = getHibernateTemplate().find(queryString, value);
}catch(RuntimeException re) {
re.printStackTrace();
}
return favoriteList;
}
public Favorite merge(Favorite detachedInstance) {
Favorite favorite = null;
try{
favorite = (Favorite) getHibernateTemplate().merge(detachedInstance);
}catch(RuntimeException re) {
re.printStackTrace();
}
return favorite;
}
/**
* @param Favorite Favorite的对象
* @return boolean
* 将传入的Favorite对象持久化
* 应注意传入的对象的id(在对象中应该保持该属性为Null)不能重复
*/
public boolean save(Favorite transientInstance) {
try{
getHibernateTemplate().save(transientInstance);
}catch(RuntimeException re) {
re.printStackTrace();
return false;
}
return true;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -